cwt 0.1.0 → 0.2.0
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 +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +36 -0
- data/.travis.yml +5 -2
- data/CHANGELOG.md +3 -3
- data/Gemfile +2 -2
- data/LICENSE.txt +1 -1
- data/README.md +15 -6
- data/Rakefile +3 -1
- data/bin/console +1 -0
- data/cwt.gemspec +18 -7
- data/lib/cwt/claims_set.rb +43 -0
- data/lib/cwt/version.rb +3 -1
- data/lib/cwt.rb +15 -4
- metadata +64 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6870c9bcd5189270ba3e8a52322cb14db72a00e5a6997826b06cec285ffb5e91
|
4
|
+
data.tar.gz: 0c16ef24fb68ad2aa392c685817be3cefdd2d9e01573397d488b5aa0da05228b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8193d39b90ff7a7e5b3894726f8f3d1552591b66f017bc5d830db1f34b07431ae59b4d5fba9292ba979bc0b3a7f1ff2fd43ee28060e38f90788534c38509b690
|
7
|
+
data.tar.gz: 25e2cb0e949780342cf8310f502fa62a0981c2444521803183d7969329065323f03b145532305ca5ae42d3855697cbe68c41a2be9c927ff86e6f3dd384493669
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -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
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [
|
3
|
+
## [v0.2.0] - 2019-08-31
|
4
4
|
|
5
5
|
### Added
|
6
6
|
|
7
|
-
-
|
7
|
+
- `CWT.decode` can decode a signed CWT
|
8
8
|
|
9
|
-
[
|
9
|
+
[v0.2.0]: https://github.com/cedarcode/cwt-ruby/compare/9985bac0a1ffe5c5d4d3d7330a453b65f71a148f...v0.2.0/
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# cwt-ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Ruby implementation of RFC 8392 CBOR Web Token (CWT)
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,18 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
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
|
+
```
|
26
35
|
|
27
36
|
## Development
|
28
37
|
|
@@ -32,7 +41,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
41
|
|
33
42
|
## Contributing
|
34
43
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cedarcode/cwt-ruby.
|
36
45
|
|
37
46
|
## License
|
38
47
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/cwt.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require "cwt/version"
|
4
6
|
|
@@ -8,21 +10,30 @@ Gem::Specification.new do |spec|
|
|
8
10
|
spec.authors = ["Gonzalo Rodriguez"]
|
9
11
|
spec.email = ["gonzalo@cedarcode.com"]
|
10
12
|
|
11
|
-
spec.summary =
|
13
|
+
spec.summary = "Ruby implementation of RFC 8392 CBOR Web Token (CWT)"
|
14
|
+
spec.homepage = "https://github.com/cedarcode/cwt-ruby"
|
12
15
|
spec.license = "MIT"
|
13
16
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
20
|
+
|
14
21
|
# Specify which files should be added to the gem when it is released.
|
15
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
16
|
-
spec.files
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
24
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
25
|
end
|
26
|
+
|
19
27
|
spec.bindir = "exe"
|
20
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
29
|
spec.require_paths = ["lib"]
|
22
30
|
|
23
|
-
spec.
|
31
|
+
spec.add_dependency "cose", "~> 0.9.0"
|
24
32
|
|
25
|
-
spec.add_development_dependency "bundler", "~>
|
26
|
-
spec.add_development_dependency "
|
27
|
-
spec.add_development_dependency "
|
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"
|
28
39
|
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
|
data/lib/cwt/version.rb
CHANGED
data/lib/cwt.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cose/key"
|
4
|
+
require "cose/sign1"
|
5
|
+
require "cwt/claims_set"
|
1
6
|
require "cwt/version"
|
2
7
|
|
3
8
|
module CWT
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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")
|
8
19
|
end
|
9
20
|
end
|
10
21
|
end
|
metadata
CHANGED
@@ -1,71 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cwt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gonzalo Rodriguez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: cose
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.9.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.9.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
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'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '11.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '12.3'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '12.3'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
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'
|
62
104
|
type: :development
|
63
105
|
prerelease: false
|
64
106
|
version_requirements: !ruby/object:Gem::Requirement
|
65
107
|
requirements:
|
66
108
|
- - "~>"
|
67
109
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
110
|
+
version: '1.4'
|
69
111
|
description:
|
70
112
|
email:
|
71
113
|
- gonzalo@cedarcode.com
|
@@ -75,6 +117,7 @@ extra_rdoc_files: []
|
|
75
117
|
files:
|
76
118
|
- ".gitignore"
|
77
119
|
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
78
121
|
- ".travis.yml"
|
79
122
|
- CHANGELOG.md
|
80
123
|
- Gemfile
|
@@ -85,11 +128,15 @@ files:
|
|
85
128
|
- bin/setup
|
86
129
|
- cwt.gemspec
|
87
130
|
- lib/cwt.rb
|
131
|
+
- lib/cwt/claims_set.rb
|
88
132
|
- lib/cwt/version.rb
|
89
|
-
homepage:
|
133
|
+
homepage: https://github.com/cedarcode/cwt-ruby
|
90
134
|
licenses:
|
91
135
|
- MIT
|
92
|
-
metadata:
|
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
|
93
140
|
post_install_message:
|
94
141
|
rdoc_options: []
|
95
142
|
require_paths:
|
@@ -105,9 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
152
|
- !ruby/object:Gem::Version
|
106
153
|
version: '0'
|
107
154
|
requirements: []
|
108
|
-
|
109
|
-
rubygems_version: 2.7.7
|
155
|
+
rubygems_version: 3.0.6
|
110
156
|
signing_key:
|
111
157
|
specification_version: 4
|
112
|
-
summary:
|
158
|
+
summary: Ruby implementation of RFC 8392 CBOR Web Token (CWT)
|
113
159
|
test_files: []
|