cwt 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6870c9bcd5189270ba3e8a52322cb14db72a00e5a6997826b06cec285ffb5e91
4
+ data.tar.gz: 0c16ef24fb68ad2aa392c685817be3cefdd2d9e01573397d488b5aa0da05228b
5
+ SHA512:
6
+ metadata.gz: 8193d39b90ff7a7e5b3894726f8f3d1552591b66f017bc5d830db1f34b07431ae59b4d5fba9292ba979bc0b3a7f1ff2fd43ee28060e38f90788534c38509b690
7
+ data.tar.gz: 25e2cb0e949780342cf8310f502fa62a0981c2444521803183d7969329065323f03b145532305ca5ae42d3855697cbe68c41a2be9c927ff86e6f3dd384493669
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ /Gemfile.lock
14
+ /.byebug_history
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,36 @@
1
+ require:
2
+ - rubocop-performance
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.6
6
+ DisabledByDefault: true
7
+
8
+ Bundler:
9
+ Enabled: true
10
+
11
+ Gemspec:
12
+ Enabled: true
13
+
14
+ Layout:
15
+ Enabled: true
16
+
17
+ Lint:
18
+ Enabled: true
19
+
20
+ Metrics/LineLength:
21
+ Max: 120
22
+
23
+ Naming:
24
+ Enabled: true
25
+
26
+ Performance:
27
+ Enabled: true
28
+
29
+ Security:
30
+ Enabled: true
31
+
32
+ Style/FrozenStringLiteralComment:
33
+ Enabled: true
34
+
35
+ Style/HashSyntax:
36
+ Enabled: true
@@ -0,0 +1,8 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.4
7
+ - 2.5.6
8
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## [v0.2.0] - 2019-08-31
4
+
5
+ ### Added
6
+
7
+ - `CWT.decode` can decode a signed CWT
8
+
9
+ [v0.2.0]: https://github.com/cedarcode/cwt-ruby/compare/9985bac0a1ffe5c5d4d3d7330a453b65f71a148f...v0.2.0/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in cwt.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Gonzalo Rodriguez
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.
@@ -0,0 +1,48 @@
1
+ # cwt-ruby
2
+
3
+ Ruby implementation of RFC 8392 CBOR Web Token (CWT)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cwt'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cwt
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ cwt = CWT.decode(data, cose_key)
25
+
26
+ # Read claims
27
+ cwt.iss
28
+ cwt.sub
29
+ cwt.aud
30
+ cwt.exp
31
+ cwt.nbf
32
+ cwt.iat
33
+ cwt.cti
34
+ ```
35
+
36
+ ## Development
37
+
38
+ 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.
39
+
40
+ 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).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cedarcode/cwt-ruby.
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "cwt"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -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
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "cwt/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "cwt"
9
+ spec.version = CWT::VERSION
10
+ spec.authors = ["Gonzalo Rodriguez"]
11
+ spec.email = ["gonzalo@cedarcode.com"]
12
+
13
+ spec.summary = "Ruby implementation of RFC 8392 CBOR Web Token (CWT)"
14
+ spec.homepage = "https://github.com/cedarcode/cwt-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "cose", "~> 0.9.0"
32
+
33
+ spec.add_development_dependency "bundler", "~> 2.0"
34
+ spec.add_development_dependency "byebug", "~> 11.0"
35
+ spec.add_development_dependency "rake", "~> 12.3"
36
+ spec.add_development_dependency "rspec", "~> 3.8"
37
+ spec.add_development_dependency "rubocop", "~> 0.74.0"
38
+ spec.add_development_dependency "rubocop-performance", "~> 1.4"
39
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cose/key"
4
+ require "cose/sign1"
5
+ require "cwt/claims_set"
6
+ require "cwt/version"
7
+
8
+ module CWT
9
+ class Error < StandardError; end
10
+
11
+ def self.decode(token, public_key)
12
+ key = COSE::Key.deserialize(public_key)
13
+ sign1 = COSE::Sign1.deserialize(token)
14
+
15
+ if sign1.verify(key)
16
+ CWT::ClaimsSet.from_cbor(sign1.payload)
17
+ else
18
+ raise(CWT::Error, "Verification failed")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cbor"
4
+
5
+ module CWT
6
+ class ClaimsSet
7
+ LABEL_ISS = 1
8
+ LABEL_SUB = 2
9
+ LABEL_AUD = 3
10
+ LABEL_EXP = 4
11
+ LABEL_NBF = 5
12
+ LABEL_IAT = 6
13
+ LABEL_CTI = 7
14
+
15
+ def self.from_cbor(cbor)
16
+ from_map(CBOR.decode(cbor))
17
+ end
18
+
19
+ def self.from_map(map)
20
+ new(
21
+ iss: map[LABEL_ISS],
22
+ sub: map[LABEL_SUB],
23
+ aud: map[LABEL_AUD],
24
+ exp: map[LABEL_EXP],
25
+ nbf: map[LABEL_NBF],
26
+ iat: map[LABEL_IAT],
27
+ cti: map[LABEL_CTI]
28
+ )
29
+ end
30
+
31
+ attr_reader :iss, :sub, :aud, :exp, :nbf, :iat, :cti
32
+
33
+ def initialize(iss:, sub:, aud:, exp:, nbf:, iat:, cti:)
34
+ @iss = iss
35
+ @sub = sub
36
+ @aud = aud
37
+ @exp = exp
38
+ @nbf = nbf
39
+ @iat = iat
40
+ @cti = cti
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CWT
4
+ VERSION = "0.2.0"
5
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cwt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Gonzalo Rodriguez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cose
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '11.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '11.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.74.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.74.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.4'
111
+ description:
112
+ email:
113
+ - gonzalo@cedarcode.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
121
+ - ".travis.yml"
122
+ - CHANGELOG.md
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - cwt.gemspec
130
+ - lib/cwt.rb
131
+ - lib/cwt/claims_set.rb
132
+ - lib/cwt/version.rb
133
+ homepage: https://github.com/cedarcode/cwt-ruby
134
+ licenses:
135
+ - MIT
136
+ metadata:
137
+ homepage_uri: https://github.com/cedarcode/cwt-ruby
138
+ source_code_uri: https://github.com/cedarcode/cwt-ruby
139
+ changelog_uri: https://github.com/cedarcode/cwt-ruby
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubygems_version: 3.0.6
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Ruby implementation of RFC 8392 CBOR Web Token (CWT)
159
+ test_files: []