envkey 0.1.0
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 +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/envkey.gemspec +39 -0
- data/ext/envkey.go +89 -0
- data/ext/envkey.h +60 -0
- data/ext/envkey.so +0 -0
- data/lib/envkey.rb +15 -0
- data/lib/envkey/core.rb +30 -0
- data/lib/envkey/rails.rb +0 -0
- data/lib/envkey/version.rb +3 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b78f4806d12bd235d5f3aea9f6630a58e79b02a1
|
4
|
+
data.tar.gz: d18595b35cb9de8e7e113d88af83d655411af440
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6fde66600f0e000e2f6154575726140ebe68eb4ea9c8307b1e6fdef66c5e3a06aac70c6743fb4337a920f7febaf96939eff7a010d0ee9d306635dcb74b9c0a87
|
7
|
+
data.tar.gz: c6cfcab36d74a6ef1e90693aa3c27556b79d111b04cfd6548ea7c7d5a6c032a513d1da9dc5496d45d3e394a9f99afeeb3559a6433cab60532eeb6e34749fc8a3
|
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) 2017 Dane Schneider
|
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,41 @@
|
|
1
|
+
# Envkey
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/envkey`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'envkey'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install envkey
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/envkey.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "envkey"
|
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
data/envkey.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'envkey/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "envkey"
|
8
|
+
spec.version = Envkey::VERSION
|
9
|
+
spec.authors = ["Dane Schneider"]
|
10
|
+
spec.email = ["dane@envkey.com"]
|
11
|
+
|
12
|
+
spec.summary = "Envkey secures and simplifies app secrets and config by storing it in an encrypted vault and granting access to developers and servers."#%q{TODO: Write a short summary, because Rubygems requires one.}
|
13
|
+
# spec.description = ""#%q{TODO: Write a longer description or delete this line.}
|
14
|
+
spec.homepage = "https://www.envkey.com"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
|
37
|
+
spec.add_runtime_dependency "ffi", "~> 1.9"
|
38
|
+
spec.add_runtime_dependency "dotenv", "~> 2.0"
|
39
|
+
end
|
data/ext/envkey.go
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
package main
|
2
|
+
|
3
|
+
import (
|
4
|
+
"C"
|
5
|
+
"bytes"
|
6
|
+
"strings"
|
7
|
+
"net/http"
|
8
|
+
// "fmt"
|
9
|
+
"encoding/json"
|
10
|
+
"io/ioutil"
|
11
|
+
"log"
|
12
|
+
"golang.org/x/crypto/openpgp"
|
13
|
+
"golang.org/x/crypto/openpgp/armor"
|
14
|
+
)
|
15
|
+
|
16
|
+
const urlBase = "https://env-service.herokuapp.com/"
|
17
|
+
|
18
|
+
type EnvResponse struct {
|
19
|
+
Env string `json:"env"`
|
20
|
+
EncryptedPrivkey string `json:"encrypted_privkey"`
|
21
|
+
}
|
22
|
+
|
23
|
+
//export EnvJson
|
24
|
+
func EnvJson(envkey *C.char) *C.char {
|
25
|
+
split := strings.Split(C.GoString(envkey), "-")
|
26
|
+
envkeyParam, pw := split[0], split[1]
|
27
|
+
envResponse := new(EnvResponse)
|
28
|
+
var err error
|
29
|
+
err = getJson(urlBase + envkeyParam, envResponse)
|
30
|
+
if (err != nil){
|
31
|
+
return C.CString("")
|
32
|
+
}
|
33
|
+
var decrypted string
|
34
|
+
decrypted, err = decrypt(envResponse.Env, envResponse.EncryptedPrivkey, pw)
|
35
|
+
if (err != nil){
|
36
|
+
return C.CString("")
|
37
|
+
}
|
38
|
+
|
39
|
+
return C.CString(decrypted)
|
40
|
+
}
|
41
|
+
|
42
|
+
func getJson(url string, target interface{}) error {
|
43
|
+
r, err := http.Get(url)
|
44
|
+
if err != nil {
|
45
|
+
return err
|
46
|
+
}
|
47
|
+
defer r.Body.Close()
|
48
|
+
|
49
|
+
return json.NewDecoder(r.Body).Decode(target)
|
50
|
+
}
|
51
|
+
|
52
|
+
func decrypt(cipher, privkey, pw string) (string, error) {
|
53
|
+
// Open the private key file
|
54
|
+
keyringFileBuffer := bytes.NewBufferString(privkey)
|
55
|
+
entityList, err := openpgp.ReadArmoredKeyRing(keyringFileBuffer)
|
56
|
+
if (err != nil){
|
57
|
+
log.Fatal(err)
|
58
|
+
}
|
59
|
+
entity := entityList[0]
|
60
|
+
|
61
|
+
// Get the passphrase and read the private key.
|
62
|
+
passphraseByte := []byte(pw)
|
63
|
+
entity.PrivateKey.Decrypt(passphraseByte)
|
64
|
+
for _, subkey := range entity.Subkeys {
|
65
|
+
subkey.PrivateKey.Decrypt(passphraseByte)
|
66
|
+
}
|
67
|
+
|
68
|
+
// Decode armored message
|
69
|
+
decbuf := bytes.NewBufferString(cipher)
|
70
|
+
result, err := armor.Decode(decbuf)
|
71
|
+
if err != nil {
|
72
|
+
return "", err
|
73
|
+
}
|
74
|
+
|
75
|
+
// Decrypt it with the contents of the private key
|
76
|
+
md, err := openpgp.ReadMessage(result.Body, entityList, nil, nil)
|
77
|
+
if err != nil {
|
78
|
+
return "", err
|
79
|
+
}
|
80
|
+
|
81
|
+
bytes, err := ioutil.ReadAll(md.UnverifiedBody)
|
82
|
+
if err != nil {
|
83
|
+
return "", err
|
84
|
+
}
|
85
|
+
|
86
|
+
return string(bytes), nil
|
87
|
+
}
|
88
|
+
|
89
|
+
func main() {}
|
data/ext/envkey.h
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
/* Created by "go tool cgo" - DO NOT EDIT. */
|
2
|
+
|
3
|
+
/* package command-line-arguments */
|
4
|
+
|
5
|
+
/* Start of preamble from import "C" comments. */
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
/* End of preamble from import "C" comments. */
|
11
|
+
|
12
|
+
|
13
|
+
/* Start of boilerplate cgo prologue. */
|
14
|
+
#line 1 "cgo-gcc-export-header-prolog"
|
15
|
+
|
16
|
+
#ifndef GO_CGO_PROLOGUE_H
|
17
|
+
#define GO_CGO_PROLOGUE_H
|
18
|
+
|
19
|
+
typedef signed char GoInt8;
|
20
|
+
typedef unsigned char GoUint8;
|
21
|
+
typedef short GoInt16;
|
22
|
+
typedef unsigned short GoUint16;
|
23
|
+
typedef int GoInt32;
|
24
|
+
typedef unsigned int GoUint32;
|
25
|
+
typedef long long GoInt64;
|
26
|
+
typedef unsigned long long GoUint64;
|
27
|
+
typedef GoInt64 GoInt;
|
28
|
+
typedef GoUint64 GoUint;
|
29
|
+
typedef __SIZE_TYPE__ GoUintptr;
|
30
|
+
typedef float GoFloat32;
|
31
|
+
typedef double GoFloat64;
|
32
|
+
typedef float _Complex GoComplex64;
|
33
|
+
typedef double _Complex GoComplex128;
|
34
|
+
|
35
|
+
/*
|
36
|
+
static assertion to make sure the file is being used on architecture
|
37
|
+
at least with matching size of GoInt.
|
38
|
+
*/
|
39
|
+
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
|
40
|
+
|
41
|
+
typedef struct { const char *p; GoInt n; } GoString;
|
42
|
+
typedef void *GoMap;
|
43
|
+
typedef void *GoChan;
|
44
|
+
typedef struct { void *t; void *v; } GoInterface;
|
45
|
+
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
46
|
+
|
47
|
+
#endif
|
48
|
+
|
49
|
+
/* End of boilerplate cgo prologue. */
|
50
|
+
|
51
|
+
#ifdef __cplusplus
|
52
|
+
extern "C" {
|
53
|
+
#endif
|
54
|
+
|
55
|
+
|
56
|
+
extern char* EnvJson(char* p0);
|
57
|
+
|
58
|
+
#ifdef __cplusplus
|
59
|
+
}
|
60
|
+
#endif
|
data/ext/envkey.so
ADDED
Binary file
|
data/lib/envkey.rb
ADDED
data/lib/envkey/core.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'dotenv'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Envkey::Core
|
6
|
+
extend FFI::Library
|
7
|
+
ffi_lib File.expand_path('../../ext/envkey.so', File.dirname(__FILE__))
|
8
|
+
attach_function :EnvJson, [:string], :string
|
9
|
+
|
10
|
+
def self.load_env
|
11
|
+
return if ENV['@@ENVKEY_LOADED_ENV']
|
12
|
+
Dotenv.load
|
13
|
+
|
14
|
+
if ENV["ENVKEY"]
|
15
|
+
json = EnvJson(ENV["ENVKEY"])
|
16
|
+
if json.present?
|
17
|
+
envs = JSON.parse(json)
|
18
|
+
envs.each do |k,v|
|
19
|
+
var = k.upcase
|
20
|
+
ENV[var] = v unless ENV[var]
|
21
|
+
end
|
22
|
+
ENV['@@ENVKEY_LOADED_ENV'] = "true"
|
23
|
+
puts "ENVKEY: env loaded and decrypted - access via ENV"
|
24
|
+
else
|
25
|
+
raise "Envkey invalid. Couldn't load env."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/lib/envkey/rails.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: envkey
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dane Schneider
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-17 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.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ffi
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.9'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- dane@envkey.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- envkey.gemspec
|
100
|
+
- ext/envkey.go
|
101
|
+
- ext/envkey.h
|
102
|
+
- ext/envkey.so
|
103
|
+
- lib/envkey.rb
|
104
|
+
- lib/envkey/core.rb
|
105
|
+
- lib/envkey/rails.rb
|
106
|
+
- lib/envkey/version.rb
|
107
|
+
homepage: https://www.envkey.com
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata:
|
111
|
+
allowed_push_host: https://rubygems.org
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.5.1
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Envkey secures and simplifies app secrets and config by storing it in an
|
132
|
+
encrypted vault and granting access to developers and servers.
|
133
|
+
test_files: []
|