json-jwt 0.3.0 → 0.3.1
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.
Potentially problematic release.
This version of json-jwt might be problematic. Click here for more details.
- data/VERSION +1 -1
- data/lib/json/jwk.rb +2 -2
- data/spec/json/jwk_spec.rb +37 -4
- data/spec/json/jwt_spec.rb +18 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/json/jwk.rb
CHANGED
@@ -41,7 +41,7 @@ module JSON
|
|
41
41
|
when OpenSSL::PKey::RSA
|
42
42
|
{
|
43
43
|
alg: :RSA,
|
44
|
-
|
44
|
+
xpo: UrlSafeBase64.encode64(public_key.e.to_s(2)),
|
45
45
|
mod: UrlSafeBase64.encode64(public_key.n.to_s(2))
|
46
46
|
}
|
47
47
|
when OpenSSL::PKey::EC
|
@@ -61,7 +61,7 @@ module JSON
|
|
61
61
|
def decode(jwk)
|
62
62
|
case jwk[:alg].to_s
|
63
63
|
when 'RSA'
|
64
|
-
exp = OpenSSL::BN.new UrlSafeBase64.decode64(jwk[:
|
64
|
+
exp = OpenSSL::BN.new UrlSafeBase64.decode64(jwk[:xpo]), 2
|
65
65
|
mod = OpenSSL::BN.new UrlSafeBase64.decode64(jwk[:mod]), 2
|
66
66
|
key = OpenSSL::PKey::RSA.new
|
67
67
|
key.e = exp
|
data/spec/json/jwk_spec.rb
CHANGED
@@ -3,9 +3,9 @@ require 'spec_helper'
|
|
3
3
|
describe JSON::JWK do
|
4
4
|
context 'when RSA public key given' do
|
5
5
|
let(:jwk) { JSON::JWK.new public_key }
|
6
|
-
it { jwk.should include :alg, :
|
6
|
+
it { jwk.should include :alg, :xpo, :mod }
|
7
7
|
its(:alg) { jwk[:alg].should == :RSA }
|
8
|
-
its(:
|
8
|
+
its(:xpo) { jwk[:xpo].should == UrlSafeBase64.encode64(public_key.e.to_s(2)) }
|
9
9
|
its(:mod) { jwk[:mod].should == UrlSafeBase64.encode64(public_key.n.to_s(2)) }
|
10
10
|
|
11
11
|
context 'when kid/use options given' do
|
@@ -68,10 +68,10 @@ describe JSON::JWK do
|
|
68
68
|
JSON::JWK.decode(
|
69
69
|
alg: :RSA,
|
70
70
|
mod: mod,
|
71
|
-
|
71
|
+
xpo: xpo
|
72
72
|
)
|
73
73
|
end
|
74
|
-
let(:
|
74
|
+
let(:xpo) { 'AQAB' }
|
75
75
|
let(:mod) { 'AK8ppaAGn6N3jDic2DhDN5mI5mWzvhfL1AFZOS9q2EBM8L5sjZbYiaHeNoKillZGmEF9a9g6Z20bDnoHTuHPsx93HYkZqPumFZ8K9lLCbqKAMWw2Qgk10RgrZ-kblJotTBCeer9-tZSWO-OWFzP4gp8MpSuQOQbwTJwDgEkFIQLUK2YgzWbn1PoW8xcfbVyWhZD880ELGRW6GhRgYAl0DN_EQS8kyUa0CusYCzOOg2W3-7qjYeojyP6jiOEr-eyjC7hcUvTVoTfz84BiZv72KS3i5JS8ZNNuRp5Ce51wjoDDUoNxDLWv6Da6qMaGpKz6NTSNbvhE_KFhpp4wf5yRQD8=' }
|
76
76
|
let(:pem) do
|
77
77
|
if RUBY_VERSION >= '1.9.3'
|
@@ -103,5 +103,38 @@ NrqoxoakrPo1NI1u+ET8oWGmnjB/nJFAPwIDAQAB
|
|
103
103
|
it { should be_instance_of OpenSSL::PKey::RSA }
|
104
104
|
its(:to_pem) { should == pem }
|
105
105
|
end
|
106
|
+
|
107
|
+
context 'when ECDSA' do
|
108
|
+
it do
|
109
|
+
expect do
|
110
|
+
JSON::JWK.decode(
|
111
|
+
alg: :EC,
|
112
|
+
crv: 'crv',
|
113
|
+
x: 'x',
|
114
|
+
y: 'y'
|
115
|
+
)
|
116
|
+
end.to raise_error NotImplementedError
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when invalid algorithm' do
|
121
|
+
it do
|
122
|
+
expect do
|
123
|
+
JSON::JWK.decode(
|
124
|
+
alg: :XXX
|
125
|
+
)
|
126
|
+
end.to raise_error JSON::JWK::UnknownAlgorithm
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'when no algorithm' do
|
131
|
+
it do
|
132
|
+
expect do
|
133
|
+
JSON::JWK.decode(
|
134
|
+
x: :x
|
135
|
+
)
|
136
|
+
end.to raise_error JSON::JWK::UnknownAlgorithm
|
137
|
+
end
|
138
|
+
end
|
106
139
|
end
|
107
140
|
end
|
data/spec/json/jwt_spec.rb
CHANGED
@@ -134,5 +134,23 @@ describe JSON::JWT do
|
|
134
134
|
end.to raise_error JSON::JWT::InvalidFormat
|
135
135
|
end
|
136
136
|
end
|
137
|
+
|
138
|
+
context 'when unexpected format' do
|
139
|
+
context 'when too few dots' do
|
140
|
+
it do
|
141
|
+
expect do
|
142
|
+
JSON::JWT.decode 'header'
|
143
|
+
end.to raise_error JSON::JWT::InvalidFormat
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when too many dots' do
|
148
|
+
it do
|
149
|
+
expect do
|
150
|
+
JSON::JWT.decode 'header.payload.signature.something.wrong'
|
151
|
+
end.to raise_error JSON::JWT::InvalidFormat
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
137
155
|
end
|
138
156
|
end
|
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.3.
|
4
|
+
version: 0.3.1
|
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-10-
|
12
|
+
date: 2012-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|