sandal 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sandal/enc/aescbc.rb +2 -2
- data/lib/sandal/sig/es.rb +14 -9
- data/lib/sandal/sig/hs.rb +1 -1
- data/lib/sandal/sig/rs.rb +1 -1
- data/lib/sandal/version.rb +1 -1
- metadata +2 -2
data/lib/sandal/enc/aescbc.rb
CHANGED
@@ -14,9 +14,9 @@ module Sandal
|
|
14
14
|
@sha_size = aes_size * 2 # TODO: Any smarter way to do this?
|
15
15
|
@name = "A#{aes_size}CBC+HS#{@sha_size}"
|
16
16
|
@alg_name = "RSA1_5" # TODO: From key?
|
17
|
-
@cipher_name = "
|
17
|
+
@cipher_name = "aes-#{aes_size}-cbc"
|
18
18
|
@key = key
|
19
|
-
@digest = OpenSSL::Digest.new("
|
19
|
+
@digest = OpenSSL::Digest.new("sha#{@sha_size}")
|
20
20
|
end
|
21
21
|
|
22
22
|
def encrypt(header, payload)
|
data/lib/sandal/sig/es.rb
CHANGED
@@ -11,7 +11,7 @@ module Sandal
|
|
11
11
|
def initialize(sha_size, key)
|
12
12
|
throw ArgumentError.new('A key is required.') unless key
|
13
13
|
@name = "ES#{sha_size}"
|
14
|
-
@digest = OpenSSL::Digest.new("
|
14
|
+
@digest = OpenSSL::Digest.new("sha#{sha_size}")
|
15
15
|
@key = key
|
16
16
|
end
|
17
17
|
|
@@ -28,7 +28,7 @@ module Sandal
|
|
28
28
|
hash = @digest.digest(payload)
|
29
29
|
r, s = self.class.decode_jws_signature(signature)
|
30
30
|
asn1_sig = self.class.encode_asn1_signature(r, s)
|
31
|
-
@key.dsa_verify_asn1(hash, asn1_sig)
|
31
|
+
result = @key.dsa_verify_asn1(hash, asn1_sig)
|
32
32
|
end
|
33
33
|
|
34
34
|
# Decodes an ASN1 signature into a pair of BNs.
|
@@ -45,17 +45,22 @@ module Sandal
|
|
45
45
|
|
46
46
|
# Decodes a JWS signature into a pair of BNs.
|
47
47
|
def self.decode_jws_signature(signature)
|
48
|
-
|
49
|
-
coord_length =
|
50
|
-
r = OpenSSL::BN.new(
|
51
|
-
s = OpenSSL::BN.new(
|
48
|
+
binary_string = Sandal::Util.base64_decode(signature)
|
49
|
+
coord_length = binary_string.length / 2
|
50
|
+
r = OpenSSL::BN.new(binary_string[0..(coord_length - 1)].unpack('H*')[0], 16)
|
51
|
+
s = OpenSSL::BN.new(binary_string[coord_length..-1].unpack('H*')[0], 16)
|
52
52
|
return r, s
|
53
53
|
end
|
54
54
|
|
55
55
|
# Encodes a pair of BNs into a JWS signature.
|
56
|
-
def self.encode_jws_signature(r, s)
|
57
|
-
|
58
|
-
|
56
|
+
def self.encode_jws_signature(r, s)
|
57
|
+
# TODO: Is there a better way to convert these to a binary string?
|
58
|
+
r_str = [r.to_s(16)].pack('H*')
|
59
|
+
r_str = "\x00" + r_str if r_str.length % 2 != 0
|
60
|
+
s_str = [s.to_s(16)].pack('H*')
|
61
|
+
s_str = "\x00" + s_str if s_str.length % 2 != 0
|
62
|
+
binary_string = r_str + s_str
|
63
|
+
Sandal::Util.base64_encode(binary_string)
|
59
64
|
end
|
60
65
|
|
61
66
|
end
|
data/lib/sandal/sig/hs.rb
CHANGED
data/lib/sandal/sig/rs.rb
CHANGED
data/lib/sandal/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sandal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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: 2013-03-
|
12
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A ruby library for creating and reading JSON Web Tokens (JWT), supporting
|
15
15
|
JSON Web Signatures (JWS) and JSON Web Encryption (JWE).
|