jrxades 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +74 -0
  9. data/Rakefile +1 -0
  10. data/java/README.TXT +32 -0
  11. data/java/lib/MITyCLibAPI-1.1.7.jar +0 -0
  12. data/java/lib/MITyCLibCert-1.1.7.jar +0 -0
  13. data/java/lib/MITyCLibCrypt-1.1.7.jar +0 -0
  14. data/java/lib/MITyCLibOCSP-1.1.7.jar +0 -0
  15. data/java/lib/MITyCLibPolicy-1.1.7.jar +0 -0
  16. data/java/lib/MITyCLibTSA-1.1.7.jar +0 -0
  17. data/java/lib/MITyCLibTrust-1.1.7.jar +0 -0
  18. data/java/lib/MITyCLibXADES-1.1.7.jar +0 -0
  19. data/java/lib/bcmail-jdk16-1.45.jar +0 -0
  20. data/java/lib/bcprov-jdk16-1.45.jar +0 -0
  21. data/java/lib/bctsp-jdk16-1.45.jar +0 -0
  22. data/java/lib/commons-codec-1.2.jar +0 -0
  23. data/java/lib/commons-httpclient-3.0.1.jar +0 -0
  24. data/java/lib/commons-lang-2.4.jar +0 -0
  25. data/java/lib/commons-logging-1.1.1.jar +0 -0
  26. data/java/lib/xml-apis-1.3.04.jar +0 -0
  27. data/java/lib/xmlsec-1.4.2-ADSI-1.0.jar +0 -0
  28. data/java/lib/xmlsec-1.4.2-ADSI-1.1.jar +0 -0
  29. data/java/sri.jar +0 -0
  30. data/jrxades.gemspec +25 -0
  31. data/lib/jrxades.rb +6 -0
  32. data/lib/jrxades/exceptions/xml_sig_exception.rb +8 -0
  33. data/lib/jrxades/version.rb +3 -0
  34. data/lib/jrxades/xml_sig.rb +51 -0
  35. data/spec/fixtures/certificate.p12 +0 -0
  36. data/spec/fixtures/certificate.pem +13 -0
  37. data/spec/fixtures/certificateRequest.csr +11 -0
  38. data/spec/fixtures/certificate_without_password.p12 +0 -0
  39. data/spec/fixtures/privateKey.pem +15 -0
  40. data/spec/fixtures/publicKey.p7b +0 -0
  41. data/spec/fixtures/testSignedFile.xml +0 -0
  42. data/spec/fixtures/text.p12 +1 -0
  43. data/spec/fixtures/unsignedFile.xml +89 -0
  44. data/spec/lib/jrxades/version_spec.rb +11 -0
  45. data/spec/lib/jrxades/xml_sig_spec.rb +116 -0
  46. data/spec/spec_helper.rb +6 -0
  47. metadata +149 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e346c67856911f3539c4548f1036ee9245073a06
4
+ data.tar.gz: ac10f941f6ca80bb56dfc4ba2f874aa154b1de60
5
+ SHA512:
6
+ metadata.gz: 5a98526bf57eea0f6ee927b4bf9f43b160e8e1cbc2ce4955b708d5101a38ade92d29d2118d4480fdc382ae4f71bb75e2602bb687a1e404cfb20370a07d845cc3
7
+ data.tar.gz: ef35794c2569a824f71341a13fe76a7067d8648f73644e151bd8268c03f2d3016c055263a8eeec0a255933b97ae49a50621ba839b9ea306d00f37a5ec6d42d3f
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1 @@
1
+ jrxades
@@ -0,0 +1 @@
1
+ jruby-9.0.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jrxades.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jose Carrion
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,74 @@
1
+ # Jrxades
2
+
3
+ Jrxades es una gema JRuby que permite firmar un documento xml con un certificado .p12,
4
+ Esta gema ha sido creada para la Facturación Electrónica que se usa en Ecuador,
5
+ sin embargo se basa en las especificaciones definidas en XADES_BES lo que permitiría ser
6
+ usada en otros ambientes que requieran XADES_BES.
7
+
8
+ ## Instalación
9
+
10
+ Agregar esta linea al archivo Gemfile
11
+
12
+ gem 'jrxades'
13
+
14
+ Luego ejecutar:
15
+
16
+ $ bundle
17
+
18
+ O instalar la gema manualmente:
19
+
20
+ $ gem install jrxades
21
+
22
+
23
+ ## Como se usa
24
+
25
+ Solo llamar directamente al metodo de la siguiente forma
26
+
27
+ Si el certificado tiene contraseña usar:
28
+
29
+ xml_sig = Jrxs::XmlSig.new(input_xml_file_path, output_xml_file_path, certificate_file_path, certificate_password)
30
+
31
+ Si el certificado no tiene contraseña, la contraseña es opcional.
32
+
33
+ xml_sig = Jrxs::XmlSig.new(input_xml_file_path, output_xml_file_path, certificate_file_path)
34
+
35
+ Esta gema tiene los siguíentes métodos
36
+
37
+ ### key_data_valid?
38
+
39
+ Verifica si un certificado p12 es válido
40
+
41
+ xml_sig.key_data_valid?
42
+
43
+ ### sign
44
+
45
+ Firma el archivo xml, y creara un archivo de salida en el directorio previamente estaablecido.
46
+
47
+ xml_sig.sign
48
+
49
+
50
+ ## Créditos
51
+
52
+ Esta gema es solo hace referencias a las clases creadas por Cristhian Carreño, quien expone en el siguiente tutorial como firmar un documento.
53
+
54
+ http://webcarreno.org/index.php/tutorials/28-sri-tutorial/24-sri-firma-digital-xades-bes
55
+
56
+ ## Para contribuir
57
+
58
+ Clonar el repositorio
59
+
60
+ $ git clone https://bitbucket.org/joselo/jrxades
61
+
62
+ Instalar JRuby
63
+
64
+ $ cd jrxades
65
+
66
+ Instalar bundler
67
+
68
+ $ gem install bundler
69
+
70
+ Ejecturar los tests.
71
+
72
+ $ rspec .
73
+
74
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ ========================
2
+ BUILD OUTPUT DESCRIPTION
3
+ ========================
4
+
5
+ When you build an Java application project that has a main class, the IDE
6
+ automatically copies all of the JAR
7
+ files on the projects classpath to your projects dist/lib folder. The IDE
8
+ also adds each of the JAR files to the Class-Path element in the application
9
+ JAR files manifest file (MANIFEST.MF).
10
+
11
+ To run the project from the command line, go to the dist folder and
12
+ type the following:
13
+
14
+ java -jar sri.jar /path/sample/certificate.p12 cErTiFicAtEPaSsWoRd /path/sample/unsignedFile.xml /path/sample outputFile.xml
15
+
16
+ To distribute this project, zip up the dist folder (including the lib folder)
17
+ and distribute the ZIP file.
18
+
19
+ Notes:
20
+
21
+ * If two JAR files on the project classpath have the same name, only the first
22
+ JAR file is copied to the lib folder.
23
+ * Only JAR files are copied to the lib folder.
24
+ If the classpath contains other types of files or folders, these files (folders)
25
+ are not copied.
26
+ * If a library on the projects classpath also has a Class-Path element
27
+ specified in the manifest,the content of the Class-Path element has to be on
28
+ the projects runtime path.
29
+ * To set a main class in a standard Java project, right-click the project node
30
+ in the Projects window and choose Properties. Then click Run and enter the
31
+ class name in the Main Class field. Alternatively, you can manually type the
32
+ class name in the manifest Main-Class element.
Binary file
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jrxades/version'
5
+ platform = "java"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "jrxades"
9
+ spec.version = Jrxades::VERSION
10
+ spec.authors = ["Jose Carrion"]
11
+ spec.email = ["joseloc@gmail.com"]
12
+ spec.summary = %q{Jrxades es una gema JRuby que permite firmar un documento xml con un certificado .p12}
13
+ spec.description = %q{Jrxades es una gema JRuby que permite firmar un documento xml con un certificado .p12, Esta gema ha sido creada para la Facturación Electrónica que se usa en Ecuador, sin embargo se basa en las especificaciones definidas en XADES_BES lo que permitiría ser usada en otros ambientes que requieran XADES_BES.}
14
+ spec.homepage = "https://github.com/joselo/jrxades"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
23
+ spec.add_development_dependency 'bundler', '~> 1.5'
24
+ spec.add_development_dependency 'rake', '~> 0'
25
+ end
@@ -0,0 +1,6 @@
1
+ require "jrxades/version"
2
+ require "jrxades/exceptions/xml_sig_exception"
3
+ require "jrxades/xml_sig"
4
+
5
+ module Jrxades
6
+ end
@@ -0,0 +1,8 @@
1
+ module Jrxades
2
+ module Exceptions
3
+
4
+ class XmlSigException < Exception
5
+ end
6
+
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Jrxades
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,51 @@
1
+ require 'java'
2
+ require File.join(File.dirname(__FILE__), '../../java/sri.jar')
3
+
4
+ java_import 'sri.XAdESBESSignature'
5
+
6
+ module Jrxades
7
+
8
+ class XmlSig
9
+
10
+ attr_accessor :key_store_path, :pass_phrase_for_key_store, :pass_phrase_for_key, :output_path, :out_file_name, :input_file_path
11
+
12
+ def initialize(input_file_path, output_file_path, key_store_path, pass_phrase_for_key_store=nil, pass_phrase_for_key=nil)
13
+ self.key_store_path = key_store_path
14
+ self.pass_phrase_for_key_store = pass_phrase_for_key_store || ''
15
+ self.pass_phrase_for_key = pass_phrase_for_key || ''
16
+ self.output_path = File.dirname(output_file_path)
17
+ self.out_file_name = File.basename(output_file_path)
18
+ self.input_file_path = input_file_path
19
+ end
20
+
21
+ def sign
22
+ XAdESBESSignature.firmar(input_file_path, key_store_path, pass_phrase_for_key_store, output_path, out_file_name)
23
+ end
24
+
25
+ def key_data_valid?
26
+ begin
27
+ sign_test
28
+ rescue Exception => e
29
+ raise Jrxades::Exceptions::XmlSigException.new(e)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def sign_test
36
+ input_test_file = File.join(File.dirname(__FILE__), '../../spec/fixtures/unsignedFile.xml')
37
+ output_test_file = File.join(File.dirname(__FILE__), '../../spec/fixtures/testSignedFile.xml')
38
+
39
+ input_file_path = input_test_file
40
+ output_path = File.dirname(output_test_file)
41
+ out_file_name = File.basename(output_test_file)
42
+
43
+ sign
44
+
45
+ File.open(output_test_file, 'w') { |f| f.print("") }
46
+ File.read(output_test_file) == ""
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,13 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICATCCAWoCCQCmCxWj/N5EUjANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB
3
+ VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0
4
+ cyBQdHkgTHRkMB4XD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----END RSA PRIVATE KEY-----
File without changes
@@ -0,0 +1 @@
1
+ This is a wrong p12 certificate it doesn't work to sing documents because it is just a text file
@@ -0,0 +1,89 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <factura id="comprobante" version="1.1.0" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://0.0.0.0:9292/xsd/factura.xsd">
3
+ <infoTributaria>
4
+ <ambiente>1</ambiente>
5
+ <tipoEmision>1</tipoEmision>
6
+ <razonSocial>José Augusto Carrión Jumbo</razonSocial>
7
+ <nombreComercial>Nationcode</nombreComercial>
8
+ <ruc>1103671804001</ruc>
9
+ <claveAcceso>1510201501110367180400110000080000000080754713012</claveAcceso>
10
+ <codDoc>01</codDoc>
11
+ <estab>001</estab>
12
+ <ptoEmi>001</ptoEmi>
13
+ <secuencial>000000008</secuencial>
14
+ <dirMatriz>Paraguay 24-38 y Nicaragua</dirMatriz>
15
+ </infoTributaria>
16
+ <infoFactura>
17
+ <fechaEmision>15/10/2015</fechaEmision>
18
+ <dirEstablecimiento>Paraguay 24-38 y Nicaragua</dirEstablecimiento>
19
+ <contribuyenteEspecial>12345</contribuyenteEspecial>
20
+ <obligadoContabilidad>SI</obligadoContabilidad>
21
+ <tipoIdentificacionComprador>05</tipoIdentificacionComprador>
22
+ <razonSocialComprador>José Carrión</razonSocialComprador>
23
+ <identificacionComprador>1103671804</identificacionComprador>
24
+ <totalSinImpuestos>16.99</totalSinImpuestos>
25
+ <totalDescuento>0.0</totalDescuento>
26
+ <totalConImpuestos>
27
+ <totalImpuesto>
28
+ <codigo>3</codigo>
29
+ <codigoPorcentaje>3092</codigoPorcentaje>
30
+ <baseImponible>15.99</baseImponible>
31
+ <valor>2.4</valor>
32
+ </totalImpuesto>
33
+ <totalImpuesto>
34
+ <codigo>2</codigo>
35
+ <codigoPorcentaje>2</codigoPorcentaje>
36
+ <baseImponible>19.39</baseImponible>
37
+ <valor>2.33</valor>
38
+ </totalImpuesto>
39
+ </totalConImpuestos>
40
+ <propina>0</propina>
41
+ <importeTotal>21.72</importeTotal>
42
+ <moneda>DOLAR</moneda>
43
+ </infoFactura>
44
+ <detalles>
45
+ <detalle>
46
+ <codigoPrincipal>1</codigoPrincipal>
47
+ <codigoAuxiliar>1</codigoAuxiliar>
48
+ <descripcion>Test Item 1</descripcion>
49
+ <cantidad>1.0</cantidad>
50
+ <precioUnitario>15.99</precioUnitario>
51
+ <descuento>0.0</descuento>
52
+ <precioTotalSinImpuesto>15.99</precioTotalSinImpuesto>
53
+ <impuestos>
54
+ <impuesto>
55
+ <codigo>3</codigo>
56
+ <codigoPorcentaje>3092</codigoPorcentaje>
57
+ <tarifa>15.0</tarifa>
58
+ <baseImponible>15.99</baseImponible>
59
+ <valor>2.4</valor>
60
+ </impuesto>
61
+ <impuesto>
62
+ <codigo>2</codigo>
63
+ <codigoPorcentaje>2</codigoPorcentaje>
64
+ <tarifa>12.0</tarifa>
65
+ <baseImponible>18.39</baseImponible>
66
+ <valor>2.21</valor>
67
+ </impuesto>
68
+ </impuestos>
69
+ </detalle>
70
+ <detalle>
71
+ <codigoPrincipal>2</codigoPrincipal>
72
+ <codigoAuxiliar>2</codigoAuxiliar>
73
+ <descripcion>Test Item 2</descripcion>
74
+ <cantidad>1.0</cantidad>
75
+ <precioUnitario>1.0</precioUnitario>
76
+ <descuento>0.0</descuento>
77
+ <precioTotalSinImpuesto>1.0</precioTotalSinImpuesto>
78
+ <impuestos>
79
+ <impuesto>
80
+ <codigo>2</codigo>
81
+ <codigoPorcentaje>2</codigoPorcentaje>
82
+ <tarifa>12.0</tarifa>
83
+ <baseImponible>1.0</baseImponible>
84
+ <valor>0.12</valor>
85
+ </impuesto>
86
+ </impuestos>
87
+ </detalle>
88
+ </detalles>
89
+ </factura>
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jrxades do
4
+
5
+ describe 'VERSION' do
6
+ it 'is not nil' do
7
+ Jrxades::VERSION.should_not be_nil
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jrxades do
4
+
5
+ # KeyData information
6
+ let(:key_store_path){ File.join(File.dirname(__FILE__), '../../fixtures/certificate.p12') }
7
+ let(:key_store_path_without_pass){ File.join(File.dirname(__FILE__), '../../fixtures/certificate_without_password.p12') }
8
+ let(:invalid_key_store_path){ File.join(File.dirname(__FILE__), '../../fixtures/text.p12') }
9
+ let(:pass_phrase_for_key_store){ 'pass' }
10
+ let(:pass_phrase_for_key){ 'pass' }
11
+
12
+ # Input file to sign and output file
13
+ let(:input_file_path){ File.join(File.dirname(__FILE__), '../../fixtures/unsignedFile.xml') }
14
+ let(:output_file_path){ File.join(File.dirname(__FILE__), '../../../tmp/outputFile.xml') }
15
+
16
+
17
+ before do
18
+ @xml_sig = Jrxades::XmlSig.new(input_file_path, output_file_path, key_store_path, pass_phrase_for_key_store, pass_phrase_for_key)
19
+ end
20
+
21
+ after do
22
+ File.delete(output_file_path) if File.exist?(output_file_path)
23
+ end
24
+
25
+ describe '.initializer' do
26
+
27
+ it 'should create a new XmlSig instance with full parameters' do
28
+ Jrxades::XmlSig.new key_store_path, pass_phrase_for_key_store, pass_phrase_for_key
29
+ end
30
+
31
+ it 'assig key_store_path' do
32
+ @xml_sig.key_store_path.should == key_store_path
33
+ end
34
+
35
+ it 'assig pass_phrase_for_key_store' do
36
+ @xml_sig.pass_phrase_for_key_store.should == pass_phrase_for_key_store
37
+ end
38
+
39
+ it 'assig pass_phrase_for_key' do
40
+ @xml_sig.pass_phrase_for_key.should == pass_phrase_for_key
41
+ end
42
+
43
+ it 'assig output_path' do
44
+ @xml_sig.output_path.should == File.dirname(output_file_path)
45
+ end
46
+
47
+ it 'assig out_file_name' do
48
+ @xml_sig.out_file_name.should == File.basename(output_file_path)
49
+ end
50
+
51
+ it 'assig input_file_path' do
52
+ @xml_sig.input_file_path.should == input_file_path
53
+ end
54
+
55
+ context 'without mandatory parameters' do
56
+
57
+ before do
58
+ @xml_sig = Jrxades::XmlSig.new(input_file_path, output_file_path, key_store_path)
59
+ end
60
+
61
+ it 'assig pass_phrase_for_key_store' do
62
+ @xml_sig.pass_phrase_for_key_store.should == ''
63
+ end
64
+
65
+ it 'assig pass_phrase_for_key' do
66
+ @xml_sig.pass_phrase_for_key.should == ''
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
73
+ describe '#sign' do
74
+ before do
75
+ @xml_sig.sign
76
+ end
77
+
78
+ it 'create a output file' do
79
+ File.exist?(output_file_path).should be_true
80
+ end
81
+
82
+ it 'create the sign into the output file' do
83
+ File.read(output_file_path).should_not be_empty
84
+ end
85
+ end
86
+
87
+ describe '#key_data_valid?' do
88
+
89
+ it 'is valid' do
90
+ @xml_sig.key_data_valid?.should be_true
91
+ end
92
+
93
+ it 'throw an exception if the p12 key is invalid' do
94
+ expect {
95
+ xml_sig = Jrxades::XmlSig.new(input_file_path, output_file_path, invalid_key_store_path)
96
+ xml_sig.key_data_valid?
97
+ }.to raise_error Jrxades::Exceptions::XmlSigException
98
+ end
99
+
100
+ it 'throw an exception if the p12 key has invalid passwords' do
101
+ expect {
102
+ xml_sig = Jrxades::XmlSig.new(input_file_path, output_file_path, key_store_path, 'foo', 'foo')
103
+ xml_sig.key_data_valid?
104
+ }.to raise_error Jrxades::Exceptions::XmlSigException
105
+ end
106
+
107
+ it 'throw an exception if the p12 key needs passwords' do
108
+ expect {
109
+ xml_sig = Jrxades::XmlSig.new(input_file_path, output_file_path, key_store_path)
110
+ xml_sig.key_data_valid?
111
+ }.to raise_error Jrxades::Exceptions::XmlSigException
112
+ end
113
+
114
+ end
115
+
116
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ require 'jrxades'
4
+
5
+ RSpec.configure do |c|
6
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jrxades
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jose Carrion
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.14'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.14.1
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2.14'
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: 2.14.1
31
+ prerelease: false
32
+ type: :development
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.5'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - "~>"
43
+ - !ruby/object:Gem::Version
44
+ version: '1.5'
45
+ prerelease: false
46
+ type: :development
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ prerelease: false
60
+ type: :development
61
+ description: Jrxades es una gema JRuby que permite firmar un documento xml con un certificado .p12, Esta gema ha sido creada para la Facturación Electrónica que se usa en Ecuador, sin embargo se basa en las especificaciones definidas en XADES_BES lo que permitiría ser usada en otros ambientes que requieran XADES_BES.
62
+ email:
63
+ - joseloc@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - ".rspec"
70
+ - ".ruby-gemset"
71
+ - ".ruby-version"
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - java/README.TXT
77
+ - java/lib/MITyCLibAPI-1.1.7.jar
78
+ - java/lib/MITyCLibCert-1.1.7.jar
79
+ - java/lib/MITyCLibCrypt-1.1.7.jar
80
+ - java/lib/MITyCLibOCSP-1.1.7.jar
81
+ - java/lib/MITyCLibPolicy-1.1.7.jar
82
+ - java/lib/MITyCLibTSA-1.1.7.jar
83
+ - java/lib/MITyCLibTrust-1.1.7.jar
84
+ - java/lib/MITyCLibXADES-1.1.7.jar
85
+ - java/lib/bcmail-jdk16-1.45.jar
86
+ - java/lib/bcprov-jdk16-1.45.jar
87
+ - java/lib/bctsp-jdk16-1.45.jar
88
+ - java/lib/commons-codec-1.2.jar
89
+ - java/lib/commons-httpclient-3.0.1.jar
90
+ - java/lib/commons-lang-2.4.jar
91
+ - java/lib/commons-logging-1.1.1.jar
92
+ - java/lib/xml-apis-1.3.04.jar
93
+ - java/lib/xmlsec-1.4.2-ADSI-1.0.jar
94
+ - java/lib/xmlsec-1.4.2-ADSI-1.1.jar
95
+ - java/sri.jar
96
+ - jrxades.gemspec
97
+ - lib/jrxades.rb
98
+ - lib/jrxades/exceptions/xml_sig_exception.rb
99
+ - lib/jrxades/version.rb
100
+ - lib/jrxades/xml_sig.rb
101
+ - spec/fixtures/certificate.p12
102
+ - spec/fixtures/certificate.pem
103
+ - spec/fixtures/certificateRequest.csr
104
+ - spec/fixtures/certificate_without_password.p12
105
+ - spec/fixtures/privateKey.pem
106
+ - spec/fixtures/publicKey.p7b
107
+ - spec/fixtures/testSignedFile.xml
108
+ - spec/fixtures/text.p12
109
+ - spec/fixtures/unsignedFile.xml
110
+ - spec/lib/jrxades/version_spec.rb
111
+ - spec/lib/jrxades/xml_sig_spec.rb
112
+ - spec/spec_helper.rb
113
+ homepage: https://github.com/joselo/jrxades
114
+ licenses:
115
+ - MIT
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.4.8
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Jrxades es una gema JRuby que permite firmar un documento xml con un certificado .p12
137
+ test_files:
138
+ - spec/fixtures/certificate.p12
139
+ - spec/fixtures/certificate.pem
140
+ - spec/fixtures/certificateRequest.csr
141
+ - spec/fixtures/certificate_without_password.p12
142
+ - spec/fixtures/privateKey.pem
143
+ - spec/fixtures/publicKey.p7b
144
+ - spec/fixtures/testSignedFile.xml
145
+ - spec/fixtures/text.p12
146
+ - spec/fixtures/unsignedFile.xml
147
+ - spec/lib/jrxades/version_spec.rb
148
+ - spec/lib/jrxades/xml_sig_spec.rb
149
+ - spec/spec_helper.rb