ncypher 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTRjMTEyYzk5MzAwZjg1YWEyOWJjYzhhOWE3MWJhZTVmZDY4YzFlMg==
5
+ data.tar.gz: !binary |-
6
+ Y2Y5ODBmNjRkNDgxMWExMjk0OWI4NGM2MTZkYTIwNGM4ZDNlNzZhNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NDk4MGY2YmM5NWQxZjAwNTI3MmFkMDczMTFlNjMyMGRlMTMxNTMwYTQ1OTE2
10
+ ZTVhMjIzZjFjNDFhYjMyN2MyOTFkNzdmMzM3ODg1OTYxOWUzZmQ4MDQxYTI0
11
+ YzU1ODkzZWE3NzY0MWFjN2E5OTFkZDZiMjU5N2Y1ZjdiYzlkNTc=
12
+ data.tar.gz: !binary |-
13
+ NWQ1Yzk1ZTgzMTI0MGJjYzUwMmI3ZDJmMjdiNDNlNThlZDI2MjRhMjE3ZThm
14
+ OGU1MmIzODM5OGEyN2QwNjM1OWE0ZmE2MWM2MzQ4YTA2ODYyNThkOGUyMjdl
15
+ YzhhNGUwYjFjMWVhZmU2NDBmODc3MmZlNWUyYjEyMWVjMGMxNWI=
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: "mBGWs5QFmmspHjc+qNywVywwu16KUT0GNqeSasAC3I8JraNTk7NDqOM9HBix67WaPvrY7t3qXTXi52pXhYciyV4tkqBSD5b8TreXQA/ABpvkZvGrbbBjfjHHZ7D0ilmmxnR1ygR07T0ozSvtWIrymOTbhQFfU7sGLwexn4ve7z0fWJEyMGcQJPA5h7gJmUtjgeTc0IO3Et4B8yiIIqdLs0zFRMAPx2WOeKJhaHHEvByViQsfuMsBxzbRrD6MTRqfMVSEPp5dAis0bdycbgwqJ9EEbtvEafBK5fmnbAUJmB6UI8HZ5pP6W7Z3Vz/br2h2LKOOlg7DvCFnDnG9sqT4wdVrjW1l7y6nNSKvtl8U3/Y4kjGPooBC8+tM574ym67KRRhZW4OgDh5bEc96dbpmCnrLZPjC6sDQkwro0VGZhCTqqkJ/pmVyrxKDHtY+fjcxL9vCNAobgKi0ribH65+SpE8/Y99CMxT4zSoCtyT1EwA4RK9JH1GGU2tndwev6NRGzoc14NwbwWihCsKBYxdc8Rl1IRX3DLxgOHT3NTeMhq7jQxlrypePajuqEdWeFVS0tK3unB01blW4IS7fWA7wAaV4+s5ao/OxhP3OEEORTxvq3dchnxvmGLoH8LdQS3pW93KYeZENACtJRLBghoLbkDGgLlG/Qjz5o+cfD520NGY="
11
+ gem: ncypher
12
+ on:
13
+ tags: true
14
+ repo: pcboy/ncypher
@@ -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 ncypher.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,69 @@
1
+ [![Code Climate](https://codeclimate.com/github/pcboy/ncypher/badges/gpa.svg)](https://codeclimate.com/github/pcboy/ncypher)
2
+ [![codebeat badge](https://codebeat.co/badges/411b2b78-0734-40ec-9ca2-4383f66cf92f)](https://codebeat.co/projects/github-com-pcboy-ncypher)
3
+ [![Build Status](https://travis-ci.org/pcboy/ncypher.svg)](https://travis-ci.org/pcboy/ncypher)
4
+
5
+ # Ncypher
6
+
7
+ Ncypher is a gem to help you to encrypt your credentials in your ruby apps in a safe manner.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'ncypher'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install ncypher
24
+
25
+ ## Basic Usage
26
+
27
+ First generate a new encryption key. Typically this key needs to be in your .gitignore.
28
+ You don't want it to be pushed to the repository. This file will be used by ncypher each time you need to encrypt/decrypt something. You need to call it `.ncypher_key` and put it in the current folder or any other folder before. (i.e ~/.ncypher_key is fine for instance).
29
+ ```
30
+ $> ncypher generate_key > .ncypher_key
31
+ ```
32
+ You can also set the env variable `NCYPHER_KEY` to that generated key (i.e `export NCYPHER_KEY=kSzARCAw9uv/LQ1o75k5ica1oCpZBUCpP99Sy+s6L2c=`) instead of saving it to a file
33
+
34
+ To encrypt a new password (or anything else):
35
+ ```
36
+ $> ncypher encrypt 'p4$$w0rd'
37
+ deB7ba27qR470UetK/HW47dYMN7p9hguuDiVt59U+Bly6cfQcjgbw/ui/2hBhCEa
38
+ ```
39
+
40
+ Now you can directy put in your .yaml files:
41
+ ```
42
+ defaults: &defaults
43
+ my_password: <%= Ncypher::Ncypher.decrypt('lXEwfKv4dEjmK0kojEAnikNsLCsVCtSMiR2aSfM6uUXYn2DzCZ3O7SA9HaGnMp/kEEsI') %>
44
+ ```
45
+
46
+ And Ncypher::Ncypher.decrypt will magically use your key in `.ncypher_key` to decrypt that password at runtime.
47
+ Note, you can also use the decrypt parameter in the ncypher binary to do the decryption:
48
+ ```
49
+ $> ncypher decrypt deB7ba27qR470UetK/HW47dYMN7p9hguuDiVt59U+Bly6cfQcjgbw/ui/2hBhCEa
50
+ p4$$w0rd
51
+ ```
52
+ So in the end:
53
+ ```
54
+ $> ncypher decrypt `ncypher encrypt 'p4$$w0rd'`
55
+ p4$$w0rd
56
+ ```
57
+
58
+ :)
59
+
60
+ ## Development
61
+
62
+ 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.
63
+
64
+ 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).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pcboy/ncypher. 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.
69
+
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 "ncypher"
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/ncypher ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require 'ncypher'
3
+
4
+ SUB_COMMANDS = %w(generate_key encrypt decrypt)
5
+
6
+ if ARGV.empty?
7
+ STDERR.puts "Ncypher a credential encryption tool"
8
+ STDERR.puts "usage: ncypher generate_key"
9
+ STDERR.puts "usage: ncypher key"
10
+ STDERR.puts "usage: ncypher encrypt <text>"
11
+ STDERR.puts "usage: ncypher decrypt <text>"
12
+ abort
13
+ end
14
+
15
+ cmd = ARGV.shift
16
+ case cmd
17
+ when "generate_key"
18
+ puts Ncypher::Ncypher.new.generate_key
19
+ when "key"
20
+ puts Ncypher::Ncypher.new.key_b64
21
+ when "encrypt"
22
+ if text = ARGV.shift
23
+ puts Ncypher::Ncypher.new.encrypt(text)
24
+ else
25
+ STDERR.puts "usage: Ncypher encrypt <text>"
26
+ end
27
+ when "decrypt"
28
+ if text = ARGV.shift
29
+ puts Ncypher::Ncypher.new.decrypt(text)
30
+ else
31
+ STDERR.puts "usage: Ncypher decrypt <text>"
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Ncypher
2
+ VERSION = "0.5.0"
3
+ end
data/lib/ncypher.rb ADDED
@@ -0,0 +1,73 @@
1
+ require "ncypher/version"
2
+
3
+ require 'base64'
4
+ require 'rbnacl/libsodium'
5
+ require 'rbnacl'
6
+
7
+ module Ncypher
8
+
9
+ class Ncypher
10
+
11
+ def initialize(key_filename: '.ncypher_key')
12
+ @key_filename = key_filename
13
+ end
14
+
15
+ def decrypt(ciphertext_b64)
16
+ box.decrypt(Base64.strict_decode64(ciphertext_b64.strip))
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['NCYPHER_KEY'] || find_keyfile
30
+ abort "Can't find .ncypher_key file or NCYPHER_KEY env variable" if saved_key.nil?
31
+ Base64.strict_decode64(saved_key.strip)
32
+ end
33
+
34
+ def key_b64
35
+ Base64.strict_encode64 key
36
+ end
37
+
38
+ def self.decrypt(cyphertext_b64)
39
+ Ncypher.new.decrypt cyphertext_b64
40
+ end
41
+
42
+ def self.encrypt(plaintext)
43
+ Ncypher.new.encrypt plaintext
44
+ end
45
+
46
+ def self.generate_key
47
+ Ncypher.new.generate_key
48
+ end
49
+
50
+ def self.key
51
+ Ncypher.new.key
52
+ end
53
+
54
+ def self.key_b64
55
+ Ncypher.new.key_b64
56
+ end
57
+
58
+ private
59
+ def box
60
+ RbNaCl::SimpleBox.from_secret_key(key)
61
+ end
62
+
63
+ def find_keyfile(folder: '.')
64
+ path = "#{folder}/#{@key_filename}"
65
+ return File.read(path) if File.exist?(path)
66
+ return nil if folder == '/'
67
+ folder = File.expand_path("#{folder}/../")
68
+ find_keyfile(folder: folder)
69
+ end
70
+
71
+ end
72
+
73
+ end
data/ncypher.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ncypher/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ncypher"
8
+ spec.version = Ncypher::VERSION
9
+ spec.authors = ["David Hagege"]
10
+ spec.email = ["david.hagege@gmail.com"]
11
+
12
+ spec.summary = %q{Ncypher lets you encrypt/decrypt credentials in a safe and transparent way}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/pcboy/ncypher"
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'
27
+ spec.add_dependency 'rbnacl', '~> 3.0'
28
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ncypher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - David Hagege
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-19 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'
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'
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'
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'
83
+ description: ''
84
+ email:
85
+ - david.hagege@gmail.com
86
+ executables:
87
+ - ncypher
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .travis.yml
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - exe/ncypher
101
+ - lib/ncypher.rb
102
+ - lib/ncypher/version.rb
103
+ - ncypher.gemspec
104
+ homepage: https://github.com/pcboy/ncypher
105
+ licenses:
106
+ - WTFPL
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.5
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Ncypher lets you encrypt/decrypt credentials in a safe and transparent way
128
+ test_files: []