paseto 0.3.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '097f41395926bd3e366dc693db7b1d488128bcdad615776bf14263ea79d2814a'
4
- data.tar.gz: 0ddabba5cd16bfac6dce3ac474af223d336564280b94f5647fc25f27b1a32c5d
3
+ metadata.gz: b97852d5f74f9beb557884c9a46eb912fc3552400474dc7c35dbbbacedead44a
4
+ data.tar.gz: e137a333a093be64c3ae218fa1884043bc61c8d3f585b8933ff777ab77a3269f
5
5
  SHA512:
6
- metadata.gz: 9876adbdd0432b13825a357f9f3a1226048461b68dd3b9f8b71e43821dfd9114050ec131b5481ae4d6afb9410396a427d8f56d195f64b7825fb218abf74f1ea1
7
- data.tar.gz: 363c81182b427a2d352ca09abf43aa0089c6bf90033ecb3dcbabccebfccdd8cf984e5531eb1ff9143db45035a83fd7f0d26163593dc0c1a86d1a5b406dd22dbd
6
+ metadata.gz: 28bdd43cb3e66b9566f9d71ffadfb6ff25b3ac47b569c51d6b2aa78af1e151e7e54f2f0508235da929e636897f62d88eee45a553675242a3d6f32976531fd197
7
+ data.tar.gz: '098f57dd56ff3468b62d14123e7ac56de4928ca8d81a88b5cced5a42ca92e4069c87f2cf70f9924a32c8365fe366c4250b80da9c2490623af9afc5b39bc2cd43'
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  /.bundle/
2
+ Gemfile.lock
2
3
  /.yardoc
3
4
  /_yardoc/
4
5
  /coverage/
data/.rubocop.yml ADDED
@@ -0,0 +1,38 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.3
5
+
6
+ Layout/MultilineMethodCallIndentation:
7
+ EnforcedStyle: indented
8
+
9
+ Metrics/LineLength:
10
+ Max: 100
11
+ Exclude:
12
+ - "spec/**/*.rb"
13
+
14
+ Metrics/AbcSize:
15
+ Max: 25
16
+
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - "spec/**/*.rb"
20
+
21
+ Metrics/MethodLength:
22
+ Max: 30
23
+
24
+ RSpec/ExampleLength:
25
+ Max: 10
26
+
27
+ RSpec/MessageSpies:
28
+ Enabled: false
29
+
30
+ RSpec/VerifiedDoubles:
31
+ Enabled: false
32
+
33
+ Security/Eval:
34
+ Exclude:
35
+ - "spec/**/*.rb"
36
+
37
+ Style/MultilineBlockChain:
38
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,9 +1,16 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.3.8
4
- - 2.4.5
5
- - 2.5.3
4
+ - 2.4.9
5
+ - 2.5.5
6
+ - 2.6.5
7
+ - 2.7.0
6
8
  dist: xenial
7
9
  before_install:
8
10
  - scripts/build-libsodium
9
- - gem install bundler -v 1.16.1
11
+ script:
12
+ - bundle exec rspec
13
+ - bundle exec rubocop
14
+ cache: bundler
15
+ env:
16
+ - CODECOV=true
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ ## Paseto.rb Changelog
2
+
3
+ ### 0.4 (Mar 7, 2020)
4
+
5
+ - Update rbnacl and fix warning [<a href="https://github.com/mguymon/paseto.rb/pull/10">Pull #10</a> by <a href="https://github.com/shaicoleman">shaicoleman</a>]
6
+ - Codecov and Travis support
7
+ - Rubocop is the law :oncoming_police_car:
8
+ - Update rake to fix vulnerability CVE-2020-8130
9
+
10
+ ### 0.3 (Dec 4, 2018)
11
+
12
+ - Use rbnacl instead of rbnacl-libsodium [<a href="https://github.com/mguymon/paseto.rb/pull/6">Pull #3</a> by <a href="https://github.com/smaximov">smaximov</a>]
13
+
14
+ - Update docs
15
+
16
+ #### 0.3.1 (Feb 16, 2019)
17
+
18
+ - Fix PAE [<a href="https://github.com/mguymon/paseto.rb/pull/6">Pull #6</a> by <a href="https://github.com/smaximov">smaximov</a>]
19
+ - Fix spec names [<a href="https://github.com/mguymon/paseto.rb/pull/5">Pull #5</a> by <a href="https://github.com/smaximov">smaximov</a>]
20
+ - Clean up links in docs
21
+
22
+ ### Start of the Universe
data/Gemfile CHANGED
@@ -1,6 +1,10 @@
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
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in paseto.gemspec
6
8
  gemspec
9
+
10
+ gem 'codecov', require: false, group: :test
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
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,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "paseto"
4
+ require 'bundler/setup'
5
+ require 'paseto'
5
6
  require 'pry'
6
7
 
7
8
  # You can add fixtures and/or initialization code here to make experimenting
data/lib/paseto.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
  require 'rbnacl'
3
5
 
@@ -7,15 +9,16 @@ require 'paseto/token'
7
9
  require 'paseto/public'
8
10
  require 'paseto/local'
9
11
 
12
+ # Platform-Agnostic SEcurity TOkens
10
13
  module Paseto
11
- EMPTY_FOOTER = ''.freeze
14
+ EMPTY_FOOTER = ''
12
15
 
13
16
  # An Array#pack format to pack an unsigned little-endian 64-bit integer
14
- UNSIGNED_LITTLE_64 = 'Q<'.freeze
17
+ UNSIGNED_LITTLE_64 = 'Q<'
15
18
 
16
19
  # https://github.com/paragonie/paseto/blob/master/docs/01-Protocol-Versions/Common.md#pae-definition
17
- def self.encode_length(n)
18
- [n].pack(UNSIGNED_LITTLE_64)
20
+ def self.encode_length(num)
21
+ [num].pack(UNSIGNED_LITTLE_64)
19
22
  end
20
23
 
21
24
  # https://github.com/paragonie/paseto/blob/master/docs/01-Protocol-Versions/Common.md#pae-definition
@@ -23,8 +26,7 @@ module Paseto
23
26
  initial_output = encode_length(pieces.length)
24
27
 
25
28
  pieces.reduce(initial_output) do |output, piece|
26
- output += encode_length(piece.length)
27
- output += piece
29
+ output + encode_length(piece.length) + piece
28
30
  end
29
31
  end
30
32
 
data/lib/paseto/error.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Paseto
2
4
  Error = Class.new(StandardError)
3
5
  HeaderError = Class.new(Error)
data/lib/paseto/local.rb CHANGED
@@ -1,11 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Paseto
2
4
  module V2
5
+ # Symmetric Encryption
3
6
  module Local
4
7
  HEADER = 'v2.local'
5
8
  NONCE_BYTES = RbNaCl::AEAD::XChaCha20Poly1305IETF.nonce_bytes
6
9
 
7
10
  NonceError = Class.new(Paseto::Error)
8
11
 
12
+ # Encryption key
9
13
  class Key
10
14
  def self.generate
11
15
  new(RbNaCl::Random.random_bytes(RbNaCl::AEAD::XChaCha20Poly1305IETF.key_bytes))
@@ -43,7 +47,7 @@ module Paseto
43
47
  nonce = parsed.payload[0, NONCE_BYTES]
44
48
  ciphertext = parsed.payload[NONCE_BYTES..-1]
45
49
 
46
- raise BadMessageError.new('Unable to process message') if nonce.nil? || ciphertext.nil?
50
+ raise BadMessageError, 'Unable to process message' if nonce.nil? || ciphertext.nil?
47
51
 
48
52
  begin
49
53
  data = additional_data(nonce, footer)
@@ -52,7 +56,7 @@ module Paseto
52
56
  raise NonceError, 'Invalid nonce'
53
57
  rescue RbNaCl::CryptoError
54
58
  raise AuthenticationError, 'Token signature invalid'
55
- rescue
59
+ rescue StandardError
56
60
  raise TokenError, 'Unable to process message'
57
61
  end
58
62
  end
data/lib/paseto/public.rb CHANGED
@@ -1,17 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Paseto
2
4
  module V2
5
+ # Asymmetric Authentication (Public-Key Signatures)
3
6
  module Public
4
7
  HEADER = 'v2.public'
5
8
  SIGNATURE_BYTES = RbNaCl::SigningKey.signature_bytes
6
9
  BadMessageError = Class.new(Paseto::Error)
7
10
 
11
+ # Encode a message + footer in a Paseto payload
8
12
  module Encoder
9
13
  private
14
+
10
15
  def encode_message(message, footer)
11
16
  Paseto.pre_auth_encode(HEADER + '.', message, footer)
12
17
  end
13
18
  end
14
19
 
20
+ # secret-key used for signing and verifing
15
21
  class SecretKey
16
22
  include Encoder
17
23
 
@@ -49,6 +55,7 @@ module Paseto
49
55
  end
50
56
  end
51
57
 
58
+ # public-key used for signing and verifing
52
59
  class PublicKey
53
60
  include Encoder
54
61
 
@@ -74,14 +81,16 @@ module Paseto
74
81
  decoded_message = parsed.payload[0..-(SIGNATURE_BYTES + 1)]
75
82
  signature = parsed.payload[-SIGNATURE_BYTES..-1]
76
83
 
77
- raise BadMessageError.new('Unable to process message') if decoded_message.nil? || signature.nil?
84
+ if decoded_message.nil? || signature.nil?
85
+ raise BadMessageError, 'Unable to process message'
86
+ end
78
87
 
79
88
  begin
80
89
  data = encode_message(decoded_message, footer)
81
90
  @nacl.verify(signature, data)
82
91
  decoded_message
83
92
  rescue RbNaCl::BadSignatureError
84
- raise AuthenticationError.new('Token signature invalid')
93
+ raise AuthenticationError, 'Token signature invalid'
85
94
  end
86
95
  end
87
96
  end
data/lib/paseto/token.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Helper for verifying and parsing tokens
1
4
  module Paseto
2
5
  Token = Struct.new(:header, :payload, :footer) do
3
6
  def to_message
@@ -14,12 +17,10 @@ module Paseto
14
17
 
15
18
  def self.verify_token(token, expected_header, expected_footer)
16
19
  token = parse(token) unless token.is_a? Token
17
- if token.header != expected_header
18
- raise HeaderError.new("Invalid message header: #{token.header}")
19
- end
20
+ raise HeaderError, "Invalid message header: #{token.header}" if token.header != expected_header
20
21
 
21
22
  if token.footer != expected_footer
22
- raise TokenError.new("Invalid message footer: #{token.footer.inspect}")
23
+ raise TokenError, "Invalid message footer: #{token.footer.inspect}"
23
24
  end
24
25
 
25
26
  token
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Paseto
2
- VERSION = "0.3.1"
4
+ VERSION = '0.4.0'
3
5
  end
data/paseto.gemspec CHANGED
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'paseto/version'
5
6
 
@@ -9,8 +10,8 @@ Gem::Specification.new do |spec|
9
10
  spec.authors = ['Michael Guymon', 'Frank Murphy']
10
11
  spec.email = ['mguymon@instructure.com', 'fmurphy@instructure.com']
11
12
 
12
- spec.summary = %q{Ruby impl of Paseto}
13
- spec.description = %q{Ruby impl of Paseto}
13
+ spec.summary = 'Ruby impl of Paseto'
14
+ spec.description = 'Ruby impl of Paseto'
14
15
  spec.homepage = 'https://github.com/mguymon/paseto.rb'
15
16
  spec.license = 'MIT'
16
17
 
@@ -20,10 +21,13 @@ Gem::Specification.new do |spec|
20
21
  spec.bindir = 'bin'
21
22
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
23
  spec.require_paths = ['lib']
24
+ spec.required_ruby_version = '>= 2.3.0'
23
25
 
24
- spec.add_dependency 'rbnacl', '~> 6.0'
25
- spec.add_development_dependency 'bundler', '~> 1.16'
26
- spec.add_development_dependency 'rake', '~> 10.0'
27
- spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_dependency 'rbnacl', '>= 7.1.1'
27
+ spec.add_development_dependency 'bundler'
28
28
  spec.add_development_dependency 'pry', '~> 0.11'
29
+ spec.add_development_dependency 'rake', '>= 12.3.3'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'rubocop', '~> 0.65.0'
32
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.32.0'
29
33
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  set -e
4
4
 
5
- wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.16.tar.gz
6
- tar -zxf libsodium-1.0.16.tar.gz
7
- cd libsodium-1.0.16
5
+ wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz
6
+ tar -zxf libsodium-1.0.18.tar.gz
7
+ cd libsodium-1.0.18
8
8
  ./configure
9
9
  make
10
10
  sudo make install
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paseto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Guymon
@@ -9,50 +9,64 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-02-19 00:00:00.000000000 Z
12
+ date: 2020-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rbnacl
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '6.0'
20
+ version: 7.1.1
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '6.0'
27
+ version: 7.1.1
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: pry
30
44
  requirement: !ruby/object:Gem::Requirement
31
45
  requirements:
32
46
  - - "~>"
33
47
  - !ruby/object:Gem::Version
34
- version: '1.16'
48
+ version: '0.11'
35
49
  type: :development
36
50
  prerelease: false
37
51
  version_requirements: !ruby/object:Gem::Requirement
38
52
  requirements:
39
53
  - - "~>"
40
54
  - !ruby/object:Gem::Version
41
- version: '1.16'
55
+ version: '0.11'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: rake
44
58
  requirement: !ruby/object:Gem::Requirement
45
59
  requirements:
46
- - - "~>"
60
+ - - ">="
47
61
  - !ruby/object:Gem::Version
48
- version: '10.0'
62
+ version: 12.3.3
49
63
  type: :development
50
64
  prerelease: false
51
65
  version_requirements: !ruby/object:Gem::Requirement
52
66
  requirements:
53
- - - "~>"
67
+ - - ">="
54
68
  - !ruby/object:Gem::Version
55
- version: '10.0'
69
+ version: 12.3.3
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: rspec
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -68,19 +82,33 @@ dependencies:
68
82
  - !ruby/object:Gem::Version
69
83
  version: '3.0'
70
84
  - !ruby/object:Gem::Dependency
71
- name: pry
85
+ name: rubocop
72
86
  requirement: !ruby/object:Gem::Requirement
73
87
  requirements:
74
88
  - - "~>"
75
89
  - !ruby/object:Gem::Version
76
- version: '0.11'
90
+ version: 0.65.0
77
91
  type: :development
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
95
  - - "~>"
82
96
  - !ruby/object:Gem::Version
83
- version: '0.11'
97
+ version: 0.65.0
98
+ - !ruby/object:Gem::Dependency
99
+ name: rubocop-rspec
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 1.32.0
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 1.32.0
84
112
  description: Ruby impl of Paseto
85
113
  email:
86
114
  - mguymon@instructure.com
@@ -93,10 +121,11 @@ extra_rdoc_files: []
93
121
  files:
94
122
  - ".gitignore"
95
123
  - ".rspec"
124
+ - ".rubocop.yml"
96
125
  - ".travis.yml"
126
+ - CHANGELOG.md
97
127
  - CODE_OF_CONDUCT.md
98
128
  - Gemfile
99
- - Gemfile.lock
100
129
  - LICENSE.txt
101
130
  - README.md
102
131
  - Rakefile
@@ -122,15 +151,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
151
  requirements:
123
152
  - - ">="
124
153
  - !ruby/object:Gem::Version
125
- version: '0'
154
+ version: 2.3.0
126
155
  required_rubygems_version: !ruby/object:Gem::Requirement
127
156
  requirements:
128
157
  - - ">="
129
158
  - !ruby/object:Gem::Version
130
159
  version: '0'
131
160
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 2.7.6
161
+ rubygems_version: 3.1.2
134
162
  signing_key:
135
163
  specification_version: 4
136
164
  summary: Ruby impl of Paseto
data/Gemfile.lock DELETED
@@ -1,45 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- paseto (0.3.0)
5
- rbnacl (~> 6.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- coderay (1.1.2)
11
- diff-lcs (1.3)
12
- ffi (1.9.25)
13
- method_source (0.9.0)
14
- pry (0.11.3)
15
- coderay (~> 1.1.0)
16
- method_source (~> 0.9.0)
17
- rake (10.5.0)
18
- rbnacl (6.0.0)
19
- ffi
20
- rspec (3.7.0)
21
- rspec-core (~> 3.7.0)
22
- rspec-expectations (~> 3.7.0)
23
- rspec-mocks (~> 3.7.0)
24
- rspec-core (3.7.1)
25
- rspec-support (~> 3.7.0)
26
- rspec-expectations (3.7.0)
27
- diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.7.0)
29
- rspec-mocks (3.7.0)
30
- diff-lcs (>= 1.2.0, < 2.0)
31
- rspec-support (~> 3.7.0)
32
- rspec-support (3.7.1)
33
-
34
- PLATFORMS
35
- ruby
36
-
37
- DEPENDENCIES
38
- bundler (~> 1.16)
39
- paseto!
40
- pry (~> 0.11)
41
- rake (~> 10.0)
42
- rspec (~> 3.0)
43
-
44
- BUNDLED WITH
45
- 1.16.3