json-jwt 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of json-jwt might be problematic. Click here for more details.

data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
data/lib/json/jwe.rb CHANGED
@@ -2,4 +2,4 @@ module JSON
2
2
  class JWE < JWT
3
3
  # TODO
4
4
  end
5
- end
5
+ end
data/lib/json/jwk.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module JSON
2
2
  class JWK < Hash
3
- class UnknownAlgorighm < JWT::Exception; end
3
+ class UnknownAlgorithm < JWT::Exception; end
4
4
 
5
5
  def initialize(public_key, options = {})
6
6
  replace encode(public_key, options)
@@ -17,7 +17,7 @@ module JSON
17
17
  when 'secp521r1'
18
18
  :'P-521'
19
19
  else
20
- raise UnknownAlgorighm.new('Unknown ECDSA Curve')
20
+ raise UnknownAlgorithm.new('Unknown ECDSA Curve')
21
21
  end
22
22
  end
23
23
 
@@ -40,23 +40,23 @@ module JSON
40
40
  hash = case public_key
41
41
  when OpenSSL::PKey::RSA
42
42
  {
43
- alg: :RSA,
44
- exp: UrlSafeBase64.encode64(public_key.e.to_s(2)),
45
- mod: UrlSafeBase64.encode64(public_key.n.to_s(2))
43
+ :alg => :RSA,
44
+ :exp => UrlSafeBase64.encode64(public_key.e.to_s(2)),
45
+ :mod => UrlSafeBase64.encode64(public_key.n.to_s(2))
46
46
  }
47
47
  when OpenSSL::PKey::EC
48
48
  {
49
- alg: :EC,
50
- crv: ecdsa_curve_name(public_key),
51
- x: UrlSafeBase64.encode64(ecdsa_coodinates(public_key)[:x].to_s),
52
- y: UrlSafeBase64.encode64(ecdsa_coodinates(public_key)[:y].to_s)
49
+ :alg => :EC,
50
+ :crv => ecdsa_curve_name(public_key),
51
+ :x => UrlSafeBase64.encode64(ecdsa_coodinates(public_key)[:x].to_s),
52
+ :y => UrlSafeBase64.encode64(ecdsa_coodinates(public_key)[:y].to_s)
53
53
  }
54
54
  else
55
- raise UnknownAlgorighm.new('Unknown Algorithm')
55
+ raise UnknownAlgorithm.new('Unknown Algorithm')
56
56
  end
57
57
  hash.merge(options)
58
58
  end
59
59
  end
60
60
  end
61
61
 
62
- require 'json/jwk/set'
62
+ require 'json/jwk/set'
data/lib/json/jws.rb CHANGED
@@ -105,4 +105,4 @@ module JSON
105
105
  self
106
106
  end
107
107
  end
108
- end
108
+ end
data/lib/json/jwt.rb CHANGED
@@ -10,7 +10,7 @@ module JSON
10
10
  class Exception < StandardError; end
11
11
  class InvalidFormat < Exception; end
12
12
  class VerificationFailed < Exception; end
13
- class UnexpectedAlgorighm < VerificationFailed; end
13
+ class UnexpectedAlgorithm < VerificationFailed; end
14
14
 
15
15
  def initialize(claims)
16
16
  @header = {
@@ -30,7 +30,7 @@ module JSON
30
30
 
31
31
  def verify(signature_base_string, signature = '', public_key_or_secret = nil)
32
32
  if header[:alg].to_s == 'none'
33
- raise UnexpectedAlgorighm if public_key_or_secret
33
+ raise UnexpectedAlgorithm if public_key_or_secret
34
34
  signature == '' or raise VerificationFailed
35
35
  else
36
36
  JWS.new(self).verify(signature_base_string, signature, public_key_or_secret)
@@ -48,16 +48,24 @@ module JSON
48
48
  end
49
49
 
50
50
  class << self
51
- def decode(jwt_string, public_key_or_secret = nil)
52
- raise InvalidFormat.new('Invalid JWT Format. JWT should include 2 dots.') unless jwt_string.count('.') == 2
53
- header, claims, signature = jwt_string.split('.', 3).collect do |segment|
54
- UrlSafeBase64.decode64 segment.to_s
51
+ def decode(jwt_string, key_or_secret = nil)
52
+ case jwt_string.count('.')
53
+ when 2 # JWT / JWS
54
+ header, claims, signature = jwt_string.split('.', 3).collect do |segment|
55
+ UrlSafeBase64.decode64 segment.to_s
56
+ end
57
+ signature_base_string = jwt_string.split('.')[0, 2].join('.')
58
+ jwt = new JSON.parse(claims, :symbolize_names => true)
59
+ jwt.header = JSON.parse(header, :symbolize_names => true)
60
+ jwt.verify signature_base_string, signature, key_or_secret
61
+ jwt
62
+ when 3 # JWE
63
+ # TODO: Concept code first.
64
+ # jwt = JWE.decrypt ...
65
+ # jwt.verify ...
66
+ else
67
+ raise InvalidFormat.new('Invalid JWT Format. JWT should include 2 or 3 dots.')
55
68
  end
56
- signature_base_string = jwt_string.split('.')[0, 2].join('.')
57
- jwt = new JSON.parse(claims, :symbolize_names => true)
58
- jwt.header = JSON.parse(header, :symbolize_names => true)
59
- jwt.verify signature_base_string, signature, public_key_or_secret
60
- jwt
61
69
  rescue JSON::ParserError
62
70
  raise InvalidFormat.new("Invalid JSON Format")
63
71
  end
@@ -67,4 +75,4 @@ end
67
75
 
68
76
  require 'json/jws'
69
77
  require 'json/jwe'
70
- require 'json/jwk'
78
+ require 'json/jwk'
@@ -48,7 +48,7 @@ describe JSON::JWK do
48
48
  key = OpenSSL::PKey::EC.new('secp112r2').generate_key
49
49
  expect do
50
50
  JSON::JWK.new key
51
- end.to raise_error JSON::JWK::UnknownAlgorighm, 'Unknown ECDSA Curve'
51
+ end.to raise_error JSON::JWK::UnknownAlgorithm, 'Unknown ECDSA Curve'
52
52
  end
53
53
  end
54
54
  end
@@ -58,7 +58,7 @@ describe JSON::JWK do
58
58
  key = OpenSSL::PKey::DSA.generate 256
59
59
  expect do
60
60
  JSON::JWK.new key
61
- end.to raise_error JSON::JWK::UnknownAlgorighm, 'Unknown Algorithm'
61
+ end.to raise_error JSON::JWK::UnknownAlgorithm, 'Unknown Algorithm'
62
62
  end
63
63
  end
64
- end
64
+ end
@@ -136,4 +136,4 @@ describe JSON::JWS do
136
136
  end
137
137
  end
138
138
  end
139
- end
139
+ end
@@ -49,7 +49,7 @@ describe JSON::JWT do
49
49
  it do
50
50
  expect do
51
51
  jwt.verify(no_signed, '', 'secret')
52
- end.to raise_error JSON::JWT::UnexpectedAlgorighm
52
+ end.to raise_error JSON::JWT::UnexpectedAlgorithm
53
53
  end
54
54
  end
55
55
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-jwt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-25 00:00:00.000000000 Z
12
+ date: 2012-08-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json