pki_express 1.3.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +2 -2
  3. data/.github/workflows/test.yml +22 -0
  4. data/.gitignore +27 -27
  5. data/.rspec +1 -0
  6. data/CHANGELOG.md +19 -12
  7. data/Gemfile +9 -4
  8. data/README.md +24 -24
  9. data/Rakefile +7 -1
  10. data/lib/pki_express/auth_complete_result.rb +21 -21
  11. data/lib/pki_express/auth_start_result.rb +76 -76
  12. data/lib/pki_express/authentication.rb +284 -284
  13. data/lib/pki_express/base_signer.rb +54 -54
  14. data/lib/pki_express/cades_signature.rb +89 -89
  15. data/lib/pki_express/cades_signature_starter.rb +242 -242
  16. data/lib/pki_express/check_service_result.rb +15 -15
  17. data/lib/pki_express/command_error.rb +13 -13
  18. data/lib/pki_express/commands.rb +24 -24
  19. data/lib/pki_express/digest_algorithm.rb +118 -118
  20. data/lib/pki_express/digest_algorithm_and_value.rb +30 -30
  21. data/lib/pki_express/discovery_service_result.rb +25 -25
  22. data/lib/pki_express/enum.rb +9 -9
  23. data/lib/pki_express/error_codes.rb +46 -46
  24. data/lib/pki_express/installation_not_found_error.rb +8 -8
  25. data/lib/pki_express/name.rb +47 -47
  26. data/lib/pki_express/oids.rb +30 -30
  27. data/lib/pki_express/pades_certification_level.rb +7 -7
  28. data/lib/pki_express/pades_horizontal_align.rb +9 -9
  29. data/lib/pki_express/pades_measurement_units.rb +8 -8
  30. data/lib/pki_express/pades_page_optimization.rb +50 -50
  31. data/lib/pki_express/pades_page_orientation.rb +9 -9
  32. data/lib/pki_express/pades_paper_size.rb +21 -21
  33. data/lib/pki_express/pades_signature.rb +16 -16
  34. data/lib/pki_express/pades_signature_explorer.rb +30 -30
  35. data/lib/pki_express/pades_signature_starter.rb +251 -251
  36. data/lib/pki_express/pades_signer.rb +274 -274
  37. data/lib/pki_express/pades_signer_info.rb +9 -9
  38. data/lib/pki_express/pades_size.rb +17 -17
  39. data/lib/pki_express/pades_text_horizontal_align.rb +8 -8
  40. data/lib/pki_express/pades_vertical_align.rb +9 -9
  41. data/lib/pki_express/pades_visual_auto_positioning.rb +21 -21
  42. data/lib/pki_express/pades_visual_image.rb +51 -51
  43. data/lib/pki_express/pades_visual_manual_positioning.rb +16 -16
  44. data/lib/pki_express/pades_visual_positioning.rb +27 -27
  45. data/lib/pki_express/pades_visual_rectangle.rb +74 -74
  46. data/lib/pki_express/pades_visual_representation.rb +22 -22
  47. data/lib/pki_express/pades_visual_text.rb +35 -35
  48. data/lib/pki_express/pk_algorithms.rb +157 -157
  49. data/lib/pki_express/pk_certificate.rb +61 -61
  50. data/lib/pki_express/pki_brazil_certificate_fields.rb +57 -57
  51. data/lib/pki_express/pki_brazil_certificate_types.rb +19 -19
  52. data/lib/pki_express/pki_express_config.rb +39 -26
  53. data/lib/pki_express/pki_express_operator.rb +240 -234
  54. data/lib/pki_express/pki_italy_certificate_fields.rb +15 -15
  55. data/lib/pki_express/pki_italy_certificate_types.rb +11 -11
  56. data/lib/pki_express/signature_algorithm_and_value.rb +34 -34
  57. data/lib/pki_express/signature_explorer.rb +74 -74
  58. data/lib/pki_express/signature_finisher.rb +314 -314
  59. data/lib/pki_express/signature_policy_identifier.rb +20 -20
  60. data/lib/pki_express/signature_start_result.rb +12 -12
  61. data/lib/pki_express/signature_starter.rb +116 -116
  62. data/lib/pki_express/signer.rb +151 -151
  63. data/lib/pki_express/standard_signature_policies.rb +58 -58
  64. data/lib/pki_express/timestamp_authority.rb +50 -50
  65. data/lib/pki_express/trust_service_auth_parameters.rb +20 -20
  66. data/lib/pki_express/trust_service_info.rb +37 -37
  67. data/lib/pki_express/trust_service_manager.rb +258 -258
  68. data/lib/pki_express/trust_service_session_result.rb +29 -29
  69. data/lib/pki_express/trust_service_session_types.rb +7 -7
  70. data/lib/pki_express/tsa_authentication_type.rb +14 -14
  71. data/lib/pki_express/validation_error.rb +8 -8
  72. data/lib/pki_express/validation_item.rb +43 -43
  73. data/lib/pki_express/validation_item_types.rb +103 -103
  74. data/lib/pki_express/validation_results.rb +120 -120
  75. data/lib/pki_express/version.rb +3 -3
  76. data/lib/pki_express/version_manager.rb +20 -20
  77. data/lib/pki_express.rb +69 -69
  78. data/pki_express.gemspec +26 -26
  79. data/spec/pki_express/pki_express_config_spec.rb +73 -0
  80. data/spec/pki_express/pki_express_operator_spec.rb +31 -0
  81. data/spec/spec_helper.rb +13 -0
  82. metadata +17 -9
@@ -1,315 +1,315 @@
1
- module PkiExpress
2
- class SignatureFinisher < PkiExpressOperator
3
- attr_reader :transfer_file_id, :output_file_path
4
-
5
- def initialize(config=PkiExpressConfig.new)
6
- super(config)
7
- @file_to_sign_path = nil
8
- @transfer_file_id = nil
9
- @data_file_path = nil
10
- @output_file_path = nil
11
- @signature = nil
12
- end
13
-
14
- # region The "file_to_sign" accessors
15
-
16
- def file_to_sign
17
- _get_file_to_sign
18
- end
19
-
20
- def _get_file_to_sign
21
- unless @file_to_sign_path
22
- return nil
23
- end
24
-
25
- File.read(@file_to_sign_path)
26
- end
27
- private :_get_file_to_sign
28
-
29
- def file_to_sign=(content_raw)
30
- _set_file_to_sign(content_raw)
31
- end
32
-
33
- def _set_file_to_sign(content_raw)
34
- unless content_raw
35
- raise 'The provided "file_to_sign" is not valid'
36
- end
37
-
38
- temp_file_path = self.create_temp_file
39
- File.open(temp_file_path, 'wb') do |f|
40
- f.write(content_raw)
41
- end
42
- @file_to_sign_path = temp_file_path
43
- end
44
- private :_set_file_to_sign
45
-
46
- def file_to_sign_base64
47
- _get_file_to_sign_base64
48
- end
49
-
50
- def _get_file_to_sign_base64
51
- unless @file_to_sign_path
52
- return nil
53
- end
54
-
55
- content = File.read(@file_to_sign_path)
56
- Base64.encode64(content)
57
- end
58
- private :_get_file_to_sign_base64
59
-
60
- def file_to_sign_base64=(content_base64)
61
- _set_file_to_sign_base64(content_base64)
62
- end
63
-
64
- def _set_file_to_sign_base64(content_base64)
65
- unless content_base64
66
- raise 'The provided "file_to_sign_base64" is not valid'
67
- end
68
-
69
- begin
70
- content_raw = Base64.decode64(content_base64)
71
- rescue Error
72
- raise 'The provided "file_to_sign_base64" is not Base64-encoded'
73
- end
74
-
75
- _set_file_to_sign(content_raw)
76
- end
77
- private :_set_file_to_sign_base64
78
-
79
- def file_to_sign_path
80
- _get_file_to_sign_path
81
- end
82
-
83
- def _get_file_to_sign_path
84
- @file_to_sign_path
85
- end
86
- private :_get_file_to_sign_path
87
-
88
- def file_to_sign_path=(path)
89
- _set_file_to_sign_path(path)
90
- end
91
-
92
- def _set_file_to_sign_path(path)
93
- unless path
94
- raise 'The provided "file_to_sign_path" is not valid'
95
- end
96
- unless File.exists?(path)
97
- raise 'The provided "file_to_sign_path" does not exist'
98
- end
99
-
100
- @file_to_sign_path = path
101
- end
102
- private :_set_file_to_sign_path
103
-
104
- # endregion
105
-
106
- # region The "data_file" accessors
107
-
108
- def data_file
109
- _get_data_file
110
- end
111
-
112
- def _get_data_file
113
- unless @data_file_path
114
- return nil
115
- end
116
-
117
- File.read(@data_file_path)
118
- end
119
- private :_get_data_file
120
-
121
- def data_file=(content_raw)
122
- _set_data_file(content_raw)
123
- end
124
-
125
- def _set_data_file(content_raw)
126
- unless content_raw
127
- raise 'The provided "data_file" is not valid'
128
- end
129
-
130
- temp_file_path = self.create_temp_file
131
- File.open(temp_file_path, 'wb') do |f|
132
- f.write(content_raw)
133
- end
134
- @data_file_path = temp_file_path
135
- end
136
- private :_set_data_file
137
-
138
- def data_file_base64
139
- _get_data_file_base64
140
- end
141
-
142
- def _get_data_file_base64
143
- unless @data_file_path
144
- return nil
145
- end
146
-
147
- content = File.read(@data_file_path)
148
- Base64.encode64(content)
149
- end
150
- private :_get_data_file_base64
151
-
152
- def data_file_base64=(content_base64)
153
- _set_data_file_base64(content_base64)
154
- end
155
-
156
- def _set_data_file_base64(content_base64)
157
- unless content_base64
158
- raise 'The provided "data_file_base64" is not valid'
159
- end
160
-
161
- begin
162
- content_raw = Base64.decode64(content_base64)
163
- rescue Error
164
- raise 'The provided "data_file_base64" is not Base64-encoded'
165
- end
166
-
167
- _set_data_file(content_raw)
168
- end
169
- private :_set_data_file_base64
170
-
171
- def data_file_path
172
- _get_data_file_path
173
- end
174
-
175
- def _get_data_file_path
176
- @data_file_path
177
- end
178
- private :_get_data_file_path
179
-
180
- def data_file_path=(path)
181
- _set_data_file_path(path)
182
- end
183
-
184
- def _set_data_file_path(path)
185
- unless path
186
- raise 'The provided "data_file_path" is not valid'
187
- end
188
- unless File.exists?(path)
189
- raise 'The provided "data_file_path" does not exist'
190
- end
191
-
192
- @data_file_path = path
193
- end
194
- private :_set_data_file_path
195
-
196
- # endregion
197
-
198
- # region The "signature" accessors
199
-
200
- def signature
201
- _get_signature
202
- end
203
-
204
- def _get_signature
205
- @signature
206
- end
207
- private :_get_signature
208
-
209
- def signature=(content_raw)
210
- _set_signature(content_raw)
211
- end
212
-
213
- def _set_signature(content_raw)
214
- unless content_raw
215
- raise 'The provided "signature" is not valid'
216
- end
217
- @signature = content_raw
218
- end
219
- private :_set_signature
220
-
221
- def signature_base64
222
- _get_signature_base64
223
- end
224
-
225
- def _get_signature_base64
226
- unless @signature
227
- return nil
228
- end
229
- Base64.encode64(@signature)
230
- end
231
- private :_get_signature_base64
232
-
233
- def signature_base64=(content_base64)
234
- _set_signature_base64(content_base64)
235
- end
236
-
237
- def _set_signature_base64(content_base64)
238
- unless content_base64
239
- raise 'The provided "signature_base64" is not valid'
240
- end
241
-
242
- begin
243
- content_raw = Base64.decode64(content_base64)
244
- rescue Error
245
- raise 'The provided "signature_base64" is not Base64-encoded'
246
- end
247
-
248
- _set_signature(content_raw)
249
- end
250
- private :_set_signature_base64
251
-
252
- # endregion
253
-
254
- def transfer_file_id=(value)
255
- unless value
256
- raise 'The provided "transfer_file_id" is not valid'
257
- end
258
- unless File.exist?(File.expand_path(value, @config.transfer_data_folder))
259
- raise 'The provided "transfer_file_id" does not exist'
260
- end
261
- @transfer_file_id = value
262
- end
263
-
264
- def output_file_path=(value)
265
- unless value
266
- raise 'The provided "output_file_path" is not valid'
267
- end
268
- @output_file_path = value
269
- end
270
-
271
- def complete(get_cert=true)
272
- unless @file_to_sign_path
273
- raise 'The file to be signed was not set'
274
- end
275
- unless @transfer_file_id
276
- raise 'The transfer data file was not set'
277
- end
278
- unless @signature
279
- raise 'The signature was not set'
280
- end
281
- unless @output_file_path
282
- raise 'The output destination was not set'
283
- end
284
-
285
- args = [
286
- @file_to_sign_path,
287
- File.expand_path(@transfer_file_id, @config.transfer_data_folder),
288
- @signature,
289
- @output_file_path,
290
- ]
291
-
292
- if @data_file_path
293
- args.append('--data-file')
294
- args.append(@data_file_path)
295
- end
296
-
297
- if get_cert
298
- # This operation can only be used on version greater than 1.8 of the
299
- # PKI Express.
300
- @version_manager.require_version('1.8')
301
-
302
- # Invoke command.
303
- result = invoke(Commands::COMPLETE_SIG, args)
304
-
305
- # Parse output and return model.
306
- model = parse_output(result)
307
- return PKCertificate.new(model.fetch(:signer))
308
- end
309
-
310
- # Invoke command.
311
- invoke(Commands::COMPLETE_SIG, args)
312
- end
313
-
314
- end
1
+ module PkiExpress
2
+ class SignatureFinisher < PkiExpressOperator
3
+ attr_reader :transfer_file_id, :output_file_path
4
+
5
+ def initialize(config=PkiExpressConfig.new)
6
+ super(config)
7
+ @file_to_sign_path = nil
8
+ @transfer_file_id = nil
9
+ @data_file_path = nil
10
+ @output_file_path = nil
11
+ @signature = nil
12
+ end
13
+
14
+ # region The "file_to_sign" accessors
15
+
16
+ def file_to_sign
17
+ _get_file_to_sign
18
+ end
19
+
20
+ def _get_file_to_sign
21
+ unless @file_to_sign_path
22
+ return nil
23
+ end
24
+
25
+ File.read(@file_to_sign_path)
26
+ end
27
+ private :_get_file_to_sign
28
+
29
+ def file_to_sign=(content_raw)
30
+ _set_file_to_sign(content_raw)
31
+ end
32
+
33
+ def _set_file_to_sign(content_raw)
34
+ unless content_raw
35
+ raise 'The provided "file_to_sign" is not valid'
36
+ end
37
+
38
+ temp_file_path = self.create_temp_file
39
+ File.open(temp_file_path, 'wb') do |f|
40
+ f.write(content_raw)
41
+ end
42
+ @file_to_sign_path = temp_file_path
43
+ end
44
+ private :_set_file_to_sign
45
+
46
+ def file_to_sign_base64
47
+ _get_file_to_sign_base64
48
+ end
49
+
50
+ def _get_file_to_sign_base64
51
+ unless @file_to_sign_path
52
+ return nil
53
+ end
54
+
55
+ content = File.read(@file_to_sign_path)
56
+ Base64.encode64(content)
57
+ end
58
+ private :_get_file_to_sign_base64
59
+
60
+ def file_to_sign_base64=(content_base64)
61
+ _set_file_to_sign_base64(content_base64)
62
+ end
63
+
64
+ def _set_file_to_sign_base64(content_base64)
65
+ unless content_base64
66
+ raise 'The provided "file_to_sign_base64" is not valid'
67
+ end
68
+
69
+ begin
70
+ content_raw = Base64.decode64(content_base64)
71
+ rescue Error
72
+ raise 'The provided "file_to_sign_base64" is not Base64-encoded'
73
+ end
74
+
75
+ _set_file_to_sign(content_raw)
76
+ end
77
+ private :_set_file_to_sign_base64
78
+
79
+ def file_to_sign_path
80
+ _get_file_to_sign_path
81
+ end
82
+
83
+ def _get_file_to_sign_path
84
+ @file_to_sign_path
85
+ end
86
+ private :_get_file_to_sign_path
87
+
88
+ def file_to_sign_path=(path)
89
+ _set_file_to_sign_path(path)
90
+ end
91
+
92
+ def _set_file_to_sign_path(path)
93
+ unless path
94
+ raise 'The provided "file_to_sign_path" is not valid'
95
+ end
96
+ unless File.exists?(path)
97
+ raise 'The provided "file_to_sign_path" does not exist'
98
+ end
99
+
100
+ @file_to_sign_path = path
101
+ end
102
+ private :_set_file_to_sign_path
103
+
104
+ # endregion
105
+
106
+ # region The "data_file" accessors
107
+
108
+ def data_file
109
+ _get_data_file
110
+ end
111
+
112
+ def _get_data_file
113
+ unless @data_file_path
114
+ return nil
115
+ end
116
+
117
+ File.read(@data_file_path)
118
+ end
119
+ private :_get_data_file
120
+
121
+ def data_file=(content_raw)
122
+ _set_data_file(content_raw)
123
+ end
124
+
125
+ def _set_data_file(content_raw)
126
+ unless content_raw
127
+ raise 'The provided "data_file" is not valid'
128
+ end
129
+
130
+ temp_file_path = self.create_temp_file
131
+ File.open(temp_file_path, 'wb') do |f|
132
+ f.write(content_raw)
133
+ end
134
+ @data_file_path = temp_file_path
135
+ end
136
+ private :_set_data_file
137
+
138
+ def data_file_base64
139
+ _get_data_file_base64
140
+ end
141
+
142
+ def _get_data_file_base64
143
+ unless @data_file_path
144
+ return nil
145
+ end
146
+
147
+ content = File.read(@data_file_path)
148
+ Base64.encode64(content)
149
+ end
150
+ private :_get_data_file_base64
151
+
152
+ def data_file_base64=(content_base64)
153
+ _set_data_file_base64(content_base64)
154
+ end
155
+
156
+ def _set_data_file_base64(content_base64)
157
+ unless content_base64
158
+ raise 'The provided "data_file_base64" is not valid'
159
+ end
160
+
161
+ begin
162
+ content_raw = Base64.decode64(content_base64)
163
+ rescue Error
164
+ raise 'The provided "data_file_base64" is not Base64-encoded'
165
+ end
166
+
167
+ _set_data_file(content_raw)
168
+ end
169
+ private :_set_data_file_base64
170
+
171
+ def data_file_path
172
+ _get_data_file_path
173
+ end
174
+
175
+ def _get_data_file_path
176
+ @data_file_path
177
+ end
178
+ private :_get_data_file_path
179
+
180
+ def data_file_path=(path)
181
+ _set_data_file_path(path)
182
+ end
183
+
184
+ def _set_data_file_path(path)
185
+ unless path
186
+ raise 'The provided "data_file_path" is not valid'
187
+ end
188
+ unless File.exists?(path)
189
+ raise 'The provided "data_file_path" does not exist'
190
+ end
191
+
192
+ @data_file_path = path
193
+ end
194
+ private :_set_data_file_path
195
+
196
+ # endregion
197
+
198
+ # region The "signature" accessors
199
+
200
+ def signature
201
+ _get_signature
202
+ end
203
+
204
+ def _get_signature
205
+ @signature
206
+ end
207
+ private :_get_signature
208
+
209
+ def signature=(content_raw)
210
+ _set_signature(content_raw)
211
+ end
212
+
213
+ def _set_signature(content_raw)
214
+ unless content_raw
215
+ raise 'The provided "signature" is not valid'
216
+ end
217
+ @signature = content_raw
218
+ end
219
+ private :_set_signature
220
+
221
+ def signature_base64
222
+ _get_signature_base64
223
+ end
224
+
225
+ def _get_signature_base64
226
+ unless @signature
227
+ return nil
228
+ end
229
+ Base64.encode64(@signature)
230
+ end
231
+ private :_get_signature_base64
232
+
233
+ def signature_base64=(content_base64)
234
+ _set_signature_base64(content_base64)
235
+ end
236
+
237
+ def _set_signature_base64(content_base64)
238
+ unless content_base64
239
+ raise 'The provided "signature_base64" is not valid'
240
+ end
241
+
242
+ begin
243
+ content_raw = Base64.decode64(content_base64)
244
+ rescue Error
245
+ raise 'The provided "signature_base64" is not Base64-encoded'
246
+ end
247
+
248
+ _set_signature(content_raw)
249
+ end
250
+ private :_set_signature_base64
251
+
252
+ # endregion
253
+
254
+ def transfer_file_id=(value)
255
+ unless value
256
+ raise 'The provided "transfer_file_id" is not valid'
257
+ end
258
+ unless File.exist?(File.expand_path(value, @config.transfer_data_folder))
259
+ raise 'The provided "transfer_file_id" does not exist'
260
+ end
261
+ @transfer_file_id = value
262
+ end
263
+
264
+ def output_file_path=(value)
265
+ unless value
266
+ raise 'The provided "output_file_path" is not valid'
267
+ end
268
+ @output_file_path = value
269
+ end
270
+
271
+ def complete(get_cert=true)
272
+ unless @file_to_sign_path
273
+ raise 'The file to be signed was not set'
274
+ end
275
+ unless @transfer_file_id
276
+ raise 'The transfer data file was not set'
277
+ end
278
+ unless @signature
279
+ raise 'The signature was not set'
280
+ end
281
+ unless @output_file_path
282
+ raise 'The output destination was not set'
283
+ end
284
+
285
+ args = [
286
+ @file_to_sign_path,
287
+ File.expand_path(@transfer_file_id, @config.transfer_data_folder),
288
+ @signature,
289
+ @output_file_path,
290
+ ]
291
+
292
+ if @data_file_path
293
+ args.append('--data-file')
294
+ args.append(@data_file_path)
295
+ end
296
+
297
+ if get_cert
298
+ # This operation can only be used on version greater than 1.8 of the
299
+ # PKI Express.
300
+ @version_manager.require_version('1.8')
301
+
302
+ # Invoke command.
303
+ result = invoke(Commands::COMPLETE_SIG, args)
304
+
305
+ # Parse output and return model.
306
+ model = parse_output(result)
307
+ return PKCertificate.new(model.fetch(:signer))
308
+ end
309
+
310
+ # Invoke command.
311
+ invoke(Commands::COMPLETE_SIG, args)
312
+ end
313
+
314
+ end
315
315
  end
@@ -1,21 +1,21 @@
1
- module PkiExpress
2
- class SignaturePolicyIdentifier
3
- attr_accessor :digest, :oid, :uri
4
-
5
- def initialize(model)
6
- @digest = nil
7
- @oid = nil
8
- @uri = nil
9
-
10
- unless model.nil?
11
- digest = model.fetch(:digest)
12
- unless digest.nil?
13
- DigestAlgorithmAndValue.new(digest)
14
- end
15
- oid = model.fetch(:oid)
16
- uri = model.fetch(:uri)
17
- end
18
- end
19
-
20
- end
1
+ module PkiExpress
2
+ class SignaturePolicyIdentifier
3
+ attr_accessor :digest, :oid, :uri
4
+
5
+ def initialize(model)
6
+ @digest = nil
7
+ @oid = nil
8
+ @uri = nil
9
+
10
+ unless model.nil?
11
+ digest = model.fetch(:digest)
12
+ unless digest.nil?
13
+ DigestAlgorithmAndValue.new(digest)
14
+ end
15
+ oid = model.fetch(:oid)
16
+ uri = model.fetch(:uri)
17
+ end
18
+ end
19
+
20
+ end
21
21
  end