pki_express 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +2 -2
  3. data/.github/workflows/test.yml +21 -21
  4. data/.gitignore +27 -27
  5. data/CHANGELOG.md +19 -16
  6. data/Gemfile +8 -7
  7. data/README.md +24 -24
  8. data/Rakefile +6 -6
  9. data/lib/pki_express/auth_complete_result.rb +21 -21
  10. data/lib/pki_express/auth_start_result.rb +76 -76
  11. data/lib/pki_express/authentication.rb +284 -284
  12. data/lib/pki_express/base_signer.rb +54 -54
  13. data/lib/pki_express/cades_signature.rb +89 -89
  14. data/lib/pki_express/cades_signature_starter.rb +242 -242
  15. data/lib/pki_express/check_service_result.rb +15 -15
  16. data/lib/pki_express/command_error.rb +13 -13
  17. data/lib/pki_express/commands.rb +24 -24
  18. data/lib/pki_express/digest_algorithm.rb +118 -118
  19. data/lib/pki_express/digest_algorithm_and_value.rb +30 -30
  20. data/lib/pki_express/discovery_service_result.rb +25 -25
  21. data/lib/pki_express/enum.rb +9 -9
  22. data/lib/pki_express/error_codes.rb +46 -46
  23. data/lib/pki_express/installation_not_found_error.rb +8 -8
  24. data/lib/pki_express/name.rb +47 -47
  25. data/lib/pki_express/oids.rb +30 -30
  26. data/lib/pki_express/pades_certification_level.rb +7 -7
  27. data/lib/pki_express/pades_horizontal_align.rb +9 -9
  28. data/lib/pki_express/pades_measurement_units.rb +8 -8
  29. data/lib/pki_express/pades_page_optimization.rb +50 -50
  30. data/lib/pki_express/pades_page_orientation.rb +9 -9
  31. data/lib/pki_express/pades_paper_size.rb +21 -21
  32. data/lib/pki_express/pades_signature.rb +16 -16
  33. data/lib/pki_express/pades_signature_explorer.rb +30 -30
  34. data/lib/pki_express/pades_signature_starter.rb +251 -251
  35. data/lib/pki_express/pades_signer.rb +274 -274
  36. data/lib/pki_express/pades_signer_info.rb +9 -9
  37. data/lib/pki_express/pades_size.rb +17 -17
  38. data/lib/pki_express/pades_text_horizontal_align.rb +8 -8
  39. data/lib/pki_express/pades_vertical_align.rb +9 -9
  40. data/lib/pki_express/pades_visual_auto_positioning.rb +21 -21
  41. data/lib/pki_express/pades_visual_image.rb +51 -51
  42. data/lib/pki_express/pades_visual_manual_positioning.rb +16 -16
  43. data/lib/pki_express/pades_visual_positioning.rb +27 -27
  44. data/lib/pki_express/pades_visual_rectangle.rb +74 -74
  45. data/lib/pki_express/pades_visual_representation.rb +22 -22
  46. data/lib/pki_express/pades_visual_text.rb +35 -35
  47. data/lib/pki_express/pk_algorithms.rb +157 -157
  48. data/lib/pki_express/pk_certificate.rb +61 -61
  49. data/lib/pki_express/pki_brazil_certificate_fields.rb +57 -57
  50. data/lib/pki_express/pki_brazil_certificate_types.rb +19 -19
  51. data/lib/pki_express/pki_express_config.rb +39 -26
  52. data/lib/pki_express/pki_express_operator.rb +240 -240
  53. data/lib/pki_express/pki_italy_certificate_fields.rb +15 -15
  54. data/lib/pki_express/pki_italy_certificate_types.rb +11 -11
  55. data/lib/pki_express/signature_algorithm_and_value.rb +34 -34
  56. data/lib/pki_express/signature_explorer.rb +74 -74
  57. data/lib/pki_express/signature_finisher.rb +314 -314
  58. data/lib/pki_express/signature_policy_identifier.rb +20 -20
  59. data/lib/pki_express/signature_start_result.rb +12 -12
  60. data/lib/pki_express/signature_starter.rb +116 -116
  61. data/lib/pki_express/signer.rb +151 -151
  62. data/lib/pki_express/standard_signature_policies.rb +58 -58
  63. data/lib/pki_express/timestamp_authority.rb +50 -50
  64. data/lib/pki_express/trust_service_auth_parameters.rb +20 -20
  65. data/lib/pki_express/trust_service_info.rb +37 -37
  66. data/lib/pki_express/trust_service_manager.rb +258 -258
  67. data/lib/pki_express/trust_service_session_result.rb +29 -29
  68. data/lib/pki_express/trust_service_session_types.rb +7 -7
  69. data/lib/pki_express/tsa_authentication_type.rb +14 -14
  70. data/lib/pki_express/validation_error.rb +8 -8
  71. data/lib/pki_express/validation_item.rb +43 -43
  72. data/lib/pki_express/validation_item_types.rb +103 -103
  73. data/lib/pki_express/validation_results.rb +120 -120
  74. data/lib/pki_express/version.rb +3 -3
  75. data/lib/pki_express/version_manager.rb +20 -20
  76. data/lib/pki_express.rb +69 -69
  77. data/pki_express.gemspec +26 -26
  78. data/spec/pki_express/pki_express_config_spec.rb +73 -0
  79. data/spec/pki_express/pki_express_operator_spec.rb +30 -30
  80. metadata +4 -2
@@ -1,251 +1,251 @@
1
- module PkiExpress
2
- class PadesSignatureStarter < SignatureStarter
3
- attr_accessor :suppress_default_visual_representation
4
- attr_accessor :custom_signature_field_name, :certification_level
5
-
6
- def initialize(config=PkiExpressConfig.new)
7
- super(config)
8
- @pdf_to_sign_path = nil
9
- @vr_json_path = nil
10
- @suppress_default_visual_representation = false
11
- @custom_signature_field_name = nil
12
- @certification_level = nil
13
- end
14
-
15
- # region The "pdf_to_sign" accessors
16
-
17
- def pdf_to_sign
18
- _get_pdf_to_sign
19
- end
20
-
21
- def _get_pdf_to_sign
22
- unless @pdf_to_sign_path
23
- return nil
24
- end
25
-
26
- File.read(@pdf_to_sign_path)
27
- end
28
- private :_get_pdf_to_sign
29
-
30
- def pdf_to_sign=(content_raw)
31
- _set_pdf_to_sign(content_raw)
32
- end
33
-
34
- def _set_pdf_to_sign(content_raw)
35
- unless content_raw
36
- raise 'The provided "pdf_to_sign" is not valid'
37
- end
38
-
39
- temp_file_path = self.create_temp_file
40
- File.open(temp_file_path, 'wb') do |f|
41
- f.write(content_raw)
42
- end
43
- @pdf_to_sign_path = temp_file_path
44
- end
45
- private :_set_pdf_to_sign
46
-
47
- def pdf_to_sign_base64
48
- _get_pdf_to_sign_base64
49
- end
50
-
51
- def _get_pdf_to_sign_base64
52
- unless @pdf_to_sign_path
53
- return nil
54
- end
55
-
56
- content = File.read(@pdf_to_sign_path)
57
- Base64.encode64(content)
58
- end
59
- private :_get_pdf_to_sign_base64
60
-
61
- def pdf_to_sign_base64=(content_base64)
62
- _set_pdf_to_sign_base64(content_base64)
63
- end
64
-
65
- def _set_pdf_to_sign_base64(content_base64)
66
- unless content_base64
67
- raise 'The provided "pdf_to_sign_base64" is not valid'
68
- end
69
-
70
- begin
71
- content_raw = Base64.decode64(content_base64)
72
- rescue Error
73
- raise 'The provided "pdf_to_sign_base64" is not Base64-encoded'
74
- end
75
-
76
- _set_pdf_to_sign(content_raw)
77
- end
78
- private :_set_pdf_to_sign_base64
79
-
80
- def pdf_to_sign_path
81
- _get_pdf_to_sign_path
82
- end
83
-
84
- def _get_pdf_to_sign_path
85
- @pdf_to_sign_path
86
- end
87
- private :_get_pdf_to_sign_path
88
-
89
- def pdf_to_sign_path=(path)
90
- _set_pdf_to_sign_path(path)
91
- end
92
-
93
- def _set_pdf_to_sign_path(path)
94
- unless path
95
- raise 'The provided "pdf_to_sign_path" is not valid'
96
- end
97
- unless File.exists?(path)
98
- raise 'The provided "pdf_to_sign_path" does not exist'
99
- end
100
- @pdf_to_sign_path = path
101
- end
102
- private :_set_pdf_to_sign_path
103
-
104
- # endregion
105
-
106
- # region set_visual_representation
107
-
108
- def visual_representation_content_raw
109
- _get_visual_representation_content_raw
110
- end
111
-
112
- def _get_visual_representation_content_raw
113
- unless @vr_json_path
114
- return nil
115
- end
116
-
117
- File.read(@vr_json_path)
118
- end
119
- private :_get_visual_representation_content_raw
120
-
121
- def visual_representation_content_raw=(content_raw)
122
- _set_visual_representation_content_raw(content_raw)
123
- end
124
-
125
- def _set_visual_representation_content_raw(content_raw)
126
- unless content_raw
127
- raise 'The provided "visual_representation" 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
- @vr_json_path = temp_file_path
135
- end
136
- private :_set_visual_representation_content_raw
137
-
138
- def visual_representation_path
139
- _get_visual_representation_path
140
- end
141
-
142
- def _get_visual_representation_path
143
- @vr_json_path
144
- end
145
- private :_get_visual_representation_path
146
-
147
- def visual_representation_path=(path)
148
- _set_visual_representation_path(path)
149
- end
150
-
151
- def _set_visual_representation_path(path)
152
- unless path
153
- raise 'The provided "visual_representation_path" is not valid'
154
- end
155
- unless File.exists?(path)
156
- raise 'The provided "visual_representation_path" does not exist'
157
- end
158
- @vr_json_path = path
159
- end
160
- private :_set_visual_representation_path
161
-
162
- def visual_representation
163
- _get_visual_representation
164
- end
165
-
166
- def _get_visual_representation
167
- unless @vr_json_path
168
- return nil
169
- end
170
-
171
- content = File.read(@vr_json_path)
172
- JSON.parse(content)
173
- end
174
- private :_get_visual_representation
175
-
176
-
177
- def visual_representation=(vr)
178
- _set_visual_representation(vr)
179
- end
180
-
181
- def _set_visual_representation(vr)
182
- temp_file_path = self.create_temp_file
183
- json = JSON.pretty_generate(vr.to_model)
184
- File.open(temp_file_path, 'w') do |f|
185
- f.write(json)
186
- end
187
- @vr_json_path = temp_file_path
188
- end
189
- private :_set_visual_representation
190
-
191
- # endregion
192
-
193
- def start
194
- unless @pdf_to_sign_path
195
- raise 'The PDF to be signed was not set'
196
- end
197
-
198
- unless @certificate_path
199
- raise 'The certificate was not set'
200
- end
201
-
202
- # Generate transfer file.
203
- transfer_file_id = get_transfer_filename
204
-
205
- args = [
206
- @pdf_to_sign_path,
207
- @certificate_path,
208
- File.expand_path(transfer_file_id, @config.transfer_data_folder),
209
- ]
210
-
211
- # Verify and add common options between signers.
212
- verify_and_add_common_options(args)
213
-
214
- if @vr_json_path
215
- args.append('--visual-rep')
216
- args.append(@vr_json_path)
217
- end
218
-
219
- if @custom_signature_field_name
220
- args.append('--custom-signature-field-name')
221
- args.append(@custom_signature_field_name)
222
- # This option can only be used on versions greater than 1.15.0 of the
223
- # PKI Express.
224
- @version_manager.require_version('1.15')
225
- end
226
-
227
- if @certification_level
228
- args.append('--certification-level')
229
- args.append(@certification_level)
230
- # This option can only be used on versions greater than 1.16.0 of the
231
- # PKI Express.
232
- @version_manager.require_version('1.16')
233
- end
234
-
235
- if @suppress_default_visual_representation
236
- args.append('--suppress-default-visual-rep')
237
-
238
- # This option can only be used on versions greater than 1.13.1 of the
239
- # PKI Express.
240
- @version_manager.require_version('1.13.1')
241
- end
242
-
243
- # Invoke command.
244
- result = invoke(Commands::START_PADES, args)
245
-
246
- # Parse output and return model.
247
- model = parse_output(result)
248
- SignatureStartResult.new(model, transfer_file_id)
249
- end
250
- end
251
- end
1
+ module PkiExpress
2
+ class PadesSignatureStarter < SignatureStarter
3
+ attr_accessor :suppress_default_visual_representation
4
+ attr_accessor :custom_signature_field_name, :certification_level
5
+
6
+ def initialize(config=PkiExpressConfig.new)
7
+ super(config)
8
+ @pdf_to_sign_path = nil
9
+ @vr_json_path = nil
10
+ @suppress_default_visual_representation = false
11
+ @custom_signature_field_name = nil
12
+ @certification_level = nil
13
+ end
14
+
15
+ # region The "pdf_to_sign" accessors
16
+
17
+ def pdf_to_sign
18
+ _get_pdf_to_sign
19
+ end
20
+
21
+ def _get_pdf_to_sign
22
+ unless @pdf_to_sign_path
23
+ return nil
24
+ end
25
+
26
+ File.read(@pdf_to_sign_path)
27
+ end
28
+ private :_get_pdf_to_sign
29
+
30
+ def pdf_to_sign=(content_raw)
31
+ _set_pdf_to_sign(content_raw)
32
+ end
33
+
34
+ def _set_pdf_to_sign(content_raw)
35
+ unless content_raw
36
+ raise 'The provided "pdf_to_sign" is not valid'
37
+ end
38
+
39
+ temp_file_path = self.create_temp_file
40
+ File.open(temp_file_path, 'wb') do |f|
41
+ f.write(content_raw)
42
+ end
43
+ @pdf_to_sign_path = temp_file_path
44
+ end
45
+ private :_set_pdf_to_sign
46
+
47
+ def pdf_to_sign_base64
48
+ _get_pdf_to_sign_base64
49
+ end
50
+
51
+ def _get_pdf_to_sign_base64
52
+ unless @pdf_to_sign_path
53
+ return nil
54
+ end
55
+
56
+ content = File.read(@pdf_to_sign_path)
57
+ Base64.encode64(content)
58
+ end
59
+ private :_get_pdf_to_sign_base64
60
+
61
+ def pdf_to_sign_base64=(content_base64)
62
+ _set_pdf_to_sign_base64(content_base64)
63
+ end
64
+
65
+ def _set_pdf_to_sign_base64(content_base64)
66
+ unless content_base64
67
+ raise 'The provided "pdf_to_sign_base64" is not valid'
68
+ end
69
+
70
+ begin
71
+ content_raw = Base64.decode64(content_base64)
72
+ rescue Error
73
+ raise 'The provided "pdf_to_sign_base64" is not Base64-encoded'
74
+ end
75
+
76
+ _set_pdf_to_sign(content_raw)
77
+ end
78
+ private :_set_pdf_to_sign_base64
79
+
80
+ def pdf_to_sign_path
81
+ _get_pdf_to_sign_path
82
+ end
83
+
84
+ def _get_pdf_to_sign_path
85
+ @pdf_to_sign_path
86
+ end
87
+ private :_get_pdf_to_sign_path
88
+
89
+ def pdf_to_sign_path=(path)
90
+ _set_pdf_to_sign_path(path)
91
+ end
92
+
93
+ def _set_pdf_to_sign_path(path)
94
+ unless path
95
+ raise 'The provided "pdf_to_sign_path" is not valid'
96
+ end
97
+ unless File.exists?(path)
98
+ raise 'The provided "pdf_to_sign_path" does not exist'
99
+ end
100
+ @pdf_to_sign_path = path
101
+ end
102
+ private :_set_pdf_to_sign_path
103
+
104
+ # endregion
105
+
106
+ # region set_visual_representation
107
+
108
+ def visual_representation_content_raw
109
+ _get_visual_representation_content_raw
110
+ end
111
+
112
+ def _get_visual_representation_content_raw
113
+ unless @vr_json_path
114
+ return nil
115
+ end
116
+
117
+ File.read(@vr_json_path)
118
+ end
119
+ private :_get_visual_representation_content_raw
120
+
121
+ def visual_representation_content_raw=(content_raw)
122
+ _set_visual_representation_content_raw(content_raw)
123
+ end
124
+
125
+ def _set_visual_representation_content_raw(content_raw)
126
+ unless content_raw
127
+ raise 'The provided "visual_representation" 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
+ @vr_json_path = temp_file_path
135
+ end
136
+ private :_set_visual_representation_content_raw
137
+
138
+ def visual_representation_path
139
+ _get_visual_representation_path
140
+ end
141
+
142
+ def _get_visual_representation_path
143
+ @vr_json_path
144
+ end
145
+ private :_get_visual_representation_path
146
+
147
+ def visual_representation_path=(path)
148
+ _set_visual_representation_path(path)
149
+ end
150
+
151
+ def _set_visual_representation_path(path)
152
+ unless path
153
+ raise 'The provided "visual_representation_path" is not valid'
154
+ end
155
+ unless File.exists?(path)
156
+ raise 'The provided "visual_representation_path" does not exist'
157
+ end
158
+ @vr_json_path = path
159
+ end
160
+ private :_set_visual_representation_path
161
+
162
+ def visual_representation
163
+ _get_visual_representation
164
+ end
165
+
166
+ def _get_visual_representation
167
+ unless @vr_json_path
168
+ return nil
169
+ end
170
+
171
+ content = File.read(@vr_json_path)
172
+ JSON.parse(content)
173
+ end
174
+ private :_get_visual_representation
175
+
176
+
177
+ def visual_representation=(vr)
178
+ _set_visual_representation(vr)
179
+ end
180
+
181
+ def _set_visual_representation(vr)
182
+ temp_file_path = self.create_temp_file
183
+ json = JSON.pretty_generate(vr.to_model)
184
+ File.open(temp_file_path, 'w') do |f|
185
+ f.write(json)
186
+ end
187
+ @vr_json_path = temp_file_path
188
+ end
189
+ private :_set_visual_representation
190
+
191
+ # endregion
192
+
193
+ def start
194
+ unless @pdf_to_sign_path
195
+ raise 'The PDF to be signed was not set'
196
+ end
197
+
198
+ unless @certificate_path
199
+ raise 'The certificate was not set'
200
+ end
201
+
202
+ # Generate transfer file.
203
+ transfer_file_id = get_transfer_filename
204
+
205
+ args = [
206
+ @pdf_to_sign_path,
207
+ @certificate_path,
208
+ File.expand_path(transfer_file_id, @config.transfer_data_folder),
209
+ ]
210
+
211
+ # Verify and add common options between signers.
212
+ verify_and_add_common_options(args)
213
+
214
+ if @vr_json_path
215
+ args.append('--visual-rep')
216
+ args.append(@vr_json_path)
217
+ end
218
+
219
+ if @custom_signature_field_name
220
+ args.append('--custom-signature-field-name')
221
+ args.append(@custom_signature_field_name)
222
+ # This option can only be used on versions greater than 1.15.0 of the
223
+ # PKI Express.
224
+ @version_manager.require_version('1.15')
225
+ end
226
+
227
+ if @certification_level
228
+ args.append('--certification-level')
229
+ args.append(@certification_level)
230
+ # This option can only be used on versions greater than 1.16.0 of the
231
+ # PKI Express.
232
+ @version_manager.require_version('1.16')
233
+ end
234
+
235
+ if @suppress_default_visual_representation
236
+ args.append('--suppress-default-visual-rep')
237
+
238
+ # This option can only be used on versions greater than 1.13.1 of the
239
+ # PKI Express.
240
+ @version_manager.require_version('1.13.1')
241
+ end
242
+
243
+ # Invoke command.
244
+ result = invoke(Commands::START_PADES, args)
245
+
246
+ # Parse output and return model.
247
+ model = parse_output(result)
248
+ SignatureStartResult.new(model, transfer_file_id)
249
+ end
250
+ end
251
+ end