Package org.picketlink.identity.xmlsec.w3.xmlenc

Examples of org.picketlink.identity.xmlsec.w3.xmlenc.ReferenceList$References


        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 = 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


        }
        return conditions;
    }

    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

                        requestToken.setUseKey(useKeyType);

                        EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                        StaxParserUtil.validate(endElement, WSTrustConstants.USE_KEY);
                    } else if (StaxParserUtil.matches(subEvent, XMLDSig.KEYINFO)) {
                        KeyInfoType keyInfo = SAMLParserUtil.parseKeyInfo(xmlEventReader);
                        useKeyType = requestToken.getUseKey();
                        if (useKeyType == null) {
                            useKeyType = new UseKeyType();
                        }
                        useKeyType.add(keyInfo);
View Full Code Here

     */
    private void validateHolderOfKeyContents(SubjectConfirmationType subjectConfirmation, String keyType,
            Certificate certificate, boolean usePublicKey) throws Exception {
        SubjectConfirmationDataType subjConfirmationDataType = subjectConfirmation.getSubjectConfirmationData();
        assertNotNull("Unexpected null subject confirmation data", subjConfirmationDataType);
        KeyInfoType keyInfo = (KeyInfoType) subjConfirmationDataType.getAnyType();
        assertEquals("Unexpected key info content size", 1, keyInfo.getContent().size());

        // if the key is a symmetric key, the KeyInfo should contain an encrypted element.
        if (WSTrustConstants.KEY_TYPE_SYMMETRIC.equals(keyType)) {
            Element encKeyElement = (Element) keyInfo.getContent().get(0);
            assertEquals("Unexpected key info content type", WSTrustConstants.XMLEnc.ENCRYPTED_KEY,
                    encKeyElement.getLocalName());
        }
        // if the key is public, KeyInfo should either contain an encoded certificate or an encoded public key.
        else if (WSTrustConstants.KEY_TYPE_PUBLIC.equals(keyType)) {
            // if the public key has been used as proof, we should be able to retrieve it from KeyValueType.
            if (usePublicKey == true) {
                KeyValueType keyValue = (KeyValueType) keyInfo.getContent().get(0);
                RSAKeyValueType rsaKeyValue = (RSAKeyValueType) keyValue;

                // reconstruct the public key and check if it matches the public key of the provided certificate.
                BigInteger modulus = new BigInteger(1, Base64.decode(new String(rsaKeyValue.getModulus())));
                BigInteger exponent = new BigInteger(1, Base64.decode(new String(rsaKeyValue.getExponent())));
                KeyFactory factory = KeyFactory.getInstance("RSA");
                RSAPublicKeySpec spec = new RSAPublicKeySpec(modulus, exponent);
                RSAPublicKey genKey = (RSAPublicKey) factory.generatePublic(spec);
                assertEquals("Invalid public key", certificate.getPublicKey(), genKey);
            }
            // if the whole certificate was used as proof, we should be able to retrieve it from X509DataType.
            else {
                X509DataType x509Data = (X509DataType) keyInfo.getContent().get(0);
                assertEquals("Unexpected X509 data content size", 1, x509Data.getDataObjects().size());
                Object content = x509Data.getDataObjects().get(0);
                assertTrue("Unexpected X509 data content type", content instanceof X509CertificateType);
                byte[] encodedCertificate = ((X509CertificateType) content).getEncodedCertificate();

View Full Code Here

        SubjectConfirmationType confirmation = subject.getConfirmation().get(0);
        assertEquals("Unexpected confirmation method", SAMLUtil.SAML2_HOLDER_OF_KEY_URI, confirmation.getMethod());

        SubjectConfirmationDataType confirmData = confirmation.getSubjectConfirmationData();
        KeyInfoType keyInfo = (KeyInfoType) confirmData.getAnyType();
        assertEquals("Unexpected key info content size", 1, keyInfo.getContent().size());
        Element encKeyElement = (Element) keyInfo.getContent().get(0);
        assertEquals("Unexpected key info content type", WSTrustConstants.XMLEnc.ENCRYPTED_KEY, encKeyElement.getLocalName());

        // Now let's set an asymmetric proof of possession token in the context.
        Certificate certificate = this.getCertificate("keystore/sts_keystore.jks", "testpass", "service1");
        context.setProofTokenInfo(WSTrustUtil.createKeyInfo(certificate));

        // call the SAML token provider and check the generated token.
        this.provider.issueToken(context);
        assertNotNull("Unexpected null security token", context.getSecurityToken());

        // check if the assertion has a subject confirmation that contains the encoded certificate.
        assertion = SAMLUtil.fromElement((Element) context.getSecurityToken().getTokenValue());
        subject = assertion.getSubject();
        nameID = (NameIDType) subject.getSubType().getBaseID();
        assertEquals("Unexpected name id qualifier", "urn:picketlink:identity-federation", nameID.getNameQualifier());
        assertEquals("Unexpected name id", "sguilhen", nameID.getValue());
        confirmation = subject.getConfirmation().get(0);
        assertEquals("Unexpected confirmation method", SAMLUtil.SAML2_HOLDER_OF_KEY_URI, confirmation.getMethod());

        /*
         * confirmationContent = confirmation.getSubjectConfirmationData().getContent();
         * assertEquals("Unexpected subject confirmation content size", 1, confirmationContent.size()); keyInfoElement =
         * (JAXBElement<?>) confirmationContent.get(0); assertEquals("Unexpected subject confirmation context type",
         * KeyInfoType.class, keyInfoElement.getDeclaredType());
         */
        keyInfo = (KeyInfoType) confirmation.getSubjectConfirmationData().getAnyType();
        assertEquals("Unexpected key info content size", 1, keyInfo.getContent().size());

        // key info should contain a X509Data section with the encoded certificate.
        X509DataType x509Data = (X509DataType) keyInfo.getContent().get(0);
        assertEquals("Unexpected X509 data content size", 1, x509Data.getDataObjects().size());
        X509CertificateType cert = (X509CertificateType) x509Data.getDataObjects().get(0);

        // certificate should have been encoded to Base64, so we need to decode it first.
        byte[] encodedCert = Base64.decode(new String(cert.getEncodedCertificate()));
View Full Code Here

            StaxUtil.writeAttribute(writer, JBossSAMLConstants.ADDRESS.get(), address);
        }

        if (subjectConfirmationData instanceof KeyInfoConfirmationDataType) {
            KeyInfoConfirmationDataType kicd = (KeyInfoConfirmationDataType) subjectConfirmationData;
            KeyInfoType keyInfo = (KeyInfoType) kicd.getAnyType();
            StaxUtil.writeKeyInfo(writer, keyInfo);
            /*
             * if (keyInfo.getContent() == null || keyInfo.getContent().size() == 0) throw new
             * ProcessingException(ErrorCodes.WRITER_INVALID_KEYINFO_NULL_CONTENT); StaxUtil.writeStartElement(this.writer,
             * WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.KEYINFO, WSTrustConstants.XMLDSig.DSIG_NS);
View Full Code Here

                        if (elementName.equals("X509Certificate")) {
                            X509DataType data = new X509DataType();
                            data.add(value);
                            value = data;
                        } else if(elementName.equals("KeyValue")){
                           KeyValueType keyValue = null;
                           Element child = DocumentUtil.getChildElement(keyElement, new QName(WSTrustConstants.XMLDSig.RSA_KEYVALUE));
                           if(child != null){
                               try {
                                keyValue = XMLSignatureUtil.getRSAKeyValue(child);
                            } catch (ParsingException e) {
View Full Code Here

                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);
View Full Code Here

                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);
View Full Code Here

                StaxUtil.writeCharacters(writer, new String(cert.getEncodedCertificate()));
                StaxUtil.writeEndElement(writer);
            }
            StaxUtil.writeEndElement(writer);
        } else if( content instanceof KeyValueType){
            KeyValueType keyvalueType = (KeyValueType) content;
            StaxUtil.writeStartElement(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.KEYVALUE,
                    WSTrustConstants.XMLDSig.DSIG_NS);
            if(keyvalueType instanceof DSAKeyValueType){
                StaxUtil.writeDSAKeyValueType(writer, (DSAKeyValueType) keyvalueType);
            }
View Full Code Here

TOP

Related Classes of org.picketlink.identity.xmlsec.w3.xmlenc.ReferenceList$References

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.