signature_dfe 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c5df7794b36da0a69173cfdf4cbd3a83c77d5d51081e36fb5efc11a730388f9
4
- data.tar.gz: 25ba27c0d7e9eb59b7c23d70fa5ec93d14a33ce0253981d7f13a1dc5b9cc63f9
3
+ metadata.gz: ebe21fdf284216178ca792906a643e8246cd96a9b4cf948729343b7e015a4a82
4
+ data.tar.gz: 87db1c580cee2c5bd9ac8800a12780e033da743e6ee22ec2f874932b7225a1eb
5
5
  SHA512:
6
- metadata.gz: 955a8199f01e01364700e335208569bceda0795253c5d5d8c90f9ffea9583ef25300a6e95720ab2672a8a18695258693ac5cd5113ec81e6e307d229af910290f
7
- data.tar.gz: c36af271b3bdb03c715484f0039a8c23326d16e91fbd753027e3f3626834bfd750d76a605f72d7b40e7348acbfeabb671737ca65e5a528221e228a53c321e474
6
+ metadata.gz: ea69d110856af0bcb6afa790a475edd8f37aeefb711c536393fc561075aa5cf7c6b449829697c8d3b1f6b5ef69494609c1b2608c950927b61215eb0364f2dd04
7
+ data.tar.gz: 13a849a8fb96bc6ff76400ec698d3000838e911f28f8c47ed9c18d659a8b0351a7a1b4dafefc6b51660903fe364efb2a0e071d2d3992ab6257df2b92ef534c46
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
+ .DS_Store
2
+ *.gem
1
3
  /.bundle/
2
4
  /.yardoc
3
5
  /_yardoc/
data/.travis.yml CHANGED
@@ -3,5 +3,5 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.5.1
6
+ - 2.6.0
7
7
  before_install: gem install bundler -v 1.17.3
data/CHANGELOG CHANGED
@@ -0,0 +1,2 @@
1
+ v 0.1.1
2
+ - add NF-e NFA-e NFC-e
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ signature_dfe (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ ipaddr (1.2.2)
11
+ mini_portile2 (2.4.0)
12
+ nokogiri (1.9.1)
13
+ mini_portile2 (~> 2.4.0)
14
+ openssl (2.1.2)
15
+ ipaddr
16
+ rake (10.5.0)
17
+ rspec (3.8.0)
18
+ rspec-core (~> 3.8.0)
19
+ rspec-expectations (~> 3.8.0)
20
+ rspec-mocks (~> 3.8.0)
21
+ rspec-core (3.8.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-expectations (3.8.2)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-mocks (3.8.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-support (3.8.0)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 1.17)
36
+ nokogiri (~> 1.9.1)
37
+ openssl (~> 2.1.2)
38
+ rake (~> 10.0)
39
+ rspec (~> 3.0)
40
+ signature_dfe!
41
+
42
+ BUNDLED WITH
43
+ 1.17.2
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # SignatureDfe
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/signature_dfe`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Assinatura digital de documentos fiscais eletrônicos (DF-e)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
5
 
7
- ## Installation
6
+ ## Descrição
7
+
8
+ Assine seu DF-e de forma rápida e fácil
9
+
10
+ ## Instalação
8
11
 
9
12
  Add this line to your application's Gemfile:
10
13
 
@@ -20,19 +23,85 @@ Or install it yourself as:
20
23
 
21
24
  $ gem install signature_dfe
22
25
 
23
- ## Usage
26
+ ## Usando
27
+
28
+ Você vai precisar do certificado PKCS12 ou da chave privada e o certificado público.
29
+
30
+ No caso de você ter o arquivo PKCS12
31
+
32
+ ```ruby
33
+ SignatureDfe::SSL.config.pkcs12 = "caminho/para/seu/cert.p12"
34
+ SignatureDfe::SSL.config.password = "sua_senha"
35
+ ```
36
+
37
+ Já se vc usa a chave privada e o certificado separado
38
+
39
+ ```ruby
40
+ SignatureDfe::SSL.config.pkey = "caminho/para/sua/chave_privada.pem"
41
+ SignatureDfe::SSL.config.password = "sua_senha"
42
+ SignatureDfe::SSL.config.cert. = "caminho/para/seu/certificado_publico.pem"
43
+ ```
44
+
45
+ Feito esta configuração você testa, no cado se tudo certo, o resultado será true
46
+
47
+ ```ruby
48
+ SignatureDfe::SSL.test
49
+ ```
24
50
 
25
- TODO: Write usage instructions here
51
+ Feito esta configuração vc já está pronto para assinar seus documentos.
26
52
 
27
- ## Development
53
+ ## Assinatura digital NF-e NFC-e e NFA-e
28
54
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
55
+ Observe que os 3 documentos possuem a mesma estrutura
56
+ Para assinar sua nf-e existem duas formas
30
57
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+ A forma qual vc tem a xml da assinautra completo onde vc passa o seu xml contendo a tag <b>infNFe</b>
32
59
 
33
- ## Contributing
60
+ ```ruby
61
+ inf_nfe = %{
62
+ <infNFe Id="NFe00000000000000000000000000000000000000000000" versao="3.10">
63
+ ...
64
+ </infNFe>}
65
+ SignatureDfe::NFe.sign inf_nfe
66
+ ```
34
67
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/signature_dfe. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
68
+ Onde a resposta será
69
+
70
+ ```xml
71
+ <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
72
+ <SignedInfo>
73
+ <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
74
+ <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
75
+ <Reference URI="#NFe#{ch_nfe}">
76
+ <Transforms>
77
+ <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
78
+ <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
79
+ </Transforms>
80
+ <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
81
+ <DigestValue>...</DigestValue>
82
+ </Reference>
83
+ </SignedInfo>
84
+ <SignatureValue>...</SignatureValue>
85
+ <KeyInfo>
86
+ <X509Data>
87
+ <X509Certificate>...</X509Certificate>
88
+ </X509Data>
89
+ </KeyInfo>
90
+ </Signature>
91
+ ```
92
+
93
+ Ou você pode obter os valores do <b>DigestValue</b>, <b>SignatureValue</b> e <b>X509Certificate</b> manualmente, e assim montar da forma como desejar seu xml
94
+
95
+ ```ruby
96
+ inf_nfe = %{
97
+ <infNFe Id="NFe00000000000000000000000000000000000000000000" versao="3.10">
98
+ ...
99
+ </infNFe>}
100
+ ch_nfe = "0000000000000000000000000000000000000000000"
101
+ digest_value = SignatureDfe::NFe.digest_value inf_nfe
102
+ signature_value = SignatureDfe::NFe.signature_value ch_nfe, digest_value
103
+ x509certificate = SignatureDfe::SSL.cert
104
+ ```
36
105
 
37
106
  ## License
38
107
 
Binary file
@@ -0,0 +1,23 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDxjCCAq4CCQC4OYuPO6x6fTANBgkqhkiG9w0BAQsFADCBpDELMAkGA1UEBhMC
3
+ VVMxETAPBgNVBAgMCE5ldyBZb3JrMREwDwYDVQQHDAhOZXcgWW9yazELMAkGA1UE
4
+ CgwCSVQxFTAT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KpUxrMPoIf3wbmWo
20
+ +s9qP+1lAK3eszg5OEoYKqSikp4ycsv3WiBAG5+emsHJaXG5TnwgvRjbp8iAyAzb
21
+ a2AaAMbtFd3GNT+/bsgMjhGTGI8RVV4QBTNeWlkVdV0VSGsjk7DGcBx5Vs8+LVBk
22
+ S8JTXOld2Ha+5w==
23
+ -----END CERTIFICATE-----
data/certs/gen.sh ADDED
@@ -0,0 +1,4 @@
1
+ openssl req -newkey rsa:2048 -keyout key.pem -x509 -days 365 -out certificate.pem -subj '/C=US/ST=New York/L=New York/O=IT/OU=Hosting Team/CN=www.domain.com/emailAddress=your@email.com/subjectAltName=domain.com'
2
+ openssl x509 -text -noout -in certificate.pem
3
+ openssl pkcs12 -inkey key.pem -in certificate.pem -export -out certificate.p12
4
+ openssl pkcs12 -in certificate.p12 -noout -info
data/certs/key.pem ADDED
@@ -0,0 +1,30 @@
1
+ -----BEGIN ENCRYPTED PRIVATE KEY-----
2
+ MIIFDzBJBgkqhkiG9w0BBQ0wPDAbBgkqhkiG9w0BBQwwDgQIfdH+OnVlAl0CAggA
3
+ MB0GCWCGSAFlAwQBKgQQNVqjaefmKGLOl69iTgEOvwSCBMAUd8z+tT9fAiPkCdy1
4
+ T2fJikEADxVgy20tLRJsCR0gQtgL/eGqFY6TSxPBfXFVB1J8W4QyWis9BylxqR/7
5
+ qrcr639kytlu8948TsSuoj6I1kdw82cc4rSj8VWeoZvuuOMBQHFNXh4DzLPxtFwO
6
+ 2bijtakoCV+ptlP70VydAgNxHaybUXi4zzeKt+TZtPzJaNHNEJRXLGOc9kwqCV+h
7
+ kLmiLSwegW8P0bmEpUV2M28XUDH15uBIsPRv/hOpte2c1saHUw4y2oEdn1A5GAqg
8
+ wuiqZxOeNIJr6CcOPjNxvRF+dhwr5czSShalloI8pfq/NhlqHChkZEcyuQW/8mUA
9
+ Y/w3mOi8pNnbQ8YCn3HE2xF70TB0SH07IMJoqMzfftCUa+rsKFl7o9wuY6Z+TqC6
10
+ MYzQ3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fRWN9W6lBzSrhaJAu+51t7yDM
26
+ aInAjxqVazDU0LMKXve2DOzVAe1JtxKZ3WtIzv1iDsIJwf+k+Ct1iv/1LNmNUY4q
27
+ P3bw31mra5/v0iC95d+fuR9t05fRApksehxFqKVUA10rdiTZYadk+g/Uy8G6vcs0
28
+ MeiTiS/TLFltbjx6vBNuSNv1dGmEQFjX/a/hBmctEMn9cljciF+Qn1sEt3+SBdE/
29
+ cwSZ
30
+ -----END ENCRYPTED PRIVATE KEY-----
@@ -0,0 +1,67 @@
1
+ require 'base64'
2
+ require 'nokogiri'
3
+ module SignatureDfe
4
+ class NFe
5
+ def self.sign something
6
+ if something.is_a? String
7
+ digest_value_ = digest_value something
8
+
9
+ ch_nfe = something.scan(/\<infnfe[\s\S]*?\>/i)[0].scan(/\d{44}/)[0]
10
+
11
+ signature_value_ = signature_value ch_nfe, digest_value_
12
+
13
+ %{<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
14
+ <SignedInfo>
15
+ <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
16
+ <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
17
+ <Reference URI="#NFe#{ch_nfe}">
18
+ <Transforms>
19
+ <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
20
+ <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
21
+ </Transforms>
22
+ <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
23
+ <DigestValue>#{digest_value_}</DigestValue>
24
+ </Reference>
25
+ </SignedInfo>
26
+ <SignatureValue>#{signature_value_}</SignatureValue>
27
+ <KeyInfo>
28
+ <X509Data>
29
+ <X509Certificate>#{SignatureDfe::SSL.cert.to_s.gsub(/\-\-\-\-\-[A-Z]+ CERTIFICATE\-\-\-\-\-/, "").strip}</X509Certificate>
30
+ </X509Data>
31
+ </KeyInfo>
32
+ </Signature>}.gsub(/\>\s{1,}\</,"><").strip
33
+ end
34
+ end
35
+
36
+ def self.canonize_inf_nfe inf_nfe
37
+ tag_inf_nfe = inf_nfe.scan(/\<infnfe[\s\S]*?\>/i)[0]
38
+ SignatureDfe.canonize(tag_inf_nfe.include?(%{xmlns="http://www.portalfiscal.inf.br/nfe"}) ? tag_inf_nfe : inf_nfe.gsub(%{<infNFe},%{<infNFe xmlns="http://www.portalfiscal.inf.br/nfe"}))
39
+ end
40
+
41
+ def self.signature_value ch_nfe, digest_value
42
+ signed_info = %{
43
+ <SignedInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
44
+ <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
45
+ <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
46
+ <Reference URI="#NFe#{ch_nfe}">
47
+ <Transforms>
48
+ <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
49
+ <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
50
+ </Transforms>
51
+ <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
52
+ <DigestValue>#{digest_value}</DigestValue>
53
+ </Reference>
54
+ </SignedInfo>
55
+ }
56
+ signed_info_canonized = SignatureDfe.canonize signed_info
57
+ Base64.encode64(SignatureDfe::SSL.sign signed_info_canonized).strip
58
+ end
59
+
60
+ def self.digest_value something
61
+ inf_nfe = something.scan(/\<infnfe[\s\S]*?\<\/infnfe\>/i)[0].gsub(/>\s+</,"><")
62
+ inf_nfe_canonized = canonize_inf_nfe inf_nfe
63
+ Base64.encode64(OpenSSL::Digest::SHA1.digest(inf_nfe_canonized)).strip
64
+ end
65
+ private_class_method :canonize_inf_nfe
66
+ end
67
+ end
@@ -0,0 +1,81 @@
1
+ module SignatureDfe
2
+ class Config
3
+ include AbstractClass
4
+
5
+ attr_accessor :pkcs12, :pkey, :cert
6
+
7
+ attr_writer :password
8
+
9
+ def initialize
10
+ @pkcs12 = nil
11
+ @pkey = nil
12
+ @cert = nil
13
+ @password = nil
14
+ end
15
+
16
+ def inspect
17
+ super.gsub(/\, \@pass[\s\S]*?\>/,">")
18
+ end
19
+
20
+ def instance_variables
21
+ super-[:@password]
22
+ end
23
+ end
24
+
25
+ class SSL
26
+ include AbstractClass
27
+
28
+ @@config = Config.new
29
+
30
+ def self.config
31
+ @@config
32
+ end
33
+
34
+ def self.sign content, sign_method=OpenSSL::Digest::SHA1.new
35
+ self.test unless defined?(@@pk)
36
+ @@pk.sign sign_method, content
37
+ end
38
+
39
+ def self.cert
40
+ self.test unless defined?(@@pk)
41
+ if @@pk.is_a? OpenSSL::PKCS12
42
+ @@pk.certificate
43
+ else
44
+ @@cert.to_s.gsub(/\-\-\-\-\-[A-Z]+ CERTIFICATE\-\-\-\-\-/, "").strip
45
+ end
46
+ end
47
+
48
+ def self.test
49
+ raise SignatureDfe::Error.new "You must be set up pkcs12 or pkey" if (config.pkcs12 == nil || config.pkcs12.empty?) and (config.pkey == nil || config.pkey.empty?)
50
+ if config.pkcs12
51
+ if File.exist? config.pkcs12
52
+ begin
53
+ @@pk = OpenSSL::PKCS12.new File.read(config.pkcs12), config.instance_variable_get(:@password)
54
+ rescue OpenSSL::PKCS12::PKCS12Error => e
55
+ raise SignatureDfe::Error.new "Wrong password for '#{config.pkcs12}'"
56
+ end
57
+ else
58
+ raise SignatureDfe::Error.new "Your pkcs12 '#{config.pkcs12}' is not a valid file"
59
+ end
60
+ elsif config.pkey
61
+ if File.exist? config.pkey
62
+ begin
63
+ @@pk = OpenSSL::PKey::RSA.new File.read(config.pkey), config.instance_variable_get(:@password)
64
+ begin
65
+ raise SignatureDfe::Error.new "You must be set up the cert if you chose use pkey" if config.cert == nil || config.cert.empty?
66
+ raise SignatureDfe::Error.new "Your cert '#{config.cert}' is not a valid file" unless File.exist? config.cert
67
+ @@cert = OpenSSL::X509::Certificate.new(File.read(config.cert))
68
+ rescue OpenSSL::X509::CertificateError => e
69
+ raise SignatureDfe::Error.new "Your cert '#{config.cert}' is not a valid file"
70
+ end
71
+ rescue OpenSSL::PKey::RSAError => e
72
+ raise SignatureDfe::Error.new "Wrong password for '#{config.pkey}'"
73
+ end
74
+ else
75
+ raise SignatureDfe::Error.new "Your pkey '#{config.pkey}' is not a valid file"
76
+ end
77
+ end
78
+ true
79
+ end
80
+ end
81
+ end
@@ -1,3 +1,3 @@
1
1
  module SignatureDfe
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/signature_dfe.rb CHANGED
@@ -1,6 +1,19 @@
1
1
  require "signature_dfe/version"
2
+ require "openssl"
2
3
 
3
4
  module SignatureDfe
4
- class Error < StandardError; end
5
- # Your code goes here...
5
+ class Error < StandardError; end
6
+
7
+ module AbstractClass
8
+ def initialize
9
+ raise "this is a abstract class"
10
+ end
11
+ end
12
+
13
+ def self.canonize xml, canonize_method=Nokogiri::XML::XML_C14N_1_1
14
+ Nokogiri::XML(xml.gsub(/>\s+</,"><")).canonicalize(canonize_method)
15
+ end
6
16
  end
17
+
18
+ require "signature_dfe/ssl"
19
+ require "signature_dfe/nfe"
@@ -23,8 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.metadata["source_code_uri"] = "https://github.com/thiaguerd/signature_dfe"
24
24
  spec.metadata["changelog_uri"] = "https://github.com/thiaguerd/signature_dfe/blob/master/CHANGELOG"
25
25
  else
26
- raise "RubyGems 2.0 or newer is required to protect against " \
27
- "public gem pushes."
26
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
28
27
  end
29
28
 
30
29
  # Specify which files should be added to the gem when it is released.
@@ -39,4 +38,6 @@ Gem::Specification.new do |spec|
39
38
  spec.add_development_dependency "bundler", "~> 1.17"
40
39
  spec.add_development_dependency "rake", "~> 10.0"
41
40
  spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "openssl", "~> 2.1.2"
42
+ spec.add_development_dependency "nokogiri", "~> 1.9.1"
42
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: signature_dfe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Feitosa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-04 00:00:00.000000000 Z
11
+ date: 2019-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: openssl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.1.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.9.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.9.1
55
83
  description: Assinatura digital de NF-e NFC-e NFA-e CT-e MDF-e BP-e
56
84
  email:
57
85
  - mail@thiago.pro
@@ -65,12 +93,19 @@ files:
65
93
  - CHANGELOG
66
94
  - CODE_OF_CONDUCT.md
67
95
  - Gemfile
96
+ - Gemfile.lock
68
97
  - LICENSE.txt
69
98
  - README.md
70
99
  - Rakefile
71
100
  - bin/console
72
101
  - bin/setup
102
+ - certs/certificate.p12
103
+ - certs/certificate.pem
104
+ - certs/gen.sh
105
+ - certs/key.pem
73
106
  - lib/signature_dfe.rb
107
+ - lib/signature_dfe/nfe.rb
108
+ - lib/signature_dfe/ssl.rb
74
109
  - lib/signature_dfe/version.rb
75
110
  - signature_dfe.gemspec
76
111
  homepage: https://github.com/thiaguerd/signature_dfe
@@ -96,8 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
131
  - !ruby/object:Gem::Version
97
132
  version: '0'
98
133
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.7.7
134
+ rubygems_version: 3.0.1
101
135
  signing_key:
102
136
  specification_version: 4
103
137
  summary: Assinatura digital de documentos fiscais eletrônicos