cwt 0.4.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: 58ca060eb1aa285140dcbd999832e2147779ed902b8524132b976db964dec35c
4
+ data.tar.gz: ec3f4154d2bae4530e462d2fc6253c305d314d96a9955d5dbdcb18e2440c9352
5
+ SHA512:
6
+ metadata.gz: 2c3dd6f536f9803aa3ca81c2b26757cccca74a0542f19fb622effa37d755f4ba3b67c0929d5db6a7f7d849df14f8129466fa93a12a675b1a537db73e7676a218
7
+ data.tar.gz: 290eadb2f3e862d52e344b197b4abeb5fdbe59f918172d2c9200a0b142d206ec23eb5e8014d97dbe593b8635c0075d94338581185e14152851ce4529632e19a0
@@ -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.4
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,17 @@
1
+ dist: bionic
2
+ language: ruby
3
+ cache: bundler
4
+
5
+ rvm:
6
+ - ruby-head
7
+ - 2.7.0
8
+ - 2.6.5
9
+ - 2.5.7
10
+ - 2.4.9
11
+
12
+ before_install: gem install bundler -v 2.1.4
13
+
14
+ matrix:
15
+ fast_finish: true
16
+ allow_failures:
17
+ - rvm: ruby-head
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ ## [v0.4.0] - 2020-01-30
4
+
5
+ ### Dependencies
6
+
7
+ - Updated `cose` from `v0.9.0` to `v0.11.0`
8
+
9
+ ## [v0.3.0] - 2019-09-02
10
+
11
+ ### Added
12
+
13
+ - `CWT.decode` can decode a MACed CWT
14
+
15
+ ## [v0.2.0] - 2019-08-31
16
+
17
+ ### Added
18
+
19
+ - `CWT.decode` can decode a signed CWT
20
+
21
+ [v0.4.0]: https://github.com/cedarcode/cwt-ruby/compare/v0.3.0...v0.4.0/
22
+ [v0.3.0]: https://github.com/cedarcode/cwt-ruby/compare/v0.2.0...v0.3.0/
23
+ [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,51 @@
1
+ # cwt-ruby
2
+
3
+ Ruby implementation of RFC [8392](https://tools.ietf.org/html/rfc8392) CBOR Web Token (CWT)
4
+
5
+ [![Gem](https://img.shields.io/gem/v/cwt.svg?style=flat-square&color=informational)](https://rubygems.org/gems/cwt)
6
+ [![Travis](https://img.shields.io/travis/cedarcode/cwt-ruby/master.svg?style=flat-square)](https://travis-ci.org/cedarcode/cwt-ruby)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'cwt'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install cwt
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ cwt = CWT.decode(data, cose_key)
28
+
29
+ # Read claims
30
+ cwt.iss
31
+ cwt.sub
32
+ cwt.aud
33
+ cwt.exp
34
+ cwt.nbf
35
+ cwt.iat
36
+ cwt.cti
37
+ ```
38
+
39
+ ## Development
40
+
41
+ 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.
42
+
43
+ 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).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cedarcode/cwt-ruby.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: [:rubocop, :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,45 @@
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.description = spec.summary
15
+ spec.homepage = "https://github.com/cedarcode/cwt-ruby"
16
+ spec.license = "MIT"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+ spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
21
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.required_ruby_version = ">= 2.4"
34
+
35
+ spec.add_dependency "cbor", "~> 0.5.9"
36
+ spec.add_dependency "cose", "~> 0.11.0"
37
+
38
+ spec.add_development_dependency "bundler", "~> 2.0"
39
+ spec.add_development_dependency "byebug", "~> 11.0"
40
+ spec.add_development_dependency "rake", "~> 13.0"
41
+ spec.add_development_dependency "rspec", "~> 3.8"
42
+ spec.add_development_dependency "rubocop", "~> 0.75.1"
43
+ spec.add_development_dependency "rubocop-performance", "~> 1.4"
44
+ spec.add_development_dependency "timecop", "~> 0.9.1"
45
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cbor"
4
+ require "cose/key"
5
+ require "cose/mac0"
6
+ require "cose/sign1"
7
+ require "cwt/claims_set"
8
+ require "cwt/version"
9
+
10
+ module CWT
11
+ class Error < StandardError; end
12
+
13
+ CBOR_TAG = 61
14
+
15
+ def self.decode(token, cose_key)
16
+ decoded = CBOR.decode(token)
17
+
18
+ case decoded.tag
19
+ when CBOR_TAG
20
+ decode(CBOR.encode(decoded.value), cose_key)
21
+ when COSE::Sign1.tag
22
+ key = COSE::Key.deserialize(cose_key)
23
+ sign1 = COSE::Sign1.deserialize(token)
24
+
25
+ if sign1.verify(key)
26
+ CWT::ClaimsSet.from_cbor(sign1.payload)
27
+ else
28
+ raise(CWT::Error, "Verification failed")
29
+ end
30
+ when COSE::Mac0.tag
31
+ key = COSE::Key.deserialize(cose_key)
32
+ mac0 = COSE::Mac0.deserialize(token)
33
+
34
+ if mac0.verify(key)
35
+ CWT::ClaimsSet.from_cbor(mac0.payload)
36
+ else
37
+ raise(CWT::Error, "Verification failed")
38
+ end
39
+ else
40
+ raise(CWT::Error, "Unsupported tag #{decoded.tag}")
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,51 @@
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
+
43
+ def expired?
44
+ Time.now >= expiration_time
45
+ end
46
+
47
+ def expiration_time
48
+ Time.at(exp)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CWT
4
+ VERSION = "0.4.0"
5
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cwt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Gonzalo Rodriguez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cbor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.9
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.9
27
+ - !ruby/object:Gem::Dependency
28
+ name: cose
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.11.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.11.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '11.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '11.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.75.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.75.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-performance
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.4'
125
+ - !ruby/object:Gem::Dependency
126
+ name: timecop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.9.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.9.1
139
+ description: Ruby implementation of RFC 8392 CBOR Web Token (CWT)
140
+ email:
141
+ - gonzalo@cedarcode.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".rubocop.yml"
149
+ - ".travis.yml"
150
+ - CHANGELOG.md
151
+ - Gemfile
152
+ - LICENSE.txt
153
+ - README.md
154
+ - Rakefile
155
+ - bin/console
156
+ - bin/setup
157
+ - cwt.gemspec
158
+ - lib/cwt.rb
159
+ - lib/cwt/claims_set.rb
160
+ - lib/cwt/version.rb
161
+ homepage: https://github.com/cedarcode/cwt-ruby
162
+ licenses:
163
+ - MIT
164
+ metadata:
165
+ homepage_uri: https://github.com/cedarcode/cwt-ruby
166
+ source_code_uri: https://github.com/cedarcode/cwt-ruby
167
+ bug_tracker_uri: https://github.com/cedarcode/cwt-ruby/issues
168
+ changelog_uri: https://github.com/cedarcode/cwt-ruby/blob/master/CHANGELOG.md
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '2.4'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubygems_version: 3.1.2
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: Ruby implementation of RFC 8392 CBOR Web Token (CWT)
188
+ test_files: []