Examples of EncryptionActionToken


Examples of org.apache.wss4j.common.EncryptionActionToken

                && actionToDo.getActionToken() == null) {
                decodeSignatureParameter(reqData);
            } else if ((actionToDo.getAction() == WSConstants.ENCR
                || actionToDo.getAction() == WSConstants.DKT_ENCR)
                && actionToDo.getActionToken() == null) {
                EncryptionActionToken actionToken = reqData.getEncryptionToken();
                if (actionToken == null) {
                    actionToken = new EncryptionActionToken();
                    reqData.setEncryptionToken(actionToken);
                }
                if (actionToken.getCrypto() == null) {
                    actionToken.setCrypto(loadEncryptionCrypto(reqData));
                }
                decodeEncryptionParameter(reqData);
            }
        }
View Full Code Here

Examples of org.apache.wss4j.common.EncryptionActionToken

    // the RequestData object
    protected void decodeEncryptionParameter(RequestData reqData)
        throws WSSecurityException {
        Object mc = reqData.getMsgContext();

        EncryptionActionToken actionToken = reqData.getEncryptionToken();
        if (actionToken == null) {
            actionToken = new EncryptionActionToken();
            reqData.setEncryptionToken(actionToken);
        }
        //
        // If the following parameters are no used (they return null) then the
        // default values of WSS4J are used.
        //
        String encKeyId = getString(WSHandlerConstants.ENC_KEY_ID, mc);
        if (encKeyId != null) {
            Integer id = WSHandlerConstants.getKeyIdentifier(encKeyId);
            if (id == null) {
                throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE,
                        "empty",
                        "WSHandler: Encryption: unknown key identification"
                );
            }
            int tmp = id;
            actionToken.setKeyIdentifierId(tmp);
            if (!(tmp == WSConstants.ISSUER_SERIAL
                    || tmp == WSConstants.X509_KEY_IDENTIFIER
                    || tmp == WSConstants.SKI_KEY_IDENTIFIER
                    || tmp == WSConstants.BST_DIRECT_REFERENCE
                    || tmp == WSConstants.THUMBPRINT_IDENTIFIER
                    || tmp == WSConstants.ENCRYPTED_KEY_SHA1_IDENTIFIER)) {
                throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE,
                        "empty",
                        "WSHandler: Encryption: illegal key identification"
                );
            }
        }
        String encSymAlgo = getString(WSHandlerConstants.ENC_SYM_ALGO, mc);
        actionToken.setSymmetricAlgorithm(encSymAlgo);

        String encKeyTransport =
            getString(WSHandlerConstants.ENC_KEY_TRANSPORT, mc);
        actionToken.setKeyTransportAlgorithm(encKeyTransport);
       
        String derivedKeyReference = getString(WSHandlerConstants.DERIVED_TOKEN_REFERENCE, mc);
        actionToken.setDerivedKeyTokenReference(derivedKeyReference);
       
        String derivedKeyIdentifier = getString(WSHandlerConstants.DERIVED_TOKEN_KEY_ID, mc);
        if (derivedKeyIdentifier != null) {
            Integer id = WSHandlerConstants.getKeyIdentifier(derivedKeyIdentifier);
            actionToken.setDerivedKeyIdentifier(id);
        }
       
        String derivedKeyLength = getString(WSHandlerConstants.DERIVED_ENCRYPTION_KEY_LENGTH, mc);
        if (derivedKeyLength != null) {
            try {
                int dKL = Integer.parseInt(derivedKeyLength);
                if (dKL > 0) {
                    actionToken.setDerivedKeyLength(dKL);
                }
            } catch (NumberFormatException e) {
                LOG.warn("Error in configuring a derived key length: " + e.getMessage());
            }
        }
       
        boolean use200512Namespace = decodeUse200512Namespace(reqData);
        reqData.setUse200512Namespace(use200512Namespace);
       
        String digestAlgo = getString(WSHandlerConstants.ENC_DIGEST_ALGO, mc);
        actionToken.setDigestAlgorithm(digestAlgo);

        String mgfAlgo = getString(WSHandlerConstants.ENC_MGF_ALGO, mc);
        actionToken.setMgfAlgorithm(mgfAlgo);
       
        String encSymEncKey = getString(WSHandlerConstants.ENC_SYM_ENC_KEY, mc);
        if (encSymEncKey != null) {
            boolean encSymEndKeyBoolean = Boolean.parseBoolean(encSymEncKey);
            actionToken.setEncSymmetricEncryptionKey(encSymEndKeyBoolean);
        }
       
        String encUser = getString(WSHandlerConstants.ENCRYPTION_USER, mc);
        if (encUser != null) {
            actionToken.setUser(encUser);
        } else {
            actionToken.setUser(reqData.getUsername());
        }
        if (actionToken.isEncSymmetricEncryptionKey() && actionToken.getUser() == null) {
            throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE,
                    "empty", "WSHandler: Encryption: no username");
        }

        handleSpecialUser(reqData);

        String encParts = getString(WSHandlerConstants.ENCRYPTION_PARTS, mc);
        if (encParts != null) {
            splitEncParts(true, encParts, actionToken.getParts(), reqData);
        }
        encParts = getString(WSHandlerConstants.OPTIONAL_ENCRYPTION_PARTS, mc);
        if (encParts != null) {
            splitEncParts(false, encParts, actionToken.getParts(), reqData);
        }
       
        boolean includeToken = decodeIncludeEncryptionToken(reqData);
        actionToken.setIncludeToken(includeToken);
    }
View Full Code Here

Examples of org.apache.wss4j.common.EncryptionActionToken

        }
    }

    @SuppressWarnings("unchecked")
    private void handleSpecialUser(RequestData reqData) {
        EncryptionActionToken actionToken = reqData.getEncryptionToken();
        if (actionToken == null
            || !WSHandlerConstants.USE_REQ_SIG_CERT.equals(actionToken.getUser())) {
            return;
        }
        List<WSHandlerResult> results =
            (List<WSHandlerResult>) getProperty(
                reqData.getMsgContext(), WSHandlerConstants.RECV_RESULTS
            );
        if (results == null) {
            return;
        }
        /*
         * Scan the results for a matching actor. Use results only if the
         * receiving Actor and the sending Actor match.
         */
        for (WSHandlerResult rResult : results) {
            String hActor = rResult.getActor();
            if (!WSSecurityUtil.isActorEqual(reqData.getActor(), hActor)) {
                continue;
            }
            List<WSSecurityEngineResult> wsSecEngineResults = rResult.getResults();
            /*
             * Scan the results for the first Signature action. Use the
             * certificate of this Signature to set the certificate for the
             * encryption action :-).
             */
            for (WSSecurityEngineResult wser : wsSecEngineResults) {
                int wserAction =
                        (Integer) wser.get(WSSecurityEngineResult.TAG_ACTION);
                if (wserAction == WSConstants.SIGN) {
                    X509Certificate cert =
                        (X509Certificate)wser.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE);
                    actionToken.setCertificate(cert);
                    return;
                }
            }
        }
    }
View Full Code Here

Examples of org.apache.wss4j.common.EncryptionActionToken

    @org.junit.Test
    public void testEncryptionWithOutRevocationCheck() throws Exception {
        final WSSConfig cfg = WSSConfig.getNewInstance();
        final RequestData reqData = new RequestData();
        reqData.setWssConfig(cfg);
        EncryptionActionToken actionToken = new EncryptionActionToken();
        actionToken.setUser("wss40rev");
        actionToken.setKeyIdentifierId(WSConstants.BST_DIRECT_REFERENCE);
        actionToken.setSymmetricAlgorithm(WSConstants.TRIPLE_DES);
        actionToken.setCrypto(crypto);
        reqData.setEncryptionToken(actionToken);
        java.util.Map<String, Object> messageContext = new java.util.TreeMap<String, Object>();
        messageContext.put(WSHandlerConstants.PW_CALLBACK_REF, keystoreCallbackHandler);
        reqData.setMsgContext(messageContext);
        reqData.setUsername("wss40rev");
View Full Code Here

Examples of org.apache.wss4j.common.EncryptionActionToken

    @org.junit.Test
    public void testEncryptionWithRevocationCheck() throws Exception {
        final WSSConfig cfg = WSSConfig.getNewInstance();
        final RequestData reqData = new RequestData();
        reqData.setWssConfig(cfg);
        EncryptionActionToken actionToken = new EncryptionActionToken();
        actionToken.setUser("wss40rev");
        actionToken.setKeyIdentifierId(WSConstants.BST_DIRECT_REFERENCE);
        actionToken.setSymmetricAlgorithm(WSConstants.TRIPLE_DES);
        actionToken.setCrypto(crypto);
        reqData.setEncryptionToken(actionToken);
        java.util.Map<String, Object> messageContext = new java.util.TreeMap<String, Object>();
        messageContext.put(WSHandlerConstants.PW_CALLBACK_REF, keystoreCallbackHandler);
        reqData.setMsgContext(messageContext);
        reqData.setUsername("wss40rev");
View Full Code Here

Examples of org.apache.wss4j.common.EncryptionActionToken

        messageContext.put(
            WSHandlerConstants.PW_CALLBACK_REF, new KeystoreCallbackHandler()
        );
        reqData.setMsgContext(messageContext);
       
        EncryptionActionToken actionToken = new EncryptionActionToken();
        actionToken.setUser("wss40");
        actionToken.setCryptoProperties("wss40.properties");
       
        final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
        CustomHandler handler = new CustomHandler();
        List<HandlerAction> actions = new ArrayList<HandlerAction>();
        actions.add(new HandlerAction(WSConstants.ENCR, actionToken));
View Full Code Here

Examples of org.apache.wss4j.common.EncryptionActionToken

        messageContext.put(
            WSHandlerConstants.PW_CALLBACK_REF, new KeystoreCallbackHandler()
        );
        reqData.setMsgContext(messageContext);
       
        EncryptionActionToken actionToken = new EncryptionActionToken();
        actionToken.setUser("wss40");
        actionToken.setCryptoProperties("wss40.properties");
        actionToken.setIncludeToken(true);
       
        final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
        CustomHandler handler = new CustomHandler();
        List<HandlerAction> actions = new ArrayList<HandlerAction>();
        actions.add(new HandlerAction(WSConstants.ENCR, actionToken));
View Full Code Here

Examples of org.apache.wss4j.common.EncryptionActionToken

        messageContext.put(
            WSHandlerConstants.PW_CALLBACK_REF, new KeystoreCallbackHandler()
        );
        reqData.setMsgContext(messageContext);
       
        EncryptionActionToken actionToken = new EncryptionActionToken();
        actionToken.setKeyIdentifierId(WSConstants.ENCRYPTED_KEY_SHA1_IDENTIFIER);
        actionToken.setKey(keyData);
        actionToken.setSymmetricAlgorithm(WSConstants.AES_128);
        actionToken.setEncSymmetricEncryptionKey(false);
       
        final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
        CustomHandler handler = new CustomHandler();
        List<HandlerAction> actions = new ArrayList<HandlerAction>();
        actions.add(new HandlerAction(WSConstants.ENCR, actionToken));
View Full Code Here

Examples of org.apache.wss4j.common.EncryptionActionToken

        messageContext.put(
            WSHandlerConstants.PW_CALLBACK_REF, new KeystoreCallbackHandler()
        );
        reqData.setMsgContext(messageContext);
       
        EncryptionActionToken actionToken = new EncryptionActionToken();
        actionToken.setUser("wss40");
        actionToken.setCryptoProperties("wss40.properties");
       
        EncryptionActionToken actionToken2 = new EncryptionActionToken();
        actionToken2.setUser("16c73ab6-b892-458f-abf5-2f875f74882e");
        actionToken2.setCryptoProperties("crypto.properties");
        WSEncryptionPart encP =
            new WSEncryptionPart("Timestamp", WSConstants.WSU_NS, "");
        actionToken2.setParts(Collections.singletonList(encP));
       
        final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
        CustomHandler handler = new CustomHandler();
        List<HandlerAction> actions = new ArrayList<HandlerAction>();
        actions.add(new HandlerAction(WSConstants.ENCR, actionToken));
View Full Code Here

Examples of org.apache.wss4j.common.EncryptionActionToken

        messageContext.put(
            WSHandlerConstants.PW_CALLBACK_REF, new KeystoreCallbackHandler()
        );
        reqData.setMsgContext(messageContext);
       
        EncryptionActionToken actionToken = new EncryptionActionToken();
        actionToken.setUser("wss40");
        actionToken.setCryptoProperties("wss40.properties");
       
        EncryptionActionToken actionToken2 = new EncryptionActionToken();
        actionToken2.setKeyIdentifierId(WSConstants.ENCRYPTED_KEY_SHA1_IDENTIFIER);
        actionToken2.setKey(keyData);
        actionToken2.setSymmetricAlgorithm(WSConstants.AES_128);
        actionToken2.setEncSymmetricEncryptionKey(false);
        WSEncryptionPart encP =
            new WSEncryptionPart("Timestamp", WSConstants.WSU_NS, "");
        actionToken2.setParts(Collections.singletonList(encP));
       
        final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
        CustomHandler handler = new CustomHandler();
        List<HandlerAction> actions = new ArrayList<HandlerAction>();
        actions.add(new HandlerAction(WSConstants.ENCR, actionToken));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.