pki_express 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +3 -0
- data/.gitignore +28 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +4 -0
- data/README.md +24 -0
- data/Rakefile +1 -0
- data/lib/pki_express.rb +48 -0
- data/lib/pki_express/auth_complete_result.rb +22 -0
- data/lib/pki_express/auth_start_result.rb +77 -0
- data/lib/pki_express/authentication.rb +285 -0
- data/lib/pki_express/base_signer.rb +55 -0
- data/lib/pki_express/cades_signature_starter.rb +242 -0
- data/lib/pki_express/command_error.rb +14 -0
- data/lib/pki_express/commands.rb +21 -0
- data/lib/pki_express/enum.rb +9 -0
- data/lib/pki_express/error_codes.rb +46 -0
- data/lib/pki_express/installation_not_found_error.rb +8 -0
- data/lib/pki_express/name.rb +48 -0
- data/lib/pki_express/pades_horizontal_align.rb +9 -0
- data/lib/pki_express/pades_measurement_units.rb +8 -0
- data/lib/pki_express/pades_page_optimization.rb +51 -0
- data/lib/pki_express/pades_page_orientation.rb +9 -0
- data/lib/pki_express/pades_paper_size.rb +21 -0
- data/lib/pki_express/pades_signature_starter.rb +232 -0
- data/lib/pki_express/pades_size.rb +17 -0
- data/lib/pki_express/pades_text_horizontal_align.rb +8 -0
- data/lib/pki_express/pades_vertical_align.rb +9 -0
- data/lib/pki_express/pades_visual_auto_positioning.rb +22 -0
- data/lib/pki_express/pades_visual_image.rb +52 -0
- data/lib/pki_express/pades_visual_manual_positioning.rb +17 -0
- data/lib/pki_express/pades_visual_positioning.rb +28 -0
- data/lib/pki_express/pades_visual_rectangle.rb +74 -0
- data/lib/pki_express/pades_visual_representation.rb +22 -0
- data/lib/pki_express/pades_visual_text.rb +35 -0
- data/lib/pki_express/pk_certificate.rb +62 -0
- data/lib/pki_express/pki_brazil_certificate_fields.rb +58 -0
- data/lib/pki_express/pki_brazil_certificate_types.rb +19 -0
- data/lib/pki_express/pki_express_config.rb +26 -0
- data/lib/pki_express/pki_express_operator.rb +216 -0
- data/lib/pki_express/pki_italy_certificate_fields.rb +16 -0
- data/lib/pki_express/pki_italy_certificate_types.rb +11 -0
- data/lib/pki_express/signature_finisher.rb +298 -0
- data/lib/pki_express/signature_start_result.rb +13 -0
- data/lib/pki_express/signature_starter.rb +115 -0
- data/lib/pki_express/signer.rb +106 -0
- data/lib/pki_express/standard_signature_policies.rb +36 -0
- data/lib/pki_express/timestamp_authority.rb +51 -0
- data/lib/pki_express/validation_error.rb +8 -0
- data/lib/pki_express/validation_item.rb +43 -0
- data/lib/pki_express/validation_results.rb +121 -0
- data/lib/pki_express/version.rb +3 -0
- data/lib/pki_express/version_manager.rb +21 -0
- data/pki_express.gemspec +27 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c36d5bb060458f62faed18815d8172334787019d8cfebdc82f0438f7d1919658
|
4
|
+
data.tar.gz: eb56ce02b6e87563ac1f50344d98967c50cbe45a00adf80388ddb626d994b2fe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 74b1f525ba74647e809a92335bdb9864bcecd09a361c7ab570c4526686c43da6f06cc4ae38ced1018a5d1b6db5e5f4895692643056e74f8187f0c4e08039f8bf
|
7
|
+
data.tar.gz: ac293189b668b04e46efda5726f8fd19fbf2367acf62a718336f7fd7d609ae97b62b129c26e7be10eec641e7a63f690fb90ef366df292fa75aa9d7f0e081cfce
|
data/.gitattributes
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
*.bundle
|
11
|
+
*.so
|
12
|
+
*.o
|
13
|
+
*.a
|
14
|
+
mkmf.log
|
15
|
+
*.gem
|
16
|
+
*.rbc
|
17
|
+
.DS_Store
|
18
|
+
.bundle
|
19
|
+
.rvmrc
|
20
|
+
.ruby-version
|
21
|
+
.yardoc
|
22
|
+
.rake_tasks~
|
23
|
+
Gemfile.lock
|
24
|
+
coverage/*
|
25
|
+
doc/*
|
26
|
+
log/*
|
27
|
+
pkg/*
|
28
|
+
.idea/*
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PKI Express for Ruby
|
2
|
+
============================
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rest_pki.svg)](https://badge.fury.io/rb/rest_pki)
|
4
|
+
|
5
|
+
This library contains classes that encapsulate the calls to PKI Express.
|
6
|
+
|
7
|
+
The recommended way to install **PKI Expresss lib** is through setting in your Gemfile:
|
8
|
+
|
9
|
+
````ruby
|
10
|
+
gem 'pki_express', '~> 1.0.0'
|
11
|
+
````
|
12
|
+
|
13
|
+
And with installing via [Bundler](http://bundler.io/) on your project root folder:
|
14
|
+
|
15
|
+
bundle install
|
16
|
+
|
17
|
+
Alternatively, You can install this gem globally by executing the following command:
|
18
|
+
|
19
|
+
gem install pki_express
|
20
|
+
|
21
|
+
Samples
|
22
|
+
-------
|
23
|
+
Please visit the [PKI Suite samples repository](https://github.com/LacunaSoftware/PkiSuiteSamples/tree/master/Ruby)
|
24
|
+
for examples on how to use this library.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/pki_express.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative 'pki_express/pki_express_config'
|
2
|
+
require_relative 'pki_express/pki_express_operator'
|
3
|
+
require_relative 'pki_express/enum'
|
4
|
+
require_relative 'pki_express/base_signer'
|
5
|
+
require_relative 'pki_express/signature_starter'
|
6
|
+
require_relative 'pki_express/signer'
|
7
|
+
require_relative 'pki_express/auth_complete_result'
|
8
|
+
require_relative 'pki_express/auth_start_result'
|
9
|
+
require_relative 'pki_express/authentication'
|
10
|
+
require_relative 'pki_express/cades_signature_starter'
|
11
|
+
require_relative 'pki_express/command_error'
|
12
|
+
require_relative 'pki_express/commands'
|
13
|
+
require_relative 'pki_express/error_codes'
|
14
|
+
require_relative 'pki_express/installation_not_found_error'
|
15
|
+
require_relative 'pki_express/name'
|
16
|
+
require_relative 'pki_express/pades_horizontal_align'
|
17
|
+
require_relative 'pki_express/pades_measurement_units'
|
18
|
+
require_relative 'pki_express/pades_page_optimization'
|
19
|
+
require_relative 'pki_express/pades_page_optimization'
|
20
|
+
require_relative 'pki_express/pades_paper_size'
|
21
|
+
require_relative 'pki_express/pades_signature_starter'
|
22
|
+
require_relative 'pki_express/pades_size'
|
23
|
+
require_relative 'pki_express/pades_text_horizontal_align'
|
24
|
+
require_relative 'pki_express/pades_vertical_align'
|
25
|
+
require_relative 'pki_express/pades_visual_positioning'
|
26
|
+
require_relative 'pki_express/pades_visual_auto_positioning'
|
27
|
+
require_relative 'pki_express/pades_visual_image'
|
28
|
+
require_relative 'pki_express/pades_visual_manual_positioning'
|
29
|
+
require_relative 'pki_express/pades_visual_rectangle'
|
30
|
+
require_relative 'pki_express/pades_visual_representation'
|
31
|
+
require_relative 'pki_express/pades_visual_text'
|
32
|
+
require_relative 'pki_express/pk_certificate'
|
33
|
+
require_relative 'pki_express/pki_brazil_certificate_fields'
|
34
|
+
require_relative 'pki_express/pki_brazil_certificate_types'
|
35
|
+
require_relative 'pki_express/pki_italy_certificate_fields'
|
36
|
+
require_relative 'pki_express/pki_italy_certificate_types'
|
37
|
+
require_relative 'pki_express/signature_finisher'
|
38
|
+
require_relative 'pki_express/signature_start_result'
|
39
|
+
require_relative 'pki_express/standard_signature_policies'
|
40
|
+
require_relative 'pki_express/timestamp_authority'
|
41
|
+
require_relative 'pki_express/validation_error'
|
42
|
+
require_relative 'pki_express/validation_item'
|
43
|
+
require_relative 'pki_express/validation_results'
|
44
|
+
require_relative 'pki_express/version'
|
45
|
+
require_relative 'pki_express/version_manager'
|
46
|
+
|
47
|
+
module PkiExpress
|
48
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module PkiExpress
|
2
|
+
class AuthCompleteResult
|
3
|
+
|
4
|
+
attr_accessor :certificate, :validation_results
|
5
|
+
|
6
|
+
def initialize(model)
|
7
|
+
@certificate = nil
|
8
|
+
@validation_results = nil
|
9
|
+
|
10
|
+
if model
|
11
|
+
certificate = model.fetch(:certificate)
|
12
|
+
if certificate
|
13
|
+
@certificate = PKCertificate.new(certificate)
|
14
|
+
end
|
15
|
+
validation_results = model.fetch(:validationResults)
|
16
|
+
if validation_results
|
17
|
+
@validation_results = ValidationResults.new(validation_results)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module PkiExpress
|
2
|
+
class AuthStartResult
|
3
|
+
attr_accessor :digest_algorithm_name, :digest_algorithm_oid
|
4
|
+
|
5
|
+
def initialize(model)
|
6
|
+
@nonce_base64 = nil
|
7
|
+
@digest_algorithm_name = nil
|
8
|
+
@digest_algorithm_oid = nil
|
9
|
+
|
10
|
+
if model
|
11
|
+
@nonce_base64 = model.fetch(:toSignData)
|
12
|
+
@digest_algorithm_name = model.fetch(:digestAlgorithmName)
|
13
|
+
@digest_algorithm_oid = model.fetch(:digestAlgorithmOid)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# region The "nonce" accessors
|
18
|
+
|
19
|
+
def nonce
|
20
|
+
_get_nonce
|
21
|
+
end
|
22
|
+
|
23
|
+
def _get_nonce
|
24
|
+
unless @nonce_base64
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
|
28
|
+
Base64.decode64(@nonce_base64)
|
29
|
+
end
|
30
|
+
private :_get_nonce
|
31
|
+
|
32
|
+
def nonce=(nonce)
|
33
|
+
_set_nonce(nonce)
|
34
|
+
end
|
35
|
+
|
36
|
+
def _set_nonce(nonce)
|
37
|
+
unless nonce
|
38
|
+
raise 'The provided "nonce" is not valid'
|
39
|
+
end
|
40
|
+
|
41
|
+
begin
|
42
|
+
b64 = Base64.encode64(nonce)
|
43
|
+
rescue Error
|
44
|
+
raise 'The provided "nonce" is not valid.'
|
45
|
+
end
|
46
|
+
|
47
|
+
@nonce_base64 = b64
|
48
|
+
end
|
49
|
+
private :_set_nonce
|
50
|
+
|
51
|
+
def nonce_base64
|
52
|
+
_get_nonce_base64
|
53
|
+
end
|
54
|
+
|
55
|
+
def _get_nonce_base64
|
56
|
+
@nonce_base64
|
57
|
+
end
|
58
|
+
private :_get_nonce_base64
|
59
|
+
|
60
|
+
def nonce_base64=(nonce_base64)
|
61
|
+
unless nonce_base64
|
62
|
+
raise 'The provided "nonce_base64" is not valid'
|
63
|
+
end
|
64
|
+
|
65
|
+
begin
|
66
|
+
Base64.decode64(nonce_base64)
|
67
|
+
rescue Error
|
68
|
+
raise 'The provided "nonce_base64" is not Base64-encoded.'
|
69
|
+
end
|
70
|
+
|
71
|
+
@nonce_base64 = nonce_base64
|
72
|
+
end
|
73
|
+
|
74
|
+
#endregion
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,285 @@
|
|
1
|
+
module PkiExpress
|
2
|
+
class Authentication < PkiExpressOperator
|
3
|
+
|
4
|
+
attr_accessor :use_external_storage
|
5
|
+
|
6
|
+
def initialize(config=PkiExpressConfig.new)
|
7
|
+
super(config)
|
8
|
+
@nonce_base64 = nil
|
9
|
+
@certificate_path = nil
|
10
|
+
@signature_base64 = nil
|
11
|
+
@use_external_storage = false
|
12
|
+
end
|
13
|
+
|
14
|
+
# region The "nonce" accessors
|
15
|
+
|
16
|
+
def nonce
|
17
|
+
_get_nonce
|
18
|
+
end
|
19
|
+
|
20
|
+
def _get_nonce
|
21
|
+
unless @nonce_base64
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
|
25
|
+
Base64.decode64(@nonce_base64)
|
26
|
+
end
|
27
|
+
private :_get_nonce
|
28
|
+
|
29
|
+
def nonce=(nonce)
|
30
|
+
_set_nonce(nonce)
|
31
|
+
end
|
32
|
+
|
33
|
+
def _set_nonce(nonce)
|
34
|
+
unless nonce
|
35
|
+
raise 'The provided "nonce" is not valid'
|
36
|
+
end
|
37
|
+
|
38
|
+
begin
|
39
|
+
b64 = Base64.encode64(nonce)
|
40
|
+
rescue Error
|
41
|
+
raise 'The provided "nonce" is not valid'
|
42
|
+
end
|
43
|
+
|
44
|
+
@nonce_base64 = b64
|
45
|
+
end
|
46
|
+
private :_set_nonce
|
47
|
+
|
48
|
+
def nonce_base64
|
49
|
+
_get_nonce_base64
|
50
|
+
end
|
51
|
+
|
52
|
+
def _get_nonce_base64
|
53
|
+
@nonce_base64
|
54
|
+
end
|
55
|
+
private :_get_nonce_base64
|
56
|
+
|
57
|
+
def nonce_base64=(nonce_base64)
|
58
|
+
unless nonce_base64
|
59
|
+
raise 'The provided "nonce_base64" is not valid'
|
60
|
+
end
|
61
|
+
|
62
|
+
begin
|
63
|
+
Base64.decode64(nonce_base64)
|
64
|
+
rescue Error
|
65
|
+
raise 'The provided "nonce_base64" is not Base64-encoded'
|
66
|
+
end
|
67
|
+
|
68
|
+
@nonce_base64 = nonce_base64
|
69
|
+
end
|
70
|
+
|
71
|
+
#endregion
|
72
|
+
|
73
|
+
# region The "certificate" accessors
|
74
|
+
|
75
|
+
def certificate
|
76
|
+
_get_certificate
|
77
|
+
end
|
78
|
+
|
79
|
+
def _get_certificate
|
80
|
+
unless @certificate_path
|
81
|
+
return nil
|
82
|
+
end
|
83
|
+
|
84
|
+
File.read(@certificate_path)
|
85
|
+
end
|
86
|
+
private :_get_certificate
|
87
|
+
|
88
|
+
def certificate=(content_raw)
|
89
|
+
_set_certificate(content_raw)
|
90
|
+
end
|
91
|
+
|
92
|
+
def _set_certificate(content_raw)
|
93
|
+
unless content_raw
|
94
|
+
raise 'The provided "certificate" is not valid'
|
95
|
+
end
|
96
|
+
|
97
|
+
temp_file_path = self.create_temp_file
|
98
|
+
File.open(temp_file_path, 'wb') do |f|
|
99
|
+
f.write(content_raw)
|
100
|
+
end
|
101
|
+
@certificate_path = temp_file_path
|
102
|
+
end
|
103
|
+
private :_set_certificate
|
104
|
+
|
105
|
+
def certificate_base64
|
106
|
+
_get_certificate_base64
|
107
|
+
end
|
108
|
+
|
109
|
+
def _get_certificate_base64
|
110
|
+
unless @certificate_path
|
111
|
+
return nil
|
112
|
+
end
|
113
|
+
|
114
|
+
content = File.read(@certificate_path)
|
115
|
+
Base64.encode64(content)
|
116
|
+
end
|
117
|
+
private :_get_certificate_base64
|
118
|
+
|
119
|
+
def certificate_base64=(content_base64)
|
120
|
+
_set_certificate_base64(content_base64)
|
121
|
+
end
|
122
|
+
|
123
|
+
def _set_certificate_base64(content_base64)
|
124
|
+
unless content_base64
|
125
|
+
raise 'The provided "certificate_base64" is not valid'
|
126
|
+
end
|
127
|
+
|
128
|
+
begin
|
129
|
+
content_raw = Base64.decode64(content_base64)
|
130
|
+
rescue Error
|
131
|
+
raise 'The provided "certificate_base64" is not Base64-encoded'
|
132
|
+
end
|
133
|
+
|
134
|
+
_set_certificate(content_raw)
|
135
|
+
end
|
136
|
+
private :_set_certificate_base64
|
137
|
+
|
138
|
+
def certificate_path
|
139
|
+
_get_certificate_path
|
140
|
+
end
|
141
|
+
|
142
|
+
def _get_certificate_path
|
143
|
+
@certificate_path
|
144
|
+
end
|
145
|
+
private :_get_certificate_path
|
146
|
+
|
147
|
+
def certificate_path=(path)
|
148
|
+
_set_certificate_path(path)
|
149
|
+
end
|
150
|
+
|
151
|
+
def _set_certificate_path(path)
|
152
|
+
unless path
|
153
|
+
raise 'The provided "certificate_path" is not valid'
|
154
|
+
end
|
155
|
+
if File.exists?(path)
|
156
|
+
raise 'The provided "certificate_path" does not exist'
|
157
|
+
end
|
158
|
+
|
159
|
+
@certificate_path = path
|
160
|
+
end
|
161
|
+
private :_set_certificate_path
|
162
|
+
|
163
|
+
# endregion
|
164
|
+
|
165
|
+
# region The "signature" accessors
|
166
|
+
|
167
|
+
def signature
|
168
|
+
_get_signature
|
169
|
+
end
|
170
|
+
|
171
|
+
def _get_signature
|
172
|
+
unless @signature_base64
|
173
|
+
return nil
|
174
|
+
end
|
175
|
+
|
176
|
+
Base64.decode64(@signature_base64)
|
177
|
+
end
|
178
|
+
private :_get_signature
|
179
|
+
|
180
|
+
def signature=(signature)
|
181
|
+
_set_signature(signature)
|
182
|
+
end
|
183
|
+
|
184
|
+
def _set_signature(signature)
|
185
|
+
unless signature
|
186
|
+
raise 'The provided "signature" is not valid'
|
187
|
+
end
|
188
|
+
begin
|
189
|
+
b64 = Base64.encode64(signature)
|
190
|
+
rescue Error
|
191
|
+
raise 'The provided "signature" is not valid'
|
192
|
+
end
|
193
|
+
|
194
|
+
@signature_base64 = b64
|
195
|
+
end
|
196
|
+
private :_set_signature
|
197
|
+
|
198
|
+
def signature_base64
|
199
|
+
_get_signature_base64
|
200
|
+
end
|
201
|
+
|
202
|
+
def _get_signature_base64
|
203
|
+
@signature_base64
|
204
|
+
end
|
205
|
+
private :_get_signature_base64
|
206
|
+
|
207
|
+
def signature_base64=(signature_base64)
|
208
|
+
_set_signature_base64(signature_base64)
|
209
|
+
end
|
210
|
+
|
211
|
+
def _set_signature_base64(signature_base64)
|
212
|
+
unless signature_base64
|
213
|
+
raise 'The provided "signature_base64" is not valid'
|
214
|
+
end
|
215
|
+
begin
|
216
|
+
Base64.decode64(signature_base64)
|
217
|
+
rescue Error
|
218
|
+
raise 'The provided "signature_base64" is not Base64-encoded'
|
219
|
+
end
|
220
|
+
|
221
|
+
@signature_base64 = signature_base64
|
222
|
+
end
|
223
|
+
private :_set_signature_base64
|
224
|
+
|
225
|
+
# endregion
|
226
|
+
|
227
|
+
def start
|
228
|
+
args = []
|
229
|
+
|
230
|
+
# The option "use external storage" is used to ignore the PKI Express's
|
231
|
+
# nonce verification, to make a own nonce store and nonce verification.
|
232
|
+
if @use_external_storage
|
233
|
+
args.append('--nonce-store')
|
234
|
+
args.append(@config.transfer_data_folder)
|
235
|
+
end
|
236
|
+
|
237
|
+
# This operation can only be used on versions greater then 1.4 of PKI
|
238
|
+
# Express.
|
239
|
+
@version_manager.require_version('1.4')
|
240
|
+
|
241
|
+
# Invoke command.
|
242
|
+
result = invoke(Commands::START_AUTH, args)
|
243
|
+
|
244
|
+
# Parse output and return result.
|
245
|
+
model = parse_output(result)
|
246
|
+
AuthStartResult.new(model)
|
247
|
+
end
|
248
|
+
|
249
|
+
def complete
|
250
|
+
unless @nonce_base64
|
251
|
+
raise 'The nonce was not set.'
|
252
|
+
end
|
253
|
+
unless @certificate_path
|
254
|
+
raise 'The certificate file was not set.'
|
255
|
+
end
|
256
|
+
unless @signature_base64
|
257
|
+
raise 'The signature was not set.'
|
258
|
+
end
|
259
|
+
|
260
|
+
args = [
|
261
|
+
@nonce_base64,
|
262
|
+
@certificate_path,
|
263
|
+
@signature_base64
|
264
|
+
]
|
265
|
+
|
266
|
+
# The option "use external storage" is used to ignore the PKI Express's
|
267
|
+
# nonce verification, to make a own nonce store and nonce verification.
|
268
|
+
unless @use_external_storage
|
269
|
+
args.append('--nonce-store')
|
270
|
+
args.append(@config.transfer_data_folder)
|
271
|
+
end
|
272
|
+
|
273
|
+
# This configuration can only be used on versions greater than 1.4 of PKI
|
274
|
+
# Express.
|
275
|
+
@version_manager.require_version('1.4')
|
276
|
+
|
277
|
+
# Invoke command.
|
278
|
+
result = invoke(Commands::COMPLETE_AUTH, args)
|
279
|
+
|
280
|
+
# Parse output and return result.
|
281
|
+
model = parse_output(result)
|
282
|
+
AuthCompleteResult.new(model)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|