pki_express 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c36d5bb060458f62faed18815d8172334787019d8cfebdc82f0438f7d1919658
4
- data.tar.gz: eb56ce02b6e87563ac1f50344d98967c50cbe45a00adf80388ddb626d994b2fe
3
+ metadata.gz: 896f1e289fc2ed607b17114868dec204a97e735406574d04aa4c042ec54b9c7f
4
+ data.tar.gz: 60b52987a7c75e589b1d97b568f5b8e49afd0bec83b525cfe198baf891ec6aa8
5
5
  SHA512:
6
- metadata.gz: 74b1f525ba74647e809a92335bdb9864bcecd09a361c7ab570c4526686c43da6f06cc4ae38ced1018a5d1b6db5e5f4895692643056e74f8187f0c4e08039f8bf
7
- data.tar.gz: ac293189b668b04e46efda5726f8fd19fbf2367acf62a718336f7fd7d609ae97b62b129c26e7be10eec641e7a63f690fb90ef366df292fa75aa9d7f0e081cfce
6
+ metadata.gz: 6614c5ea29ff158f27878d0c84cf097ad1ef99ff336ecc528c3b9d1ee242333b8c909d4f47a909583ecafa65f024516b9d8cd46ed6b9aa66f6b665aaf9905fb6
7
+ data.tar.gz: 9ed53c11cd926a4bf1fc99f594706f7532e802db5992b911d08e7ffa2df776f2c95b16379c39b8461007834c8037e0e9433611cf7e8676fa5b9c7208474131de
@@ -1,2 +1,6 @@
1
+ ## 1.1.0 (2020-09-09)
2
+ * Adds PAdES Signer
3
+ * Adds support for Trust Services Management
4
+
1
5
  ## 1.0.0 (2018-04-11)
2
6
  * First publicly available version
data/README.md CHANGED
@@ -7,7 +7,7 @@ This library contains classes that encapsulate the calls to PKI Express.
7
7
  The recommended way to install **PKI Expresss lib** is through setting in your Gemfile:
8
8
 
9
9
  ````ruby
10
- gem 'pki_express', '~> 1.0.0'
10
+ gem 'pki_express', '~> 1.1.0'
11
11
  ````
12
12
 
13
13
  And with installing via [Bundler](http://bundler.io/) on your project root folder:
@@ -8,17 +8,21 @@ require_relative 'pki_express/auth_complete_result'
8
8
  require_relative 'pki_express/auth_start_result'
9
9
  require_relative 'pki_express/authentication'
10
10
  require_relative 'pki_express/cades_signature_starter'
11
+ require_relative 'pki_express/check_service_result'
11
12
  require_relative 'pki_express/command_error'
12
13
  require_relative 'pki_express/commands'
14
+ require_relative 'pki_express/discovery_service_result'
13
15
  require_relative 'pki_express/error_codes'
14
16
  require_relative 'pki_express/installation_not_found_error'
15
17
  require_relative 'pki_express/name'
18
+ require_relative 'pki_express/pades_certification_level'
16
19
  require_relative 'pki_express/pades_horizontal_align'
17
20
  require_relative 'pki_express/pades_measurement_units'
18
21
  require_relative 'pki_express/pades_page_optimization'
19
22
  require_relative 'pki_express/pades_page_optimization'
20
23
  require_relative 'pki_express/pades_paper_size'
21
24
  require_relative 'pki_express/pades_signature_starter'
25
+ require_relative 'pki_express/pades_signer'
22
26
  require_relative 'pki_express/pades_size'
23
27
  require_relative 'pki_express/pades_text_horizontal_align'
24
28
  require_relative 'pki_express/pades_vertical_align'
@@ -38,8 +42,15 @@ require_relative 'pki_express/signature_finisher'
38
42
  require_relative 'pki_express/signature_start_result'
39
43
  require_relative 'pki_express/standard_signature_policies'
40
44
  require_relative 'pki_express/timestamp_authority'
45
+ require_relative 'pki_express/trust_service_auth_parameters'
46
+ require_relative 'pki_express/trust_service_info'
47
+ require_relative 'pki_express/trust_service_manager'
48
+ require_relative 'pki_express/trust_service_session_result'
49
+ require_relative 'pki_express/trust_service_session_types'
50
+ require_relative 'pki_express/tsa_authentication_type'
41
51
  require_relative 'pki_express/validation_error'
42
52
  require_relative 'pki_express/validation_item'
53
+ require_relative 'pki_express/validation_item_types'
43
54
  require_relative 'pki_express/validation_results'
44
55
  require_relative 'pki_express/version'
45
56
  require_relative 'pki_express/version_manager'
@@ -0,0 +1,16 @@
1
+ module PkiExpress
2
+
3
+ class CheckServiceResult
4
+
5
+ attr_accessor :user_has_certificates
6
+
7
+ def initialize(model)
8
+ @user_has_certificates = nil
9
+
10
+ unless model.nil?
11
+ @user_has_certificates = model.fetch(:userHasCertificates)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -16,6 +16,10 @@ module PkiExpress
16
16
  STAMP_PDF = 'stamp-pdf',
17
17
  READ_CERT = 'read-cert',
18
18
  GEN_KEY = 'gen-key',
19
- CREATE_PFX = 'create-pfx'
19
+ CREATE_PFX = 'create-pfx',
20
+ CHECK_SERVICE = 'check-service',
21
+ DISCOVER_SERVICES = 'discover-services',
22
+ PASSWORD_AUTHORIZE = 'pwd-auth',
23
+ COMPLETE_SERVICE_AUTH = 'complete-service-auth'
20
24
  end
21
25
  end
@@ -0,0 +1,26 @@
1
+ module PkiExpress
2
+
3
+ class DiscoverServicesResult
4
+
5
+ attr_accessor :services, :auth_parameters
6
+
7
+ def initialize(model)
8
+ @services = []
9
+ @auth_parameters = []
10
+
11
+ unless model.nil?
12
+ services = model.fetch(:services)
13
+ if services
14
+ @services = services.map { |s| TrustServiceInfo.new(s) }
15
+ end
16
+
17
+ auth_parameters = model.fetch(:authParameters)
18
+ if auth_parameters
19
+ @auth_parameters = auth_parameters.map { |a| TrustServiceAuthParameters.new(a) }
20
+ end
21
+
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ module PkiExpress
2
+ class PadesCertificationLevel < Enum
3
+ NOT_CERTIFIED = 'not-certified'
4
+ CERTIFIED_FORM_FILLING = 'certified-form-filling'
5
+ CERTIFIED_FORM_FILLING_AND_ANNOTATIONS = 'certified-form-filling-annotations'
6
+ CERTIFIED_NO_CHANGES_ALLOWED = 'certified-no-changes-allowed'
7
+ end
8
+ end
@@ -1,12 +1,15 @@
1
1
  module PkiExpress
2
2
  class PadesSignatureStarter < SignatureStarter
3
3
  attr_accessor :suppress_default_visual_representation
4
+ attr_accessor :custom_signature_field_name, :certification_level
4
5
 
5
6
  def initialize(config=PkiExpressConfig.new)
6
7
  super(config)
7
8
  @pdf_to_sign_path = nil
8
9
  @vr_json_path = nil
9
10
  @suppress_default_visual_representation = false
11
+ @custom_signature_field_name = nil
12
+ @certification_level = nil
10
13
  end
11
14
 
12
15
  # region The "pdf_to_sign" accessors
@@ -213,6 +216,22 @@ module PkiExpress
213
216
  args.append(@vr_json_path)
214
217
  end
215
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
+
216
235
  if @suppress_default_visual_representation
217
236
  args.append('--suppress-default-visual-rep')
218
237
 
@@ -0,0 +1,275 @@
1
+ module PkiExpress
2
+
3
+ class PadesSigner < Signer
4
+ attr_accessor :suppress_default_visual_representation, :overwrite_original_file
5
+ attr_accessor :custom_signature_field_name, :certification_level, :reason
6
+
7
+ def initialize(config=PkiExpressConfig.new)
8
+ super(config)
9
+ @pdf_to_sign_path = nil
10
+ @vr_json_path = nil
11
+ @overwrite_original_file = false
12
+ @version_manager = VersionManager.new
13
+ @custom_signature_field_name = nil
14
+ @certification_level = nil
15
+ @reason = nil
16
+ @suppress_default_visual_representation = false
17
+ end
18
+
19
+ # region set_visual_representation
20
+
21
+ def visual_representation_content_raw
22
+ _get_visual_representation_content_raw
23
+ end
24
+
25
+ def _get_visual_representation_content_raw
26
+ unless @vr_json_path
27
+ return nil
28
+ end
29
+
30
+ File.read(@vr_json_path)
31
+ end
32
+ private :_get_visual_representation_content_raw
33
+
34
+ def visual_representation_content_raw=(content_raw)
35
+ _set_visual_representation_content_raw(content_raw)
36
+ end
37
+
38
+ def _set_visual_representation_content_raw(content_raw)
39
+ unless content_raw
40
+ raise 'The provided "visual_representation" is not valid'
41
+ end
42
+
43
+ temp_file_path = self.create_temp_file
44
+ File.open(temp_file_path, 'wb') do |f|
45
+ f.write(content_raw)
46
+ end
47
+ @vr_json_path = temp_file_path
48
+ end
49
+ private :_set_visual_representation_content_raw
50
+
51
+ def visual_representation_path
52
+ _get_visual_representation_path
53
+ end
54
+
55
+ def _get_visual_representation_path
56
+ @vr_json_path
57
+ end
58
+ private :_get_visual_representation_path
59
+
60
+ def visual_representation_path=(path)
61
+ _set_visual_representation_path(path)
62
+ end
63
+
64
+ def _set_visual_representation_path(path)
65
+ unless path
66
+ raise 'The provided "visual_representation_path" is not valid'
67
+ end
68
+ unless File.exists?(path)
69
+ raise 'The provided "visual_representation_path" does not exist'
70
+ end
71
+ @vr_json_path = path
72
+ end
73
+ private :_set_visual_representation_path
74
+
75
+ def visual_representation
76
+ _get_visual_representation
77
+ end
78
+
79
+ def _get_visual_representation
80
+ unless @vr_json_path
81
+ return nil
82
+ end
83
+
84
+ content = File.read(@vr_json_path)
85
+ JSON.parse(content)
86
+ end
87
+ private :_get_visual_representation
88
+
89
+
90
+ def visual_representation=(vr)
91
+ _set_visual_representation(vr)
92
+ end
93
+
94
+ def _set_visual_representation(vr)
95
+ temp_file_path = self.create_temp_file
96
+ json = JSON.pretty_generate(vr.to_model)
97
+ File.open(temp_file_path, 'w') do |f|
98
+ f.write(json)
99
+ end
100
+ @vr_json_path = temp_file_path
101
+ end
102
+ private :_set_visual_representation
103
+
104
+ # endregion
105
+
106
+ # region The "pdf_to_sign" accessors
107
+
108
+ def pdf_to_sign
109
+ _get_pdf_to_sign
110
+ end
111
+
112
+ def _get_pdf_to_sign
113
+ unless @pdf_to_sign_path
114
+ return nil
115
+ end
116
+
117
+ File.read(@pdf_to_sign_path)
118
+ end
119
+ private :_get_pdf_to_sign
120
+
121
+ def pdf_to_sign=(content_raw)
122
+ _set_pdf_to_sign(content_raw)
123
+ end
124
+
125
+ def _set_pdf_to_sign(content_raw)
126
+ unless content_raw
127
+ raise 'The provided "pdf_to_sign" 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
+ @pdf_to_sign_path = temp_file_path
135
+ end
136
+ private :_set_pdf_to_sign
137
+
138
+ def pdf_to_sign_base64
139
+ _get_pdf_to_sign_base64
140
+ end
141
+
142
+ def _get_pdf_to_sign_base64
143
+ unless @pdf_to_sign_path
144
+ return nil
145
+ end
146
+
147
+ content = File.read(@pdf_to_sign_path)
148
+ Base64.encode64(content)
149
+ end
150
+ private :_get_pdf_to_sign_base64
151
+
152
+ def pdf_to_sign_base64=(content_base64)
153
+ _set_pdf_to_sign_base64(content_base64)
154
+ end
155
+
156
+ def _set_pdf_to_sign_base64(content_base64)
157
+ unless content_base64
158
+ raise 'The provided "pdf_to_sign_base64" is not valid'
159
+ end
160
+
161
+ begin
162
+ content_raw = Base64.decode64(content_base64)
163
+ rescue Error
164
+ raise 'The provided "pdf_to_sign_base64" is not Base64-encoded'
165
+ end
166
+
167
+ _set_pdf_to_sign(content_raw)
168
+ end
169
+ private :_set_pdf_to_sign_base64
170
+
171
+ def pdf_to_sign_path
172
+ _get_pdf_to_sign_path
173
+ end
174
+
175
+ def _get_pdf_to_sign_path
176
+ @pdf_to_sign_path
177
+ end
178
+ private :_get_pdf_to_sign_path
179
+
180
+ def pdf_to_sign_path=(path)
181
+ _set_pdf_to_sign_path(path)
182
+ end
183
+
184
+ def _set_pdf_to_sign_path(path)
185
+ unless path
186
+ raise 'The provided "pdf_to_sign_path" is not valid'
187
+ end
188
+ unless File.exists?(path)
189
+ raise 'The provided "pdf_to_sign_path" does not exist'
190
+ end
191
+ @pdf_to_sign_path = path
192
+ end
193
+ private :_set_pdf_to_sign_path
194
+
195
+ # endregion
196
+
197
+ def sign(get_cert=false)
198
+ unless @pdf_to_sign_path
199
+ raise 'The PDF to be signed was not set'
200
+ end
201
+
202
+ unless @overwrite_original_file || @output_file_path
203
+ raise 'The output destination was not set'
204
+ end
205
+
206
+ args = [
207
+ @pdf_to_sign_path,
208
+ ]
209
+
210
+ # Logic to overwrite original file or use the output file
211
+ if @overwrite_original_file
212
+ args.append('--overwrite')
213
+ else
214
+ args.append(@output_file_path)
215
+ end
216
+
217
+ # Verify and add common options between signers.
218
+ verify_and_add_common_options(args)
219
+
220
+ if @vr_json_path
221
+ args.append('--visual-rep')
222
+ args.append(@vr_json_path)
223
+ end
224
+
225
+ if @custom_signature_field_name
226
+ args.append('--custom-signature-field-name')
227
+ args.append(@custom_signature_field_name)
228
+ # This option can only be used on versions greater than 1.15.0 of the
229
+ # PKI Express.
230
+ @version_manager.require_version('1.15')
231
+ end
232
+
233
+ if @certification_level
234
+ args.append('--certification-level')
235
+ args.append(@certification_level)
236
+ # This option can only be used on versions greater than 1.16.0 of the
237
+ # PKI Express.
238
+ @version_manager.require_version('1.16')
239
+ end
240
+
241
+ if @suppress_default_visual_representation
242
+ args.append('--suppress-default-visual-rep')
243
+ # This option can only be used on versions greater than 1.13.1 of the
244
+ # PKI Express.
245
+ @version_manager.require_version('1.13.1')
246
+ end
247
+
248
+ if @reason
249
+ args.append('--reason')
250
+ args.append(@reason)
251
+ # This option can only be used on versions greater than 1.13 of the
252
+ # PKI Express.
253
+ @version_manager.require_version('1.13')
254
+ end
255
+
256
+ if get_cert
257
+ # This option can only be used on versions greater than 1.8.0 of the
258
+ # PKI Express.
259
+ @version_manager.require_version('1.8')
260
+
261
+ # Invoke command.
262
+ result = invoke(Commands::SIGN_PADES, args)
263
+
264
+ # Parse output and return result.
265
+ model = parse_output(result)
266
+ return PKCertificate.new(model.fetch(:signer))
267
+ else
268
+ # Invoke command with plain text output (to support PKI Express < 1.3)
269
+ result = invoke_plain(Commands::SIGN_PADES, args)
270
+ end
271
+
272
+ end
273
+
274
+ end
275
+ end