ncipher 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 18bd0912ca40f3f784b195e7f80cbf48aa6ce80e
4
+ data.tar.gz: ff2ee37ae885147995897d3136cc196fb7d208d3
5
+ SHA512:
6
+ metadata.gz: 3e4b36aab5ffbf0e032f274bca212e0c4a7b12598cb90b55a90b3116b861e8a0ef3d72c0ce1096477a2cedd6d3b11292b609ac5a2fe9e9f7eb7c8a28e4da4a3a
7
+ data.tar.gz: 3b5682c5eb756b9f1e074742808122955680092d4b25b53c83378ba5b9ad4a9001588c3bf37e70927bb7e3e6112579f925f35a1c24d9e9bf0a6b5a3275e84b10
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.1
5
+ before_install: gem install bundler -v 1.12.5
6
+ script: rake
7
+ deploy:
8
+ provider: rubygems
9
+ api_key:
10
+ secure: ahAeEGLzp7Y3lPGTmPC1UeuVkE8WwBmdDu7JXm9Hf5FRc3AIQgf+eEFB+M6jDqithbA5kyC59UwsP/tohwBGRFwPpFrxgFT4dKxjgzec+wR2jlEcoFqUzc9Tug2IHBLIMMhK1Vo7FPJJ3J0Fho+VDlOYnG9nV69Lhf9A82BAPtQ=
11
+ gem: ncipher
12
+ on:
13
+ tags: true
14
+ repo: pcboy/ncipher
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at david.hagege@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ncipher.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding : utf-8 -*-
2
+ #
3
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
4
+ # Version 2, December 2004
5
+ #
6
+ # Copyright (C) 2004 Sam Hocevar
7
+ # 14 rue de Plaisance, 75014 Paris, France
8
+ # Everyone is permitted to copy and distribute verbatim or modified
9
+ # copies of this license document, and changing it is allowed as long
10
+ # as the name is changed.
11
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
12
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
14
+ #
15
+ #
16
+ # David Hagege <david.hagege@gmail.com>
17
+ #
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ [![Code Climate](https://codeclimate.com/github/pcboy/ncipher/badges/gpa.svg)](https://codeclimate.com/github/pcboy/ncipher)
2
+ [![Build Status](https://travis-ci.org/pcboy/ncipher.svg)](https://travis-ci.org/pcboy/ncipher)
3
+
4
+ # Ncipher
5
+
6
+ Ncipher is a gem to help you to encrypt your credentials in your ruby apps in a safe manner.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'ncipher'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install ncipher
23
+
24
+ ## Basic Usage
25
+
26
+ First generate a new encryption key. Typically this key needs to be in your .gitignore.
27
+ You don't want it to be pushed to the repository. This file will be used by ncipher each time you need to encrypt/decrypt something. You need to call it `.ncipher_key` and put it in the current folder or any other folder before. (i.e ~/.ncipher_key is fine for instance).
28
+ ```
29
+ $> ncipher generate_key > .ncipher_key
30
+ ```
31
+ You can also set the env variable `NCIPHER_KEY` to that generated key (i.e `export NCIPHER_KEY=kSzARCAw9uv/LQ1o75k5ica1oCpZBUCpP99Sy+s6L2c=`) instead of saving it to a file
32
+
33
+ To encrypt a new password (or anything else):
34
+ ```
35
+ $> ncipher encrypt 'p4$$w0rd'
36
+ deB7ba27qR470UetK/HW47dYMN7p9hguuDiVt59U+Bly6cfQcjgbw/ui/2hBhCEa
37
+ ```
38
+
39
+ Now you can directy put in your .yaml files:
40
+ ```
41
+ defaults: &defaults
42
+ my_password: <%= Ncipher::Ncipher.decrypt('lXEwfKv4dEjmK0kojEAnikNsLCsVCtSMiR2aSfM6uUXYn2DzCZ3O7SA9HaGnMp/kEEsI') %>
43
+ ```
44
+
45
+ And Ncipher::Ncipher.decrypt will magically use your key in `.ncipher_key` to decrypt that password at runtime.
46
+ Note, you can also use the decrypt parameter in the ncipher binary to do the decryption:
47
+ ```
48
+ $> ncipher decrypt deB7ba27qR470UetK/HW47dYMN7p9hguuDiVt59U+Bly6cfQcjgbw/ui/2hBhCEa
49
+ p4$$w0rd
50
+ ```
51
+ So in the end:
52
+ ```
53
+ $> ncipher decrypt `ncipher encrypt 'p4$$w0rd'`
54
+ p4$$w0rd
55
+ ```
56
+
57
+ :)
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ 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).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pcboy/ncipher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
68
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ncipher"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/ncipher ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require 'ncipher'
3
+
4
+ SUB_COMMANDS = %w(generate_key encrypt decrypt)
5
+
6
+ if ARGV.empty?
7
+ STDERR.puts "Ncipher a credential encryption tool"
8
+ STDERR.puts "usage: ncipher generate_key"
9
+ STDERR.puts "usage: ncipher key"
10
+ STDERR.puts "usage: ncipher encrypt <text>"
11
+ STDERR.puts "usage: ncipher decrypt <text>"
12
+ abort
13
+ end
14
+
15
+ cmd = ARGV.shift
16
+ case cmd
17
+ when "generate_key"
18
+ puts Ncipher::Ncipher.new.generate_key
19
+ when "key"
20
+ puts Base64.strict_encode64(Ncipher::Ncipher.new.key)
21
+ when "encrypt"
22
+ if text = ARGV.shift
23
+ puts Ncipher::Ncipher.new.encrypt(text)
24
+ else
25
+ STDERR.puts "usage: Ncipher encrypt <text>"
26
+ end
27
+ when "decrypt"
28
+ if text = ARGV.shift
29
+ puts Ncipher::Ncipher.new.decrypt(text)
30
+ else
31
+ STDERR.puts "usage: Ncipher decrypt <text>"
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Ncipher
2
+ VERSION = "0.2.1"
3
+ end
data/lib/ncipher.rb ADDED
@@ -0,0 +1,65 @@
1
+ require "ncipher/version"
2
+
3
+ require 'base64'
4
+ require 'rbnacl/libsodium'
5
+ require 'rbnacl'
6
+
7
+ module Ncipher
8
+
9
+ class Ncipher
10
+
11
+ def initialize(key_filename: '.ncipher_key')
12
+ @key_filename = key_filename
13
+ end
14
+
15
+ def decrypt(ciphertext_b64)
16
+ box.decrypt(Base64.strict_decode64(ciphertext_b64))
17
+ end
18
+
19
+ def encrypt(plaintext)
20
+ Base64.strict_encode64(box.encrypt(plaintext))
21
+ end
22
+
23
+ def generate_key
24
+ generated_key = RbNaCl::Random.random_bytes(RbNaCl::SecretBox.key_bytes)
25
+ Base64.strict_encode64(generated_key)
26
+ end
27
+
28
+ def key
29
+ saved_key = ENV['NCIPHER_KEY'] || find_keyfile
30
+ abort "Can't find .ncipher_key file or NCIPHER_KEY env variable" if saved_key.nil?
31
+ Base64.decode64(saved_key)
32
+ end
33
+
34
+ def self.decrypt(cyphertext_b64)
35
+ Ncipher.new.decrypt cyphertext_b64
36
+ end
37
+
38
+ def self.encrypt(plaintext)
39
+ Ncipher.new.encrypt plaintext
40
+ end
41
+
42
+ def self.generate_key
43
+ Ncipher.new.generate_key
44
+ end
45
+
46
+ def self.key
47
+ Ncipher.new.key
48
+ end
49
+
50
+ private
51
+ def box
52
+ RbNaCl::SimpleBox.from_secret_key(key)
53
+ end
54
+
55
+ def find_keyfile(folder: '.')
56
+ path = "#{folder}/#{@key_filename}"
57
+ return File.read(path) if File.exist?(path)
58
+ return nil if folder == '/'
59
+ folder = File.expand_path("#{folder}/../")
60
+ find_keyfile(folder: folder)
61
+ end
62
+
63
+ end
64
+
65
+ end
data/ncipher.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ncipher/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ncipher"
8
+ spec.version = Ncipher::VERSION
9
+ spec.authors = ["David Hagege"]
10
+ spec.email = ["david.hagege@gmail.com"]
11
+
12
+ spec.summary = %q{Ncipher lets you encrypt/decrypt credentials in a safe and transparent way}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/pcboy/ncipher"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+ spec.license = 'WTFPL'
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+
26
+ spec.add_dependency 'rbnacl-libsodium', '~> 1.0.10'
27
+ spec.add_dependency 'rbnacl', '~> 3.0.1'
28
+ spec.add_dependency 'trollop', '~> 2.1'
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ncipher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - David Hagege
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-16 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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rbnacl-libsodium
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.10
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.10
69
+ - !ruby/object:Gem::Dependency
70
+ name: rbnacl
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: trollop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
97
+ description: ''
98
+ email:
99
+ - david.hagege@gmail.com
100
+ executables:
101
+ - ncipher
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - exe/ncipher
115
+ - lib/ncipher.rb
116
+ - lib/ncipher/version.rb
117
+ - ncipher.gemspec
118
+ homepage: https://github.com/pcboy/ncipher
119
+ licenses:
120
+ - WTFPL
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.4.6
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Ncipher lets you encrypt/decrypt credentials in a safe and transparent way
142
+ test_files: []