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,"","");
request = replaceString(request,"","");
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")+
"";
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",
"");
supp.closeSupplement();
String requestEnd = createSignatureInfoEnd()+
supp.getSupplement() + createRequestShortEnd(false);
String requestStart = createRequestStart(testNumber,true,0);
String reqDocString =
""
+ "daten" ;
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(("").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()),"","") + requestEnd;
writeFile(vxReqFile(testNumber),request);
String response = createResponsePart(cpkcs.getX509CertString()) +
vxBean.createSignatureCheck("0")+
vxBean.createCertificateCheck("0")+
"";
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,"","") +
String reqDocString = /*createRequestStart(testNumber,true,0) +*/
""
+ "\ndaten\n" /*+ 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("");
request = request.substring("".length());
request = ""+request;
System.out.println("DOC:"+request);
request =""+Base64Utils.encode(request.getBytes())+"//dsig:Signature"+supp.getSupplement()+"TrustProfile1";
/*int i_pos = request.indexOf("\n" +request.substring(i_pos);*/
/*i_pos = request.indexOf(""+
""+
""+
""+
""+
""+
""+
""+
""+
""+
""+
""+
"id('signed-data')/node()"+
""+
""+
""+
"4lngV1x/OvR8iFWEBenH4fDihwA="+
""+
""+
""+
""+
"id('refetsi')/etsi:QualifyingProperties/etsi:SignedProperties"+
""+
""+
""+
"1j0DWguieuw2cGA06gFjoSNXr+w="+
""+
""+
"Yb6fsPNbKyYW+u7cU1EqF9n5QrwLXHqdGD4tJNT5+sA7kQR3Ztqz965vlBH+1pJE"+
"nGxehxXsesZboVvkJa/jhuI0goCTW9KkdGOP71B7o7/vlyBbxaYKpnVNtBU4/qtT"+
"xba7M0E32X+tm/x9O6foXIM0AoP3oQBZmjo9rEJ9kfk="+
""+
""+
"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=="+
/*""+
readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/IAIKRootMusterbehoerde.cer")+
""+*/
""+
""+
""+
""+
"IdentityLink"+
""+
""+
""+
""+
""+
""+
""+
"2003-03-04T12:32:54Z"+
""+
""+
""+
""+
"Frhu1o4mL4gQHdJcU0xSA/h4COE="+
""+
""+
"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"+
"6455"+
""+
""+
""+
""+
""+
""+
""+
""+
""+
"text/xml"+
""+
""+
""+
""+
""+
""+
""+
""+
"//dsig:Signature"+
""+
"TrustProfile1"+
"";
String response =
""+
""+
" "+
" "+
" serialNumber=790187461633,givenName=Testperson MOA4,SN=BRZ,CN=Testperson MOA4 BRZ,C=AT"+
" "+
" 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"+
" 6455"+
" "+
"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=="+
" "+
" "+
" "+
" "+
" 0
"+
" "+
" "+
" 0
"+
" "+
"";
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",
"");
supp.closeSupplement();
String requestEnd = createSignatureInfoEnd()+
supp.getSupplement() + createRequestShortEnd(false);
String requestStart = createRequestStart(testNumber,true,0);
String reqDocString =
""
+ "daten" ;
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(("").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()),"","") + requestEnd;
writeFile(vxReqFile(testNumber),request);
String response = createResponsePart(cpkcs.getX509CertString()) +
vxBean.createSignatureCheck("0")+
vxBean.createCertificateCheck("0")+
"";
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")+
"";
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() + ""+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() + ""+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()+""+
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()) +
""+
readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/testSimple.txt") +
""+
""+
readBinaryFileAsBase64_new(configuration_.getProperty("baseDir")+"resources/testXML.txt") +
""+
vxBean.createSignatureCheck("0")+
vxBean.createCertificateCheck("0")+
"";
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()+
"SupplementProfile2" +
"" +
"SupplementProfile1" +
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","CN=IAIK ECDSA Test,OU=JavaSecurity,O=IAIK,C=AT","CN=IAIK ECDSA Test,OU=JavaSecurity,O=IAIK,C=AT","68172"));
}
/**
* 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,"","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,"","");
/*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")+
"";
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) +
""
+ "" + requestEnd;
InputStream bis = new ByteArrayInputStream((""
+ "").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:"+""));
}
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")+
"";
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, "","");
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")+
"";
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" +
"\n" +
" \n" +
" \n" +
"" +
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()) +
""+
Base64Utils.encode(stripNLCR(convertManifestToString(elem)).getBytes()) +
""+
vxBean.createSignatureCheck("0")+
vxBean.createXMLDSIGManifestCheck("0","","1")+
vxBean.createCertificateCheck("0")+
"";
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()) +
""+
Base64Utils.encode(stripNLCR(convertManifestToString(man1)).getBytes()) +
""+
""+
Base64Utils.encode(stripNLCR(convertManifestToString(man2)).getBytes()) +
""+
vxBean.createSignatureCheck("0")+
vxBean.createXMLDSIGManifestCheck("0","","1")+
vxBean.createXMLDSIGManifestCheck("0","","2")+
vxBean.createCertificateCheck("0")+
"";
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()) +
""+
Base64Utils.encode(stripNLCR(convertManifestToString(man)).getBytes()) +
""+
vxBean.createSignatureCheck("0")+
vxBean.createXMLDSIGManifestCheck("0","","1")+
vxBean.createCertificateCheck("0")+
"";
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()) +
""+
Base64Utils.encode(stripNLCR(convertManifestToString(mani)).getBytes()) +
""+
vxBean.createSignatureCheck("0")+
vxBean.createXMLDSIGManifestCheck("1","1","1")+
vxBean.createCertificateCheck("0")+
"";
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,"","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")+
"";
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 Prologue
int pos = erg.indexOf(""
+ "\n";
if(dtd!=null && !dtd.trim().equals(""))
reqStart += dtd;
reqStart+= "\n";
if (useDate) {
reqStart += " "
+ getDate(changeHours)
+ "\n";
}
reqStart += " \n"
+ " \n"
+ " " ;
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 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 =
"\n"
+ " #xpointer(/VerifyXMLSignatureRequest/VerifySignatureInfo/VerifySignatureEnvironment/dsig:Signature)\n"
+ " \n";
*/
reqEnd =""+
"\n"
+ " //dsig:Signature\n"
+ " \n";
if (useSupplement)
{
reqEnd += " \n" +
" \n" +
" "+readFileCR(supplementReference.toString())+"\n" +
" \n" +
" \n";
}
if (useReturnHashInputData) {
reqEnd += " \n";
}
reqEnd += " TrustProfile1\n"
+ "\n";
return reqEnd;
}
private String createSignatureInfoEnd()
throws Exception {
return ""+"\n"
+ " //dsig:Signature\n"
+ " \n";
}
private String createRequestShortEnd(boolean useReturnHashInputData)
throws Exception {
String reqEnd = "";
if (useReturnHashInputData)
reqEnd = " \n";
reqEnd += " TrustProfile1\n"
+ "\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 += " \n";
res += vxBean.getIssuerDN();
res += vxBean.getSerialNumber();
res += " \n"
+ x509cert
+ " \n"
+ " \n";
res += " \n" + " ";
/*res += ""+readFileCR(
configuration_.getProperty("baseDir")
+ "resources/testSimple.txt")+
"";*/
res += ""+readBinaryFileAsBase64_new((configuration_.getProperty("baseDir")+ "resources/testSimple.txt"))+"";
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 += " \n";
res += vxBean.getIssuerDN();
res += vxBean.getSerialNumber();
res += " \n"
+ x509cert
+ " \n"
+ " \n";
res += replaceString(vxBean.getFooterSignatureCheck(signatureCheckCode, "0"),"","");
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 += " \n";
res += vxBean.getIssuerDN();
res += vxBean.getSerialNumber();
res += " \n"
+ x509cert
+ " \n"
+ " \n";
res += " \n" +
" 1
1\n" +
" \n" +
" \n" +
" 0
\n" +
" \n" +
"";;
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 += " \n";
res += vxBean.getIssuerDN();
res += vxBean.getSerialNumber();
res += " \n"
+ x509cert
+ " \n"
+ " \n";
res += " \n" + " ";
/*res += ""+readFileCR(
configuration_.getProperty("baseDir")
+ "resources/testSimple.txt")+
"";*/
if(filename.startsWith("text:"))
res += ""+Base64Utils.encode(filename.substring(5).getBytes())+"";
else
res += ""+readBinaryFileAsBase64_new((configuration_.getProperty("baseDir")+ filename))+"";
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 += " \n";
res += iss;
res += serial;
res += " \n"
+ x509cert
+ " \n"
+ " \n";
res += " \n" + " ";
/*res += ""+readFileCR(
configuration_.getProperty("baseDir")
+ "resources/testSimple.txt")+
"";*/
res += ""+readBinaryFileAsBase64_new((configuration_.getProperty("baseDir")+ "resources/testSimple.txt"))+"";
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 += " \n";
res += vxBean.getIssuerDN();
res += vxBean.getSerialNumber();
res += " \n"
+ x509cert
+ " \n"
+ " \n";
res += " \n";
/* " "+
hashData +
"\n";*/
res += ""+Base64Utils.encode(hashData.getBytes())+"";
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 += " \n";
res += vxBean.getIssuerDN();
res += vxBean.getSerialNumber();
res += " \n"
+ x509cert
+ " \n"
+ " \n";
res += " \n";
/* " "+
hashData +
"\n";*/
res += ""+Base64Utils.encode(hashData.getBytes())+"";
res += "";
res += ""+Base64Utils.encode(hashData2.getBytes())+"";
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 += " \n";
res += vxBean.getIssuerDN();
res += vxBean.getSerialNumber();
res += " \n"
+ x509cert
+ " \n"
+ " \n"
+ " \n" +
" " + signatureCheckCode + "
\n" +
" \n";
if(dsig) res+=vxBean.createXMLDSIGManifestCheck("0","","1");
res+= " \n" +
" 0
\n" +
" \n" +
"";
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 += " \n";
res += vxBean.getIssuerDN();
res += vxBean.getSerialNumber();
res += " \n"
+ x509cert
+ " \n"
+ " \n"
+ " \n" +
" " + signatureCheckCode + "
\n" +
" \n" +
" \n" +
" 0
\n" +
" \n" +
"";
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 += " \n";
res += vxBean.getIssuerDN();
res += vxBean.getSerialNumber();
res += " \n";
res +=x509cert;
res += " \n"
+ " \n";
/*res += " \n" + " ";
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","");
}
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,"","");
result = replaceStringAll(result,"'","'");
result = replaceStringAll(result,"#sha1\"/>