diff options
author | gregor <gregor@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2003-11-11 22:36:36 +0000 |
---|---|---|
committer | gregor <gregor@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2003-11-11 22:36:36 +0000 |
commit | 643b4096cdd0f0ed98f21c9b5b681ed89bcb08dc (patch) | |
tree | 9e750c9103ad923b291820bc85fcbd669c2e7900 /spss.test/src/testgenerator/TestGeneratorVX2.java | |
parent | bc620256eb9b4dc6a33244b1105e58773358dbe6 (diff) | |
download | moa-id-spss-643b4096cdd0f0ed98f21c9b5b681ed89bcb08dc.tar.gz moa-id-spss-643b4096cdd0f0ed98f21c9b5b681ed89bcb08dc.tar.bz2 moa-id-spss-643b4096cdd0f0ed98f21c9b5b681ed89bcb08dc.zip |
Erstellt.tags/Build-1.2.0.D01-svn
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@51 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'spss.test/src/testgenerator/TestGeneratorVX2.java')
-rw-r--r-- | spss.test/src/testgenerator/TestGeneratorVX2.java | 1600 |
1 files changed, 1600 insertions, 0 deletions
diff --git a/spss.test/src/testgenerator/TestGeneratorVX2.java b/spss.test/src/testgenerator/TestGeneratorVX2.java new file mode 100644 index 000000000..96612da9e --- /dev/null +++ b/spss.test/src/testgenerator/TestGeneratorVX2.java @@ -0,0 +1,1600 @@ +package testgenerator; +import iaik.ixsil.algorithms.DigestAlgorithmImplSHA1; +import iaik.ixsil.algorithms.Transform; +import iaik.ixsil.algorithms.TransformImplCanonicalXML; +import iaik.ixsil.algorithms.TransformImplXSLT; +import iaik.ixsil.util.URI; + +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.RandomAccessFile; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +import at.gv.egovernment.moa.util.Base64Utils; + +/** + * @author stephan + */ +public class TestGeneratorVX2 extends TestCases { + + private static final int canAlgCanXML = 1; + private static final int canAlgCanXMLwithCom = 2; + private static final int canAlgExcXML = 3; + private static final int canAlgExcXMLwithCom = 4; + private static VXResponseBean vxBean = null; + private static String etsiPropertyName = "ETSIProperties"; + private static URI etsiURI; + + public static void main(String[] args) throws Exception { + + vxBean = new VXResponseBean(); + + TestGeneratorVX2 testcase = new TestGeneratorVX2(); + + etsiURI = new URI("http://uri.etsi.org/01903/v1.1.1#SignedProperties"); + + testcase.create201(); + testcase.create202(); + testcase.create203(); + testcase.create205(); + testcase.create206(); + testcase.create208(); + testcase.create209(); + testcase.create210(); + testcase.create211(); + testcase.create212(); + testcase.create213(); + testcase.create214(); + testcase.create215(); + testcase.create216(); + testcase.create217(); + } + + /* ==================================================================================================== */ + + public TestGeneratorVX2() throws Exception { + + super(); + + // Set config properties + configuration_.setProperty("TestClass", "TestGeneratorVX"); + + // configuration_.setProperty("privateKeyFile", baseDir + "additionalFiles/keys/RSAPrivateKey.der"); + // configuration_.setProperty("publicKeyFile", baseDir + "additionalFiles/keys/RSAPublicKey.der"); + // configuration_.setProperty("signatureFile", baseDir + "additionalFiles/signatures/Signature.unit1.xml"); + + iaik.security.provider.IAIK.addAsProvider(); + iaik.security.ecc.provider.ECCProvider.addAsProvider(); + } + + /* ==================================================================================================== */ + + + /** + * Method create001. + * @throws Exception + */ + /* ===================================================================================================================== */ + /* ===================================================================================================================== */ + /* ===================================================================================================================== */ + + +public void create201() throws Exception + { String testNumber = "201"; + + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans; + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + cpkcs.createEnvelopedDataObject(etsiPropertyName, + ets.getQualProp()); + + cpkcs.createReference(new URI("#xmlns(etsi=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('ETSIProperties')/child::etsi:QualifyingProperties/child::etsi:SignedProperties)"), + etsiURI); + + cpkcs.setKeyInformation(); + + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/"+ filename); + smcp.addTransParaElement("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/"+ filename + "")); + + String request = + makeOutputFile( + createRequestStart("201 a simple request w/ SignatureManifestCheckParams (but w/o Supplement)",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + + // + + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + pos_1 = request.indexOf("<etsi:SignedProperties"); + pos_2 = request.indexOf("</etsi:SignedProperties>"); + + String etsi = request.substring(pos_1,pos_2+"</etsi:SignedProperties>".length()); + //etsi = replaceStringAll(etsi,"etsi:","ns1:"); + etsi = replaceString(etsi,"<etsi:SignedProperties","<etsi:SignedProperties xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\""); + etsi = replaceString(etsi,"<dsig:X509IssuerName","<dsig:X509IssuerName xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + etsi = replaceString(etsi,"<dsig:X509SerialNumber","<dsig:X509SerialNumber xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("0")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + + public void create202() throws Exception + { String testNumber = "202"; + + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans; + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + cpkcs.createEnvelopedDataObject( + etsiPropertyName,ets.getQualProp()); + + cpkcs.createReference(new URI("#xmlns(etsi=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('ETSIProperties')/child::etsi:QualifyingProperties/child::etsi:SignedProperties)"), + etsiURI); + + cpkcs.setKeyInformation(); + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams(null); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/"+ filename); + smcp.addTransParaElement("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/"+ filename)); + + String request = + makeOutputFile( + createRequestStart("202 no SignatureManifestCheckParams/@ReturnReferenceInputData" ,true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + pos_1 = request.indexOf("<etsi:SignedProperties"); + pos_2 = request.indexOf("</etsi:SignedProperties>"); + + String etsi = request.substring(pos_1,pos_2+"</etsi:SignedProperties>".length()); + //etsi = replaceStringAll(etsi,"etsi:","ns1:"); + etsi = replaceString(etsi,"<etsi:SignedProperties","<etsi:SignedProperties xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\""); + etsi = replaceString(etsi,"<dsig:X509IssuerName","<dsig:X509IssuerName xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + etsi = replaceString(etsi,"<dsig:X509SerialNumber","<dsig:X509SerialNumber xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("0")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } +public void create203() throws Exception + { String testNumber = "203"; + + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans; + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + cpkcs.createEnvelopedDataObject( + etsiPropertyName,ets.getQualProp()); + + cpkcs.createReference(new URI("#xmlns(etsi=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('ETSIProperties')/child::etsi:QualifyingProperties/child::etsi:SignedProperties)"), + etsiURI); + + cpkcs.setKeyInformation(); + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("false"); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/"+ filename); + smcp.addTransParaElement("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/"+ filename)); + + String request = + makeOutputFile( + createRequestStart("203 SignatureManifestCheckParams/@ReturnReferenceInputData = false",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + String response = createResponsePart(cpkcs.getX509CertString()) + + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("0")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + + + + + public void create205() throws Exception + { String testNumber = "205"; + + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[2]; + TransformImplCanonicalXML trans0 = new TransformImplCanonicalXML(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans0.setInput(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans0; + + TransformImplXSLT trans = new TransformImplXSLT(); + s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[1] = trans; + + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + cpkcs.createEnvelopedDataObject( + etsiPropertyName,ets.getQualProp()); + + cpkcs.createReference(new URI("#xmlns(etsi=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('ETSIProperties')/child::etsi:QualifyingProperties/child::etsi:SignedProperties)"), + etsiURI); + + cpkcs.setKeyInformation(); + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/"+ filename); + smcp.addTransParaElement("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/"+ filename )); + + String request = + makeOutputFile( + createRequestStart("206 - 2 dsig:Transform elements ==> Canonisierung + Stylesheet",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + pos_1 = request.indexOf("<etsi:SignedProperties"); + pos_2 = request.indexOf("</etsi:SignedProperties>"); + + String etsi = request.substring(pos_1,pos_2+"</etsi:SignedProperties>".length()); + //etsi = replaceStringAll(etsi,"etsi:","ns1:"); + etsi = replaceString(etsi,"<etsi:SignedProperties","<etsi:SignedProperties xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\""); + etsi = replaceString(etsi,"<dsig:X509IssuerName","<dsig:X509IssuerName xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + etsi = replaceString(etsi,"<dsig:X509SerialNumber","<dsig:X509SerialNumber xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("0")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + +public void create206() throws Exception + { String testNumber = "206"; + + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans; + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + cpkcs.createEnvelopedDataObject( + etsiPropertyName,ets.getQualProp()); + + cpkcs.createReference(new URI("#xmlns(etsi=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('ETSIProperties')/child::etsi:QualifyingProperties/child::etsi:SignedProperties)"), + etsiURI); + + cpkcs.setKeyInformation(); + + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/"+ filename); + smcp.addTransParaElement("Hash",getBase64Hash(configuration_.getProperty("baseDir")+"resources/" + filename)); + + String request = + makeOutputFile( + createRequestStart("206 TransformParameter/Hash statt TransformParameter/Base64Content (Der Hash wird von " + filename + " gebildet)",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + pos_1 = request.indexOf("<etsi:SignedProperties"); + pos_2 = request.indexOf("</etsi:SignedProperties>"); + + String etsi = request.substring(pos_1,pos_2+"</etsi:SignedProperties>".length()); + //etsi = replaceStringAll(etsi,"etsi:","ns1:"); + etsi = replaceString(etsi,"<etsi:SignedProperties","<etsi:SignedProperties xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\""); + etsi = replaceString(etsi,"<dsig:X509IssuerName","<dsig:X509IssuerName xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + etsi = replaceString(etsi,"<dsig:X509SerialNumber","<dsig:X509SerialNumber xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("0")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + +public void create208() throws Exception + { String testNumber = "208"; + + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans; + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + cpkcs.createEnvelopedDataObject( + etsiPropertyName,ets.getQualProp()); + + cpkcs.createReference(new URI("#xmlns(etsi=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('ETSIProperties')/child::etsi:QualifyingProperties/child::etsi:SignedProperties)"), + etsiURI); + + cpkcs.setKeyInformation(); + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_book.xsl"); + + String request = + makeOutputFile( + createRequestStart("208 - weder Base64Content noch Hash wird verwendet ",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + pos_1 = request.indexOf("<etsi:SignedProperties"); + pos_2 = request.indexOf("</etsi:SignedProperties>"); + + String etsi = request.substring(pos_1,pos_2+"</etsi:SignedProperties>".length()); + //etsi = replaceStringAll(etsi,"etsi:","ns1:"); + etsi = replaceString(etsi,"<etsi:SignedProperties","<etsi:SignedProperties xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\""); + etsi = replaceString(etsi,"<dsig:X509IssuerName","<dsig:X509IssuerName xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + etsi = replaceString(etsi,"<dsig:X509SerialNumber","<dsig:X509SerialNumber xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("0")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + + +public void create209() throws Exception + { String testNumber = "209"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_book.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_book.xsl")); + tr[0] = trans; + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); +// cpkcs.createReferenceWithManifest( +// new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), +// "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + cpkcs.createEnvelopedDataObject( + etsiPropertyName,ets.getQualProp()); + + cpkcs.createReference(new URI("#xmlns(etsi=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('ETSIProperties')/child::etsi:QualifyingProperties/child::etsi:SignedProperties)"), + etsiURI); + + cpkcs.setKeyInformation(); + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + + String request = + makeOutputFile( + createRequestStart("209 0 TransformParameter ==> ganzes Element raus und direkt auf CX1_book.xsl verweisen (in der Transformations-Referenz)",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + + /*int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\"");*/ + + int pos_1 = request.indexOf("<etsi:SignedProperties"); + int pos_2 = request.indexOf("</etsi:SignedProperties>"); + + String etsi = request.substring(pos_1,pos_2+"</etsi:SignedProperties>".length()); + //etsi = replaceStringAll(etsi,"etsi:","ns1:"); + etsi = replaceString(etsi,"<etsi:SignedProperties","<etsi:SignedProperties xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\""); + etsi = replaceString(etsi,"<dsig:X509IssuerName","<dsig:X509IssuerName xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + etsi = replaceString(etsi,"<dsig:X509SerialNumber","<dsig:X509SerialNumber xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("2")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } +public void create210() throws Exception + { String testNumber = "210"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/VX2_bookref2includes.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/VX2_bookref2includes.xsl")); + trans.setInput(s,null); + tr[0] = trans; + + //System.out.println(getTransformsResult(tr)); + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + cpkcs.createReferencesWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/VX2_book0.xsl"), + "Manifest",new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/VX2_book1.xsl"), "http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + cpkcs.createEnvelopedDataObject(etsiPropertyName, + ets.getQualProp()); + + cpkcs.createReference(new URI("#xmlns(etsi=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('ETSIProperties')/child::etsi:QualifyingProperties/child::etsi:SignedProperties)"), + etsiURI); + + cpkcs.setKeyInformation(); + + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/VX2_book0.xsl"); + smcp.addTransParaElement("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/VX2_book0.xsl")); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/VX2_book1.xsl"); + smcp.addTransParaElement("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/VX2_book1.xsl")); + + + String request = + makeOutputFile( + createRequestStart("210 2 includes",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + pos_1 = request.indexOf("<etsi:SignedProperties"); + pos_2 = request.indexOf("</etsi:SignedProperties>"); + + String etsi = request.substring(pos_1,pos_2+"</etsi:SignedProperties>".length()); + //etsi = replaceStringAll(etsi,"etsi:","ns1:"); + etsi = replaceString(etsi,"<etsi:SignedProperties","<etsi:SignedProperties xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\""); + etsi = replaceString(etsi,"<dsig:X509IssuerName","<dsig:X509IssuerName xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + etsi = replaceString(etsi,"<dsig:X509SerialNumber","<dsig:X509SerialNumber xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("0")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + +public void create211() throws Exception + { String testNumber = "211"; + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans; + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + cpkcs.createEnvelopedDataObject(etsiPropertyName, + ets.getQualProp()); + + cpkcs.createReference(new URI("#xmlns(etsi=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('ETSIProperties')/child::etsi:QualifyingProperties/child::etsi:SignedProperties)"), + etsiURI); + + cpkcs.setKeyInformation(); + + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + /*for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_book.xsl"); + smcp.addTransParaElement("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/CX1_book.xsl"));*/ + + smcp.addTransformsProfileID("TransformsInfoProfile1"); + smcp.addTransformsProfileID("TransformsInfoProfile2"); + + String request = + makeOutputFile( + createRequestStart("211 2 VerifyTransformsInfoID ==> Statt TransformsInfoProfile , in ein IntoProfileID auf Datei mit orig.Daten des TransInfoProfile verweisen, das andere auf ein Transforms, das nur Canonisiserung enthaelt",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + pos_1 = request.indexOf("<etsi:SignedProperties"); + pos_2 = request.indexOf("</etsi:SignedProperties>"); + + String etsi = request.substring(pos_1,pos_2+"</etsi:SignedProperties>".length()); + //etsi = replaceStringAll(etsi,"etsi:","ns1:"); + etsi = replaceString(etsi,"<etsi:SignedProperties","<etsi:SignedProperties xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\""); + etsi = replaceString(etsi,"<dsig:X509IssuerName","<dsig:X509IssuerName xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + etsi = replaceString(etsi,"<dsig:X509SerialNumber","<dsig:X509SerialNumber xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("0")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + + public void create212() throws Exception + { String testNumber = "212"; + + String filepath = configuration_.getProperty("webbaseDir")+"resources/"; + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans; + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-2"); + + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + ets.addDataObjectFormat("#reference-2"); + cpkcs.createEnvelopedDataObject( + etsiPropertyName,ets.getQualProp()); + //2. DataObject Format + cpkcs.createReference(new URI("#xmlns(etsi=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('ETSIProperties')/child::etsi:QualifyingProperties/child::etsi:SignedProperties)"),etsiURI); + cpkcs.setKeyInformation(); + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/"+ filename); + smcp.addTransParaElement("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/"+ filename )); + + SignatureManifestCheckParams smcp2 = new SignatureManifestCheckParams(null); + for (int trNr=0; trNr < tr.length; trNr++) + smcp2.addDisgTransform(tr[trNr].toElement(smcp2.getDoc())); + smcp2.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/"+ filename); + smcp2.addTransParaElement("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/"+ filename )); + + String signManiDoc = replaceString(smcp.returnDoc(),"</SignatureManifestCheckParams>","") + + replaceString(smcp2.returnDoc(),"<SignatureManifestCheckParams>",""); + + String request = + makeOutputFile( + createRequestStart("212 2 ReferenceInfo (for 2 dsig:Reference (pplus Manifest + SignedProperties) : etsi:DataObjectFormat 2mal, Reference 2mal, Manifest 1mal, ReferenceInfo 2mal)",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + signManiDoc + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + pos_1 = request.indexOf("<etsi:SignedProperties"); + pos_2 = request.indexOf("</etsi:SignedProperties>"); + + String etsi = request.substring(pos_1,pos_2+"</etsi:SignedProperties>".length()); + //etsi = replaceStringAll(etsi,"etsi:","ns1:"); + etsi = replaceString(etsi,"<etsi:SignedProperties","<etsi:SignedProperties xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\""); + etsi = replaceString(etsi,"<dsig:X509IssuerName","<dsig:X509IssuerName xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + etsi = replaceString(etsi,"<dsig:X509SerialNumber","<dsig:X509SerialNumber xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("0")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + + + public void create213() throws Exception + { + String testNumber = "213"; + + String filepath = configuration_.getProperty("webbaseDir")+"resources/"; + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans; + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + cpkcs.createEnvelopedDataObject(etsiPropertyName, + ets.getQualProp()); + + cpkcs.createReference(new URI("#xpointer(id('" + etsiPropertyName + "'))/*/*"), + etsiURI); + + cpkcs.setKeyInformation(); + + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + + String request = + makeOutputFile( + createRequestStart("213 kein TransformParameter element obwohl in Transforms URIs referenziert werden",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + /*pos_1 = request.indexOf("<etsi:SignedProperties"); + pos_2 = request.indexOf("</etsi:SignedProperties>"); + + String etsi = request.substring(pos_1,pos_2+"</etsi:SignedProperties>".length()); + //etsi = replaceStringAll(etsi,"etsi:","ns1:"); + etsi = replaceString(etsi,"<etsi:SignedProperties","<etsi:SignedProperties xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\""); + etsi = replaceString(etsi,"<dsig:X509IssuerName","<dsig:X509IssuerName xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + etsi = replaceString(etsi,"<dsig:X509SerialNumber","<dsig:X509SerialNumber xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\"");*/ + + pos_1 = request.indexOf("<dsig:Object Id=\"ETSIProperties\">"); + pos_2 = request.substring(pos_1).indexOf("</dsig:Object>"); + + String etsi = request.substring(pos_1,pos_1+pos_2+"</dsig:Object>".length()); + etsi = replaceString(etsi,"<dsig:Object Id=\"ETSIProperties\">","<dsig:Object Id=\"ETSIProperties\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">"); + + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("1","<Info><FailedReference>1</FailedReference></Info>")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + + public void create214() throws Exception + { + String testNumber = "214"; + + String filepath = configuration_.getProperty("webbaseDir")+"resources/"; + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans; + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + cpkcs.createEnvelopedDataObject(etsiPropertyName, + ets.getQualProp()); + + cpkcs.createReference(new URI("#xpointer(id('" + etsiPropertyName + "'))/*/*"), + etsiURI); + + cpkcs.setKeyInformation(); + + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + + smcp.addTransformsProfileID("TransformsInfoProfile2"); + + String request = + makeOutputFile( + createRequestStart("214 1 VerifyTransformsInfoID ==> Passt aber nicht zur Transformation (XSLT <==> Canonisiserung)",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + pos_1 = request.indexOf("<dsig:Object Id=\"ETSIProperties\">"); + pos_2 = request.substring(pos_1).indexOf("</dsig:Object>"); + + String etsi = request.substring(pos_1,pos_1+pos_2+"</dsig:Object>".length()); + etsi = replaceString(etsi,"<dsig:Object Id=\"ETSIProperties\">","<dsig:Object Id=\"ETSIProperties\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">"); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("1","<Info><FailedReference>1</FailedReference></Info>")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + + public void create215() throws Exception + { String testNumber = "215"; + + String filepath = configuration_.getProperty("webbaseDir")+"resources/"; + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans; + //Reference 1 + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + //ets.addDataObjectFormat("#reference-2"); + cpkcs.createEnvelopedDataObject( + etsiPropertyName,ets.getQualProp()); + + cpkcs.createReference(new URI("#xpointer(id('" + etsiPropertyName + "')/*/*)"),etsiURI); + cpkcs.setKeyInformation(); + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/"+ filename); + smcp.addTransParaElement("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/"+ filename)); + + SignatureManifestCheckParams smcp2 = new SignatureManifestCheckParams(null); + for (int trNr=0; trNr < tr.length; trNr++) + smcp2.addDisgTransform(tr[trNr].toElement(smcp2.getDoc())); + smcp2.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/"+ filename); + smcp2.addTransParaElement("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/"+ filename)); + + String signManiDoc = replaceString(smcp.returnDoc(),"</SignatureManifestCheckParams>","") + + replaceString(smcp2.returnDoc(),"<SignatureManifestCheckParams>",""); + + String request = + makeOutputFile( + createRequestStart("215 number of ReferenceInfo is different from number of dsig:Reference in the signature",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + signManiDoc + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + //writeFile(vxResErrFile(testNumber),"2271"); + + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + pos_1 = request.indexOf("<etsi:SignedProperties"); + pos_2 = request.indexOf("</etsi:SignedProperties>"); + + String etsi = request.substring(pos_1,pos_2+"</etsi:SignedProperties>".length()); + //etsi = replaceStringAll(etsi,"etsi:","ns1:"); + etsi = replaceString(etsi,"<etsi:SignedProperties","<etsi:SignedProperties xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\""); + etsi = replaceString(etsi,"<dsig:X509IssuerName","<dsig:X509IssuerName xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + etsi = replaceString(etsi,"<dsig:X509SerialNumber","<dsig:X509SerialNumber xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("1")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + + public void create216() throws Exception + { + String testNumber = "216"; + + String filepath = configuration_.getProperty("webbaseDir")+"resources/"; + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans; + //Reference 1 + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-2"); + + + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + ets.addDataObjectFormat("#reference-2"); + cpkcs.createEnvelopedDataObject( + etsiPropertyName,ets.getQualProp()); + + cpkcs.createReference(new URI("#xpointer(id('" + etsiPropertyName + "')/*/*)"),etsiURI); + cpkcs.setKeyInformation(); + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/"+ filename); + smcp.addTransParaElement("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/"+ filename)); + + String request = + makeOutputFile( + createRequestStart("216 number of References id bigger then number of ReferenceInfos",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + writeFile(vxReqFile(testNumber),request); + //writeFile(vxResErrFile(testNumber),"2271"); + + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + pos_1 = request.indexOf("<etsi:SignedProperties"); + pos_2 = request.indexOf("</etsi:SignedProperties>"); + + String etsi = request.substring(pos_1,pos_2+"</etsi:SignedProperties>".length()); + //etsi = replaceStringAll(etsi,"etsi:","ns1:"); + etsi = replaceString(etsi,"<etsi:SignedProperties","<etsi:SignedProperties xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\""); + etsi = replaceString(etsi,"<dsig:X509IssuerName","<dsig:X509IssuerName xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + etsi = replaceString(etsi,"<dsig:X509SerialNumber","<dsig:X509SerialNumber xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("1")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + + public void create217() throws Exception + { String testNumber = "217"; + + String filepath = configuration_.getProperty("webbaseDir")+"resources/"; + String filename = "CX1_book.xsl"; + + CreatePKCSSignature cpkcs = new CreatePKCSSignature(); + cpkcs.init("signature"); + cpkcs.setCanoncialization(canAlgCanXML); + + Transform[] tr = new Transform[1]; + TransformImplXSLT trans = new TransformImplXSLT(); + InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref.xsl"); + trans.setStyleSheet(s,new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_bookref.xsl")); + tr[0] = trans; + cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1"); + cpkcs.createReferenceWithManifest( + new URI("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/" + filename), + "Manifest","http://www.buergerkarte.at/specifications/Securitylayer/20020225#SignatureManifest"); + + EtsiProperties ets = new EtsiProperties(); + ets.addDataObjectFormat("#reference-1"); + cpkcs.createEnvelopedDataObject(etsiPropertyName, ets.getQualProp()); + cpkcs.createReference(new URI("#xpointer(id('" + etsiPropertyName + "'))/*/*"), etsiURI); + cpkcs.setKeyInformation(); + + SignatureManifestCheckParams smcp = new SignatureManifestCheckParams("true"); + for (int trNr=0; trNr < tr.length; trNr++) + smcp.addDisgTransform(tr[trNr].toElement(smcp.getDoc())); + smcp.addTransPara("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/"+ filename); + smcp.addTransParaElement("Hash",getBase64Hash(configuration_.getProperty("baseDir")+"resources/" + filename)); + + String request = + makeOutputFile( + createRequestStart("217 - TransformParameter/@URI resolves but Hash does not match - which hashing algorithm?",true,0), + cpkcs.returnSig(), + createSignatureInfoEnd() + smcp.returnDoc() + + createRequestShortEnd(false)); + + request = replaceString(request,"<Hash><dsig:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><dsig:DigestValue>", + "<Hash><dsig:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><dsig:DigestValue>abcd"); + + writeFile(vxReqFile(testNumber),request); + //writeFile(vxResErrFile(testNumber),"2205"); + + int pos_1 = request.indexOf("<dsig:Manifest"); + int pos_2 = request.indexOf("</dsig:Manifest>"); + + String manifest = request.substring(pos_1,pos_2+"</dsig:Manifest>".length()); + manifest = replaceString(manifest,"<dsig:Manifest Id=\"Manifest\"","<dsig:Manifest Id=\"Manifest\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\""); + + pos_1 = request.indexOf("<dsig:Object Id=\"ETSIProperties\">"); + pos_2 = request.substring(pos_1).indexOf("</dsig:Object>"); + + String etsi = request.substring(pos_1,pos_1+pos_2+"</dsig:Object>".length()); + etsi = replaceString(etsi,"<dsig:Object Id=\"ETSIProperties\">","<dsig:Object Id=\"ETSIProperties\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">"); + + String response = createResponsePart(cpkcs.getX509CertString()) + + "<ReferenceInputData><Base64Content>"+ + readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/BookData.xml")+ + "</Base64Content></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+manifest+"</XMLContent></ReferenceInputData>"+ + "<ReferenceInputData><XMLContent xml:space=\"preserve\">"+etsi+"</XMLContent></ReferenceInputData>"+ + vxBean.createSignatureCheck("0")+ + vxBean.createSignatureManifestCheck("1","<Info><FailedReference>1</FailedReference></Info>")+ + vxBean.createCertificateCheck("0")+ + "</VerifyXMLSignatureResponse>"; + + writeFile(vxResFile(testNumber), response); + } + + + /** + * Method makeOutputFile. + * @param start + * @param signatureDoc + * @param end + * @return String + * @throws Exception + */ + public String makeOutputFile( + String start, + Document signatureDoc, + String end) + throws Exception { + ArrayList foundNodes = new ArrayList(); + findNode( + signatureDoc.getDocumentElement(), + "dsig:Signature", + foundNodes); + + Node outputNode = null; + + if (foundNodes.size() > 0) { + outputNode = (Node) foundNodes.get(0); + } + + String erg = Node2String(outputNode); + + // remove the <?xml ?> Prologue + int pos = erg.indexOf("<dsig"); + erg = erg.substring(pos); + + // insert the dsig:signature element in a MOA Response Message + erg = start + erg + end; + + return erg; + } + + /** + * Method createRequestStart. + * @param testNumber + * @param useDate + * @param changeHours + * @return String + */ + private String createRequestStart(String testNumber, boolean useDate, int changeHours) + {String reqStart = null; + System.out.println("======================================================"); + System.out.println("================== TEST-NUMBER "+ testNumber + " ==================="); + System.out.println("======================================================"); + + reqStart = + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + "<!-- Testnumber: " + + testNumber + + "-->\n" + + "<VerifyXMLSignatureRequest\n" + + " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n" + + " xmlns:xml=\"http://www.w3.org/XML/1998/namespace\"" + + " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">\n"; + + if (useDate) { + reqStart += " <DateTime>" + + getDate(changeHours) + + "</DateTime>\n"; + } + + reqStart += " <VerifySignatureInfo>\n" + + " <VerifySignatureEnvironment>\n" + + " <XMLContent xml:space=\"preserve\">" ; + return reqStart; + } + + /** + * Method getTransformsResult:the input transforms array will + * be calculated to return a string-representation of the result + * @param tr + * @return String + * @throws Exception + */ + private String getTransformsResult(Transform[] tr) throws Exception + { + Transform[] myTransforms = tr; + String result = ""; + for (int t=0; t<tr.length-1; t++) + { + myTransforms[t+1].setInput((InputStream)myTransforms[t].transform(),null); + } + + ByteArrayInputStream is = (ByteArrayInputStream)myTransforms[tr.length-1].transform(); + + + byte[] b = new byte[1]; + is.read(b); + while (is.available() > 0) + { + result += new String(b); + is.read(b); + } + result += new String(b); + + return result; + } + + private String getBase64Hash(String filename) throws Exception + { + DigestAlgorithmImplSHA1 dig = new DigestAlgorithmImplSHA1(); + + dig.setInput(new FileInputStream(filename)); + + InputStream erg = dig.digest(); + String result = ""; + + int size = erg.available(); + + byte[] b = new byte[size]; + erg.read(b); + + return Base64Utils.encode(b); + } + + /** + * Method createRequestEnd. + * @param useReturnHashInputData + * @param useSupplement + * @param supplementReference + * @return String + * @throws Exception + */ + private String createRequestEnd( + boolean useReturnHashInputData, + boolean useSupplement, + String supplementReference) + throws Exception { + + String reqEnd = null; + +/* reqEnd = + "</VerifySignatureEnvironment>\n" + + " <VerifySignatureLocation>#xpointer(/VerifyXMLSignatureRequest/VerifySignatureInfo/VerifySignatureEnvironment/dsig:Signature)</VerifySignatureLocation>\n" + + " </VerifySignatureInfo>\n"; +*/ + reqEnd ="</XMLContent>"+ + "</VerifySignatureEnvironment>\n" + + " <VerifySignatureLocation>//dsig:Signature</VerifySignatureLocation>\n" + + " </VerifySignatureInfo>\n"; + + + + if (useSupplement) + { + reqEnd += " <Supplement>\n" + + " <Content Reference=\"file:/" + supplementReference.toString() + "\">\n" + + " <XMLContent>"+readFile(supplementReference.toString())+"</XMLContent>\n" + + " </Content>\n" + + " </Supplement>\n"; + } + + if (useReturnHashInputData) { + reqEnd += " <ReturnHashInputData/>\n"; + } + reqEnd += " <TrustProfileID>TrustProfile1</TrustProfileID>\n" + + "</VerifyXMLSignatureRequest>\n"; + return reqEnd; + + } + + private String createSignatureInfoEnd() + throws Exception { + + return "</XMLContent>"+"</VerifySignatureEnvironment>\n" + + " <VerifySignatureLocation>//dsig:Signature</VerifySignatureLocation>\n" + + " </VerifySignatureInfo>\n"; + + } + + private String createRequestShortEnd(boolean useReturnHashInputData) + throws Exception { + + String reqEnd = ""; + + if (useReturnHashInputData) + reqEnd = " <ReturnHashInputData/>\n"; + + reqEnd += " <TrustProfileID>TrustProfile1</TrustProfileID>\n" + + "</VerifyXMLSignatureRequest>\n"; + return reqEnd; + + } + /** + * Method createResponse. + * @param testNumber + * @param signatureCheckCode + * @return String + * @throws Exception + */ + private String createResponse(String testNumber, String signatureCheckCode) throws Exception { + // + vxBean.init(configuration_.getProperty("webbaseDir")+ "resources/" + "test-ee2003_normal.der"); + + String res = null; + + res = vxBean.getHeader(); + res += vxBean.getSubjectDN(); + res += " <dsig:X509IssuerSerial>\n"; + res += vxBean.getIssuerDN(); + res += vxBean.getSerialNumber(); + res += " </dsig:X509IssuerSerial>\n" + + " </dsig:X509Data>\n" + + " </SignerInfo>\n"; + res += " <HashInputData>\n" + " <XMLContent xml:space=\"preserve\">"; + res += readFile( + configuration_.getProperty("webbaseDir") + + "resources/testDaten.txt")+ + "</XMLContent>"; + + res += vxBean.getFooterSignatureCheck(signatureCheckCode, "0"); + + return res; + } + + private String createResponse(String testNumber, String signatureCheckCode, String hashData) throws Exception { + // + vxBean.init(configuration_.getProperty("webbaseDir")+ "resources/" + "test-ee2003_normal.der"); + + String res = null; + + res = vxBean.getHeader(); + res += vxBean.getSubjectDN(); + res += " <dsig:X509IssuerSerial>\n"; + res += vxBean.getIssuerDN(); + res += vxBean.getSerialNumber(); + res += " </dsig:X509IssuerSerial>\n" + + " </dsig:X509Data>\n" + + " </SignerInfo>\n"; + res += " <HashInputData>\n" + + " <XMLContent xml:space=\"preserve\">"+ + hashData + + "</XMLContent>\n"; + res += vxBean.getFooterSignatureCheck(signatureCheckCode, "0"); + + return res; + } + + + private String createResponseWithoutHashInputData(String testNumber, String signatureCheckCode) throws Exception { + // + vxBean.init(configuration_.getProperty("webbaseDir")+ "resources/" + "test-ee2003_normal.der"); + + String res = null; + + res = vxBean.getHeader(); + res += vxBean.getSubjectDN(); + res += " <dsig:X509IssuerSerial>\n"; + res += vxBean.getIssuerDN(); + res += vxBean.getSerialNumber(); + res += " </dsig:X509IssuerSerial>\n" + + " </dsig:X509Data>\n" + + " </SignerInfo>\n" + + " <SignatureCheck>\n" + + " <Code>" + signatureCheckCode + "</Code>\n" + + " </SignatureCheck>\n" + + " <CertificateCheck>\n" + + " <Code>0</Code>\n" + + " </CertificateCheck>\n" + + "</VerifyXMLSignatureResponse>"; + + return res; + } +/* private String createResponseXMLDsigCheck(String testNumber, String xmlDSIGManifestCheckCode) throws Exception { + + // + vxBean.init(configuration_.getProperty("webbaseDir")+ "resources/" + "test-ee2003_normal.der"); + + String res = null; + + res = vxBean.getHeader(); + res += vxBean.getSubjectDN(); + res += " <dsig:X509IssuerSerial>\n"; + res += vxBean.getIssuerDN(); + res += vxBean.getSerialNumber(); + res += " </dsig:X509IssuerSerial>\n" + + " </dsig:X509Data>\n" + + " </SignerInfo>\n"; + res += " <HashInputData>\n" + " <XMLContent>"; + res += readFile( + configuration_.getProperty("webbaseDir") + + "resources/testDaten.txt"); + + res += vxBean.getFooterXMLDSIGManifestCheck(xmlDSIGManifestCheckCode,"0"); + + return res; + }*/ + + private String createResponsePart(String x509cert) throws Exception { + + // + vxBean.init(configuration_.getProperty("webbaseDir")+ "resources/" + "test-ee2003_normal.der"); + + String res = null; + + res = vxBean.getHeader(); + res += vxBean.getSubjectDN(); + res += " <dsig:X509IssuerSerial>\n"; + res += vxBean.getIssuerDN(); + res += vxBean.getSerialNumber(); + res += " </dsig:X509IssuerSerial>\n" + + x509cert + + " </dsig:X509Data>\n" + + " </SignerInfo>\n"; + /*res += " <HashInputData>\n" + " <XMLContent>"; + res += readFile( + configuration_.getProperty("webbaseDir") + + "resources/testDaten.txt"); + */ + //res += vxBean.getFooterXMLDSIGManifestCheck(xmlDSIGManifestCheckCode,"0"); + + return res; + } + + public String readFileCR(String filename) throws Exception { + + /*StringBuffer data = new StringBuffer(); + String line = null; + BufferedReader br = new BufferedReader(new FileReader(filename)); + while ((line = br.readLine()) != null) { + data.append(line); + data.append("\n"); + } + */ + String response=""; + byte[] result; + + if (filename.substring(0,4).toLowerCase().equals("http")) + { + + URL targetUrl = new URL(filename); + HttpURLConnection h = (HttpURLConnection)targetUrl.openConnection(); + InputStream is = h.getInputStream(); + + int size = 0; + + result = new byte[h.getContentLength()]; + for (int i = 0; i < result.length; i++) { + byte[] b = new byte[1]; + is.read(b); + result[i]=b[0]; + } + is.close(); + } + else + { + RandomAccessFile raf = new RandomAccessFile(filename, "r"); + if (raf.length() > Integer.MAX_VALUE) + throw new IOException("file too big to fit in byte array."); + + result = new byte[(int) raf.length()]; + raf.read(result); + raf.close(); + + } + + byte[] temp = new byte[result.length]; + int s = 0; + for (int t=0; t<result.length; t++) + { + temp[s] = result[t]; + s++; + if (temp[s-1]==10) + { + if (temp[s-2]==13) + { + temp[s-2]=10; + s--; + } + } + } + byte[] res = new byte[s]; + result = null; + + System.arraycopy(temp,0,res,0,s); + + + response = new String(res); + + try { + response = replaceString(response,"<?xml version=\"1.0\" encoding=\"utf-8\"?>",""); + } + catch (Exception e) {} + + return response; + } + +private InputStream getHttpInputStream(String url) throws Exception + { + + return ((HttpURLConnection)new URL(url).openConnection()).getInputStream(); + } + + + +} |