mobile_id 0.0.13 → 0.0.15

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: 23c0f87295e5303fe359317d68393e1c9cb50f8ba1d51030edb01f6d9aed12c9
4
- data.tar.gz: 02efb290beb29fcc719fe2b9a291fbd5590426f681835949630ae977e2167055
3
+ metadata.gz: 471b24920bcc581ae61b62629bf81b1bb9d7714b5a8fb56c35be92da0b1f813f
4
+ data.tar.gz: 4bc0e35fd965c21485113fef8f40cb3607a01c4b5f2ad01d09ef7a934d580e7d
5
5
  SHA512:
6
- metadata.gz: f4223ca81fabe81ad3bacad29f1a7ea9026f797f619fb2bdd7f1ae4d1c15f931e61cb47e6dc6eb49f18b2b4293760b5fb324cddefb6c35b4b659ca2d05926e6f
7
- data.tar.gz: f21c96ae471cfeff68341e19b3a83bed6ae4ba6b62262a8cb174e5f65f59bc4aeff114beb14638fad093a7ef59af0d983a42bdb29ac0bff061dae32fc95d85f2
6
+ metadata.gz: 7137ef520eddcacc1855dc6dbf4a2e18dddbc35c389d0ff95eac8e4d8832a1fa775db99650ff7ac350044ceef5c09bb789a802610f5c86c7f27cac000768f668
7
+ data.tar.gz: 3f5daa9b2b7fdc2fd97080af483c3a9ab20f5b43222087a8e3bbb109b61af2957501b686ed1032e1dee5156b8a4ff9024788f74ad5bb43ecea0a1983022ed4ef
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
+ Release 0.0.15
2
+ * Restored older Ruby 2.7 support
3
+
4
+ Release 0.0.14
5
+ * Added LT locale with locale init update (thanks Mijora)
6
+ * Init rubocop (thanks Thales Ribeiro)
7
+
1
8
  Release 0.0.13
2
- * More test friendly init
3
- * More precise sert check
9
+ * Gems updated to latest
10
+ * More test friendly init (thanks Juri Linkov)
11
+ * More precise sert check (thanks Andri Möll)
4
12
 
5
13
  Release 0.0.12
6
14
  * Supports session RUNNING state
data/README.md CHANGED
@@ -114,10 +114,12 @@ After checking out the repo, run `bundle` to install dependencies. For testing c
114
114
  * Priit Tark
115
115
  * Andri Möll for pointing out user signature issue and cert date check
116
116
  * Juri Linkov for pointing out unpack method issue and test friendly init
117
+ * Thales Ribeiro for rubocop initial
118
+ * Mijora for LT locale
117
119
 
118
120
  ## Contributing
119
121
 
120
- Bug reports and pull requests are welcome on GitHub at https://github.com/gitlabeu/mobile_id
122
+ Bug reports and pull requests are welcome on GitHub at https://github.com/domify/mobile_id
121
123
 
122
124
  ## Roadmap
123
125
 
@@ -130,4 +132,4 @@ The gem is available as open source under the terms of the [MIT License](http://
130
132
 
131
133
  ## Sponsors
132
134
 
133
- Gem development and testing is sponsored by [GiTLAB](https://gitlab.eu).
135
+ Gem development and testing is sponsored by [Domify](https://domify.io).
@@ -3,11 +3,11 @@
3
3
  module MobileId
4
4
  class Auth
5
5
  # API documentation https://github.com/SK-EID/MID
6
- LIVE_URL = "https://mid.sk.ee/mid-api"
7
- TEST_URL = "https://tsp.demo.sk.ee/mid-api"
6
+ LIVE_URL = 'https://mid.sk.ee/mid-api'
7
+ TEST_URL = 'https://tsp.demo.sk.ee/mid-api'
8
8
 
9
- TEST_UUID = "00000000-0000-0000-0000-000000000000"
10
- TEST_NAME = "DEMO"
9
+ TEST_UUID = '00000000-0000-0000-0000-000000000000'
10
+ TEST_NAME = 'DEMO'
11
11
 
12
12
  attr_accessor :url, :uuid, :name, :doc, :hash, :user_cert, :live
13
13
 
@@ -24,25 +24,25 @@ module MobileId
24
24
  self.hash = Digest::SHA256.digest(doc)
25
25
  end
26
26
 
27
- def authenticate!(phone_calling_code: nil, phone:, personal_code:, language: nil, display_text: nil)
27
+ def authenticate!(phone:, personal_code:, phone_calling_code: nil, language: nil, display_text: nil)
28
28
  phone_calling_code ||= '+372'
29
29
  full_phone = "#{phone_calling_code}#{phone}"
30
- language ||=
30
+ language ||=
31
31
  case I18n.locale
32
32
  when :et
33
- display_text ||= 'Autentimine'
33
+ display_text ||= 'Autentimine'
34
34
  'EST'
35
35
  when :ru
36
- display_text ||= 'Аутентификация'
36
+ display_text ||= 'Аутентификация'
37
37
  'RUS'
38
38
  else
39
- display_text ||= 'Authentication'
39
+ display_text ||= 'Authentication'
40
40
  'ENG'
41
41
  end
42
-
42
+
43
43
  options = {
44
44
  headers: {
45
- "Content-Type": "application/json"
45
+ 'Content-Type': 'application/json'
46
46
  },
47
47
  query: {},
48
48
  body: {
@@ -58,7 +58,7 @@ module MobileId
58
58
  }.to_json
59
59
  }
60
60
 
61
- response = HTTParty.post(url + '/authentication', options)
61
+ response = HTTParty.post("#{url}/authentication", options)
62
62
  raise Error, "#{I18n.t('mobile_id.some_error')} #{response}" unless response.code == 200
63
63
 
64
64
  ActiveSupport::HashWithIndifferentAccess.new(
@@ -85,39 +85,41 @@ module MobileId
85
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
+
88
89
  response
89
90
  end
90
91
 
91
92
  def long_poll!(session_id:, doc:)
92
93
  response = nil
93
94
 
94
- # Retries until RUNNING state turns to COMPLETE
95
- 30.times do |i|
95
+ # Retries until RUNNING state turns to COMPLETE
96
+ 30.times do |_i|
96
97
  response = session_request(session_id)
97
98
  break if response['state'] == 'COMPLETE'
99
+
98
100
  sleep 1
99
101
  end
100
102
  raise Error, "#{I18n.t('mobile_id.some_error')} #{response.code} #{response}" if response['state'] != 'COMPLETE'
101
103
 
102
104
  if response['result'] != 'OK'
103
- message =
105
+ message =
104
106
  case response['result']
105
- when "TIMEOUT"
107
+ when 'TIMEOUT'
106
108
  I18n.t('mobile_id.timeout')
107
- when "NOT_MID_CLIENT"
109
+ when 'NOT_MID_CLIENT'
108
110
  I18n.t('mobile_id.user_is_not_mobile_id_client')
109
- when "USER_CANCELLED"
111
+ when 'USER_CANCELLED'
110
112
  I18n.t('mobile_id.user_cancelled')
111
- when "SIGNATURE_HASH_MISMATCH"
113
+ when 'SIGNATURE_HASH_MISMATCH'
112
114
  I18n.t('mobile_id.signature_hash_mismatch')
113
- when "PHONE_ABSENT"
115
+ when 'PHONE_ABSENT'
114
116
  I18n.t('mobile_id.phone_absent')
115
- when "DELIVERY_ERROR"
117
+ when 'DELIVERY_ERROR'
116
118
  I18n.t('mobile_id.delivery_error')
117
- when "SIM_ERROR"
119
+ when 'SIM_ERROR'
118
120
  I18n.t('mobile_id.sim_error')
119
121
  end
120
- raise Error, message
122
+ raise Error, message
121
123
  end
122
124
 
123
125
  @user_cert = MobileId::Cert.new(response['cert'], live: live)
@@ -126,8 +128,8 @@ module MobileId
126
128
  end
127
129
 
128
130
  def verification_code
129
- binary = hash.to_s.unpack('B*').first
130
- "%04d" % (binary[0...6] + binary[-7..-1]).to_i(2)
131
+ binary = hash.to_s.unpack1('B*')
132
+ '%04d' % (binary[0...6] + binary[-7..]).to_i(2)
131
133
  end
132
134
 
133
135
  def given_name
@@ -139,7 +141,7 @@ module MobileId
139
141
  user_cert.surname
140
142
  end
141
143
  alias last_name surname
142
-
144
+
143
145
  def country
144
146
  user_cert.country
145
147
  end
@@ -8,34 +8,41 @@ module MobileId
8
8
  end
9
9
 
10
10
  def live_store
11
- @live_store ||=
12
- build_store([
13
- File.join(root_path, 'EE_Certification_Centre_Root_CA.pem.crt'),
14
- File.join(root_path, 'EE-GovCA2018.pem.crt'),
15
- File.join(root_path, 'EID-SK_2011.pem.crt'),
16
- File.join(root_path, 'EID-SK_2016.pem.crt'),
17
- File.join(root_path, 'esteid2018.pem.crt'),
18
- File.join(root_path, 'ESTEID-SK_2011.pem.crt'),
19
- File.join(root_path, 'ESTEID-SK_2015.pem.crt'),
20
- File.join(root_path, 'KLASS3-SK_2010_EECCRCA.pem.crt'),
21
- File.join(root_path, 'KLASS3-SK_2010_EECCRCA_SHA384.pem.crt'),
22
- File.join(root_path, 'KLASS3-SK_2016_EECCRCA_SHA384.pem.crt'),
23
- File.join(root_path, 'KLASS3-SK.pem.crt'),
24
- File.join(root_path, 'NQ-SK_2016.pem.crt')
25
- ])
11
+ @live_store ||=
12
+ build_store(
13
+ [
14
+ File.join(root_path, 'EE_Certification_Centre_Root_CA.pem.crt'),
15
+ File.join(root_path, 'EE-GovCA2018.pem.crt'),
16
+ File.join(root_path, 'EID-SK_2011.pem.crt'),
17
+ File.join(root_path, 'EID-SK_2016.pem.crt'),
18
+ File.join(root_path, 'esteid2018.pem.crt'),
19
+ File.join(root_path, 'ESTEID-SK_2011.pem.crt'),
20
+ File.join(root_path, 'ESTEID-SK_2015.pem.crt'),
21
+ File.join(root_path, 'KLASS3-SK_2010_EECCRCA.pem.crt'),
22
+ File.join(root_path, 'KLASS3-SK_2010_EECCRCA_SHA384.pem.crt'),
23
+ File.join(root_path, 'KLASS3-SK_2016_EECCRCA_SHA384.pem.crt'),
24
+ File.join(root_path, 'KLASS3-SK.pem.crt'),
25
+ File.join(root_path, 'NQ-SK_2016.pem.crt')
26
+ ]
27
+ )
26
28
  end
27
29
 
28
30
  def test_store
29
- @test_store ||=
30
- build_store([
31
- File.join(root_path, 'TEST_of_EE_Certification_Centre_Root_CA.pem.crt'),
32
- File.join(root_path, 'TEST_of_ESTEID-SK_2015.pem.crt')
33
- ])
31
+ @test_store ||=
32
+ build_store(
33
+ [
34
+ File.join(root_path, 'TEST_of_EE_Certification_Centre_Root_CA.pem.crt'),
35
+ File.join(root_path, 'TEST_of_ESTEID-SK_2015.pem.crt')
36
+ ]
37
+ )
34
38
  end
35
39
 
36
40
  def build_store(paths)
37
41
  store = OpenSSL::X509::Store.new
38
- paths.each { |path| cert = OpenSSL::X509::Certificate.new(File.read(path)); store.add_cert(cert) }
42
+ paths.each do |path|
43
+ cert = OpenSSL::X509::Certificate.new(File.read(path))
44
+ store.add_cert(cert)
45
+ end
39
46
  store
40
47
  end
41
48
  end
@@ -44,7 +51,7 @@ module MobileId
44
51
 
45
52
  def initialize(base64_cert, live:)
46
53
  self.cert = OpenSSL::X509::Certificate.new(Base64.decode64(base64_cert))
47
- verify!(self.cert, live: live)
54
+ verify!(cert, live: live)
48
55
  build_cert_subject
49
56
  end
50
57
 
@@ -52,11 +59,14 @@ module MobileId
52
59
  if live == true
53
60
  raise Error, 'User certificate is not valid' unless self.class.live_store.verify(cert)
54
61
  else
55
- raise Error, 'User certificate is not valid' unless self.class.test_store.verify(cert) || self.class.live_store.verify(cert)
62
+ unless self.class.test_store.verify(cert) || self.class.live_store.verify(cert)
63
+ raise Error,
64
+ 'User certificate is not valid'
65
+ end
56
66
  end
57
67
 
58
68
  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...cert.not_after) === Time.now
69
+ raise Error, 'User certificate is expired' unless (cert.not_before...cert.not_after).include?(Time.now)
60
70
 
61
71
  true
62
72
  end
@@ -77,47 +87,48 @@ module MobileId
77
87
  end
78
88
 
79
89
  def cvc_to_der(cvc)
80
- sign_hex = cvc.unpack('H*').first
90
+ sign_hex = cvc.unpack1('H*')
81
91
  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))]
92
+ i = [OpenSSL::ASN1::Integer.new(sign_hex[0...half].to_i(16)),
93
+ OpenSSL::ASN1::Integer.new(sign_hex[half..sign_hex.size].to_i(16))]
83
94
  seq = OpenSSL::ASN1::Sequence.new(i)
84
95
  seq.to_der
85
96
  end
86
97
 
87
98
  def given_name
88
- subject["GN"].tr(",", " ")
99
+ subject['GN'].tr(',', ' ')
89
100
  end
90
101
  alias first_name given_name
91
102
 
92
103
  def surname
93
- subject["SN"].tr(",", " ")
104
+ subject['SN'].tr(',', ' ')
94
105
  end
95
106
  alias last_name surname
96
-
107
+
97
108
  def country
98
- subject["C"].tr(",", " ")
109
+ subject['C'].tr(',', ' ')
99
110
  end
100
111
 
101
112
  def common_name
102
- subject["CN"]
113
+ subject['CN']
103
114
  end
104
115
 
105
116
  def organizational_unit
106
- subject["OU"]
117
+ subject['OU']
107
118
  end
108
119
 
109
120
  def serial_number
110
- subject["serialNumber"]
121
+ subject['serialNumber']
111
122
  end
112
123
  alias personal_code serial_number
113
124
 
114
125
  private
115
126
 
116
127
  def build_cert_subject
117
- self.subject = cert.subject.to_utf8.split(/(?<!\\)\,+/).each_with_object({}) do |c, result|
118
- next unless c.include?("=")
128
+ self.subject = cert.subject.to_utf8.split(/(?<!\\),+/).each_with_object({}) do |c, result|
129
+ next unless c.include?('=')
119
130
 
120
- key, val = c.split("=")
131
+ key, val = c.split('=')
121
132
  result[key] = val
122
133
  end
123
134
  end
@@ -0,0 +1,10 @@
1
+ lt:
2
+ mobile_id:
3
+ some_error: Įvyko klaida
4
+ timeout: "M-parašo sesija pasibaigė"
5
+ user_is_not_mobile_id_client: Vartotojas nėra m-parašo klientas.
6
+ user_cancelled: Vartotojas nutraukė m-parašo operaciją.
7
+ signature_hash_mismatch: "M-parašo turi problemą. Vartotojas turėtų kreiptis į savo operatorių."
8
+ phone_absent: m-parašo SIM nepasiekiama.
9
+ delivery_error: m-parašo SMS siuntimo klaida.
10
+ sim_error: Neteisingas atsakymas iš m-parašo SIM kortelės
@@ -1,12 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails'
2
4
 
3
5
  module MobileId
4
- class Railtie < ::Rails::Railtie #:nodoc:
5
- initializer 'mobile_id' do |app|
6
- DeviseI18n::Railtie.instance_eval do
7
- (app.config.i18n.available_locales & MobileId::LOCALES).each do |loc|
8
- I18n.load_path << File.expand_path("locales/#{loc}.yml", __dir__)
9
- end
6
+ class Railtie < ::Rails::Railtie # :nodoc:
7
+ initializer 'mobile_id' do |_app|
8
+ MobileId::LOCALES.each do |loc|
9
+ I18n.load_path << File.expand_path("locales/#{loc}.yml", __dir__)
10
10
  end
11
11
  end
12
12
  end
data/lib/mobile_id.rb CHANGED
@@ -5,16 +5,17 @@ require 'digest'
5
5
  require 'httparty'
6
6
  require 'active_support/core_ext/hash/indifferent_access'
7
7
  require 'i18n'
8
+
8
9
  if defined?(Rails)
9
- require 'mobile_id/railtie'
10
+ require 'mobile_id/railtie'
10
11
  else
11
- I18n.load_path << Dir[File.expand_path("lib/mobile_id/locales") + "/*.yml"]
12
+ I18n.load_path << Dir["#{File.expand_path('lib/mobile_id/locales')}/*.yml"]
12
13
  end
13
14
 
14
15
  module MobileId
15
16
  class Error < StandardError; end
16
17
 
17
- LOCALES = [:en, :et, :ru]
18
+ LOCALES = %i[en et lt ru].freeze
18
19
  end
19
20
 
20
21
  require 'mobile_id/cert'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobile_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.15
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-10-15 00:00:00.000000000 Z
11
+ date: 2023-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: httparty
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: i18n
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: openssl
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -39,13 +67,13 @@ dependencies:
39
67
  - !ruby/object:Gem::Version
40
68
  version: 2.2.0
41
69
  - !ruby/object:Gem::Dependency
42
- name: i18n
70
+ name: pry
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - ">="
46
74
  - !ruby/object:Gem::Version
47
75
  version: '0'
48
- type: :runtime
76
+ type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
@@ -53,13 +81,13 @@ dependencies:
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
- name: activesupport
84
+ name: rspec
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - ">="
60
88
  - !ruby/object:Gem::Version
61
89
  version: '0'
62
- type: :runtime
90
+ type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
@@ -67,7 +95,7 @@ dependencies:
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
- name: rspec
98
+ name: rubocop
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
101
  - - ">="
@@ -81,7 +109,7 @@ dependencies:
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
- name: pry
112
+ name: rubocop-rspec
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - ">="
@@ -94,8 +122,8 @@ dependencies:
94
122
  - - ">="
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
- description: Estonia Mobile ID authentication
98
- email: priit@gitlab.eu
125
+ description: Ruby client for Estonia and Lithuania Mobile ID authentication
126
+ email: priit@domify.io
99
127
  executables: []
100
128
  extensions: []
101
129
  extra_rdoc_files: []
@@ -122,12 +150,15 @@ files:
122
150
  - lib/mobile_id/certs/esteid2018.pem.crt
123
151
  - lib/mobile_id/locales/en.yml
124
152
  - lib/mobile_id/locales/et.yml
153
+ - lib/mobile_id/locales/lt.yml
125
154
  - lib/mobile_id/locales/ru.yml
126
155
  - lib/mobile_id/railtie.rb
127
- homepage: https://github.com/gitlabeu/mobile_id
156
+ homepage: https://github.com/domify/mobile_id
128
157
  licenses:
129
158
  - MIT
130
- metadata: {}
159
+ metadata:
160
+ changelog_uri: https://github.com/domify/mobile_id/blob/main/CHANGELOG.md
161
+ rubygems_mfa_required: 'true'
131
162
  post_install_message:
132
163
  rdoc_options: []
133
164
  require_paths:
@@ -146,5 +177,5 @@ requirements: []
146
177
  rubygems_version: 3.4.10
147
178
  signing_key:
148
179
  specification_version: 4
149
- summary: Estonia Mobile ID authentication
180
+ summary: Estonia and Lithuania Mobile ID authentication
150
181
  test_files: []