key_control 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/key_control.gemspec +27 -0
- data/lib/key_control/key_ring.rb +54 -0
- data/lib/key_control/system.rb +59 -0
- data/lib/key_control/version.rb +3 -0
- data/lib/key_control.rb +13 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a43d357aa17e6404d6b196fb576fdf25946bdab
|
4
|
+
data.tar.gz: 126e9d849870e97199913868ab3ec380e6a142ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6bd5cc1776e64ecdee7abc6425d180a1983e2d6428860e5fc7a52f10d6082ea1b64ceeb156aaa857eae8ee48689d01194cbfa40f53292ac2ff8b6c43e3401c07
|
7
|
+
data.tar.gz: 5e3828a75ac5addee2ae31f590290ac1a36c96d38fcabca66cbbafcccde52150fcc1c2af603649d3c8493f0f8a10c2ea948af77a368d2eaa63804adcd2f183f4
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Andrew Horner
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# KeyControl
|
2
|
+
|
3
|
+
KeyControl is a Ruby wrapper for the `keyctl` commands available on most Linux
|
4
|
+
systems. It provides a Hash-like API for storing and retrieving data using the
|
5
|
+
kernel's built-in key management facilities.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'key_control'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install key_control
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The basic API consists of a single class, `KeyControl::KeyRing`. The `KeyRing`
|
24
|
+
initializer takes a single argument, the ID of the keyring you wish to store
|
25
|
+
your data in. There are several (very useful) [special keyrings](http://manpages.ubuntu.com/manpages/oneiric/man1/keyctl.1.html),
|
26
|
+
which are available for use as constants in the `KeyControl` module.
|
27
|
+
|
28
|
+
As an example, we'll create a basic accessor for the session keyring (useful for sharing information among several grouped processes):
|
29
|
+
```ruby
|
30
|
+
keyring = KeyControl::KeyRing.new(KeyControl::SESSION)
|
31
|
+
```
|
32
|
+
|
33
|
+
Once you have your keyring instance, just treat it like you would a hash:
|
34
|
+
```ruby
|
35
|
+
keyring["mykey"] = "my passphrase"
|
36
|
+
keyring["mykey"]
|
37
|
+
# => "my passphrase"
|
38
|
+
```
|
39
|
+
|
40
|
+
That's it! The power of this gem comes from the ability to use your kernel's
|
41
|
+
built-in key management mechanism to share information between Ruby processes
|
42
|
+
without exposing your data to the outside world.
|
43
|
+
|
44
|
+
## Future Enhancements
|
45
|
+
|
46
|
+
- Improved `libkeyutils` shared object library detection
|
47
|
+
- Basic keyring management (creation, specifically)
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( http://github.com/<my-github-username>/key_control/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/key_control.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'key_control/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "key_control"
|
8
|
+
spec.version = KeyControl::VERSION
|
9
|
+
spec.authors = ["Andrew Horner"]
|
10
|
+
spec.email = ["andrew@tablexi.com"]
|
11
|
+
spec.summary = "A simple wrapper for the `keyctl` utility."
|
12
|
+
spec.description = <<-TEXT
|
13
|
+
Provides a Hash-like syntax for storing and retrieving data from the
|
14
|
+
system's keyctl utility.
|
15
|
+
TEXT
|
16
|
+
|
17
|
+
spec.homepage = "https://github.com/ahorner/key_control"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0")
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module KeyControl
|
2
|
+
|
3
|
+
class KeyRing
|
4
|
+
|
5
|
+
# Public: Get a new KeyControl::KeyRing instance with the specified keyring
|
6
|
+
# identifier.
|
7
|
+
#
|
8
|
+
# keyring - A String or Integer identifying the desired keyring.
|
9
|
+
#
|
10
|
+
# Returns a KeyControl::KeyRing instance.
|
11
|
+
def initialize(keyring)
|
12
|
+
@keyring = keyring
|
13
|
+
@system = System.new
|
14
|
+
end
|
15
|
+
|
16
|
+
# Public: Add the requested data to the keychain for the given description.
|
17
|
+
#
|
18
|
+
# name - The description of the data.
|
19
|
+
# data - The data to store in the keychain.
|
20
|
+
#
|
21
|
+
# Returns nothing.
|
22
|
+
def []=(name, data)
|
23
|
+
execute(:add, "user", name, data, data.length, @keyring)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Public: Get the data matching the passed description from the keychain.
|
27
|
+
#
|
28
|
+
# name - The description of the data for which to search.
|
29
|
+
#
|
30
|
+
# Returns the requested data or nil.
|
31
|
+
def [](name)
|
32
|
+
handle = execute(:search, "user", name, nil, @keyring)
|
33
|
+
return nil if handle == -1
|
34
|
+
|
35
|
+
length = execute(:read, handle, "", 0)
|
36
|
+
buffer = "0" * length
|
37
|
+
execute(:read, handle, buffer, length)
|
38
|
+
|
39
|
+
buffer
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# Private: Execute the requested action in keyctl.
|
45
|
+
#
|
46
|
+
# action - The action to perform.
|
47
|
+
# args - A list of arguments which should be passed to the action.
|
48
|
+
#
|
49
|
+
# Returns the stdout value returned by the call.
|
50
|
+
def execute(action, *args)
|
51
|
+
@system.send(action).call(*args)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "fiddle"
|
2
|
+
|
3
|
+
module KeyControl
|
4
|
+
|
5
|
+
class System
|
6
|
+
|
7
|
+
# Public: Get a proc representing the add_key system call.
|
8
|
+
#
|
9
|
+
# Returns a Fiddle::Function.
|
10
|
+
def add
|
11
|
+
@add ||= Fiddle::Function.new(
|
12
|
+
keyutils["add_key"],
|
13
|
+
[ Fiddle::ALIGN_CHAR,
|
14
|
+
Fiddle::ALIGN_CHAR,
|
15
|
+
Fiddle::TYPE_VOIDP,
|
16
|
+
Fiddle::TYPE_SIZE_T,
|
17
|
+
Fiddle::TYPE_INT ],
|
18
|
+
Fiddle::TYPE_INT )
|
19
|
+
end
|
20
|
+
|
21
|
+
# Public: Get a proc representing the request_key system call.
|
22
|
+
#
|
23
|
+
# Returns a Fiddle::Function.
|
24
|
+
def search
|
25
|
+
@search ||= Fiddle::Function.new(
|
26
|
+
keyutils["request_key"],
|
27
|
+
[ Fiddle::ALIGN_CHAR,
|
28
|
+
Fiddle::ALIGN_CHAR,
|
29
|
+
Fiddle::ALIGN_CHAR,
|
30
|
+
Fiddle::TYPE_INT ],
|
31
|
+
Fiddle::TYPE_INT )
|
32
|
+
end
|
33
|
+
|
34
|
+
# Public: Get a proc representing the keyctl_read system call.
|
35
|
+
#
|
36
|
+
# Returns a Fiddle::Function.
|
37
|
+
def read
|
38
|
+
@read ||= Fiddle::Function.new(
|
39
|
+
keyutils["keyctl_read"],
|
40
|
+
[ Fiddle::TYPE_INT,
|
41
|
+
Fiddle::ALIGN_CHAR,
|
42
|
+
Fiddle::TYPE_SIZE_T ],
|
43
|
+
Fiddle::TYPE_LONG )
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Private: Get a handle representing the system calls available through
|
49
|
+
# libkeyutils.so.
|
50
|
+
# TODO: For now, we assume that the shared object file is in the default
|
51
|
+
# location for CentOS installations. It would be nice to make this more
|
52
|
+
# flexible.
|
53
|
+
#
|
54
|
+
# Returns a Fiddle::Handle.
|
55
|
+
def keyutils
|
56
|
+
@keyutils ||= Fiddle::Handle.new("/lib64/libkeyutils.so.1")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/key_control.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: key_control
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Horner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: |2
|
42
|
+
Provides a Hash-like syntax for storing and retrieving data from the
|
43
|
+
system's keyctl utility.
|
44
|
+
email:
|
45
|
+
- andrew@tablexi.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- .gitignore
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- key_control.gemspec
|
56
|
+
- lib/key_control.rb
|
57
|
+
- lib/key_control/key_ring.rb
|
58
|
+
- lib/key_control/system.rb
|
59
|
+
- lib/key_control/version.rb
|
60
|
+
homepage: https://github.com/ahorner/key_control
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.0.6
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: A simple wrapper for the `keyctl` utility.
|
84
|
+
test_files: []
|