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,48 +1,48 @@
1
- module PkiExpress
2
-
3
- class Name
4
-
5
- attr_accessor :country, :organization, :organization_unit, :dn_qualifier,
6
- :state_name, :common_name, :serial_number, :locality, :title,
7
- :surname, :given_name, :initials, :pseudonym,
8
- :generation_qualifier, :email_address
9
-
10
- def initialize(model)
11
- @country = nil
12
- @organization = nil
13
- @organization_unit = nil
14
- @dn_qualifier = nil
15
- @state_name = nil
16
- @common_name = nil
17
- @serial_number = nil
18
- @locality = nil
19
- @title = nil
20
- @surname = nil
21
- @given_name = nil
22
- @initials = nil
23
- @pseudonym = nil
24
- @generation_qualifier = nil
25
- @email_address = nil
26
-
27
-
28
- if model
29
- @country = model.fetch(:country)
30
- @organization = model.fetch(:organization)
31
- @organization_unit = model.fetch(:organizationUnit)
32
- @dn_qualifier = model.fetch(:dnQualifier)
33
- @state_name = model.fetch(:stateName)
34
- @common_name = model.fetch(:commonName)
35
- @serial_number = model.fetch(:serialNumber)
36
- @locality = model.fetch(:locality)
37
- @title = model.fetch(:title)
38
- @surname = model.fetch(:surname)
39
- @given_name = model.fetch(:givenName)
40
- @initials = model.fetch(:initials)
41
- @pseudonym = model.fetch(:pseudonym)
42
- @generation_qualifier = model.fetch(:generationQualifier)
43
- @email_address = model.fetch(:emailAddress)
44
- end
45
- end
46
- end
47
-
1
+ module PkiExpress
2
+
3
+ class Name
4
+
5
+ attr_accessor :country, :organization, :organization_unit, :dn_qualifier,
6
+ :state_name, :common_name, :serial_number, :locality, :title,
7
+ :surname, :given_name, :initials, :pseudonym,
8
+ :generation_qualifier, :email_address
9
+
10
+ def initialize(model)
11
+ @country = nil
12
+ @organization = nil
13
+ @organization_unit = nil
14
+ @dn_qualifier = nil
15
+ @state_name = nil
16
+ @common_name = nil
17
+ @serial_number = nil
18
+ @locality = nil
19
+ @title = nil
20
+ @surname = nil
21
+ @given_name = nil
22
+ @initials = nil
23
+ @pseudonym = nil
24
+ @generation_qualifier = nil
25
+ @email_address = nil
26
+
27
+
28
+ if model
29
+ @country = model.fetch(:country)
30
+ @organization = model.fetch(:organization)
31
+ @organization_unit = model.fetch(:organizationUnit)
32
+ @dn_qualifier = model.fetch(:dnQualifier)
33
+ @state_name = model.fetch(:stateName)
34
+ @common_name = model.fetch(:commonName)
35
+ @serial_number = model.fetch(:serialNumber)
36
+ @locality = model.fetch(:locality)
37
+ @title = model.fetch(:title)
38
+ @surname = model.fetch(:surname)
39
+ @given_name = model.fetch(:givenName)
40
+ @initials = model.fetch(:initials)
41
+ @pseudonym = model.fetch(:pseudonym)
42
+ @generation_qualifier = model.fetch(:generationQualifier)
43
+ @email_address = model.fetch(:emailAddress)
44
+ end
45
+ end
46
+ end
47
+
48
48
  end
@@ -1,31 +1,31 @@
1
- module PkiExpress
2
-
3
- class Oids < Enum
4
- # region Digest Algorithms
5
- MD5 = '1.2.840.113549.2.5'
6
- SHA1 = '1.3.14.3.2.26'
7
- # SHA224 = '2.16.840.1.101.3.4.2.4', # RFC 3874 section 4
8
- SHA256 = '2.16.840.1.101.3.4.2.1'
9
- SHA384 = '2.16.840.1.101.3.4.2.2'
10
- SHA512 = '2.16.840.1.101.3.4.2.3'
11
- # endregion
12
-
13
- # region Signature Algorithms
14
- MD2_WITH_RSA = '1.2.840.113549.1.1.2'
15
- MD5_WITH_RSA = '1.2.840.113549.1.1.4'
16
- SHA1_WITH_RSA = '1.2.840.113549.1.1.5'
17
- SHA256_WITH_RSA = '1.2.840.113549.1.1.11'
18
- SHA384_WITH_RSA = '1.2.840.113549.1.1.12'
19
- SHA512_WITH_RSA = '1.2.840.113549.1.1.13'
20
-
21
- SHA1_WITH_DSA = '1.2.840.10040.4.3' # RFC 3279 section 2.2.2
22
- # SHA224_WITH_DSA = '2.16.840.1.101.3.4.3.1' # RFC 5758 section 3.1
23
- SHA256_WITH_DSA = '2.16.840.1.101.3.4.3.2' # RFC 5758 section 3.1
24
- # endregion
25
-
26
- # region Asymmetric Algorithms
27
- RSA = '1.2.840.113549.1.1.1' # RFC 3279 section 2.3.1
28
- DSA = '1.2.840.10040.4.1' # RFC 3279 section 2.3.2
29
- # endregion
30
- end
1
+ module PkiExpress
2
+
3
+ class Oids < Enum
4
+ # region Digest Algorithms
5
+ MD5 = '1.2.840.113549.2.5'
6
+ SHA1 = '1.3.14.3.2.26'
7
+ # SHA224 = '2.16.840.1.101.3.4.2.4', # RFC 3874 section 4
8
+ SHA256 = '2.16.840.1.101.3.4.2.1'
9
+ SHA384 = '2.16.840.1.101.3.4.2.2'
10
+ SHA512 = '2.16.840.1.101.3.4.2.3'
11
+ # endregion
12
+
13
+ # region Signature Algorithms
14
+ MD2_WITH_RSA = '1.2.840.113549.1.1.2'
15
+ MD5_WITH_RSA = '1.2.840.113549.1.1.4'
16
+ SHA1_WITH_RSA = '1.2.840.113549.1.1.5'
17
+ SHA256_WITH_RSA = '1.2.840.113549.1.1.11'
18
+ SHA384_WITH_RSA = '1.2.840.113549.1.1.12'
19
+ SHA512_WITH_RSA = '1.2.840.113549.1.1.13'
20
+
21
+ SHA1_WITH_DSA = '1.2.840.10040.4.3' # RFC 3279 section 2.2.2
22
+ # SHA224_WITH_DSA = '2.16.840.1.101.3.4.3.1' # RFC 5758 section 3.1
23
+ SHA256_WITH_DSA = '2.16.840.1.101.3.4.3.2' # RFC 5758 section 3.1
24
+ # endregion
25
+
26
+ # region Asymmetric Algorithms
27
+ RSA = '1.2.840.113549.1.1.1' # RFC 3279 section 2.3.1
28
+ DSA = '1.2.840.10040.4.1' # RFC 3279 section 2.3.2
29
+ # endregion
30
+ end
31
31
  end
@@ -1,8 +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
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
8
  end
@@ -1,9 +1,9 @@
1
- module PkiExpress
2
- class PadesHorizontalAlign < Enum
3
- LEFT = 'Left'
4
- CENTER = 'Center'
5
- RIGHT = 'Right'
6
-
7
- VALUES = [ LEFT, CENTER, RIGHT ]
8
- end
9
- end
1
+ module PkiExpress
2
+ class PadesHorizontalAlign < Enum
3
+ LEFT = 'Left'
4
+ CENTER = 'Center'
5
+ RIGHT = 'Right'
6
+
7
+ VALUES = [ LEFT, CENTER, RIGHT ]
8
+ end
9
+ end
@@ -1,8 +1,8 @@
1
- module PkiExpress
2
- class PadesMeasurementUnits < Enum
3
- CENTIMETERS = 'Centimeters'
4
- PDF_POINTS = 'PdfPoints'
5
-
6
- VALUES = [ CENTIMETERS, PDF_POINTS ]
7
- end
8
- end
1
+ module PkiExpress
2
+ class PadesMeasurementUnits < Enum
3
+ CENTIMETERS = 'Centimeters'
4
+ PDF_POINTS = 'PdfPoints'
5
+
6
+ VALUES = [ CENTIMETERS, PDF_POINTS ]
7
+ end
8
+ end
@@ -1,51 +1,51 @@
1
- module PkiExpress
2
- class PadesPageOptimization
3
- attr_reader :custom_paper_size, :paper_size, :page_orientation
4
-
5
- def initialize(paper_size=nil, custom_paper_size=nil)
6
- @page_orientation = PadesPageOrientation::AUTO
7
- if custom_paper_size
8
- @paper_size = PadesPaperSize::CUSTOM
9
- @custom_paper_size = custom_paper_size
10
- else
11
- @paper_size = paper_size
12
- end
13
- end
14
-
15
- def custom_paper_size=(value)
16
- @custom_paper_size = value
17
- @paper_size = PadesPaperSize::CUSTOM
18
- end
19
-
20
- def paper_size=(value)
21
- unless PadesPaperSize.contains?(value)
22
- raise 'The provided "paper_size" is not valid. Try using PadesPaperSize constants'
23
- end
24
- @paper_size = value
25
- end
26
-
27
- def page_orientation=(value)
28
- unless PadesPageOrientation.contains?(value)
29
- raise 'The provided "page_orientation" is not valid. Try using PadesPageOrientation constants'
30
- end
31
- @page_orientation = value
32
- end
33
-
34
- def to_model
35
- custom_paper_size = nil
36
- if @paper_size == PadesPaperSize::CUSTOM
37
- if @custom_paper_size
38
- custom_paper_size = @custom_paper_size&.to_model
39
- else
40
- raise 'paper_size is set to :custom but no custom_paper_size was set'
41
- end
42
- end
43
-
44
- {
45
- 'pageSize': @paper_size,
46
- 'customPageSize': custom_paper_size,
47
- 'pageOrientation': @page_orientation,
48
- }
49
- end
50
- end
1
+ module PkiExpress
2
+ class PadesPageOptimization
3
+ attr_reader :custom_paper_size, :paper_size, :page_orientation
4
+
5
+ def initialize(paper_size=nil, custom_paper_size=nil)
6
+ @page_orientation = PadesPageOrientation::AUTO
7
+ if custom_paper_size
8
+ @paper_size = PadesPaperSize::CUSTOM
9
+ @custom_paper_size = custom_paper_size
10
+ else
11
+ @paper_size = paper_size
12
+ end
13
+ end
14
+
15
+ def custom_paper_size=(value)
16
+ @custom_paper_size = value
17
+ @paper_size = PadesPaperSize::CUSTOM
18
+ end
19
+
20
+ def paper_size=(value)
21
+ unless PadesPaperSize.contains?(value)
22
+ raise 'The provided "paper_size" is not valid. Try using PadesPaperSize constants'
23
+ end
24
+ @paper_size = value
25
+ end
26
+
27
+ def page_orientation=(value)
28
+ unless PadesPageOrientation.contains?(value)
29
+ raise 'The provided "page_orientation" is not valid. Try using PadesPageOrientation constants'
30
+ end
31
+ @page_orientation = value
32
+ end
33
+
34
+ def to_model
35
+ custom_paper_size = nil
36
+ if @paper_size == PadesPaperSize::CUSTOM
37
+ if @custom_paper_size
38
+ custom_paper_size = @custom_paper_size&.to_model
39
+ else
40
+ raise 'paper_size is set to :custom but no custom_paper_size was set'
41
+ end
42
+ end
43
+
44
+ {
45
+ 'pageSize': @paper_size,
46
+ 'customPageSize': custom_paper_size,
47
+ 'pageOrientation': @page_orientation,
48
+ }
49
+ end
50
+ end
51
51
  end
@@ -1,9 +1,9 @@
1
- module PkiExpress
2
- class PadesPageOrientation < Enum
3
- AUTO = 'Auto'
4
- PORTRAIT = 'Portrait'
5
- LANDSCAPE = 'Landscape'
6
-
7
- VALUES = [ AUTO, PORTRAIT, LANDSCAPE ]
8
- end
9
- end
1
+ module PkiExpress
2
+ class PadesPageOrientation < Enum
3
+ AUTO = 'Auto'
4
+ PORTRAIT = 'Portrait'
5
+ LANDSCAPE = 'Landscape'
6
+
7
+ VALUES = [ AUTO, PORTRAIT, LANDSCAPE ]
8
+ end
9
+ end
@@ -1,21 +1,21 @@
1
- module PkiExpress
2
- class PadesPaperSize < Enum
3
- CUSTOM = 'Custom'
4
- A0 = 'A0'
5
- A1 = 'A1'
6
- A2 = 'A2'
7
- A3 = 'A3'
8
- A4 = 'A4'
9
- A5 = 'A5'
10
- A6 = 'A6'
11
- A7 = 'A7'
12
- A8 = 'A8'
13
- LETTER = 'Letter'
14
- LEGAL = 'Legal'
15
- LEDGER = 'Ledger'
16
-
17
- VALUES = [
18
- CUSTOM, A0, A1, A2, A3, A4, A5, A6, A7, A8, LETTER, LEGAL, LEDGER
19
- ]
20
- end
21
- end
1
+ module PkiExpress
2
+ class PadesPaperSize < Enum
3
+ CUSTOM = 'Custom'
4
+ A0 = 'A0'
5
+ A1 = 'A1'
6
+ A2 = 'A2'
7
+ A3 = 'A3'
8
+ A4 = 'A4'
9
+ A5 = 'A5'
10
+ A6 = 'A6'
11
+ A7 = 'A7'
12
+ A8 = 'A8'
13
+ LETTER = 'Letter'
14
+ LEGAL = 'Legal'
15
+ LEDGER = 'Ledger'
16
+
17
+ VALUES = [
18
+ CUSTOM, A0, A1, A2, A3, A4, A5, A6, A7, A8, LETTER, LEGAL, LEDGER
19
+ ]
20
+ end
21
+ end
@@ -1,17 +1,17 @@
1
- module PkiExpress
2
- class PadesSignature
3
- attr_accessor :signers
4
-
5
- def initialize(model)
6
- @signers = []
7
-
8
- unless model.nil?
9
- signers = model.fetch(:signers)
10
- if signers
11
- @signers = signers.map { |s| PadesSignerInfo.new(s) }
12
- end
13
- end
14
- end
15
-
16
- end
1
+ module PkiExpress
2
+ class PadesSignature
3
+ attr_accessor :signers
4
+
5
+ def initialize(model)
6
+ @signers = []
7
+
8
+ unless model.nil?
9
+ signers = model.fetch(:signers)
10
+ if signers
11
+ @signers = signers.map { |s| PadesSignerInfo.new(s) }
12
+ end
13
+ end
14
+ end
15
+
16
+ end
17
17
  end
@@ -1,31 +1,31 @@
1
- module PkiExpress
2
- class PadesSignatureExplorer < SignatureExplorer
3
-
4
- def initialize(config=PkiExpressConfig.new)
5
- super(config)
6
- end
7
-
8
- def open()
9
- if @signature_file_path.nil?
10
- raise 'The signature file was not set'
11
- end
12
-
13
- args = [@signature_file_path]
14
-
15
- # Verify and add common options
16
- verify_and_add_common_options(args)
17
-
18
- # This operation can only be used on versions greater
19
- # than 1.3 of the PKI Express.
20
- @version_manager.require_version('1.3')
21
-
22
- # Invoke command.
23
- result = invoke(Commands::OPEN_PADES, args)
24
-
25
- # Parse output and return model.
26
- model = parse_output(result)
27
- PadesSignature.new(model)
28
- end
29
-
30
- end
1
+ module PkiExpress
2
+ class PadesSignatureExplorer < SignatureExplorer
3
+
4
+ def initialize(config=PkiExpressConfig.new)
5
+ super(config)
6
+ end
7
+
8
+ def open()
9
+ if @signature_file_path.nil?
10
+ raise 'The signature file was not set'
11
+ end
12
+
13
+ args = [@signature_file_path]
14
+
15
+ # Verify and add common options
16
+ verify_and_add_common_options(args)
17
+
18
+ # This operation can only be used on versions greater
19
+ # than 1.3 of the PKI Express.
20
+ @version_manager.require_version('1.3')
21
+
22
+ # Invoke command.
23
+ result = invoke(Commands::OPEN_PADES, args)
24
+
25
+ # Parse output and return model.
26
+ model = parse_output(result)
27
+ PadesSignature.new(model)
28
+ end
29
+
30
+ end
31
31
  end