secure_conf 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/secure_conf/config.rb +49 -0
- data/lib/secure_conf/core_ext/string.rb +9 -0
- data/lib/secure_conf/core_ext.rb +1 -0
- data/lib/secure_conf/encrypter.rb +37 -0
- data/lib/secure_conf/serializer/json.rb +15 -0
- data/lib/secure_conf/serializer/marshal.rb +13 -0
- data/lib/secure_conf/serializer.rb +7 -0
- data/lib/secure_conf/storage/yaml.rb +27 -0
- data/lib/secure_conf/storage.rb +10 -0
- data/lib/secure_conf/version.rb +3 -0
- data/lib/secure_conf.rb +21 -0
- data/secure_conf.gemspec +25 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5577c49a1bbfcc5e15217e66b508445823bea95e
|
4
|
+
data.tar.gz: 47d482b939a3c124cd7e5112af2c6611a7a13eb2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a3b111bf1d3ca46607d03d76d2324238cbe25bd1c087a58d35d2b827d188ee7f5bbd00f1f5fcc0a95a1fbfcc58f41260c974b395b2f380a6f47586d9432e0b7
|
7
|
+
data.tar.gz: 3aab96dbf9603ecfedc503df1cce653e01d827ca4b470df05a53045e8999a8fdf7a0a98fdfb4498ba36041808dd7bb7cfcd3fecf27310a988c468fa6dea12bd3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 yoshida
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# SecureConf
|
2
|
+
|
3
|
+
To encrypt the configuration value.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'secure_conf'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install secure_conf
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
path = File.expand_path("config.yml", File.dirname(__FILE__))
|
24
|
+
config = SecureConf::Config.new(path)
|
25
|
+
p config["enc:aaa"]
|
26
|
+
config["enc:aaa"] = "aaa"
|
27
|
+
config.save
|
28
|
+
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
33
|
+
|
34
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yoshida-eth0/ruby-secure_conf.
|
39
|
+
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
44
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "secure_conf"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module SecureConf
|
2
|
+
class Config < Hash
|
3
|
+
attr_reader :path
|
4
|
+
attr_reader :encripter
|
5
|
+
attr_reader :serializer
|
6
|
+
attr_reader :storage
|
7
|
+
attr_accessor :auto_commit
|
8
|
+
|
9
|
+
def initialize(path, encripter: nil, serializer: nil, storage: nil, auto_commit: false)
|
10
|
+
@path = path
|
11
|
+
@encripter = encripter || SecureConf.default
|
12
|
+
@serializer = serializer || Serializer::Marshal
|
13
|
+
@storage = storage || Storage.fetch(path)
|
14
|
+
@auto_commit = auto_commit
|
15
|
+
self.replace(@storage.load(path))
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :plain_store, :store
|
19
|
+
|
20
|
+
def store(key, value)
|
21
|
+
if key.to_s.start_with?("enc:")
|
22
|
+
secure_store(key, value)
|
23
|
+
else
|
24
|
+
plain_store(key, value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
alias_method :[]=, :store
|
28
|
+
|
29
|
+
def secure_store(key, value)
|
30
|
+
value = @serializer.dump(value)
|
31
|
+
plain_store(key, @encripter.encrypt(value))
|
32
|
+
end
|
33
|
+
|
34
|
+
alias_method :plain_get, :[]
|
35
|
+
|
36
|
+
def [](key)
|
37
|
+
value = plain_get(key)
|
38
|
+
if value && key.to_s.start_with?("enc:")
|
39
|
+
value = @encripter.decrypt(value)
|
40
|
+
value = @serializer.load(value)
|
41
|
+
end
|
42
|
+
value
|
43
|
+
end
|
44
|
+
|
45
|
+
def save
|
46
|
+
@storage.save(path, self)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "secure_conf/core_ext/string"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module SecureConf
|
5
|
+
class Encrypter
|
6
|
+
def initialize(pkey=nil, pass=nil)
|
7
|
+
pkey ||= "~/.ssh/id_rsa"
|
8
|
+
self.pkey = [pkey, pass]
|
9
|
+
end
|
10
|
+
|
11
|
+
def pkey=(pk)
|
12
|
+
pk, pass = [pk].flatten
|
13
|
+
|
14
|
+
case pk
|
15
|
+
when OpenSSL::PKey::RSA
|
16
|
+
@pkey = pk
|
17
|
+
when String
|
18
|
+
pk2 = File.expand_path(pk)
|
19
|
+
if File.file?(pk2) && File.readable?(pk2)
|
20
|
+
pk = File.read(pk2)
|
21
|
+
end
|
22
|
+
|
23
|
+
@pkey = OpenSSL::PKey::RSA.new(pk, pass)
|
24
|
+
when Integer
|
25
|
+
@pkey = OpenSSL::PKey::RSA.new(pk)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def encrypt(str)
|
30
|
+
Base64.strict_encode64(@pkey.public_encrypt(str))
|
31
|
+
end
|
32
|
+
|
33
|
+
def decrypt(str)
|
34
|
+
@pkey.private_decrypt(Base64.strict_decode64(str))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module SecureConf
|
4
|
+
module Storage
|
5
|
+
def self.fetch(path)
|
6
|
+
ext = File.extname(path).sub(".", "").capitalize
|
7
|
+
const_get(ext)
|
8
|
+
end
|
9
|
+
|
10
|
+
module Yaml
|
11
|
+
def self.load(path)
|
12
|
+
if File.file?(path)
|
13
|
+
YAML.load_file(path)
|
14
|
+
else
|
15
|
+
{}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.save(path, obj)
|
20
|
+
h = {}
|
21
|
+
h.replace(obj)
|
22
|
+
YAML.dump(h, File.open(path, "w"))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
Yml = Yaml
|
26
|
+
end
|
27
|
+
end
|
data/lib/secure_conf.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "secure_conf/version"
|
2
|
+
require "secure_conf/config"
|
3
|
+
require "secure_conf/encrypter"
|
4
|
+
require "secure_conf/serializer"
|
5
|
+
require "secure_conf/storage"
|
6
|
+
|
7
|
+
module SecureConf
|
8
|
+
class << self
|
9
|
+
def default
|
10
|
+
@@default ||= SecureConf::Encrypter.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def default=(encrypter)
|
14
|
+
@@default = encrypter
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(method, *args)
|
18
|
+
default.send(method, *args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/secure_conf.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'secure_conf/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "secure_conf"
|
8
|
+
spec.version = SecureConf::VERSION
|
9
|
+
spec.authors = ["yoshida"]
|
10
|
+
spec.email = ["yoshida.eth0@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{To encrypt the configuration value.}
|
13
|
+
spec.description = %q{To encrypt the configuration value.}
|
14
|
+
spec.homepage = "https://github.com/yoshida-eth0/ruby-secure_conf"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: secure_conf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yoshida
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-05 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: To encrypt the configuration value.
|
56
|
+
email:
|
57
|
+
- yoshida.eth0@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/secure_conf.rb
|
72
|
+
- lib/secure_conf/config.rb
|
73
|
+
- lib/secure_conf/core_ext.rb
|
74
|
+
- lib/secure_conf/core_ext/string.rb
|
75
|
+
- lib/secure_conf/encrypter.rb
|
76
|
+
- lib/secure_conf/serializer.rb
|
77
|
+
- lib/secure_conf/serializer/json.rb
|
78
|
+
- lib/secure_conf/serializer/marshal.rb
|
79
|
+
- lib/secure_conf/storage.rb
|
80
|
+
- lib/secure_conf/storage/yaml.rb
|
81
|
+
- lib/secure_conf/version.rb
|
82
|
+
- secure_conf.gemspec
|
83
|
+
homepage: https://github.com/yoshida-eth0/ruby-secure_conf
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.5.1
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: To encrypt the configuration value.
|
107
|
+
test_files: []
|