diff options
author | pdanner <pdanner@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2007-09-05 10:02:19 +0000 |
---|---|---|
committer | pdanner <pdanner@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2007-09-05 10:02:19 +0000 |
commit | 4075bf26b65cf2be4c55f2e9cbdc1b854a41dbce (patch) | |
tree | ce47b59636e31eb8aa64f075773cbef88c9324f3 /spss.test/src/testgenerator | |
parent | 31d5acacc9c22f45251827b38ad689cdeb705efc (diff) | |
download | moa-id-spss-4075bf26b65cf2be4c55f2e9cbdc1b854a41dbce.tar.gz moa-id-spss-4075bf26b65cf2be4c55f2e9cbdc1b854a41dbce.tar.bz2 moa-id-spss-4075bf26b65cf2be4c55f2e9cbdc1b854a41dbce.zip |
removed obsolete files
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@990 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'spss.test/src/testgenerator')
23 files changed, 0 insertions, 16716 deletions
diff --git a/spss.test/src/testgenerator/CMSKeyStore.java b/spss.test/src/testgenerator/CMSKeyStore.java deleted file mode 100644 index a85da893b..000000000 --- a/spss.test/src/testgenerator/CMSKeyStore.java +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright (C) 1997-2002 IAIK -// email: jce-info@iaik.tu-graz.ac.at -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -// SUCH DAMAGE. -// -// $Header$ -// -// $Header$ -// - -package testgenerator; - -import iaik.utils.Util; -import iaik.x509.X509Certificate; - -import java.io.File; -import java.io.FileInputStream; -import java.security.KeyStore; -import java.security.PrivateKey; - -public class CMSKeyStore implements CMSKeyStoreConstants { - - static Object[][] certificates = new Object[3][7]; - static PrivateKey[][] keys = new PrivateKey[3][7]; - static X509Certificate[] ca_certificates = new X509Certificate[2]; - static PrivateKey[] ca_keys = new PrivateKey[2]; - - public final static int RSA = 0; - public final static int DSA = 1; - public final static int ESDH = 2; - - public final static int SZ_512_SIGN = 0; - public final static int SZ_1024_SIGN = 1; - public final static int SZ_2048_SIGN = 2; - public final static int SZ_512_CRYPT = 3; - public final static int SZ_1024_CRYPT = 4; - public final static int SZ_1024_CRYPT_ = 5; - public final static int SZ_2048_CRYPT = 6; - - static KeyStore key_store; - - static { - System.out.println("initializing KeyStore..."); - loadKeyStore(); - initKeyStore(); - } - - private static void loadKeyStore() { - // try to locate the KeyStore - // first check the current working directory - System.out.println("User.dir:"+System.getProperty("user.dir")); - File ks = new File(System.getProperty("user.dir"), KS_FILENAME); - if (!ks.exists()) { - System.out.println("Can not find the KeyStore in directory:"); - System.out.println(ks.getAbsolutePath()); - System.exit(1); - } - - // now try to create and load the KeyStore - try { - key_store = KeyStore.getInstance("IAIKKeyStore"); - key_store.load(new FileInputStream(ks), KS_PASSWORD); - } catch (Exception ex) { - System.out.println("Unable to load KeyStore!"); - ex.printStackTrace(); - System.exit(1); - } - } - - private static void initKeyStore() { - - try { - ca_certificates[RSA] = Util.convertCertificateChain(key_store.getCertificateChain(CA_RSA))[0]; - ca_keys[RSA] = (PrivateKey)key_store.getKey(CA_RSA, KS_PASSWORD); - - // RSA for signing - certificates[RSA][SZ_512_SIGN] = Util.convertCertificateChain(key_store.getCertificateChain(RSA_512_SIGN)); - keys[RSA][SZ_512_SIGN] = (PrivateKey)key_store.getKey(RSA_512_SIGN, KS_PASSWORD); - certificates[RSA][SZ_1024_SIGN] = Util.convertCertificateChain(key_store.getCertificateChain(RSA_1024_SIGN)); - keys[RSA][SZ_1024_SIGN] = (PrivateKey)key_store.getKey(RSA_1024_SIGN, KS_PASSWORD); - certificates[RSA][SZ_2048_SIGN] = Util.convertCertificateChain(key_store.getCertificateChain(RSA_2048_SIGN)); - keys[RSA][SZ_2048_SIGN] = (PrivateKey)key_store.getKey(RSA_2048_SIGN, KS_PASSWORD); - // RSA for encrypting - certificates[RSA][SZ_512_CRYPT] = Util.convertCertificateChain(key_store.getCertificateChain(RSA_512_CRYPT)); - keys[RSA][SZ_512_CRYPT] = (PrivateKey)key_store.getKey(RSA_512_CRYPT, KS_PASSWORD); - certificates[RSA][SZ_1024_CRYPT] = Util.convertCertificateChain(key_store.getCertificateChain(RSA_1024_CRYPT)); - keys[RSA][SZ_1024_CRYPT] = (PrivateKey)key_store.getKey(RSA_1024_CRYPT, KS_PASSWORD); - certificates[RSA][SZ_1024_CRYPT_] = Util.convertCertificateChain(key_store.getCertificateChain(RSA_1024_CRYPT_)); - keys[RSA][SZ_1024_CRYPT_] = (PrivateKey)key_store.getKey(RSA_1024_CRYPT_, KS_PASSWORD); - certificates[RSA][SZ_2048_CRYPT] = Util.convertCertificateChain(key_store.getCertificateChain(RSA_2048_CRYPT)); - keys[RSA][SZ_2048_CRYPT] = (PrivateKey)key_store.getKey(RSA_2048_CRYPT, KS_PASSWORD); - } catch (Exception ex) { - System.out.println("Unable to get RSA certificates from KeyStore."); - ex.printStackTrace(); - } - - try { - ca_certificates[DSA] = Util.convertCertificateChain(key_store.getCertificateChain(CA_DSA))[0]; - ca_keys[DSA] = (PrivateKey)key_store.getKey(CA_DSA, KS_PASSWORD); - - certificates[DSA][SZ_512_SIGN] = Util.convertCertificateChain(key_store.getCertificateChain(DSA_512)); - keys[DSA][SZ_512_SIGN] = (PrivateKey)key_store.getKey(DSA_512, KS_PASSWORD); - certificates[DSA][SZ_1024_SIGN] = Util.convertCertificateChain(key_store.getCertificateChain(DSA_1024)); - keys[DSA][SZ_1024_SIGN] = (PrivateKey)key_store.getKey(DSA_1024, KS_PASSWORD); - - } catch (Exception ex) { - System.out.println("Unable to get DSA certificate from KeyStore."); - ex.printStackTrace(); - } - - /*try { - certificates[ESDH][SZ_512_CRYPT] = Util.convertCertificateChain(key_store.getCertificateChain(ESDH_512)); - keys[ESDH][SZ_512_CRYPT] = (PrivateKey)key_store.getKey(ESDH_512, KS_PASSWORD); - certificates[ESDH][SZ_1024_CRYPT] = Util.convertCertificateChain(key_store.getCertificateChain(ESDH_1024)); - keys[ESDH][SZ_1024_CRYPT] = (PrivateKey)key_store.getKey(ESDH_1024, KS_PASSWORD); - certificates[ESDH][SZ_1024_CRYPT_] = Util.convertCertificateChain(key_store.getCertificateChain(ESDH_1024_)); - keys[ESDH][SZ_1024_CRYPT_] = (PrivateKey)key_store.getKey(ESDH_1024_, KS_PASSWORD); - certificates[ESDH][SZ_2048_CRYPT] = Util.convertCertificateChain(key_store.getCertificateChain(ESDH_2048)); - keys[ESDH][SZ_2048_CRYPT] = (PrivateKey)key_store.getKey(ESDH_2048, KS_PASSWORD); - } catch (Exception ex) { - System.out.println("Unable to get Diffie-Hellman certificate from KeyStore."); - ex.printStackTrace(); - }*/ - } - - /** - * Returns the private key of a CA certificate. - * - * @param type {@link #RSA RSA} or {@link #DSA DSA} or {@link #ESDH ESDH} - */ - public static PrivateKey getPrivateKey(int type, int size) { - try { - return keys[type][size]; - } catch (ArrayIndexOutOfBoundsException ex) { - throw new RuntimeException("Wrong type or size!"); - } - } - - /** - * Returns a demo user certificate. - * - * @param type {@link #RSA RSA} or {@link #DSA DSA} or {@link #ESDH ESDH} - */ - public static X509Certificate[] getCertificateChain(int type, int size) { - try { - return (X509Certificate[])certificates[type][size]; - } catch (ArrayIndexOutOfBoundsException ex) { - throw new RuntimeException("Wrong type or size!"); - } - } - - /** - * Returns the private key of a CA certificate. - * - * @param type {@link #RSA RSA} or {@link #DSA DSA} - */ - public static PrivateKey getCaPrivateKey(int type) { - try { - return ca_keys[type]; - } catch (ArrayIndexOutOfBoundsException ex) { - throw new RuntimeException("Wrong type or size!"); - } - } - - /** - * Returns a demo CA certificate. - * - * @param type {@link #RSA RSA} or {@link #DSA DSA} - */ - public static X509Certificate getCaCertificate(int type) { - try { - return ca_certificates[type]; - } catch (ArrayIndexOutOfBoundsException ex) { - throw new RuntimeException("Wrong type or size!"); - } - } -} diff --git a/spss.test/src/testgenerator/CMSKeyStoreConstants.java b/spss.test/src/testgenerator/CMSKeyStoreConstants.java deleted file mode 100644 index 6e4892d64..000000000 --- a/spss.test/src/testgenerator/CMSKeyStoreConstants.java +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 1997-2002 IAIK -// email: jce-info@iaik.tu-graz.ac.at -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -// SUCH DAMAGE. -// -// $Header$ -// - -package testgenerator; - -public interface CMSKeyStoreConstants { - public final static String CA_RSA = "CA.RSA"; - public final static String CA_DSA = "CA.DSA"; - public final static String RSA_512_SIGN = "RSA_SIGN.512"; - public final static String RSA_512_CRYPT = "RSA_CRYPT.512"; - public final static String RSA_1024_SIGN = "RSA_SIGN.1024"; - public final static String RSA_1024_CRYPT = "RSA_CRYPT.1024"; - public final static String RSA_1024_CRYPT_ = "RSA_CRYPT_.1024"; - public final static String RSA_2048_SIGN = "RSA_SIGN.2048"; - public final static String RSA_2048_CRYPT = "RSA_CRYPT.2048"; - public final static String DSA_512 = "DSA.512"; - public final static String DSA_1024 = "DSA.1024"; - public final static String ESDH_512 = "ESDH.512"; - public final static String ESDH_1024 = "ESDH.1024"; - public final static String ESDH_1024_ = "ESDH_.1024"; - public final static String ESDH_2048 = "ESDH.2048"; - public final static String KS_FILENAME = "resources/cms.keystore"; - public final static char[] KS_PASSWORD = "topSecret".toCharArray(); -} -
\ No newline at end of file diff --git a/spss.test/src/testgenerator/CreatePKCSSignature.java b/spss.test/src/testgenerator/CreatePKCSSignature.java deleted file mode 100644 index 896daf6d1..000000000 --- a/spss.test/src/testgenerator/CreatePKCSSignature.java +++ /dev/null @@ -1,874 +0,0 @@ -package testgenerator; - -import iaik.ixsil.algorithms.CanonicalizationAlgorithm; -import iaik.ixsil.algorithms.CanonicalizationAlgorithmImplCanonicalXML; -import iaik.ixsil.algorithms.CanonicalizationAlgorithmImplCanonicalXMLWithComments; -import iaik.ixsil.algorithms.CanonicalizationAlgorithmImplExclusiveCanonicalXML; -import iaik.ixsil.algorithms.CanonicalizationAlgorithmImplExclusiveCanonicalXMLWithComments; -import iaik.ixsil.algorithms.DigestAlgorithmImplSHA1; -import iaik.ixsil.algorithms.SignatureAlgorithmImplECDSA; -import iaik.ixsil.algorithms.SignatureAlgorithmImplRSA; -import iaik.ixsil.algorithms.Transform; -import iaik.ixsil.core.Position; -import iaik.ixsil.core.Signer; -import iaik.ixsil.core.SignerManifest; -import iaik.ixsil.core.SignerReference; -import iaik.ixsil.core.SignerSignature; -import iaik.ixsil.core.SignerSignedInfo; -import iaik.ixsil.core.URIResolverParameters; -import iaik.ixsil.init.IXSILConstants; -import iaik.ixsil.keyinfo.KeyManagerImpl; -import iaik.ixsil.keyinfo.retrieval.KeyProviderImplRetrievalMethod; -import iaik.ixsil.keyinfo.retrieval.RetrievalMethod; -import iaik.ixsil.keyinfo.x509.KeyProviderImplX509Data; -import iaik.ixsil.keyinfo.x509.X509Data; -import iaik.ixsil.util.URI; -import iaik.pkcs.pkcs12.PKCS12; -import iaik.security.ecc.interfaces.ECDSAPrivateKey; -import iaik.utils.Base64OutputStream; -import java.io.ByteArrayOutputStream; -import java.security.cert.X509Certificate; -import java.security.interfaces.RSAPrivateKey; - -import javax.xml.parsers.DocumentBuilderFactory; - -import org.apache.xml.serialize.DOMWriterImpl; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; - - -/** - * @author Stevie (Admin) - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class CreatePKCSSignature 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 Document doc; - public Signer signer; - private SignerSignature signature; - private SignerSignedInfo signedInfo; - private PKCS12 pkcs12; - private String x509CertString; - public CreatePKCSSignature() throws Exception { - iaik.security.provider.IAIK.addAsProvider(); - iaik.security.ecc.provider.ECCProvider.addAsProvider(); - } - - // Schritt 1 - - public void init() throws Exception{ - pkcs12 = decryptPKCS12( - configuration_.getProperty("PKCS12file"), - configuration_.getProperty("PKCS12password")); - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - signer = new Signer(baseURI); - - // Configure signed information - - // Get interface for signed information - signature = signer.getSignature(); - signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set signature algorithm - SignatureAlgorithmImplRSA signatureAlg = - new SignatureAlgorithmImplRSA(); - RSAPrivateKey privateKey = getPrivateKey(pkcs12); - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - - } - public void init(String iD) throws Exception{ - pkcs12 = decryptPKCS12( - configuration_.getProperty("PKCS12file"), - configuration_.getProperty("PKCS12password")); - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - signer = new Signer(baseURI); - - // Configure signed information - - // Get interface for signed information - signature = signer.getSignature(); - signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set signature algorithm - SignatureAlgorithmImplRSA signatureAlg = - new SignatureAlgorithmImplRSA(); - RSAPrivateKey privateKey = getPrivateKey(pkcs12); - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - signature.setId(iD); - } - - public void init(Document doc, Position position) throws Exception{ - pkcs12 = decryptPKCS12( - configuration_.getProperty("PKCS12file"), - configuration_.getProperty("PKCS12password")); - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - signer = new Signer(doc, baseURI, position); - - // Configure signed information - - // Get interface for signed information - signature = signer.getSignature(); - signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set signature algorithm - SignatureAlgorithmImplRSA signatureAlg = - new SignatureAlgorithmImplRSA(); - RSAPrivateKey privateKey = getPrivateKey(pkcs12); - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - - } - - public void init(Document doc, Position position,String iD) throws Exception{ - pkcs12 = decryptPKCS12( - configuration_.getProperty("PKCS12file"), - configuration_.getProperty("PKCS12password")); - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - signer = new Signer(doc, baseURI, position); - - // Configure signed information - - // Get interface for signed information - signature = signer.getSignature(); - signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set signature algorithm - SignatureAlgorithmImplRSA signatureAlg = - new SignatureAlgorithmImplRSA(); - RSAPrivateKey privateKey = getPrivateKey(pkcs12); - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - signature.setId(iD); - - } - - - public void initECDSA() throws Exception{ - pkcs12 = decryptPKCS12( - configuration_.getProperty("ECDSPKCS12file"), - configuration_.getProperty("ECDSPKCS12password")); - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - signer = new Signer(baseURI); - - // Configure signed information - - // Get interface for signed information - signature = signer.getSignature(); - signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set signature algorithm - SignatureAlgorithmImplECDSA signatureAlg = new SignatureAlgorithmImplECDSA(); - - ECDSAPrivateKey privateKey = (ECDSAPrivateKey)pkcs12.getKeyBag().getPrivateKey(); - - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - - SignerSignature signature = signer.getSignature(); - SignerSignedInfo signedInfo = signature.getSignerSignedInfo(); - - } - - // Schritt 2 - - public void setCanoncialization(int CanonicalizationMethodNumber) throws Exception - { - // Set canonicalization algorithm - CanonicalizationAlgorithm calg = null; - - switch (CanonicalizationMethodNumber) - { - case canAlgCanXML : - calg = new CanonicalizationAlgorithmImplCanonicalXML(); break; - case canAlgCanXMLwithCom : - calg = new CanonicalizationAlgorithmImplCanonicalXMLWithComments(); break; - case canAlgExcXML : - calg = new CanonicalizationAlgorithmImplExclusiveCanonicalXML(); break; - case canAlgExcXMLwithCom : - calg = new CanonicalizationAlgorithmImplExclusiveCanonicalXMLWithComments(); break; - } - - signedInfo.setCanonicalizationAlgorithm(calg); - - } - /** - * Method createReference. - * @param booelan env: if set, the data-string will be enveloped, else an uri pointing to data will be created - * @param data - * @throws Exception - */ - // Schritt 3.1 - - public void createEnvelopedDataObject(String iD, String data) throws Exception - { - iaik.ixsil.core.Object object = null; - object = signature.createObject(data); - object.setId(iD); - signature.addObject(object); - } - - public void createEnvelopedDataObject(String iD, Element doc) throws Exception - { - iaik.ixsil.core.Object object = null; - object = signature.createObject(doc); - object.setId(iD); - signature.addObject(object); - } - - public void createReference(URI uri, URI type) throws Exception - { - SignerReference reference = signedInfo.createReference(); - - reference.setURI(uri); - reference.setType(type); - DigestAlgorithmImplSHA1 digestAlg = - new DigestAlgorithmImplSHA1(); - - reference.setDigestAlgorithm(digestAlg); - signedInfo.addReference(reference); - - } - - public void createReference(boolean env, String data, String iD) throws Exception - { - SignerReference reference = signedInfo.createReference(); - - if (env) { - iaik.ixsil.core.Object object = null; - object = signature.createObject(data); - object.setId("envelopedData"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = - new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - reference.setURI( - new URI("#xpointer(id('envelopedData')/node())")); - } else { - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(data); - - reference.setURI(refURI); - if (iD!=null) - reference.setId(iD); - DigestAlgorithmImplSHA1 digestAlg = - new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - } - - signedInfo.addReference(reference); - - } - public void createReference(boolean env, String data) throws Exception - { - createReference(env,data,null); - } - - public void createETSIObjects(String data) throws Exception - { - SignerReference reference = signedInfo.createReference(); - - URI refURI = null; - refURI = new URI(data); - - reference.setURI(new URI("#xmlns(etsi=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('etsi-signed-1-1')/child::etsi:QualifyingProperties/child::etsi:SignedProperties)")); - reference.setType(new URI("http://uri.etsi.org/01903/v1.1.1#SignedProperties")); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - signedInfo.addReference(reference); - - iaik.ixsil.core.Object object = null; - object = signature.createObject(getElement("TEST")); - object.setId("etsi-signed-1-1"); - signature.addObject(object); - } - - public Element getElement(String data) throws Exception - { - String etsinamespace = "http://uri.etsi.org/01903/v1.1.1#"; - - getX509Content(); - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - //dbf.setNamespaceAware(true); - //dbf.setValidating(true); - - Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - - - Element qualprop = doc.createElementNS(etsinamespace,"etsi:QualifyingProperties"); - qualprop.setAttributeNS(null,"Target","#signature-1-1"); - qualprop.setAttributeNS(IXSILConstants.NAMESPACE_URI_NAMESPACES_,"xmlns:etsi",etsinamespace); - //qualprop.setPrefix("etsi");*/ - //qualprop.setAttributeNodeNS(doc.createAttributeNS(etsinamespace,"etsi")); - Element signprop = doc.createElementNS(etsinamespace,"etsi:SignedProperties"); - Element signsigprop = doc.createElementNS(etsinamespace,"etsi:SignedSignatureProperties"); - Element signdataobjectprop = doc.createElementNS(etsinamespace,"etsi:SignedDataObjectProperties"); - Element signdate = doc.createElementNS(etsinamespace,"etsi:SigningTime"); - Text datevalue = doc.createTextNode("2003-05-10T00:01:01"); - Element signcert = doc.createElementNS(etsinamespace,"etsi:SigningCertificate"); - Element cert = doc.createElementNS(etsinamespace,"etsi:Cert"); - Element signpolyident = doc.createElementNS(etsinamespace,"etsi:SignaturePolicyIdentifier"); - Element signpolyimp = doc.createElementNS(etsinamespace,"etsi:SignaturePolicyImplied"); - Element certdig = doc.createElementNS(etsinamespace,"etsi:CertDigest"); - Element digmeth = doc.createElementNS(etsinamespace,"etsi:DigestMethod"); - digmeth.setAttribute("Algorithm","http://www.w3.org/2000/09/xmldsig#sha1"); - Element digvalue = doc.createElementNS(etsinamespace,"etsi:DigestValue"); - - ByteArrayOutputStream fos = new ByteArrayOutputStream(); - Base64OutputStream base64os = new Base64OutputStream(fos); - base64os.write(this.X509hash.getBytes()); - base64os.flush(); - - Text dig_value = doc.createTextNode(fos.toString()); - Element is = doc.createElementNS(etsinamespace,"etsi:IssuerSerial"); - Element i = doc.createElement("dsig:X509IssuerName"); - Text i_value = doc.createTextNode(this.X509name); - Element s = doc.createElement("dsig:X509SerialNumber"); - Text s_value = doc.createTextNode(this.X509number.toString()); - Element dataobjformat = doc.createElementNS(etsinamespace,"etsi:DataObjectFormat"); - dataobjformat.setAttribute("ObjectReference","#reference-1-1"); - Element mimetype = doc.createElementNS(etsinamespace,"etsi:MimeType"); - //mimetype.setNodeValue("text/plain"); - Text mimevalue = doc.createTextNode("text/html"); - - qualprop.appendChild(signprop); - signprop.appendChild(signsigprop); - signsigprop.appendChild(signdate); - signdate.appendChild(datevalue); - signsigprop.appendChild(signcert); - signcert.appendChild(cert); - cert.appendChild(certdig); - certdig.appendChild(digmeth); - certdig.appendChild(digvalue); - digvalue.appendChild(dig_value); - cert.appendChild(is); - is.appendChild(i); - i.appendChild(i_value); - is.appendChild(s); - s.appendChild(s_value); - signsigprop.appendChild(signpolyident); - signpolyident.appendChild(signpolyimp); - signprop.appendChild(signdataobjectprop); - signdataobjectprop.appendChild(dataobjformat); - dataobjformat.appendChild(mimetype); - mimetype.appendChild(mimevalue); - - - - return qualprop; - } - - - - public void createReferenceEnvElement(Element data) throws Exception - { - SignerReference reference = signedInfo.createReference(); - - iaik.ixsil.core.Object object = null; - object = signature.createObject(data); - object.setId("envelopedData"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = - new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - reference.setURI( - new URI("#xpointer(Data/node())")); - - - signedInfo.addReference(reference); - - } - public void createReferenceWithTransforms(URI uriToData, Transform[] transforms) throws Exception - { - createReferenceWithTransforms(uriToData, transforms,null); - } - - public void createReferenceWithTransforms(URI uriToData, Transform[] transforms, String iD) throws Exception - { - SignerReference reference = signedInfo.createReference(); - - // Create and configure reference - URI refURI = null; - //String baseDir = configuration_.getProperty("baseDir"); - refURI = uriToData; - - reference.setURI(refURI); - if (iD!=null) - reference.setId(iD); - - DigestAlgorithmImplSHA1 digestAlg = - new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - for (int trNr=0; trNr < transforms.length; trNr++) - { - reference.insertTransformAt(transforms[trNr],trNr); - //transforms[trNr].transform(); - } - - signedInfo.addReference(reference); - - - } - public Element createReferenceWithManifest( - URI uriToData1, String iD1) throws Exception - { - return createReferencesWithManifest(uriToData1,iD1,null); - } - - public Element createReferenceWithManifest( - URI uriToData1, String iD1, String type) throws Exception - { - /* - public void createReferenceWithManifest( - URI uriToData1, String iD1, - URI uriToData2, String iD2 - ) throws Exception - */ - SignerReference reference = signedInfo.createReference(); - SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - manifestRef.setDigestAlgorithm(digestAlg); - - manifestRef.setURI(uriToData1); - manifest.addReference(manifestRef); - - manifest.setId(iD1); - iaik.ixsil.core.Object manifestObject = - signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - reference = signedInfo.createReference(); - reference.setURI(new URI("#xpointer(id('"+iD1+"'))")); - if (type==null) - reference.setType( - new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - else - reference.setType(new URI(type)); - - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference); - return manifest.toElement(); - } - - public Element createReferencesWithManifest( - URI uriToData1, String iD1, - URI uriToData2 - ) throws Exception - { - /* - public void createReferenceWithManifest( - URI uriToData1, String iD1, - URI uriToData2, String iD2 - ) throws Exception - */ - SignerReference reference = signedInfo.createReference(); - - SignerManifest manifest = signer.createManifest(); - - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - - SignerReference manifestRef = manifest.createReference(); - manifestRef.setDigestAlgorithm(digestAlg); - manifestRef.setURI(uriToData1); - manifest.addReference(manifestRef); - - if (uriToData2!=null) - { - SignerReference manifestRef2 = manifest.createReference(); - manifestRef2.setDigestAlgorithm(digestAlg); - manifestRef2.setURI(uriToData2); - manifest.addReference(manifestRef2); - } - manifest.setId(iD1); - iaik.ixsil.core.Object manifestObject = - signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - reference = signedInfo.createReference(); - reference.setURI(new URI("#xpointer(id('"+iD1+"'))")); - reference.setType( - new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference); - /* - if (iD2!=null) - { - SignerReference reference2 = signedInfo.createReference(); - SignerManifest manifest2 = signer.createManifest(); - SignerReference manifestRef2 = manifest.createReference(); - - - manifestRef2.setDigestAlgorithm(digestAlg); - - manifestRef2.setURI(uriToData2); - - manifest2.addReference(manifestRef2); - manifest2.setId(iD2); - iaik.ixsil.core.Object manifestObject2 = - signature.createObject(manifest2); - signature.addObject(manifestObject2); - manifest2.computeDigestValues(); - - reference2 = signedInfo.createReference(); - reference2.setURI(new URI("#xpointer(id('"+iD1+"'))")); - reference2.setType( - new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference2.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference2); - - } - */ - return manifest.toElement(); - } - -public Element createReferencesWithManifest( - URI uriToData1, String iD1, - URI uriToData2, String type - ) throws Exception - { - SignerReference reference = signedInfo.createReference(); - - SignerManifest manifest = signer.createManifest(); - - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - - SignerReference manifestRef = manifest.createReference(); - manifestRef.setDigestAlgorithm(digestAlg); - manifestRef.setURI(uriToData1); - manifest.addReference(manifestRef); - - SignerReference manifestRef2 = manifest.createReference(); - manifestRef2.setDigestAlgorithm(digestAlg); - manifestRef2.setURI(uriToData2); - manifest.addReference(manifestRef2); - - manifest.setId(iD1); - iaik.ixsil.core.Object manifestObject = - signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - reference = signedInfo.createReference(); - reference.setURI(new URI("#xpointer(id('"+iD1+"'))")); - reference.setType(new URI(type)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference); - return manifest.toElement(); - } - - - public void setKeyInformation() throws Exception - { - // Create key information - KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument()); - - - X509Certificate[] certs = getCertificates(pkcs12); - X509Data x509Data = new X509Data(); - - for (int i = 0; i < certs.length; i++) { - x509Data.insertHintAt(certs[i], i); - } - - KeyProviderImplX509Data x509DataKeyProvider = - new KeyProviderImplX509Data(signer.toDocument()); - - x509DataKeyProvider.insertX509DataAt(x509Data, 0); - - // X509Data key information (certificate chain) - keyManager.addKeyProvider(x509DataKeyProvider); - - Element e = (Element)keyManager.getKeyInfo(); - NodeList nl = e.getChildNodes(); - x509CertString = ((new DOMWriterImpl(true)).writeToString(nl.item(0).getChildNodes().item(1))); - if(x509CertString==null) - x509CertString = ((new DOMWriterImpl(true)).writeToString(nl.item(0).getChildNodes().item(0))); - - signer.getSignature().setKeyManager(keyManager); - - - - } - public void setKeyInformation(String retrievalMethod) throws Exception - { // Create key information - KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument()); - - KeyProviderImplRetrievalMethod x509RetrievalMethod = - new KeyProviderImplRetrievalMethod(signer.toDocument()); - - URI fileURI = null; - - if (retrievalMethod == "XML") - fileURI = - new URI( - "file:" - + configuration_.getProperty("baseDir") - + configuration_.getProperty("RetrievalURIXML")); - else - fileURI = - new URI( - "file:" - + configuration_.getProperty("baseDir") - + configuration_.getProperty("RetrievalURIRaw")); - - RetrievalMethod retMet = - new RetrievalMethod( - signer.toDocument(), - new URIResolverParameters(fileURI)); - - retMet.setURI(fileURI); - - if (retrievalMethod == "XML") - retMet.setType( - new URI(configuration_.getProperty("RetrievalTypeXML"))); - else - retMet.setType( - new URI(configuration_.getProperty("RetrievalTypeRaw"))); - - x509RetrievalMethod.insertRetrievalMethodAt(retMet, 0); - keyManager.addKeyProvider(x509RetrievalMethod); - Element e = (Element)keyManager.getKeyInfo(); - NodeList nl = e.getChildNodes(); - x509CertString = ((new DOMWriterImpl(true)).writeToString(nl.item(0).getChildNodes().item(0))); - - - signer.getSignature().setKeyManager(keyManager); - } - - public void setKeyInformation(int pos) throws Exception - { - // Create key information - KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument()); - - - X509Certificate[] certs = getCertificates(pkcs12); - X509Data x509Data = new X509Data(); - - x509Data.insertHintAt(certs[pos], 0); - - - KeyProviderImplX509Data x509DataKeyProvider = - new KeyProviderImplX509Data(signer.toDocument()); - - x509DataKeyProvider.insertX509DataAt(x509Data, 0); - - // X509Data key information (certificate chain) - keyManager.addKeyProvider(x509DataKeyProvider); - - signer.getSignature().setKeyManager(keyManager); - - Element e = (Element)keyManager.getKeyInfo(); - NodeList nl = e.getChildNodes(); - x509CertString = ((new DOMWriterImpl(true)).writeToString(nl.item(0).getChildNodes().item(0))); - - //((Element)signer.getSignature().getSignatureDOMElement().getChildNodes().item(0)).setAttributeNS(IXSILConstants.NAMESPACE_URI_NAMESPACES_,"xmlns:data","http://uri.data.org"); - - //display(signer.getSignature().getSignatureDOMElement()); - } - - private void display(Node base) - { - display(base,1); - } - - private void display(Node base,int level) - { - String spacer = ""; - for(int counter=0;counter<level;counter++) - { - spacer+=" "; - } - - int att_size=0; - if(base.getAttributes()!=null) - { - att_size=base.getAttributes().getLength(); - } - if(base.getNodeName().equals("#text")) - System.out.println(spacer+base.getNodeName()+base.getChildNodes().getLength()+":"+att_size+" ("+base.getNodeValue()+")"); - else - System.out.println(spacer+base.getNodeName()+base.getChildNodes().getLength()+":"+att_size); - - NamedNodeMap nnm = base.getAttributes(); - if(nnm!=null) - { - int size = nnm.getLength(); - for(int counter=0;counter<size;counter++) - { - display(nnm.item(counter),level+3); - } - } - - NodeList children = base.getChildNodes(); - int size = children.getLength(); - for(int counter=0;counter<size;counter++) - { - display(children.item(counter),level+1); - } - } - - public void setKeyInformation(boolean xpointer, URI fileURI, URI typeURI, Transform[] transforms) throws Exception - { // Create key information - KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument()); - - KeyProviderImplRetrievalMethod x509RetrievalMethod = - new KeyProviderImplRetrievalMethod(signer.toDocument()); - - RetrievalMethod retMet = null; - - if (xpointer) - { - retMet = new RetrievalMethod(signer.toDocument(),null); - } - else - { - retMet = new RetrievalMethod(signer.toDocument(),new URIResolverParameters(fileURI)); - } - - - - retMet.setURI(fileURI); - - - retMet.setType(typeURI); - - if (transforms!=null) - {for (int trNr=0; trNr < transforms.length; trNr++) - retMet.insertTransformAt(transforms[trNr],trNr); - } - - - x509RetrievalMethod.insertRetrievalMethodAt(retMet, 0); - keyManager.addKeyProvider(x509RetrievalMethod); - - Element e = (Element)keyManager.getKeyInfo(); - NodeList nl = e.getChildNodes(); - x509CertString = ((new DOMWriterImpl(true)).writeToString(nl.item(0).getChildNodes().item(0))); - - - signer.getSignature().setKeyManager(keyManager); - - - } - -/* public Document createPKCS12Sig( - String TestNumber, - int CanonicalizationMethodNumber, - String data, - boolean env, - boolean mani, - String data2, - boolean env2, - String retrievalMethod) - throws Exception { - - - - if (data2 != null) { - reference = signedInfo.createReference(); - if (env2) { - iaik.ixsil.core.Object object = null; - object = signature.createObject(data2); - object.setId("envelopedData2"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = - new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - reference.setURI( - new URI("#xpointer(id('envelopedData2')/node())")); - } else { - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(data2); - - reference.setURI(refURI); - DigestAlgorithmImplSHA1 digestAlg = - new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - } - signedInfo.addReference(reference); - } - - // Add reference to signature - - - - // Compute signature value - signer.getSignature().sign(); - - return signer.toDocument(); - } -*/ - public Document returnSig() throws Exception { - //signature.getObjects(); - - signer.getSignature().sign(); - - //((Element)signer.getSignature().getSignatureDOMElement().getChildNodes().item(0)).removeAttribute("xmlns:data"); - //display(((Element)signer.getSignature().getSignatureDOMElement().getChildNodes().item(0))); - //.removeAttributeNS(IXSILConstants.NAMESPACE_URI_NAMESPACES_,"xmlns:data"); - - return signer.toDocument(); - - } - public String getX509CertString() throws Exception{ - TestCases tc = new TestCases(); - - if(x509CertString==null) return null; - String result = TestCases.replaceString(x509CertString,"<?xml version=\"1.0\"?>",""); - if(x509CertString.indexOf("xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\"")!=-1) - result = TestCases.replaceString(result,"xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\"",""); - - return result; - } -} diff --git a/spss.test/src/testgenerator/DataGenerator.java b/spss.test/src/testgenerator/DataGenerator.java deleted file mode 100644 index d0743612e..000000000 --- a/spss.test/src/testgenerator/DataGenerator.java +++ /dev/null @@ -1,45 +0,0 @@ -package testgenerator; - -import java.io.BufferedWriter; -import java.io.FileWriter; - -/** - * @author Administrator - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class DataGenerator { - - public static final String text_to_be_signed="Something to be Signed :) "; - - public static void main(String[] args) throws Exception { - generateData("1kb.txt",1000); - generateData("10kb.txt",10000); - generateData("20kb.txt",20000); - generateData("50kb.txt",50000); - generateData("100kb.txt",100000); - generateData("500kb.txt",500000); - generateData("1mb.txt",1000000); - generateData("10mb.txt",10000000); - } - - public static void generateData(String filename,int size) throws Exception - { - StringBuffer sb = new StringBuffer(size); - int max = size-text_to_be_signed.length(); - while(sb.length()<(max)) - { - sb.append(text_to_be_signed); - } - - sb.append(text_to_be_signed.substring(0,(size-sb.length()))); - - BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); - bw.write(sb.toString()); - bw.flush(); - bw.close(); - } -} diff --git a/spss.test/src/testgenerator/EtsiProperties.java b/spss.test/src/testgenerator/EtsiProperties.java deleted file mode 100644 index c306ddeb6..000000000 --- a/spss.test/src/testgenerator/EtsiProperties.java +++ /dev/null @@ -1,113 +0,0 @@ -package testgenerator; - -import iaik.ixsil.init.IXSILConstants; - -import iaik.utils.Base64OutputStream; - -import java.io.ByteArrayOutputStream; - -import javax.xml.parsers.DocumentBuilderFactory; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Text; -/** - * @author knirschs - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class EtsiProperties extends TestCases { - - /** - * Constructor for EtsiProperties. - * - */ - private Element qualprop; - private Element signdataobjectprop; - private static String etsinamespace = "http://uri.etsi.org/01903/v1.1.1#"; - private Document doc; - - public EtsiProperties() throws Exception{ - - getX509Content(); - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - //dbf.setNamespaceAware(true); - //dbf.setValidating(true); - - doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - - - qualprop = doc.createElementNS(etsinamespace,"etsi:QualifyingProperties"); - qualprop.setAttributeNS(null,"Target","#signature"); - qualprop.setAttributeNS(IXSILConstants.NAMESPACE_URI_NAMESPACES_,"xmlns:etsi",etsinamespace); - //qualprop.setPrefix("etsi");*/ - //qualprop.setAttributeNodeNS(doc.createAttributeNS(etsinamespace,"etsi")); - Element signprop = doc.createElementNS(etsinamespace,"etsi:SignedProperties"); - Element signsigprop = doc.createElementNS(etsinamespace,"etsi:SignedSignatureProperties"); - signdataobjectprop = doc.createElementNS(etsinamespace,"etsi:SignedDataObjectProperties"); - Element signdate = doc.createElementNS(etsinamespace,"etsi:SigningTime"); - Text datevalue = doc.createTextNode("2003-03-01T00:01:01"); - Element signcert = doc.createElementNS(etsinamespace,"etsi:SigningCertificate"); - Element cert = doc.createElementNS(etsinamespace,"etsi:Cert"); - Element signpolyident = doc.createElementNS(etsinamespace,"etsi:SignaturePolicyIdentifier"); - Element signpolyimp = doc.createElementNS(etsinamespace,"etsi:SignaturePolicyImplied"); - Element certdig = doc.createElementNS(etsinamespace,"etsi:CertDigest"); - Element digmeth = doc.createElementNS(etsinamespace,"etsi:DigestMethod"); - digmeth.setAttribute("Algorithm","http://www.w3.org/2000/09/xmldsig#sha1"); - Element digvalue = doc.createElementNS(etsinamespace,"etsi:DigestValue"); - - ByteArrayOutputStream fos = new ByteArrayOutputStream(); - Base64OutputStream base64os = new Base64OutputStream(fos); - base64os.write(this.X509hash.getBytes()); - base64os.flush(); - - Text dig_value = doc.createTextNode(fos.toString()); - Element is = doc.createElementNS(etsinamespace,"etsi:IssuerSerial"); - Element i = doc.createElement("dsig:X509IssuerName"); - Text i_value = doc.createTextNode(this.X509name); - Element s = doc.createElement("dsig:X509SerialNumber"); - Text s_value = doc.createTextNode(this.X509number.toString()); - - - qualprop.appendChild(signprop); - signprop.appendChild(signsigprop); - signsigprop.appendChild(signdate); - signdate.appendChild(datevalue); - signsigprop.appendChild(signcert); - signcert.appendChild(cert); - cert.appendChild(certdig); - certdig.appendChild(digmeth); - certdig.appendChild(digvalue); - digvalue.appendChild(dig_value); - cert.appendChild(is); - is.appendChild(i); - i.appendChild(i_value); - is.appendChild(s); - s.appendChild(s_value); - signsigprop.appendChild(signpolyident); - signpolyident.appendChild(signpolyimp); - signprop.appendChild(signdataobjectprop); - - - } - public Element getQualProp() - { - return qualprop; - } - public void addDataObjectFormat(String reference) throws Exception - { - Element dataobjformat = doc.createElementNS(etsinamespace,"etsi:DataObjectFormat"); - dataobjformat.setAttribute("ObjectReference",reference); - Element mimetype = doc.createElementNS(etsinamespace,"etsi:MimeType"); - //mimetype.setNodeValue("text/plain"); - Text mimevalue = doc.createTextNode("text/html"); - signdataobjectprop.appendChild(dataobjformat); - dataobjformat.appendChild(mimetype); - mimetype.appendChild(mimevalue); - } - -} diff --git a/spss.test/src/testgenerator/LauchAll.java b/spss.test/src/testgenerator/LauchAll.java deleted file mode 100644 index 70965ae09..000000000 --- a/spss.test/src/testgenerator/LauchAll.java +++ /dev/null @@ -1,28 +0,0 @@ -package testgenerator; - -/** - * @author Administrator - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class LauchAll { - - public static void main(String[] args) { - try { - TestGeneratorCX0.main(null); - TestGeneratorCX1.main(null); - TestGeneratorCX2.main(null); - TestGeneratorVC0.main(null); - TestGeneratorVX.main(null); - TestGeneratorVX2.main(null); - TestGeneratorVXErrors.main(null); - } - catch(Exception e) - { - e.printStackTrace(); - } - } -} diff --git a/spss.test/src/testgenerator/LaunchVX.java b/spss.test/src/testgenerator/LaunchVX.java deleted file mode 100644 index 3c4191411..000000000 --- a/spss.test/src/testgenerator/LaunchVX.java +++ /dev/null @@ -1,24 +0,0 @@ -package testgenerator; - -/** - * @author Administrator - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class LaunchVX { - - public static void main(String[] args) { - try { - TestGeneratorVX.main(null); - TestGeneratorVX2.main(null); - TestGeneratorVXErrors.main(null); - } - catch(Exception e) - { - e.printStackTrace(); - } - } -} diff --git a/spss.test/src/testgenerator/Pass.java b/spss.test/src/testgenerator/Pass.java deleted file mode 100644 index b6fef9575..000000000 --- a/spss.test/src/testgenerator/Pass.java +++ /dev/null @@ -1,22 +0,0 @@ -package testgenerator; - -import iaik.apps.util.passphrase.PassphrasePrompt; - -/** - * @author Administrator - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class Pass implements PassphrasePrompt -{ - public Pass() {}; - public void setCancelAllowed(boolean b) {}; - public void setMessage(Object o) {}; - public boolean isCancelAllowed() { return false; } - public char[] promptPassphrase() { return "1111".toCharArray(); }; - public void setProtectedResourceInfo(Object o) {}; - -} diff --git a/spss.test/src/testgenerator/SetupCMSKeyStore.java b/spss.test/src/testgenerator/SetupCMSKeyStore.java deleted file mode 100644 index 441e64236..000000000 --- a/spss.test/src/testgenerator/SetupCMSKeyStore.java +++ /dev/null @@ -1,671 +0,0 @@ -// Copyright (C) 1997-2002 IAIK -// email: jce-info@iaik.tu-graz.ac.at -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -// SUCH DAMAGE. -// -// $Header$ -// - -package testgenerator; - -import iaik.asn1.CodingException; -import iaik.asn1.ObjectID; -import iaik.asn1.structures.AlgorithmID; -import iaik.asn1.structures.GeneralName; -import iaik.asn1.structures.GeneralNames; -import iaik.asn1.structures.Name; -import iaik.asn1.structures.PolicyInformation; -import iaik.asn1.structures.PolicyQualifierInfo; -import iaik.security.provider.IAIK; -import iaik.x509.SimpleChainVerifier; -import iaik.x509.X509Certificate; -import iaik.x509.X509ExtensionException; -import iaik.x509.extensions.AuthorityKeyIdentifier; -import iaik.x509.extensions.BasicConstraints; -import iaik.x509.extensions.CertificatePolicies; -import iaik.x509.extensions.KeyUsage; -import iaik.x509.extensions.SubjectAltName; -import iaik.x509.extensions.SubjectKeyIdentifier; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.math.BigInteger; -import java.security.InvalidKeyException; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.cert.CertificateException; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.Random; - -/** - * Creates a default KeyStore in the current working directory. - * These keys are used by many demos included in IAIK-JCE. - * The aliases and the password for accessing the keys and - * certificates can be found in {@link demo.keystore.CMSKeyStoreConstants CMSKeyStoreConstants}. - * - * @see CMSKeyStoreConstants - */ -public class SetupCMSKeyStore implements CMSKeyStoreConstants { - - // the keylength of the CA certificate shall be 1024 - private final static int CA_KEYLENGTH = 1024; - - // the key store to create - KeyStore key_store; - // the file where the key store shall be saved - String keystore_file; - // takes the existing keys from the KeyStore and only creates new certificates - boolean create_only_certificates = true; - - // the private keys - KeyPair ca_rsa = null; - // RSA for signing - KeyPair rsa512_sign = null; - KeyPair rsa1024_sign = null; - KeyPair rsa2048_sign = null; - // RSA for encrypting - KeyPair rsa512_crypt = null; - KeyPair rsa1024_crypt = null; - KeyPair rsa1024_crypt_ = null; - KeyPair rsa2048_crypt = null; - - KeyPair ca_dsa = null; - KeyPair dsa512 = null; - KeyPair dsa1024 = null; - KeyPair esdh512 = null; - KeyPair esdh1024 = null; - KeyPair esdh1024_ = null; - KeyPair esdh2048 = null; - - // create RSA keys and certificates - boolean create_rsa = true; - // create DSA keys and certificates - boolean create_dsa = true; - // create ESDH keys and certificates - boolean create_esdh = true; - - /** - * Generate a KeyPair using the specified algorithm with the given size. - * - * @param algorithm the algorithm to use - * @param bits the length of the key (modulus) in bits - * @return the KeyPair - */ - public static KeyPair generateKeyPair(String algorithm, int bits) - throws NoSuchAlgorithmException { - - KeyPairGenerator generator = null; - - try { - generator = KeyPairGenerator.getInstance(algorithm, "IAIK"); - - } catch (NoSuchProviderException ex) { - throw new NoSuchAlgorithmException("Provider IAIK not found!"); - } - - generator.initialize(bits); - KeyPair kp = generator.generateKeyPair(); - - return kp; - } - - /** - * Creates a certificate from the given values. - * - * @param subject the subject of the certificate - * @param publicKey the public key to include - * @param issuer the issuer of the certificate - * @param privateKey the private key for signing the certificate - * @param algorithm the signature algorithm to use - */ - public static X509Certificate createCertificate(Name subject, PublicKey publicKey, - Name issuer, PrivateKey privateKey, AlgorithmID algorithm, byte[] keyID, boolean forSigning) { - - // create a new certificate - X509Certificate cert = new X509Certificate(); - - try { - // set the values - cert.setSerialNumber(new BigInteger(20, new Random())); - cert.setSubjectDN(subject); - cert.setPublicKey(publicKey); - cert.setIssuerDN(issuer); - - GregorianCalendar date = new GregorianCalendar(); - date.add(Calendar.DATE, -1); - // not before now - cert.setValidNotBefore(date.getTime()); - - if (issuer.equals(subject)) { - date.add(Calendar.MONTH, 12); - BasicConstraints basicConstraints = new BasicConstraints(true); - cert.addExtension(basicConstraints); - KeyUsage keyUsage = new KeyUsage(KeyUsage.keyCertSign | KeyUsage.cRLSign); - cert.addExtension(keyUsage); - } else { - date.add(Calendar.MONTH, 11); - KeyUsage keyUsage = null; - if (forSigning) { - keyUsage = new KeyUsage(KeyUsage.digitalSignature | - KeyUsage.nonRepudiation); - } else { - keyUsage = new KeyUsage(KeyUsage.keyEncipherment | - KeyUsage.dataEncipherment); - } - cert.addExtension(keyUsage); - AuthorityKeyIdentifier authID = new AuthorityKeyIdentifier(); - authID.setKeyIdentifier(keyID); - cert.addExtension(authID); - GeneralNames generalNames = new GeneralNames(); - generalNames.addName(new GeneralName(GeneralName.rfc822Name, "smimetest@iaik.at")); - generalNames.addName(new GeneralName(GeneralName.rfc822Name, "smimetest@iaik.tu-graz.ac.at")); - SubjectAltName subjectAltName = new SubjectAltName(generalNames); - cert.addExtension(subjectAltName); - } - String explicitText = "This certificate only may be used for test purposes"; - PolicyQualifierInfo policyQualifier = new PolicyQualifierInfo(null, null, explicitText); - PolicyInformation[] policyInformations = - { new PolicyInformation(new ObjectID("1.3.6.1.4.1.2706.17.0.11.1.1"), - new PolicyQualifierInfo[] { policyQualifier }) }; - CertificatePolicies certPolicies = new CertificatePolicies(policyInformations); - - SubjectKeyIdentifier subjectKeyID = new SubjectKeyIdentifier(cert.getPublicKey()); - cert.addExtension(subjectKeyID); - - cert.addExtension(certPolicies); - cert.setValidNotAfter(date.getTime()); - // and sign the certificate - cert.sign(algorithm ,privateKey); - } catch (CertificateException ex) { - throw new RuntimeException("Error creating the certificate: "+ex.getMessage()); - } catch (InvalidKeyException ex) { - throw new RuntimeException("Error creating the certificate: "+ex.getMessage()); - } catch (NoSuchAlgorithmException ex) { - throw new RuntimeException("Error creating the certificate: "+ex.getMessage()); - } catch (X509ExtensionException ex) { - throw new RuntimeException("Error adding extension: "+ex.getMessage()); - } catch (CodingException ex) { - throw new RuntimeException("Error adding SubjectKeyIdentifier extension: "+ex.getMessage()); - } -/* - System.out.println(cert.toString(true)); - iaik.utils.Util.waitKey(); -*/ - - return cert; - } - - /** - * Load or create a KeyStore and initialize it. - */ - private void initializeKeyStore() { - - BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - String line; - - try { - // default directory is the current user dir - String keystore_dir = System.getProperty("user.dir"); - File ks = new File(keystore_dir, KS_FILENAME); - - // KeyStore does already exist - if (ks.exists()) { - keystore_file = ks.getAbsolutePath(); - if (create_only_certificates) { - System.out.println("Create only new certificates from already existing keys!"); - } - else { - System.out.println("Existing KeyStore will be deleted!"); - } - System.out.println("KeyStore: "+keystore_file); - } - else { - // there is no KeyStore -> create also new keys - create_only_certificates = false; - - while (true) { - System.out.print("Create new KeyStore in directory: "+keystore_dir+" [y]"); - line = reader.readLine(); - if (line.length() == 0 || line.equals("y")) { - ks = new File(keystore_dir, KS_FILENAME); - keystore_file = ks.getAbsolutePath(); - System.out.println("KeyStore will be saved to: "+keystore_file); - break; - } - System.out.print("Enter directory: "); - keystore_dir = reader.readLine(); - } - } - - // get a new KeyStore onject - key_store = KeyStore.getInstance("IAIKKeyStore"); - - if (create_only_certificates) { - // take private keys from existing KeyStore - key_store.load(new FileInputStream(ks), KS_PASSWORD); - } - else { - // create a new KeyStore - key_store.load(null, null); - } - - } catch (Exception ex) { - System.out.println("Error creating new IAIK KeyStore!"); - throw new RuntimeException("Error creating new KeyStore: "+ex.getMessage()); - } - } - - /** - * Save the KeyStore to disk. - */ - private void saveKeyStore() { - try { - // write the KeyStore to disk - FileOutputStream os = new FileOutputStream(keystore_file); - key_store.store(os, KS_PASSWORD); - os.close(); - } catch (Exception ex) { - System.out.println("Error saving KeyStore!"); - ex.printStackTrace(); - } - } - - /** - * Add the private key and the certificate chain to the key store. - */ - public void addToKeyStore(KeyPair keyPair, X509Certificate[] chain, String alias) throws KeyStoreException { - key_store.setKeyEntry(alias, keyPair.getPrivate(), KS_PASSWORD, chain); - } - - /** - * Returns a KeyPair form the KeyStore. - */ - private KeyPair getKeyPair(String type) throws Exception { - PrivateKey privKey = (PrivateKey)key_store.getKey(type, KS_PASSWORD); - PublicKey pubKey = key_store.getCertificateChain(type)[0].getPublicKey(); - return new KeyPair(pubKey, privKey); - } - - /** - * Get all private keys from the KeyStore. - */ - private void getPrivateKeys() { - // RSA - try { - ca_rsa = getKeyPair(CA_RSA); - // for signing - rsa512_sign = getKeyPair(RSA_512_SIGN); - rsa1024_sign = getKeyPair(RSA_1024_SIGN); - rsa2048_sign = getKeyPair(RSA_2048_SIGN); - // for encrypting - rsa512_crypt = getKeyPair(RSA_512_CRYPT); - rsa1024_crypt = getKeyPair(RSA_1024_CRYPT); - rsa1024_crypt_ = getKeyPair(RSA_1024_CRYPT_); - rsa2048_crypt = getKeyPair(RSA_2048_CRYPT); - } catch (Exception ex) { - System.out.println("Unable to get RSA keys from KeyStore."); - ex.printStackTrace(); - create_rsa = false; - } - // DSA - try { - ca_dsa = getKeyPair(CA_DSA); - dsa512 = getKeyPair(DSA_512); - dsa1024 = getKeyPair(DSA_1024); - } catch (Exception ex) { - System.out.println("Unable to get DSA keys from KeyStore."); - ex.printStackTrace(); - create_dsa = false; - } - // ESDH - try { - esdh512 = getKeyPair(ESDH_512); - esdh1024 = getKeyPair(ESDH_1024); - esdh1024_ = getKeyPair(ESDH_1024_); - esdh2048 = getKeyPair(ESDH_2048); - } catch (Exception ex) { - System.out.println("Unable to get ESDH keys from KeyStore."); - ex.printStackTrace(); - create_esdh = false; - } - } - - /** - * Gernerate new prviate keys. - */ - private void generatePrivateKeys() { - try { - // first create the KeyPairs - if (create_rsa) { - try { - System.out.println("generate RSA KeyPair for CA certificate ["+CA_KEYLENGTH+" bits]..."); - ca_rsa = generateKeyPair("RSA", CA_KEYLENGTH); - System.out.println("Generate RSA signing keys..."); - System.out.println("generate RSA KeyPair for a test certificate [512 bits]..."); - rsa512_sign = generateKeyPair("RSA", 512); - System.out.println("generate RSA KeyPair for a test certificate [1024 bits]..."); - rsa1024_sign = generateKeyPair("RSA", 1024); - System.out.println("generate RSA KeyPair for a test certificate [2048 bits]..."); - rsa2048_sign = generateKeyPair("RSA", 2048); - System.out.println("Generate RSA encryption keys..."); - System.out.println("generate RSA KeyPair for a test certificate [512 bits]..."); - rsa512_crypt = generateKeyPair("RSA", 512); - System.out.println("generate RSA KeyPair for a test certificate [1024 bits]..."); - rsa1024_crypt = generateKeyPair("RSA", 1024); - System.out.println("generate second RSA KeyPair for a test certificate [1024 bits]..."); - rsa1024_crypt_ = generateKeyPair("RSA", 1024); - System.out.println("generate RSA KeyPair for a test certificate [2048 bits]..."); - rsa2048_crypt = generateKeyPair("RSA", 2048); - } catch (NoSuchAlgorithmException ex) { - create_rsa = false; - System.out.println("No implementation for RSA! RSA certificates are not created!\n"); - } - } - if (create_dsa) { - try { - System.out.println("generate DSA KeyPair for CA certificate ["+CA_KEYLENGTH+" bits]..."); - ca_dsa = generateKeyPair("DSA", CA_KEYLENGTH); - System.out.println("generate DSA KeyPair for a test certificate [512 bits]..."); - dsa512 = generateKeyPair("DSA", 512); - System.out.println("generate DSA KeyPair for a test certificate [1024 bits]..."); - dsa1024 = generateKeyPair("DSA", 1024); - } catch (NoSuchAlgorithmException ex) { - create_dsa = false; - System.out.println("No implementation for DSA! DSA certificates are not created!\n"); - } - } - - if (create_esdh) { - try { - System.out.println("generate ESDH KeyPair for a test certificate [512 bits]..."); - esdh512 = generateKeyPair("ESDH", 512); - System.out.println("generate ESDH KeyPair for a test certificate [1024 bits]..."); - esdh1024 = generateKeyPair("ESDH", 1024); - System.out.println("generate ESDH KeyPair for a test certificate [1024 bits]..."); - esdh1024_ = generateKeyPair("ESDH", 1024); - System.out.println("generate ESDH KeyPair for a test certificate [2048 bits]..."); - esdh2048 = generateKeyPair("ESDH", 2048); - } catch (NoSuchAlgorithmException ex) { - create_esdh = false; - System.out.println("No implementation for ESDH! ESDH certificates are not created!\n"); - } - } - } catch (Exception ex) { - System.out.println("Exception: "+ex); - } - } - - public void generateCertificates() { - - try { - - // Now create the certificates - Name issuer = new Name(); - issuer.addRDN(ObjectID.country, "AT"); - issuer.addRDN(ObjectID.organization ,"IAIK"); - issuer.addRDN(ObjectID.organizationalUnit ,"JavaSecurity"); - - Name subject = new Name(); - subject.addRDN(ObjectID.country, "AT"); - subject.addRDN(ObjectID.organization ,"IAIK"); - subject.addRDN(ObjectID.organizationalUnit ,"JavaSecurity"); - - // - // create self signed CA certs - // - X509Certificate caRSA = null; - X509Certificate caDSA = null; - X509Certificate[] chain = new X509Certificate[1]; - // for verifying the created certificates - SimpleChainVerifier verifier = new SimpleChainVerifier(); - - if (create_rsa) { - issuer.addRDN(ObjectID.commonName ,"IAIK RSA Test CA"); - System.out.println("create self signed RSA CA certificate..."); - caRSA = createCertificate(issuer, ca_rsa.getPublic(), - issuer, ca_rsa.getPrivate(), AlgorithmID.sha1WithRSAEncryption, null, true); - // verify the self signed certificate - caRSA.verify(); - // set the CA cert as trusted root - verifier.addTrustedCertificate(caRSA); - chain[0] = caRSA; - addToKeyStore(ca_rsa, chain, CA_RSA); - issuer.removeRDN(ObjectID.commonName); - } - - if (create_dsa) { - issuer.addRDN(ObjectID.commonName ,"IAIK DSA Test CA"); - System.out.println("create self signed DSA CA certificate..."); - caDSA = createCertificate(issuer, ca_dsa.getPublic(), - issuer, ca_dsa.getPrivate(), AlgorithmID.dsaWithSHA, null, true); - // verify the self signed certificate - caDSA.verify(); - // set the CA cert as trusted root - verifier.addTrustedCertificate(caDSA); - chain[0] = caDSA; - addToKeyStore(ca_dsa, chain, CA_DSA); - issuer.removeRDN(ObjectID.commonName); - } - - // - // create certificates - // - chain = new X509Certificate[2]; - - // create a RSA certificate - if (create_rsa) { - issuer.addRDN(ObjectID.commonName ,"IAIK RSA Test CA"); - SubjectKeyIdentifier subjectKeyID = (SubjectKeyIdentifier)caRSA.getExtension(SubjectKeyIdentifier.oid); - // 512 - // for signing - System.out.println("Create RSA demo certificates to be used for signing..."); - - // 512 - subject.addRDN(ObjectID.commonName, "RSA 512 bit Demo Signing Certificate"); - System.out.println("create 512 bit RSA demo certificate..."); - chain[0] = createCertificate(subject, rsa512_sign.getPublic(), - issuer, ca_rsa.getPrivate(), AlgorithmID.sha1WithRSAEncryption, subjectKeyID.get(), true); - chain[1] = caRSA; - // and verify the chain - verifier.verifyChain(chain); - addToKeyStore(rsa512_sign, chain, RSA_512_SIGN); - subject.removeRDN(ObjectID.commonName); - - // 1024 - - subject.addRDN(ObjectID.commonName ,"RSA 1024 bit Demo Signing Certificate"); - System.out.println("create 1024 bit RSA demo certificate..."); - chain[0] = createCertificate(subject, rsa1024_sign.getPublic(), - issuer, ca_rsa.getPrivate(), AlgorithmID.sha1WithRSAEncryption, subjectKeyID.get(), true); - chain[1] = caRSA; - verifier.verifyChain(chain); - addToKeyStore(rsa1024_sign, chain, RSA_1024_SIGN); - subject.removeRDN(ObjectID.commonName); - - // 2048 - - subject.addRDN(ObjectID.commonName ,"RSA 2048 bit Demo Signing Certificate"); - System.out.println("create 2048 bit RSA demo certificate..."); - chain[0] = createCertificate(subject, rsa2048_sign.getPublic(), - issuer, ca_rsa.getPrivate(), AlgorithmID.sha1WithRSAEncryption, subjectKeyID.get(), true); - chain[1] = caRSA; - verifier.verifyChain(chain); - - addToKeyStore(rsa2048_sign, chain, RSA_2048_SIGN); - subject.removeRDN(ObjectID.commonName); - - // for encrypting - System.out.println("Create RSA demo certificates to be used for encryption..."); - // 512 - subject.addRDN(ObjectID.commonName, "RSA 512 bit Demo Encryption Certificate"); - System.out.println("create 512 bit RSA demo certificate..."); - chain[0] = createCertificate(subject, rsa512_crypt.getPublic(), - issuer, ca_rsa.getPrivate(), AlgorithmID.sha1WithRSAEncryption, subjectKeyID.get(), false); - chain[1] = caRSA; - // and verify the chain - verifier.verifyChain(chain); - addToKeyStore(rsa512_crypt, chain, RSA_512_CRYPT); - subject.removeRDN(ObjectID.commonName); - - // 1024 - - subject.addRDN(ObjectID.commonName ,"RSA 1024 bit Demo Encryption Certificate"); - System.out.println("create 1024 bit RSA demo certificate..."); - chain[0] = createCertificate(subject, rsa1024_crypt.getPublic(), - issuer, ca_rsa.getPrivate(), AlgorithmID.sha1WithRSAEncryption, subjectKeyID.get(), false); - chain[1] = caRSA; - verifier.verifyChain(chain); - addToKeyStore(rsa1024_crypt, chain, RSA_1024_CRYPT); - - System.out.println("create second 1024 bit RSA demo Encryption certificate..."); - chain[0] = createCertificate(subject, rsa1024_crypt_.getPublic(), - issuer, ca_rsa.getPrivate(), AlgorithmID.sha1WithRSAEncryption, subjectKeyID.get(), false); - chain[1] = caRSA; - verifier.verifyChain(chain); - addToKeyStore(rsa1024_crypt_, chain, RSA_1024_CRYPT_); - subject.removeRDN(ObjectID.commonName); - - // 2048 - - subject.addRDN(ObjectID.commonName ,"RSA 2048 bit Demo Encryption Certificate"); - System.out.println("create 2048 bit RSA demo certificate..."); - chain[0] = createCertificate(subject, rsa2048_crypt.getPublic(), - issuer, ca_rsa.getPrivate(), AlgorithmID.sha1WithRSAEncryption, subjectKeyID.get(), false); - chain[1] = caRSA; - verifier.verifyChain(chain); - addToKeyStore(rsa2048_crypt, chain, RSA_2048_CRYPT); - subject.removeRDN(ObjectID.commonName); - issuer.removeRDN(ObjectID.commonName); - } - - // create a DSA test certificate - if (create_dsa) { - issuer.addRDN(ObjectID.commonName ,"IAIK DSA Test CA"); - // 512 - subject.addRDN(ObjectID.commonName ,"DSA 512 bit Demo Certificate"); - System.out.println("create 512 bit DSA demo certificate..."); - SubjectKeyIdentifier subjectKeyID = (SubjectKeyIdentifier)caDSA.getExtension(SubjectKeyIdentifier.oid); - chain[0] = createCertificate(subject, dsa512.getPublic(), - issuer, ca_dsa.getPrivate(), AlgorithmID.dsaWithSHA, subjectKeyID.get(), true); - subject.removeRDN(ObjectID.commonName); - chain[1] = caDSA; - verifier.verifyChain(chain); - - addToKeyStore(dsa512, chain, DSA_512); - // 1024 - subject.addRDN(ObjectID.commonName ,"DSA 1024 bit Demo Certificate"); - System.out.println("create 1024 bit DSA demo certificate..."); - chain[0] = createCertificate(subject, dsa1024.getPublic(), - issuer, ca_dsa.getPrivate(), AlgorithmID.dsaWithSHA, subjectKeyID.get(), true); - subject.removeRDN(ObjectID.commonName); - chain[1] = caDSA; - verifier.verifyChain(chain); - addToKeyStore(dsa1024, chain, DSA_1024); - issuer.removeRDN(ObjectID.commonName); - } - - // create a ESDH test certificate - if (create_esdh) { - issuer.addRDN(ObjectID.commonName ,"IAIK DSA Test CA"); - // 512 - subject.addRDN(ObjectID.commonName ,"ESDH 512 bit Demo Certificate"); - System.out.println("create 512 bit ESDH demo certificate..."); - SubjectKeyIdentifier subjectKeyID = (SubjectKeyIdentifier)caDSA.getExtension(SubjectKeyIdentifier.oid); - chain[0] = createCertificate(subject, esdh512.getPublic(), - issuer, ca_dsa.getPrivate(), AlgorithmID.dsaWithSHA, subjectKeyID.get(), false); - subject.removeRDN(ObjectID.commonName); - chain[1] = caDSA; - verifier.verifyChain(chain); - addToKeyStore(esdh512, chain, ESDH_512); - // 1024 - subject.addRDN(ObjectID.commonName ,"ESDH 1024 bit Demo Certificate 1"); - System.out.println("create 1024 bit ESDH demo certificate..."); - chain[0] = createCertificate(subject, esdh1024.getPublic(), - issuer, ca_dsa.getPrivate(), AlgorithmID.dsaWithSHA, subjectKeyID.get(), false); - subject.removeRDN(ObjectID.commonName); - chain[1] = caDSA; - verifier.verifyChain(chain); - addToKeyStore(esdh1024, chain, ESDH_1024); - // 1024 - subject.addRDN(ObjectID.commonName ,"ESDH 1024 bit Demo Certificate 2"); - System.out.println("create second 1024 bit ESDH demo certificate..."); - chain[0] = createCertificate(subject, esdh1024_.getPublic(), - issuer, ca_dsa.getPrivate(), AlgorithmID.dsaWithSHA, subjectKeyID.get(), false); - subject.removeRDN(ObjectID.commonName); - chain[1] = caDSA; - verifier.verifyChain(chain); - addToKeyStore(esdh1024_, chain, ESDH_1024_); - // 2048 - subject.addRDN(ObjectID.commonName ,"ESDH 2048 bit Demo Certificate"); - System.out.println("create 2048 bit ESDH demo certificate..."); - chain[0] = createCertificate(subject, esdh2048.getPublic(), - issuer, ca_dsa.getPrivate(), AlgorithmID.dsaWithSHA, subjectKeyID.get(), false); - subject.removeRDN(ObjectID.commonName); - chain[1] = caDSA; - verifier.verifyChain(chain); - addToKeyStore(esdh2048, chain, ESDH_2048); - issuer.removeRDN(ObjectID.commonName); - } - - System.out.println("\nCertificates created!"); - - } catch (Exception ex) { - System.out.println("Exception: "+ex); - } - } - - public static void start() { - SetupCMSKeyStore suks = new SetupCMSKeyStore(); - suks.initializeKeyStore(); - if (suks.create_only_certificates) { - suks.getPrivateKeys(); - } - else { - suks.generatePrivateKeys(); - } - suks.generateCertificates(); - suks.saveKeyStore(); - } - - /** - * Creates the test certificates. - */ - public static void main(String arg[]) throws IOException { - - IAIK.addAsProvider(true); - start(); - System.in.read(); - } -}
\ No newline at end of file diff --git a/spss.test/src/testgenerator/SignatureManifestCheckParams.java b/spss.test/src/testgenerator/SignatureManifestCheckParams.java deleted file mode 100644 index b1505418d..000000000 --- a/spss.test/src/testgenerator/SignatureManifestCheckParams.java +++ /dev/null @@ -1,176 +0,0 @@ -package testgenerator; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.apache.xml.serialize.DOMWriterImpl; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - - -/** - * @author knirschs - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class SignatureManifestCheckParams { -/* So solls mal aussehen :-) - - <SignatureManifestCheckParams ReturnReferenceInputData="true"> - <ReferenceInfo> - <VerifyTransformsInfoProfile> - <dsig:Transforms> - <dsig:Transform Algorithm="http://www.w3.org/TR/1999/REC-xslt-19991116"> - <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/> - </dsig:Transform> - </dsig:Transforms> - <TransformParameter URI="validURI"> - <Base64Content>validBase64Data</Base64Content> - </TransformParameter> - </VerifyTransformsInfoProfile> - <VerifyTransformsInfoProfileID>validID</VerifyTransformsInfoProfileID> - </ReferenceInfo> - </SignatureManifestCheckParams> -*/ - private Document document; - private Element refInfo; - private Element verifyTrans; - private Element transPara; - private Element dsigTrans; - - public SignatureManifestCheckParams(String returnReferenceInputData) throws Exception{ - - // Find the implementation - DocumentBuilderFactory factory - = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - DOMImplementation impl = builder.getDOMImplementation(); - - // Create the document - document = impl.createDocument(null, "SignatureManifestCheckParams", null); - - //document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); // Create from whole cloth - Element root = document.getDocumentElement(); - if (returnReferenceInputData!=null) - root.setAttribute("ReturnReferenceInputData",returnReferenceInputData); - - refInfo = (Element) document.createElement("ReferenceInfo"); - root.appendChild(refInfo); - - verifyTrans = (Element) document.createElement("VerifyTransformsInfoProfile"); - - - } - - public void addTransPara(String URI) - { - transPara = document.createElement("TransformParameter"); - transPara.setAttribute("URI",URI); - verifyTrans.appendChild(transPara); - - } - - - /** - * Method addDsigTransform: To add an dsig:Tranform element with a special algorithm - * @param algName - */ - public void addDsigTransform(String algName, Element el) - { - if (dsigTrans==null) - { - dsigTrans = (Element) document.createElementNS("http://www.w3.org/2000/09/xmldsig#","Transforms"); - dsigTrans.setPrefix("dsig"); - verifyTrans.appendChild(dsigTrans); - - refInfo.appendChild(verifyTrans); - } - - - Element trans = document.createElementNS("http://www.w3.org/2000/09/xmldsig#","Transform"); - trans.setPrefix("dsig"); - trans.setAttribute("Algorithm",algName); - if (el!=null) trans.appendChild(el); - dsigTrans.appendChild(trans); - } - - public void addDisgTransform(Element transformElement) - { - if (dsigTrans==null) - { - dsigTrans = (Element) document.createElementNS("http://www.w3.org/2000/09/xmldsig#","Transforms"); - dsigTrans.setPrefix("dsig"); - verifyTrans.appendChild(dsigTrans); - - refInfo.appendChild(verifyTrans); - } - - dsigTrans.appendChild(transformElement); - } - - /** - * Method addTransformsProfileID. - * @param id - */ - public void addTransformsProfileID(String id) - { - Element profID = (Element) document.createElement("VerifyTransformsInfoProfileID"); - profID.appendChild(document.createTextNode(id)); - refInfo.appendChild(profID); - } - - public void addTransParaElement(String elemName, String content) - { - if (elemName!="Hash") { - - Element eleName = document.createElement(elemName); - eleName.appendChild(document.createTextNode(content)); - transPara.appendChild(eleName); - - } else { - - Element eleName = document.createElement(elemName); - Element digMethod = document.createElementNS("http://www.w3.org/2000/09/xmldsig#","DigestMethod"); - digMethod.setPrefix("dsig"); - digMethod.setAttribute("Algorithm","http://www.w3.org/2000/09/xmldsig#sha1"); - eleName.appendChild(digMethod); - Element hash = document.createElementNS("http://www.w3.org/2000/09/xmldsig#","DigestValue"); - hash.setPrefix("dsig"); - hash.appendChild(document.createTextNode(content)); - eleName.appendChild(hash); - - transPara.appendChild(eleName); - - - } - - } - -public String returnDoc() throws Exception - { - String result =(new DOMWriterImpl(true)).writeToString(document.getDocumentElement()); - - TestCases tc = new TestCases(); - - result = TestCases.replaceString(result,"<?xml version=\"1.0\"?>",""); - try { - result = TestCases.replaceString(result," xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\"",""); - result = TestCases.replaceString(result," xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\"",""); - result = TestCases.replaceString(result," xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\"",""); - } catch (Exception e) { - } - - - return result; - } - - public Document getDoc() throws Exception - { - return document; - } -} diff --git a/spss.test/src/testgenerator/Supplement.java b/spss.test/src/testgenerator/Supplement.java deleted file mode 100644 index 41edd4118..000000000 --- a/spss.test/src/testgenerator/Supplement.java +++ /dev/null @@ -1,62 +0,0 @@ -package testgenerator; - -/** - * @author Stevie (Admin) - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class Supplement { - - private String supplement; - /** - * Constructor for Supplement. - */ - public Supplement() { - supplement = " <SupplementProfile>\n"; - - } - - public void addMetaInfo(String mimeType, String description) - { - supplement += " <MetaInfo>\n" + - " <MimeType>" + mimeType + "</MimeType>"; - if (!(description==null)) - { - supplement+= " <Description>" + description + "</Description>"; - } - - supplement+= " </MetaInfo>"; - } - - public void addBase64Content(String fileName, String data) - { - supplement+= " <Content Reference=\"" + fileName + "\">\n"+ - " <Base64Content>"+data+"</Base64Content>\n" + - " </Content>\n"; - - } - - public void addXMLContent(String fileName, String data) - { - supplement+= " <Content Reference=\"" + fileName + "\">\n"+ - " <XMLContent xml:space=\"preserve\">"+data+"</XMLContent>\n" + - " </Content>\n"; - - } - - - public void closeSupplement() - { - supplement+= " </SupplementProfile>\n"; - } - - public String getSupplement() - { - return supplement; - } - - -} diff --git a/spss.test/src/testgenerator/TestCMS.java b/spss.test/src/testgenerator/TestCMS.java deleted file mode 100644 index e4d022383..000000000 --- a/spss.test/src/testgenerator/TestCMS.java +++ /dev/null @@ -1,118 +0,0 @@ -package testgenerator; - -import iaik.asn1.CodingException; -import iaik.asn1.ObjectID; -import iaik.asn1.structures.AlgorithmID; -import iaik.asn1.structures.Attribute; -import iaik.asn1.structures.ChoiceOfTime; -import iaik.cms.CMSException; -import iaik.cms.ContentInfoStream; -import iaik.cms.SignedDataStream; -import iaik.cms.SignerInfo; -import iaik.utils.StreamCopier; -import iaik.x509.X509Certificate; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.KeyStore; -import java.security.Provider; -import java.security.Security; -import java.security.SignatureException; - - -/** - * @author Administrator - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class TestCMS { - - public static void main(String[] args) - { - try { - iaik.security.provider.IAIK.addAsProvider(true); - - Provider [] list = Security.getProviders(); - for(int counter=0;counter<list.length;counter++) - { - System.out.println(list[counter].getName()); - } - - KeyStore.getInstance("IAIKKeyStore"); - } - catch(Exception e) - { - e.printStackTrace(); - } - } - - public static String getSignedDataStream(byte[] signedData, byte[] message,boolean two_users) throws CMSException, IOException { - - // we are testing the stream interface - ByteArrayInputStream is = new ByteArrayInputStream(signedData); - // create the ContentInfo object - ContentInfoStream cis = new ContentInfoStream(is); - System.out.println("This ContentInfo holds content of type " + cis.getContentType().getName()); - SignedDataStream signed_data = null; - - if (message == null) { - // implicitly signed; get the content - signed_data = (SignedDataStream)cis.getContent(); - } - else { - // explicitly signed; set the data stream for digesting the message - AlgorithmID[] algIDs = { AlgorithmID.sha1, AlgorithmID.md5 }; - signed_data = new SignedDataStream(new ByteArrayInputStream(message), algIDs); - - } - - // get an InputStream for reading the signed content - InputStream data = signed_data.getInputStream(); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - StreamCopier sc = new StreamCopier(data, os); - sc.copyStream(); - - - if (message != null) { - // if explicitly signed read now the DER encoded object - // an explicit S/MIME signed message also consits of message|signature - signed_data.decode(cis.getContentInputStream()); - } - - System.out.println("SignedData contains the following signer information:"); - SignerInfo[] signer_infos = signed_data.getSignerInfos(); - - for (int i=0; i<signer_infos.length; i++) { - try { - // verify the signed data using the SignerInfo at index i - X509Certificate signer_cert = signed_data.verify(i); - // if the signature is OK the certificate of the signer is returned - System.out.println("Signature OK from signer: "+signer_cert.getSubjectDN()); - Attribute signingTime = signer_infos[i].getSignedAttribute(ObjectID.signingTime); - if (signingTime != null) { - ChoiceOfTime cot = new ChoiceOfTime(signingTime.getValue()[0]); - System.out.println("This message has been signed at " + cot.getDate()); - } - Attribute contentType = signer_infos[i].getSignedAttribute(ObjectID.contentType); - if (contentType != null) { - System.out.println("The content has CMS content type " + contentType.getValue()[0]); - } - - } catch (SignatureException ex) { - // if the signature is not OK a SignatureException is thrown - System.out.println("Signature ERROR from signer: "+signed_data.getCertificate((signer_infos[i].getSignerIdentifier())).getSubjectDN()); - ex.printStackTrace(); - } catch (CodingException ex) { - System.out.println("Attribute decoding error: " + ex.getMessage()); - ex.printStackTrace(); - } - } - - return os.toString(); - } - -} diff --git a/spss.test/src/testgenerator/TestCases.java b/spss.test/src/testgenerator/TestCases.java deleted file mode 100644 index db61af297..000000000 --- a/spss.test/src/testgenerator/TestCases.java +++ /dev/null @@ -1,611 +0,0 @@ -package testgenerator; -import iaik.ixsil.init.IXSILInit; -import iaik.ixsil.util.DOMUtilsImpl; -import iaik.ixsil.util.URI; - -import iaik.asn1.ASN1Object; -import iaik.asn1.ObjectID; -import iaik.asn1.structures.AlgorithmID; -import iaik.asn1.structures.Attribute; -import iaik.asn1.structures.ChoiceOfTime; -import iaik.asn1.structures.Name; -import iaik.cms.CMSException; -import iaik.cms.ContentInfo; -import iaik.cms.IssuerAndSerialNumber; -import iaik.cms.SignedData; -import iaik.cms.SignerInfo; -import iaik.pkcs.pkcs12.CertificateBag; -import iaik.pkcs.pkcs12.KeyBag; -import iaik.pkcs.pkcs12.PKCS12; -import iaik.security.ecc.interfaces.ECDSAPrivateKey; -import iaik.security.provider.IAIK; -import iaik.utils.Base64OutputStream; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedWriter; -import java.io.ByteArrayOutputStream; -import java.io.CharArrayWriter; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.math.BigInteger; -import java.security.NoSuchAlgorithmException; -import java.security.cert.X509Certificate; -import java.security.interfaces.RSAPrivateKey; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.Properties; - -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * Base class for all tutorial units. - * Provides some basic functionality, such as properties and signature - * serialization. - */ -public class TestCases -{ - public String Node2String(Node outputNode) - throws - TransformerFactoryConfigurationError, - TransformerConfigurationException, - TransformerException { - CharArrayWriter caw = new CharArrayWriter(); - TransformerFactory transformerFactory = - TransformerFactory.newInstance(); - Transformer transformer = transformerFactory.newTransformer(); - transformer.setOutputProperty(OutputKeys.METHOD, "xml"); - transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); - transformer.transform(new DOMSource(outputNode), new StreamResult(caw)); - - String erg = caw.toString(); - return erg; - } - - public void findNode(Node base,String name,ArrayList foundNodes) - { - findNode(base,name,foundNodes,-1); - } - - - public void findNode(Node base,String name,ArrayList foundNodes, int max_level) - { - findNode(base,name,foundNodes,max_level,0); - } - - - public void findNode(Node base,String name,ArrayList foundNodes, int max_level, int level) - { - if(max_level!=-1 && max_level<=level) return; - //System.out.println("FINDNODE "+name); - //System.out.println("CHECKING "+base.getNodeName()); - if(base.getNodeName().equals(name)) - { - //System.out.println("ADD BASE !"+name); - foundNodes.add(base); - } - - NodeList children = base.getChildNodes(); - int size = children.getLength(); - for(int counter=0;counter<size;counter++) - { - findNode(children.item(counter),name,foundNodes,max_level,level+1); - } - } - - Properties configuration_; - boolean[] variations_; - - /* ==================================================================================================== */ - - public TestCases() throws Exception - { - // Set some basic configuration properties - configuration_ = new Properties(); - - String baseDir = "e:/cio/projekte/basismodule/wartung/projekt/spss.test/"; - String webBaseDir = "http://localhost:8080/moa-spss-testdata/"; - - configuration_.setProperty("baseDir", baseDir); - configuration_.setProperty("webbaseDir", webBaseDir); - - configuration_.setProperty("PKCS12file", (baseDir + "/resources/test-ee2003_normal(buergerkarte).p12")); - configuration_.setProperty("PKCS12password", "buergerkarte"); - - configuration_.setProperty("ECDSPKCS12file", baseDir + "/resources/ecc(ego).p12"); - configuration_.setProperty("ECDSPKCS12password", "ego"); - - configuration_.setProperty("IXSILInitPropertiesURI", "file:/" + baseDir + "resources/init.properties"); - - configuration_.setProperty("CERT", baseDir + "resources/test-ee2003_normal_extract.cer"); - - // Initialize IXSIL - IXSILInit.init(new URI(configuration_.getProperty("IXSILInitPropertiesURI"))); - - // Switch on debug information - IXSILInit.setPrintDebugLog(true); - - // Add IAIK JCE provider - IAIK.addAsProvider(); - } - - public String X509name = null; - public BigInteger X509number = null; - public String X509hash = null; - public String X509sub = null; - public iaik.x509.X509Certificate user1_sign = null; - - public void getX509Content() throws Exception - { - BufferedInputStream bis = new BufferedInputStream(new FileInputStream(configuration_.getProperty("CERT"))); - iaik.x509.X509Certificate cert = new iaik.x509.X509Certificate(bis); - X509name = ((Name)(cert.getIssuerDN())).getRFC2253String(); - X509number = cert.getSerialNumber(); - X509hash = new String(cert.getFingerprintSHA()); - X509sub = ((Name)(cert.getSubjectDN())).getRFC2253String(); - } - - /* ==================================================================================================== */ - - public void serialize2File(Document signature, String fileName) throws Exception - { - FileOutputStream signatureFIS = new FileOutputStream(fileName); - DOMUtilsImpl.serializeDocument(signature, signatureFIS); - } - - /* ==================================================================================================== */ - - public static HashMap pkcs12cache = new HashMap(); - - public PKCS12 decryptPKCS12( String pkcs12file, String password ) throws Exception - { - if(pkcs12cache.containsKey(pkcs12file)) return (PKCS12) pkcs12cache.get(pkcs12file); - PKCS12 pkcs12 = new PKCS12(new FileInputStream(pkcs12file)); - -// if (!pkcs12.verify(password.toCharArray())) { -// System.out.println("could not verify pkcs12 " + pkcs12.toString() + " with password " + password); -// } else { -// System.out.println("verified pkcs12 " + pkcs12.toString() + " with password " + password); -// } - - pkcs12.decrypt(password.toCharArray()); - System.out.println("decrypted pkcs12 " + pkcs12.toString() + " with password " + password); - pkcs12cache.put(pkcs12file,pkcs12); - return pkcs12; - } - - /* ==================================================================================================== */ - - public static HashMap privkeycache = new HashMap(); - - public RSAPrivateKey getPrivateKey( PKCS12 pkcs12 ) throws Exception - { - if(privkeycache.containsKey(pkcs12)) return (RSAPrivateKey)privkeycache.get(pkcs12); - KeyBag[] keyBags = pkcs12.getKeyBags(); - System.out.println("PKCS12.getKeyBags(): " + keyBags.length + " KeyBags found"); - privkeycache.put(pkcs12,keyBags[0].getPrivateKey()); - return (RSAPrivateKey) keyBags[0].getPrivateKey(); - } - - public static HashMap ecdsaprivkeycache = new HashMap(); - - public ECDSAPrivateKey getPrivateKeyECDS( PKCS12 pkcs12 ) throws Exception - { - if(ecdsaprivkeycache.containsKey(pkcs12)) return (ECDSAPrivateKey)ecdsaprivkeycache.get(pkcs12); - KeyBag[] keyBags = pkcs12.getKeyBags(); - System.out.println("PKCS12.getKeyBags(): " + keyBags.length + " KeyBags found"); - ecdsaprivkeycache.put(pkcs12,keyBags[0].getPrivateKey()); - return (ECDSAPrivateKey) keyBags[0].getPrivateKey(); - } - - /* ==================================================================================================== */ - - public static HashMap x509cache = new HashMap(); - - public X509Certificate[] getCertificates( PKCS12 pkcs12 ) throws Exception - { - if(x509cache.containsKey(pkcs12)) return (X509Certificate[])x509cache.get(pkcs12); - X509Certificate[] ret = CertificateBag.getCertificates(pkcs12.getCertificateBags()); - x509cache.put(pkcs12,ret); - return ret; - } - - /* ==================================================================================================== */ - /* ==================Created and or changed Methods by Stefan Knirsch================================== */ - /* ==================================================================================================== */ - - public String vxReqFile(String testNumber) - { - return configuration_.getProperty("baseDir") + - "/data/VX0/"+ - configuration_.getProperty("TestClass") + - "." + - testNumber + - ".Req.xml"; - } - - public String vxResFile(String testNumber) - { - return configuration_.getProperty("baseDir") + - "/data/VX0/"+ - configuration_.getProperty("TestClass") + - "." + - testNumber + - ".Res.xml"; - } - - public String vxReqFileL(String testNumber,String filename) - { - return configuration_.getProperty("baseDir") + - "/data/LVX"+filename+"/"+ - configuration_.getProperty("TestClass") + - "." + - testNumber + - ".Req.xml"; - } - - public String vxResFileL(String testNumber,String filename) - { - return configuration_.getProperty("baseDir") + - "/data/LVX"+filename+"/"+ - configuration_.getProperty("TestClass") + - "." + - testNumber + - ".Res.xml"; - } - - public void createVXConfig() throws Exception { - - String file = - configuration_.getProperty("baseDir") - + "resources/" - + configuration_.getProperty("TestClass") - + ".Config.xml"; - String config = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+ - "<MOAConfiguration xmlns=\"http://reference.e-government.gv.at/namespace/moaconfig/20021122#\">" - + "<TrustProfile id=\"TrustProfile1\" uri=\"file://SERVER_WORKING_DIRECTORY/TrustProfile1\"/>" - + "<SupplementProfile id=\"SupplementProfile1\" uri=\"file://SERVER_WORKING_DIRECTORY/SupplementProfile1\"/>" - + "<SupplementProfile id=\"SupplementProfile2\" uri=\"file://SERVER_WORKING_DIRECTORY/SupplementProfile2\"/>" - + "</MOAConfiguration>"; - - FileOutputStream fos = new FileOutputStream(file); - fos.write(config.getBytes()); - } - - /** - * Method replaceString. - * @param input: String to be changed - * @param oldPart: subString in input to be changed - * @param newPart: new subString instead of the oldPart - * @return String - * @throws Exception - */ - public static String replaceString( - String input, - String oldPart, - String newPart) - throws Exception { - String erg = null; - - //First Part - erg = input.substring(0, input.indexOf(oldPart)); - //Insert new Part - erg += newPart; - - //insert REST - erg - += input.substring( - input.indexOf(oldPart) + oldPart.length(), - input.length()); - - return erg; - } - - public static String replaceStringAll( - String input, - String oldPart, - String newPart) - throws Exception { - - String erg = input; - - while(true) - { - - //First Part - int pos = input.indexOf(oldPart); - if(pos==-1) break; - erg = input.substring(0, pos); - - //Insert new Part - erg += newPart; - - //insert REST - erg - += input.substring( - input.indexOf(oldPart) + oldPart.length(), - input.length()); - - input = erg; - } - return erg; - } - - /** - * Method readFile. - * @param filename - * @return String - * @throws Exception - */ - - public String readFile(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"); - } - */ - RandomAccessFile raf = new RandomAccessFile(filename, "r"); - if (raf.length() > Integer.MAX_VALUE) - throw new IOException("file too big to fit in byte array."); - - byte[] result = new byte[(int) raf.length()]; - - raf.read(result); - - return new String(result); - - } - /** - * Method readBinaryFileAsBase64. - * @param filename - * @return Stringrepresentation as Base64 of the inputfile and saves that file - * @throws Exception - */ - public String readBinaryFileAsBase64_new(String filename) throws Exception { - - RandomAccessFile raf = new RandomAccessFile(filename, "r"); - if (raf.length() > Integer.MAX_VALUE) - throw new IOException("file too big to fit in byte array."); - byte[] result = new byte[(int) raf.length()]; - //READ the original binary Data - raf.read(result); - - //Convert the data to bas64 and store it in a new file - - ByteArrayOutputStream fos = new ByteArrayOutputStream(); - Base64OutputStream base64os = new Base64OutputStream(fos); - base64os.write(result); - base64os.flush(); - - return fos.toString(); - - } - public String readBinaryFileAsBase64(String filename) throws Exception { - - RandomAccessFile raf = new RandomAccessFile(filename, "r"); - if (raf.length() > Integer.MAX_VALUE) - throw new IOException("file too big to fit in byte array."); - byte[] result = new byte[(int) raf.length()]; - //READ the original binary Data - raf.read(result); - - //Convert the data to bas64 and store it in a new file - FileOutputStream fos = new FileOutputStream(filename + "base64.enc"); - Base64OutputStream base64os = new Base64OutputStream(fos); - base64os.write(result); - base64os.flush(); - base64os.close(); - - //read the converted data und return it - raf = new RandomAccessFile(filename + "base64.enc", "r"); - if (raf.length() > Integer.MAX_VALUE) - throw new IOException("Converted base64 file too big to fit in byte array."); - result = new byte[(int) raf.length()]; - //READ the original binary Data - raf.read(result); - - return new String(result); - - } - - /** - * Method writeFile. - * @param filename - * @param data - * @throws Exception - */ - public void writeFile(String filename, String data) throws Exception { - BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); - bw.write(data); - bw.close(); - } - - /** - * Method writeFileBinary - * @param filename - * @param data - * @throws Exception - */ - public void writeFileBinary(String filename, byte[] data) throws Exception { - BufferedOutputStream bw = new BufferedOutputStream(new FileOutputStream(filename)); - bw.write(data); - bw.close(); - } - /** - * Method getDate. - * @param changeHours to change the time into the past or future - * @return String - */ - - public String getDate(long changeHours) { - - //Use the XML-Format for the Time - SimpleDateFormat formatter = - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'+01:00"); - //get the current Time - Date currentTime = new Date(); - //add or substract a few hours - currentTime.setTime( - (currentTime.getTime() + changeHours * 1000 * 60 * 60)); - - return formatter.format(currentTime); - } - - public ASN1Object createSignedCMSData(byte[] message, int mode,boolean two_users) throws Exception { - - System.out.println("Create a new message signed by user 1:"); - - // create a new SignedData object which includes the data - SignedData signed_data = new SignedData(message, mode); - // SignedData shall include the certificate chain for verifying - - PKCS12 pkcs12 = decryptPKCS12( - configuration_.getProperty("PKCS12file"), - configuration_.getProperty("PKCS12password")); - - BufferedInputStream bis = new BufferedInputStream(new FileInputStream(configuration_.getProperty("CERT"))); - iaik.x509.X509Certificate cert = new iaik.x509.X509Certificate(bis); - user1_sign = cert; - X509name = ((Name)(cert.getIssuerDN())).getRFC2253String(); - X509number = cert.getSerialNumber(); - X509hash = new String(cert.getFingerprintSHA()); - X509sub = ((Name)cert.getSubjectDN()).getRFC2253String(); - - iaik.x509.X509Certificate[] certarray = new iaik.x509.X509Certificate[1]; - certarray[0] = cert; - - signed_data.setCertificates(certarray); - - - RSAPrivateKey privateKey = getPrivateKey( pkcs12 ); - - // cert at index 0 is the user certificate - IssuerAndSerialNumber issuer = new IssuerAndSerialNumber((Name)cert.getIssuerDN(),X509number); - - // create a new SignerInfo - SignerInfo signer_info = new SignerInfo(issuer, AlgorithmID.sha1, privateKey); - // create some authenticated attributes - // the message digest attribute is automatically added - Attribute[] attributes = new Attribute[2]; - // content type is data - attributes[0] = new Attribute(ObjectID.contentType, new ASN1Object[] {ObjectID.cms_data}); - // signing time is now - attributes[1] = new Attribute(ObjectID.signingTime, new ASN1Object[] {new ChoiceOfTime().toASN1Object()}); - // set the attributes - signer_info.setSignedAttributes(attributes); - // finish the creation of SignerInfo by calling method addSigner - try { - signed_data.addSignerInfo(signer_info); - - if(two_users) - { - // another SignerInfo without authenticated attributes and MD5 as hash algorithm - signer_info = new SignerInfo(new IssuerAndSerialNumber((Name)cert.getIssuerDN(),X509number), - AlgorithmID.md5, privateKey); - // the message digest itself is protected - signed_data.addSignerInfo(signer_info); - } - - } catch (NoSuchAlgorithmException ex) { - ex.printStackTrace(); - throw new CMSException("No implementation for signature algorithm: "+ex.getMessage()); - } - - ContentInfo ci = new ContentInfo(signed_data); - return ci.toASN1Object(); - } - - public ASN1Object createSignedCMSData(byte[] message, int mode,boolean two_users,String pkcs12file,String pkcs12password,String certname) throws Exception { - - System.out.println("Create a new message signed by user 1:"); - - // create a new SignedData object which includes the data - SignedData signed_data = new SignedData(message, mode); - // SignedData shall include the certificate chain for verifying - - PKCS12 pkcs12 = decryptPKCS12( - configuration_.getProperty(pkcs12file), - configuration_.getProperty(pkcs12password)); - - BufferedInputStream bis = new BufferedInputStream(new FileInputStream(configuration_.getProperty(certname))); - iaik.x509.X509Certificate cert = new iaik.x509.X509Certificate(bis); - X509name = ((Name)(cert.getIssuerDN())).getRFC2253String(); - X509number = cert.getSerialNumber(); - X509hash = new String(cert.getFingerprintSHA()); - X509sub = ((Name)cert.getSubjectDN()).getRFC2253String(); - - iaik.x509.X509Certificate[] certarray = new iaik.x509.X509Certificate[1]; - certarray[0] = cert; - - signed_data.setCertificates(certarray); - - - RSAPrivateKey privateKey = getPrivateKey( pkcs12 ); - - // cert at index 0 is the user certificate - IssuerAndSerialNumber issuer = new IssuerAndSerialNumber((Name)cert.getIssuerDN(),X509number); - - // create a new SignerInfo - SignerInfo signer_info = new SignerInfo(issuer, AlgorithmID.sha1, privateKey); - // create some authenticated attributes - // the message digest attribute is automatically added - Attribute[] attributes = new Attribute[2]; - // content type is data - attributes[0] = new Attribute(ObjectID.contentType, new ASN1Object[] {ObjectID.cms_data}); - // signing time is now - attributes[1] = new Attribute(ObjectID.signingTime, new ASN1Object[] {new ChoiceOfTime().toASN1Object()}); - // set the attributes - signer_info.setSignedAttributes(attributes); - // finish the creation of SignerInfo by calling method addSigner - try { - signed_data.addSignerInfo(signer_info); - - if(two_users) - { - // another SignerInfo without authenticated attributes and MD5 as hash algorithm - signer_info = new SignerInfo(new IssuerAndSerialNumber((Name)cert.getIssuerDN(),X509number), - AlgorithmID.md5, privateKey); - // the message digest itself is protected - signed_data.addSignerInfo(signer_info); - } - - } catch (NoSuchAlgorithmException ex) { - throw new CMSException("No implementation for signature algorithm: "+ex.getMessage()); - } - - ContentInfo ci = new ContentInfo(signed_data); - return ci.toASN1Object(); - } - -public String cutXML(String input) - { - int pos = input.indexOf(">"); - if(pos!=-1) - return input.substring(pos+1); - else - return input; - } - - -} diff --git a/spss.test/src/testgenerator/TestGeneratorCX0.java b/spss.test/src/testgenerator/TestGeneratorCX0.java deleted file mode 100644 index 31778c6a2..000000000 --- a/spss.test/src/testgenerator/TestGeneratorCX0.java +++ /dev/null @@ -1,2940 +0,0 @@ - -package testgenerator; -import iaik.apps.util.passphrase.PassphrasePrompt; -import iaik.asn1.structures.Name; -import iaik.ixsil.algorithms.CanonicalizationAlgorithmImplCanonicalXML; -import iaik.ixsil.algorithms.DigestAlgorithmImplSHA1; -import iaik.ixsil.algorithms.SignatureAlgorithmImplECDSA; -import iaik.ixsil.algorithms.SignatureAlgorithmImplRSA; -import iaik.ixsil.algorithms.TransformImplBase64Decode; -import iaik.ixsil.core.Signer; -import iaik.ixsil.core.SignerManifest; -import iaik.ixsil.core.SignerReference; -import iaik.ixsil.core.SignerSignature; -import iaik.ixsil.core.SignerSignedInfo; -import iaik.ixsil.init.IXSILConstants; -import iaik.ixsil.init.IXSILInit; -import iaik.ixsil.keyinfo.KeyManagerImpl; -import iaik.ixsil.keyinfo.x509.KeyProviderImplX509Data; -import iaik.ixsil.keyinfo.x509.X509Data; -import iaik.ixsil.util.URI; -import iaik.pkcs.pkcs11.objects.Certificate; -import iaik.pkcs.pkcs11.objects.PrivateKey; -import iaik.pkcs.pkcs11.objects.PublicKey; -import iaik.pkcs.pkcs11.provider.IAIKPkcs11; -import iaik.pkcs.pkcs11.provider.keys.IAIKPKCS11RsaPrivateKey; -import iaik.pkcs.pkcs11.provider.keys.IAIKPKCS11RsaPublicKey; -import iaik.pkcs.pkcs12.CertificateBag; -import iaik.pkcs.pkcs12.PKCS12; -import iaik.security.ecc.interfaces.ECDSAPrivateKey; -import iaik.security.provider.IAIK; -import iaik.utils.Base64OutputStream; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.RandomAccessFile; -import java.net.URL; -import java.security.Key; -import java.security.KeyStore; -import java.security.Security; -import java.security.Signature; -import java.security.cert.X509Certificate; -import java.security.interfaces.RSAPrivateKey; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Properties; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.apache.xerces.dom.DocumentFragmentImpl; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.Text; - -import at.gv.egovernment.moa.util.Base64Utils; -import at.gv.egovernment.moa.util.DOMUtils; - -import sun.misc.BASE64Encoder; - -/** - * @author stephan - */ -public class TestGeneratorCX0 extends TestCases { - - String datadirectory = "data/CX0/"; - String datadirectory_3 = "data/CX3/"; - String datadirectory_4 = "data/CX4/"; - String datadirectory_l = "data/LCX"; - - public String defaultblock = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\">\n"+ - " <!-- Hint -->\n"+ - " </DataObject>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - public static void main(String[] args) throws Exception { - TestGeneratorCX0 testcase = new TestGeneratorCX0(); - - testcase.createConfig(); - testcase.create001(); - testcase.create002(); - testcase.create003(); - //testcase.create004(); - testcase.create005(); - //testcase.create006(); - testcase.create007(); - testcase.create008(); - testcase.create009(); - testcase.create010(); - testcase.create011(); - testcase.create012(); - testcase.create013(); - testcase.create014(); - testcase.create015(); - testcase.create016(); - testcase.create017(); - testcase.create018(); - testcase.create019(); - - testcase.create051(); - testcase.create052(); - testcase.create053(); - testcase.create054(); - testcase.create055(); - testcase.create056(); - testcase.create057(); - testcase.create058(); - testcase.create059(); - testcase.create060(); - //testcase.create061(); - testcase.create062(); - //testcase.create063(); - testcase.create064(); - testcase.create065(); - - //testcase.createL00();*/ - - } - - /* ==================================================================================================== */ - - public TestGeneratorCX0() throws Exception { - - super(); - - // Set config properties - configuration_.setProperty("TestClass", "TestGeneratorCX0"); -// 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.provider.IAIK.addAsJDK14Provider(); - iaik.security.ecc.provider.ECCProvider.addAsProvider(); - //iaik.security.ecc.provider.ECCProvider.addAsProvider(); - } - - /* ==================================================================================================== */ - - public Document createECDSPKCS12Sig(String tn,String fileref) throws Exception - { - String TestNumber = tn; - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - // String res = "emtpy"; - // FileOutputStream resFOS = new FileOutputStream(resFile); - // resFOS.write(res.getBytes()); - - PKCS12 pkcs12 = decryptPKCS12( - configuration_.getProperty("ECDSPKCS12file"), - configuration_.getProperty("ECDSPKCS12password" ) ); - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - Signer signer = new Signer(baseURI); - - // Configure signed information - - // Get interface for signed information - SignerSignedInfo signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set canonicalization algorithm - CanonicalizationAlgorithmImplCanonicalXML c14nAlg = - new CanonicalizationAlgorithmImplCanonicalXML(); - signedInfo.setCanonicalizationAlgorithm(c14nAlg); - - CertificateBag cb[] = pkcs12.getCertificateBags(); - System.out.println("LEN:"+cb.length); - iaik.x509.X509Certificate cert[] = cb[0].getCertificates(cb); - System.out.println("LEN2:"+cert.length); - System.out.println("CERT:"+(((Name)(cert[0].getIssuerDN())).getRFC2253String())); - - - // Set signature algorithm - /* TODO: Change to ECDS Impl */ - SignatureAlgorithmImplECDSA signatureAlg = new SignatureAlgorithmImplECDSA(); - ECDSAPrivateKey privateKey = getPrivateKeyECDS( pkcs12 ); - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(fileref); - - SignerReference reference = signedInfo.createReference(); - reference.setURI(refURI); - reference.setId("reference-1-1"); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - // Add reference to signature - signedInfo.addReference(reference); - - // Create key information - KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument()); - - X509Certificate[] certs = getCertificates(pkcs12); - X509Data x509Data = new X509Data(); - for (int i = 0; i < certs.length; i++) - { - x509Data.insertHintAt(certs[i], i); - } - - KeyProviderImplX509Data x509DataKeyProvider = new KeyProviderImplX509Data(signer.toDocument()); - x509DataKeyProvider.insertX509DataAt(x509Data, 0); - - // X509Data key information (certificate chain) - keyManager.addKeyProvider(x509DataKeyProvider); - - signer.getSignature().setKeyManager(keyManager); - signer.getSignature().setId("signature-1-1"); - // Compute signature value - signer.getSignature().sign(); - Document doc = signer.toDocument(); - System.out.println(doc.getDocumentElement().getNodeName()); - - return doc; - } - - public Document createPKCS12Sig(String tn,String fileref) throws Exception - { - return createPKCS12Sig(tn,fileref,false,false,null,false); - } - - public Document createPKCS12Sig(String tn,String fileref,String id1,String id2) throws Exception - { - return createPKCS12Sig(tn,fileref,false,false,null,false,id1,id2); - } - - public Document createPKCS12SigWithEnveloping(String TestNumber,String data) throws Exception - { - return createPKCS12Sig(TestNumber,data,true,false,null,false); - } - - public Document createPKCS12Sig(String TestNumber,String data,boolean env,boolean mani) throws Exception - { - return createPKCS12Sig(TestNumber,data,env,mani,null,false); - } - - public Document createPKCS12Sig(String TestNumber,String data,boolean env,boolean mani,String data2,boolean env2) throws Exception - { - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - PKCS12 pkcs12 = decryptPKCS12( - configuration_.getProperty("PKCS12file"), - configuration_.getProperty("PKCS12password" ) ); - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - Signer signer = new Signer(baseURI); - - // Configure signed information - - // Get interface for signed information - SignerSignature signature = signer.getSignature(); - SignerSignedInfo signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set canonicalization algorithm - CanonicalizationAlgorithmImplCanonicalXML c14nAlg = - new CanonicalizationAlgorithmImplCanonicalXML(); - signedInfo.setCanonicalizationAlgorithm(c14nAlg); - - // Set signature algorithm - SignatureAlgorithmImplRSA signatureAlg = new SignatureAlgorithmImplRSA(); - RSAPrivateKey privateKey = getPrivateKey( pkcs12 ); - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - - if(!mani) - { - SignerReference reference = signedInfo.createReference(); - if(env) - { - iaik.ixsil.core.Object object = null; - //object = signature.createObject(data); - if(data.startsWith("<xml")) - { - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(data.getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else if(data.startsWith("<Testdaten")) - { - - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(("<?xml version=\"1.0\" encoding=\"utf-8\"?>"+data).getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else if(data.startsWith("b64:")) - { - data = data.substring(4); - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.newDocument(); - Element root = doc.createElement("root"); - doc.appendChild(root); - //String encoded = Base64Utils.encode(data.getBytes()); - String encoded = Base64Utils.encode(data.getBytes()); - /*encoded = replaceStringAll(encoded,"\n",""); - encoded = replaceStringAll(encoded,"\r","");*/ - Text textnode = doc.createTextNode(encoded); - - System.out.println("Encoded:"+encoded); - //root.appendChild(textnode); - - DocumentFragment df = doc.createDocumentFragment(); - - df.appendChild(textnode); - - object = signature.createObject(df); - - TransformImplBase64Decode trans = new TransformImplBase64Decode(); - InputStream s = new ByteArrayInputStream(encoded.getBytes()); - trans.setInput(s,null); - - reference.insertTransformAt(trans,0); - } - else - { - object = signature.createObject(data); - } - - object.setId("signed-data-1-1-1"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - reference.setURI(new URI("#xpointer(id('signed-data-1-1-1')/node())")); - - - } - else - { - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(data); - - - reference.setURI(refURI); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - } - reference.setId("reference-1-1"); - signedInfo.addReference(reference); - } - - if(data2!=null) - { - SignerReference reference = signedInfo.createReference(); - reference = signedInfo.createReference(); - if(env2) - { - iaik.ixsil.core.Object object = null; - if(data2.startsWith("<xml")) - { - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(data.getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else if(data2.startsWith("<Testdaten")) - { - - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(("<?xml version=\"1.0\" encoding=\"utf-8\"?>"+data).getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else - object = signature.createObject(data2); - - if(!env) - object.setId("signed-data-1-2-1"); - else - object.setId("signed-data-1-2-1"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - if(!env) - reference.setURI(new URI("#xpointer(id('signed-data-1-2-1')/node())")); - else - reference.setURI(new URI("#xpointer(id('signed-data-1-2-1')/node())")); - } - else - { - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(data2); - - - reference.setURI(refURI); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - } - reference.setId("reference-1-2"); - signedInfo.addReference(reference); - } - - // Add reference to signature - - - - if(mani) - { - - /*iaik.ixsil.core.Object object = null; - if(env) - object = signature.createObject(readFile(data)); - else - object = signature.createObject(data); - - object.setId("envelopedData"); - signature.addObject(object);*/ - SignerReference reference = signedInfo.createReference(); - SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - manifestRef.setDigestAlgorithm(digestAlg); - - manifestRef.setURI(new URI(data)); - manifestRef.setId("reference-1-1"); - - manifest.addReference(manifestRef); - manifest.setId("dsig-manifest-1-1"); - iaik.ixsil.core.Object manifestObject = signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - reference = signedInfo.createReference(); - reference.setURI( - new URI("#dsig-manifest-1-1")); - reference.setType(new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference); - - - /*Element envelopedDataElem = - signer.toDocument().createElement("EnvelopedDataElement"); - - if(env) - { - envelopedDataElem.appendChild( - signer.toDocument().createTextNode(readFile(data))); - } - else - { - envelopedDataElem.appendChild( - signer.toDocument().createTextNode(data)); - } - - iaik.ixsil.core.Object object = signature.createObject(envelopedDataElem); - signature.addObject(object); - - // Create Manifest with a single reference pointing to the enveloped data - SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - manifestRef.setURI( - new URI( - null, - null, - null, - null, - "xmlns(dsig=" - + IXSILConstants.NAMESPACE_URI_XMLSIGNATURE_ELEM_ - + ") " - + "xpointer(here()/ancestor::dsig:Signature[1]/dsig:Object[1]/descendant::node())")); - manifestRef.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - manifest.addReference(manifestRef); - - // Add Manifest to signature structure (use an Object) and compute digest values for manifest reference - iaik.ixsil.core.Object manifestObject = signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - // Create and configure reference to manifest - reference = signedInfo.createReference(); - reference.setURI( - new URI( - null, - null, - null, - null, - "xmlns(dsig=" - + IXSILConstants.NAMESPACE_URI_XMLSIGNATURE_ELEM_ - + ") " - + "xpointer(here()/ancestor::dsig:Signature[1]/dsig:Object[2]/dsig:Manifest)")); - reference.setType(new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference);*/ - } - - // Create key information - KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument()); - - X509Certificate[] certs = getCertificates(pkcs12); - X509Data x509Data = new X509Data(); - x509Data.insertHintAt(certs[1], 0); - /*for (int i = 0; i < certs.length; i++) - { - - }*/ - - KeyProviderImplX509Data x509DataKeyProvider = new KeyProviderImplX509Data(signer.toDocument()); - x509DataKeyProvider.insertX509DataAt(x509Data, 0); - - // X509Data key information (certificate chain) - keyManager.addKeyProvider(x509DataKeyProvider); - - signer.getSignature().setKeyManager(keyManager); - signer.getSignature().setId("signature-1-1"); - // Compute signature value - signer.getSignature().sign(); - - return signer.toDocument(); - } - - public Document createPKCS12Sig(String TestNumber,String data,boolean env,boolean mani,String data2,boolean env2,String id1,String id2) throws Exception - { - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - PKCS12 pkcs12 = decryptPKCS12( - configuration_.getProperty("PKCS12file"), - configuration_.getProperty("PKCS12password" ) ); - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - Signer signer = new Signer(baseURI); - - // Configure signed information - - // Get interface for signed information - SignerSignature signature = signer.getSignature(); - SignerSignedInfo signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set canonicalization algorithm - CanonicalizationAlgorithmImplCanonicalXML c14nAlg = - new CanonicalizationAlgorithmImplCanonicalXML(); - signedInfo.setCanonicalizationAlgorithm(c14nAlg); - - // Set signature algorithm - SignatureAlgorithmImplRSA signatureAlg = new SignatureAlgorithmImplRSA(); - RSAPrivateKey privateKey = getPrivateKey( pkcs12 ); - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - - if(!mani) - { - SignerReference reference = signedInfo.createReference(); - if(env) - { - iaik.ixsil.core.Object object = null; - //object = signature.createObject(data); - if(data.startsWith("<xml")) - { - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(data.getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else if(data.startsWith("<Testdaten")) - { - - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(("<?xml version=\"1.0\" encoding=\"utf-8\"?>"+data).getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else if(data.startsWith("b64:")) - { - data = data.substring(4); - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.newDocument(); - Element root = doc.createElement("root"); - doc.appendChild(root); - //String encoded = Base64Utils.encode(data.getBytes()); - String encoded = Base64Utils.encode(data.getBytes()); - /*encoded = replaceStringAll(encoded,"\n",""); - encoded = replaceStringAll(encoded,"\r","");*/ - Text textnode = doc.createTextNode(encoded); - - System.out.println("Encoded:"+encoded); - //root.appendChild(textnode); - - DocumentFragment df = doc.createDocumentFragment(); - - df.appendChild(textnode); - - object = signature.createObject(df); - - TransformImplBase64Decode trans = new TransformImplBase64Decode(); - InputStream s = new ByteArrayInputStream(encoded.getBytes()); - trans.setInput(s,null); - - reference.insertTransformAt(trans,0); - } - else - { - object = signature.createObject(data); - } - - object.setId("signed-data-1-1-1"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - reference.setURI(new URI("#xpointer(id('signed-data-1-1-1')/node())")); - - - } - else - { - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(data); - - - reference.setURI(refURI); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - } - reference.setId("reference-2-1"); - signedInfo.addReference(reference); - } - - if(data2!=null) - { - SignerReference reference = signedInfo.createReference(); - reference = signedInfo.createReference(); - if(env2) - { - iaik.ixsil.core.Object object = null; - if(data2.startsWith("<xml")) - { - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(data.getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else if(data2.startsWith("<Testdaten")) - { - - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(("<?xml version=\"1.0\" encoding=\"utf-8\"?>"+data).getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else - object = signature.createObject(data2); - - if(!env) - object.setId("signed-data-1-2-1"); - else - object.setId("signed-data-1-2-1"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - if(!env) - reference.setURI(new URI("#xpointer(id('signed-data-1-2-1')/node())")); - else - reference.setURI(new URI("#xpointer(id('signed-data-1-2-1')/node())")); - } - else - { - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(data2); - - - reference.setURI(refURI); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - } - reference.setId("reference-1-2"); - signedInfo.addReference(reference); - } - - // Add reference to signature - - - - if(mani) - { - - /*iaik.ixsil.core.Object object = null; - if(env) - object = signature.createObject(readFile(data)); - else - object = signature.createObject(data); - - object.setId("envelopedData"); - signature.addObject(object);*/ - SignerReference reference = signedInfo.createReference(); - SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - manifestRef.setDigestAlgorithm(digestAlg); - - manifestRef.setURI(new URI(data)); - manifestRef.setId("reference-1-1"); - - manifest.addReference(manifestRef); - manifest.setId("dsig-manifest-1-1"); - iaik.ixsil.core.Object manifestObject = signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - reference = signedInfo.createReference(); - reference.setURI( - new URI("#dsig-manifest-1-1")); - reference.setType(new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference); - - - /*Element envelopedDataElem = - signer.toDocument().createElement("EnvelopedDataElement"); - - if(env) - { - envelopedDataElem.appendChild( - signer.toDocument().createTextNode(readFile(data))); - } - else - { - envelopedDataElem.appendChild( - signer.toDocument().createTextNode(data)); - } - - iaik.ixsil.core.Object object = signature.createObject(envelopedDataElem); - signature.addObject(object); - - // Create Manifest with a single reference pointing to the enveloped data - SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - manifestRef.setURI( - new URI( - null, - null, - null, - null, - "xmlns(dsig=" - + IXSILConstants.NAMESPACE_URI_XMLSIGNATURE_ELEM_ - + ") " - + "xpointer(here()/ancestor::dsig:Signature[1]/dsig:Object[1]/descendant::node())")); - manifestRef.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - manifest.addReference(manifestRef); - - // Add Manifest to signature structure (use an Object) and compute digest values for manifest reference - iaik.ixsil.core.Object manifestObject = signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - // Create and configure reference to manifest - reference = signedInfo.createReference(); - reference.setURI( - new URI( - null, - null, - null, - null, - "xmlns(dsig=" - + IXSILConstants.NAMESPACE_URI_XMLSIGNATURE_ELEM_ - + ") " - + "xpointer(here()/ancestor::dsig:Signature[1]/dsig:Object[2]/dsig:Manifest)")); - reference.setType(new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference);*/ - } - - // Create key information - KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument()); - - X509Certificate[] certs = getCertificates(pkcs12); - X509Data x509Data = new X509Data(); - x509Data.insertHintAt(certs[1], 0); - /*for (int i = 0; i < certs.length; i++) - { - - }*/ - - KeyProviderImplX509Data x509DataKeyProvider = new KeyProviderImplX509Data(signer.toDocument()); - x509DataKeyProvider.insertX509DataAt(x509Data, 0); - - // X509Data key information (certificate chain) - keyManager.addKeyProvider(x509DataKeyProvider); - - signer.getSignature().setKeyManager(keyManager); - signer.getSignature().setId("signature-2-1"); - // Compute signature value - signer.getSignature().sign(); - - return signer.toDocument(); - } - - public Document createHSMSig(String TestNumber,String data,boolean env,boolean mani,String data2,boolean env2) throws Exception - { - String keyId = null; - String certId = null; - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - Signer signer = new Signer(baseURI); - - // Configure signed information - - // Get interface for signed information - SignerSignature signature = signer.getSignature(); - SignerSignedInfo signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set canonicalization algorithm - CanonicalizationAlgorithmImplCanonicalXML c14nAlg = - new CanonicalizationAlgorithmImplCanonicalXML(); - signedInfo.setCanonicalizationAlgorithm(c14nAlg); - - Properties config = new Properties(); - config.put("PKCS11_NATIVE_MODULE","cryptoki.dll"); - config.put("SLOT_ID","0"); - config.put("DEFAULT_PROMPT_DIALOG","testgenerator.Pass"); - - Security.addProvider(new IAIK()); - IAIKPkcs11 pkcs11Provider_ = new IAIKPkcs11(config); - Security.addProvider(pkcs11Provider_); - - // Set signature algorithm - SignatureAlgorithmImplRSA signatureAlg = new SignatureAlgorithmImplRSA(); - signatureAlg.setJCEProviderName(pkcs11Provider_.getName()); - - // HSM Action start - - // load the keystore of the PKCS#11 provider given via input stream - KeyStore tokenKeyStore = pkcs11Provider_.getTokenManager().getKeyStore(); - tokenKeyStore.load(null,"1111".toCharArray()); - - Enumeration enum = tokenKeyStore.aliases(); - - String ali = null; - while(enum.hasMoreElements()) - { - //enum.nextElement(); - ali = (String)enum.nextElement(); - //ali = (String)enum.nextElement(); - System.out.println("Alias:"+ali); - if(tokenKeyStore.containsAlias(ali)) System.out.println("ALIAS vorhanden"); - if(tokenKeyStore.isKeyEntry(ali)) System.out.println("KEYENTRY vorhanden"); - } - - Enumeration enum2 = tokenKeyStore.aliases(); - - while (enum2.hasMoreElements()) { - String alias = enum2.nextElement().toString(); - - if (tokenKeyStore.isKeyEntry(alias)) { - System.out.println("________________________________________________________________________________"); - System.out.println("Key entry with alias: " + alias); - Key key = tokenKeyStore.getKey(alias, null); - System.out.println(key); - java.security.cert.Certificate[] certificateChain2 = tokenKeyStore.getCertificateChain(alias); - if (certificateChain2 != null) { - System.out.println("Certificate chain of length: " + certificateChain2.length); - for (int i = 0; i < certificateChain2.length; i++) { - System.out.println("--------------------------------------------------------------------------------"); - System.out.println(certificateChain2[i]); - } - } else { - System.out.println("Certificate chain is null!"); - } - System.out.println("________________________________________________________________________________"); - } else if (tokenKeyStore.isCertificateEntry(alias)) { - System.out.println("________________________________________________________________________________"); - System.out.println("Certificate entry with alias: " + alias); - java.security.cert.Certificate certificate = tokenKeyStore.getCertificate(alias); - System.out.println(certificate); - System.out.println("________________________________________________________________________________"); - } else { - System.out.println("________________________________________________________________________________"); - System.out.println("ERROR! Unknown entry type with alias: " + alias); - System.out.println("________________________________________________________________________________"); - } - } - - - IAIKPKCS11RsaPrivateKey privateKey = (IAIKPKCS11RsaPrivateKey)tokenKeyStore.getKey("MOAHSMRSAKEY_cert", null); - keyId = new String(privateKey.getKeyID()); - - System.out.println(new String(privateKey.getKeyID())); - //System.out.println("got:"+signatureKey+" : "+signatureKey.getClass().getName()); - - Signature signatureEngine = Signature.getInstance("ExternalSHA1WithRSA", pkcs11Provider_.getName()); - signatureEngine.initSign(privateKey); - /*signatureEngine.update("This is some data to be signed.".getBytes()); - byte[] bytesig = signatureEngine.sign(); - System.out.println("SIG:"+new String(bytesig)); - - System.out.println("KEY:\n"+privateKey);*/ - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - - SignerReference reference = signedInfo.createReference(); - - if(!mani) - { - if(env) - { - iaik.ixsil.core.Object object = null; - object = signature.createObject(data); - object.setId("signed-data-0-1"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - reference.setURI(new URI("#xpointer(id('signed-data-0-1')/node())")); - } - else - { - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(data); - - - reference.setURI(refURI); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - } - reference.setId("reference-1-1"); - signedInfo.addReference(reference); - } - - if(data2!=null) - { - reference = signedInfo.createReference(); - if(env2) - { - iaik.ixsil.core.Object object = null; - object = signature.createObject(data2); - object.setId("signed-data-0-2"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - reference.setURI(new URI("#xpointer(id('signed-data-0-2')/node())")); - } - else - { - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(data2); - - - reference.setURI(refURI); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - } - signedInfo.addReference(reference); - } - - // Add reference to signature - - - - if(mani) - { - - /*iaik.ixsil.core.Object object = null; - if(env) - object = signature.createObject(readFile(data)); - else - object = signature.createObject(data); - - object.setId("envelopedData"); - signature.addObject(object);*/ - - SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - manifestRef.setDigestAlgorithm(digestAlg); - - manifestRef.setURI(new URI(data)); - - manifest.addReference(manifestRef); - manifest.setId("manifest-1"); - iaik.ixsil.core.Object manifestObject = signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - reference = signedInfo.createReference(); - reference.setURI( - new URI("#xpointer(id('manifest-1'))")); - reference.setType(new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference); - - - /*Element envelopedDataElem = - signer.toDocument().createElement("EnvelopedDataElement"); - - if(env) - { - envelopedDataElem.appendChild( - signer.toDocument().createTextNode(readFile(data))); - } - else - { - envelopedDataElem.appendChild( - signer.toDocument().createTextNode(data)); - } - - iaik.ixsil.core.Object object = signature.createObject(envelopedDataElem); - signature.addObject(object); - - // Create Manifest with a single reference pointing to the enveloped data - SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - manifestRef.setURI( - new URI( - null, - null, - null, - null, - "xmlns(dsig=" - + IXSILConstants.NAMESPACE_URI_XMLSIGNATURE_ELEM_ - + ") " - + "xpointer(here()/ancestor::dsig:Signature[1]/dsig:Object[1]/descendant::node())")); - manifestRef.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - manifest.addReference(manifestRef); - - // Add Manifest to signature structure (use an Object) and compute digest values for manifest reference - iaik.ixsil.core.Object manifestObject = signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - // Create and configure reference to manifest - reference = signedInfo.createReference(); - reference.setURI( - new URI( - null, - null, - null, - null, - "xmlns(dsig=" - + IXSILConstants.NAMESPACE_URI_XMLSIGNATURE_ELEM_ - + ") " - + "xpointer(here()/ancestor::dsig:Signature[1]/dsig:Object[2]/dsig:Manifest)")); - reference.setType(new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference);*/ - } - - enum2 = tokenKeyStore.aliases(); - - while(enum2.hasMoreElements()) - { - System.out.println(enum2.nextElement()); - } - - enum2 = tokenKeyStore.aliases(); - - while (enum2.hasMoreElements()) { - String alias = enum2.nextElement().toString(); - - if (tokenKeyStore.isKeyEntry(alias)) { - System.out.println("________________________________________________________________________________"); - System.out.println("Key entry with alias: " + alias); - Key key = tokenKeyStore.getKey(alias, null); - System.out.println(key); - java.security.cert.Certificate[] certificateChain2 = tokenKeyStore.getCertificateChain(alias); - if (certificateChain2 != null) { - System.out.println("Certificate chain of length: " + certificateChain2.length); - for (int i = 0; i < certificateChain2.length; i++) { - System.out.println("--------------------------------------------------------------------------------"); - System.out.println(certificateChain2[i]); - } - } else { - System.out.println("Certificate chain is null!"); - } - System.out.println("________________________________________________________________________________"); - } else if (tokenKeyStore.isCertificateEntry(alias)) { - System.out.println("________________________________________________________________________________"); - System.out.println("Certificate entry with alias: " + alias); - java.security.cert.Certificate certificate = tokenKeyStore.getCertificate(alias); - System.out.println(certificate); - System.out.println("________________________________________________________________________________"); - } else { - System.out.println("________________________________________________________________________________"); - System.out.println("ERROR! Unknown entry type with alias: " + alias); - System.out.println("________________________________________________________________________________"); - } - } - - // Create key information - KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument()); - - //DOMUtils.serializeNode(keyManager.getKeyInfo()); - - java.security.cert.Certificate[] certificateChain = tokenKeyStore.getCertificateChain("MOAHSMRSAKEY_cert"); - - System.out.println("CERTLEN:"+certificateChain.length); - - X509Data x509Data = new X509Data(); - for (int i = 0; i < certificateChain.length; i++) - { - System.out.println("CERT:"+((Name)(((X509Certificate)certificateChain[i]).getIssuerDN())).getRFC2253String()); - x509Data.insertHintAt((X509Certificate)certificateChain[i], i); - } - - KeyProviderImplX509Data x509DataKeyProvider = new KeyProviderImplX509Data(signer.toDocument()); - x509DataKeyProvider.insertX509DataAt(x509Data, 0); - - // X509Data key information (certificate chain) - keyManager.addKeyProvider(x509DataKeyProvider); - - signer.getSignature().setKeyManager(keyManager); - signer.getSignature().setId("signature-1-1"); - - // Compute signature value - signer.getSignature().sign(); - - return signer.toDocument(); - } - - public Document createPKCS12SigSL(String TestNumber,String data) throws Exception - { - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - PKCS12 pkcs12 = decryptPKCS12( - configuration_.getProperty("PKCS12file"), - configuration_.getProperty("PKCS12password" ) ); - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - Signer signer = new Signer(baseURI); - - // Configure signed information - - // Get interface for signed information - SignerSignature signature = signer.getSignature(); - SignerSignedInfo signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set canonicalization algorithm - CanonicalizationAlgorithmImplCanonicalXML c14nAlg = - new CanonicalizationAlgorithmImplCanonicalXML(); - signedInfo.setCanonicalizationAlgorithm(c14nAlg); - - // Set signature algorithm - SignatureAlgorithmImplRSA signatureAlg = new SignatureAlgorithmImplRSA(); - RSAPrivateKey privateKey = getPrivateKey( pkcs12 ); - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - - SignerReference reference = signedInfo.createReference(); - - // env - /*iaik.ixsil.core.Object object = null; - object = signature.createObject(data); - object.setId("envelopedData"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - reference.setURI(new URI("#xpointer(id('envelopedData')/node())"));*/ - - // detached - // Create and configure reference - URI refURI = null; - refURI = new URI(data); - - reference.setURI(refURI); - reference.setId("reference-1-1"); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - signedInfo.addReference(reference); - - reference = signedInfo.createReference(); - - refURI = null; - refURI = new URI(data); - - //reference.setURI(new URI("#xpointer(id('ETSIProperties'))/*/*")); - reference.setURI(new URI("#xmlns(etsi=http://uri.etsi.org/01903/v1.1.1%23)%20xpointer(id('etsi-signed-1-1')/child::etsi:QualifyingProperties/child::etsi:SignedProperties)")); - reference.setType(new URI("http://uri.etsi.org/01903/v1.1.1#SignedProperties")); - digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - signedInfo.addReference(reference); - - /*iaik.ixsil.core.Object object = null; - object = signature.createObject(data); - object.setId("SLManifestObject"); - - signature.addObject(object);*/ - - - /*SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - - digestAlg = new DigestAlgorithmImplSHA1(); - manifestRef.setDigestAlgorithm(digestAlg); - - manifestRef.setURI(new URI(data)); - - manifest.addReference(manifestRef); - manifest.setId("SLManifestObject"); - iaik.ixsil.core.Object manifestObject = signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - reference = manifest.createReference(); - reference.setType(new URI("http://www.buergerkarte.at/specifications/Security-Layer/20020225#SignatureManifest")); - reference.setURI(new URI("#SLManifestObject")); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference);*/ - - iaik.ixsil.core.Object object = null; - object = signature.createObject(getElement("TEST")); - object.setId("etsi-signed-1-1"); - signature.addObject(object); - - - - /*if(mani) - { - - SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - manifestRef.setDigestAlgorithm(digestAlg); - - manifestRef.setURI(new URI(data)); - - manifest.addReference(manifestRef); - manifest.setId("manifestObject"); - iaik.ixsil.core.Object manifestObject = signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - reference = signedInfo.createReference(); - reference.setURI( - new URI("#xpointer(id('manifestObject'))")); - reference.setType(new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference); - - }*/ - - signature.setId("signature-1-1"); - - // Create key information - KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument()); - - X509Certificate[] certs = getCertificates(pkcs12); - X509Data x509Data = new X509Data(); - x509Data.insertHintAt(certs[1], 0); - - KeyProviderImplX509Data x509DataKeyProvider = new KeyProviderImplX509Data(signer.toDocument()); - x509DataKeyProvider.insertX509DataAt(x509Data, 0); - - // X509Data key information (certificate chain) - keyManager.addKeyProvider(x509DataKeyProvider); - - signer.getSignature().setKeyManager(keyManager); - - // Compute signature value - signer.getSignature().sign(); - - return signer.toDocument(); - } - - public Element getElement(String data) throws Exception - { - String etsinamespace = "http://uri.etsi.org/01903/v1.1.1#"; - - getX509Content(); - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - //dbf.setNamespaceAware(true); - //dbf.setValidating(true); - - Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - - - Element qualprop = doc.createElementNS(etsinamespace,"etsi:QualifyingProperties"); - qualprop.setAttributeNS(null,"Target","#signature-1-1"); - qualprop.setAttributeNS(IXSILConstants.NAMESPACE_URI_NAMESPACES_,"xmlns:etsi",etsinamespace); - //qualprop.setPrefix("etsi");*/ - //qualprop.setAttributeNodeNS(doc.createAttributeNS(etsinamespace,"etsi")); - Element signprop = doc.createElementNS(etsinamespace,"etsi:SignedProperties"); - Element signsigprop = doc.createElementNS(etsinamespace,"etsi:SignedSignatureProperties"); - Element signdataobjectprop = doc.createElementNS(etsinamespace,"etsi:SignedDataObjectProperties"); - Element signdate = doc.createElementNS(etsinamespace,"etsi:SigningTime"); - Text datevalue = doc.createTextNode("2003-05-10T00:01:01"); - Element signcert = doc.createElementNS(etsinamespace,"etsi:SigningCertificate"); - Element cert = doc.createElementNS(etsinamespace,"etsi:Cert"); - Element signpolyident = doc.createElementNS(etsinamespace,"etsi:SignaturePolicyIdentifier"); - Element signpolyimp = doc.createElementNS(etsinamespace,"etsi:SignaturePolicyImplied"); - Element certdig = doc.createElementNS(etsinamespace,"etsi:CertDigest"); - Element digmeth = doc.createElementNS(etsinamespace,"etsi:DigestMethod"); - digmeth.setAttribute("Algorithm","http://www.w3.org/2000/09/xmldsig#sha1"); - Element digvalue = doc.createElementNS(etsinamespace,"etsi:DigestValue"); - - ByteArrayOutputStream fos = new ByteArrayOutputStream(); - Base64OutputStream base64os = new Base64OutputStream(fos); - base64os.write(this.X509hash.getBytes()); - base64os.flush(); - - Text dig_value = doc.createTextNode(fos.toString()); - Element is = doc.createElementNS(etsinamespace,"etsi:IssuerSerial"); - Element i = doc.createElement("dsig:X509IssuerName"); - Text i_value = doc.createTextNode(this.X509name); - Element s = doc.createElement("dsig:X509SerialNumber"); - Text s_value = doc.createTextNode(this.X509number.toString()); - Element dataobjformat = doc.createElementNS(etsinamespace,"etsi:DataObjectFormat"); - dataobjformat.setAttribute("ObjectReference","#reference-1-1"); - Element mimetype = doc.createElementNS(etsinamespace,"etsi:MimeType"); - //mimetype.setNodeValue("text/plain"); - Text mimevalue = doc.createTextNode("text/plain"); - - qualprop.appendChild(signprop); - signprop.appendChild(signsigprop); - signsigprop.appendChild(signdate); - signdate.appendChild(datevalue); - signsigprop.appendChild(signcert); - signcert.appendChild(cert); - cert.appendChild(certdig); - certdig.appendChild(digmeth); - certdig.appendChild(digvalue); - digvalue.appendChild(dig_value); - cert.appendChild(is); - is.appendChild(i); - i.appendChild(i_value); - is.appendChild(s); - s.appendChild(s_value); - signsigprop.appendChild(signpolyident); - signpolyident.appendChild(signpolyimp); - signprop.appendChild(signdataobjectprop); - signdataobjectprop.appendChild(dataobjformat); - dataobjformat.appendChild(mimetype); - mimetype.appendChild(mimevalue); - - - - return qualprop; - } - - - public void createConfig() throws Exception { - - String file = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - ".Config.xml"; - String config = - -"<MOAConfiguration xmlns=\"http://reference.e-government.gv.at/namespace/moaconfig/20021122#\">"+ -" <KeyGroup id=\"PKCS12RSAKey1\"> <Key id=\"resources/test-ee2003_normal(buergerkarte).p12\"/> </KeyGroup>"+ -" <KeyGroup id=\"PKCS12RSAKeyExpired\"> <Key id=\"sicher-demo(buergerkarte).p12\"/> </KeyGroup>"+ -" <KeyGroup id=\"PKCS12ECDSAKey1\"> <Key id=\"ecc.p12\"/> </KeyGroup> "+ -" <KeyGroup id=\"DSAinPKCS12\"> <Key id=\"DSA.512.p12\"/> </KeyGroup> "+ -" <KeyGroup id=\"HSMRSAKey1\"> <Key id=\"???\"/> </KeyGroup>"+ -" <KeyGroup id=\"HSMECDSAKey1\"> <Key id=\"???\"/> </KeyGroup>"+ -" <DigestMethodAlgorithm name=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>"+ -" <SignatureAlgorithm name=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>"+ -" <CanonicalizationAlgorithm name=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/>"+ -"</MOAConfiguration>"; - - - /*"<MOAConfiguration>\n"+ - " <KeyGroup id=\"PKCS12RSAKey1\"/> <!-- mapped auf \"test(1234).p12\" -->\n"+ - "</MOAConfiguration>\n"+ - "<!-- CanonicalizationMethod = http://www.w3.org/TR/2001/REC-xml-c14n-20010315 -->" + - "<!-- SignatureMethod = http://www.w3.org/2000/09/xmldsig#rsa-sha1 -->";*/ - - FileOutputStream fos = new FileOutputStream(file); - fos.write(config.getBytes()); - fos.flush(); - fos.close(); - - String file_3 = configuration_.getProperty("baseDir") + datadirectory_3 + - "TestGeneratorCX3" + - ".Config.xml"; - - fos = new FileOutputStream(file_3); - fos.write(config.getBytes()); - fos.flush(); - fos.close(); - - String file_4 = configuration_.getProperty("baseDir") + datadirectory_4 + - "TestGeneratorCX4" + - ".Config.xml"; - - fos = new FileOutputStream(file_4); - fos.write(config.getBytes()); - fos.flush(); - fos.close(); - - } - - public void createL00() throws Exception { - createL001("1kb"); - createL001("10kb"); - createL001("20kb"); - createL001("50kb"); - createL001("100kb"); - createL001("500kb"); - createL001("1mb"); - createL001("10mb"); - } - - public void createL001(String filename) throws Exception { - String TestNumber = "001"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory_l+filename+"/" + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/"+filename+".txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory_l+filename+"/" + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/"+filename+".txt"); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - } - - /* ==================================================================================================== */ - - public void create001() throws Exception { - - String TestNumber = "001"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - - // CX3 wird gleich mit generiert - - String reqFile_3 = configuration_.getProperty("baseDir") + datadirectory_3 + - "TestGeneratorCX3" + - "."; - String reqFile_4 = configuration_.getProperty("baseDir") + datadirectory_4 + - "TestGeneratorCX4" + - "."; - - writeFile(reqFile_3+"001" + ".Req.xml",req); - writeFile(reqFile_4+"051" + ".Req.xml",req); - - req = replaceString(req,"PKCS12RSAKey1","PKCS12RSAKeyNotAllowed"); - - writeFile(reqFile_3+"052" + ".Req.xml",req); - - String resFile_3 = configuration_.getProperty("baseDir") + datadirectory_3 + - "TestGeneratorCX3" + - "." ; - String resFile_4 = configuration_.getProperty("baseDir") + datadirectory_4 + - "TestGeneratorCX4" + - "." ; - - writeFile(resFile_3+ "001" + ".Res.xml",erg); - writeFile(resFile_4+ "051" + ".ErrRes.xml","0000"); - writeFile(resFile_3+ "052" + ".ErrRes.xml","2231"); - - } - - public void writeFile(String filename,String data) throws Exception - { - BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); - bw.write(data); - bw.close(); - } - - - public void create002() throws Exception { - - String TestNumber = "002"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - public void create003() throws Exception { - - String TestNumber = "003"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" ?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - public void create004() throws Exception { - - /*Properties config = new Properties(); - config.put("PKCS11_NATIVE_MODULE","cryptoki.dll"); - config.put("SLOT_ID","0"); - - Security.addProvider(new IAIK()); - IAIKPkcs11 pkcs11Provider_ = new IAIKPkcs11(config); - Security.addProvider(pkcs11Provider_); - - // load the keystore of the PKCS#11 provider given via input stream - KeyStore tokenKeyStore = pkcs11Provider_.getTokenManager().getKeyStore(); - - Object signatureKey = tokenKeyStore.getKey("HSMRSAKEY", null); - //System.out.println("got:"+signatureKey+" : "+signatureKey.getClass().getName()); - if(signatureKey instanceof IAIKPKCS11RsaPrivateKey) - { - System.out.println("GOT PRIVATE KEY:"+(IAIKPKCS11RsaPrivateKey)signatureKey); - java.security.cert.Certificate[] certificateChain = tokenKeyStore.getCertificateChain("HSMRSAKEY"); - X509Certificate signerCertificate = (X509Certificate) certificateChain[0]; - - } - if(signatureKey instanceof IAIKPKCS11RsaPublicKey) - { - System.out.println("GOT PUBLIC KEY:"+(IAIKPKCS11RsaPublicKey)signatureKey); - }*/ - - String TestNumber = "004"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" ?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>MOAHSMRSAKEY</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createHSMSig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt",false,false,null,false); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - public void create005() throws Exception { - - String TestNumber = "005"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" ?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12ECDSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createECDSPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt"); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - - public void create006() throws Exception { - - String TestNumber = "006"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - - writeFile(reqFile,""); - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - writeFile(resFile,"0000"); - } - - public void create007() throws Exception { - - String TestNumber = "007"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt\">\n"+ - " <XMLContent xml:space=\"preserve\">Dies sind Testdaten</XMLContent>\n"+ - " </DataObject>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt"); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - public void create008() throws Exception { - - String TestNumber = "008"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt\">\n"+ - " <Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg==</Base64Content>\n"+ - " </DataObject>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt"); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - - /* ==================================================================================================== */ - - public void create009() throws Exception { - - // based on create000() - - String TestNumber = "009"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"enveloping\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12SigWithEnveloping(TestNumber,"b64:Dies sind Testdaten"); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - public void create010() throws Exception { - - // based on create000() - - String TestNumber = "010"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"enveloping\" ChildOfManifest=\"false\">\n"+ - " <DataObject>\n"+ - " <XMLContent xml:space=\"preserve\"><Testdaten>Dies sind Testdaten</Testdaten></XMLContent>\n"+ - " </DataObject>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12SigWithEnveloping(TestNumber,"<Testdaten>Dies sind Testdaten</Testdaten>"); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - public void create011() throws Exception { - - // based on create000() - - String TestNumber = "011"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"enveloping\" ChildOfManifest=\"false\">\n"+ - " <DataObject>\n"+ - " <Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg==</Base64Content>\n"+ - " </DataObject>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12SigWithEnveloping(TestNumber,"b64:Dies sind Testdaten"); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - public void create012() throws Exception { - - // based on create000() - - String TestNumber = "012"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" >\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt\">\n"+ - " <XMLContent xml:space=\"preserve\">Dies sind Testdaten</XMLContent>\n"+ - " </DataObject>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt"); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - - public void create013() throws Exception { - - // based on create000() - - String TestNumber = "013"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"true\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\" />\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt",false,true); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - public void create014() throws Exception { - - // based on create000() - - String TestNumber = "014"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"true\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testUTF8.txt\" />\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12SigSL(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testUTF8.txt"); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - public void create015() throws Exception { - - // based on create000() - - String TestNumber = "015"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " <DataObjectInfo Structure=\"detached\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt",false,false,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt",false); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - public void create016() throws Exception { - - // based on create000() - - String TestNumber = "016"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"enveloping\">\n"+ - " <DataObject>\n"+ - " <XMLContent xml:space=\"preserve\">Dies sind Testdaten</XMLContent>\n"+ - " </DataObject>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " <DataObjectInfo Structure=\"enveloping\">\n"+ - " <DataObject>\n"+ - " <XMLContent xml:space=\"preserve\">Dies sind Testdaten</XMLContent>\n"+ - " </DataObject>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(TestNumber,"Dies sind Testdaten",true,false,"Dies sind Testdaten",true); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - public void create017() throws Exception { - - // based on create000() - - String TestNumber = "017"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " <DataObjectInfo Structure=\"enveloping\">\n"+ - " <DataObject>\n"+ - " <XMLContent xml:space=\"preserve\">Dies sind Testdaten</XMLContent>\n"+ - " </DataObject>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt",false,false,"Dies sind Testdaten",true); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - - } - - public void create018() throws Exception { - - // based on create000() - - String TestNumber = "018"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - Document signatureDoc2 = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt","id","id"); - - String erg = makeOutputFile(signatureDoc,signatureDoc2); - - writeFile(resFile,erg); - - } - - public void create019() throws Exception { - - String TestNumber = "019"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"enveloping\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testXML.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/xml</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Res.xml"; - - Document signatureDoc = createPKCS12SigWithEnveloping(TestNumber,"b64:"+readFile(configuration_.getProperty("baseDir")+"resources/testXML.txt")); - - String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,erg); - } - - public void create064() throws Exception { - - // based on create000() - - String TestNumber = "064"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"enveloping\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"testDatenFalsch.txt\">\n"+ - " <Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg==</Base64Content>\n"+ - " </DataObject>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - //Document signatureDoc = createPKCS12SigWithEnveloping(TestNumber,"Dies sind Testdaten"); - - //String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,"1110"); - - } - - - public void create051() throws Exception { - - String TestNumber = "051"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\"/>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " <SuperExtraElementThatShouldNotBeValidWithTheSchema/>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"1100"); - - } - - public void create052() throws Exception { - - String TestNumber = "052"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = this.replaceString(defaultblock,"version=\"1.0\"",""); - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"0000"); - - } - - public void create053() throws Exception { - - String TestNumber = "053"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = this.replaceString(defaultblock,"version=\"1.0\"","version=\"5.0alpha3\""); - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"0000"); - - } - - public void create054() throws Exception { - - String TestNumber = "054"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = this.replaceString(defaultblock,"ISO-8859-1","SuperSvenEncoding:)"); - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"0000"); - - } - - public void create055() throws Exception { - - String TestNumber = "055"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = this.replaceString(defaultblock,"xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"","xmlns=\"http://www.w3.org/2000/09/svens_schema#\""); - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"1100"); - - } - - public void create056() throws Exception { - - String TestNumber = "056"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = this.replaceString(defaultblock,"PKCS12RSAKey1","wrong_value_KeyIdentifier"); - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"2231"); - - } - - public void create057() throws Exception { - - String TestNumber = "057"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = this.replaceString(defaultblock,"PKCS12RSAKey1","PKCS12RSAKeyExpired"); - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"2220"); - - } - - public void create058() throws Exception { - - String TestNumber = "058"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = this.replaceString(defaultblock,"PKCS12RSAKey1","DSAinPKCS12"); - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"2220"); - - } - - public void create059() throws Exception { - - String TestNumber = "059"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = this.replaceString(defaultblock,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt",configuration_.getProperty("webbaseDir")+"not_here.txt"); - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"2208"); - - } - - /* - - public String defaultblock = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\">\n"+ - " <!-- Hint -->\n"+ - " </DataObject>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - */ - - public void create060() throws Exception { - - String TestNumber = "060"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = this.replaceString(defaultblock,"Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\"",""); - /*req = this.replaceString(req,"<CreateTransformsInfoProfile>",""); - req = this.replaceString(req,"<CreateTransformsInfo>",""); - req = this.replaceString(req,"<FinalDataMetaInfo>",""); - req = this.replaceString(req,"<MimeType>text/plain</MimeType>",""); - req = this.replaceString(req,"</FinalDataMetaInfo>",""); - req = this.replaceString(req,"</CreateTransformsInfo>",""); - req = this.replaceString(req,"</CreateTransformsInfoProfile>","");*/ - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"1102"); - - } - - public void create061() throws Exception { - - String TestNumber = "061"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = this.replaceString(defaultblock,"Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\"",""); - req = this.replaceString(req,"<!-- Hint -->","<XMLContent xml:space=\"preserve\"><DieserTagIstNichtZu></XMLContent>"); - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"0000"); - - } - - public void create062() throws Exception { - - String TestNumber = "062"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = this.replaceString(defaultblock,"Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDaten.txt\"",""); - req = this.replaceString(req,"<!-- Hint -->","<Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg=</Base64Content>"); - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"1100"); - - } - - public void create063() throws Exception { - - String TestNumber = "063"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = this.replaceString(defaultblock,"<MimeType>text/plain</MimeType>","<MimeType>something/some thing/something</MimeType>"); - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - writeFile(resFile,"1100"); - - } - - public void create065() throws Exception { - - String TestNumber = "065"; - String reqFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".Req.xml"; - String req = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - "<CreateXMLSignatureRequest\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >\n"+ - " <KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>\n"+ - " <SingleSignatureInfo SecurityLayerConformity=\"false\">\n"+ - " <DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">\n"+ - " <DataObject>\n"+ - " <XMLContent xml:space=\"preserve\">Dies sind Testdaten</XMLContent>\n"+ - " </DataObject>\n"+ - " <CreateTransformsInfoProfile>\n"+ - " <CreateTransformsInfo>\n"+ - " <FinalDataMetaInfo>\n"+ - " <MimeType>text/plain</MimeType>\n"+ - " </FinalDataMetaInfo>\n"+ - " </CreateTransformsInfo>\n"+ - " </CreateTransformsInfoProfile>\n"+ - " </DataObjectInfo>\n"+ - " </SingleSignatureInfo>\n"+ - "</CreateXMLSignatureRequest>"; - - writeFile(reqFile,req); - - /* ---------------------------------------------------------------------------------------------------- */ - - String resFile = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - "." + TestNumber + ".ErrRes.xml"; - - //Document signatureDoc = createPKCS12Sig(TestNumber,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - - //String erg = makeOutputFile(signatureDoc); - - writeFile(resFile,"1102"); - - } - - - - - public String makeOutputFile(Document signatureDoc) 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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+ - "<CreateXMLSignatureResponse\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " >"+ - //" xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\">\n"+ - "<SignatureEnvironment>" + - erg + "</SignatureEnvironment></CreateXMLSignatureResponse>"; - - return erg; - } - - public String makeOutputFile(Document signatureDoc,Document signatureDoc2) 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); - - foundNodes.clear(); - findNode(signatureDoc2.getDocumentElement(),"dsig:Signature",foundNodes); - - outputNode = null; - - if(foundNodes.size()>0) - { - outputNode = (Node)foundNodes.get(0); - } - - String erg2 = Node2String(outputNode); - - // remove the <?xml ?> Prologue - pos = erg2.indexOf("<dsig"); - erg2 = erg2.substring(pos); - - // insert the dsig:signature element in a MOA Response Message - erg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+ - "<CreateXMLSignatureResponse\n" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n"+ - " >"+ - "<SignatureEnvironment>" + - erg +"</SignatureEnvironment><SignatureEnvironment>"+erg2+"</SignatureEnvironment> </CreateXMLSignatureResponse>"; - - //erg = replaceString(erg,"Id=\"signature-1-1\"","Id=\"signature-2-1\""); - //erg = replaceString(erg,"Id=\"reference-1-1\"","Id=\"reference-2-1\""); - - - return erg; - } - - public String readFile(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"); - } - return data.toString();*/ - - RandomAccessFile raf = new RandomAccessFile(filename, "r"); - if (raf.length() > Integer.MAX_VALUE) - throw new IOException("file too big to fit in byte array."); - - byte[] result = new byte[(int) raf.length()]; - - raf.read(result); - - return new String(result); - - } - -} - diff --git a/spss.test/src/testgenerator/TestGeneratorCX1.java b/spss.test/src/testgenerator/TestGeneratorCX1.java deleted file mode 100644 index 44670742b..000000000 --- a/spss.test/src/testgenerator/TestGeneratorCX1.java +++ /dev/null @@ -1,1054 +0,0 @@ -package testgenerator; - -import iaik.ixsil.algorithms.Transform; -import iaik.ixsil.algorithms.TransformImplBase64Decode; -import iaik.ixsil.algorithms.TransformImplCanonicalXML; -import iaik.ixsil.algorithms.TransformImplCanonicalXMLWithComments; -import iaik.ixsil.algorithms.TransformImplEnvelopedSignature; -import iaik.ixsil.algorithms.TransformImplExclusiveCanonicalXML; -import iaik.ixsil.algorithms.TransformImplExclusiveCanonicalXMLWithComments; -import iaik.ixsil.algorithms.TransformImplXPath; -import iaik.ixsil.algorithms.TransformImplXPath2; -import iaik.ixsil.algorithms.TransformImplXSLT; -import iaik.ixsil.core.Position; -import iaik.ixsil.util.URI; -import java.io.BufferedWriter; -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.HashMap; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -import at.gv.egovernment.moa.util.Base64Utils; -import at.gv.egovernment.moa.util.DOMUtils; - -/** - * @author Administrator - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class TestGeneratorCX1 extends TestCases { - - String datadirectory = "data/CX1/"; - - String base64content = "RGllcyBzaW5kIFRlc3RkYXRlbg=="; - - String defaultblock = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ - "<CreateXMLSignatureRequest xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" >"+ - "<KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>"+ - "<SingleSignatureInfo SecurityLayerConformity=\"false\">"+ - "<DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">"+ - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/BookData.xml"+"\">"+ - "<XMLContent xml:space=\"preserve\">"+ - "<data:book xmlns:data=\"http://uri.data.org\" data:hardback=\"yes\">"+ - "<data:title>Gesundheitliche Auswirkungen elektronischer Signaturen</data:title>"+ - "<data:first-name>Ellipse</data:first-name>"+ - "<data:last-name>Kurvenreich</data:last-name>"+ - "<data:birth-date>1951-04-16</data:birth-date>"+ - "<data:birth-location>Hinterm Berg</data:birth-location>"+ - "<data:register-number>6-930-21512-12</data:register-number>"+ - "</data:book>"+ - "</XMLContent>"+ - "</DataObject>"+ - "<CreateTransformsInfoProfile>"+ - "<CreateTransformsInfo>"+ - "<dsig:Transforms>"+ - "<!-- insert transform -->"+ - "</dsig:Transforms>"+ - "<FinalDataMetaInfo>"+ - "<MimeType>text/html</MimeType>"+ - "<Description>http://www.description.com</Description>"+ - "</FinalDataMetaInfo>"+ - "</CreateTransformsInfo>"+ - "<!-- insert supp -->"+ - "</CreateTransformsInfoProfile>"+ - "</DataObjectInfo>"+ - "<!-- insert data2 -->"+ - "</SingleSignatureInfo>"+ - "</CreateXMLSignatureRequest>"; - - private static final int canAlgCanXML = 1; - private static final int canAlgCanXMLwithCom = 2; - private static final int canAlgExcXML = 3; - private static final int canAlgExcXMLwithCom = 4; - - - public String fileprefix = null; - public String filesuffix = null; - - public TestGeneratorCX1() throws Exception { - - super(); - - // Set config properties - configuration_.setProperty("TestClass", "TestGeneratorCX1"); -// 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(); - } - - public static void main(String[] args) throws Exception { - TestGeneratorCX1 testcase = new TestGeneratorCX1(); - - testcase.createConfig(); - testcase.create001(); - testcase.create002(); - testcase.create003(); - testcase.create004(); - testcase.create005(); - testcase.create006(); - testcase.create007(); - testcase.create008(); - testcase.create009(); - testcase.create010(); - testcase.create011(); - testcase.create012(); - testcase.create013(); - testcase.create014(); - - testcase.create051(); - testcase.create052(); - testcase.create053(); - testcase.create054(); - testcase.create055(); - - } - - public void createConfig() throws Exception { - - String file = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - ".Config.xml"; - String config = - - "<MOAConfiguration xmlns=\"http://reference.e-government.gv.at/namespace/moaconfig/20021122#\">"+ - " <KeyGroup id=\"PKCS12RSAKey1\"> <Key id=\"resources/test-ee2003_normal(buergerkarte).p12\"/> </KeyGroup>"+ - " <KeyGroup id=\"PKCS12RSAKeyExpired\"> <Key id=\"sicher-demo(buergerkarte).p12\"/> </KeyGroup>"+ - - " <KeyGroup id=\"PKCS12ECDSAKey1\"> <Key id=\"ecc.p12\"/> </KeyGroup> "+ - " <KeyGroup id=\"HSMRSAKey1\"> <Key id=\"???\"/> </KeyGroup>"+ - " <KeyGroup id=\"HSMECDSAKey1\"> <Key id=\"???\"/> </KeyGroup>"+ - " <DigestMethodAlgorithm name=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>"+ - " <SignatureAlgorithm name=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>"+ - " <CanonicalizationAlgorithm name=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/>"+ - " <CreateTransformsInfoProfile id=\"CreateTransformsInfoProfile1\" filename=\""+"file:/"+configuration_.getProperty("webbaseDir")+"CX1_bookprofile.xsl\"/>"+ - "</MOAConfiguration>"; - - - /*"<MOAConfiguration>"+ - " <KeyGroup id=\"PKCS12RSAKey1\"/> <!-- mapped auf \"test(1234).p12\" -->"+ - "</MOAConfiguration>"+ - "<!-- CanonicalizationMethod = http://www.w3.org/TR/2001/REC-xml-c14n-20010315 -->" + - "<!-- SignatureMethod = http://www.w3.org/2000/09/xmldsig#rsa-sha1 -->";*/ - - FileOutputStream fos = new FileOutputStream(file); - fos.write(config.getBytes()); - fos.flush(); - fos.close(); - - fileprefix = configuration_.getProperty("baseDir")+ datadirectory + configuration_.getProperty("TestClass") + "."; - filesuffix = ".xml"; - } - - public void create001() throws Exception { - - String TestNumber = "001"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xslt-19991116\">"+ - "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"><xsl:output method=\"html\" indent=\"no\"/><xsl:template match=\"data:book\" xmlns:data=\"http://uri.data.org\"><HTML><BODY><H1>Buch: <xsl:value-of select=\"data:title\"/></H1></BODY></HTML></xsl:template></xsl:stylesheet>"+ - "</dsig:Transform>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplXSLT trans = new TransformImplXSLT(); - InputStream s = new FileInputStream(configuration_.getProperty("baseDir")+"resources/CX1_book.xsl"); - trans.setInput(s,null); - trans.setStyleSheet(s,null); - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-1"); - - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - writeFile(resFile, output); - - } - - public void create002() throws Exception { - - String TestNumber = "002"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xslt-19991116\">"+ - "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">"+ - "<xsl:output method=\"html\" indent=\"no\"/>"+ - "<xsl:template match=\"data:book\" xmlns:data=\"http://uri.data.org\">"+ - "<HTML>"+ - "<BODY>"+ - "<H1>Buch: <xsl:value-of select=\"data:title\"/>"+ - "</H1>"+ - "</BODY>"+ - "</HTML>"+ - "</xsl:template>"+ - "</xsl:stylesheet>"+ - "</dsig:Transform>"); - - req = replaceString(req,"SecurityLayerConformity=\"false\"","SecurityLayerConformity=\"true\""); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplXSLT trans = new TransformImplXSLT(); - InputStream s = new FileInputStream(configuration_.getProperty("baseDir")+"resources/CX1_book.xsl"); - trans.setInput(s,null); - trans.setStyleSheet(s,null); - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-1"); - //cpkcs.createReferenceWithManifest(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),"manifestObject"); - cpkcs.createETSIObjects("file:/"+configuration_.getProperty("webbaseDir")+"resources/BookData.xml"); - cpkcs.setKeyInformation(1); - - cpkcs.signer.getSignature().setId("signature-1-1"); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - writeFile(resFile, output); - - } - - public void create003() throws Exception { - - String TestNumber = "003"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xpath-19991116\">"+ - "<dsig:XPath xmlns:data=\"http://uri.data.org\">//data:book/data:first-name</dsig:XPath>"+ - "</dsig:Transform>"); - - req = replaceString(req,"<MimeType>text/html</MimeType>","<MimeType>text/plain</MimeType>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplXPath trans = new TransformImplXPath(); - InputStream s = new FileInputStream(configuration_.getProperty("baseDir")+"resources/BookData.xml"); - trans.setInput(s,null); - trans.addNSDeclaration("data",new URI("http://uri.data.org")); - trans.setXPath("//data:book/data:first-name"); - //trans.setXPath("ancestor-or-self::data:first-name"); - - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - output = replaceString(output,"<dsig:XPath xmlns:data=\"http://uri.data.org\">","<dsig:XPath>"); // workaround - - writeFile(resFile, output); - - } - - public void create004() throws Exception { - - String TestNumber = "004"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/2002/06/xmldsig-filter2\">"+ - "<xf2:XPath Filter=\"subtract\" xmlns:xf2=\"http://www.w3.org/2002/06/xmldsig-filter2\" xmlns:data=\"http://uri.data.org\">//data:book/data:first-name</xf2:XPath>"+ - "</dsig:Transform>"); - - req = replaceString(req,"<MimeType>text/html</MimeType>","<MimeType>text/xml</MimeType>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplXPath2 trans = new TransformImplXPath2(); - InputStream s = new FileInputStream(configuration_.getProperty("baseDir")+"resources/BookData.xml"); - trans.setInput(s,null); - //trans.addNSDeclaration("data",new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml")); - //trans.setXPath("/data:book/data:first-name/node()"); - HashMap temp = new HashMap(); - temp.put("data",new URI("http://uri.data.org")); - trans.addXPathFilter("//data:book/data:first-name",TransformImplXPath2.FILTER_MODE_SUBTRACT_,temp); - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - output = replaceString(output,"<xf2:XPath Filter=\"subtract\" xmlns:data=\"http://uri.data.org\"","<xf2:XPath Filter=\"subtract\" "); - - writeFile(resFile, output); - - } - - public void create005() throws Exception { - - String TestNumber = "005"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/>"); - - req = replaceString(req,"<MimeType>text/html</MimeType>","<MimeType>text/xml</MimeType>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplCanonicalXML trans = new TransformImplCanonicalXML(); - InputStream s = new FileInputStream(configuration_.getProperty("baseDir")+"resources/CX1_book.xsl"); - trans.setInput(s,null); - /*trans.addNSDeclaration("data",new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml")); - trans.setXPath("/data:book/data:first-name/node()"); - trans.*/ - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - writeFile(resFile, output); - - } - - public void create006() throws Exception { - - String TestNumber = "006"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments\"/>"); - - req = replaceString(req,"<MimeType>text/html</MimeType>","<MimeType>text/xml</MimeType>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplCanonicalXMLWithComments trans = new TransformImplCanonicalXMLWithComments(); - InputStream s = new FileInputStream(configuration_.getProperty("baseDir")+"resources/CX1_book.xsl"); - trans.setInput(s,null); - /*trans.addNSDeclaration("data",new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml")); - trans.setXPath("/data:book/data:first-name/node()"); - trans.*/ - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - writeFile(resFile, output); - - } - - public void create007() throws Exception { - - String TestNumber = "007"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"><ec:InclusiveNamespaces PrefixList=\"dsig\" xmlns:ec=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/></dsig:Transform>"); - - req = replaceString(req,"<MimeType>text/html</MimeType>","<MimeType>text/xml</MimeType>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplExclusiveCanonicalXML trans = new TransformImplExclusiveCanonicalXML(); - InputStream s = new FileInputStream(configuration_.getProperty("baseDir")+"resources/CX1_book.xsl"); - trans.setInput(s,null); - trans.setInclusiveNamespacePrefixes("dsig"); - /*trans.addNSDeclaration("data",new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml")); - trans.setXPath("/data:book/data:first-name/node()"); - trans.*/ - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - writeFile(resFile, output); - - } - - public void create008() throws Exception { - - String TestNumber = "008"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#WithComments\"><ec:InclusiveNamespaces PrefixList=\"dsig\" xmlns:ec=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/></dsig:Transform>"); - - req = replaceString(req,"<MimeType>text/html</MimeType>","<MimeType>text/xml</MimeType>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplExclusiveCanonicalXMLWithComments trans = new TransformImplExclusiveCanonicalXMLWithComments(); - InputStream s = new FileInputStream(configuration_.getProperty("baseDir")+"resources/CX1_book.xsl"); - trans.setInput(s,null); - trans.setInclusiveNamespacePrefixes("dsig"); - /*trans.addNSDeclaration("data",new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml")); - trans.setXPath("/data:book/data:first-name/node()"); - trans.*/ - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - writeFile(resFile, output); - - } - - public void create009() throws Exception { - - String TestNumber = "009"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/>"); - - req = replaceString(req,"<XMLContent xml:space=\"preserve\">"+ - "<data:book xmlns:data=\"http://uri.data.org\" data:hardback=\"yes\">"+ - "<data:title>Gesundheitliche Auswirkungen elektronischer Signaturen</data:title>"+ - "<data:first-name>Ellipse</data:first-name>"+ - "<data:last-name>Kurvenreich</data:last-name>"+ - "<data:birth-date>1951-04-16</data:birth-date>"+ - "<data:birth-location>Hinterm Berg</data:birth-location>"+ - "<data:register-number>6-930-21512-12</data:register-number>"+ - "</data:book>"+ - "</XMLContent>",""); - - req = replaceString(req, - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/BookData.xml"+"\">", - "<DataObject Reference=\"\">"); - - //req = replaceString(req,"Structure=\"detached\"","Structure=\"enveloping\""); - - - req = replaceString(req,"<!-- insert data2 -->", - "<CreateSignatureInfo><CreateSignatureEnvironment><XMLContent xml:space=\"preserve\"><env:Document xmlns:env=\"http://uri.env.org\">Text</env:Document></XMLContent></CreateSignatureEnvironment><CreateSignatureEnvironmentProfile><CreateSignatureLocation xmlns:env=\"http://uri.env.org\" Index=\"1\">//env:Document</CreateSignatureLocation></CreateSignatureEnvironmentProfile></CreateSignatureInfo>"); - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - InputStream bis = new ByteArrayInputStream(("<env:Document xmlns:env=\"http://uri.env.org\">Text</env:Document>").getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - //Dokument Parsen - Document reqDoc = builder.parse(bis); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - //Position für die Signatur angeben - String xPath_Pos = "/node()"; - //XPAth-Prefixe deklarieren - String xPath_Prefix = "env xmlns:env=\"http://uri.env.org\""; - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(reqDoc,pos,"signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplEnvelopedSignature trans = new TransformImplEnvelopedSignature(); - - /*trans.addNSDeclaration("data",new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml")); - trans.setXPath("/data:book/data:first-name/node()"); - trans.*/ - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(""),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - output = replaceString(output,"<dsig:Signature","<env:Document xmlns:env=\"http://uri.env.org\">Text<dsig:Signature"); - output = replaceString(output,"</dsig:Signature>","</dsig:Signature></env:Document>"); - - - - writeFile(resFile, output); - - } - - public void create010() throws Exception { - - String TestNumber = "010"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/>"+ - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xslt-19991116\">"+ - "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">"+ - "<xsl:output method=\"html\" indent=\"no\"/>"+ - "<xsl:template match=\"data:book\" xmlns:data=\"http://uri.data.org\">"+ - "<HTML>"+ - "<BODY>"+ - "<H1>Buch: <xsl:value-of select=\"data:title\"/>"+ - "</H1>"+ - "</BODY>"+ - "</HTML>"+ - "</xsl:template>"+ - "</xsl:stylesheet>"+ - "</dsig:Transform>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[2]; - TransformImplCanonicalXML trans = new TransformImplCanonicalXML(); - InputStream s = new FileInputStream(configuration_.getProperty("baseDir")+"resources/CX1_book.xsl"); - trans.setInput(s,null); - /*trans.addNSDeclaration("data",new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml")); - trans.setXPath("/data:book/data:first-name/node()"); - trans.*/ - tr[0] = trans; - - TransformImplXSLT tr2 = new TransformImplXSLT(); - InputStream s2 = new FileInputStream(configuration_.getProperty("baseDir")+"resources/CX1_book.xsl"); - tr2.setInput(s2,null); - tr2.setStyleSheet(s2,null); - tr[1] = tr2; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - writeFile(resFile, output); - - } - - public void create011() throws Exception { - - String TestNumber = "011"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xslt-19991116\">"+ - "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">"+ - "<xsl:include href=\""+configuration_.getProperty("webbaseDir")+"resources/CX1_book_not_here.xsl"+"\"/>"+ - "</xsl:stylesheet>"+ - "</dsig:Transform>"); - - req = replaceString(req,"<!-- insert supp -->", - "<Supplement>"+ - "<Content Reference=\""+configuration_.getProperty("webbaseDir")+"resources/CX1_book_not_here.xsl"+"\">"+ - "<Base64Content>"+ - Base64Utils.encode(("<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">"+ - "<xsl:output method=\"html\" indent=\"no\"/>"+ - "<xsl:template match=\"data:book\" xmlns:data=\"http://uri.data.org\">"+ - "<HTML>"+ - "<BODY>"+ - "<H1>Buch: <xsl:value-of select=\"data:title\"/>"+ - "</H1>"+ - "</BODY>"+ - "</HTML>"+ - "</xsl:template>"+ - "</xsl:stylesheet>").getBytes())+ - "</Base64Content>"+ - "</Content>"+ - "</Supplement>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplXSLT trans = new TransformImplXSLT(); - URL u = new URL(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref_not_here.xsl"); - URLConnection hu = u.openConnection(); - //trans.setInput(s,null); - trans.setStyleSheet(hu.getInputStream(),new URI(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref_not_here.xsl")); - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-1"); - //cpkcs.createReferenceWithManifest(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),"manifestObject"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - writeFile(resFile, output); - } - - public void create012() throws Exception { - - String TestNumber = "012"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xslt-19991116\">"+ - "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">"+ - "<xsl:include href=\""+configuration_.getProperty("webbaseDir")+"resources/CX1_book_not_here.xsl"+"\"/>"+ - "</xsl:stylesheet>"+ - "</dsig:Transform>"); - - req = replaceString(req,"<!-- insert data2 -->", - "<DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">"+ - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/BookData.xml"+"\">"+ - "<XMLContent xml:space=\"preserve\">"+ - "<data:book xmlns:data=\"http://uri.data.org\" data:hardback=\"yes\">"+ - "<data:title>Gesundheitliche Auswirkungen elektronischer Signaturen</data:title>"+ - "<data:first-name>Ellipse</data:first-name>"+ - "<data:last-name>Kurvenreich</data:last-name>"+ - "<data:birth-date>1951-04-16</data:birth-date>"+ - "<data:birth-location>Hinterm Berg</data:birth-location>"+ - "<data:register-number>6-930-21512-12</data:register-number>"+ - "</data:book>"+ - "</XMLContent>"+ - "</DataObject>"+ - "<CreateTransformsInfoProfile>"+ - "<CreateTransformsInfo>"+ - "<dsig:Transforms>"+ - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xslt-19991116\">"+ - "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">"+ - "<xsl:include href=\""+configuration_.getProperty("webbaseDir")+"resources/CX1_book_not_here.xsl\"/>"+ - "</xsl:stylesheet>"+ - "</dsig:Transform>"+ - "</dsig:Transforms>"+ - "<FinalDataMetaInfo>"+ - "<MimeType>text/html</MimeType>"+ - "</FinalDataMetaInfo>"+ - "</CreateTransformsInfo>"+ - "<Supplement>"+ - "<Content Reference=\""+configuration_.getProperty("webbaseDir")+"resources/CX1_book_not_here.xsl"+"\">"+ - "<Base64Content>"+ - Base64Utils.encode(("<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">"+ - "<xsl:output method=\"html\" indent=\"no\"/>"+ - "<xsl:template match=\"data:book\" xmlns:data=\"http://uri.data.org\">"+ - "<HTML>"+ - "<BODY>"+ - "<H1>Buch: <xsl:value-of select=\"data:title\"/>"+ - "</H1>"+ - "</BODY>"+ - "</HTML>"+ - "</xsl:template>"+ - "</xsl:stylesheet>").getBytes())+ - "</Base64Content>"+ - "</Content>"+ - "</Supplement>"+ - "</CreateTransformsInfoProfile>"+ - "</DataObjectInfo>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplXSLT trans = new TransformImplXSLT(); - URL u = new URL(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref_not_here.xsl"); - URLConnection hu = u.openConnection(); - //trans.setInput(s,null); - trans.setStyleSheet(hu.getInputStream(),new URI(configuration_.getProperty("webbaseDir")+"resources/CX1_bookref_not_here.xsl")); - - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-1"); - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-2"); - //cpkcs.createReferenceWithManifest(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),"manifestObject"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - writeFile(resFile, output); - - } - - public void create013() throws Exception { - - String TestNumber = "013"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock, - "<CreateTransformsInfoProfile>"+ - "<CreateTransformsInfo>"+ - "<dsig:Transforms>"+ - "<!-- insert transform -->"+ - "</dsig:Transforms>"+ - "<FinalDataMetaInfo>"+ - "<MimeType>text/html</MimeType>"+ - "<Description>http://www.description.com</Description>"+ - "</FinalDataMetaInfo>"+ - "</CreateTransformsInfo>"+ - "<!-- insert supp -->"+ - "</CreateTransformsInfoProfile>", - "<CreateTransformsInfoProfileID>CreateTransformsInfoProfile1</CreateTransformsInfoProfileID>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplXSLT trans = new TransformImplXSLT(); - InputStream s = new FileInputStream(configuration_.getProperty("baseDir")+"resources/CX1_book.xsl"); - trans.setInput(s,null); - trans.setStyleSheet(s,null); - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),tr,"reference-1-1"); - //cpkcs.createReferenceWithManifest(new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"),"manifestObject"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - writeFile(resFile, output); - - } - - public void create014() throws Exception { - - String TestNumber = "014"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#base64\"/>"); - - req = replaceString(req, - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/BookData.xml"+"\">", - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testBase64.txt"+"\">"); - - req = replaceString(req, - "<XMLContent xml:space=\"preserve\">"+ - "<data:book xmlns:data=\"http://uri.data.org\" data:hardback=\"yes\">"+ - "<data:title>Gesundheitliche Auswirkungen elektronischer Signaturen</data:title>"+ - "<data:first-name>Ellipse</data:first-name>"+ - "<data:last-name>Kurvenreich</data:last-name>"+ - "<data:birth-date>1951-04-16</data:birth-date>"+ - "<data:birth-location>Hinterm Berg</data:birth-location>"+ - "<data:register-number>6-930-21512-12</data:register-number>"+ - "</data:book>"+ - "</XMLContent>", - /*"<Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg==</Base64Content>"*/""); - - req = replaceString(req,"<MimeType>text/html</MimeType>","<MimeType>text/plain</MimeType>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplBase64Decode trans = new TransformImplBase64Decode(); - InputStream s = new FileInputStream(configuration_.getProperty("baseDir")+"resources/testBase64.txt"); - trans.setInput(s,null); - /*trans.addNSDeclaration("data",new URI(configuration_.getProperty("webbaseDir")+"resources/BookData.xml")); - trans.setXPath("/data:book/data:first-name/node()"); - trans.*/ - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir")+"resources/testBase64.txt"),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc); - - writeFile(resFile, output); - - } - - public void create051() throws Exception { - - String TestNumber = "051"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xpath-19991116\">"+ - "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">"+ - "<xsl:output method=\"html\" indent=\"no\"/>"+ - "<xsl:template match=\"data:book\" xmlns:data=\"http://uri.data.org\">"+ - "<HTML>"+ - "<BODY>"+ - "<H1>Buch: <xsl:value-of select=\"data:title\"/>"+ - "</H1>"+ - "</BODY>"+ - "</HTML>"+ - "</xsl:template>"+ - "</xsl:stylesheet>"+ - "</dsig:Transform>"); - - req = replaceString(req,"SecurityLayerConformity=\"false\"","SecurityLayerConformity=\"true\""); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2202"); - } - - public void create052() throws Exception { - - String TestNumber = "052"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xslt-19991116\">"+ - "<XPath>/data:book/data:first-name/node()</XPath>"+ - "</dsig:Transform>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2215"); - - - } - - public void create053() throws Exception { - - String TestNumber = "053"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - " <dsig:Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xslt-19991116\">"+ - " <xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">"+ - " <xsl:include href=\"file:/transform.xsl\"/>"+ - " </xsl:stylesheet>"+ - " </dsig:Transform>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2220"); - - } - - public void create054() throws Exception { - - String TestNumber = "054"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock, - "<CreateTransformsInfoProfile>"+ - "<CreateTransformsInfo>"+ - "<dsig:Transforms>"+ - "<!-- insert transform -->"+ - "</dsig:Transforms>"+ - "<FinalDataMetaInfo>"+ - "<MimeType>text/html</MimeType>"+ - "<Description>http://www.description.com</Description>"+ - "</FinalDataMetaInfo>"+ - "</CreateTransformsInfo>"+ - "<!-- insert supp -->"+ - "</CreateTransformsInfoProfile>", - "<CreateTransformsInfoProfileID>CreateTransformsInfoProfileNonValid</CreateTransformsInfoProfileID>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2234"); - - } - - public void create055() throws Exception { - - String TestNumber = "055"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert transform -->", - "<dsig:Transform Algorithm=\"http://www.w3.org/2002/06/xmldsig-filter2\">"+ - "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">"+ - "<xsl:output method=\"html\" indent=\"no\"/>"+ - "<xsl:template match=\"data:book\" xmlns:data=\"http://uri.data.org\">"+ - "<HTML>"+ - "<BODY>"+ - "<H1>Buch: <xsl:value-of select=\"data:title\"/>"+ - "</H1>"+ - "</BODY>"+ - "</HTML>"+ - "</xsl:template>"+ - "</xsl:stylesheet>"+ - "</dsig:Transform>"); - - req = replaceString(req,"SecurityLayerConformity=\"false\"","SecurityLayerConformity=\"true\""); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2216"); - } - - public void writeFile(String filename,String data) throws Exception - { - BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); - bw.write(data); - bw.close(); - } - - public String makeOutputFile(Document signatureDoc) 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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+ - "<CreateXMLSignatureResponse" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\""+ - ">"+ - //" xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\">"+ - "<SignatureEnvironment>" + - erg + "</SignatureEnvironment> </CreateXMLSignatureResponse>"; - - return erg; - } -} diff --git a/spss.test/src/testgenerator/TestGeneratorCX2.java b/spss.test/src/testgenerator/TestGeneratorCX2.java deleted file mode 100644 index ed5c5194a..000000000 --- a/spss.test/src/testgenerator/TestGeneratorCX2.java +++ /dev/null @@ -1,1050 +0,0 @@ -package testgenerator; - -import iaik.ixsil.algorithms.Transform; -import iaik.ixsil.algorithms.TransformImplEnvelopedSignature; -import iaik.ixsil.core.Position; -import iaik.ixsil.util.URI; - -import java.io.BufferedWriter; -import java.io.ByteArrayInputStream; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -import at.gv.egovernment.moa.util.Base64Utils; -import at.gv.egovernment.moa.util.Constants; -import at.gv.egovernment.moa.util.DOMUtils; -import at.gv.egovernment.moa.util.EntityResolverChain; -import at.gv.egovernment.moa.util.MOAEntityResolver; -import at.gv.egovernment.moa.util.MOAErrorHandler; -import at.gv.egovernment.moa.util.StreamEntityResolver; - -/** - * @author Administrator - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class TestGeneratorCX2 extends TestCases { - - String datadirectory = "data/CX2/"; - - String defaultblock = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ - "<CreateXMLSignatureRequest xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">"+ - "<KeyIdentifier>PKCS12RSAKey1</KeyIdentifier>"+ - "<SingleSignatureInfo SecurityLayerConformity=\"false\">"+ - "<DataObjectInfo Structure=\"detached\" ChildOfManifest=\"false\">"+ - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt"+"\">"+ - "<XMLContent xml:space=\"preserve\">Dies sind Testdaten</XMLContent>"+ - "</DataObject>"+ - "<CreateTransformsInfoProfile>"+ - "<CreateTransformsInfo>"+ - "<FinalDataMetaInfo>"+ - "<MimeType>text/plain</MimeType>"+ - "</FinalDataMetaInfo>"+ - "</CreateTransformsInfo>"+ - "</CreateTransformsInfoProfile>"+ - "</DataObjectInfo>"+ - "<CreateSignatureInfo xmlns:data=\"http://uri.data.org\">"+ - "<!-- insert create -->"+ - "<CreateSignatureEnvironmentProfile>"+ - "<CreateSignatureLocation Index=\"0\">//data:Document</CreateSignatureLocation>"+ - "<!-- insert supp -->"+ - "</CreateSignatureEnvironmentProfile>"+ - "</CreateSignatureInfo>"+ - "</SingleSignatureInfo>"+ - "</CreateXMLSignatureRequest>"; - - public String fileprefix = null; - public String filesuffix = null; - - private static final int canAlgCanXML = 1; - private static final int canAlgCanXMLwithCom = 2; - private static final int canAlgExcXML = 3; - private static final int canAlgExcXMLwithCom = 4; - - public TestGeneratorCX2() throws Exception { - - super(); - - // Set config properties - configuration_.setProperty("TestClass", "TestGeneratorCX2"); -// 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(); - } - - public static void main(String[] args) throws Exception { - TestGeneratorCX2 testcase = new TestGeneratorCX2(); - - testcase.createConfig(); - testcase.create001(); - testcase.create002(); - testcase.create003(); - testcase.create004(); - testcase.create005(); - testcase.create006(); - testcase.create007(); - testcase.create008(); - testcase.create009(); - - testcase.create051(); - testcase.create052(); - testcase.create053(); - testcase.create054(); - testcase.create055(); - testcase.create056(); - testcase.create057(); - - } - - public void createConfig() throws Exception { - - String file = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - ".Config.xml"; - String config = - - "<MOAConfiguration xmlns=\"http://reference.e-government.gv.at/namespace/moaconfig/20021122#\">"+ - " <KeyGroup id=\"PKCS12RSAKey1\"> <Key id=\"resources/test-ee2003_normal(buergerkarte).p12\"/> </KeyGroup>"+ - " <KeyGroup id=\"PKCS12RSAKeyExpired\"> <Key id=\"sicher-demo(buergerkarte).p12\"/> </KeyGroup>"+ - " <KeyGroup id=\"PKCS12ECDSAKey1\"> <Key id=\"ecc.p12\"/> </KeyGroup> "+ - " <KeyGroup id=\"HSMRSAKey1\"> <Key id=\"???\"/> </KeyGroup>"+ - " <KeyGroup id=\"HSMECDSAKey1\"> <Key id=\"???\"/> </KeyGroup>"+ - " <DigestMethodAlgorithm name=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>"+ - " <SignatureAlgorithm name=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>"+ - " <CanonicalizationAlgorithm name=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/>"+ - " <CreateSignatureEnvironmentProfile id=\"CreateSignatureEnvironmentProfile1\" filename=\""+"file:/"+configuration_.getProperty("webbaseDir")+"resources/CSEP.xml\"/>"+ - "</MOAConfiguration>"; - - FileOutputStream fos = new FileOutputStream(file); - fos.write(config.getBytes()); - fos.flush(); - fos.close(); - - fileprefix = configuration_.getProperty("baseDir")+ datadirectory + configuration_.getProperty("TestClass") + "."; - filesuffix = ".xml"; - } - - public void create001() throws Exception { - - String TestNumber = "001"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<XMLContent xml:space=\"preserve\">"+ - "<data:Document xmlns:data=\"http://uri.data.org\">"+readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>"+ - //readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+ - "</XMLContent>"+ - "</CreateSignatureEnvironment>"); - - writeFile(reqFile,req); - - InputStream bis = new ByteArrayInputStream(("<data:Document xmlns:data=\"http://uri.data.org\">"+readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>").getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - //Dokument Parsen - Document reqDoc = builder.parse(bis); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - //Position für die Signatur angeben - String xPath_Pos = "/node()"; - //XPAth-Prefixe deklarieren - String xPath_Prefix = "data xmlns:data=\"http://uri.data.org\""; - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc,pos,"signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt","reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc,"<data:Document xmlns:data=\"http://uri.data.org\">",readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>"); - - writeFile(resFile, output); - - } - - public void create002() throws Exception { - - String TestNumber = "002"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testDocument.xml"+"\"/>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - InputStream bis = new ByteArrayInputStream(("<data:Document xmlns:data=\"http://uri.data.org\">"+readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>").getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - //Dokument Parsen - Document reqDoc = builder.parse(bis); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - //Position für die Signatur angeben - String xPath_Pos = "/node()"; - //XPAth-Prefixe deklarieren - String xPath_Prefix = "data xmlns:data=\"http://uri.data.org\""; - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc,pos,"signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt","reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc,"<data:Document xmlns:data=\"http://uri.data.org\">",readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>"); - - writeFile(resFile, output); - - } - - public void create003() throws Exception { - - String TestNumber = "003"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<Base64Content>"+readBinaryFileAsBase64(configuration_.getProperty("baseDir")+"resources/testDocument.xml")+"</Base64Content>"+ - "</CreateSignatureEnvironment>"); - - //req = replaceString(req,"Index=\"0\">//data:Document","Index=\"0\">//Hugo"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - InputStream bis = new ByteArrayInputStream(("<data:Document xmlns:data=\"http://uri.data.org\">"+readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>").getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - //Dokument Parsen - Document reqDoc = builder.parse(bis); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - //Position für die Signatur angeben - String xPath_Pos = "/node()"; - //XPAth-Prefixe deklarieren - String xPath_Prefix = "data xmlns:data=\"http://uri.data.org\""; - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc,pos,"signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt","reference-1-1"); - cpkcs.setKeyInformation(1); - - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc,"<data:Document xmlns:data=\"http://uri.data.org\">",cutXML(readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt"))+"</data:Document>"); - - writeFile(resFile, output); - - } - - public void create004() throws Exception { - - String TestNumber = "004"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<XMLContent xml:space=\"preserve\">"+ - "<data:Document xmlns:data=\"http://uri.data.org\">"+readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>"+ - "</XMLContent>"+ - "</CreateSignatureEnvironment>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - InputStream bis = new ByteArrayInputStream(("<data:Document xmlns:data=\"http://uri.data.org\">"+readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>").getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - //Dokument Parsen - Document reqDoc = builder.parse(bis); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - //Position für die Signatur angeben - String xPath_Pos = "/node()"; - //XPAth-Prefixe deklarieren - String xPath_Prefix = "data xmlns:data=\"http://uri.data.org\""; - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc,pos,"signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt","reference-1-1"); - cpkcs.setKeyInformation(1); - - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc,"<data:Document xmlns:data=\"http://uri.data.org\">",readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>"); - - writeFile(resFile, output); - } - - public void create005() throws Exception { - - String TestNumber = "005"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<XMLContent xml:space=\"preserve\">"+ - "<data:Document xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" attr=\"document\" xsi:schemaLocation=\"http://uri.data.org http://tollesSchema.org/test.xsd\">Dies sind Testdaten</data:Document>"+ - "</XMLContent>"+ - "</CreateSignatureEnvironment>"); - - req = replaceString(req,"<!-- insert supp -->", - "<Supplement>"+ - "<Content Reference=\"http://tollesSchema.org/test.xsd\">"+ - "<XMLContent xml:space=\"preserve\">"+ - "<xsd:schema targetNamespace=\"http://uri.data.org\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://uri.data.org\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\" id=\"tollesSchema\">"+ - "<xsd:element name=\"Document\">"+ - "<xsd:complexType mixed=\"true\">"+ - "<xsd:sequence maxOccurs=\"unbounded\" minOccurs=\"0\">"+ - "<xsd:any namespace=\"##any\" processContents=\"lax\"/>"+ - "</xsd:sequence>"+ - "<xsd:attribute name=\"attr\" type=\"xsd:ID\" use=\"required\"/>"+ - "</xsd:complexType>"+ - "</xsd:element>"+ - "</xsd:schema>"+ - "</XMLContent>"+ - "</Content>"+ - "</Supplement>"); - - req = replaceString(req,"<FinalDataMetaInfo>", - "<dsig:Transforms><dsig:Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/></dsig:Transforms>"+ - "<FinalDataMetaInfo>"); - - - - //req = replaceString(req,"Index=\"0\">//data:Document","Index=\"0\">//data:Document"); - System.out.println("!!!"); - System.out.println(req); - - req = replaceString(req, - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt"+"\">"+ - "<XMLContent xml:space=\"preserve\">Dies sind Testdaten</XMLContent>"+ - "</DataObject>", - "<DataObject Reference=\"#document\">"+ - "</DataObject>" - ); - - System.out.println(req); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - //InputStream bis = new ByteArrayInputStream(("<data:Document attr=\"document\" xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://uri.data.org http://tollesSchema.org\">Dies sind Testdaten</data:Document>").getBytes()); - InputStream bis = new ByteArrayInputStream(("<data:Document xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" attr=\"document\" xsi:schemaLocation=\"http://uri.data.org http://tollesSchema.org/test.xsd\">Dies sind Testdaten</data:Document>").getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setValidating(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - - Map m = new HashMap(); - m.put("http://tollesSchema.org/test.xsd",new ByteArrayInputStream(( - "<xsd:schema targetNamespace=\"http://uri.data.org\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://uri.data.org\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\" id=\"tollesSchema\">"+ - "<xsd:element name=\"Document\">"+ - "<xsd:complexType mixed=\"true\">"+ - "<xsd:sequence maxOccurs=\"unbounded\" minOccurs=\"0\">"+ - "<xsd:any namespace=\"##any\" processContents=\"lax\"/>"+ - "</xsd:sequence>"+ - "<xsd:attribute name=\"attr\" type=\"xsd:ID\" use=\"required\"/>"+ - "</xsd:complexType>"+ - "</xsd:element></xsd:schema>").getBytes())); - - EntityResolverChain chain = new EntityResolverChain(); - chain.addEntityResolver(new StreamEntityResolver(m)); - chain.addEntityResolver(new MOAEntityResolver()); - builder.setEntityResolver(chain); - - //Dokument Parsen - Document reqDoc = DOMUtils.parseDocument(bis,true,Constants.ALL_SCHEMA_LOCATIONS, null,chain,new MOAErrorHandler()); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - //Position für die Signatur angeben - //String xPath_Pos = "/node()"; - String xPath_Pos = "//data:Document"; - //XPAth-Prefixe deklarieren - //String xPath_Prefix = "data xmlns:data=\"http://uri.data.org\""; - String xPath_Prefix = "data http://uri.data.org"; - - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc,pos,"signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt","reference-1-1"); - Transform[] tr = new Transform[1]; - TransformImplEnvelopedSignature trans = new TransformImplEnvelopedSignature(); - tr[0] = trans; - //Enveloped Transformation - cpkcs.createReferenceWithTransforms(new URI("#document"),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc,"<data:Document xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" attr=\"document\" xsi:schemaLocation=\"http://uri.data.org http://tollesSchema.org/test.xsd\">",readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>"); - - writeFile(resFile, output); - - } - - public void create006() throws Exception { - - String TestNumber = "006"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<XMLContent xml:space=\"preserve\">"+ - "<data:Document xmlns:data=\"http://uri.data.org\">Dies sind Testdaten</data:Document>"+ - "</XMLContent>"+ - "</CreateSignatureEnvironment>"); - - req = replaceString(req, - "<CreateSignatureEnvironmentProfile>"+ - "<CreateSignatureLocation Index=\"0\">//data:Document</CreateSignatureLocation>"+ - "<!-- insert supp -->"+ - "</CreateSignatureEnvironmentProfile>", - "<CreateSignatureEnvironmentProfileID>CreateSignatureEnvironmentProfile1</CreateSignatureEnvironmentProfileID>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - InputStream bis = new ByteArrayInputStream(("<data:Document xmlns:data=\"http://uri.data.org\">"+readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>").getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - //Dokument Parsen - - - Document reqDoc = builder.parse(bis); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - //Position für die Signatur angeben - String xPath_Pos = "/node()"; - //XPAth-Prefixe deklarieren - String xPath_Prefix = "data xmlns:data=\"http://uri.data.org\""; - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc,pos,"signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt","reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc,"<data:Document xmlns:data=\"http://uri.data.org\">",readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>"); - - writeFile(resFile, output); - - } - - public void create007() throws Exception { - - String TestNumber = "007"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<Base64Content>"+ - ""+Base64Utils.encode(("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Document SYSTEM \"http://dtd.org/tollesDTD.dtd\"><Document attr=\"document\">Dies sind Testdaten</Document>").getBytes())+""+ - "</Base64Content>"+ - "</CreateSignatureEnvironment>"); - - req = replaceString(req, - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt"+"\">"+ - "<XMLContent xml:space=\"preserve\">Dies sind Testdaten</XMLContent>"+ - "</DataObject>", - "<DataObject Reference=\"#document\">"+ - "</DataObject>" - ); - - req = replaceString(req,"<!-- insert supp -->", - "<Supplement>"+ - "<Content Reference=\"http://dtd.org/tollesDTD.dtd\">"+ - "<Base64Content>"+ - ""+Base64Utils.encode(("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!ELEMENT Document (#PCDATA | ANY)*><!ATTLIST Document attr ID #REQUIRED>").getBytes())+""+ - "</Base64Content>"+ - "</Content>"+ - "</Supplement>"); - - req = replaceString(req," xmlns:data=\"http://uri.data.org\"",""); - req = replaceString(req,"//data:Document","//Document"); - - - req = replaceString(req,"<FinalDataMetaInfo>", - "<dsig:Transforms><dsig:Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/></dsig:Transforms>"+ - "<FinalDataMetaInfo>"); - - //req = replaceString(req,"Index=\"0\">//data:Document","Index=\"0\">//Hugo"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - InputStream bis = new ByteArrayInputStream(("<!DOCTYPE Document SYSTEM \"http://dtd.org/tollesDTD.dtd\"><Document attr=\"document\">"+readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</Document>").getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setValidating(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - //Dokument Parsen - Map m = new HashMap(); - m.put("http://dtd.org/tollesDTD.dtd",new ByteArrayInputStream(( - "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!ELEMENT Document (#PCDATA | ANY)*><!ATTLIST Document attr ID #REQUIRED>").getBytes())); - - EntityResolverChain chain = new EntityResolverChain(); - chain.addEntityResolver(new StreamEntityResolver(m)); - chain.addEntityResolver(new MOAEntityResolver()); - builder.setEntityResolver(chain); - - Document reqDoc = DOMUtils.parseDocument(bis,true,Constants.ALL_SCHEMA_LOCATIONS, null,chain,new MOAErrorHandler()); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - //Position für die Signatur angeben - String xPath_Pos = "/Document"; - //XPAth-Prefixe deklarieren - String xPath_Prefix = ""; - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc,pos,"signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt","reference-1-1"); - Transform[] tr = new Transform[1]; - TransformImplEnvelopedSignature trans = new TransformImplEnvelopedSignature(); - tr[0] = trans; - //Enveloped Transformation - cpkcs.createReferenceWithTransforms(new URI("#document"),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc,"<Document attr=\"document\" xmlns=\"\">",readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</Document>"); - - writeFile(resFile, output); - - } - - public void create008() throws Exception { - - String TestNumber = "008"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<XMLContent xml:space=\"preserve\">"+ - "<data:Document xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" attr=\"document\" xsi:schemaLocation=\"http://uri.data.org http://tollesSchema.org/test.xsd\">Dies sind Testdaten</data:Document>"+ - "</XMLContent>"+ - "</CreateSignatureEnvironment>"); - - req = replaceString(req,"<!-- insert supp -->", - "<Supplement>"+ - "<Content Reference=\"http://tollesSchema.org/test.xsd\">"+ - "<Base64Content>"+ - - Base64Utils.encode(("<xsd:schema targetNamespace=\"http://uri.data.org\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://uri.data.org\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\" id=\"tollesSchema\">"+ - "<xsd:element name=\"Document\">"+ - "<xsd:complexType mixed=\"true\">"+ - "<xsd:sequence maxOccurs=\"unbounded\" minOccurs=\"0\">"+ - "<xsd:any namespace=\"##any\" processContents=\"lax\"/>"+ - "</xsd:sequence>"+ - "<xsd:attribute name=\"attr\" type=\"xsd:ID\" use=\"required\"/>"+ - "</xsd:complexType>"+ - "</xsd:element>"+ - "</xsd:schema>").getBytes())+ - - "</Base64Content>"+ - "</Content>"+ - "</Supplement>"); - - req = replaceString(req,"<FinalDataMetaInfo>", - "<dsig:Transforms><dsig:Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/></dsig:Transforms>"+ - "<FinalDataMetaInfo>"); - - - //req = replaceString(req,"Index=\"0\">//data:Document","Index=\"0\">//data:Document"); - System.out.println("!!!"); - System.out.println(req); - - req = replaceString(req, - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt"+"\">"+ - "<XMLContent xml:space=\"preserve\">Dies sind Testdaten</XMLContent>"+ - "</DataObject>", - "<DataObject Reference=\"#document\">"+ - "</DataObject>" - ); - - System.out.println(req); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - InputStream bis = new ByteArrayInputStream(("<data:Document xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" attr=\"document\" xsi:schemaLocation=\"http://uri.data.org http://tollesSchema.org/test.xsd\">Dies sind Testdaten</data:Document>").getBytes()); - //Document-Builder holen - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setValidating(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - - Map m = new HashMap(); - m.put("http://tollesSchema.org/test.xsd",new ByteArrayInputStream(( - "<xsd:schema targetNamespace=\"http://uri.data.org\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://uri.data.org\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\" id=\"tollesSchema\">"+ - "<xsd:element name=\"Document\">"+ - "<xsd:complexType mixed=\"true\">"+ - "<xsd:sequence maxOccurs=\"unbounded\" minOccurs=\"0\">"+ - "<xsd:any namespace=\"##any\" processContents=\"lax\"/>"+ - "</xsd:sequence>"+ - "<xsd:attribute name=\"attr\" type=\"xsd:ID\" use=\"required\"/>"+ - "</xsd:complexType>"+ - "</xsd:element>"+ - "</xsd:schema>").getBytes())); - - EntityResolverChain chain = new EntityResolverChain(); - chain.addEntityResolver(new StreamEntityResolver(m)); - chain.addEntityResolver(new MOAEntityResolver()); - builder.setEntityResolver(chain); - - //Dokument Parsen - Document reqDoc = DOMUtils.parseDocument(bis,true,Constants.ALL_SCHEMA_LOCATIONS, null,chain,new MOAErrorHandler()); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - //Position für die Signatur angeben - String xPath_Pos = "//data:Document"; - //XPAth-Prefixe deklarieren - //String xPath_Prefix = "data xmlns:data=\"http://uri.data.org\""; - String xPath_Prefix = "data http://uri.data.org"; - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc,pos,"signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt","reference-1-1"); - Transform[] tr = new Transform[1]; - TransformImplEnvelopedSignature trans = new TransformImplEnvelopedSignature(); - tr[0] = trans; - //Enveloped Transformation - cpkcs.createReferenceWithTransforms(new URI("#document"),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc,"<data:Document attr=\"document\" xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://uri.data.org http://tollesSchema.org/test.xsd\">",readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>"); - - writeFile(resFile, output); - - } - - public void create009() throws Exception { - - String TestNumber = "009"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<XMLContent xml:space=\"preserve\">"+ - "<data:Document xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" attr=\"document\" xsi:schemaLocation=\"http://uri.data.org http://tollesSchema.org/test.xsd\">Dies sind Testdaten</data:Document>"+ - "</XMLContent>"+ - "</CreateSignatureEnvironment>"); - - req = replaceString(req,"<!-- insert supp -->", - "<Supplement>"+ - "<Content Reference=\"http://tollesSchema.org/test.xsd\">"+ - "<XMLContent xml:space=\"preserve\">"+ - "<xsd:schema targetNamespace=\"http://uri.data.org\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://uri.data.org\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\" id=\"tollesSchema\">"+ - "<xsd:element name=\"Document\">"+ - "<xsd:complexType mixed=\"true\">"+ - "<xsd:sequence maxOccurs=\"unbounded\" minOccurs=\"0\">"+ - "<xsd:any namespace=\"##any\" processContents=\"lax\"/>"+ - "</xsd:sequence>"+ - "<xsd:attribute name=\"attr\" type=\"xsd:ID\" use=\"required\"/>"+ - "</xsd:complexType>"+ - "</xsd:element>"+ - "</xsd:schema>"+ - "</XMLContent>"+ - "</Content>"+ - "</Supplement>"); - - req = replaceString(req,"<FinalDataMetaInfo>", - "<dsig:Transforms><dsig:Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/></dsig:Transforms>"+ - "<FinalDataMetaInfo>"); - - - - //req = replaceString(req,"Index=\"0\">//data:Document","Index=\"0\">//data:Document"); - System.out.println("!!!"); - System.out.println(req); - - req = replaceString(req, - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt"+"\">"+ - "<XMLContent xml:space=\"preserve\">Dies sind Testdaten</XMLContent>"+ - "</DataObject>", - "<DataObject Reference=\"#xpointer(id(document))\">"+ - "</DataObject>" - ); - - System.out.println(req); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - //InputStream bis = new ByteArrayInputStream(("<data:Document attr=\"document\" xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://uri.data.org http://tollesSchema.org\">Dies sind Testdaten</data:Document>").getBytes()); - InputStream bis = new ByteArrayInputStream(("<data:Document xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" attr=\"document\" xsi:schemaLocation=\"http://uri.data.org http://tollesSchema.org/test.xsd\">Dies sind Testdaten</data:Document>").getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setValidating(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - - Map m = new HashMap(); - m.put("http://tollesSchema.org/test.xsd",new ByteArrayInputStream(( - "<xsd:schema targetNamespace=\"http://uri.data.org\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://uri.data.org\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\" id=\"tollesSchema\">"+ - "<xsd:element name=\"Document\">"+ - "<xsd:complexType mixed=\"true\">"+ - "<xsd:sequence maxOccurs=\"unbounded\" minOccurs=\"0\">"+ - "<xsd:any namespace=\"##any\" processContents=\"lax\"/>"+ - "</xsd:sequence>"+ - "<xsd:attribute name=\"attr\" type=\"xsd:ID\" use=\"required\"/>"+ - "</xsd:complexType>"+ - "</xsd:element></xsd:schema>").getBytes())); - - EntityResolverChain chain = new EntityResolverChain(); - chain.addEntityResolver(new StreamEntityResolver(m)); - chain.addEntityResolver(new MOAEntityResolver()); - builder.setEntityResolver(chain); - - //Dokument Parsen - Document reqDoc = DOMUtils.parseDocument(bis,true,Constants.ALL_SCHEMA_LOCATIONS, null,chain,new MOAErrorHandler()); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - //Position für die Signatur angeben - //String xPath_Pos = "/node()"; - String xPath_Pos = "//data:Document"; - //XPAth-Prefixe deklarieren - //String xPath_Prefix = "data xmlns:data=\"http://uri.data.org\""; - String xPath_Prefix = "data http://uri.data.org"; - - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc,pos,"signature-1-1"); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt","reference-1-1"); - Transform[] tr = new Transform[1]; - TransformImplEnvelopedSignature trans = new TransformImplEnvelopedSignature(); - tr[0] = trans; - //Enveloped Transformation - cpkcs.createReferenceWithTransforms(new URI("#xpointer(id(document))"),tr,"reference-1-1"); - cpkcs.setKeyInformation(1); - - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc,"<data:Document xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" attr=\"document\" xsi:schemaLocation=\"http://uri.data.org http://tollesSchema.org/test.xsd\">",readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</data:Document>"); - - writeFile(resFile, output); - - } - - public void create051() throws Exception { - - String TestNumber = "051"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<CreateSignatureInfo xmlns:data=\"http://uri.data.org\">","<CreateSignatureInfo>"); - - req = replaceString(req,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<XMLContent xml:space=\"preserve\">"+ - "<data:Document xmlns:data=\"http://uri.data.org\">daten</data:Document><Text>toller Text</Text>"+ - "</XMLContent>"+ - "</CreateSignatureEnvironment>"); - - req = replaceString(req,"<CreateSignatureLocation Index=\"0\">","<CreateSignatureLocation Index=\"0\" xmlns:data=\"http://uri.data.org\">"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"1109"); - - } - - public void create052() throws Exception { - - String TestNumber = "052"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<Base64Content>PFRhZzE+PC9UYWcxPjxUYWcyPjwvVGFnMj4NCg0K</Base64Content><!-- Inhalt: <Tag1></Tag1><Tag2></Tag2> -->"+ - "</CreateSignatureEnvironment>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2218"); - - } - - public void create053() throws Exception { - - String TestNumber = "053"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment/>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"1110"); - - } - - public void create054() throws Exception { - - String TestNumber = "054"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<XMLContent xml:space=\"preserve\"><data:Document xmlns:data=\"http://uri.data.org\">Dies sind Testdaten</data:Document></XMLContent>"+ - "</CreateSignatureEnvironment>"); - - req = replaceString(req, - "<CreateTransformsInfo>"+ - "<FinalDataMetaInfo>"+ - "<MimeType>text/plain</MimeType>"+ - "</FinalDataMetaInfo>"+ - "</CreateTransformsInfo>", - "<CreateTransformsInfo>"+ - "<dsig:Transforms>"+ - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xpath-19991116\">"+ - "<dsig:XPath>/data:book/data:first-name/node()</dsig:XPath>"+ - "</dsig:Transform>"+ - "</dsig:Transforms>"+ - "<FinalDataMetaInfo>"+ - "<MimeType>text/xml</MimeType>"+ - "</FinalDataMetaInfo>"+ - "</CreateTransformsInfo>"); - - req = replaceString(req, - "<CreateSignatureLocation Index=\"0\">//data:Document</CreateSignatureLocation>", - "<CreateSignatureLocation Index=\"0\">//data:Document1</CreateSignatureLocation>"); - - req = replaceString(req, - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt"+"\">"+ - "<XMLContent xml:space=\"preserve\">"+readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</XMLContent>"+ - "</DataObject>", - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/BookData.xml"+"\"/>"); - - //req = replaceString(req,"/data:Document","/data:nonExistingElement"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2212"); - - } - - public void create056() throws Exception { - - String TestNumber = "056"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<XMLContent xml:space=\"preserve\">"+ - "<data:Document>andereDaten als in "+configuration_.getProperty("webbaseDir")+"resources/CSEP.xml</data:Document>"+ - "</XMLContent>"+ - "</CreateSignatureEnvironment>"); - - req = replaceString(req, - "<CreateSignatureEnvironmentProfile>"+ - "<CreateSignatureLocation Index=\"0\">//data:Document</CreateSignatureLocation>"+ - "<!-- insert supp -->"+ - "</CreateSignatureEnvironmentProfile>", - "<CreateSignatureEnvironmentProfileID>wrongCreateSignatureEnvironmentProfile</CreateSignatureEnvironmentProfileID>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2236"); - - } - - public void create057() throws Exception { - - String TestNumber = "057"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment>"+ - "<XMLContent xml:space=\"preserve\"><data:Document xmlns:data=\"http://uri.data.org\">Dies sind Testdaten</data:Document></XMLContent>"+ - "</CreateSignatureEnvironment>"); - - req = replaceString(req, - "<CreateTransformsInfo>"+ - "<FinalDataMetaInfo>"+ - "<MimeType>text/plain</MimeType>"+ - "</FinalDataMetaInfo>"+ - "</CreateTransformsInfo>", - "<CreateTransformsInfo>"+ - "<dsig:Transforms>"+ - "<dsig:Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xpath-19991116\">"+ - "<dsig:XPath>/data:book/data:first-name/node()</dsig:XPath>"+ - "</dsig:Transform>"+ - "</dsig:Transforms>"+ - "<FinalDataMetaInfo>"+ - "<MimeType>text/xml</MimeType>"+ - "</FinalDataMetaInfo>"+ - "</CreateTransformsInfo>"); - - req = replaceString(req, - "<CreateSignatureLocation Index=\"0\">//data:Document</CreateSignatureLocation>", - "<CreateSignatureLocation Index=\"0\">]]'_'[[//data:Document</CreateSignatureLocation>"); - - req = replaceString(req, - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt"+"\">"+ - "<XMLContent xml:space=\"preserve\">"+readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")+"</XMLContent>"+ - "</DataObject>", - "<DataObject Reference=\""+configuration_.getProperty("webbaseDir")+"resources/BookData.xml"+"\"/>"); - - //req = replaceString(req,"/data:Document","/data:nonExistingElement"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2212"); - - } - - public void create055() throws Exception { - - String TestNumber = "055"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert create -->", - "<CreateSignatureEnvironment Reference=\""+configuration_.getProperty("webbaseDir")+"resources/CSEP.xml\">"+ - "<XMLContent xml:space=\"preserve\">"+ - "<data:Document>andereDaten als in "+configuration_.getProperty("webbaseDir")+"resources/CSEP.xml</data:Document>"+ - "</XMLContent>"+ - "</CreateSignatureEnvironment>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"1110"); - - } - - - public void writeFile(String filename,String data) throws Exception - { - BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); - bw.write(data); - bw.close(); - } - - public String makeOutputFile(Document signatureDoc,String prefix,String suffix) 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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+ - "<CreateXMLSignatureResponse" + - " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\""+ - " >"+ - //" xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\">"+ - "<SignatureEnvironment>" +prefix+ - erg +suffix+ "</SignatureEnvironment> </CreateXMLSignatureResponse>"; - - return erg; - } - - public String makeOutputFile(Document signatureDoc) throws Exception - { - return this.makeOutputFile(signatureDoc,"",""); - } -} diff --git a/spss.test/src/testgenerator/TestGeneratorFeature41.java b/spss.test/src/testgenerator/TestGeneratorFeature41.java deleted file mode 100644 index 7ecb28449..000000000 --- a/spss.test/src/testgenerator/TestGeneratorFeature41.java +++ /dev/null @@ -1,1167 +0,0 @@ -package testgenerator; - -import iaik.ixsil.algorithms.CanonicalizationAlgorithmImplCanonicalXML; -import iaik.ixsil.algorithms.DigestAlgorithmImplSHA1; -import iaik.ixsil.algorithms.SignatureAlgorithmImplRSA; -import iaik.ixsil.algorithms.Transform; -import iaik.ixsil.algorithms.TransformImplBase64Decode; -import iaik.ixsil.algorithms.TransformImplEnvelopedSignature; -import iaik.ixsil.algorithms.TransformImplXSLT; -import iaik.ixsil.core.Position; -import iaik.ixsil.core.Signer; -import iaik.ixsil.core.SignerManifest; -import iaik.ixsil.core.SignerReference; -import iaik.ixsil.core.SignerSignature; -import iaik.ixsil.core.SignerSignedInfo; -import iaik.ixsil.init.IXSILConstants; -import iaik.ixsil.keyinfo.KeyManagerImpl; -import iaik.ixsil.keyinfo.x509.KeyProviderImplX509Data; -import iaik.ixsil.keyinfo.x509.X509Data; -import iaik.ixsil.util.URI; - -import iaik.pkcs.pkcs12.PKCS12; -import iaik.utils.Base64OutputStream; - -import java.io.BufferedWriter; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; -import java.security.cert.X509Certificate; -import java.security.interfaces.RSAPrivateKey; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.Text; - -import at.gv.egovernment.moa.util.Base64Utils; -import at.gv.egovernment.moa.util.Constants; -import at.gv.egovernment.moa.util.DOMUtils; -import at.gv.egovernment.moa.util.EntityResolverChain; -import at.gv.egovernment.moa.util.MOAEntityResolver; -import at.gv.egovernment.moa.util.MOAErrorHandler; -import at.gv.egovernment.moa.util.StreamEntityResolver; - -/** - * @author Gregor Karlinger - */ -public class TestGeneratorFeature41 extends TestCases -{ - - String datadirectory = "data/feature41/"; - - public static void main(String[] args) throws Exception - { - TestGeneratorFeature41 testcase = new TestGeneratorFeature41(); - - testcase.create001(); - testcase.create002(); - testcase.create003(); - testcase.create004(); - testcase.create005(); - } - - /* ==================================================================================================== */ - - public TestGeneratorFeature41() throws Exception - { - - super(); - - // Set config properties - configuration_.setProperty("TestClass", "TestGeneratorFeature41"); - - iaik.security.provider.IAIK.addAsJDK14Provider(); - iaik.security.ecc.provider.ECCProvider.addAsProvider(); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - public Document createPKCS12Sig( - String TestNumber, - String data, - boolean env, - boolean mani, - String data2, - boolean env2) - throws Exception - { - String resFile = - configuration_.getProperty("baseDir") - + datadirectory - + configuration_.getProperty("TestClass") - + "." - + TestNumber - + ".Res.xml"; - - PKCS12 pkcs12 = - decryptPKCS12(configuration_.getProperty("PKCS12file"), configuration_.getProperty("PKCS12password")); - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - Signer signer = new Signer(baseURI); - - // Configure signed information - - // Get interface for signed information - SignerSignature signature = signer.getSignature(); - SignerSignedInfo signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set canonicalization algorithm - CanonicalizationAlgorithmImplCanonicalXML c14nAlg = new CanonicalizationAlgorithmImplCanonicalXML(); - signedInfo.setCanonicalizationAlgorithm(c14nAlg); - - // Set signature algorithm - SignatureAlgorithmImplRSA signatureAlg = new SignatureAlgorithmImplRSA(); - RSAPrivateKey privateKey = getPrivateKey(pkcs12); - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - - if (!mani) - { - SignerReference reference = signedInfo.createReference(); - if (env) - { - iaik.ixsil.core.Object object = null; - //object = signature.createObject(data); - if (data.startsWith("<xml")) - { - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(data.getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else if (data.startsWith("<Testdaten")) - { - - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = - db.parse( - new ByteArrayInputStream(("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + data).getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else if (data.startsWith("b64:")) - { - data = data.substring(4); - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.newDocument(); - Element root = doc.createElement("root"); - doc.appendChild(root); - //String encoded = Base64Utils.encode(data.getBytes()); - String encoded = Base64Utils.encode(data.getBytes()); - /*encoded = replaceStringAll(encoded,"\n",""); - encoded = replaceStringAll(encoded,"\r","");*/ - Text textnode = doc.createTextNode(encoded); - - System.out.println("Encoded:" + encoded); - //root.appendChild(textnode); - - DocumentFragment df = doc.createDocumentFragment(); - - df.appendChild(textnode); - - object = signature.createObject(df); - - TransformImplBase64Decode trans = new TransformImplBase64Decode(); - InputStream s = new ByteArrayInputStream(encoded.getBytes()); - trans.setInput(s, null); - - reference.insertTransformAt(trans, 0); - } - else - { - object = signature.createObject(data); - } - - object.setId("signed-data-1-1-1"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - reference.setURI(new URI("#xpointer(id('signed-data-1-1-1')/node())")); - - } - else - { - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(data); - - reference.setURI(refURI); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - } - reference.setId("reference-1-1"); - signedInfo.addReference(reference); - } - - if (data2 != null) - { - SignerReference reference = signedInfo.createReference(); - reference = signedInfo.createReference(); - if (env2) - { - iaik.ixsil.core.Object object = null; - if (data2.startsWith("<xml")) - { - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(data.getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else if (data2.startsWith("<Testdaten")) - { - - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = - db.parse( - new ByteArrayInputStream(("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + data).getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else - object = signature.createObject(data2); - - if (!env) - object.setId("signed-data-1-2-1"); - else - object.setId("signed-data-1-2-1"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - if (!env) - reference.setURI(new URI("#xpointer(id('signed-data-1-2-1')/node())")); - else - reference.setURI(new URI("#xpointer(id('signed-data-1-2-1')/node())")); - } - else - { - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(data2); - - reference.setURI(refURI); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - } - reference.setId("reference-1-2"); - signedInfo.addReference(reference); - } - - // Add reference to signature - - if (mani) - { - - /*iaik.ixsil.core.Object object = null; - if(env) - object = signature.createObject(readFile(data)); - else - object = signature.createObject(data); - - object.setId("envelopedData"); - signature.addObject(object);*/ - SignerReference reference = signedInfo.createReference(); - SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - manifestRef.setDigestAlgorithm(digestAlg); - - manifestRef.setURI(new URI(data)); - manifestRef.setId("reference-1-1"); - - manifest.addReference(manifestRef); - manifest.setId("dsig-manifest-1-1"); - iaik.ixsil.core.Object manifestObject = signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - reference = signedInfo.createReference(); - reference.setURI(new URI("#dsig-manifest-1-1")); - reference.setType(new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference); - - /*Element envelopedDataElem = - signer.toDocument().createElement("EnvelopedDataElement"); - - if(env) - { - envelopedDataElem.appendChild( - signer.toDocument().createTextNode(readFile(data))); - } - else - { - envelopedDataElem.appendChild( - signer.toDocument().createTextNode(data)); - } - - iaik.ixsil.core.Object object = signature.createObject(envelopedDataElem); - signature.addObject(object); - - // Create Manifest with a single reference pointing to the enveloped data - SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - manifestRef.setURI( - new URI( - null, - null, - null, - null, - "xmlns(dsig=" - + IXSILConstants.NAMESPACE_URI_XMLSIGNATURE_ELEM_ - + ") " - + "xpointer(here()/ancestor::dsig:Signature[1]/dsig:Object[1]/descendant::node())")); - manifestRef.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - manifest.addReference(manifestRef); - - // Add Manifest to signature structure (use an Object) and compute digest values for manifest reference - iaik.ixsil.core.Object manifestObject = signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - // Create and configure reference to manifest - reference = signedInfo.createReference(); - reference.setURI( - new URI( - null, - null, - null, - null, - "xmlns(dsig=" - + IXSILConstants.NAMESPACE_URI_XMLSIGNATURE_ELEM_ - + ") " - + "xpointer(here()/ancestor::dsig:Signature[1]/dsig:Object[2]/dsig:Manifest)")); - reference.setType(new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference);*/ - } - - // Create key information - KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument()); - - X509Certificate[] certs = getCertificates(pkcs12); - X509Data x509Data = new X509Data(); - x509Data.insertHintAt(certs[1], 0); - /*for (int i = 0; i < certs.length; i++) - { - - }*/ - - KeyProviderImplX509Data x509DataKeyProvider = new KeyProviderImplX509Data(signer.toDocument()); - x509DataKeyProvider.insertX509DataAt(x509Data, 0); - - // X509Data key information (certificate chain) - keyManager.addKeyProvider(x509DataKeyProvider); - - signer.getSignature().setKeyManager(keyManager); - signer.getSignature().setId("signature-1-1"); - // Compute signature value - signer.getSignature().sign(); - - return signer.toDocument(); - } - - public Document createPKCS12Sig( - String TestNumber, - String data, - boolean env, - boolean mani, - String data2, - boolean env2, - String id1, - String id2) - throws Exception - { - String resFile = - configuration_.getProperty("baseDir") - + datadirectory - + configuration_.getProperty("TestClass") - + "." - + TestNumber - + ".Res.xml"; - - PKCS12 pkcs12 = - decryptPKCS12(configuration_.getProperty("PKCS12file"), configuration_.getProperty("PKCS12password")); - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - Signer signer = new Signer(baseURI); - - // Configure signed information - - // Get interface for signed information - SignerSignature signature = signer.getSignature(); - SignerSignedInfo signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set canonicalization algorithm - CanonicalizationAlgorithmImplCanonicalXML c14nAlg = new CanonicalizationAlgorithmImplCanonicalXML(); - signedInfo.setCanonicalizationAlgorithm(c14nAlg); - - // Set signature algorithm - SignatureAlgorithmImplRSA signatureAlg = new SignatureAlgorithmImplRSA(); - RSAPrivateKey privateKey = getPrivateKey(pkcs12); - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - - if (!mani) - { - SignerReference reference = signedInfo.createReference(); - if (env) - { - iaik.ixsil.core.Object object = null; - //object = signature.createObject(data); - if (data.startsWith("<xml")) - { - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(data.getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else if (data.startsWith("<Testdaten")) - { - - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = - db.parse( - new ByteArrayInputStream(("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + data).getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else if (data.startsWith("b64:")) - { - data = data.substring(4); - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.newDocument(); - Element root = doc.createElement("root"); - doc.appendChild(root); - //String encoded = Base64Utils.encode(data.getBytes()); - String encoded = Base64Utils.encode(data.getBytes()); - /*encoded = replaceStringAll(encoded,"\n",""); - encoded = replaceStringAll(encoded,"\r","");*/ - Text textnode = doc.createTextNode(encoded); - - System.out.println("Encoded:" + encoded); - //root.appendChild(textnode); - - DocumentFragment df = doc.createDocumentFragment(); - - df.appendChild(textnode); - - object = signature.createObject(df); - - TransformImplBase64Decode trans = new TransformImplBase64Decode(); - InputStream s = new ByteArrayInputStream(encoded.getBytes()); - trans.setInput(s, null); - - reference.insertTransformAt(trans, 0); - } - else - { - object = signature.createObject(data); - } - - object.setId("signed-data-1-1-1"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - reference.setURI(new URI("#xpointer(id('signed-data-1-1-1')/node())")); - - } - else - { - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(data); - - reference.setURI(refURI); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - } - reference.setId("reference-2-1"); - signedInfo.addReference(reference); - } - - if (data2 != null) - { - SignerReference reference = signedInfo.createReference(); - reference = signedInfo.createReference(); - if (env2) - { - iaik.ixsil.core.Object object = null; - if (data2.startsWith("<xml")) - { - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(data.getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else if (data2.startsWith("<Testdaten")) - { - - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = - db.parse( - new ByteArrayInputStream(("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + data).getBytes())); - - object = signature.createObject(doc.getDocumentElement()); - } - else - object = signature.createObject(data2); - - if (!env) - object.setId("signed-data-1-2-1"); - else - object.setId("signed-data-1-2-1"); - signature.addObject(object); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - - if (!env) - reference.setURI(new URI("#xpointer(id('signed-data-1-2-1')/node())")); - else - reference.setURI(new URI("#xpointer(id('signed-data-1-2-1')/node())")); - } - else - { - // Create and configure reference - URI refURI = null; - String baseDir = configuration_.getProperty("baseDir"); - refURI = new URI(data2); - - reference.setURI(refURI); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - } - reference.setId("reference-1-2"); - signedInfo.addReference(reference); - } - - // Add reference to signature - - if (mani) - { - - /*iaik.ixsil.core.Object object = null; - if(env) - object = signature.createObject(readFile(data)); - else - object = signature.createObject(data); - - object.setId("envelopedData"); - signature.addObject(object);*/ - SignerReference reference = signedInfo.createReference(); - SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - manifestRef.setDigestAlgorithm(digestAlg); - - manifestRef.setURI(new URI(data)); - manifestRef.setId("reference-1-1"); - - manifest.addReference(manifestRef); - manifest.setId("dsig-manifest-1-1"); - iaik.ixsil.core.Object manifestObject = signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - reference = signedInfo.createReference(); - reference.setURI(new URI("#dsig-manifest-1-1")); - reference.setType(new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference); - - /*Element envelopedDataElem = - signer.toDocument().createElement("EnvelopedDataElement"); - - if(env) - { - envelopedDataElem.appendChild( - signer.toDocument().createTextNode(readFile(data))); - } - else - { - envelopedDataElem.appendChild( - signer.toDocument().createTextNode(data)); - } - - iaik.ixsil.core.Object object = signature.createObject(envelopedDataElem); - signature.addObject(object); - - // Create Manifest with a single reference pointing to the enveloped data - SignerManifest manifest = signer.createManifest(); - SignerReference manifestRef = manifest.createReference(); - manifestRef.setURI( - new URI( - null, - null, - null, - null, - "xmlns(dsig=" - + IXSILConstants.NAMESPACE_URI_XMLSIGNATURE_ELEM_ - + ") " - + "xpointer(here()/ancestor::dsig:Signature[1]/dsig:Object[1]/descendant::node())")); - manifestRef.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - manifest.addReference(manifestRef); - - // Add Manifest to signature structure (use an Object) and compute digest values for manifest reference - iaik.ixsil.core.Object manifestObject = signature.createObject(manifest); - signature.addObject(manifestObject); - manifest.computeDigestValues(); - - // Create and configure reference to manifest - reference = signedInfo.createReference(); - reference.setURI( - new URI( - null, - null, - null, - null, - "xmlns(dsig=" - + IXSILConstants.NAMESPACE_URI_XMLSIGNATURE_ELEM_ - + ") " - + "xpointer(here()/ancestor::dsig:Signature[1]/dsig:Object[2]/dsig:Manifest)")); - reference.setType(new URI(IXSILConstants.REFERENCETYPE_ATTR_VALUE_MANIFEST_)); - reference.setDigestAlgorithm(new DigestAlgorithmImplSHA1()); - - // Add reference to signature - signedInfo.addReference(reference);*/ - } - - // Create key information - KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument()); - - X509Certificate[] certs = getCertificates(pkcs12); - X509Data x509Data = new X509Data(); - x509Data.insertHintAt(certs[1], 0); - /*for (int i = 0; i < certs.length; i++) - { - - }*/ - - KeyProviderImplX509Data x509DataKeyProvider = new KeyProviderImplX509Data(signer.toDocument()); - x509DataKeyProvider.insertX509DataAt(x509Data, 0); - - // X509Data key information (certificate chain) - keyManager.addKeyProvider(x509DataKeyProvider); - - signer.getSignature().setKeyManager(keyManager); - signer.getSignature().setId("signature-2-1"); - // Compute signature value - signer.getSignature().sign(); - - return signer.toDocument(); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - public Element getElement(String data) throws Exception - { - String etsinamespace = "http://uri.etsi.org/01903/v1.1.1#"; - - getX509Content(); - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - //dbf.setNamespaceAware(true); - //dbf.setValidating(true); - - Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - - Element qualprop = doc.createElementNS(etsinamespace, "etsi:QualifyingProperties"); - qualprop.setAttributeNS(null, "Target", "#signature-1-1"); - qualprop.setAttributeNS(IXSILConstants.NAMESPACE_URI_NAMESPACES_, "xmlns:etsi", etsinamespace); - //qualprop.setPrefix("etsi");*/ - //qualprop.setAttributeNodeNS(doc.createAttributeNS(etsinamespace,"etsi")); - Element signprop = doc.createElementNS(etsinamespace, "etsi:SignedProperties"); - Element signsigprop = doc.createElementNS(etsinamespace, "etsi:SignedSignatureProperties"); - Element signdataobjectprop = doc.createElementNS(etsinamespace, "etsi:SignedDataObjectProperties"); - Element signdate = doc.createElementNS(etsinamespace, "etsi:SigningTime"); - Text datevalue = doc.createTextNode("2003-05-10T00:01:01"); - Element signcert = doc.createElementNS(etsinamespace, "etsi:SigningCertificate"); - Element cert = doc.createElementNS(etsinamespace, "etsi:Cert"); - Element signpolyident = doc.createElementNS(etsinamespace, "etsi:SignaturePolicyIdentifier"); - Element signpolyimp = doc.createElementNS(etsinamespace, "etsi:SignaturePolicyImplied"); - Element certdig = doc.createElementNS(etsinamespace, "etsi:CertDigest"); - Element digmeth = doc.createElementNS(etsinamespace, "etsi:DigestMethod"); - digmeth.setAttribute("Algorithm", "http://www.w3.org/2000/09/xmldsig#sha1"); - Element digvalue = doc.createElementNS(etsinamespace, "etsi:DigestValue"); - - ByteArrayOutputStream fos = new ByteArrayOutputStream(); - Base64OutputStream base64os = new Base64OutputStream(fos); - base64os.write(this.X509hash.getBytes()); - base64os.flush(); - - Text dig_value = doc.createTextNode(fos.toString()); - Element is = doc.createElementNS(etsinamespace, "etsi:IssuerSerial"); - Element i = doc.createElement("dsig:X509IssuerName"); - Text i_value = doc.createTextNode(this.X509name); - Element s = doc.createElement("dsig:X509SerialNumber"); - Text s_value = doc.createTextNode(this.X509number.toString()); - Element dataobjformat = doc.createElementNS(etsinamespace, "etsi:DataObjectFormat"); - dataobjformat.setAttribute("ObjectReference", "#reference-1-1"); - Element mimetype = doc.createElementNS(etsinamespace, "etsi:MimeType"); - //mimetype.setNodeValue("text/plain"); - Text mimevalue = doc.createTextNode("text/plain"); - - qualprop.appendChild(signprop); - signprop.appendChild(signsigprop); - signsigprop.appendChild(signdate); - signdate.appendChild(datevalue); - signsigprop.appendChild(signcert); - signcert.appendChild(cert); - cert.appendChild(certdig); - certdig.appendChild(digmeth); - certdig.appendChild(digvalue); - digvalue.appendChild(dig_value); - cert.appendChild(is); - is.appendChild(i); - i.appendChild(i_value); - is.appendChild(s); - s.appendChild(s_value); - signsigprop.appendChild(signpolyident); - signpolyident.appendChild(signpolyimp); - signprop.appendChild(signdataobjectprop); - signdataobjectprop.appendChild(dataobjformat); - dataobjformat.appendChild(mimetype); - mimetype.appendChild(mimevalue); - - return qualprop; - } - - /* ---------------------------------------------------------------------------------------------------- */ - - public void create001() throws Exception - { - - String testNumber = "001"; - - String resFile = - configuration_.getProperty("baseDir") - + datadirectory - + configuration_.getProperty("TestClass") - + "." - + testNumber - + ".Res.xml"; - - PKCS12 pkcs12 = - decryptPKCS12(configuration_.getProperty("PKCS12file"), configuration_.getProperty("PKCS12password")); - - // Create signature generator - URI baseURI = new URI(IXSILConstants.DUMMY_ABSURI_); - Signer signer = new Signer(baseURI); - - // Configure signed information - - // Get interface for signed information - SignerSignature signature = signer.getSignature(); - SignerSignedInfo signedInfo = signer.getSignature().getSignerSignedInfo(); - - // Set canonicalization algorithm - CanonicalizationAlgorithmImplCanonicalXML c14nAlg = new CanonicalizationAlgorithmImplCanonicalXML(); - signedInfo.setCanonicalizationAlgorithm(c14nAlg); - - // Set signature algorithm - SignatureAlgorithmImplRSA signatureAlg = new SignatureAlgorithmImplRSA(); - RSAPrivateKey privateKey = getPrivateKey(pkcs12); - signatureAlg.setSignerKey(privateKey); - signedInfo.setSignatureAlgorithm(signatureAlg); - - // Create and configure reference - String baseDir = configuration_.getProperty("baseDir"); - InputStream dataIS = new FileInputStream(baseDir + "resources/documents/testDaten.txt"); - - SignerReference reference = signedInfo.createReference(); - reference.setURI(new URI("testDaten.txt")); - reference.setExplicitData(dataIS, SignerReference.EXPLICITDATATYPE_RAW_); - DigestAlgorithmImplSHA1 digestAlg = new DigestAlgorithmImplSHA1(); - reference.setDigestAlgorithm(digestAlg); - reference.setId("reference-1-1"); - signedInfo.addReference(reference); - - // Create key information - KeyManagerImpl keyManager = new KeyManagerImpl(signer.toDocument()); - - X509Certificate[] certs = getCertificates(pkcs12); - X509Data x509Data = new X509Data(); - x509Data.insertHintAt(certs[1], 0); - KeyProviderImplX509Data x509DataKeyProvider = new KeyProviderImplX509Data(signer.toDocument()); - x509DataKeyProvider.insertX509DataAt(x509Data, 0); - - // X509Data key information (certificate chain) - keyManager.addKeyProvider(x509DataKeyProvider); - - signer.getSignature().setKeyManager(keyManager); - signer.getSignature().setId("signature-1-1"); - // Compute signature value - signer.getSignature().sign(); - - String erg = makeOutputFile(signer.toDocument()); - writeFile(resFile, erg); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - public void create002() throws Exception - { - - String testNumber = "002"; - - String resFile = - configuration_.getProperty("baseDir") - + datadirectory - + configuration_.getProperty("TestClass") - + "." - + testNumber - + ".Res.xml"; - - Document signatureDoc = createPKCS12Sig(testNumber, "b64:Dies sind Testdaten", true, false, null, false); - String erg = makeOutputFile(signatureDoc); - writeFile(resFile, erg); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - public void create003() throws Exception - { - - String testNumber = "003"; - - String resFile = - configuration_.getProperty("baseDir") - + datadirectory - + configuration_.getProperty("TestClass") - + "." - + testNumber - + ".Res.xml"; - - InputStream bis = - new ByteArrayInputStream( - ("<data:Document xmlns:data=\"http://uri.data.org\">" - + readFile(configuration_.getProperty("baseDir") + "resources/documents/testSimple.txt") - + "</data:Document>") - .getBytes()); - - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - //Dokument Parsen - Document reqDoc = builder.parse(bis); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - //Position für die Signatur angeben - String xPath_Pos = "/node()"; - //XPAth-Präfixe deklarieren - String xPath_Prefix = "data xmlns:data=\"http://uri.data.org\""; - Position pos = new Position(xPath_Pos, xPath_Prefix, 0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc, pos, "signature-1-1"); - cpkcs.setCanoncialization(1); - cpkcs.createReference( - false, - configuration_.getProperty("webbaseDir") + "resources/documents/testSimple.txt", - "reference-1-1"); - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = - makeOutputFile( - doc, - "<data:Document xmlns:data=\"http://uri.data.org\">", - cutXML(readFile(configuration_.getProperty("baseDir") + "resources/documents/testSimple.txt")) - + "</data:Document>"); - - writeFile(resFile, output); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - public void create004() throws Exception - { - - String testNumber = "004"; - - String resFile = - configuration_.getProperty("baseDir") - + datadirectory - + configuration_.getProperty("TestClass") - + "." - + testNumber - + ".Res.xml"; - - InputStream bis = - new ByteArrayInputStream( - ("<data:Document xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" attr=\"document\" xsi:schemaLocation=\"http://uri.data.org http://anywhere.org/testDocument.schema.xsd\">Dies sind Testdaten</data:Document>") - .getBytes()); - - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setValidating(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - - Map m = new HashMap(); - m.put( - "http://anywhere.org/testDocument.schema.xsd", - new ByteArrayInputStream( - ("<xsd:schema targetNamespace=\"http://uri.data.org\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://uri.data.org\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\" id=\"tollesSchema\">" - + "<xsd:element name=\"Document\">" - + "<xsd:complexType mixed=\"true\">" - + "<xsd:sequence maxOccurs=\"unbounded\" minOccurs=\"0\">" - + "<xsd:any namespace=\"##any\" processContents=\"lax\"/>" - + "</xsd:sequence>" - + "<xsd:attribute name=\"attr\" type=\"xsd:ID\" use=\"required\"/>" - + "</xsd:complexType>" - + "</xsd:element></xsd:schema>") - .getBytes())); - - EntityResolverChain chain = new EntityResolverChain(); - chain.addEntityResolver(new StreamEntityResolver(m)); - chain.addEntityResolver(new MOAEntityResolver()); - builder.setEntityResolver(chain); - - //Dokument Parsen - Document reqDoc = - DOMUtils.parseDocument(bis, true, Constants.ALL_SCHEMA_LOCATIONS, null, chain, new MOAErrorHandler()); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - - //Position für die Signatur angeben - String xPath_Pos = "//data:Document"; - - //XPAth-Prefixe deklarieren - String xPath_Prefix = "data http://uri.data.org"; - - Position pos = new Position(xPath_Pos, xPath_Prefix, 0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc, pos, "signature-1-1"); - cpkcs.setCanoncialization(1); - - //Enveloped Transformation - Transform[] tr = new Transform[1]; - TransformImplEnvelopedSignature trans = new TransformImplEnvelopedSignature(); - tr[0] = trans; - cpkcs.createReferenceWithTransforms(new URI("#document"), tr, "reference-1-1"); - - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - - String output = - makeOutputFile( - doc, - "<data:Document xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" attr=\"document\" xsi:schemaLocation=\"http://uri.data.org http://anywhere.org/testDocument.schema.xsd\">", - readFile(configuration_.getProperty("baseDir") + "resources/documents/testSimple.txt") - + "</data:Document>"); - - writeFile(resFile, output); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - public void create005() throws Exception - { - - String testNumber = "005"; - String resFile = - configuration_.getProperty("baseDir") - + datadirectory - + configuration_.getProperty("TestClass") - + "." - + testNumber - + ".Res.xml"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature-1-1"); - cpkcs.setCanoncialization(1); - - Transform[] tr = new Transform[1]; - TransformImplXSLT trans = new TransformImplXSLT(); - URL u = new URL(configuration_.getProperty("webbaseDir") + "resources/stylesheets/ref.book.notavailable.xsl"); - URLConnection hu = u.openConnection(); - - trans.setStyleSheet( - hu.getInputStream(), - new URI(configuration_.getProperty("webbaseDir") + "resources/stylesheets/ref.book.notavailable.xsl")); - tr[0] = trans; - - cpkcs.createReferenceWithTransforms( - new URI(configuration_.getProperty("webbaseDir") + "resources/documents/bookData.xml"), - tr, - "reference-1-1"); - - cpkcs.setKeyInformation(1); - - Document doc = cpkcs.returnSig(); - String output = makeOutputFile(doc); - writeFile(resFile, output); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - public void writeFile(String filename, String data) throws Exception - { - BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); - bw.write(data); - bw.close(); - } - - /* ---------------------------------------------------------------------------------------------------- */ - - private String makeOutputFile(Document signatureDoc) 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 = - "<?xml version=\"1.0\" encoding=\"utf-8\"?>" - + "<CreateXMLSignatureResponse\n" - + " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n" - + " >" - + - //" xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\">\n"+ - "<SignatureEnvironment>" + erg + "</SignatureEnvironment></CreateXMLSignatureResponse>"; - - return erg; - } - - /* ---------------------------------------------------------------------------------------------------- */ - - private String makeOutputFile(Document signatureDoc, Document signatureDoc2) 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); - - foundNodes.clear(); - findNode(signatureDoc2.getDocumentElement(), "dsig:Signature", foundNodes); - - outputNode = null; - - if (foundNodes.size() > 0) - { - outputNode = (Node) foundNodes.get(0); - } - - String erg2 = Node2String(outputNode); - - // remove the <?xml ?> Prologue - pos = erg2.indexOf("<dsig"); - erg2 = erg2.substring(pos); - - // insert the dsig:signature element in a MOA Response Message - erg = - "<?xml version=\"1.0\" encoding=\"utf-8\"?>" - + "<CreateXMLSignatureResponse\n" - + " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"\n" - + " >" - + "<SignatureEnvironment>" - + erg - + "</SignatureEnvironment><SignatureEnvironment>" - + erg2 - + "</SignatureEnvironment> </CreateXMLSignatureResponse>"; - - //erg = replaceString(erg,"Id=\"signature-1-1\"","Id=\"signature-2-1\""); - //erg = replaceString(erg,"Id=\"reference-1-1\"","Id=\"reference-2-1\""); - - return erg; - } - - /* ---------------------------------------------------------------------------------------------------- */ - - public String makeOutputFile(Document signatureDoc, String prefix, String suffix) 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 = - "<?xml version=\"1.0\" encoding=\"utf-8\"?>" - + "<CreateXMLSignatureResponse" - + " xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\"" - + " >" - + - //" xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\">"+ - "<SignatureEnvironment>" - + prefix - + erg - + suffix - + "</SignatureEnvironment> </CreateXMLSignatureResponse>"; - - return erg; - } - -} diff --git a/spss.test/src/testgenerator/TestGeneratorVC0.java b/spss.test/src/testgenerator/TestGeneratorVC0.java deleted file mode 100644 index f54689875..000000000 --- a/spss.test/src/testgenerator/TestGeneratorVC0.java +++ /dev/null @@ -1,1057 +0,0 @@ -package testgenerator; - -import iaik.asn1.ASN1Object; -import iaik.asn1.CodingException; -import iaik.asn1.DerCoder; -import iaik.asn1.ObjectID; -import iaik.asn1.structures.AlgorithmID; -import iaik.asn1.structures.Attribute; -import iaik.asn1.structures.ChoiceOfTime; -import iaik.asn1.structures.Name; -import iaik.cms.CMSException; -import iaik.cms.ContentInfoStream; -import iaik.cms.SignedDataStream; -import iaik.cms.SignerInfo; -import iaik.security.random.SecRandom; -import iaik.utils.StreamCopier; -import iaik.x509.X509Certificate; - -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.PrivateKey; -import java.security.Provider; -import java.security.SecureRandom; -import java.security.Security; -import java.security.SignatureException; - -import sun.misc.BASE64Encoder; - - -/** - * @author Administrator - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class TestGeneratorVC0 extends TestCases { - - String datadirectory = "data/VC0/"; - String datadirectory_l = "data/LVC"; - - public String defaultblock = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ - "<VerifyCMSSignatureRequest xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" Signatories=\"1\">"+ - "<DateTime>2003-04-04T09:30:47-05:00</DateTime>"+ - "<CMSSignature><!-- insert data --></CMSSignature>"+ - "<DataObject>"+ - "<MetaInfo>"+ - "<MimeType>text/plain</MimeType>"+ - "<Description>anyURI</Description>"+ - "</MetaInfo>"+ - "<Content>"+ - "<Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg0KMi4gWmVpbGUNCjMuIFplaWxlDQphdXM=</Base64Content>"+ - "</Content>"+ - "</DataObject>"+ - "<TrustProfileID>TrustProfile1</TrustProfileID>"+ - "</VerifyCMSSignatureRequest>"; - - public String defaultresponse = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ - "<VerifyCMSSignatureResponse xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\" >"+ - "<SignerInfo>"+ - "<dsig:X509Data xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">"+ - "<dsig:X509SubjectName><!-- subn --></dsig:X509SubjectName>"+ - "<dsig:X509IssuerSerial>"+ - "<dsig:X509IssuerName><!-- in --></dsig:X509IssuerName>"+ - "<dsig:X509SerialNumber><!-- sn --></dsig:X509SerialNumber>"+ - "</dsig:X509IssuerSerial>"+ - "<dsig:X509Certificate><!-- cert --></dsig:X509Certificate>"+ - "<!-- cert2 -->"+ - "</dsig:X509Data>"+ - "</SignerInfo>"+ - "<SignatureCheck>"+ - "<Code><!-- sc_code --></Code>"+ - "</SignatureCheck>"+ - "<CertificateCheck>"+ - "<Code><!-- cc_code --></Code>"+ - "</CertificateCheck>"+ - "</VerifyCMSSignatureResponse>"; - - public String defaultresponse2 = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ - "<VerifyCMSSignatureResponse xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\" >"+ - "<SignerInfo>"+ - "<dsig:X509Data xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">"+ - "<dsig:X509SubjectName><!-- subn --></dsig:X509SubjectName>"+ - "<dsig:X509IssuerSerial>"+ - "<dsig:X509IssuerName><!-- in --></dsig:X509IssuerName>"+ - "<dsig:X509SerialNumber><!-- sn --></dsig:X509SerialNumber>"+ - "</dsig:X509IssuerSerial>"+ - "<dsig:X509Certificate><!-- cert --></dsig:X509Certificate>"+ - "</dsig:X509Data>"+ - "</SignerInfo>"+ - "<SignatureCheck>"+ - "<Code><!-- sc_code --></Code>"+ - "</SignatureCheck>"+ - "<CertificateCheck>"+ - "<Code><!-- cc_code --></Code>"+ - "</CertificateCheck>"+ - "<SignerInfo>"+ - "<dsig:X509Data xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">"+ - "<dsig:X509SubjectName><!-- subn --></dsig:X509SubjectName>"+ - "<dsig:X509IssuerSerial>"+ - "<dsig:X509IssuerName><!-- in --></dsig:X509IssuerName>"+ - "<dsig:X509SerialNumber><!-- sn --></dsig:X509SerialNumber>"+ - "</dsig:X509IssuerSerial>"+ - "<dsig:X509Certificate><!-- cert --></dsig:X509Certificate>"+ - "</dsig:X509Data>"+ - "</SignerInfo>"+ - "<SignatureCheck>"+ - "<Code><!-- sc_code --></Code>"+ - "</SignatureCheck>"+ - "<CertificateCheck>"+ - "<Code><!-- cc_code --></Code>"+ - "</CertificateCheck>"+ - "</VerifyCMSSignatureResponse>"; - - /* - <!-- in --> - <!-- sn --> - <!-- subn --> - <!-- sc_code --> - <!-- cc_code --> - */ - - public String b64_der_data = null; - public String b64_der_data_two = null; - public String b64_der_data_exp = null; - public String b64_der_data_exp_two = null; - public String b64_der_data_max = null; - - public String b64_der_data_1kb = null; - public String b64_der_data_10kb = null; - public String b64_der_data_100kb = null; - public String b64_der_data_1mb = null; - public String b64_der_data_10mb = null; - - public String cert_file_data = null; - public String cert_max_file_data = null; - public String cert_root_file_data = null; - - - public String fileprefix = null; - public String filesuffix = null; - - // signing certificate of user 2 - X509Certificate user2_sign; - // signing private key of user 2 - PrivateKey user2_sign_pk; - - // encryption certificate of user 2 - X509Certificate user2_crypt; - // encryption private key of user 2 - PrivateKey user2_crypt_pk; - // a certificate chain containing the user certs + CA - - X509Certificate[] certificates; - // secure random number generator - SecureRandom random; - - public TestGeneratorVC0() throws Exception - { - super(); - // Set config properties - configuration_.setProperty("TestClass", "TestGeneratorVC0"); - - - configuration_.setProperty( - "PKCS12file_maxmustermann", - (configuration_.getProperty("baseDir") + "/resources/Max_Mustermann (max).p12")); - - configuration_.setProperty("PKCS12password_maxmustermann", "max"); - - configuration_.setProperty( - "CERT_maxmustermann", - (configuration_.getProperty("baseDir") + "resources/Max_Mustermann.cer")); - - configuration_.setProperty( - "CERT_ROOT", - (configuration_.getProperty("baseDir") + "resources/IAIKRootMusterbehoerde.cer")); - - Provider [] list = Security.getProviders(); - for(int counter=0;counter<list.length;counter++) - { - System.out.println(list[counter].getName()); - } - - iaik.security.provider.IAIK.addAsProvider(); - iaik.security.ecc.provider.ECCProvider.addAsProvider(); - - X509Certificate[] certs = CMSKeyStore.getCertificateChain(CMSKeyStore.RSA, CMSKeyStore.SZ_1024_SIGN); - user2_sign = CMSKeyStore.getCertificateChain(CMSKeyStore.RSA, CMSKeyStore.SZ_2048_SIGN)[0]; - user2_sign_pk = CMSKeyStore.getPrivateKey(CMSKeyStore.RSA, CMSKeyStore.SZ_2048_SIGN); - certificates = new X509Certificate[certs.length+1]; - System.arraycopy(certs, 0, certificates, 0, certs.length); - certificates[certs.length] = user2_sign; - - // encryption certs - user2_crypt = CMSKeyStore.getCertificateChain(CMSKeyStore.RSA, CMSKeyStore.SZ_2048_CRYPT)[0]; - user2_crypt_pk = CMSKeyStore.getPrivateKey(CMSKeyStore.RSA, CMSKeyStore.SZ_2048_CRYPT); - - random = SecRandom.getDefault(); - - byte[] received_message = null; - ASN1Object obj = null; - - String m = readFile(configuration_.getProperty("baseDir")+"resources/testDaten.txt"); - //String m = "This is a message"; - System.out.println("*"+m+"*"); - byte[] message = m.getBytes(); - - System.out.println("Implicit SignedData demo [create]:"); - obj = createSignedCMSData(message, SignedDataStream.IMPLICIT,false); - byte[] sig = DerCoder.encode(obj); - writeFileBinary("testimpl.ber",sig); - b64_der_data = (new BASE64Encoder()).encode(sig); - - obj = createSignedCMSData(message, SignedDataStream.IMPLICIT,true); - sig = DerCoder.encode(obj); - writeFileBinary("testimpl2.ber",sig); - b64_der_data_two = (new BASE64Encoder()).encode(sig); - - obj = createSignedCMSData(message, SignedDataStream.EXPLICIT,false); - sig = DerCoder.encode(obj); - writeFileBinary("testexp.ber",sig); - b64_der_data_exp = (new BASE64Encoder()).encode(sig); - - String output = getSignedDataStream(sig,message,false); - System.out.println("Output:"+output); - - obj = createSignedCMSData(message, SignedDataStream.EXPLICIT,true); - sig = DerCoder.encode(obj); - writeFileBinary("testexp2.ber",sig); - b64_der_data_exp_two = (new BASE64Encoder()).encode(sig); - - cert_file_data = readBinaryFileAsBase64_new(configuration_.getProperty("CERT")); - cert_max_file_data = readBinaryFileAsBase64_new(configuration_.getProperty("CERT_maxmustermann")); - cert_root_file_data = readBinaryFileAsBase64_new(configuration_.getProperty("CERT_ROOT")); - - // transmit data - /*System.out.println("Implicit SignedData demo [parse]:"); - received_message = getSignedData(obj, null,true); - System.out.print("Signed content: "); - System.out.println(new String(received_message));*/ - - //readBinaryFileAsBase64(configuration_.getProperty("baseDir")+"resources/testDaten.txt"); - } - - public String getCMSData(String filename) throws Exception - { - ASN1Object obj = null; - obj = createSignedCMSData(readFile(configuration_.getProperty("baseDir") + "resources/"+filename+".txt").getBytes(), SignedDataStream.EXPLICIT,true); - byte[] sig = DerCoder.encode(obj); - //writeFileBinary("testexp2.ber",sig); - return (new BASE64Encoder()).encode(sig); - } - - public String getSignedDataStream(byte[] signedData, byte[] message,boolean two_users) throws CMSException, IOException { - - // we are testing the stream interface - ByteArrayInputStream is = new ByteArrayInputStream(signedData); - // create the ContentInfo object - ContentInfoStream cis = new ContentInfoStream(is); - System.out.println("This ContentInfo holds content of type " + cis.getContentType().getName()); - SignedDataStream signed_data = null; - - if (message == null) { - // implicitly signed; get the content - signed_data = (SignedDataStream)cis.getContent(); - } - else { - // explicitly signed; set the data stream for digesting the message - AlgorithmID[] algIDs = { AlgorithmID.sha1, AlgorithmID.md5 }; - signed_data = new SignedDataStream(new ByteArrayInputStream(message), algIDs); - - } - - // get an InputStream for reading the signed content - InputStream data = signed_data.getInputStream(); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - StreamCopier sc = new StreamCopier(data, os); - sc.copyStream(); - - - if (message != null) { - // if explicitly signed read now the DER encoded object - // an explicit S/MIME signed message also consits of message|signature - signed_data.decode(cis.getContentInputStream()); - } - - System.out.println("SignedData contains the following signer information:"); - SignerInfo[] signer_infos = signed_data.getSignerInfos(); - - for (int i=0; i<signer_infos.length; i++) { - try { - // verify the signed data using the SignerInfo at index i - X509Certificate signer_cert = signed_data.verify(i); - // if the signature is OK the certificate of the signer is returned - System.out.println("Signature OK from signer: "+signer_cert.getSubjectDN()); - Attribute signingTime = signer_infos[i].getSignedAttribute(ObjectID.signingTime); - if (signingTime != null) { - ChoiceOfTime cot = new ChoiceOfTime(signingTime.getValue()[0]); - System.out.println("This message has been signed at " + cot.getDate()); - } - Attribute contentType = signer_infos[i].getSignedAttribute(ObjectID.contentType); - if (contentType != null) { - System.out.println("The content has CMS content type " + contentType.getValue()[0]); - } - - } catch (SignatureException ex) { - // if the signature is not OK a SignatureException is thrown - System.out.println("Signature ERROR from signer: "+signed_data.getCertificate((signer_infos[i].getSignerIdentifier())).getSubjectDN()); - } catch (CodingException ex) { - System.out.println("Attribute decoding error: " + ex.getMessage()); - } - } - // now check alternative signature verification - System.out.println("Now check the signature assuming that no certs have been included:"); - try { - SignerInfo signer_info = signed_data.verify(user1_sign); - // if the signature is OK the certificate of the signer is returned - System.out.println("Signature OK from signer: "+signed_data.getCertificate(signer_info.getSignerIdentifier()).getSubjectDN()); - - } catch (SignatureException ex) { - // if the signature is not OK a SignatureException is thrown - System.out.println("Signature ERROR from signer: "+user1_sign.getSubjectDN()); - } - - if(two_users) - try { - SignerInfo signer_info = signed_data.verify(user2_sign); - // if the signature is OK the certificate of the signer is returned - System.out.println("Signature OK from signer: "+signed_data.getCertificate(signer_info.getSignerIdentifier()).getSubjectDN()); - - } catch (SignatureException ex) { - // if the signature is not OK a SignatureException is thrown - System.out.println("Signature ERROR from signer: "+user2_sign.getSubjectDN()); - } - - - return os.toString(); - } - - public void createConfig() throws Exception { - - String file = configuration_.getProperty("baseDir") + datadirectory + - configuration_.getProperty("TestClass") + - ".Config.xml"; - String config = - - "<MOAConfiguration xmlns=\"http://reference.e-government.gv.at/namespace/moaconfig/20021122#\">"+ - " <KeyGroup id=\"PKCS12RSAKey1\"> <Key id=\"resources/test-ee2003_normal(buergerkarte).p12\"/> </KeyGroup>"+ - " <KeyGroup id=\"PKCS12RSAKeyExpired\"> <Key id=\"sicher-demo(buergerkarte).p12\"/> </KeyGroup>"+ - " <KeyGroup id=\"PKCS12ECDSAKey1\"> <Key id=\"ecc.p12\"/> </KeyGroup> "+ - " <KeyGroup id=\"HSMRSAKey1\"> <Key id=\"???\"/> </KeyGroup>"+ - " <KeyGroup id=\"HSMECDSAKey1\"> <Key id=\"???\"/> </KeyGroup>"+ - " <DigestMethodAlgorithm name=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>"+ - " <SignatureAlgorithm name=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>"+ - " <CanonicalizationAlgorithm name=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/>"+ - " <CreateSignatureEnvironmentProfile id=\"CreateSignatureEnvironmentProfile1\" filename=\""+"file:/"+configuration_.getProperty("baseDir")+"resources/csep.xml\"/>"+ - " <TrustProfile id=\"validTrustProfileID1\" uri=\""+"file:/"+configuration_.getProperty("baseDir")+"TrustProfile1/\"/>"+ - "</MOAConfiguration>"; - - FileOutputStream fos = new FileOutputStream(file); - fos.write(config.getBytes()); - fos.flush(); - fos.close(); - - fileprefix = configuration_.getProperty("baseDir")+ datadirectory + configuration_.getProperty("TestClass") + "."; - filesuffix = ".xml"; - - } - - public static void main(String[] args) throws Exception { - TestGeneratorVC0 testcase = new TestGeneratorVC0(); - - testcase.createConfig(); - testcase.create001(); - testcase.create002(); - testcase.create003(); - testcase.create004(); - testcase.create005(); - testcase.create006(); - testcase.create007(); - testcase.create008(); - testcase.create009(); - testcase.create010(); - //testcase.create011(); - testcase.create012(); - - testcase.create051(); - testcase.create052(); - //testcase.create053(); - testcase.create054(); - testcase.create055(); - testcase.create056(); - testcase.create057(); - testcase.create058(); - - //testcase.createL00(); - - } - - public void createL00() throws Exception { - createL001("1kb"); - createL001("10kb"); - createL001("20kb"); - createL001("50kb"); - createL001("100kb"); - createL001("500kb"); - createL001("1mb"); - createL001("10mb"); - } - - public void createL001(String filename) throws Exception - { - String TestNumber = "001"; - - String reqFile = configuration_.getProperty("baseDir")+ datadirectory_l+filename+"/" + configuration_.getProperty("TestClass") + "." + TestNumber + ".Req.xml"; - - String req = replaceString(defaultblock,"<!-- insert data -->",getCMSData(filename)); - req = replaceString(req,"<Content>","<Content Reference=\"anyURI\">"); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/"+filename+".txt"); - req = replaceString(req, - "<Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg0KMi4gWmVpbGUNCjMuIFplaWxlDQphdXM=</Base64Content>", - ""); - - writeFile(reqFile,req); - - String resFile = configuration_.getProperty("baseDir")+ datadirectory_l+filename+"/" + configuration_.getProperty("TestClass") + "." + TestNumber + ".Res.xml"; - - String res = replaceString(defaultresponse,"<!-- in -->",this.X509name); - res = replaceString(res,"<!-- sn -->",this.X509number.toString()); - res = replaceString(res,"<!-- subn -->",this.X509sub); - res = replaceString(res,"<!-- sc_code -->","0"); - res = replaceString(res,"<!-- cc_code -->","0"); - res = replaceString(res,"<!-- cert -->",cert_file_data); - res = replaceString(res,"<!-- cert2 -->",""); - //res = replaceString(res,"<dsig:X509Certificate><!-- cert --></dsig:X509Certificate>",""); - - - writeFile(resFile,res); - - - } - - public void create001() throws Exception - { - String TestNumber = "001"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - /*CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,"file:/"+configuration_.getProperty("baseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc,"<data:Document xmlns:data=\"uri.data.org\">",readFile(configuration_.getProperty("baseDir")+"resources/testDaten.txt")+"</data:Document>"); - - writeFile(resFile, output);*/ - - String res = replaceString(defaultresponse,"<!-- in -->",this.X509name); - res = replaceString(res,"<!-- sn -->",this.X509number.toString()); - res = replaceString(res,"<!-- subn -->",this.X509sub); - res = replaceString(res,"<!-- sc_code -->","0"); - res = replaceString(res,"<!-- cc_code -->","0"); - res = replaceString(res,"<!-- cert -->",cert_file_data); - res = replaceString(res,"<!-- cert2 -->",""); - //res = replaceString(res,"<dsig:X509Certificate><!-- cert --></dsig:X509Certificate>",""); - - - writeFile(resFile,res); - - - } - - public void create002() throws Exception - { - String TestNumber = "002"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp_two); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "Signatories=\"1\"", - "Signatories=\"1 2\""); - - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - String res = replaceStringAll(defaultresponse2,"<!-- in -->",this.X509name); - res = replaceStringAll(res,"<!-- sn -->",this.X509number.toString()); - res = replaceStringAll(res,"<!-- subn -->",this.X509sub); - res = replaceStringAll(res,"<!-- sc_code -->","0"); - res = replaceStringAll(res,"<!-- cc_code -->","0"); - res = replaceStringAll(res,"<!-- cert -->",cert_file_data); - //res = replaceString(res,"<!-- cert2 -->",""); - writeFile(resFile,res); - } - - public void create003() throws Exception - { - String TestNumber = "003"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "Signatories=\"1\"", - "Signatories=\"all\""); - - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - String res = replaceString(defaultresponse,"<!-- in -->",this.X509name); - res = replaceString(res,"<!-- sn -->",this.X509number.toString()); - res = replaceString(res,"<!-- subn -->",this.X509sub); - res = replaceString(res,"<!-- sc_code -->","0"); - res = replaceString(res,"<!-- cc_code -->","0"); - res = replaceString(res,"<!-- cert -->",cert_file_data); - res = replaceString(res,"<!-- cert2 -->",""); - writeFile(resFile,res); - } - - public void create004() throws Exception - { - String TestNumber = "004"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "<DateTime>2003-04-04T09:30:47-05:00</DateTime>", - ""); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - String res = replaceString(defaultresponse,"<!-- in -->",this.X509name); - res = replaceString(res,"<!-- sn -->",this.X509number.toString()); - res = replaceString(res,"<!-- subn -->",this.X509sub); - res = replaceString(res,"<!-- sc_code -->","0"); - res = replaceString(res,"<!-- cc_code -->","0"); - res = replaceString(res,"<!-- cert -->",cert_file_data); - res = replaceString(res,"<!-- cert2 -->",""); - writeFile(resFile,res); - } - - public void create005() throws Exception - { - String TestNumber = "005"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "<DateTime>2003-04-04T09:30:47-05:00</DateTime>", - "<DateTime>2003-04-04T09:30:47-05:00</DateTime>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - String res = replaceString(defaultresponse,"<!-- in -->",this.X509name); - res = replaceString(res,"<!-- sn -->",this.X509number.toString()); - res = replaceString(res,"<!-- subn -->",this.X509sub); - res = replaceString(res,"<!-- sc_code -->","0"); - res = replaceString(res,"<!-- cc_code -->","0"); - res = replaceString(res,"<!-- cert -->",cert_file_data); - res = replaceString(res,"<!-- cert2 -->",""); - writeFile(resFile,res); - } - - public void create006() throws Exception - { - String TestNumber = "006"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "<DataObject>"+ - "<MetaInfo>"+ - "<MimeType>text/plain</MimeType>"+ - "<Description>"+configuration_.getProperty("webbaseDir") + "resources/testDaten.txt</Description>"+ - "</MetaInfo>"+ - "<Content>"+ - "<Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg0KMi4gWmVpbGUNCjMuIFplaWxlDQphdXM=</Base64Content>"+ - "</Content>"+ - "</DataObject>", - ""); - - //req = replaceString(defaultblock, - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - String res = replaceString(defaultresponse,"<!-- in -->",this.X509name); - res = replaceString(res,"<!-- sn -->",this.X509number.toString()); - res = replaceString(res,"<!-- subn -->",this.X509sub); - res = replaceString(res,"<!-- sc_code -->","0"); - res = replaceString(res,"<!-- cc_code -->","0"); - res = replaceString(res,"<!-- cert -->",cert_file_data); - res = replaceString(res,"<!-- cert2 -->",""); - writeFile(resFile,res); - } - - public void create007() throws Exception - { - String TestNumber = "007"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "<MetaInfo>"+ - "<MimeType>text/plain</MimeType>"+ - "<Description>"+configuration_.getProperty("webbaseDir") + "resources/testDaten.txt</Description>"+ - "</MetaInfo>", - ""); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - String res = replaceString(defaultresponse,"<!-- in -->",this.X509name); - res = replaceString(res,"<!-- sn -->",this.X509number.toString()); - res = replaceString(res,"<!-- subn -->",this.X509sub); - res = replaceString(res,"<!-- sc_code -->","0"); - res = replaceString(res,"<!-- cc_code -->","0"); - res = replaceString(res,"<!-- cert -->",cert_file_data); - res = replaceString(res,"<!-- cert2 -->",""); - writeFile(resFile,res); - } - - public void create008() throws Exception - { - String TestNumber = "008"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - String res = replaceString(defaultresponse,"<!-- in -->",this.X509name); - res = replaceString(res,"<!-- sn -->",this.X509number.toString()); - res = replaceString(res,"<!-- subn -->",this.X509sub); - res = replaceString(res,"<!-- sc_code -->","0"); - res = replaceString(res,"<!-- cc_code -->","0"); - res = replaceString(res,"<!-- cert -->",cert_file_data); - res = replaceString(res,"<!-- cert2 -->",""); - writeFile(resFile,res); - } - - public void create009() throws Exception - { - String TestNumber = "009"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceString(req,"<Content>","<Content Reference=\"anyURI\">"); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "<Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg0KMi4gWmVpbGUNCjMuIFplaWxlDQphdXM=</Base64Content>", - ""); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - String res = replaceString(defaultresponse,"<!-- in -->",this.X509name); - res = replaceString(res,"<!-- sn -->",this.X509number.toString()); - res = replaceString(res,"<!-- subn -->",this.X509sub); - res = replaceString(res,"<!-- sc_code -->","0"); - res = replaceString(res,"<!-- cc_code -->","0"); - res = replaceString(res,"<!-- cert -->",cert_file_data); - res = replaceString(res,"<!-- cert2 -->",""); - writeFile(resFile,res); - } - - public void create011() throws Exception - { - String TestNumber = "011"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",readFile(configuration_.getProperty("baseDir") + "resources/VC0.011.cms.ber.b64.txt")); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "<DataObject>"+ - "<MetaInfo>"+ - "<MimeType>text/plain</MimeType>"+ - "<Description>"+configuration_.getProperty("webbaseDir") + "resources/testDaten.txt</Description>"+ - "</MetaInfo>"+ - "<Content>"+ - "<Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg0KMi4gWmVpbGUNCjMuIFplaWxlDQphdXM=</Base64Content>"+ - "</Content>"+ - "</DataObject>", - ""); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - String res = replaceString(defaultresponse,"<!-- in -->","CN=a-sign-TEST-Premium-Enc-01,OU=a-sign-TEST-Premium-Enc-01,O=A-Trust Ges. f. Sicherheitssysteme im elektr. Datenverkehr GmbH,C=AT"); - res = replaceString(res,"<!-- sn -->","6455"); - res = replaceString(res,"<!-- subn -->","Seriennummer=790187461633,G=Testperson MOA4,SN=BRZ,CN=Testperson MOA4 BRZ,C=AT"); - res = replaceString(res,"<!-- sc_code -->","0"); - res = replaceString(res,"<!-- cc_code -->","0"); - res = replaceString(res,"<!-- cert -->",cert_file_data); - res = replaceString(res,"<!-- cert2 -->",""); - res = replaceString(res, - "</dsig:X509Data>", - "<sl11:QualifiedCertificate xmlns:sl11=\"http://www.buergerkarte.at/namespaces/securitylayer/20020831#\"/>"+ - "</dsig:X509Data>"); - - - writeFile(resFile,res); - } - - public void create012() throws Exception - { - String TestNumber = "012"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - BufferedInputStream bis = new BufferedInputStream(new FileInputStream(configuration_.getProperty("CERT_maxmustermann"))); - iaik.x509.X509Certificate cert = new iaik.x509.X509Certificate(bis); - X509name = ((Name)(cert.getIssuerDN())).getRFC2253String(); - X509number = cert.getSerialNumber(); - X509hash = new String(cert.getFingerprintSHA()); - X509sub = ((Name)(cert.getSubjectDN())).getRFC2253String(); - - String m = "This is a message"; - System.out.println("*"+m+"*"); - byte[] message = m.getBytes(); - - ASN1Object obj = null; - obj = createSignedCMSData(message, SignedDataStream.IMPLICIT,false,"PKCS12file_maxmustermann","PKCS12password_maxmustermann","CERT_maxmustermann"); - byte[] sig = DerCoder.encode(obj); - writeFileBinary("testimplmax.ber",sig); - b64_der_data_max = (new BASE64Encoder()).encode(sig); - - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_max); - - req = replaceString(req, - "<DataObject>"+ - "<MetaInfo>"+ - "<MimeType>text/plain</MimeType>"+ - "<Description>anyURI</Description>"+ - "</MetaInfo>"+ - "<Content>"+ - "<Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg0KMi4gWmVpbGUNCjMuIFplaWxlDQphdXM=</Base64Content>"+ - "</Content>"+ - "</DataObject>", - ""); - - //req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - /*CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,"file:/"+configuration_.getProperty("baseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - - Document doc = cpkcs.returnSig(); - - String output = makeOutputFile(doc,"<data:Document xmlns:data=\"uri.data.org\">",readFile(configuration_.getProperty("baseDir")+"resources/testDaten.txt")+"</data:Document>"); - - writeFile(resFile, output);*/ - - - String res = replaceString(defaultresponse,"<!-- in -->",X509name); - res = replaceString(res,"<!-- sn -->",X509number.toString()); - res = replaceString(res,"<!-- subn -->",X509sub); - res = replaceString(res,"<!-- sc_code -->","0"); - res = replaceString(res,"<!-- cc_code -->","0"); - res = replaceString(res,"<!-- cert -->",cert_max_file_data); - res = replaceString(res,"<!-- cert2 -->",""); - res = replaceString(res, - "</dsig:X509Data>", - "<PublicAuthority>"+ - "<Code>Musterbehörde</Code>"+ - //"<Code>Musterbehörde</Code>"+ - "</PublicAuthority>"+ - "</dsig:X509Data>"); - - - writeFile(resFile,res); - - - } - - public void create051() throws Exception - { - String TestNumber = "051"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "Signatories=\"1\"", - "Signatories=\"0\""); - - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"1100"); - } - - public void create052() throws Exception - { - String TestNumber = "052"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "Signatories=\"1\"", - "Signatories=\"10\""); - - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2249"); - } - - public void create053() throws Exception - { - String TestNumber = "053"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "<DateTime>2003-04-04T09:30:47-05:00</DateTime>", - "<DateTime>"+getDate(1*34*24)+"</DateTime>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"0000"); - } - - public void create054() throws Exception - { - String TestNumber = "054"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock, - "<CMSSignature><!-- insert data --></CMSSignature>", - "<CMSSignature>this is no Base64 Data</CMSSignature>"); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"1100"); - - } - - public void create055() throws Exception - { - String TestNumber = "055"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "<DataObject>"+ - "<MetaInfo>"+ - "<MimeType>text/plain</MimeType>"+ - "<Description>"+configuration_.getProperty("webbaseDir") + "resources/testDaten.txt</Description>"+ - "</MetaInfo>"+ - "<Content>"+ - "<Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg0KMi4gWmVpbGUNCjMuIFplaWxlDQphdXM=</Base64Content>"+ - "</Content>"+ - "</DataObject>", - ""); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2248"); - - } - - - - public void create010() throws Exception - { - String TestNumber = "010"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceString(req,"<Content>","<Content Reference=\"anyURI\">"); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "<Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg0KMi4gWmVpbGUNCjMuIFplaWxlDQphdXM=</Base64Content>", - ""); - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".Res"+filesuffix; - - String res = replaceString(defaultresponse,"<!-- in -->",this.X509name); - res = replaceString(res,"<!-- sn -->",this.X509number.toString()); - res = replaceString(res,"<!-- subn -->",this.X509sub); - res = replaceString(res,"<!-- sc_code -->","0"); - res = replaceString(res,"<!-- cc_code -->","0"); - res = replaceString(res,"<!-- cert -->",cert_file_data); - res = replaceString(res,"<!-- cert2 -->",""); - - writeFile(resFile,res); - - } - - public void create056() throws Exception - { - String TestNumber = "056"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - req = replaceString(req, - "<TrustProfileID>TrustProfile1</TrustProfileID>", - "<TrustProfileID>notvalidTrustProfileID</TrustProfileID>"); - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2203"); - - } - - - public void create057() throws Exception - { - String TestNumber = "057"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - - configuration_.setProperty( - "PKCS12file_maxmustermann", - (configuration_.getProperty("baseDir") + "/resources/Max_Mustermann (max).p12")); - - configuration_.setProperty("PKCS12password_maxmustermann", "max"); - - configuration_.setProperty( - "CERT_maxmustermann", - (configuration_.getProperty("baseDir") + "resources/Max_Mustermann.cer")); - - BufferedInputStream bis = new BufferedInputStream(new FileInputStream(configuration_.getProperty("CERT_maxmustermann"))); - iaik.x509.X509Certificate cert = new iaik.x509.X509Certificate(bis); - X509name = ((Name)(cert.getIssuerDN())).getRFC2253String(); - X509number = cert.getSerialNumber(); - X509hash = new String(cert.getFingerprintSHA()); - X509sub = ((Name)(cert.getSubjectDN())).getRFC2253String(); - - String m = "This is a message"; - System.out.println("*"+m+"*"); - byte[] message = m.getBytes(); - - ASN1Object obj = null; - obj = createSignedCMSData(message, SignedDataStream.IMPLICIT,false,"PKCS12file_maxmustermann","PKCS12password_maxmustermann","CERT_maxmustermann"); - byte[] sig = DerCoder.encode(obj); - writeFileBinary("testimplmax.ber",sig); - b64_der_data_max = (new BASE64Encoder()).encode(sig); - - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_max); - - /*req = replaceString(req, - " <DataObject>"+ - " <MetaInfo>"+ - " <MimeType>text/plain</MimeType>"+ - " <Description>anyURI</Description>"+ - " </MetaInfo>"+ - " <Content Reference=\"anyURI\">"+ - " <Base64Content>RGllcyBzaW5kIFRlc3RkYXRlbg0KMi4gWmVpbGUNCjMuIFplaWxlDQphdXM=</Base64Content>"+ - " </Content>"+ - " </DataObject>", - "");*/ - - //req = replaceString(req,"Reference=\"anyURI\"",""); - - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - - - - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"2248"); - - - } - - public void create058() throws Exception - { - String TestNumber = "058"; - String reqFile = fileprefix + TestNumber + ".Req"+filesuffix; - - String req = replaceString(defaultblock,"<!-- insert data -->",b64_der_data_exp); - req = replaceStringAll(req,"anyURI",configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - - req = replaceString(req,"RGllcyBzaW5kIFRlc3RkYXRlbg0KMi4gWmVpbGUNCjMuIFplaWxlDQphdXM=","RGllcyBzaW5kIFRlc3RkYXRlbg0KMi4gWmVpbGUNCjMuIFplaWxlDQphdXM=()"); - writeFile(reqFile,req); - - String resFile = fileprefix + TestNumber + ".ErrRes"+filesuffix; - - writeFile(resFile,"1100"); - - } - - - - - - - -} diff --git a/spss.test/src/testgenerator/TestGeneratorVX.java b/spss.test/src/testgenerator/TestGeneratorVX.java deleted file mode 100644 index 20ff44a22..000000000 --- a/spss.test/src/testgenerator/TestGeneratorVX.java +++ /dev/null @@ -1,2793 +0,0 @@ -package testgenerator; -import iaik.ixsil.algorithms.Transform; -import iaik.ixsil.algorithms.TransformImplBase64Decode; -import iaik.ixsil.algorithms.TransformImplCanonicalXML; -import iaik.ixsil.algorithms.TransformImplCanonicalXMLWithComments; -import iaik.ixsil.algorithms.TransformImplEnvelopedSignature; -import iaik.ixsil.algorithms.TransformImplExclusiveCanonicalXML; -import iaik.ixsil.algorithms.TransformImplExclusiveCanonicalXMLWithComments; -import iaik.ixsil.algorithms.TransformImplXPath; -import iaik.ixsil.algorithms.TransformImplXPath2; -import iaik.ixsil.algorithms.TransformImplXSLT; -import iaik.ixsil.core.Position; -import iaik.ixsil.util.URI; - -import java.io.ByteArrayInputStream; -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 java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.apache.xml.serialize.DOMWriterImpl; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -import at.gv.egovernment.moa.util.Base64Utils; -import at.gv.egovernment.moa.util.Constants; -import at.gv.egovernment.moa.util.DOMUtils; -import at.gv.egovernment.moa.util.EntityResolverChain; -import at.gv.egovernment.moa.util.MOAEntityResolver; -import at.gv.egovernment.moa.util.MOAErrorHandler; -import at.gv.egovernment.moa.util.StreamEntityResolver; - -/** - * @author stephan - */ -public class TestGeneratorVX 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; - - public static void main(String[] args) throws Exception { - - vxBean = new VXResponseBean(); - - TestGeneratorVX testcase = new TestGeneratorVX(); - testcase.createVXConfig(); - - testcase.create001(); - testcase.create002(); - testcase.create003(); - testcase.create004(); - testcase.create005(); - testcase.create006(); - testcase.create007(); - testcase.create009(); - testcase.create008(); - - testcase.create101(); - testcase.create102(); - testcase.create103(); - testcase.create104(); - testcase.create105(); - testcase.create106(); - - testcase.create301(); - testcase.create302(); - testcase.create303(); - testcase.create304(); - testcase.create305(); - - testcase.create307(); - testcase.create308(); - - testcase.create310(); - testcase.create311(); - testcase.create312(); - testcase.create313(); - testcase.create314(); - testcase.create314_2(); - testcase.create315(); - testcase.create316(); - testcase.create317(); - testcase.create318(); - testcase.create318_2(); - testcase.create319(); - testcase.create320(); - testcase.create320_2(); - testcase.create321(); - testcase.create322(); - testcase.create323(); - testcase.create324(); - testcase.create325(); - testcase.create326(); - testcase.create327(); - - //testcase.createL00(); - - } - - /* ==================================================================================================== */ - - public TestGeneratorVX() 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(); - } - - /* ==================================================================================================== */ - - public void testEcc() throws Exception - { - Date d = new Date(); - long start = d.getTime(); - long initEcc = 0; - long timeEcc = 0; - long initRSA = 0; - long timeRSA = 0; - - - TestGeneratorVX testcase = new TestGeneratorVX(); - testcase.ecccreate319(); - initEcc = (new Date()).getTime() - start; - testcase.ecccreate320(); - testcase.ecccreate321(); - testcase.ecccreate322(); - testcase.ecccreate323(); - testcase.ecccreate324(); - - timeEcc = (new Date()).getTime() - start; - - start = (new Date()).getTime(); - - testcase = new TestGeneratorVX(); - testcase.create319(); - initRSA = (new Date()).getTime() - start; - testcase.create320(); - testcase.create321(); - testcase.create322(); - testcase.create323(); - testcase.create324(); - timeRSA =(new Date()).getTime() - start; - - System.out.println("========================================================="); - System.out.println("========================================================="); - - System.out.println("Init ECC (inkl. 1st Test): "+ (initEcc)+ "ms" ); - System.out.println("ECC-Tests gesamt: "+ (timeEcc)+ "ms" ); - System.out.println("ECC-Tests 2-5: "+ (timeEcc-initEcc)+ "ms" ); - System.out.println("========================================================="); - System.out.println("Init RSA (inkl. 1st Test): "+ (initRSA)+ "ms" ); - System.out.println("RSA-Tests gesamt: "+ (timeRSA)+ "ms" ); - System.out.println("RSA-Tests 2-5: "+ (timeRSA-initRSA)+ "ms" ); - System.out.println("========================================================="); - } - -public void ecccreate319() throws Exception { - String testNumber = "ecc319"; - - - // Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); // Create from whole cloth -// - // Element root = (Element) document.createElement("Data"); - // root.appendChild(document.createTextNode(readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")) ); -// Element root2 = (Element) document.createElement("Element2"); - // root2.appendChild(document.createTextNode("Some other text") ); - - // root.appendChild(root2); - - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //cpkcs.init(); - long start = (new Date()).getTime(); - cpkcs.initECDSA(); - System.out.println("Init-Dauer für " +testNumber + ":" + ((new Date()).getTime()-start)); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(true,"Dies sind Testdaten"); - //cpkcs.createReferenceEnvElement(root); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - start = (new Date()).getTime(); - Document sign = cpkcs.returnSig(); - System.out.println("Sign-Dauer für " +testNumber + ":" + ((new Date()).getTime()-start)); - - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0")); - } - - /** - * Method create320: - * The element KeyInfo does NOT contain the X509-certificate but - * an URI pointing to an external xml-encoded X509-file - * @throws Exception - */ - public void ecccreate320() throws Exception { - String testNumber = "ecc320"; - - //RetrievalMethdos instead of the integratede Keys - - //URI fileURI = new URI(configuration_.getProperty("baseDir") + "resources/test-ee2003_normal.der"); - URI fileURI = new URI("file:/"+configuration_.getProperty("baseDir") + "resources/X509Data.xml"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#X509Data"); - //URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#rawX509Certificate"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); -// cpkcs.init(); - - cpkcs.initECDSA(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - - long start = (new Date()).getTime(); - Document sign = cpkcs.returnSig(); - System.out.println("Sign-Dauer für " +testNumber + ":" + ((new Date()).getTime()-start)); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0")); - } - - - public void ecccreate321() throws Exception { - String testNumber = "ecc321"; - - //RetrievalMethdos instead of the integratede Keys - - URI fileURI = new URI("file:/"+configuration_.getProperty("baseDir") + "resources/test-ee2003_normal.der"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#rawX509Certificate"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - // cpkcs.init(); - cpkcs.initECDSA(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - - long start = (new Date()).getTime(); - Document sign = cpkcs.returnSig(); - System.out.println("Sign-Dauer für " +testNumber + ":" + ((new Date()).getTime()-start)); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0")); - } - - - /** - * Method create322. - * The reference in the signature points with an xpointer - * to the ID of an embedded valid manifest dsig:object - * @throws Exception - */ - public void ecccreate322() throws Exception { - String testNumber = "ecc322"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - // cpkcs.init(); - cpkcs.initECDSA(); - cpkcs.setCanoncialization(canAlgCanXML); - URI fileURI1 = new URI(configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.createReferenceWithManifest(fileURI1,"manifestObject"); - - cpkcs.setKeyInformation(); - long start = (new Date()).getTime(); - Document sign = cpkcs.returnSig(); - System.out.println("Sign-Dauer für " +testNumber + ":" + ((new Date()).getTime()-start)); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - - } - /** - * Method create323: - * There are two references in the signature pointing - * with xpointer to two embedded valid manifest dsig:objects - * @throws Exception - */ - public void ecccreate323() throws Exception { - String testNumber = "ecc323"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - // cpkcs.init(); - cpkcs.initECDSA(); - cpkcs.setCanoncialization(canAlgCanXML); - URI fileURI1 = new URI(configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - URI fileURI2 = new URI(configuration_.getProperty("webbaseDir") + "resources/testXML.txt"); - cpkcs.createReferenceWithManifest(fileURI1,"manifestObject"); - - //HINWEIS: Durch das 2malige Aufrufen wird ein WEITERES dsig:Object ELEMENT erzeugt... darf das so sein...??? - - cpkcs.createReferenceWithManifest(fileURI2,"manifestObject2"); - cpkcs.setKeyInformation(); - long start = (new Date()).getTime(); - Document sign = cpkcs.returnSig(); - System.out.println("Sign-Dauer für " +testNumber + ":" + ((new Date()).getTime()-start)); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - - } - public void ecccreate324() throws Exception { - String testNumber = "ecc324"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - // cpkcs.init(); - cpkcs.initECDSA(); - cpkcs.setCanoncialization(canAlgCanXML); - URI fileURI1 = new URI(configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - URI fileURI2 = new URI(configuration_.getProperty("webbaseDir") + "resources/testXML.txt"); - cpkcs.createReferencesWithManifest(fileURI1,"manifestObject",fileURI2); - - //HINWEIS: Durch das 2malige Aufrufen wird ein WEITERES dsig:Object ELEMENT erzeugt... darf das so sein...??? - cpkcs.setKeyInformation(); - long start = (new Date()).getTime(); - Document sign = cpkcs.returnSig(); - System.out.println("Sign-Dauer für " +testNumber + ":" + ((new Date()).getTime()-start)); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - - } - - public void createL00() throws Exception { - createL001("1kb"); - createL001("10kb"); - createL001("20kb"); - createL001("50kb"); - createL001("100kb"); - createL001("500kb"); - createL001("1mb"); - createL001("10mb"); - } - - public void createL001(String filename) throws Exception { - - String testNumber = "001"; - - //Create a Request with number 001, the current Time (+0 hours) - // and with the Date and ReturnHashInputDate Elements present - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/"+filename+".txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(false,false,null)); - - writeFile(vxReqFileL(testNumber,filename),request); - - - - writeFile(vxResFileL(testNumber,filename), createResponseL(cpkcs.getX509CertString(), testNumber,"0",filename)); - } - - /** - * Method create001. - * @throws Exception - */ - /* ===================================================================================================================== */ - /* ===================================================================================================================== */ - /* ===================================================================================================================== */ - - public void create001() throws Exception { - - String testNumber = "001"; - - //Create a Request with number 001, the current Time (+0 hours) - // and with the Date and ReturnHashInputDate Elements present - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0")); - } - - /** - * Method create002. - * @throws Exception - */ - public void create002() throws Exception { - String testNumber = "002"; - //Create a Request with number 002, the current Time (+0 hours) - // and without the Date and with ReturnHashInputDate Elements present - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,false,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0")); - } - - /** - * Method create003. - * @throws Exception - */ - public void create003() throws Exception { - String testNumber = "003"; - //Create a Request with number 003, the Time one Day in the past (-24 hours) - // and with the Date and with ReturnHashInputDate Elements present - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,-24), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0")); - } - - /** - * Method create004. - * @throws Exception - */ - public void create004() throws Exception { - String testNumber = "004"; - //Create a Request with number 004, the current Time (+0 hours) - // and with the Date and without ReturnHashInputDate Elements present - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(false,false,null)); - - writeFile(vxReqFile(testNumber),request); - - - writeFile(vxResFile(testNumber), createResponseWithoutHashInputData(cpkcs.getX509CertString(), testNumber,"0")); - } - public void create005() throws Exception { - String testNumber = "005"; - - String request = - createRequestStart(testNumber,true,0, "Reference=\"" + configuration_.getProperty("webbaseDir") + "resources/SignatureVX005.xml\" ")+ - createRequestEnd(false,false,null); - - request = replaceString(request,"<XMLContent xml:space=\"preserve\">",""); - request = replaceString(request,"</XMLContent>",""); - writeFile(vxReqFile(testNumber),request); - - String response = createResponsePart(readFileCR(configuration_.getProperty("webbaseDir") + "resources/SignatureVX005Cert.xml")) + - vxBean.createSignatureCheck("0")+ - vxBean.createXMLDSIGManifestCheck("1","1","1")+ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - - writeFile(vxResFile(testNumber), response); - } - /** - * Method create051. - * @throws Exception - */ - -public void create006() throws Exception { - - String testNumber = "006"; - // ERST MAL DAS DOKUMENT ALS STRING AUFBAUEN - Supplement supp = new Supplement(); - supp.addXMLContent("http://MyServer.com/resources/something.xsd", - "<xsd:schema targetNamespace=\"http://uri2.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\"><xsd:element name=\"Document\"><xsd:complexType mixed=\"true\"><xsd:sequence minOccurs=\"0\" maxOccurs=\"unbounded\"><xsd:any namespace=\"##any\" processContents=\"lax\"/></xsd:sequence><xsd:attribute name=\"Id\" type=\"xsd:ID\" use=\"required\"/></xsd:complexType></xsd:element></xsd:schema>"); - supp.closeSupplement(); - - String requestEnd = createSignatureInfoEnd()+ - supp.getSupplement() + createRequestShortEnd(false); - - String requestStart = createRequestStart(testNumber,true,0); - - - String reqDocString = - "<daten:Document Id=\"myDocument\" " + - "xmlns:daten=\"http://uri2.data.org\" "+ - "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+ - "xsi:schemaLocation=\"http://uri2.data.org http://MyServer.com/resources/something.xsd http://www.w3.org/2000/09/xmldsig# http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd\" >" - + "daten</daten:Document>" ; - - InputStream bis = new ByteArrayInputStream(reqDocString.getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setValidating(true); - //factory.setValidating(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - - Map m = new HashMap(); - m.put("http://MyServer.com/resources/something.xsd",new ByteArrayInputStream(("<xsd:schema targetNamespace=\"http://uri2.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\"><xsd:element name=\"Document\"><xsd:complexType mixed=\"true\"><xsd:sequence minOccurs=\"0\" maxOccurs=\"unbounded\"><xsd:any namespace=\"##any\" processContents=\"lax\"/></xsd:sequence><xsd:attribute name=\"Id\" type=\"xsd:ID\" use=\"required\"/></xsd:complexType></xsd:element></xsd:schema>").getBytes())); - - EntityResolverChain chain = new EntityResolverChain(); - chain.addEntityResolver(new StreamEntityResolver(m)); - chain.addEntityResolver(new MOAEntityResolver()); - builder.setEntityResolver(chain); - - - //Dokument Parsen - System.out.println(reqDocString); - //Document reqDoc = builder.parse(bis); - Document reqDoc = DOMUtils.parseDocument(bis,true,Constants.ALL_SCHEMA_LOCATIONS, null,chain,new MOAErrorHandler()); - //Position für die Signatur angeben - //String xPath_Pos = "/moa:VerifyXMLSignatureRequest/moa:VerifySignatureInfo/moa:VerifySignatureEnvironment/moa:XMLContent - String xPath_Pos = "//daten:Document"; - //XPAth-Prefixe deklarieren - String xPath_Prefix = "daten http://uri2.data.org"; - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - System.out.println("REQDOC:"+DOMUtils.serializeNode(reqDoc)); - cpkcs.init(reqDoc,pos); - cpkcs.setCanoncialization(canAlgCanXML); - - cpkcs.setKeyInformation(); - /*cpkcs.createEnvelopedDataObject("envelopedData",readFileCR(configuration_.getProperty("webbaseDir")+"resources/testSimple.txt")); - cpkcs.createReferenceWithManifest(new URI("#xpointer(id('envelopedData')/node())"),"manifestObject");*/ - - Transform[] tr = new Transform[1]; - TransformImplEnvelopedSignature trans = new TransformImplEnvelopedSignature(); - tr[0] = trans; - //Enveloped Transformation - cpkcs.createReferenceWithTransforms(new URI("#myDocument"),tr); -//Signieren - - cpkcs.returnSig(); - //Serialisieren - String request = requestStart + replaceString(Node2String(reqDoc.getDocumentElement()),"<?xml version=\"1.0\" encoding=\"utf-8\"?>","") + requestEnd; - - writeFile(vxReqFile(testNumber),request); - - String response = createResponsePart(cpkcs.getX509CertString()) + - vxBean.createSignatureCheck("0")+ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - - writeFile(vxResFile(testNumber), response); - } - - public void create007() throws Exception { - - String testNumber = "007"; - - String dtdLocation = configuration_.getProperty("webbaseDir") + "resources/VX.007DTD.dtd"; - - // ERST MAL DAS DOKUMENT ALS STRING AUFBAUEN - Supplement supp = new Supplement(); - supp.addBase64Content(dtdLocation, - readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/VX.007DTD.dtd")); - supp.closeSupplement(); - - String requestEnd = createSignatureInfoEnd()+ - createRequestShortEnd(false); - - //String reqDocString = createRequestStart(testNumber,true,0,"","<!DOCTYPE data:Document SYSTEM \"http://MyServer.com/resources/VX.006DTD.dtd\">") + - String reqDocString = /*createRequestStart(testNumber,true,0) +*/ - "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Document SYSTEM \"" + dtdLocation + "\"><Document Id=\"myDocument\" " + - - "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+ - "xsi:schemaLocation=\"http://www.w3.org/2000/09/xmldsig# http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd\" >" - + "\ndaten\n</Document>" /*+ requestEnd*/; - - InputStream bis = new ByteArrayInputStream(reqDocString.getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setValidating(false); - - System.out.println(reqDocString); - - DocumentBuilder builder = factory.newDocumentBuilder(); - //Dokument Parsen - Document reqDoc = builder.parse(bis); - //Position für die Signatur angeben - String xPath_Pos = "/Document"; - //XPAth-Prefixe deklarieren - String xPath_Prefix = "";//"data http://uri2.data.org"; - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc,pos); - cpkcs.setCanoncialization(canAlgCanXML); - - cpkcs.setKeyInformation(); - /*cpkcs.createEnvelopedDataObject("envelopedData",readFileCR(configuration_.getProperty("webbaseDir")+"resources/testSimple.txt")); - cpkcs.createReferenceWithManifest(new URI("#xpointer(id('envelopedData')/node())"),"manifestObject");*/ - - Transform[] tr = new Transform[1]; - TransformImplEnvelopedSignature trans = new TransformImplEnvelopedSignature(); - tr[0] = trans; - //Enveloped Transformation - cpkcs.createReferenceWithTransforms(new URI("#myDocument"),tr); -//Signieren - cpkcs.returnSig(); - //Serialisieren - String request = Node2String(reqDoc.getDocumentElement()); - - int i_pos = request.indexOf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); - request = request.substring("<?xml version=\"1.0\" encoding=\"utf-8\"?>".length()); - - request = "<!DOCTYPE Document SYSTEM \"" + dtdLocation + "\">"+request; - - System.out.println("DOC:"+request); - - request ="<?xml version=\"1.0\" encoding=\"utf-8\"?><VerifyXMLSignatureRequest xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\"><VerifySignatureInfo><VerifySignatureEnvironment><Base64Content>"+Base64Utils.encode(request.getBytes())+"</Base64Content></VerifySignatureEnvironment><VerifySignatureLocation>//dsig:Signature</VerifySignatureLocation></VerifySignatureInfo>"+supp.getSupplement()+"<TrustProfileID>TrustProfile1</TrustProfileID></VerifyXMLSignatureRequest>"; - - - - - /*int i_pos = request.indexOf("<VerifyXMLSignatureRequest"); - request = request.substring(0,i_pos)+"<!DOCTYPE data:Document SYSTEM \"http://MyServer.com/resources/VX.006DTD.dtd\">\n" +request.substring(i_pos);*/ - - /*i_pos = request.indexOf("<TrustProfile"); - request = request.substring(0,i_pos)+supp.getSupplement() +request.substring(i_pos);*/ - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponseWithoutHashInputData(cpkcs.getX509CertString(), testNumber,"0",false)); - } - - - public void create008() throws Exception { - - String testNumber = "008"; - - String request = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ - "<VerifyXMLSignatureRequest xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">"+ - "<VerifySignatureInfo>"+ - "<VerifySignatureEnvironment>"+ - "<XMLContent xml:space=\"preserve\">"+ - "<dsig:Signature Id=\"HS_signature\" xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">"+ - "<dsig:SignedInfo>"+ - "<dsig:CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/>"+ - "<dsig:SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>"+ - "<dsig:Reference Id=\"reference-data-1\" URI=\"#signed-data\">"+ - "<dsig:Transforms>"+ - "<dsig:Transform Algorithm=\"http://www.w3.org/2002/06/xmldsig-filter2\">"+ - "<xf2:XPath Filter=\"intersect\" xmlns:xf2=\"http://www.w3.org/2002/06/xmldsig-filter2\">id('signed-data')/node()</xf2:XPath>"+ - "</dsig:Transform>"+ - "</dsig:Transforms>"+ - "<dsig:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>"+ - "<dsig:DigestValue>4lngV1x/OvR8iFWEBenH4fDihwA=</dsig:DigestValue>"+ - "</dsig:Reference>"+ - "<dsig:Reference Type=\"http://uri.etsi.org/01903/v1.1.1#SignedProperties\" URI=\"#refetsi\">"+ - "<dsig:Transforms>"+ - "<dsig:Transform Algorithm=\"http://www.w3.org/2002/06/xmldsig-filter2\">"+ - "<xf2:XPath Filter=\"intersect\" xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\" xmlns:xf2=\"http://www.w3.org/2002/06/xmldsig-filter2\">id('refetsi')/etsi:QualifyingProperties/etsi:SignedProperties</xf2:XPath>"+ - "</dsig:Transform>"+ - "</dsig:Transforms>"+ - "<dsig:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>"+ - "<dsig:DigestValue>1j0DWguieuw2cGA06gFjoSNXr+w=</dsig:DigestValue>"+ - "</dsig:Reference>"+ - "</dsig:SignedInfo>"+ - "<dsig:SignatureValue>Yb6fsPNbKyYW+u7cU1EqF9n5QrwLXHqdGD4tJNT5+sA7kQR3Ztqz965vlBH+1pJE"+ - "nGxehxXsesZboVvkJa/jhuI0goCTW9KkdGOP71B7o7/vlyBbxaYKpnVNtBU4/qtT"+ - "xba7M0E32X+tm/x9O6foXIM0AoP3oQBZmjo9rEJ9kfk=</dsig:SignatureValue>"+ - "<dsig:KeyInfo>"+ - "<dsig:X509Data>"+ - "<dsig:X509Certificate>MIIFJTCCBA2gAwIBAgICGTcwDQYJKoZIhvcNAQEFBQAwgaExCzAJBgNVBAYTAkFU"+ - "MUgwRgYDVQQKEz9BLVRydXN0IEdlcy4gZi4gU2ljaGVyaGVpdHNzeXN0ZW1lIGlt"+ - "IGVsZWt0ci4gRGF0ZW52ZXJrZWhyIEdtYkgxIzAhBgNVBAsTGmEtc2lnbi1URVNU"+ - "LVByZW1pdW0tRW5jLTAxMSMwIQYDVQQDExphLXNpZ24tVEVTVC1QcmVtaXVtLUVu"+ - "Yy0wMTAeFw0wMzAyMTAxMzIwNThaFw0wNjAyMTAxMzIwNThaMGoxCzAJBgNVBAYT"+ - "AkFUMRwwGgYDVQQDExNUZXN0cGVyc29uIE1PQTQgQlJaMQwwCgYDVQQEEwNCUlox"+ - "GDAWBgNVBCoTD1Rlc3RwZXJzb24gTU9BNDEVMBMGA1UEBRMMNzkwMTg3NDYxNjMz"+ - "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDS/UW1/tZeCh7HHQmj8auUTEc4"+ - "edAgRDkUVKOm0tF3kE3WZlhGDZL0p84xsdIKyI+bwDCMATATkQwDo/Xxn9jJMi4/"+ - "t80bNyRsHk9giA0wcvz9NgmEcDwKNqawGsR9gNeK8TyIC8AuDkj1EwtkAObMvtp/"+ - "Z1phi47x3JxDDfGDpQIDAQABo4ICHzCCAhswEwYDVR0jBAwwCoAIS7OAw3GTPNgw"+ - "JwYIKwYBBQUHAQMBAf8EGDAWMAgGBgQAjkYBATAKBggrBgEFBQcLATCBggYIKwYB"+ - "BQUHAQEEdjB0MCkGCCsGAQUFBzABhh1odHRwOi8vd3d3LmEtdHJ1c3QuYXQ6ODIv"+ - "b2NzcDBHBggrBgEFBQcwAoY7aHR0cDovL3d3dy5hLXRydXN0LmF0L2NlcnRzL2Et"+ - "c2lnbi1URVNULVByZW1pdW0tU2lnLTAxYS5jcnQwgZQGA1UdIASBjDCBiTB9BgYq"+ - "KAARAQQwczA1BggrBgEFBQcCARYpaHR0cDovL3d3dy5hLXRydXN0LmF0L2RvY3Mv"+ - "Y3AvYS1zaWduLVRFU1QwOgYIKwYBBQUHAgIwLhosRGllc2VzIFplcnRpZmlrYXQg"+ - "ZGllbnQgbnVyIHp1IFRlc3R6d2Vja2VuICEwCAYGBACLMAEBMG8GA1UdHwRoMGYw"+ - "ZKBioGCGXmxkYXA6Ly9sZGFwLmEtdHJ1c3QuYXQvb3U9YS1zaWduLVRFU1QtUHJl"+ - "bWl1bS1FbmMtMDEsbz1BLVRydXN0LGM9QVQ/Y2VydGlmaWNhdGVyZXZvY2F0aW9u"+ - "bGlzdD8wEQYDVR0OBAoECE4DxL9ky4M+MA4GA1UdDwEB/wQEAwIGwDAgBgNVHREE"+ - "GTAXgRV0ZXN0cGVyc29uNEBicnouZ3YuYXQwCQYDVR0TBAIwADANBgkqhkiG9w0B"+ - "AQUFAAOCAQEAioVvsZN+NnQxXMTGdjKveTBMRTYzHflkSC8lI9XXltP5+mjIuoB2"+ - "Tn6voovA8dXz9jTsnQt8f8ye0CL2bSS9UVD1jv8So3bavquW+HlkZBAZvL39APNL"+ - "PjUUnWn0QOnrQAJ6W47UwGAUgEw3KcBcJaEa4Xb/8kUj618xGzWl6X0mKsVpxkrf"+ - "+5Cj+nmwDqChll08/90MmhSY4M5FrvmQ9GjAN5FHVsk0FPp02tKCRzoBJtzpB1DW"+ - "KHlgiDHUAXy5eD0XI7PXebPNZ4InvY/jC/IH8PRLdJT249YQmUxZ4neTtFDvb8C1"+ - "Qh6k725fh3hVxqX8ZwwWj9+iGQVk53K3CA==</dsig:X509Certificate>"+ - /*"<dsig:X509Certificate>"+ - readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/IAIKRootMusterbehoerde.cer")+ - "</dsig:X509Certificate>"+*/ - "</dsig:X509Data>"+ - "</dsig:KeyInfo>"+ - "<dsig:Object Id=\"signed-data\">"+ - "<sl10:InfoboxReadRequest xmlns:sl10=\"http://www.buergerkarte.at/namespaces/securitylayer/20020225#\">"+ - "<sl10:InfoboxIdentifier>IdentityLink</sl10:InfoboxIdentifier>"+ - "<sl10:BinaryFileParameters ContentIsXMLEntity=\"true\"/>"+ - "</sl10:InfoboxReadRequest>"+ - "</dsig:Object>"+ - "<dsig:Object Id=\"refetsi\">"+ - "<etsi:QualifyingProperties Target=\"#HS_signature\" xmlns:etsi=\"http://uri.etsi.org/01903/v1.1.1#\">"+ - "<etsi:SignedProperties>"+ - "<etsi:SignedSignatureProperties>"+ - "<etsi:SigningTime>2003-03-04T12:32:54Z</etsi:SigningTime>"+ - "<etsi:SigningCertificate>"+ - "<etsi:Cert>"+ - "<etsi:CertDigest>"+ - "<etsi:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>"+ - "<etsi:DigestValue>Frhu1o4mL4gQHdJcU0xSA/h4COE=</etsi:DigestValue>"+ - "</etsi:CertDigest>"+ - "<etsi:IssuerSerial>"+ - "<dsig:X509IssuerName>CN=a-sign-TEST-Premium-Enc-01,OU=a-sign-TEST-Premium-Enc-01,O=A-Trust Ges. f. Sicherheitssysteme im elektr. Datenverkehr GmbH,C=AT</dsig:X509IssuerName>"+ - "<dsig:X509SerialNumber>6455</dsig:X509SerialNumber>"+ - "</etsi:IssuerSerial>"+ - "</etsi:Cert>"+ - "</etsi:SigningCertificate>"+ - "<etsi:SignaturePolicyIdentifier>"+ - "<etsi:SignaturePolicyImplied/>"+ - "</etsi:SignaturePolicyIdentifier>"+ - "</etsi:SignedSignatureProperties>"+ - "<etsi:SignedDataObjectProperties>"+ - "<etsi:DataObjectFormat ObjectReference=\"#reference-data-1\">"+ - "<etsi:MimeType>text/xml</etsi:MimeType>"+ - "</etsi:DataObjectFormat>"+ - "</etsi:SignedDataObjectProperties>"+ - "</etsi:SignedProperties>"+ - "</etsi:QualifyingProperties>"+ - "</dsig:Object>"+ - "</dsig:Signature>"+ - "</XMLContent>"+ - "</VerifySignatureEnvironment>"+ - "<VerifySignatureLocation>//dsig:Signature</VerifySignatureLocation>"+ - "</VerifySignatureInfo>"+ - "<TrustProfileID>TrustProfile1</TrustProfileID>"+ - "</VerifyXMLSignatureRequest>"; - - String response = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ - "<VerifyXMLSignatureResponse xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\" >"+ - " <SignerInfo>"+ - " <dsig:X509Data xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">"+ - " <dsig:X509SubjectName>serialNumber=790187461633,givenName=Testperson MOA4,SN=BRZ,CN=Testperson MOA4 BRZ,C=AT</dsig:X509SubjectName>"+ - " <dsig:X509IssuerSerial>"+ - " <dsig:X509IssuerName>CN=a-sign-TEST-Premium-Enc-01,OU=a-sign-TEST-Premium-Enc-01,O=A-Trust Ges. f. Sicherheitssysteme im elektr. Datenverkehr GmbH,C=AT</dsig:X509IssuerName>"+ - " <dsig:X509SerialNumber>6455</dsig:X509SerialNumber>"+ - " </dsig:X509IssuerSerial>"+ - "<dsig:X509Certificate>MIIFJTCCBA2gAwIBAgICGTcwDQYJKoZIhvcNAQEFBQAwgaExCzAJBgNVBAYTAkFU"+ - "MUgwRgYDVQQKEz9BLVRydXN0IEdlcy4gZi4gU2ljaGVyaGVpdHNzeXN0ZW1lIGlt"+ - "IGVsZWt0ci4gRGF0ZW52ZXJrZWhyIEdtYkgxIzAhBgNVBAsTGmEtc2lnbi1URVNU"+ - "LVByZW1pdW0tRW5jLTAxMSMwIQYDVQQDExphLXNpZ24tVEVTVC1QcmVtaXVtLUVu"+ - "Yy0wMTAeFw0wMzAyMTAxMzIwNThaFw0wNjAyMTAxMzIwNThaMGoxCzAJBgNVBAYT"+ - "AkFUMRwwGgYDVQQDExNUZXN0cGVyc29uIE1PQTQgQlJaMQwwCgYDVQQEEwNCUlox"+ - "GDAWBgNVBCoTD1Rlc3RwZXJzb24gTU9BNDEVMBMGA1UEBRMMNzkwMTg3NDYxNjMz"+ - "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDS/UW1/tZeCh7HHQmj8auUTEc4"+ - "edAgRDkUVKOm0tF3kE3WZlhGDZL0p84xsdIKyI+bwDCMATATkQwDo/Xxn9jJMi4/"+ - "t80bNyRsHk9giA0wcvz9NgmEcDwKNqawGsR9gNeK8TyIC8AuDkj1EwtkAObMvtp/"+ - "Z1phi47x3JxDDfGDpQIDAQABo4ICHzCCAhswEwYDVR0jBAwwCoAIS7OAw3GTPNgw"+ - "JwYIKwYBBQUHAQMBAf8EGDAWMAgGBgQAjkYBATAKBggrBgEFBQcLATCBggYIKwYB"+ - "BQUHAQEEdjB0MCkGCCsGAQUFBzABhh1odHRwOi8vd3d3LmEtdHJ1c3QuYXQ6ODIv"+ - "b2NzcDBHBggrBgEFBQcwAoY7aHR0cDovL3d3dy5hLXRydXN0LmF0L2NlcnRzL2Et"+ - "c2lnbi1URVNULVByZW1pdW0tU2lnLTAxYS5jcnQwgZQGA1UdIASBjDCBiTB9BgYq"+ - "KAARAQQwczA1BggrBgEFBQcCARYpaHR0cDovL3d3dy5hLXRydXN0LmF0L2RvY3Mv"+ - "Y3AvYS1zaWduLVRFU1QwOgYIKwYBBQUHAgIwLhosRGllc2VzIFplcnRpZmlrYXQg"+ - "ZGllbnQgbnVyIHp1IFRlc3R6d2Vja2VuICEwCAYGBACLMAEBMG8GA1UdHwRoMGYw"+ - "ZKBioGCGXmxkYXA6Ly9sZGFwLmEtdHJ1c3QuYXQvb3U9YS1zaWduLVRFU1QtUHJl"+ - "bWl1bS1FbmMtMDEsbz1BLVRydXN0LGM9QVQ/Y2VydGlmaWNhdGVyZXZvY2F0aW9u"+ - "bGlzdD8wEQYDVR0OBAoECE4DxL9ky4M+MA4GA1UdDwEB/wQEAwIGwDAgBgNVHREE"+ - "GTAXgRV0ZXN0cGVyc29uNEBicnouZ3YuYXQwCQYDVR0TBAIwADANBgkqhkiG9w0B"+ - "AQUFAAOCAQEAioVvsZN+NnQxXMTGdjKveTBMRTYzHflkSC8lI9XXltP5+mjIuoB2"+ - "Tn6voovA8dXz9jTsnQt8f8ye0CL2bSS9UVD1jv8So3bavquW+HlkZBAZvL39APNL"+ - "PjUUnWn0QOnrQAJ6W47UwGAUgEw3KcBcJaEa4Xb/8kUj618xGzWl6X0mKsVpxkrf"+ - "+5Cj+nmwDqChll08/90MmhSY4M5FrvmQ9GjAN5FHVsk0FPp02tKCRzoBJtzpB1DW"+ - "KHlgiDHUAXy5eD0XI7PXebPNZ4InvY/jC/IH8PRLdJT249YQmUxZ4neTtFDvb8C1"+ - "Qh6k725fh3hVxqX8ZwwWj9+iGQVk53K3CA==</dsig:X509Certificate>"+ - " <sl11:QualifiedCertificate xmlns:sl11=\"http://www.buergerkarte.at/namespaces/securitylayer/20020831#\"/>"+ - " </dsig:X509Data>"+ - " </SignerInfo>"+ - " <SignatureCheck>"+ - " <Code>0</Code>"+ - " </SignatureCheck>"+ - " <CertificateCheck>"+ - " <Code>0</Code>"+ - " </CertificateCheck>"+ - "</VerifyXMLSignatureResponse>"; - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber),response); - } - - public void create009() throws Exception { - - String testNumber = "009"; - // ERST MAL DAS DOKUMENT ALS STRING AUFBAUEN - Supplement supp = new Supplement(); - supp.addXMLContent("http://MyServer.com/resources/something.xsd", - "<xsd:schema targetNamespace=\"http://uri2.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\"><xsd:element name=\"Document\"><xsd:complexType mixed=\"true\"><xsd:sequence minOccurs=\"0\" maxOccurs=\"unbounded\"><xsd:any namespace=\"##any\" processContents=\"lax\"/></xsd:sequence><xsd:attribute name=\"Id\" type=\"xsd:ID\" use=\"required\"/></xsd:complexType></xsd:element></xsd:schema>"); - supp.closeSupplement(); - - String requestEnd = createSignatureInfoEnd()+ - supp.getSupplement() + createRequestShortEnd(false); - - String requestStart = createRequestStart(testNumber,true,0); - - - String reqDocString = - "<daten:Document Id=\"myDocument\" " + - "xmlns:daten=\"http://uri2.data.org\" "+ - "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+ - "xsi:schemaLocation=\"http://uri2.data.org http://MyServer.com/resources/something.xsd http://www.w3.org/2000/09/xmldsig# http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd\" >" - + "daten</daten:Document>" ; - - InputStream bis = new ByteArrayInputStream(reqDocString.getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setValidating(true); - //factory.setValidating(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - - Map m = new HashMap(); - m.put("http://MyServer.com/resources/something.xsd",new ByteArrayInputStream(("<xsd:schema targetNamespace=\"http://uri2.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\"><xsd:element name=\"Document\"><xsd:complexType mixed=\"true\"><xsd:sequence minOccurs=\"0\" maxOccurs=\"unbounded\"><xsd:any namespace=\"##any\" processContents=\"lax\"/></xsd:sequence><xsd:attribute name=\"Id\" type=\"xsd:ID\" use=\"required\"/></xsd:complexType></xsd:element></xsd:schema>").getBytes())); - - EntityResolverChain chain = new EntityResolverChain(); - chain.addEntityResolver(new StreamEntityResolver(m)); - chain.addEntityResolver(new MOAEntityResolver()); - builder.setEntityResolver(chain); - - - //Dokument Parsen - System.out.println(reqDocString); - //Document reqDoc = builder.parse(bis); - Document reqDoc = DOMUtils.parseDocument(bis,true,Constants.ALL_SCHEMA_LOCATIONS, null,chain,new MOAErrorHandler()); - //Position für die Signatur angeben - //String xPath_Pos = "/moa:VerifyXMLSignatureRequest/moa:VerifySignatureInfo/moa:VerifySignatureEnvironment/moa:XMLContent - String xPath_Pos = "//daten:Document"; - //XPAth-Prefixe deklarieren - String xPath_Prefix = "daten http://uri2.data.org"; - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - System.out.println("REQDOC:"+DOMUtils.serializeNode(reqDoc)); - cpkcs.init(reqDoc,pos); - cpkcs.setCanoncialization(canAlgCanXML); - - cpkcs.setKeyInformation(); - /*cpkcs.createEnvelopedDataObject("envelopedData",readFileCR(configuration_.getProperty("webbaseDir")+"resources/testSimple.txt")); - cpkcs.createReferenceWithManifest(new URI("#xpointer(id('envelopedData')/node())"),"manifestObject");*/ - - Transform[] tr = new Transform[1]; - TransformImplEnvelopedSignature trans = new TransformImplEnvelopedSignature(); - tr[0] = trans; - //Enveloped Transformation - cpkcs.createReferenceWithTransforms(new URI("#xpointer(id(myDocument))"),tr); -//Signieren - - cpkcs.returnSig(); - //Serialisieren - String request = requestStart + replaceString(Node2String(reqDoc.getDocumentElement()),"<?xml version=\"1.0\" encoding=\"utf-8\"?>","") + requestEnd; - - writeFile(vxReqFile(testNumber),request); - - String response = createResponsePart(cpkcs.getX509CertString()) + - vxBean.createSignatureCheck("0")+ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - - writeFile(vxResFile(testNumber), response); - } - - public void create101() throws Exception { - - String testNumber = "101"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - Supplement supp = new Supplement(); - supp.addMetaInfo("text/plain","http://www.buergerkarte.at"); - supp.addBase64Content(configuration_.getProperty("webbaseDir")+"resources/testSimple.txt", - readBinaryFileAsBase64(configuration_.getProperty("baseDir")+"resources/testSimple.txt")); - supp.closeSupplement(); - //supp.addProfileID("Some ID"); - - String requestEnd = createSignatureInfoEnd()+ - supp.getSupplement() + createRequestShortEnd(false); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - requestEnd); - - writeFile(vxReqFile(testNumber),request); - - String response = createResponsePart(cpkcs.getX509CertString()) + - vxBean.createSignatureCheck("0")+ - /*vxBean.createXMLDSIGManifestCheck("0","","1")+ */ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - - writeFile(vxResFile(testNumber), response); - } - public void create102() throws Exception { - - String testNumber = "102"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - Supplement supp = new Supplement(); - supp.addMetaInfo("text/plain",null); - supp.addBase64Content(configuration_.getProperty("webbaseDir")+"resources/testSimple.txt", - readBinaryFileAsBase64(configuration_.getProperty("baseDir")+"resources/testSimple.txt")); - supp.closeSupplement(); - //supp.addProfileID("Some ID"); - - String requestEnd = createSignatureInfoEnd()+ - supp.getSupplement() + "<ReturnHashInputData/>"+createRequestShortEnd(false); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - requestEnd); - - writeFile(vxReqFile(testNumber),request); - - - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0")); - } - - public void create103() throws Exception { - - String testNumber = "103"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - Supplement supp = new Supplement(); - //supp.addMetaInfo("text/plain",null); - supp.addXMLContent(configuration_.getProperty("webbaseDir")+"resources/testSimple.txt",readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")); - //supp.addBase64Content(configuration_.getProperty("webbaseDir")+"resources/testSimple.txt", - // readBinaryFileAsBase64(configuration_.getProperty("webbaseDir")+"resources/testSimple.txt")); - supp.closeSupplement(); - //supp.addProfileID("Some ID"); - - String requestEnd = createSignatureInfoEnd()+ - supp.getSupplement() + "<ReturnHashInputData/>"+createRequestShortEnd(false); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - requestEnd); - - writeFile(vxReqFile(testNumber),request); - - - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0")); - } -public void create104() throws Exception { - - String testNumber = "104"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - Supplement supp = new Supplement(); - supp.addXMLContent(configuration_.getProperty("webbaseDir")+"resources/testSimple.txt", readFileCR(configuration_.getProperty("baseDir")+"resources/testSimple.txt")); - supp.closeSupplement(); - - String requestEnd = - createSignatureInfoEnd()+ - supp.getSupplement()+"<ReturnHashInputData/>"+ - createRequestShortEnd(false); - - String request = - makeOutputFile( - createRequestStart(testNumber+" - Supplement/Content/XMLContent instead of Supplement/Content/Base64Content",true,0), - cpkcs.returnSig(), - requestEnd); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0")); - } - - public void create105() throws Exception { - - String testNumber = "105"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testXML.txt"); - cpkcs.setKeyInformation(); - - Supplement supp = new Supplement(); - supp.addXMLContent(configuration_.getProperty("webbaseDir")+"resources/testSimple.txt", readFileCR(configuration_.getProperty("baseDir")+"resources/testSimple.txt")); - supp.closeSupplement(); - - Supplement supp2 = new Supplement(); - supp2.addBase64Content(configuration_.getProperty("webbaseDir")+"resources/testXML.txt", readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/testXML.txt")); - supp2.closeSupplement(); - - String requestEnd = - createSignatureInfoEnd()+ - supp.getSupplement()+ - supp2.getSupplement() + - createRequestShortEnd(true); - - String request = - makeOutputFile( - createRequestStart(testNumber + " - 2 Supplement elements",true,0), - cpkcs.returnSig(), - requestEnd); - - String response = createResponsePart(cpkcs.getX509CertString()) + - "<HashInputData><Base64Content>"+ - readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/testSimple.txt") + - "</Base64Content></HashInputData>"+ - "<HashInputData><Base64Content>"+ - readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/testXML.txt") + - "</Base64Content></HashInputData>"+ - vxBean.createSignatureCheck("0")+ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResFile(testNumber), response); - } - -public void create106() throws Exception { - - String testNumber = "106"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - String requestEnd = - createSignatureInfoEnd()+ - "<SupplementProfileID>SupplementProfile2</SupplementProfileID>" + - "<!-- Supplement Profile 2 enthaelt nicht die referenzierte URI -->" + - "<SupplementProfileID>SupplementProfile1</SupplementProfileID><ReturnHashInputData/>" + - createRequestShortEnd(false); - - String request = - makeOutputFile( - createRequestStart(testNumber +" - 2 SupplementProfileID elements" ,true,0), - cpkcs.returnSig(), - requestEnd); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0")); - } - - - public void create301() throws Exception { - - String testNumber = "301"; - - //Testcast with another canoicalization algorithm - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXMLwithCom); - //cpkcs.createReference(true,"Dies sind testdaten"); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0")); - } - /** - * Method create302. - * @throws Exception - */ - public void create302() throws Exception { - - String testNumber = "302"; - - //Testcast with another canoicalization algorithm - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - - cpkcs.init(); - cpkcs.setCanoncialization(canAlgExcXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0")); - } - /** - * Method create303. - * @throws Exception - */ - public void create303() throws Exception { - - String testNumber = "303"; - - //Testcast with another canoicalization algorithm - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - - cpkcs.init(); - cpkcs.setCanoncialization(canAlgExcXMLwithCom); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0")); - } - - public void create304() throws Exception { - - String testNumber = "304"; - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.initECDSA(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - //cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - //cpkcs.createEnvelopedDataObject("envelopedData",readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")); - - cpkcs.createReference(true,readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt"),"envelopedData"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0","<dsig:X509IssuerName>CN=IAIK ECDSA Test,OU=JavaSecurity,O=IAIK,C=AT</dsig:X509IssuerName>","<dsig:X509SubjectName>CN=IAIK ECDSA Test,OU=JavaSecurity,O=IAIK,C=AT</dsig:X509SubjectName>","<dsig:X509SerialNumber>68172</dsig:X509SerialNumber>")); - } - /** - * Method create305. - * @throws Exception - */ - public void create305() throws Exception { - - String testNumber = "305"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - - String refData = "Dies sind Testdaten"; - - cpkcs.createReference(true,refData); - - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0",refData)); - } - - /** - * Method create307. - * @throws Exception - */ - public void create307() throws Exception { - - String testNumber = "307"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - Supplement supp = new Supplement(); - supp.addXMLContent(configuration_.getProperty("baseDir")+"resources/testSimple.txt", readFileCR(configuration_.getProperty("baseDir")+"resources/testSimple.txt")); - supp.closeSupplement(); - - String requestEnd = createSignatureInfoEnd()+ - supp.getSupplement() + - createRequestShortEnd(true); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - requestEnd); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0")); - } - - /** - * Method create308. - * @throws Exception - */ - public void create308() throws Exception { - - String testNumber = "308"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - Supplement supp = new Supplement(); - supp.addXMLContent(configuration_.getProperty("webbaseDir")+"resources/testSimple.txt", readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")); - supp.closeSupplement(); - - - String requestEnd = createSignatureInfoEnd()+ supp.getSupplement() + - createRequestShortEnd(false); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - requestEnd); - - //request = replaceString(request,"<XMLContent xml:space=\"preserve\">","<XMLContent xml:space=\"preserve\">VERAENDERTE DATEN und die Ursprungsdaten: "); - request = replaceString(request,"Dies sind Testdaten","VERAENDERTE DATEN und die Ursprungsdaten: Dies sind Testdaten"); - //request = replaceString(request,Base64Utils.encode("Dies sind Testdaten".getBytes()),Base64Utils.encode("VERAENDERTE DATEN und die Ursprungsdaten: Dies sind Testdaten".getBytes())); - //request = replaceString(request,"<ReturnHashInputData/>",""); - /*request = replaceString(request,"Reference=\""+configuration_.getProperty("baseDir")+"resources/testSimple.txt\"","Reference=\"\""); - request = replaceString(request,"URI=\""+configuration_.getProperty("webbaseDir")+"resources/testSimple.txt\"","URI=\"\"");*/ - writeFile(vxReqFile(testNumber),request); - - String response = createResponse(cpkcs.getX509CertString(),testNumber,"1",1); - - writeFile(vxResFile(testNumber), response); - } - public void create310() throws Exception { - - String testNumber = "310"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - //Erzeugen der Base64-Daten - //String tmp = readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/testSimple.txt"); - - URI target = new URI(configuration_.getProperty("webbaseDir") + "resources/testSimple.txtbase64.enc"); - - Transform[] tr = new Transform[1]; - tr[0] = new TransformImplBase64Decode(); - InputStream s = getHttpInputStream(target.toString()); - tr[0].setInput(s,null); - - cpkcs.createReferenceWithTransforms(target,tr); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0")); - } -//------------------------------------------------------------------------- -//------------------------------------------------------------------------- -//------------------------------------------------------------------------- -//------------------------------------------------------------------------- -//-------311 scheint die XPAth - Transformation nicht richtig auszuführen- -// (Siehe Output in der Konsole.....) - - public void create311() throws Exception { - - String testNumber = "311"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - Transform[] tr = new Transform[1]; - TransformImplXPath trans = new TransformImplXPath(); -// TransformImplXSLT trans = new TransformImplXSLT(); - - - InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/BookData.xml"); -// InputStream s2 = new FileInputStream(configuration_.getProperty("baseDir")+"resources/transform.xsl"); - trans.setInput(s,null); -// trans.setStyleSheet(s2,null); - - trans.addNSDeclaration("data",new URI("http://uri.data.org")); //new URI("file:/"+configuration_.getProperty("baseDir")+"resources/BookData.xml")); - // trans.setXPath("ancestor-or-self::data:first-name"); - trans.setXPath("ancestor-or-self::text()/ancestor-or-self::data:first-name"); - - tr[0] = trans; - - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir") + "resources/BookData.xml"),tr); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0",1,"text:Ellipse")); - } - -public void create312() throws Exception - { String testNumber = "312"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init("signature"); - cpkcs.setCanoncialization(canAlgCanXML); - - Transform[] tr = new Transform[1]; - TransformImplXPath2 trans = new TransformImplXPath2(); - InputStream s = getHttpInputStream(configuration_.getProperty("webbaseDir")+"resources/CX1_book.xsl"); - trans.setInput(s,null); - - HashMap temp = new HashMap(); - temp.put("data",new URI("http://uri.data.org")); - trans.addXPathFilter("/data:book/data:first-name",TransformImplXPath2.FILTER_MODE_SUBTRACT_,temp); - tr[0] = trans; - //System.out.println(getTransformsResult(tr)); - cpkcs.createReferenceWithTransforms(new URI(configuration_.getProperty("webbaseDir") + "resources/BookData.xml"),tr,"reference-1"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart("312",true,0), - cpkcs.returnSig(), - createSignatureInfoEnd() - + createRequestShortEnd(false)); - - writeFile(vxReqFile(testNumber),request); - - String response = createResponsePart(cpkcs.getX509CertString()) + - vxBean.createSignatureCheck("0")+ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - - writeFile(vxResFile(testNumber), response); - } - -public void create313() throws Exception - { String testNumber = "313"; - - // ERST MAL DAS DOKUMENT ALS STRING AUFBAUEN - - String requestEnd = createRequestEnd(true,false,null); - - String reqDocString = createRequestStart(testNumber,true,0) + - "<data:Document " + - "xmlns:data=\"http://uri.data.org\" "+ - "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" Id=\"myDocument\" "+ - "xsi:schemaLocation=\"http://uri.data.org http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/VX.006Schema.xsd http://www.w3.org/2000/09/xmldsig# http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd\" >" - + "</data:Document>" + requestEnd; - - - InputStream bis = new ByteArrayInputStream(("<data:Document " + - "xmlns:data=\"http://uri.data.org\" "+ - "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" Id=\"myDocument\" "+ - "xsi:schemaLocation=\"http://uri.data.org http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/VX.006Schema.xsd http://www.w3.org/2000/09/xmldsig# http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd\" >" - + "</data:Document>").getBytes()); - //Document-Builder holen - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - //Dokument Parsen - Document reqDoc = builder.parse(bis); - - System.out.println(DOMUtils.serializeNode(reqDoc.getDocumentElement())); - //Position für die Signatur angeben - //String xPath_Pos = "/moa:VerifyXMLSignatureRequest/moa:VerifySignatureInfo/moa:VerifySignatureEnvironment/moa:XMLContent/data:Document"; - String xPath_Pos = "/node()"; - //XPAth-Prefixe deklarieren - String xPath_Prefix = "data xmlns:data=\"http://uri.data.org\""; - Position pos = new Position(xPath_Pos, xPath_Prefix,0); - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - //Signer erzeugen, der das obige Doc als Basis nimmt, und die Signatur an der besagten stelle einfügt - cpkcs.init(reqDoc,pos); - cpkcs.setCanoncialization(canAlgCanXML); - - cpkcs.setKeyInformation(1); - //cpkcs.createEnvelopedDataObject("envelopedData",readFileCR(configuration_.getProperty("webbaseDir")+"resources/testSimple.txt")); - //cpkcs.createReferenceWithManifest(new URI("#xpointer(id('envelopedData')/node())"),"manifestObject"); - - Transform[] tr = new Transform[1]; - TransformImplEnvelopedSignature trans = new TransformImplEnvelopedSignature(); - tr[0] = trans; - //Enveloped Transformation - cpkcs.createReferenceWithTransforms(new URI(""),tr); -//Signieren - cpkcs.returnSig(); - //Serialisieren - String request = Node2String(reqDoc.getDocumentElement()); - - writeFile(vxReqFile(testNumber),createRequestStart(testNumber,true,0).trim() +cutXML(request).trim()+requestEnd.trim()); - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0",1,"text:"+"<data:Document xmlns:data=\"http://uri.data.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" Id=\"myDocument\" xsi:schemaLocation=\"http://uri.data.org http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/VX.006Schema.xsd http://www.w3.org/2000/09/xmldsig# http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd\"></data:Document>")); - - } - - - public void create314() throws Exception - { String testNumber = "314"; - - 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.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart("314",true,0), - cpkcs.returnSig(), - createSignatureInfoEnd() - + createRequestShortEnd(false)); - - writeFile(vxReqFile(testNumber),request); - - String response = createResponsePart(cpkcs.getX509CertString()) + - vxBean.createSignatureCheck("0")+ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - - writeFile(vxResFile(testNumber), response); - } - -public void create314_2() throws Exception - { String testNumber = "314_2"; - - 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.setKeyInformation(); - - Supplement supp = new Supplement(); - String suppContent = readFileCR(configuration_.getProperty("baseDir")+"resources/CX1_book.xsl"); - suppContent = replaceString(suppContent, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",""); - supp.addXMLContent("http://moa-test.brz.intra.gv.at/TestDatenGenerator/resources/CX1_book.xsl", suppContent ); - supp.closeSupplement(); - - String request = - makeOutputFile( - createRequestStart("314_2",true,0), - cpkcs.returnSig(), - createSignatureInfoEnd() + - supp.getSupplement() - + createRequestShortEnd(false)); - -/* request = replaceString(request, "http://moa-test.brz.intra.gv.at", "http://MyServer.com"); - request = replaceString(request, "http://moa-test.brz.intra.gv.at", "http://MyServer.com"); - request = replaceString(request, "http://moa-test.brz.intra.gv.at", "http://MyServer.com"); - //Hinweis: ich nehmen an, die URI in DSIG:REFERENCE sollte schon stimmen.... - request = replaceString(request, "http://MyServer.com", "http://moa-test.brz.intra.gv.at"); */ - writeFile(vxReqFile(testNumber),request); - - String response = createResponsePart(cpkcs.getX509CertString()) + - vxBean.createSignatureCheck("0")+ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - writeFile(vxResFile(testNumber), response); - } - - - public void create315() throws Exception { - - String testNumber = "315"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - URI target = new URI(configuration_.getProperty("webbaseDir") + "resources/test_wo_canonicalisation.XML"); - - Transform[] tr = new Transform[1]; - tr[0] = new TransformImplCanonicalXML(); - InputStream s = getHttpInputStream(target.toString()); - tr[0].setInput(s,null); - - String erg = getTransformsResult(tr); - - cpkcs.createReferenceWithTransforms(target,tr); - //cpkcs.createReference(false, "file:/"+ configuration_.getProperty("baseDir")+"resources/test_wo_canonicalisation.XML"); - //cpkcs.createReference(false, "file:/"+ configuration_.getProperty("baseDir")+"resources/test_w_canonicalisation.XML"); -// cpkcs.createReferenceWithManifest(new URI("file:/"+ configuration_.getProperty("baseDir")+"resources/test_w_canonicalisation.XML"),"canonicalizedData"); - - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - - - writeFile(vxReqFile(testNumber),request); - - - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0",erg)); - } - - public void create316() throws Exception { - - String testNumber = "316"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - - URI target = new URI(configuration_.getProperty("webbaseDir") + "resources/test_wo_canonicalisation.XML"); - - Transform[] tr = new Transform[1]; - tr[0] = new TransformImplCanonicalXMLWithComments(); - InputStream s = getHttpInputStream(target.toString()); - tr[0].setInput(s,null); - - String erg = getTransformsResult(tr); - - cpkcs.createReferenceWithTransforms(target,tr); - - cpkcs.setKeyInformation(); - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0",erg)); - } - public void create317() throws Exception { - - String testNumber = "317"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - - URI target = new URI(configuration_.getProperty("webbaseDir") + "resources/test_wo_canonicalisation.XML"); - - Transform[] tr = new Transform[1]; - tr[0] = new TransformImplExclusiveCanonicalXML(); - InputStream s = getHttpInputStream(target.toString()); - tr[0].setInput(s,null); - String erg = getTransformsResult(tr); - cpkcs.createReferenceWithTransforms(target,tr); - - cpkcs.setKeyInformation(); - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0",erg)); - } - public void create318() throws Exception { - - String testNumber = "318"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - URI target = new URI(configuration_.getProperty("webbaseDir") + "resources/test_wo_canonicalisation.XML"); - Transform[] tr = new Transform[1]; - tr[0] = new TransformImplExclusiveCanonicalXMLWithComments(); - InputStream s = getHttpInputStream(target.toString()); - tr[0].setInput(s,null); - - String erg = getTransformsResult(tr); - cpkcs.createReferenceWithTransforms(target,tr); - - cpkcs.setKeyInformation(); - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0",erg)); - } - - public void create318_2() throws Exception { - - String testNumber = "318_2"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - - //Create a base64-encoded version of the xml file - - //String tmp = readBinaryFileAsBase64(configuration_.getProperty("baseDir")+"resources/test_wo_canonicalisation.XML"); - - URI target = new URI(configuration_.getProperty("webbaseDir") + "resources/test_wo_canonicalisation.XMLbase64.enc"); - - Transform[] tr = new Transform[3]; - tr[0] = new TransformImplBase64Decode(); - InputStream s = getHttpInputStream(target.toString()); - tr[0].setInput(s,null); - tr[1] = new TransformImplCanonicalXMLWithComments(); - tr[1].setInput(s,null); - - tr[2] = new TransformImplExclusiveCanonicalXML(); - tr[2].setInput(s,null); - String erg = getTransformsResult(tr); - cpkcs.createReferenceWithTransforms(target,tr); - - cpkcs.setKeyInformation(); - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0",erg)); - } - - /** - * Method create319: - * SignedInfo/Reference appears two times: - * the first reference points to an enveloped dsig:Object, - * the seconde reference points to an external File - * @throws Exception - */ - public void create319() throws Exception { - String testNumber = "319"; - - - // Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); // Create from whole cloth - -// Element root = (Element) document.createElement("Data"); - // root.appendChild(document.createTextNode(readFileCR(configuration_.getProperty("baseDir")+"resources/test-ee2003_normal.derbase64.enc.bak")) ); - //root.appendChild(document.createTextNode("Hallo\nHallo\nHallo")); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(true,"Dies sind Testdaten"); - //cpkcs.createReferenceEnvElement(root); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(); - - Document sign = cpkcs.returnSig(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,false,null)); - - /*String erg = "Dies sind Testdaten" + - "</XMLContent>\n" + - " </HashInputData>\n" + - " <HashInputData>\n" + - "<XMLContent xml:space=\"preserve\">" + - readFileCR(configuration_.getProperty("baseDir")+"resources/testSimple.txt"); */ - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(),testNumber,"0","Dies sind Testdaten",readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt"))); - } - - /** - * Method create320: - * The element KeyInfo does NOT contain the X509-certificate but - * an URI pointing to an external xml-encoded X509-file - * @throws Exception - */ - public void create320() throws Exception { - String testNumber = "320"; - - //RetrievalMethdos instead of the integratede Keys - - //URI fileURI = new URI(configuration_.getProperty("baseDir") + "resources/test-ee2003_normal.der"); - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/X509Data.xml"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#X509Data"); - //URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#rawX509Certificate"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - - Document sign = cpkcs.returnSig(); - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResFile(testNumber), createResponse(readFileCR(configuration_.getProperty("webbaseDir") + "resources/SignatureVX005Cert.xml"),testNumber,"0")); - } - -public void create320_2() throws Exception { - String testNumber = "320_2"; - - //RetrievalMethdos instead of the integratede Keys - - //URI fileURI = new URI(configuration_.getProperty("baseDir") + "resources/test-ee2003_normal.der"); - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/TEMPX509Data.xml"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#X509Data"); - //URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#rawX509Certificate"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - -// Supplement supp = new Supplement(); - -// supp.addXMLContent(configuration_.getProperty("webbaseDir") + "resources/X509Data.xml",readFileCR(configuration_.getProperty("webbaseDir") + "resources/X509Data.xml")); -// supp.closeSupplement(); - Document sign = cpkcs.returnSig(); - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,true,configuration_.getProperty("webbaseDir") + "resources/TEMPX509Data.xml")); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResFile(testNumber), createResponse(readFileCR(configuration_.getProperty("webbaseDir") + "resources/SignatureVX005Cert.xml"),testNumber,"0")); - } - - - /** - * Method create321. - * The element KeyInfo does NOT contain the X509-certificate but - * an URI pointing to an external raw X509-file - * @throws Exception - */ - public void create321() throws Exception { - String testNumber = "321"; - - //RetrievalMethdos instead of the integratede Keys - - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/test-ee2003_normal.der"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#rawX509Certificate"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - Document sign = cpkcs.returnSig(); String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResFile(testNumber), createResponse(readFileCR(configuration_.getProperty("webbaseDir") + "resources/SignatureVX005Cert.xml"),testNumber,"0")); - } - - - /** - * Method create322. - * The reference in the signature points with an xpointer - * to the ID of an embedded valid manifest dsig:object - * @throws Exception - */ -public void create322() throws Exception { - String testNumber = "322"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - URI fileURI1 = new URI(configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - Element elem = cpkcs.createReferenceWithManifest(fileURI1,"manifestObject"); - - cpkcs.setKeyInformation(); - Document sign = cpkcs.returnSig(); String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - - String response = createResponsePart(cpkcs.getX509CertString()) + - "<HashInputData><Base64Content>"+ - Base64Utils.encode(stripNLCR(convertManifestToString(elem)).getBytes()) + - "</Base64Content></HashInputData>"+ - vxBean.createSignatureCheck("0")+ - vxBean.createXMLDSIGManifestCheck("0","","1")+ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - - writeFile(vxResFile(testNumber), response); - } - /** - * Method create323: - * There are two references in the signature pointing - * with xpointer to two embedded valid manifest dsig:objects - * @throws Exception - */ - public void create323() throws Exception { - String testNumber = "323"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - URI fileURI1 = new URI(configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - URI fileURI2 = new URI(configuration_.getProperty("webbaseDir") + "resources/testXML.txt"); - Element man1 = cpkcs.createReferenceWithManifest(fileURI1,"manifestObject"); - - //HINWEIS: Durch das 2malige Aufrufen wird ein WEITERES dsig:Object ELEMENT erzeugt... darf das so sein...??? - - Element man2 = cpkcs.createReferenceWithManifest(fileURI2,"manifestObject2"); - cpkcs.setKeyInformation(); - Document sign = cpkcs.returnSig(); - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - String response = createResponsePart(cpkcs.getX509CertString()) + - "<HashInputData><Base64Content>"+ - Base64Utils.encode(stripNLCR(convertManifestToString(man1)).getBytes()) + - "</Base64Content></HashInputData>"+ - "<HashInputData><Base64Content>"+ - Base64Utils.encode(stripNLCR(convertManifestToString(man2)).getBytes()) + - "</Base64Content></HashInputData>"+ - vxBean.createSignatureCheck("0")+ - vxBean.createXMLDSIGManifestCheck("0","","1")+ - vxBean.createXMLDSIGManifestCheck("0","","2")+ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - - writeFile(vxResFile(testNumber), response); - - } - public void create324() throws Exception { - String testNumber = "324"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - URI fileURI1 = new URI(configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - URI fileURI2 = new URI(configuration_.getProperty("webbaseDir") + "resources/testXML.txt"); - Element man = cpkcs.createReferencesWithManifest(fileURI1,"manifestObject",fileURI2); - - //HINWEIS: Durch das 2malige Aufrufen wird ein WEITERES dsig:Object ELEMENT erzeugt... darf das so sein...??? - cpkcs.setKeyInformation(); - Document sign = cpkcs.returnSig(); - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - sign, - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - String response = createResponsePart(cpkcs.getX509CertString()) + - "<HashInputData><Base64Content>"+ - Base64Utils.encode(stripNLCR(convertManifestToString(man)).getBytes()) + - "</Base64Content></HashInputData>"+ - vxBean.createSignatureCheck("0")+ - vxBean.createXMLDSIGManifestCheck("0","","1")+ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - - writeFile(vxResFile(testNumber), response); - - } - - /** - * Method create325. - * @throws Exception - */ - public void create325() throws Exception { - String testNumber = "325"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - - Element mani = cpkcs.createReferenceWithManifest(new URI("#xpointer(id('envelopedData')/node())"),"manifestObject"); - cpkcs.createEnvelopedDataObject("envelopedData",readFile(configuration_.getProperty("baseDir")+"resources/testSimple.txt")); - - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - String response = createResponsePart(cpkcs.getX509CertString()) + - "<HashInputData><Base64Content>"+ - Base64Utils.encode(stripNLCR(convertManifestToString(mani)).getBytes()) + - "</Base64Content></HashInputData>"+ - vxBean.createSignatureCheck("0")+ - vxBean.createXMLDSIGManifestCheck("1","1","1")+ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - - writeFile(vxResFile(testNumber), response); - } - - public void create326() throws Exception { - String testNumber = "326"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - - Element mani = cpkcs.createReferenceWithManifest(new URI("#xpointer(id('envelopedData')/node())"),"manifestObject"); - cpkcs.createEnvelopedDataObject("envelopedData",readFileCR(configuration_.getProperty("baseDir")+"resources/testSimple.txt")); - - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(false,false,null)); - - request = replaceString(request,"<dsig:Object Id=\"envelopedData\">","<dsig:Object Id=\"envelopedData\">Dies sind veraenderte Daten und die Ursprungsdaten: \n"); - - writeFile(vxReqFile(testNumber),request); - - String response = createResponsePart(cpkcs.getX509CertString()) + - vxBean.createSignatureCheck("0")+ - vxBean.createXMLDSIGManifestCheck("1","1","1")+ - vxBean.createCertificateCheck("0")+ - "</VerifyXMLSignatureResponse>"; - - - writeFile(vxResFile(testNumber), response); - } - - /** - * Method create327: The certificate comes as raw data and is converted to a dsig:object with - * base64-data, the KeyInfo has a retrievalMethod pointing to that object and transforming the - * data back to raw-data for using that to create the signature - * @throws Exception - */ - public void create327() throws Exception { - - String testNumber = "327"; - - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/test-ee2003_normal.der"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#rawX509Certificate"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testSimple.txt"); - - //DER-encoded RAW-Zertifikat zu Binary64 konvertieren - - //String tmp = readBinaryFileAsBase64(fileURI.getPath()); : Funktioniert nicht mehr wegen http-addi - - //dsig:Object mit den Binary64-Daten erzeugen (==> CRs weglassen!!!!!) - cpkcs.createEnvelopedDataObject("rawCertAsBase64",readFileCR(fileURI.toString()+"base64.enc")); - - //Neue Transformation erzeugen, um die Base64-Daten zurückzuwandeln - Transform[] tr = new Transform[1]; - tr[0] = new TransformImplBase64Decode(); - InputStream s = getHttpInputStream(fileURI.toString() + "base64.enc"); - tr[0].setInput(s,null); - - //Neues KeyInfo-Objekt erzeugen, wobei nicht die Zertifikate sondern - //nur eine RetrievalMethod angegeben wird, die auf das oben erzeugte Base64-dsig:Object verweist - cpkcs.setKeyInformation(true, new URI("#xpointer(id('rawCertAsBase64')/node())") , typeURI, tr); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - - cpkcs.setKeyInformation(1); - - writeFile(vxResFile(testNumber), createResponse(cpkcs.getX509CertString(), testNumber,"0")); - } - - /** - * 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) -{ - return createRequestStart(testNumber, useDate,changeHours,""); - -} - - private String createRequestStart(String testNumber, boolean useDate, int changeHours, String attribut) - { - return createRequestStart(testNumber, useDate,changeHours,attribut,""); - } - private String createRequestStart(String testNumber, boolean useDate, int changeHours, String attribut,String dtd) - {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"; - - if(dtd!=null && !dtd.trim().equals("")) - reqStart += dtd; - - reqStart+= "<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 "+attribut+">\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; - } - - - /** - * 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 += " <SupplementProfile>\n" + - " <Content Reference=\"" + supplementReference.toString() + "\">\n" + - " <XMLContent xml:space=\"preserve\">"+readFileCR(supplementReference.toString())+"</XMLContent>\n" + - " </Content>\n" + - " </SupplementProfile>\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 x509cert, String testNumber, String signatureCheckCode) throws Exception { - // - vxBean.init(configuration_.getProperty("webbaseDir")+ "resources/" + "test-ee2003_normal_extract.cer"); - - 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" + " "; - /*res += "<XMLContent xml:space=\"preserve\">"+readFileCR( - configuration_.getProperty("baseDir") - + "resources/testSimple.txt")+ - "</XMLContent>";*/ - res += "<Base64Content>"+readBinaryFileAsBase64_new((configuration_.getProperty("baseDir")+ "resources/testSimple.txt"))+"</Base64Content>"; - - res += vxBean.getFooterSignatureCheck(signatureCheckCode, "0"); - - return res; - } - - private String createResponseL(String x509cert, String testNumber, String signatureCheckCode,String filename) throws Exception { - // - vxBean.init(configuration_.getProperty("webbaseDir")+ "resources/" + "test-ee2003_normal_extract.cer"); - - 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 += replaceString(vxBean.getFooterSignatureCheck(signatureCheckCode, "0"),"</HashInputData>",""); - - return res; - } - - private String createResponse(String x509cert, String testNumber, String signatureCheckCode,int code) throws Exception { - // - vxBean.init(configuration_.getProperty("webbaseDir")+ "resources/" + "test-ee2003_normal_extract.cer"); - - 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 += " <SignatureCheck>\n" + - " <Code>1</Code><Info><FailedReference>1</FailedReference></Info>\n" + - " </SignatureCheck>\n" + - " <CertificateCheck>\n" + - " <Code>0</Code>\n" + - " </CertificateCheck>\n" + - "</VerifyXMLSignatureResponse>";; - - return res; - } - - - /** - * Method createResponse. - * @param testNumber - * @param signatureCheckCode - * @return String - * @throws Exception - */ - private String createResponse(String x509cert, String testNumber, String signatureCheckCode,int code,String filename) throws Exception { - // - vxBean.init(configuration_.getProperty("webbaseDir")+ "resources/" + "test-ee2003_normal_extract.cer"); - - 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" + " "; - /*res += "<XMLContent xml:space=\"preserve\">"+readFileCR( - configuration_.getProperty("baseDir") - + "resources/testSimple.txt")+ - "</XMLContent>";*/ - if(filename.startsWith("text:")) - res += "<Base64Content>"+Base64Utils.encode(filename.substring(5).getBytes())+"</Base64Content>"; - else - res += "<Base64Content>"+readBinaryFileAsBase64_new((configuration_.getProperty("baseDir")+ filename))+"</Base64Content>"; - - res += vxBean.getFooterSignatureCheck(signatureCheckCode, "0"); - - return res; - } - -/** - * Method createResponse. - * @param testNumber - * @param signatureCheckCode - * @return String - * @throws Exception - */ - private String createResponse(String x509cert, String testNumber, String signatureCheckCode,String iss,String subject,String serial) throws Exception { - // - vxBean.init(configuration_.getProperty("webbaseDir")+ "resources/" + "test-ee2003_normal_extract.cer"); - - String res = null; - - res = vxBean.getHeader(); - res += subject; - res += " <dsig:X509IssuerSerial>\n"; - res += iss; - res += serial; - res += " </dsig:X509IssuerSerial>\n" - + x509cert - + " </dsig:X509Data>\n" - + " </SignerInfo>\n"; - res += " <HashInputData>\n" + " "; - /*res += "<XMLContent xml:space=\"preserve\">"+readFileCR( - configuration_.getProperty("baseDir") - + "resources/testSimple.txt")+ - "</XMLContent>";*/ - res += "<Base64Content>"+readBinaryFileAsBase64_new((configuration_.getProperty("baseDir")+ "resources/testSimple.txt"))+"</Base64Content>"; - - res += vxBean.getFooterSignatureCheck(signatureCheckCode, "0"); - - return res; - } - - - private String createResponse(String x509cert, 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" - + x509cert - + " </dsig:X509Data>\n" - + " </SignerInfo>\n"; - res += " <HashInputData>\n"; - /* " <XMLContent xml:space=\"preserve\">"+ - hashData + - "</XMLContent>\n";*/ - res += "<Base64Content>"+Base64Utils.encode(hashData.getBytes())+"</Base64Content>"; - System.out.println(res); - res += vxBean.getFooterSignatureCheck(signatureCheckCode, "0"); - System.out.println(res); - - return res; - } - - private String createResponse(String x509cert, String testNumber, String signatureCheckCode, String hashData,String hashData2) 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 xml:space=\"preserve\">"+ - hashData + - "</XMLContent>\n";*/ - res += "<Base64Content>"+Base64Utils.encode(hashData.getBytes())+"</Base64Content>"; - res += "</HashInputData><HashInputData>"; - res += "<Base64Content>"+Base64Utils.encode(hashData2.getBytes())+"</Base64Content>"; - res += vxBean.getFooterSignatureCheck(signatureCheckCode, "0"); - - return res; - } - - private String createResponseWithoutHashInputData(String x509cert, String testNumber, String signatureCheckCode,boolean dsig) 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" - + " <SignatureCheck>\n" + - " <Code>" + signatureCheckCode + "</Code>\n" + - " </SignatureCheck>\n"; - - if(dsig) res+=vxBean.createXMLDSIGManifestCheck("0","","1"); - res+= " <CertificateCheck>\n" + - " <Code>0</Code>\n" + - " </CertificateCheck>\n" + - "</VerifyXMLSignatureResponse>"; - - return res; - } - - private String createResponseWithoutHashInputData(String x509cert, 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" - + x509cert - + " </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 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"; - - res +=x509cert; - - res += " </dsig:X509Data>\n" - + " </SignerInfo>\n"; - /*res += " <HashInputData>\n" + " <XMLContent>"; - res += readFile( - configuration_.getProperty("baseDir") - + "resources/testSimple.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 - { - URL targetUrl = new URL(url); - HttpURLConnection h = (HttpURLConnection)targetUrl.openConnection(); - return h.getInputStream(); - } - -private String convertManifestToString(Element e) throws Exception - { - String result =(new DOMWriterImpl(true)).writeToString(e); - result = replaceString(result,"<?xml version=\"1.0\"?>",""); - result = replaceStringAll(result,"'","'"); - result = replaceStringAll(result,"#sha1\"/><dsig:","#sha1\"></dsig:DigestMethod><dsig:"); - - //result = replaceString(result," xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\"",""); - return result; - } - - private String stripNLCR(String input) - { - String output = replaceStringAll(input,"\n",""); - output = replaceStringAll(output,"\r",""); - return output; - } - - public static String replaceStringAll( - String input, - String oldPart, - String newPart) - { - - String erg = null; - - int pos = input.indexOf(oldPart); - if(pos==-1) return input; - - while(true) - { - - //First Part - pos = input.indexOf(oldPart); - if(pos==-1) break; - erg = input.substring(0, pos); - - //Insert new Part - erg += newPart; - - //insert REST - erg - += input.substring( - input.indexOf(oldPart) + oldPart.length(), - input.length()); - - input = erg; - } - return erg; - } - - -} - diff --git a/spss.test/src/testgenerator/TestGeneratorVX2.java b/spss.test/src/testgenerator/TestGeneratorVX2.java deleted file mode 100644 index 96612da9e..000000000 --- a/spss.test/src/testgenerator/TestGeneratorVX2.java +++ /dev/null @@ -1,1600 +0,0 @@ -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(); - } - - - -} diff --git a/spss.test/src/testgenerator/TestGeneratorVXErrors.java b/spss.test/src/testgenerator/TestGeneratorVXErrors.java deleted file mode 100644 index 3c9db0dad..000000000 --- a/spss.test/src/testgenerator/TestGeneratorVXErrors.java +++ /dev/null @@ -1,1775 +0,0 @@ -package testgenerator; -import iaik.ixsil.algorithms.DigestAlgorithmImplSHA1; -import iaik.ixsil.algorithms.Transform; -import iaik.ixsil.algorithms.TransformImplBase64Decode; -import iaik.ixsil.algorithms.TransformImplXSLT; -import iaik.ixsil.util.URI; -import iaik.utils.Base64OutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -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; - -/** - * @author stephan - */ -public class TestGeneratorVXErrors 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 { - - etsiURI = new URI("http://uri.etsi.org/01903/v1.1.1#SignedProperties"); - - vxBean = new VXResponseBean(); - - TestGeneratorVXErrors testcase = new TestGeneratorVXErrors(); - testcase.createVXConfig(); - - - //testcase.create051(); - testcase.create052(); - testcase.create053(); - testcase.create054(); - testcase.create055(); - - testcase.create151(); - //testcase.create152(); - testcase.create153(); - testcase.create154(); -//N.A.: testcase.create155(); - - testcase.create251(); - //testcase.create252(); - //testcase.create252_2(); - testcase.create253(); - //testcase.create254(); - //testcase.create255(); - //testcase.create256(); - - testcase.create351(); - testcase.create352(); - //testcase.create353(); - testcase.create354(); - //testcase.create355(); - testcase.create356(); - testcase.create357(); - //testcase.create358(); - testcase.create359(); - testcase.create360(); - testcase.create360_2(); - //testcase.create361(); - testcase.create362(); - testcase.create363(); - testcase.create364(); - testcase.create365(); - testcase.create366(); - testcase.create367(); - //testcase.create368(); - testcase.create369(); - testcase.create370(); - - - } - - /* ==================================================================================================== */ - - public TestGeneratorVXErrors() 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(); - } - - /* ==================================================================================================== */ - - public void create051() throws Exception { - String testNumber = "051"; - //Create a Request with number 051, Time in the future (+24 hours) - // and with the Date and ReturnHashInputDate Elements present - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,24), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"0000"); - - } - /** - * Method create052. - * @throws Exception - */ - public void create052() throws Exception { - String testNumber = "052"; - //Create a Request with number 052, with current Time (+0 hours) - // and with the Date and ReturnHashInputDate Elements present - - // BUT there is in invalid Element to crash validation against XMLDsig - // </dsig:SignedInfo> is replaces by </dsig:NoValidDSigSignedInfo> - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = - replaceString( - request, - "<dsig:SignedInfo>", - "<dsig:NoValidDSigSignedInfo>"); - request = - replaceString( - request, - "</dsig:SignedInfo>", - "</dsig:NoValidDSigSignedInfo>"); - - writeFile(vxReqFile(testNumber), request); - writeFile(vxResErrFile(testNumber),"1100"); - } - - /** - * Method create053. - * @throws Exception - */ - public void create053() throws Exception { - String testNumber = "053"; - //Create a Request with number 053, with current Time (+0 hours) - // and with the Date and ReturnHashInputDate Elements present - - // BUT with an invalid XPath expression - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = - replaceString( - request, - "<VerifySignatureLocation>//dsig:Signature</VerifySignatureLocation>", - "<VerifySignatureLocation>//invalid XPath Expression</VerifySignatureLocation>"); - - writeFile(vxReqFile(testNumber), request); - writeFile(vxResErrFile(testNumber),"2212"); - } - /** - * Method create054. - * @throws Exception - */ - public void create054() throws Exception { - String testNumber = "054"; - - //Create a Request with number 053, with current Time (+0 hours) - // and with the Date and ReturnHashInputDate Elements present - - // BUT with an valid XPath expression not referencing a valid element - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = - replaceString(request, "//dsig:Signature", "//dsig:NoValidElement"); - writeFile(vxReqFile(testNumber), request); - writeFile(vxResErrFile(testNumber),"2212"); - } - public void create055() throws Exception { - - String testNumber = "055"; - - //Create a Request with number 001, the current Time (+0 hours) - // and with the Date and ReturnHashInputDate Elements present - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = - replaceString(request, - "TrustProfile1", "InvalidProfile"); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"2203"); - - - // writeFile(vxResFile(testNumber), createResponse(testNumber,"0")); - } - public void create151() throws Exception { - - String testNumber = "151"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - - - String requestEnd = createSignatureInfoEnd()+ - createRequestShortEnd(false); - - String request = - makeOutputFile( - createRequestStart(testNumber + " an URI referenced in dsig:Signature does not resolve and no SupplementProfile is available",true,0), - cpkcs.returnSig(), - requestEnd); - - request = replaceString(request, configuration_.getProperty("webbaseDir")+"resources/testDaten.txt","http://no.uritoresolve.com" ); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"2264"); - - } - public void create152() throws Exception { - - String testNumber = "152"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - - Supplement supp = new Supplement(); - supp.addMetaInfo("text/plain","http://www.buergerkarte.at"); - supp.addBase64Content(configuration_.getProperty("webbaseDir")+"resources/testDaten.txt", - readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/testDaten.txt")); - supp.closeSupplement(); - //supp.addProfileID("Some ID"); - - String requestEnd = createSignatureInfoEnd()+ - supp.getSupplement() + createRequestShortEnd(false); - - String request = - makeOutputFile( - createRequestStart(testNumber + "- MimeType",true,0), - cpkcs.returnSig(), - requestEnd); - - request = replaceString(request, "text/plain","no valid MIME-Type" ); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"1100"); - } - - public void create153() throws Exception { - - String testNumber = "153"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - - String requestEnd = - createSignatureInfoEnd()+ - "<SupplementProfileID>NO VALID SUPPLEMENT PROFILE ID</SupplementProfileID>" + - createRequestShortEnd(false); - - String request = - makeOutputFile( - createRequestStart(testNumber + " - invalid SupplementProfileID",true,0), - cpkcs.returnSig(), - requestEnd); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"2267"); - } - - public void create154() throws Exception { - - String testNumber = "154"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - - Supplement supp = new Supplement(); - supp.addMetaInfo("text/plain","http://www.buergerkarte.at"); - supp.addBase64Content(configuration_.getProperty("webbaseDir")+"resources/testDaten.txt", - readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/testDaten.txt")); - supp.closeSupplement(); - //supp.addProfileID("Some ID"); - - String requestEnd = createSignatureInfoEnd()+ - supp.getSupplement() + createRequestShortEnd(false); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - requestEnd); - request = replaceString(request,"<Base64Content>","<Base64Content>AAAAAAAAAAAAAAAAAA"); - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"1100"); - } - -public void create155() throws Exception { - String testNumber = "155"; -/* CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - - Supplement supp = new Supplement(); - supp.addXMLContent(configuration_.getProperty("webbaseDir")+"resources/testDaten.txt", readFileCR(configuration_.getProperty("webbaseDir")+"resources/testDaten.txt")); - supp.closeSupplement(); - - String requestEnd = - createSignatureInfoEnd()+ - supp.getSupplement()+ - createRequestShortEnd(false); - - String request = - makeOutputFile( - createRequestStart(testNumber+" - Supplement/Content/XMLContent does not match to the signature",true,0), - cpkcs.returnSig(), - requestEnd); -*/ -// request = replaceString(request,"<XMLContent>","<XMLContent><OPEN_ELEMENT>"); - - writeFile(vxReqFile(testNumber),"N.A."); - writeFile(vxResErrFile(testNumber),"0000"); - } - - - -public void create251() throws Exception - { String testNumber = "251"; - - 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("InvalidTransformsProfile"); - - String request = - makeOutputFile( - createRequestStart("251 - VerifyTransformsInfoID: invalidID",true,0), - cpkcs.returnSig(), - createSignatureInfoEnd() + smcp.returnDoc() - + createRequestShortEnd(false)); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"2268"); - } - - - public void create252() throws Exception - { String testNumber = "252"; - - 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("252 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"); - } - -public void create252_2() throws Exception - { String testNumber = "252_2"; - - 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("252_2 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"); - } - -public void create253() throws Exception - { String testNumber = "253"; - - 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("Base64Content",readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/"+ filename)); - - String request = - makeOutputFile( - createRequestStart("253 mismatching dsig:Transform/@Algorithm and dsig:Transform content",true,0), - cpkcs.returnSig(), - createSignatureInfoEnd() + smcp.returnDoc() - + createRequestShortEnd(false)); - - request = replaceString(request, - "http://www.w3.org/TR/1999/REC-xslt-19991116","MismatchingTransformAlgorithm"); - request = replaceString(request, - "http://www.w3.org/TR/1999/REC-xslt-19991116","http://www.w3.org/TR/1999/REC-xpath-19991116"); - request = replaceString(request,"MismatchingTransformAlgorithm", - "http://www.w3.org/TR/1999/REC-xslt-19991116"); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"2202"); - } -public void create254() throws Exception - { String testNumber = "254"; - - 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("webbaseDir")+"resources/" + filename)); - - String request = - makeOutputFile( - createRequestStart("254 - 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"); - } - -public void create255() throws Exception - { String testNumber = "255"; - - 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("255 kein TransformParameter element obwohl in Transforms URIs referenziert werden",true,0), - cpkcs.returnSig(), - createSignatureInfoEnd() + smcp.returnDoc() - + createRequestShortEnd(false)); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"2204"); - } - -public void create256() throws Exception - { String testNumber = "256"; - - 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("256 1 VerifyTransformsInfoID ==> Passt aber nicht zur Transformation (XSLT <==> Canonisiserung)",true,0), - cpkcs.returnSig(), - createSignatureInfoEnd() + smcp.returnDoc() - + createRequestShortEnd(false)); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2204"); - } - -public void create351() throws Exception { - - String testNumber = "351"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - String request = - makeOutputFile( createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - request = replaceString( request, - "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", - "http://www.w3.org/TR/2001/unknownCanonicalzationMethod"); - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"2240"); - } - - -public void create352() throws Exception { - - String testNumber = "352"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - String request = - makeOutputFile( createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - request = replaceString( request, - "http://www.w3.org/2000/09/xmldsig#rsa-sha1", - "http://www.w3.org/TR/2001/unknownSignatureMethod"); - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"2240"); - } -public void create353()throws Exception { - - String testNumber = "353"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,"#xpointer(id('envelopedData'))"); - cpkcs.createEnvelopedDataObject("envelopedData",readFileCR(configuration_.getProperty("webbaseDir")+"resources/testDaten.txt")); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = - replaceString( - request, - "#xpointer(id('envelopedData'))", - "#xpointer(id('unknownURITarget'))"); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2264"); - } - public void create354() throws Exception { - - String testNumber = "354"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(false,configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.setKeyInformation(); - String request = - makeOutputFile( createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - request = replaceString( request, - "http://www.w3.org/2000/09/xmldsig#sha1", - "http://www.w3.org/TR/2001/unknownDigestMethod"); - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"2240"); - } - public void create355() throws Exception { - - String testNumber = "355"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(true,readFileCR(configuration_.getProperty("webbaseDir")+"resources/testDaten.txt")); - cpkcs.setKeyInformation(); - String request = - makeOutputFile( createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - request = replaceString( request, - "<dsig:DigestValue>", - "<dsig:DigestValue>WrongData and the original:"); - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"0000"); - } - public void create356() throws Exception { - - String testNumber = "356"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - //Erzeugen der Base64-Daten -// String tmp = readBinaryFileAsBase64(configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - - URI target = new URI(configuration_.getProperty("webbaseDir")+"resources/testDaten.txtbase64.enc"); - - Transform[] tr = new Transform[1]; - tr[0] = new TransformImplBase64Decode(); - InputStream s = getHttpInputStream(target.toString()); - tr[0].setInput(s,null); - - cpkcs.createReferenceWithTransforms(target,tr); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - request = replaceString( request, - "http://www.w3.org/2000/09/xmldsig#base64", - "http://www.w3.org/TR/2001/unknownTransformsMethod"); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2240"); - } - public void create357() throws Exception { - - String testNumber = "357"; - - 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.setKeyInformation(); - - - String request = - makeOutputFile( - createRequestStart("357 nicht zu Reference/Transforms/Transform/@Algorithm passender Inha",true,0), - cpkcs.returnSig(), - createSignatureInfoEnd() - + createRequestShortEnd(false)); - - request = replaceString(request, "http://www.w3.org/TR/1999/REC-xslt-19991116", - "http://www.w3.org/TR/1999/REC-xpath-19991116"); - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2240"); - } - - public void create358() throws Exception { - - String testNumber = "358"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - //cpkcs.createReference(true,"Dies sind testdaten"); - - URI target = new URI(configuration_.getProperty("webbaseDir")+"resources/testDaten.txtBase64.enc"); - - // cpkcs.createEnvelopedDataObject("envelopedData",readBinaryFileAsBase64(configuration_.getProperty("webbaseDir")+"resources/testDaten.txt")); - - Transform[] tr = new Transform[1]; - tr[0] = new TransformImplBase64Decode(); - InputStream s = getHttpInputStream(target.toString()); - tr[0].setInput(s,null); - - cpkcs.createReferenceWithTransforms(target,tr); - //cpkcs.createReference(false, "file:/"+ configuration_.getProperty("webbaseDir")+"resources/test_wo_canonicalisation.XML"); - //cpkcs.createReference(false, "file:/"+ configuration_.getProperty("webbaseDir")+"resources/test_w_canonicalisation.XML"); -// cpkcs.createReferenceWithManifest(new URI("file:/"+ configuration_.getProperty("webbaseDir")+"resources/test_w_canonicalisation.XML"),"canonicalizedData"); - - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request, - "<dsig:SignatureValue>","<dsig:SignatureValue>abcd"); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2240"); - } - - public void create359() throws Exception { - - String testNumber = "359"; - - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/X509Data.xml"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#X509Data"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(true,readFileCR(configuration_.getProperty("webbaseDir") + "resources/testDaten.txt")); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request,"<dsig:KeyInfo>",""); - request = replaceString(request,"<dsig:RetrievalMethod Type=\"http://www.w3.org/2000/09/xmldsig#X509Data\" URI=\""+configuration_.getProperty("webbaseDir") + "resources/X509Data.xml\"/>",""); - request = replaceString(request,"</dsig:KeyInfo>",""); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2243"); - } - public void create360() throws Exception { - - String testNumber = "360"; - - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/X509Data.xml"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#X509Data"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(true,readFileCR(configuration_.getProperty("webbaseDir") + "resources/testDaten.txt")); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request,"<dsig:RetrievalMethod Type=\"http://www.w3.org/2000/09/xmldsig#X509Data\" URI=\""+configuration_.getProperty("webbaseDir") + "resources/X509Data.xml\"/>", - "<dsig:X509Data><dsig:X509SubjectName>Some kind of Subject</dsig:X509SubjectName></dsig:X509Data>"); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2240"); - } - - public void create360_2() throws Exception { - - String testNumber = "360_2"; - - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/X509Data.xml"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#X509Data"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(true,readFileCR(configuration_.getProperty("webbaseDir") + "resources/testDaten.txt")); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request,"<dsig:RetrievalMethod Type=\"http://www.w3.org/2000/09/xmldsig#X509Data\" URI=\""+configuration_.getProperty("webbaseDir") + "resources/X509Data.xml\"/>", - "<dsig:KeyName>Some kind of string as KeyName</dsig:KeyName>"); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2240"); - } - - public void create361() throws Exception { - - String testNumber = "361"; - - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/X509Data.xml"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#X509Data"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(true,readFileCR(configuration_.getProperty("webbaseDir") + "resources/testDaten.txt")); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request,"<dsig:RetrievalMethod Type=\"http://www.w3.org/2000/09/xmldsig#X509Data\" URI=\""+configuration_.getProperty("webbaseDir") + "resources/X509Data.xml\"/>", - " <dsig:X509Data>\n"+ - " <dsig:X509Certificate>"+ - readFileCR(configuration_.getProperty("webbaseDir") + "resources/tests.cer.b64") + - "</dsig:X509Certificate>\n"+ - " </dsig:X509Data>\n"); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2243"); - } - - public void create362() throws Exception { - - String testNumber = "362"; - - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/X509Data.xml"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#X509Data"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(true,readFileCR(configuration_.getProperty("webbaseDir") + "resources/testDaten.txt")); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request,"<dsig:RetrievalMethod Type=\"http://www.w3.org/2000/09/xmldsig#X509Data\" URI=\""+configuration_.getProperty("webbaseDir") + "resources/X509Data.xml\"/>", - " <dsig:X509Data>\n"+ - " <dsig:X509Certificate>"+ - readFileCR(configuration_.getProperty("webbaseDir")+"resources/testDaten.txtbase64.enc") + - "</dsig:X509Certificate>\n"+ - " </dsig:X509Data>\n"); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2240"); - } - public void create363() throws Exception { - - String testNumber = "363"; - - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/X509Data.xml"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#X509Data"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(true,readFileCR(configuration_.getProperty("webbaseDir") + "resources/testDaten.txt")); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request,"<dsig:RetrievalMethod Type=\"http://www.w3.org/2000/09/xmldsig#X509Data\" URI=\""+configuration_.getProperty("webbaseDir") + "resources/X509Data.xml\"/>", - " <dsig:X509Data>\n"+ - " <dsig:X509Certificate>"+ - "( no BASE64 data )" + - "</dsig:X509Certificate>\n"+ - " </dsig:X509Data>\n"); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"1100"); - } - - public void create364() throws Exception { - - String testNumber = "364"; - - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/X509Data.xml"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#X509Data"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(true,readFileCR(configuration_.getProperty("webbaseDir") + "resources/testDaten.txt")); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request, - "http://www.w3.org/2000/09/xmldsig#X509Data", - "http://www.w3.org/2000/09/noValidRetrievalMethodType"); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2240"); - } - public void create365() throws Exception { - - String testNumber = "365"; - - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/X509Data.xml"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#X509Data"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - cpkcs.createReference(true,readFileCR(configuration_.getProperty("webbaseDir") + "resources/testDaten.txt")); - cpkcs.setKeyInformation(false, fileURI, typeURI, null); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request, - configuration_.getProperty("webbaseDir") + "resources/X509Data.xml", - configuration_.getProperty("webbaseDir") + "resources/test-ee2003_normal.der"); - - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2240"); - } - - public void create366() throws Exception { - - String testNumber = "366"; - - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/test-ee2003_normal.der"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#rawX509Certificate"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - - //DER-encoded RAW-Zertifikat zu Binary64 konvertieren - // String tmp = readBinaryFileAsBase64(fileURI.getPath()); - //dsig:Object mit den Binary64-Daten erzeugen (==> CRs weglassen!!!!!) - cpkcs.createEnvelopedDataObject("rawCertAsBase64",readFileCR(fileURI.toString()+"base64.enc")); - - //Neue Transformation erzeugen, um die Base64-Daten zurückzuwandeln - Transform[] tr = new Transform[1]; - tr[0] = new TransformImplBase64Decode(); - InputStream s = getHttpInputStream(fileURI.toString()+ "base64.enc"); - tr[0].setInput(s,null); - - //Neues KeyInfo-Objekt erzeugen, wobei nicht die Zertifikate sondern - //nur eine RetrievalMethod angegeben wird, die auf das oben erzeugte Base64-dsig:Object verweist - cpkcs.setKeyInformation(true, new URI("#xpointer(id('rawCertAsBase64')/node())") , typeURI, tr); - - String request = makeOutputFile( createRequestStart(testNumber,true,0), cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request, "http://www.w3.org/2000/09/xmldsig#base64", - "http://Invalid.URI.com"); - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2240"); - } - public void create367() throws Exception { - - String testNumber = "367"; - - URI fileURI = new URI(configuration_.getProperty("webbaseDir") + "resources/test-ee2003_normal.der"); - URI typeURI = new URI("http://www.w3.org/2000/09/xmldsig#rawX509Certificate"); - - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - - cpkcs.createReference(false,configuration_.getProperty("webbaseDir") + "resources/testDaten.txt"); - - //DER-encoded RAW-Zertifikat zu Binary64 konvertieren - // String tmp = readBinaryFileAsBase64(fileURI.getPath()); - //dsig:Object mit den Binary64-Daten erzeugen (==> CRs weglassen!!!!!) - cpkcs.createEnvelopedDataObject("rawCertAsBase64",readFileCR(fileURI.toString()+"base64.enc")); - - //Neue Transformation erzeugen, um die Base64-Daten zurückzuwandeln - Transform[] tr = new Transform[1]; - tr[0] = new TransformImplBase64Decode(); - InputStream s = getHttpInputStream(fileURI.toString()+ "base64.enc"); - tr[0].setInput(s,null); - - //Neues KeyInfo-Objekt erzeugen, wobei nicht die Zertifikate sondern - //nur eine RetrievalMethod angegeben wird, die auf das oben erzeugte Base64-dsig:Object verweist - cpkcs.setKeyInformation(true, new URI("#xpointer(id('rawCertAsBase64')/node())") , typeURI, tr); - - String request = makeOutputFile( createRequestStart(testNumber,true,0), cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request, "http://www.w3.org/2000/09/xmldsig#rawX509Certificate", - "http://www.w3.org/2000/09/xmldsig#X509Data"); - writeFile(vxReqFile(testNumber),request); - - writeFile(vxResErrFile(testNumber),"2240"); - } - - public void create368() throws Exception { - String testNumber = "368"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - URI fileURI1 = new URI(configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.createReferenceWithManifest(fileURI1,"manifestObject"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request, "http://www.w3.org/2000/09/xmldsig#Manifest", - "http://No.valid_manifest_URI.com"); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"2240"); - } - - public void create369() throws Exception { - String testNumber = "369"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - URI fileURI1 = new URI(configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.createReferenceWithManifest(fileURI1,"manifestObject"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - request = replaceString(request, "#xpointer(id('manifestObject'))", - "#xpointer(id('NoValidManifestObject'))"); - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"2262"); - } - public void create370() throws Exception { - String testNumber = "370"; - - CreatePKCSSignature cpkcs = new CreatePKCSSignature(); - cpkcs.init(); - cpkcs.setCanoncialization(canAlgCanXML); - URI fileURI1 = new URI(configuration_.getProperty("webbaseDir")+"resources/testDaten.txt"); - cpkcs.createReferenceWithManifest(fileURI1,"manifestObject"); - cpkcs.setKeyInformation(); - - String request = - makeOutputFile( - createRequestStart(testNumber,true,0), - cpkcs.returnSig(), - createRequestEnd(true,false,null)); - - //Hier wird der DigestAlg vom Reference-Objekt im SignedInfo verändert - request = replaceString(request, - "http://www.w3.org/2000/09/xmldsig#sha1", - "noValidDigestAlg"); - //Hier wird der DigestAlg vom Reference-Objekt im Manifset verändert - request = replaceString(request, - "http://www.w3.org/2000/09/xmldsig#sha1", - "noValidDigestAlg"); - //Hier wird der DigestAlg vom Reference-Objekt im SignedInfo zurück geändert - request = replaceString(request, - "noValidDigestAlg", - "http://www.w3.org/2000/09/xmldsig#sha1"); - - - writeFile(vxReqFile(testNumber),request); - writeFile(vxResErrFile(testNumber),"2262"); } - - - /** - * 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; - } - - - /** - * 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>"+readFileCR(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 += readFileCR( - 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() 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"; - 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 - { - URL targetUrl = new URL(url); - HttpURLConnection h = (HttpURLConnection)targetUrl.openConnection(); - return h.getInputStream(); - } - -public String vxResErrFile(String testNumber) - { - return configuration_.getProperty("baseDir") + - "/data/VX0/"+ - configuration_.getProperty("TestClass") + - "." + - testNumber + - ".ErrRes.xml"; - } -private String getBase64Hash(String filename) throws Exception - { - DigestAlgorithmImplSHA1 dig = new DigestAlgorithmImplSHA1(); - InputStream s = getHttpInputStream(filename); - - dig.setInput(s); - - InputStream erg = dig.digest(); - String result = ""; - - byte[] b = new byte[1]; - erg.read(b); - while (erg.available() > 0) - { - result += new String(b); - erg.read(b); - } - result += new String(b); - - ByteArrayOutputStream fos = new ByteArrayOutputStream(); - Base64OutputStream base64os = new Base64OutputStream(fos); - base64os.write(result.getBytes()); - base64os.flush(); - - return fos.toString(); - } -} diff --git a/spss.test/src/testgenerator/TestPKCS12.java b/spss.test/src/testgenerator/TestPKCS12.java deleted file mode 100644 index 97aa8acd0..000000000 --- a/spss.test/src/testgenerator/TestPKCS12.java +++ /dev/null @@ -1,107 +0,0 @@ - -package testgenerator; -import iaik.pkcs.pkcs12.CertificateBag; -import iaik.pkcs.pkcs12.KeyBag; -import iaik.pkcs.pkcs12.PKCS12; -import iaik.security.ecc.ecdsa.ECPrivateKey; -import iaik.security.ecc.ecdsa.ECPublicKey; -import iaik.security.ecc.math.ecgroup.ECPoint; - -import java.io.FileInputStream; - - -/** - * @author stephan - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class TestPKCS12 { - -/* - public static void main(String[] args) throws Exception { - -// String file = "C:/Daten/MOAPhase2/additionalFiles/keys/TestUser.p12"; -// String password = "testuser"; -// String file = "C:\\Certs\\grill(1234).p12"; -// String password = "1234"; - - // SL eCard Demo P12 Files - String file = "C:\\Daten\\MOAPhase2\\Keys\\sl2002mmdd.ecard.sicher(ego).p12"; - String password = "ego"; -// String file = "C:\\Daten\\MOAPhase2\\Keys\\sl2002mmdd.ecard.normal(ego).p12"; -// String password = "ego"; - - // SL Personalausweis Demo P12 Files -// String file = "C:\\Daten\\MOAPhase2\\Keys\\sicher-demo(buergerkarte).p12"; -// String password = "buergerkarte"; -// String file = "C:\\Daten\\MOAPhase2\\Keys\\normal().p12"; -// String password = ""; - - IAIK.addAsJDK14Provider(); - - FileInputStream pkcs12FIS = new FileInputStream(file); - PKCS12 pkcs12 = new PKCS12(pkcs12FIS); - if (!pkcs12.verify(password.toCharArray())) - { - System.out.println("could not PKCS12.verify file " + file + " with password " + password); - } else - { - System.out.println("could PKCS12.verify file " + file + " with password " + password); - } - - pkcs12.decrypt(password.toCharArray()); - System.out.println("could PKCS12.decrypt file " + file + " with password " + password); - - KeyBag[] keyBags = pkcs12.getKeyBags(); - System.out.println("PKCS12.getKeyBags(): " + keyBags.length + " KeyBags found"); - - RSAPrivateKey privKey = (RSAPrivateKey) keyBags[0].getPrivateKey(); - System.out.println("getFriendlyName(): " + keyBags[0].getFriendlyName() ); - - X509Certificate[] certBag = CertificateBag.getCertificates(pkcs12.getCertificateBags()); - System.out.println("PKCS12.getCertificates(): " + certBag.length + " certificates found"); - - System.out.println("certBag[0]: " + certBag[0]); - - } -*/ - - public static void main(String[] args) throws Exception { - // von Wolfgang Bauer - iaik.security.provider.IAIK.addAsProvider(); - iaik.security.ecc.provider.ECCProvider.addAsProvider(); - - final String FILENAME = "sl2002mmdd.ecard.sicher.p12"; - final char[] PASSWORD = "ego".toCharArray(); -// public final static String FILENAME = "sl2002mmdd.ecard.sicher.p12"; -// public final static char[] PASSWORD = "ego".toCharArray(); - - System.out.println("Checking"); - FileInputStream fis = new FileInputStream(FILENAME); - PKCS12 p12 = new PKCS12(fis); - p12.decrypt(PASSWORD); - CertificateBag[] cb = p12.getCertificateBags(); - - KeyBag kb = p12.getKeyBag(); - ECPrivateKey pk = (ECPrivateKey) kb.getPrivateKey(); - - ECPoint p = pk.getParameter().getG(); - p.multiply(pk.getS()); - - ECPoint p2 = ((ECPublicKey)cb[0].getCertificate().getPublicKey()).getW(); - if (p.equals(p2) ) { - System.out.println("Check OK"); - } else { - System.out.println("Nix wars"); - } - cb[0].getCertificate().verify(); - - } - - - -} - diff --git a/spss.test/src/testgenerator/VXResponseBean.java b/spss.test/src/testgenerator/VXResponseBean.java deleted file mode 100644 index bbdf02bbc..000000000 --- a/spss.test/src/testgenerator/VXResponseBean.java +++ /dev/null @@ -1,180 +0,0 @@ - -package testgenerator; -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; - -import iaik.asn1.structures.Name; -import iaik.x509.X509Certificate; - -/** - * @author KNIRSCHS - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class VXResponseBean { - - private X509Certificate cert = null; - - /** - * Constructor for VXResponseBean. - */ - public String getHeader() { - - String result = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + - "<VerifyXMLSignatureResponse xmlns=\"http://reference.e-government.gv.at/namespace/moa/20020822#\" >\n" + - " <SignerInfo>\n" + - " <dsig:X509Data xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">\n"; - - return result; - } - - public void init(String Filename) throws Exception { - if (cert == null) { - InputStream cfile = getHttpInputStream(Filename); - cert = new iaik.x509.X509Certificate(cfile); - } - } - public String getCert() throws Exception { - return " <dsig:X509Certificate>" - + (cert) - + "</dsig:X509Certificate>\n"; - - } - - - public String getSubjectDN() throws Exception { - return " <dsig:X509SubjectName>" - + ((Name) cert.getSubjectDN()).getRFC2253String() - + "</dsig:X509SubjectName>\n"; - } - public String getIssuerDN() throws Exception { - - return " <dsig:X509IssuerName>" + - ((Name)cert.getIssuerDN()).getRFC2253String() + - "</dsig:X509IssuerName>\n"; - } - - public String getSerialNumber() throws Exception { - - return " <dsig:X509SerialNumber>" + - cert.getSerialNumber() + - "</dsig:X509SerialNumber>\n"; - } - - public String getFooterSignatureCheck(String signatureCheckCode, String certificateCheckCode) - { - String res = null; - res = " </HashInputData>\n" + - " <SignatureCheck>\n" + - " <Code>" + signatureCheckCode + "</Code>\n" + - " </SignatureCheck>\n" + - " <CertificateCheck>\n" + - " <Code>"+certificateCheckCode+"</Code>\n" + - " </CertificateCheck>\n" + - "</VerifyXMLSignatureResponse>"; - - return res; - - } - public String getFooterXMLDSIGManifestCheck(String xmlDSIGManifestCheckCode , String certificateCheckCode) - { - String res = null; -/* res = "</XMLContent>\n" + - " </HashInputData>\n" + - " <XMLDSIGManifestCheck>\n" + - " <Code>" + xmlDSIGManifestCheckCode + "</Code>\n" + - " </XMLDSIGManifestCheck>\n" + - " <CertificateCheck>\n" + - " <Code>"+certificateCheckCode+"</Code>\n" + - " </CertificateCheck>\n" + - "</VerifyXMLSignatureResponse>"; -*/ - res = " <XMLDSIGManifestCheck>\n" + - " <Code>" + xmlDSIGManifestCheckCode + "</Code>\n" + - " </XMLDSIGManifestCheck>\n" + - " <CertificateCheck>\n" + - " <Code>"+certificateCheckCode+"</Code>\n" + - " </CertificateCheck>\n" + - "</VerifyXMLSignatureResponse>"; - - return res; - - } -public String createXMLDSIGManifestCheck(String xmlDSIGManifestCheckCode, String failedReference, String referringSigRefData) - { - - if(failedReference != null && !failedReference.trim().equals("")) - { - String res = null; - res = " <XMLDSIGManifestCheck>\n" + - " <Code>" + xmlDSIGManifestCheckCode + "</Code>\n" + - " <Info><FailedReference>" + failedReference + - "</FailedReference><ReferringSigReference>" + referringSigRefData + "</ReferringSigReference>" + - " </Info>\n" + - " </XMLDSIGManifestCheck>\n"; - - return res; - } - else - { - String res = null; - res = " <XMLDSIGManifestCheck>\n" + - " <Code>" + xmlDSIGManifestCheckCode + "</Code>\n" + - " <Info>" + failedReference + - " <ReferringSigReference>" + referringSigRefData + "</ReferringSigReference>" + - " </Info>\n" + - " </XMLDSIGManifestCheck>\n"; - - return res; - } - - } - -public String createSignatureCheck(String signatureCheckCode) - { - String res = null; - res = " <SignatureCheck>\n" + - " <Code>" + signatureCheckCode + "</Code>\n" + - " </SignatureCheck>\n"; - return res; - - } -public String createSignatureManifestCheck(String signatureCheckCode) - { - String res = null; - res = " <SignatureManifestCheck>\n" + - " <Code>" + signatureCheckCode + "</Code>\n" + - " </SignatureManifestCheck>\n"; - return res; - - } - -public String createSignatureManifestCheck(String signatureCheckCode,String info) - { - String res = null; - res = " <SignatureManifestCheck>\n" + - " <Code>" + signatureCheckCode + "</Code>\n" + info + - " </SignatureManifestCheck>\n"; - return res; - - } -public String createCertificateCheck(String certificateCheckCode) - { - String res = null; - res = " <CertificateCheck>\n" + - " <Code>"+certificateCheckCode+"</Code>\n" + - " </CertificateCheck>\n"; - return res; - } -private InputStream getHttpInputStream(String url) throws Exception - { - - return ((HttpURLConnection)new URL(url).openConnection()).getInputStream(); - } - -} |