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,89 +1,89 @@
1
- module PkiExpress
2
- class CadesSignature
3
- attr_accessor :encapsulated_content_type, :has_encapsulated_content, :signers
4
-
5
- def initialize(model)
6
- @encapsulated_content_type = nil
7
- @has_encapsulated_content = nil
8
- @signers = []
9
-
10
- unless model.nil?
11
- @encapsulated_content_type = model.fetch(:encapsulatedContentType)
12
- @has_encapsulated_content = model.fetch(:hasEncapsulatedContent)
13
-
14
- signers = model.fetch(:signers)
15
- if signers
16
- @signers = signers.map { |s| CadesSignerInfo.new(s) }
17
- end
18
- end
19
- end
20
- end
21
-
22
-
23
- class CadesTimestamp < CadesSignature
24
- attr_accessor :gen_time, :serial_number, :message_imprint
25
-
26
- def initialize(model)
27
- super(model)
28
- @gen_time = nil
29
- @serial_number = nil
30
- @message_imprint = nil
31
- @gen_time = model.fetch(:genTime)
32
- @serial_number = model.fetch(:serialNumber)
33
- @message_imprint = model.fetch(:messageImprint)
34
- end
35
- end
36
-
37
-
38
- class CadesSignerInfo
39
- attr_accessor :signing_time, :certified_date_reference, :message_digest
40
- attr_accessor :signature, :certificate, :signature_policy, :timestamps
41
- attr_accessor :validation_results
42
-
43
- def initialize(model)
44
- @signing_time = nil
45
- @certified_date_reference = nil
46
- @message_digest = nil
47
- @signature = nil
48
- @certificate = nil
49
- @signature_policy = nil
50
- @timestamps = []
51
- @validation_results = nil
52
-
53
- unless model.nil?
54
- @certified_date_reference = model.fetch(:certifiedDateReference)
55
- @signing_time = model.fetch(:signingTime)
56
-
57
- message_digest = model.fetch(:messageDigest)
58
- if message_digest
59
- @message_digest = DigestAlgorithmAndValue.new(message_digest)
60
- end
61
-
62
- signature = model.fetch(:signature)
63
- if signature
64
- @signature = SignatureAlgorithmAndValue.new(signature)
65
- end
66
-
67
- certificate = model.fetch(:certificate)
68
- if certificate
69
- @certificate = PKCertificate.new(certificate)
70
- end
71
-
72
- signature_policy = model.fetch(:signaturePolicy)
73
- if signature_policy
74
- @signature_policy = SignaturePolicyIdentifier.new(signature_policy)
75
- end
76
-
77
- timestamps = model.fetch(:timestamps)
78
- if timestamps
79
- @timestamps = timestamps.map { |t| CadesTimestamp.new(t) }
80
- end
81
-
82
- validation_results = model.fetch(:validationResults)
83
- if validation_results
84
- @validation_results = ValidationResults.new(validation_results)
85
- end
86
- end
87
- end
88
- end
89
- end
1
+ module PkiExpress
2
+ class CadesSignature
3
+ attr_accessor :encapsulated_content_type, :has_encapsulated_content, :signers
4
+
5
+ def initialize(model)
6
+ @encapsulated_content_type = nil
7
+ @has_encapsulated_content = nil
8
+ @signers = []
9
+
10
+ unless model.nil?
11
+ @encapsulated_content_type = model.fetch(:encapsulatedContentType)
12
+ @has_encapsulated_content = model.fetch(:hasEncapsulatedContent)
13
+
14
+ signers = model.fetch(:signers)
15
+ if signers
16
+ @signers = signers.map { |s| CadesSignerInfo.new(s) }
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+
23
+ class CadesTimestamp < CadesSignature
24
+ attr_accessor :gen_time, :serial_number, :message_imprint
25
+
26
+ def initialize(model)
27
+ super(model)
28
+ @gen_time = nil
29
+ @serial_number = nil
30
+ @message_imprint = nil
31
+ @gen_time = model.fetch(:genTime)
32
+ @serial_number = model.fetch(:serialNumber)
33
+ @message_imprint = model.fetch(:messageImprint)
34
+ end
35
+ end
36
+
37
+
38
+ class CadesSignerInfo
39
+ attr_accessor :signing_time, :certified_date_reference, :message_digest
40
+ attr_accessor :signature, :certificate, :signature_policy, :timestamps
41
+ attr_accessor :validation_results
42
+
43
+ def initialize(model)
44
+ @signing_time = nil
45
+ @certified_date_reference = nil
46
+ @message_digest = nil
47
+ @signature = nil
48
+ @certificate = nil
49
+ @signature_policy = nil
50
+ @timestamps = []
51
+ @validation_results = nil
52
+
53
+ unless model.nil?
54
+ @certified_date_reference = model.fetch(:certifiedDateReference)
55
+ @signing_time = model.fetch(:signingTime)
56
+
57
+ message_digest = model.fetch(:messageDigest)
58
+ if message_digest
59
+ @message_digest = DigestAlgorithmAndValue.new(message_digest)
60
+ end
61
+
62
+ signature = model.fetch(:signature)
63
+ if signature
64
+ @signature = SignatureAlgorithmAndValue.new(signature)
65
+ end
66
+
67
+ certificate = model.fetch(:certificate)
68
+ if certificate
69
+ @certificate = PKCertificate.new(certificate)
70
+ end
71
+
72
+ signature_policy = model.fetch(:signaturePolicy)
73
+ if signature_policy
74
+ @signature_policy = SignaturePolicyIdentifier.new(signature_policy)
75
+ end
76
+
77
+ timestamps = model.fetch(:timestamps)
78
+ if timestamps
79
+ @timestamps = timestamps.map { |t| CadesTimestamp.new(t) }
80
+ end
81
+
82
+ validation_results = model.fetch(:validationResults)
83
+ if validation_results
84
+ @validation_results = ValidationResults.new(validation_results)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -1,242 +1,242 @@
1
- module PkiExpress
2
-
3
- class CadesSignatureStarter < SignatureStarter
4
-
5
- attr_accessor :encapsulated_content
6
-
7
- def initialize(config=PkiExpressConfig.new)
8
- super(config)
9
- @file_to_sign_path = nil
10
- @data_file_path = nil
11
- @encapsulated_content = true
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
- def start
199
-
200
- unless @file_to_sign_path
201
- raise 'The file to be signed was not set'
202
- end
203
-
204
- unless @certificate_path
205
- raise 'The certificate was not set'
206
- end
207
-
208
- # Generate transfer file.
209
- transfer_file_id = get_transfer_filename
210
-
211
- args = [
212
- @file_to_sign_path,
213
- @certificate_path,
214
- File.expand_path(transfer_file_id, @config.transfer_data_folder),
215
- ]
216
-
217
- # Verify and add common options between signers.
218
- verify_and_add_common_options(args)
219
-
220
- if @data_file_path
221
- args.append('--data-file')
222
- args.append(@data_file_path)
223
- end
224
-
225
- unless @encapsulated_content
226
- args.append('--detached')
227
- end
228
-
229
- # This operation can only be used on version greater than 1.3 of the
230
- # PKI Express.
231
- @version_manager.require_version('1.3')
232
-
233
- # Invoke command.
234
- result = invoke(Commands::START_CADES, args)
235
-
236
- # Parse output and return model.
237
- model = parse_output(result)
238
- SignatureStartResult.new(model, transfer_file_id)
239
- end
240
- end
241
-
242
- end
1
+ module PkiExpress
2
+
3
+ class CadesSignatureStarter < SignatureStarter
4
+
5
+ attr_accessor :encapsulated_content
6
+
7
+ def initialize(config=PkiExpressConfig.new)
8
+ super(config)
9
+ @file_to_sign_path = nil
10
+ @data_file_path = nil
11
+ @encapsulated_content = true
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
+ def start
199
+
200
+ unless @file_to_sign_path
201
+ raise 'The file to be signed was not set'
202
+ end
203
+
204
+ unless @certificate_path
205
+ raise 'The certificate was not set'
206
+ end
207
+
208
+ # Generate transfer file.
209
+ transfer_file_id = get_transfer_filename
210
+
211
+ args = [
212
+ @file_to_sign_path,
213
+ @certificate_path,
214
+ File.expand_path(transfer_file_id, @config.transfer_data_folder),
215
+ ]
216
+
217
+ # Verify and add common options between signers.
218
+ verify_and_add_common_options(args)
219
+
220
+ if @data_file_path
221
+ args.append('--data-file')
222
+ args.append(@data_file_path)
223
+ end
224
+
225
+ unless @encapsulated_content
226
+ args.append('--detached')
227
+ end
228
+
229
+ # This operation can only be used on version greater than 1.3 of the
230
+ # PKI Express.
231
+ @version_manager.require_version('1.3')
232
+
233
+ # Invoke command.
234
+ result = invoke(Commands::START_CADES, args)
235
+
236
+ # Parse output and return model.
237
+ model = parse_output(result)
238
+ SignatureStartResult.new(model, transfer_file_id)
239
+ end
240
+ end
241
+
242
+ end