mobile_id 0.0.11 → 0.0.13
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +2 -2
- data/lib/mobile_id/auth.rb +18 -5
- data/lib/mobile_id/cert.rb +17 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23c0f87295e5303fe359317d68393e1c9cb50f8ba1d51030edb01f6d9aed12c9
|
4
|
+
data.tar.gz: 02efb290beb29fcc719fe2b9a291fbd5590426f681835949630ae977e2167055
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4223ca81fabe81ad3bacad29f1a7ea9026f797f619fb2bdd7f1ae4d1c15f931e61cb47e6dc6eb49f18b2b4293760b5fb324cddefb6c35b4b659ca2d05926e6f
|
7
|
+
data.tar.gz: f21c96ae471cfeff68341e19b3a83bed6ae4ba6b62262a8cb174e5f65f59bc4aeff114beb14638fad093a7ef59af0d983a42bdb29ac0bff061dae32fc95d85f2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -112,7 +112,8 @@ After checking out the repo, run `bundle` to install dependencies. For testing c
|
|
112
112
|
## Contributors
|
113
113
|
|
114
114
|
* Priit Tark
|
115
|
-
* Andri Möll for pointing out user signature issue
|
115
|
+
* Andri Möll for pointing out user signature issue and cert date check
|
116
|
+
* Juri Linkov for pointing out unpack method issue and test friendly init
|
116
117
|
|
117
118
|
## Contributing
|
118
119
|
|
@@ -120,7 +121,6 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/gitlab
|
|
120
121
|
|
121
122
|
## Roadmap
|
122
123
|
|
123
|
-
* Auth signature validation
|
124
124
|
* Document sign
|
125
125
|
* Rails generators
|
126
126
|
|
data/lib/mobile_id/auth.rb
CHANGED
@@ -11,12 +11,12 @@ module MobileId
|
|
11
11
|
|
12
12
|
attr_accessor :url, :uuid, :name, :doc, :hash, :user_cert, :live
|
13
13
|
|
14
|
-
def initialize(live:, uuid: nil, name: nil)
|
14
|
+
def initialize(live:, uuid: nil, name: nil, doc: nil)
|
15
15
|
self.url = live == true ? LIVE_URL : TEST_URL
|
16
16
|
self.uuid = live == true ? uuid : TEST_UUID
|
17
17
|
self.name = live == true ? name : TEST_NAME
|
18
18
|
self.live = live
|
19
|
-
init_doc(SecureRandom.hex(40))
|
19
|
+
init_doc(doc || SecureRandom.hex(40))
|
20
20
|
end
|
21
21
|
|
22
22
|
def init_doc(doc)
|
@@ -82,11 +82,24 @@ module MobileId
|
|
82
82
|
)
|
83
83
|
end
|
84
84
|
|
85
|
-
def
|
85
|
+
def session_request(session_id)
|
86
86
|
response = HTTParty.get(url + "/authentication/session/#{session_id}")
|
87
87
|
raise Error, "#{I18n.t('mobile_id.some_error')} #{response.code} #{response}" if response.code != 200
|
88
|
+
response
|
89
|
+
end
|
90
|
+
|
91
|
+
def long_poll!(session_id:, doc:)
|
92
|
+
response = nil
|
93
|
+
|
94
|
+
# Retries until RUNNING state turns to COMPLETE
|
95
|
+
30.times do |i|
|
96
|
+
response = session_request(session_id)
|
97
|
+
break if response['state'] == 'COMPLETE'
|
98
|
+
sleep 1
|
99
|
+
end
|
100
|
+
raise Error, "#{I18n.t('mobile_id.some_error')} #{response.code} #{response}" if response['state'] != 'COMPLETE'
|
88
101
|
|
89
|
-
if response['
|
102
|
+
if response['result'] != 'OK'
|
90
103
|
message =
|
91
104
|
case response['result']
|
92
105
|
when "TIMEOUT"
|
@@ -104,7 +117,7 @@ module MobileId
|
|
104
117
|
when "SIM_ERROR"
|
105
118
|
I18n.t('mobile_id.sim_error')
|
106
119
|
end
|
107
|
-
|
120
|
+
raise Error, message
|
108
121
|
end
|
109
122
|
|
110
123
|
@user_cert = MobileId::Cert.new(response['cert'], live: live)
|
data/lib/mobile_id/cert.rb
CHANGED
@@ -56,7 +56,7 @@ module MobileId
|
|
56
56
|
end
|
57
57
|
|
58
58
|
raise Error, 'User certificate is not valid [check_key]' unless cert.public_key.check_key
|
59
|
-
raise Error, 'User certificate is expired' unless (cert.not_before
|
59
|
+
raise Error, 'User certificate is expired' unless (cert.not_before...cert.not_after) === Time.now
|
60
60
|
|
61
61
|
true
|
62
62
|
end
|
@@ -65,10 +65,23 @@ module MobileId
|
|
65
65
|
signature = Base64.decode64(signature_base64)
|
66
66
|
digest = OpenSSL::Digest::SHA256.new(doc)
|
67
67
|
|
68
|
-
|
68
|
+
valid =
|
69
|
+
begin
|
70
|
+
cert.public_key.verify(digest, signature, doc)
|
71
|
+
rescue OpenSSL::PKey::PKeyError
|
72
|
+
der_signature = cvc_to_der(signature) # Probably signature is CVC encoded
|
73
|
+
cert.public_key.verify(digest, der_signature, doc)
|
74
|
+
end
|
69
75
|
|
70
|
-
|
71
|
-
|
76
|
+
raise Error, 'We could not verify user signature' unless valid
|
77
|
+
end
|
78
|
+
|
79
|
+
def cvc_to_der(cvc)
|
80
|
+
sign_hex = cvc.unpack('H*').first
|
81
|
+
half = sign_hex.size / 2
|
82
|
+
i = [OpenSSL::ASN1::Integer.new(sign_hex[0...half].to_i(16)), OpenSSL::ASN1::Integer.new(sign_hex[half..sign_hex.size].to_i(16))]
|
83
|
+
seq = OpenSSL::ASN1::Sequence.new(i)
|
84
|
+
seq.to_der
|
72
85
|
end
|
73
86
|
|
74
87
|
def given_name
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobile_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Priit Tark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
146
|
+
rubygems_version: 3.4.10
|
147
147
|
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: Estonia Mobile ID authentication
|