Search in sources :

Example 1 with WSSecHeader

use of org.apache.wss4j.dom.message.WSSecHeader in project testcases by coheigea.

the class EncryptionAlgorithmBenchmark method doEncryption.

private void doEncryption(String keyTransportAlgorithm, Crypto verifyingCrypto) throws Exception {
    Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
    WSSecHeader secHeader = new WSSecHeader(doc);
    secHeader.insertSecurityHeader();
    WSSecEncrypt builder = new WSSecEncrypt(secHeader);
    builder.setUserInfo("myservicekey", "skpass");
    builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
    builder.setKeyEncAlgo(keyTransportAlgorithm);
    Document encryptedDoc = builder.build(serviceCrypto);
    WSSecurityEngine engine = new WSSecurityEngine();
    RequestData data = new RequestData();
    data.setWssConfig(WSSConfig.getNewInstance());
    data.setDecCrypto(verifyingCrypto);
    data.setCallbackHandler(new CommonCallbackHandler());
    if (WSConstants.KEYTRANSPORT_RSA15.equals(keyTransportAlgorithm)) {
        data.setAllowRSA15KeyTransportAlgorithm(true);
    }
    Element securityHeader = WSSecurityUtil.getSecurityHeader(encryptedDoc, "");
    Assert.assertNotNull(securityHeader);
    WSHandlerResult results = engine.processSecurityHeader(securityHeader, data);
    WSSecurityEngineResult actionResult = results.getActionResults().get(WSConstants.ENCR).get(0);
    Assert.assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE));
    Assert.assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_REFERENCE_TYPE));
}
Also used : WSSecHeader(org.apache.wss4j.dom.message.WSSecHeader) WSSecEncrypt(org.apache.wss4j.dom.message.WSSecEncrypt) RequestData(org.apache.wss4j.dom.handler.RequestData) Element(org.w3c.dom.Element) WSSecurityEngine(org.apache.wss4j.dom.engine.WSSecurityEngine) Document(org.w3c.dom.Document) WSHandlerResult(org.apache.wss4j.dom.handler.WSHandlerResult) WSSecurityEngineResult(org.apache.wss4j.dom.engine.WSSecurityEngineResult)

Example 2 with WSSecHeader

use of org.apache.wss4j.dom.message.WSSecHeader in project testcases by coheigea.

the class SignatureAlgorithmBenchmark method doSignature.

private void doSignature(String c14nAlgo, boolean addInclusivePrefixes, String digestAlgo, String sigAlgo, Crypto verifyingCrypto) throws Exception {
    Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
    WSSecHeader secHeader = new WSSecHeader(doc);
    secHeader.insertSecurityHeader();
    WSSecSignature builder = new WSSecSignature(secHeader);
    builder.setUserInfo("myclientkey", "ckpass");
    builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
    builder.setSigCanonicalization(c14nAlgo);
    builder.setDigestAlgo(digestAlgo);
    builder.setSignatureAlgorithm(sigAlgo);
    builder.setAddInclusivePrefixes(addInclusivePrefixes);
    Document signedDoc = builder.build(clientCrypto);
    WSSecurityEngine engine = new WSSecurityEngine();
    RequestData data = new RequestData();
    data.setWssConfig(WSSConfig.getNewInstance());
    data.setSigVerCrypto(verifyingCrypto);
    data.setSubjectCertConstraints(Collections.singletonList(certConstraint));
    List<BSPRule> ignoredRules = new ArrayList<BSPRule>();
    ignoredRules.add(BSPRule.R5404);
    ignoredRules.add(BSPRule.R5406);
    data.setIgnoredBSPRules(ignoredRules);
    Element securityHeader = WSSecurityUtil.getSecurityHeader(signedDoc, "");
    Assert.assertNotNull(securityHeader);
    WSHandlerResult results = engine.processSecurityHeader(securityHeader, data);
    WSSecurityEngineResult actionResult = results.getActionResults().get(WSConstants.SIGN).get(0);
    Assert.assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE));
    Assert.assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_REFERENCE_TYPE));
}
Also used : BSPRule(org.apache.wss4j.common.bsp.BSPRule) WSSecHeader(org.apache.wss4j.dom.message.WSSecHeader) RequestData(org.apache.wss4j.dom.handler.RequestData) WSSecSignature(org.apache.wss4j.dom.message.WSSecSignature) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) WSSecurityEngine(org.apache.wss4j.dom.engine.WSSecurityEngine) Document(org.w3c.dom.Document) WSHandlerResult(org.apache.wss4j.dom.handler.WSHandlerResult) WSSecurityEngineResult(org.apache.wss4j.dom.engine.WSSecurityEngineResult)

Example 3 with WSSecHeader

use of org.apache.wss4j.dom.message.WSSecHeader in project testcases by coheigea.

the class EncryptionSerializerBenchmark method doEncryption.

private Document doEncryption(Serializer serializer) throws Exception {
    Document doc = StaxUtils.read(new StringReader(SOAPUtil.SAMPLE_SOAP_MSG));
    WSSecHeader secHeader = new WSSecHeader(doc);
    secHeader.insertSecurityHeader();
    WSSecEncrypt builder = new WSSecEncrypt(secHeader);
    builder.setUserInfo("myservicekey", "skpass");
    builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
    builder.setEncryptionSerializer(serializer);
    return builder.build(serviceCrypto);
}
Also used : WSSecHeader(org.apache.wss4j.dom.message.WSSecHeader) WSSecEncrypt(org.apache.wss4j.dom.message.WSSecEncrypt) StringReader(java.io.StringReader) Document(org.w3c.dom.Document)

Example 4 with WSSecHeader

use of org.apache.wss4j.dom.message.WSSecHeader in project testcases by coheigea.

the class EncryptionReferenceBenchmark method doEncryption.

private void doEncryption(int identifier, REFERENCE_TYPE referenceType, Crypto verifyingCrypto) throws Exception {
    Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
    WSSecHeader secHeader = new WSSecHeader(doc);
    secHeader.insertSecurityHeader();
    WSSecEncrypt builder = new WSSecEncrypt(secHeader);
    builder.setUserInfo("myservicekey", "skpass");
    builder.setKeyIdentifierType(identifier);
    Document encryptedDoc = builder.build(serviceCrypto);
    WSSecurityEngine engine = new WSSecurityEngine();
    RequestData data = new RequestData();
    data.setWssConfig(WSSConfig.getNewInstance());
    data.setDecCrypto(verifyingCrypto);
    data.setCallbackHandler(new CommonCallbackHandler());
    Element securityHeader = WSSecurityUtil.getSecurityHeader(encryptedDoc, "");
    Assert.assertNotNull(securityHeader);
    WSHandlerResult results = engine.processSecurityHeader(securityHeader, data);
    WSSecurityEngineResult actionResult = results.getActionResults().get(WSConstants.ENCR).get(0);
    Assert.assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE));
    Assert.assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_REFERENCE_TYPE));
    REFERENCE_TYPE refType = (REFERENCE_TYPE) actionResult.get(WSSecurityEngineResult.TAG_X509_REFERENCE_TYPE);
    Assert.assertTrue(refType == referenceType);
}
Also used : WSSecHeader(org.apache.wss4j.dom.message.WSSecHeader) WSSecEncrypt(org.apache.wss4j.dom.message.WSSecEncrypt) RequestData(org.apache.wss4j.dom.handler.RequestData) REFERENCE_TYPE(org.apache.wss4j.dom.str.STRParser.REFERENCE_TYPE) Element(org.w3c.dom.Element) WSSecurityEngine(org.apache.wss4j.dom.engine.WSSecurityEngine) Document(org.w3c.dom.Document) WSHandlerResult(org.apache.wss4j.dom.handler.WSHandlerResult) WSSecurityEngineResult(org.apache.wss4j.dom.engine.WSSecurityEngineResult)

Example 5 with WSSecHeader

use of org.apache.wss4j.dom.message.WSSecHeader in project testcases by coheigea.

the class SignatureReferenceBenchmark method doSignature.

private void doSignature(int identifier, REFERENCE_TYPE referenceType, Crypto verifyingCrypto) throws Exception {
    Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
    WSSecHeader secHeader = new WSSecHeader(doc);
    secHeader.insertSecurityHeader();
    WSSecSignature builder = new WSSecSignature(secHeader);
    builder.setUserInfo("myclientkey", "ckpass");
    builder.setKeyIdentifierType(identifier);
    Document signedDoc = builder.build(clientCrypto);
    WSSecurityEngine engine = new WSSecurityEngine();
    RequestData data = new RequestData();
    data.setWssConfig(WSSConfig.getNewInstance());
    data.setSigVerCrypto(verifyingCrypto);
    data.setSubjectCertConstraints(Collections.singletonList(certConstraint));
    Element securityHeader = WSSecurityUtil.getSecurityHeader(signedDoc, "");
    Assert.assertNotNull(securityHeader);
    WSHandlerResult results = engine.processSecurityHeader(securityHeader, data);
    WSSecurityEngineResult actionResult = results.getActionResults().get(WSConstants.SIGN).get(0);
    Assert.assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE));
    Assert.assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_REFERENCE_TYPE));
    REFERENCE_TYPE refType = (REFERENCE_TYPE) actionResult.get(WSSecurityEngineResult.TAG_X509_REFERENCE_TYPE);
    Assert.assertTrue(refType == referenceType);
}
Also used : WSSecHeader(org.apache.wss4j.dom.message.WSSecHeader) RequestData(org.apache.wss4j.dom.handler.RequestData) REFERENCE_TYPE(org.apache.wss4j.dom.str.STRParser.REFERENCE_TYPE) WSSecSignature(org.apache.wss4j.dom.message.WSSecSignature) Element(org.w3c.dom.Element) WSSecurityEngine(org.apache.wss4j.dom.engine.WSSecurityEngine) Document(org.w3c.dom.Document) WSHandlerResult(org.apache.wss4j.dom.handler.WSHandlerResult) WSSecurityEngineResult(org.apache.wss4j.dom.engine.WSSecurityEngineResult)

Aggregations

WSSecHeader (org.apache.wss4j.dom.message.WSSecHeader)6 Document (org.w3c.dom.Document)6 Element (org.w3c.dom.Element)5 WSSecurityEngine (org.apache.wss4j.dom.engine.WSSecurityEngine)4 WSSecurityEngineResult (org.apache.wss4j.dom.engine.WSSecurityEngineResult)4 RequestData (org.apache.wss4j.dom.handler.RequestData)4 WSHandlerResult (org.apache.wss4j.dom.handler.WSHandlerResult)4 WSSecEncrypt (org.apache.wss4j.dom.message.WSSecEncrypt)3 WSSecSignature (org.apache.wss4j.dom.message.WSSecSignature)3 REFERENCE_TYPE (org.apache.wss4j.dom.str.STRParser.REFERENCE_TYPE)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 MessageFactory (javax.xml.soap.MessageFactory)1 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 SOAPPart (javax.xml.soap.SOAPPart)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 StreamSource (javax.xml.transform.stream.StreamSource)1