cwt 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc08b2ccb9b61d7e9ffd292da8e37211263caffb525ea113d82988d41cb82327
4
- data.tar.gz: 76246d7f2fd7a52256aaaf0a83e59c3b00464ef056c57b8cbd8b436ced963180
3
+ metadata.gz: 6870c9bcd5189270ba3e8a52322cb14db72a00e5a6997826b06cec285ffb5e91
4
+ data.tar.gz: 0c16ef24fb68ad2aa392c685817be3cefdd2d9e01573397d488b5aa0da05228b
5
5
  SHA512:
6
- metadata.gz: 495b1ec645639816439cc09e6e34f974a89e94205f97fce1868bee4f234d5073447a61f393275dba49ea22a91c83c9a8cef839855db7c029ba7d2b7c393f62d7
7
- data.tar.gz: bd93b9fd4666b106d2446d6d45cc7a3b4acd3f3a81a7552f8f07226e51a9dd7f8a37caa6fc761c4cc5f42ce9ef70089e0bd2c904b9ddd97c26b3d1728a1dcb08
6
+ metadata.gz: 8193d39b90ff7a7e5b3894726f8f3d1552591b66f017bc5d830db1f34b07431ae59b4d5fba9292ba979bc0b3a7f1ff2fd43ee28060e38f90788534c38509b690
7
+ data.tar.gz: 25e2cb0e949780342cf8310f502fa62a0981c2444521803183d7969329065323f03b145532305ca5ae42d3855697cbe68c41a2be9c927ff86e6f3dd384493669
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  .rspec_status
12
12
 
13
13
  /Gemfile.lock
14
+ /.byebug_history
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
@@ -1,5 +1,8 @@
1
+ ---
1
2
  sudo: false
2
3
  language: ruby
4
+ cache: bundler
3
5
  rvm:
4
- - 2.5.1
5
- before_install: gem install bundler -v 1.16.2
6
+ - 2.6.4
7
+ - 2.5.6
8
+ before_install: gem install bundler -v 2.0.2
data/CHANGELOG.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Changelog
2
2
 
3
- ## [Unreleased]
3
+ ## [v0.2.0] - 2019-08-31
4
4
 
5
5
  ### Added
6
6
 
7
- - Validates the token is a valid CBOR map
7
+ - `CWT.decode` can decode a signed CWT
8
8
 
9
- [Unreleased]: https://github.com/cedarcode/cwt-ruby/compare/5e30d7d10803ba0ba52c2a6638ddf0b889b9bb53...HEAD/
9
+ [v0.2.0]: https://github.com/cedarcode/cwt-ruby/compare/9985bac0a1ffe5c5d4d3d7330a453b65f71a148f...v0.2.0/
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in cwt.gemspec
6
6
  gemspec
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 Gonzalo
3
+ Copyright (c) 2019 Gonzalo Rodriguez
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # Cwt
1
+ # cwt-ruby
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cwt`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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/[USERNAME]/cwt.
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
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "cwt"
data/cwt.gemspec CHANGED
@@ -1,4 +1,6 @@
1
- lib = File.expand_path("../lib", __FILE__)
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 = %q{CWT in ruby}
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 = Dir.chdir(File.expand_path('..', __FILE__)) do
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.add_runtime_dependency "cbor"
31
+ spec.add_dependency "cose", "~> 0.9.0"
24
32
 
25
- spec.add_development_dependency "bundler", "~> 1.16"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "rspec", "~> 3.0"
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CWT
2
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
3
5
  end
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
- def self.validate(token)
5
- begin
6
- CBOR.decode(token)
7
- rescue
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.1.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: 2018-08-18 00:00:00.000000000 Z
11
+ date: 2019-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: cbor
14
+ name: cose
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
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: '0'
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: '1.16'
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: '1.16'
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: '10.0'
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: '10.0'
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.0'
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: '3.0'
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
- rubyforge_project:
109
- rubygems_version: 2.7.7
155
+ rubygems_version: 3.0.6
110
156
  signing_key:
111
157
  specification_version: 4
112
- summary: CWT in ruby
158
+ summary: Ruby implementation of RFC 8392 CBOR Web Token (CWT)
113
159
  test_files: []