jwk-tool 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.
Files changed (8) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/LICENSE +21 -0
  4. data/README.md +15 -0
  5. data/Rakefile +10 -0
  6. data/bin/jwk_tool +74 -0
  7. data/jwk-tool.gemspec +23 -0
  8. metadata +79 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 094af6b8e41a0b218d4205381bb988f6aa409ef8
4
+ data.tar.gz: 1d21033835a5fcef8620b52639c2a6aa093c6c35
5
+ SHA512:
6
+ metadata.gz: aa7e1c634e1f1370886ed7e26896bd98d3d8bf46de8529af6d38db83a466fa1c574816720b922f9491a4b3cb9fcfc7635775552aa2919d457467d0c76b72f53b
7
+ data.tar.gz: fdec515b52e33154f12e9a7af9640d0a9a8c2b26067910db19895a64102bb57922c845e5c9ce081e17e1111c8eb3d03de88ad17c803bdba5b3115d96c0a24426
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Toyokazu Akiyama
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # jwk-tool
2
+
3
+ Command line tools for operating JSON Web Key
4
+
5
+
6
+ # Install
7
+
8
+ gem install jwk-tool
9
+
10
+ # Usage
11
+
12
+ The following command generate key pairs, private key 'privkey' and public key 'privkey.pub' into the current folder.
13
+
14
+ jwk_tool -g -k privkey
15
+
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/jwk_tool ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require 'rubygems' unless defined?(gem)
4
+ #here = File.dirname(__FILE__)
5
+ #$LOAD_PATH << File.expand_path(File.join(here, '..', 'lib'))
6
+ require 'json/jwt'
7
+ require 'optparse'
8
+
9
+ class JwkTool
10
+ attr_accessor :options
11
+
12
+ def output_usage_and_exit(parser = @parser)
13
+ $stderr.puts parser
14
+ exit
15
+ end
16
+
17
+ def initialize(argv, options = {})
18
+ @argv = argv
19
+ @options = options
20
+ if @argv.size < 1
21
+ @argv << "-h"
22
+ end
23
+ parse!
24
+ end
25
+
26
+ def parser
27
+ @parser ||= OptionParser.new do |opts|
28
+ opts.banner = "Usage: #{$0} [options]"
29
+ opts.separator ""
30
+ opts.separator "options:"
31
+ opts.on("-g", "--generate", "Generate key pairs as file.") { |v| options[:command] = :generate }
32
+ opts.on("-k", "--key=file", String, "Specify private key file name.", "Default: priv_key") { |v| options[:key] = v }
33
+ opts.separator ""
34
+ opts.on("-h", "--help", "Show this help message.") { output_usage_and_exit(opts) }
35
+ end
36
+ end
37
+
38
+ def parse!
39
+ parser.parse!(@argv)
40
+ end
41
+
42
+ def run!
43
+ case options[:command]
44
+ when :generate
45
+ generate
46
+ else
47
+ output_usage_and_exit
48
+ end
49
+ end
50
+
51
+ def generate
52
+ if options[:key].nil?
53
+ $stderr.puts "-g, --generate option requires -k, --key to specify key file name"
54
+ exit
55
+ end
56
+ privkey_file = options[:key]
57
+ pubkey_file = "#{options[:key]}.pub"
58
+ # generate RSA key pair
59
+ ssl_pkey = OpenSSL::PKey::RSA.new(2048)
60
+ # create JSON Web Key (private) for receiver
61
+ jwk = JSON::JWK.new(ssl_pkey)
62
+ # create JSON Web Key (public) for sender
63
+ jwk_pub = JSON::JWK.new(ssl_pkey.public_key)
64
+ begin
65
+ open(pubkey_file, "w") {|f| f.write(jwk_pub)}
66
+ open(privkey_file, "w") {|f| f.write(jwk)}
67
+ rescue => e
68
+ $stderr.puts "#{e.class}, #{e.message}"
69
+ end
70
+ end
71
+ end
72
+
73
+ jwk_tool = JwkTool.new(ARGV)
74
+ jwk_tool.run!
data/jwk-tool.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = "jwk-tool"
3
+ gem.version = "0.0.1"
4
+
5
+ gem.authors = ["Toyokazu Akiyama"]
6
+ gem.email = ["toyokazu@gmail.com"]
7
+ gem.description = %q{Command line tools for operating JSON Web Key}
8
+ gem.summary = %q{Command line tools for operating JSON Web Key}
9
+ gem.homepage = "https://github.com/toyokazu/jwk-tool"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.require_paths = ["lib"]
15
+ gem.has_rdoc = false
16
+ gem.license = "MIT"
17
+
18
+ gem.required_ruby_version = '>= 1.9.3'
19
+
20
+ gem.add_runtime_dependency("json-jwt", [">= 1.5.2"])
21
+
22
+ gem.add_development_dependency("rake", [">= 0.9.2"])
23
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jwk-tool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Toyokazu Akiyama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json-jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.2
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.9.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.2
41
+ description: Command line tools for operating JSON Web Key
42
+ email:
43
+ - toyokazu@gmail.com
44
+ executables:
45
+ - jwk_tool
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - bin/jwk_tool
54
+ - jwk-tool.gemspec
55
+ homepage: https://github.com/toyokazu/jwk-tool
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 1.9.3
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.4.5.1
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Command line tools for operating JSON Web Key
79
+ test_files: []