Package org.picketlink.identity.xmlsec.w3.xmldsig

Examples of org.picketlink.identity.xmlsec.w3.xmldsig.DSAKeyValueType


        StaxUtil.writeNameSpace(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.DSIG_NS);
        if (type instanceof RSAKeyValueType) {
            RSAKeyValueType rsaKeyValue = (RSAKeyValueType) type;
            StaxUtil.writeRSAKeyValueType(writer,rsaKeyValue);
        } else if(type instanceof DSAKeyValueType) {
            DSAKeyValueType dsaKeyValue = (DSAKeyValueType)type;
            StaxUtil.writeDSAKeyValueType(writer, dsaKeyValue);
        }
        StaxUtil.writeEndElement(writer);
    }
View Full Code Here


        assertNotNull(doc.getDocumentElement());
       
        Element dsaEl = (Element) doc.getElementsByTagName("ds:DSAKeyValue").item(0);
        assertNotNull(dsaEl);
       
        DSAKeyValueType dsa = XMLSignatureUtil.getDSAKeyValue(dsaEl);
        assertNotNull(dsa);
        assertNotNull(dsa.getP());
        assertNotNull(dsa.getQ());
        assertNotNull(dsa.getG());
        assertNotNull(dsa.getY());
       
        System.out.println(dsa);

        DSAPublicKey publicKey = dsa.convertToPublicKey();
        assertNotNull(publicKey);
    }
View Full Code Here

     * @param element
     * @return
     * @throws ProcessingException
     */
    public static DSAKeyValueType getDSAKeyValue(Element element) throws ParsingException {
        DSAKeyValueType dsa = new DSAKeyValueType();
        NodeList nl  = element.getChildNodes();
        int length = nl.getLength();

        for(int i = 0; i < length; i++){
            Node node  = nl.item(i);
            if(node instanceof Element){
                Element childElement = (Element) node;
                String tag = childElement.getLocalName();
               
                byte[] text = childElement.getTextContent().getBytes();
               
                if(WSTrustConstants.XMLDSig.P.equals(tag)){
                    dsa.setP(text);
                } else if(WSTrustConstants.XMLDSig.Q.equals(tag)){
                    dsa.setQ(text);
                } else if(WSTrustConstants.XMLDSig.G.equals(tag)){
                    dsa.setG(text);
                } else if(WSTrustConstants.XMLDSig.Y.equals(tag)){
                    dsa.setY(text);
                } else if(WSTrustConstants.XMLDSig.SEED.equals(tag)){
                    dsa.setSeed(text);
                } else if(WSTrustConstants.XMLDSig.PGEN_COUNTER.equals(tag)){
                    dsa.setPgenCounter(text);
                }
            }
        }

        return dsa;
View Full Code Here

            byte[] P = pubKey.getParams().getP().toByteArray();
            byte[] Q = pubKey.getParams().getQ().toByteArray();
            byte[] G = pubKey.getParams().getG().toByteArray();
            byte[] Y = pubKey.getY().toByteArray();

            DSAKeyValueType dsaKeyValue = new DSAKeyValueType();
            dsaKeyValue.setP(Base64.encodeBytes(P).getBytes());
            dsaKeyValue.setQ(Base64.encodeBytes(Q).getBytes());
            dsaKeyValue.setG(Base64.encodeBytes(G).getBytes());
            dsaKeyValue.setY(Base64.encodeBytes(Y).getBytes());
            return dsaKeyValue;
        }
        throw logger.unsupportedType(key.toString());
    }
View Full Code Here

                                }
                               }
                               value = keyValue;
                           }
                        }
                        KeyInfoType keyInfo = new KeyInfoType();
                        keyInfo.addContent(value);
                        requestContext.setProofTokenInfo(keyInfo);
                    } else if (value instanceof KeyInfoType) {
                        requestContext.setProofTokenInfo((KeyInfoType) value);
                    } else
                        throw new WSTrustException(logger.unsupportedType(value.toString()));
View Full Code Here

     * @param keyWrapAlgo the key wrap algorithm to be used.
     * @return the constructed {@code KeyInfoType} instance.
     * @throws WSTrustException if an error occurs while creating the {@code KeyInfoType} object.
     */
    public static KeyInfoType createKeyInfo(byte[] secret, PublicKey encryptionKey, URI keyWrapAlgo, X509Certificate cer) throws WSTrustException {
        KeyInfoType keyInfo = null;

        // if a public key has been specified, encrypt the secret using the public key.
        if (encryptionKey != null) {
            try {
                Document document = DocumentUtil.createDocument();
                // TODO: XMLEncryptionUtil should allow for the specification of the key wrap algorithm.
                EncryptedKey key = XMLEncryptionUtil.encryptKey(document, new SecretKeySpec(secret, "AES"), encryptionKey,
                        secret.length * 8);
               
                //if certificate is not null provide the information about the key
                if(cer != null && includeKeyInfoInEncryptedKey == true) {
                  KeyInfo kiEnc = new KeyInfo(document);
                  X509Data xData = new X509Data(document);
                  xData.addIssuerSerial(cer.getIssuerDN().getName(), cer.getSerialNumber());
                  kiEnc.add(xData);
                    key.setKeyInfo(kiEnc);
                }
               
                Element encryptedKeyElement = XMLCipher.getInstance().martial(key);
                keyInfo = new KeyInfoType();
                keyInfo.addContent(encryptedKeyElement);
               
               
            } catch (Exception e) {
                throw logger.stsKeyInfoTypeCreationError(e);
            }
View Full Code Here

     * @param certificate the {@code Certificate} to be wrapped as a {@code X509DataType} inside the {@code KeyInfoType}.
     * @return the constructed {@code KeyInfoType} object.
     * @throws WSTrustException if an error occurs while creating the {@code KeyInfoType}.
     */
    public static KeyInfoType createKeyInfo(Certificate certificate) throws WSTrustException {
        KeyInfoType keyInfo = null;
        try {
            // don't Base64 encode the certificate - JAXB marshaling performs the encoding.
            byte[] encodedCert = certificate.getEncoded();

            // first create a X509DataType that contains the encoded certificate.
            X509DataType x509 = new X509DataType();
            X509CertificateType cert = new X509CertificateType();
            cert.setEncodedCertificate(Base64.encodeBytes(encodedCert).getBytes());
            x509.add(cert);

            // set the X509DataType in the KeyInfoType.
            keyInfo = new KeyInfoType();
            keyInfo.addContent(x509);
        } catch (Exception e) {
            throw logger.stsKeyInfoTypeCreationError(e);
        }
        return keyInfo;
    }
View Full Code Here

        // the assertion principal (default is caller principal)
        Principal principal = wstContext.getCallerPrincipal();

        String confirmationMethod = null;
        KeyInfoType keyInfoType = null;
        // if there is a on-behalf-of principal, we have the sender vouches confirmation method.
        if (wstContext.getOnBehalfOfPrincipal() != null) {
            principal = wstContext.getOnBehalfOfPrincipal();
            confirmationMethod = SAMLUtil.SAML11_SENDER_VOUCHES_URI;
        }
View Full Code Here

public class SAMLParserUtil {

    private static final PicketLinkLogger logger = PicketLinkLoggerFactory.getLogger();

    public static KeyInfoType parseKeyInfo(XMLEventReader xmlEventReader) throws ParsingException {
        KeyInfoType keyInfo = new KeyInfoType();
        StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
        StaxParserUtil.validate(startElement, WSTrustConstants.XMLDSig.KEYINFO);

        XMLEvent xmlEvent = null;
        String tag = null;

        while (xmlEventReader.hasNext()) {
            xmlEvent = StaxParserUtil.peek(xmlEventReader);
            if (xmlEvent instanceof EndElement) {
                tag = StaxParserUtil.getEndElementName((EndElement) xmlEvent);
                if (tag.equals(WSTrustConstants.XMLDSig.KEYINFO)) {
                    xmlEvent = StaxParserUtil.getNextEndElement(xmlEventReader);
                    break;
                } else
                    throw logger.parserUnknownEndElement(tag);
            }
            startElement = (StartElement) xmlEvent;
            tag = StaxParserUtil.getStartElementName(startElement);
            if (tag.equals(WSTrustConstants.XMLEnc.ENCRYPTED_KEY)) {
                keyInfo.addContent(StaxParserUtil.getDOMElement(xmlEventReader));
            } else if (tag.equals(WSTrustConstants.XMLDSig.X509DATA)) {
                startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
                X509DataType x509 = new X509DataType();

                // Let us go for the X509 certificate
                startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
                StaxParserUtil.validate(startElement, WSTrustConstants.XMLDSig.X509CERT);

                X509CertificateType cert = new X509CertificateType();
                String certValue = StaxParserUtil.getElementText(xmlEventReader);
                cert.setEncodedCertificate(certValue.getBytes());
                x509.add(cert);

                EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                StaxParserUtil.validate(endElement, WSTrustConstants.XMLDSig.X509DATA);
                keyInfo.addContent(x509);
            } else if (tag.equals(WSTrustConstants.XMLDSig.KEYVALUE)) {
                startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
                KeyValueType keyValue = null;

                startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
                tag = StaxParserUtil.getStartElementName(startElement);
                if (tag.equals(WSTrustConstants.XMLDSig.RSA_KEYVALUE)) {
                    keyValue = parseRSAKeyValue(xmlEventReader);
                } else if (tag.equals(WSTrustConstants.XMLDSig.DSA_KEYVALUE)) {
                    keyValue = parseDSAKeyValue(xmlEventReader);
                } else
                    throw logger.parserUnknownTag(tag, startElement.getLocation());

                EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                StaxParserUtil.validate(endElement, WSTrustConstants.XMLDSig.KEYVALUE);

                keyInfo.addContent(keyValue);
            }
        }
        return keyInfo;
    }
View Full Code Here

        XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
        if (!(xmlEvent instanceof EndElement)) {
            startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
            String tag = StaxParserUtil.getStartElementName(startElement);
            if (tag.equals(WSTrustConstants.XMLDSig.KEYINFO)) {
                KeyInfoType keyInfo = SAMLParserUtil.parseKeyInfo(xmlEventReader);
                subjectConfirmationData.setAnyType(keyInfo);
            } else if (tag.equals(WSTrustConstants.XMLEnc.ENCRYPTED_KEY)) {
                subjectConfirmationData.setAnyType(StaxParserUtil.getDOMElement(xmlEventReader));
            } else
                throw logger.parserUnknownTag(tag, startElement.getLocation());
View Full Code Here

TOP

Related Classes of org.picketlink.identity.xmlsec.w3.xmldsig.DSAKeyValueType

Copyright © 2018 www.massapicom. 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.