rest_pki 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/README.md +6 -1
  4. data/lib/rest_pki.rb +32 -0
  5. data/lib/rest_pki/cades_signature.rb +52 -0
  6. data/lib/rest_pki/color.rb +37 -0
  7. data/lib/rest_pki/digest_algorithm.rb +158 -0
  8. data/lib/rest_pki/digest_algorithm_and_value.rb +29 -0
  9. data/lib/rest_pki/oids.rb +163 -0
  10. data/lib/rest_pki/pades_measurement_units.rb +6 -0
  11. data/lib/rest_pki/pades_page_orientation.rb +7 -0
  12. data/lib/rest_pki/pades_paper_size.rb +17 -0
  13. data/lib/rest_pki/pades_signature_explorer.rb +17 -0
  14. data/lib/rest_pki/pades_signer_info.rb +11 -0
  15. data/lib/rest_pki/pades_size.rb +17 -0
  16. data/lib/rest_pki/pades_visual_rectangle.rb +25 -0
  17. data/lib/rest_pki/page_optimization.rb +34 -0
  18. data/lib/rest_pki/pdf_container_definition.rb +266 -0
  19. data/lib/rest_pki/pdf_helper.rb +29 -0
  20. data/lib/rest_pki/pdf_mark.rb +81 -0
  21. data/lib/rest_pki/pdf_mark_element.rb +54 -0
  22. data/lib/rest_pki/pdf_mark_element_type.rb +7 -0
  23. data/lib/rest_pki/pdf_mark_image.rb +25 -0
  24. data/lib/rest_pki/pdf_mark_image_element.rb +33 -0
  25. data/lib/rest_pki/pdf_mark_page_options.rb +8 -0
  26. data/lib/rest_pki/pdf_mark_qr_code_element.rb +32 -0
  27. data/lib/rest_pki/pdf_mark_text_element.rb +47 -0
  28. data/lib/rest_pki/pdf_marker.rb +61 -0
  29. data/lib/rest_pki/pdf_text_section.rb +57 -0
  30. data/lib/rest_pki/pdf_text_style.rb +7 -0
  31. data/lib/rest_pki/pk_algorithms.rb +173 -0
  32. data/lib/rest_pki/pk_certificate.rb +99 -0
  33. data/lib/rest_pki/resource_content_or_reference.rb +25 -0
  34. data/lib/rest_pki/resources/pades_explorer_model.rb +12 -0
  35. data/lib/rest_pki/resources/pdf_marker_model.rb +12 -0
  36. data/lib/rest_pki/signature_algorithm_and_value.rb +11 -0
  37. data/lib/rest_pki/signature_explorer.rb +48 -0
  38. data/lib/rest_pki/signature_policy_identifier.rb +10 -0
  39. data/lib/rest_pki/validation_item.rb +2 -2
  40. data/lib/rest_pki/validation_results.rb +11 -11
  41. data/lib/rest_pki/version.rb +1 -1
  42. metadata +37 -3
@@ -0,0 +1,99 @@
1
+ module RestPki
2
+ class PKCertificate
3
+ attr_reader :email_address, :serial_number, :validity_start, :validity_end, :subject_name
4
+ attr_reader :issuer_name, :pki_brazil, :pki_italy, :issuer
5
+ def initialize(model)
6
+ @email_address = model['emailAddress']
7
+ @serial_number = model['serialNumber']
8
+ @validity_start = model['validityStart']
9
+ @validity_end = model['validityEnd']
10
+
11
+ if model['subjectName']
12
+ @subject_name = Name.new(model['subjectName'])
13
+ end
14
+
15
+ if model['issuerName']
16
+ @issuer_name = Name.new(model['issuerName'])
17
+ end
18
+
19
+ if model['pkiBrazil']
20
+ @pki_brazil = PkiBrazilCertificateFields.new(model['pkiBrazil'])
21
+ end
22
+
23
+ if model['pkiItaly']
24
+ @pki_italy = PkiItalyCertificateFields.new(model['pkiItaly'])
25
+ end
26
+
27
+ if model['issuer']
28
+ @issuer = PKCertificate.new(model['issuer'])
29
+ end
30
+ end
31
+ end
32
+ class PkiItalyCertificateFields
33
+ attr_reader :certificate_type, :codice_fiscale, :id_carta
34
+ def initialize(model)
35
+ @certificate_type = model['certificateType']
36
+ @codice_fiscale = model['codiceFiscale']
37
+ @id_carta = model['idCarta']
38
+ end
39
+ end
40
+ class PkiBrazilCertificateFields
41
+ attr_reader :certificate_type, :cpf, :cnpj, :responsavel, :company_name, :oab_uf, :oab_numero
42
+ attr_reader :rg_numero, :rg_emissor, :rg_emissor_uf, :date_of_birth
43
+ def initialize(model)
44
+ @certificate_type = model['certificateType']
45
+ @cpf = model['cpf']
46
+ @cnpj = model['cnpj']
47
+ @responsavel = model['responsavel']
48
+ @company_name = model['companyName']
49
+ @oab_uf = model['oabUF']
50
+ @oab_numero = model['oabNumero']
51
+ @rg_numero = model['rgNumero']
52
+ @rg_emissor = model['rgEmissor']
53
+ @rg_emissor_uf = model['rgEmissorUF']
54
+ unless model['dateOfBirth'].to_s.empty?
55
+ @date_of_birth = Date.parse(model['dateOfBirth'])
56
+ end
57
+ end
58
+ def cpf_formatted
59
+ if @cpf.to_s.empty?
60
+ return ''
61
+ end
62
+ unless @cpf.gsub(/[.-]/, "").length == 11
63
+ return @cpf
64
+ end
65
+ @cpf.gsub(/[.-]/, "").gsub(/\A(\d{3})(\d{3})(\d{3})(\d{2})\Z/, "\\1.\\2.\\3-\\4")
66
+ end
67
+
68
+ def cnpj_formatted
69
+ if @cnpj.to_s.empty?
70
+ return ''
71
+ end
72
+ unless @cnpj.gsub(/[.-]/, "").length == 14
73
+ return @cnpj
74
+ end
75
+ @cnpj.gsub(/[.-]/, "").gsub(/\A(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})\Z/, "\\1.\\2.\\3/\\4-\\5")
76
+ end
77
+ end
78
+ class Name
79
+ attr_reader :common_name, :country, :dn_qualifier, :email_address, :generation_qualifier, :given_name, :initials
80
+ attr_reader :locality, :organization, :organization_unit, :pseudonym, :serial_number, :state_name, :surname, :title
81
+ def initialize(model)
82
+ @common_name = model['commonName']
83
+ @country = model['country']
84
+ @dn_qualifier = model['dnQualifier']
85
+ @email_address = model['emailAddress']
86
+ @generation_qualifier = model['generationQualifier']
87
+ @given_name = model['givenName']
88
+ @initials = model['initials']
89
+ @locality = model['locality']
90
+ @organization = model['organization']
91
+ @organization_unit = model['organizationUnit']
92
+ @pseudonym = model['pseudonym']
93
+ @serial_number = model['serialNumber']
94
+ @state_name = model['stateName']
95
+ @surname = model['surname']
96
+ @title = model['title']
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,25 @@
1
+ require 'base64'
2
+
3
+ module RestPki
4
+ class ResourceContentOrReference
5
+ attr_accessor :url, :mime_type, :content
6
+
7
+ def initialize
8
+ @url = nil
9
+ @mime_type = nil
10
+ @content = nil
11
+ end
12
+
13
+ def to_model
14
+ content = nil
15
+ unless @content.nil?
16
+ content = Base64.encode64(@content)
17
+ end
18
+ {
19
+ url: @url,
20
+ mimeType: @mime_type,
21
+ content: content,
22
+ }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,12 @@
1
+ module RestPki
2
+ class PadesExplorerModel
3
+ attr_reader :signers
4
+
5
+ def initialize(model, _)
6
+ @signers = []
7
+ model['signers'].each { |signer|
8
+ @signers.push(PadesSignerInfo.new(signer))
9
+ }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'base64'
2
+ module RestPki
3
+ class PdfMarkerModel
4
+ attr_reader :file_content, :mime_type
5
+
6
+ def initialize(model, _)
7
+ file = model['file']
8
+ @file_content = Base64.decode64(file['content'])
9
+ @mime_type = file['mimeType']
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'base64'
2
+
3
+ module RestPki
4
+ class SignatureAlgorithmAndValue
5
+ attr_reader :algorithm, :value
6
+ def initialize(model)
7
+ @algorithm = SignatureAlgorithm.get_instance_by_api_model(model['algorithmIdentifier'])
8
+ @value = Base64.decode64(model['value'])
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,48 @@
1
+ require 'base64'
2
+
3
+ module RestPki
4
+ class SignatureExplorer
5
+ attr_accessor :default_signature_policy_id, :security_context_id, :acceptable_explicit_policies, :validate
6
+
7
+ def initialize(restpki_client)
8
+ @restpki_client = restpki_client
9
+ @signature_file_content = nil
10
+ @default_signature_policy_id = nil
11
+ @security_context_id = nil
12
+ @validate = true
13
+ @acceptable_explicit_policies = nil
14
+ end
15
+
16
+ def set_signature_file_from_path(path)
17
+ file = File.open(path, 'rb')
18
+ @signature_file_content = file.read
19
+ file.close
20
+ end
21
+
22
+ def set_signature_file_from_content_raw(content_raw)
23
+ @signature_file_content = content_raw
24
+ end
25
+
26
+ def set_signature_file_from_content_base64(content_base64)
27
+ @signature_file_content = Base64.decode64(content_base64)
28
+ end
29
+
30
+ protected
31
+ def get_request(mime_type)
32
+ request = {
33
+ validate: @validate,
34
+ securityContextId: @security_context_id,
35
+ acceptableExplicitPolicies: @acceptable_explicit_policies,
36
+ defaultSignaturePolicyId: @default_signature_policy_id
37
+ }
38
+
39
+ unless @signature_file_content.to_s.empty?
40
+ request['file'] = {
41
+ content: Base64.encode64(@signature_file_content),
42
+ mimeType: mime_type
43
+ }
44
+ end
45
+ request
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,10 @@
1
+ module RestPki
2
+ class SignaturePolicyIdentifier
3
+ attr_reader :digest, :oid, :uri
4
+ def initialize(model)
5
+ @digest = DigestAlgorithmAndValue.new(model['digest'])
6
+ @oid = model['oid']
7
+ @uri = model['uri']
8
+ end
9
+ end
10
+ end
@@ -18,13 +18,13 @@ module RestPki
18
18
  end
19
19
 
20
20
  def to_string(indentation_level)
21
- text = ''
21
+ text = ""
22
22
  text += @message
23
23
  unless @detail.to_s.blank?
24
24
  text += " (#{@detail})"
25
25
  end
26
26
  unless @inner_validation_results.nil?
27
- text += '\n'
27
+ text += "\n"
28
28
  text += @inner_validation_results.to_string(indentation_level + 1)
29
29
  end
30
30
  text
@@ -33,9 +33,9 @@ module RestPki
33
33
  end
34
34
 
35
35
  def to_string(indentation_level)
36
- tab = ''
37
- (1..indentation_level).each do; tab += '\t'; end
38
- text = ''
36
+ tab = ""
37
+ (1..indentation_level).each do; tab += "\t"; end
38
+ text = ""
39
39
  text += get_summary(indentation_level)
40
40
  if has_errors
41
41
  text += "\n#{tab}Errors:\n"
@@ -53,11 +53,11 @@ module RestPki
53
53
  end
54
54
 
55
55
  def get_summary(indentation_level=0)
56
- tab = ''
57
- (1..indentation_level).each do; tab += '\t'; end
56
+ tab = ""
57
+ (1..indentation_level).each do; tab += "\t"; end
58
58
  text = "#{tab}Validation results: "
59
59
  if get_checks_performed == 0
60
- text += 'no checks performed'
60
+ text += "no checks performed"
61
61
  else
62
62
  text += "#{get_checks_performed} checks performed"
63
63
  if has_errors
@@ -68,7 +68,7 @@ module RestPki
68
68
  end
69
69
  if has_passed_checks
70
70
  if !has_errors && !has_warnings
71
- text += ', all passed'
71
+ text += ", all passed"
72
72
  else
73
73
  text += ", #{@passed_checks.to_a.length} passed"
74
74
  end
@@ -87,16 +87,16 @@ module RestPki
87
87
  end
88
88
 
89
89
  def join_items(items, indentation_level)
90
- text = ''
90
+ text = ""
91
91
  is_first = true
92
- tab = ''
93
- (1..indentation_level).each do; tab += '\t'; end
92
+ tab = ""
93
+ (1..indentation_level).each do; tab += "\t"; end
94
94
 
95
95
  items.each do |item|
96
96
  if is_first
97
97
  is_first = false
98
98
  else
99
- text += '\n'
99
+ text += "\n"
100
100
  end
101
101
  text += "#{tab}- "
102
102
  text += item.to_string(indentation_level)
@@ -1,3 +1,3 @@
1
1
  module RestPki
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_pki
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murilo Zaffalon
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-04-11 00:00:00.000000000 Z
12
+ date: 2020-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -83,17 +83,48 @@ files:
83
83
  - Rakefile
84
84
  - lib/rest_pki.rb
85
85
  - lib/rest_pki/authentication.rb
86
+ - lib/rest_pki/cades_signature.rb
86
87
  - lib/rest_pki/cades_signature_finisher.rb
87
88
  - lib/rest_pki/cades_signature_starter.rb
89
+ - lib/rest_pki/color.rb
90
+ - lib/rest_pki/digest_algorithm.rb
91
+ - lib/rest_pki/digest_algorithm_and_value.rb
88
92
  - lib/rest_pki/full_xml_signature_starter.rb
89
93
  - lib/rest_pki/namespace_manager.rb
90
94
  - lib/rest_pki/object.rb
95
+ - lib/rest_pki/oids.rb
96
+ - lib/rest_pki/pades_measurement_units.rb
97
+ - lib/rest_pki/pades_page_orientation.rb
98
+ - lib/rest_pki/pades_paper_size.rb
99
+ - lib/rest_pki/pades_signature_explorer.rb
91
100
  - lib/rest_pki/pades_signature_finisher.rb
92
101
  - lib/rest_pki/pades_signature_starter.rb
102
+ - lib/rest_pki/pades_signer_info.rb
103
+ - lib/rest_pki/pades_size.rb
93
104
  - lib/rest_pki/pades_visual_positioning_presets.rb
105
+ - lib/rest_pki/pades_visual_rectangle.rb
106
+ - lib/rest_pki/page_optimization.rb
107
+ - lib/rest_pki/pdf_container_definition.rb
108
+ - lib/rest_pki/pdf_helper.rb
109
+ - lib/rest_pki/pdf_mark.rb
110
+ - lib/rest_pki/pdf_mark_element.rb
111
+ - lib/rest_pki/pdf_mark_element_type.rb
112
+ - lib/rest_pki/pdf_mark_image.rb
113
+ - lib/rest_pki/pdf_mark_image_element.rb
114
+ - lib/rest_pki/pdf_mark_page_options.rb
115
+ - lib/rest_pki/pdf_mark_qr_code_element.rb
116
+ - lib/rest_pki/pdf_mark_text_element.rb
117
+ - lib/rest_pki/pdf_marker.rb
118
+ - lib/rest_pki/pdf_text_section.rb
119
+ - lib/rest_pki/pdf_text_style.rb
120
+ - lib/rest_pki/pk_algorithms.rb
121
+ - lib/rest_pki/pk_certificate.rb
122
+ - lib/rest_pki/resource_content_or_reference.rb
94
123
  - lib/rest_pki/resources/authentication_model.rb
95
124
  - lib/rest_pki/resources/cades_model.rb
125
+ - lib/rest_pki/resources/pades_explorer_model.rb
96
126
  - lib/rest_pki/resources/pades_model.rb
127
+ - lib/rest_pki/resources/pdf_marker_model.rb
97
128
  - lib/rest_pki/resources/response_model.rb
98
129
  - lib/rest_pki/resources/xml_model.rb
99
130
  - lib/rest_pki/rest_base_error.rb
@@ -101,7 +132,10 @@ files:
101
132
  - lib/rest_pki/rest_unreachable_error.rb
102
133
  - lib/rest_pki/restpki_client.rb
103
134
  - lib/rest_pki/restpki_error.rb
135
+ - lib/rest_pki/signature_algorithm_and_value.rb
136
+ - lib/rest_pki/signature_explorer.rb
104
137
  - lib/rest_pki/signature_finisher.rb
138
+ - lib/rest_pki/signature_policy_identifier.rb
105
139
  - lib/rest_pki/signature_starter.rb
106
140
  - lib/rest_pki/standard_security_contexts.rb
107
141
  - lib/rest_pki/standard_signature_policies.rb
@@ -139,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
173
  version: '0'
140
174
  requirements: []
141
175
  rubyforge_project:
142
- rubygems_version: 2.7.6
176
+ rubygems_version: 2.7.6.2
143
177
  signing_key:
144
178
  specification_version: 4
145
179
  summary: Client lib for REST PKI