Java Code Examples for com.sun.org.apache.xml.internal.security.utils.Base64

The following examples show how to use com.sun.org.apache.xml.internal.security.utils.Base64. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jdk1.8-source-analysis   Source File: Reference.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 2
Source Project: jdk1.8-source-analysis   Source File: XMLSignature.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Base64 encodes and sets the bytes as the content of the SignatureValue
 * Node.
 *
 * @param bytes bytes to be used by SignatureValue before Base64 encoding
 */
private void setSignatureValueElement(byte[] bytes) {

    while (signatureValueElement.hasChildNodes()) {
        signatureValueElement.removeChild(signatureValueElement.getFirstChild());
    }

    String base64codedValue = Base64.encode(bytes);

    if (base64codedValue.length() > 76 && !XMLUtils.ignoreLineBreaks()) {
        base64codedValue = "\n" + base64codedValue + "\n";
    }

    Text t = this.doc.createTextNode(base64codedValue);
    signatureValueElement.appendChild(t);
}
 
Example 3
Source Project: jdk8u-jdk   Source File: DOMReference.java    License: GNU General Public License v2.0 6 votes vote down vote up
public boolean validate(XMLValidateContext validateContext)
    throws XMLSignatureException
{
    if (validateContext == null) {
        throw new NullPointerException("validateContext cannot be null");
    }
    if (validated) {
        return validationStatus;
    }
    Data data = dereference(validateContext);
    calcDigestValue = transform(data, validateContext);

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Expected digest: " + Base64.encode(digestValue));
        log.log(java.util.logging.Level.FINE, "Actual digest: " + Base64.encode(calcDigestValue));
    }

    validationStatus = Arrays.equals(digestValue, calcDigestValue);
    validated = true;
    return validationStatus;
}
 
Example 4
Source Project: jdk8u_jdk   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 5
Source Project: r2m-plugin-android   Source File: URLHelper.java    License: Apache License 2.0 6 votes vote down vote up
public static String checkURLConnection(String urlS, String username, String password){
    String status = "Error connection to server!";
    FormattedLogger logger = new FormattedLogger(URLHelper.class);
    logger.append("checkURLConnection:" + urlS);
    try {
        URL url = new URL(urlS);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        if (username != null && username.trim().length() > 0 && password != null && password.trim().length() > 0) {
            final String authString = username + ":" + password;
            conn.setRequestProperty("Authorization", "Basic " + Base64.encode(authString.getBytes()));
        }

        conn.setRequestMethod("GET");
        conn.setDoInput(true);

        status = "" + conn.getResponseCode();
        logger.append("Response code:" + status);
        logger.showInfoLog();
    } catch (Exception e) {
        logger.append(">>>" +  e.getClass().getName() + " message: " + e.getMessage());
        logger.showErrorLog();
    }
    return status;
}
 
Example 6
Source Project: openjdk-jdk9   Source File: XMLSignature.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Base64 encodes and sets the bytes as the content of the SignatureValue
 * Node.
 *
 * @param bytes bytes to be used by SignatureValue before Base64 encoding
 */
private void setSignatureValueElement(byte[] bytes) {

    while (signatureValueElement.hasChildNodes()) {
        signatureValueElement.removeChild(signatureValueElement.getFirstChild());
    }

    String base64codedValue = Base64.encode(bytes);

    if (base64codedValue.length() > 76 && !XMLUtils.ignoreLineBreaks()) {
        base64codedValue = "\n" + base64codedValue + "\n";
    }

    Text t = this.doc.createTextNode(base64codedValue);
    signatureValueElement.appendChild(t);
}
 
Example 7
/**
 * Method main
 *
 * @param unused
 * @throws Exception
 */
public static void main(String unused[]) throws Exception {

    CertsInFilesystemDirectoryResolver krs =
        new CertsInFilesystemDirectoryResolver(
            "data/ie/baltimore/merlin-examples/merlin-xmldsig-eighteen/certs");

    for (Iterator<Certificate> i = krs.getIterator(); i.hasNext(); ) {
        X509Certificate cert = (X509Certificate) i.next();
        byte[] ski =
            com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI.getSKIBytesFromCert(cert);

        System.out.println();
        System.out.println("Base64(SKI())=                 \""
                           + Base64.encode(ski) + "\"");
        System.out.println("cert.getSerialNumber()=        \""
                           + cert.getSerialNumber().toString() + "\"");
        System.out.println("cert.getSubjectX500Principal().getName()= \""
                           + cert.getSubjectX500Principal().getName() + "\"");
        System.out.println("cert.getIssuerX500Principal().getName()=  \""
                           + cert.getIssuerX500Principal().getName() + "\"");
    }
}
 
Example 8
/**
 * Method main
 *
 * @param unused
 * @throws Exception
 */
public static void main(String unused[]) throws Exception {

    CertsInFilesystemDirectoryResolver krs =
        new CertsInFilesystemDirectoryResolver(
            "data/ie/baltimore/merlin-examples/merlin-xmldsig-eighteen/certs");

    for (Iterator<Certificate> i = krs.getIterator(); i.hasNext(); ) {
        X509Certificate cert = (X509Certificate) i.next();
        byte[] ski =
            com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI.getSKIBytesFromCert(cert);

        System.out.println();
        System.out.println("Base64(SKI())=                 \""
                           + Base64.encode(ski) + "\"");
        System.out.println("cert.getSerialNumber()=        \""
                           + cert.getSerialNumber().toString() + "\"");
        System.out.println("cert.getSubjectX500Principal().getName()= \""
                           + cert.getSubjectX500Principal().getName() + "\"");
        System.out.println("cert.getIssuerX500Principal().getName()=  \""
                           + cert.getIssuerX500Principal().getName() + "\"");
    }
}
 
Example 9
/**
 * Method main
 *
 * @param unused
 * @throws Exception
 */
public static void main(String unused[]) throws Exception {

    CertsInFilesystemDirectoryResolver krs =
        new CertsInFilesystemDirectoryResolver(
            "data/ie/baltimore/merlin-examples/merlin-xmldsig-eighteen/certs");

    for (Iterator<Certificate> i = krs.getIterator(); i.hasNext(); ) {
        X509Certificate cert = (X509Certificate) i.next();
        byte[] ski =
            com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI.getSKIBytesFromCert(cert);

        System.out.println();
        System.out.println("Base64(SKI())=                 \""
                           + Base64.encode(ski) + "\"");
        System.out.println("cert.getSerialNumber()=        \""
                           + cert.getSerialNumber().toString() + "\"");
        System.out.println("cert.getSubjectX500Principal().getName()= \""
                           + cert.getSubjectX500Principal().getName() + "\"");
        System.out.println("cert.getIssuerX500Principal().getName()=  \""
                           + cert.getIssuerX500Principal().getName() + "\"");
    }
}
 
Example 10
Source Project: hottub   Source File: DOMReference.java    License: GNU General Public License v2.0 6 votes vote down vote up
public boolean validate(XMLValidateContext validateContext)
    throws XMLSignatureException
{
    if (validateContext == null) {
        throw new NullPointerException("validateContext cannot be null");
    }
    if (validated) {
        return validationStatus;
    }
    Data data = dereference(validateContext);
    calcDigestValue = transform(data, validateContext);

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Expected digest: " + Base64.encode(digestValue));
        log.log(java.util.logging.Level.FINE, "Actual digest: " + Base64.encode(calcDigestValue));
    }

    validationStatus = Arrays.equals(digestValue, calcDigestValue);
    validated = true;
    return validationStatus;
}
 
Example 11
Source Project: openjdk-jdk8u   Source File: DOMReference.java    License: GNU General Public License v2.0 6 votes vote down vote up
public boolean validate(XMLValidateContext validateContext)
    throws XMLSignatureException
{
    if (validateContext == null) {
        throw new NullPointerException("validateContext cannot be null");
    }
    if (validated) {
        return validationStatus;
    }
    Data data = dereference(validateContext);
    calcDigestValue = transform(data, validateContext);

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Expected digest: " + Base64.encode(digestValue));
        log.log(java.util.logging.Level.FINE, "Actual digest: " + Base64.encode(calcDigestValue));
    }

    validationStatus = Arrays.equals(digestValue, calcDigestValue);
    validated = true;
    return validationStatus;
}
 
Example 12
Source Project: TencentKona-8   Source File: DOMReference.java    License: GNU General Public License v2.0 6 votes vote down vote up
public boolean validate(XMLValidateContext validateContext)
    throws XMLSignatureException
{
    if (validateContext == null) {
        throw new NullPointerException("validateContext cannot be null");
    }
    if (validated) {
        return validationStatus;
    }
    Data data = dereference(validateContext);
    calcDigestValue = transform(data, validateContext);

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Expected digest: " + Base64.encode(digestValue));
        log.log(java.util.logging.Level.FINE, "Actual digest: " + Base64.encode(calcDigestValue));
    }

    validationStatus = Arrays.equals(digestValue, calcDigestValue);
    validated = true;
    return validationStatus;
}
 
Example 13
Source Project: ranger   Source File: RangerMasterKey.java    License: Apache License 2.0 6 votes vote down vote up
private String decryptMasterKey(byte masterKey[], String password, String encryptedPassString) throws Throwable {
    if (logger.isDebugEnabled()) {
        logger.debug("==> RangerMasterKey.decryptMasterKey()");
        logger.debug("Decrypting Master Key...");
    }
    if (encryptedPassString == null) {
        getPasswordParam(password);
    }
    PBEKeySpec pbeKeyspec = getPBEParameterSpec(password);
    byte[] masterKeyFromDBDecrypted = decryptKey(masterKey, pbeKeyspec);
    SecretKey masterKeyFromDB = getMasterKeyFromBytes(masterKeyFromDBDecrypted);
    if (logger.isDebugEnabled()) {
        logger.debug("<== RangerMasterKey.decryptMasterKey()");
    }
    return Base64.encode(masterKeyFromDB.getEncoded());
}
 
Example 14
/**
 * Method main
 *
 * @param unused
 * @throws Exception
 */
public static void main(String unused[]) throws Exception {

    CertsInFilesystemDirectoryResolver krs =
        new CertsInFilesystemDirectoryResolver(
            "data/ie/baltimore/merlin-examples/merlin-xmldsig-eighteen/certs");

    for (Iterator<Certificate> i = krs.getIterator(); i.hasNext(); ) {
        X509Certificate cert = (X509Certificate) i.next();
        byte[] ski =
            com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI.getSKIBytesFromCert(cert);

        System.out.println();
        System.out.println("Base64(SKI())=                 \""
                           + Base64.encode(ski) + "\"");
        System.out.println("cert.getSerialNumber()=        \""
                           + cert.getSerialNumber().toString() + "\"");
        System.out.println("cert.getSubjectX500Principal().getName()= \""
                           + cert.getSubjectX500Principal().getName() + "\"");
        System.out.println("cert.getIssuerX500Principal().getName()=  \""
                           + cert.getIssuerX500Principal().getName() + "\"");
    }
}
 
Example 15
Source Project: openjdk-8-source   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 16
Source Project: jdk8u-jdk   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 17
Source Project: jdk8u60   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 18
Source Project: jdk8u-dev-jdk   Source File: Reference.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests reference validation is success or false
 *
 * @return true if reference validation is success, otherwise false
 * @throws ReferenceNotInitializedException
 * @throws XMLSecurityException
 */
public boolean verify()
    throws ReferenceNotInitializedException, XMLSecurityException {
    byte[] elemDig = this.getDigestValue();
    byte[] calcDig = this.calculateDigest(true);
    boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);

    if (!equal) {
        log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
        log.log(java.util.logging.Level.WARNING, "Expected Digest: " + Base64.encode(elemDig));
        log.log(java.util.logging.Level.WARNING, "Actual Digest: " + Base64.encode(calcDig));
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Verification successful for URI \"" + this.getURI() + "\"");
        }
    }

    return equal;
}
 
Example 19
Source Project: jdk8u60   Source File: XMLSignature.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Base64 encodes and sets the bytes as the content of the SignatureValue
 * Node.
 *
 * @param bytes bytes to be used by SignatureValue before Base64 encoding
 */
private void setSignatureValueElement(byte[] bytes) {

    while (signatureValueElement.hasChildNodes()) {
        signatureValueElement.removeChild(signatureValueElement.getFirstChild());
    }

    String base64codedValue = Base64.encode(bytes);

    if (base64codedValue.length() > 76 && !XMLUtils.ignoreLineBreaks()) {
        base64codedValue = "\n" + base64codedValue + "\n";
    }

    Text t = this.doc.createTextNode(base64codedValue);
    signatureValueElement.appendChild(t);
}
 
Example 20
Source Project: openjdk-8-source   Source File: DOMX509Data.java    License: GNU General Public License v2.0 5 votes vote down vote up
private ByteArrayInputStream unmarshalBase64Binary(Element elem)
    throws MarshalException {
    try {
        if (cf == null) {
            cf = CertificateFactory.getInstance("X.509");
        }
        return new ByteArrayInputStream(Base64.decode(elem));
    } catch (CertificateException e) {
        throw new MarshalException("Cannot create CertificateFactory", e);
    } catch (Base64DecodingException bde) {
        throw new MarshalException("Cannot decode Base64-encoded val", bde);
    }
}
 
Example 21
Source Project: compiler   Source File: MetadataLangCacher.java    License: Apache License 2.0 5 votes vote down vote up
public int authenticate(String username, String password) {
        String authenStr = username + ":" + password;
        String encodedAuthenStr = Base64.encode(authenStr.getBytes());
        this.connection.setRequestProperty("Authorization", "Basic " + encodedAuthenStr);
        try {
            this.responseCode = this.connection.getResponseCode();
//            this.authenticated = (this.responseCode / 100 == 2);
        } catch (IOException e) {
            // considered as failed
        }
        return this.responseCode;
    }
 
Example 22
Source Project: jdk8u_jdk   Source File: DOMX509Data.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void marshalSKI(byte[] skid, Node parent, Document doc,
                        String dsPrefix)
{
    Element skidElem = DOMUtils.createElement(doc, "X509SKI",
                                              XMLSignature.XMLNS, dsPrefix);
    skidElem.appendChild(doc.createTextNode(Base64.encode(skid)));
    parent.appendChild(skidElem);
}
 
Example 23
Source Project: jdk1.8-source-analysis   Source File: XMLX509SKI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Method getSKIBytesFromCert
 *
 * @param cert
 * @return ski bytes from the given certificate
 *
 * @throws XMLSecurityException
 * @see java.security.cert.X509Extension#getExtensionValue(java.lang.String)
 */
public static byte[] getSKIBytesFromCert(X509Certificate cert)
    throws XMLSecurityException {

    if (cert.getVersion() < 3) {
        Object exArgs[] = { Integer.valueOf(cert.getVersion()) };
        throw new XMLSecurityException("certificate.noSki.lowVersion", exArgs);
    }

    /*
     * Gets the DER-encoded OCTET string for the extension value
     * (extnValue) identified by the passed-in oid String. The oid
     * string is represented by a set of positive whole numbers
     * separated by periods.
     */
    byte[] extensionValue = cert.getExtensionValue(XMLX509SKI.SKI_OID);
    if (extensionValue == null) {
        throw new XMLSecurityException("certificate.noSki.null");
    }

    /**
     * Strip away first four bytes from the extensionValue
     * The first two bytes are the tag and length of the extensionValue
     * OCTET STRING, and the next two bytes are the tag and length of
     * the ski OCTET STRING.
     */
    byte skidValue[] = new byte[extensionValue.length - 4];

    System.arraycopy(extensionValue, 4, skidValue, 0, skidValue.length);

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Base64 of SKI is " + Base64.encode(skidValue));
    }

    return skidValue;
}
 
Example 24
Source Project: openjdk-8   Source File: DOMCryptoBinary.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a <code>DOMCryptoBinary</code> from a node.
 *
 * @param cbNode a CryptoBinary text node
 * @throws MarshalException if value cannot be decoded (invalid format)
 */
public DOMCryptoBinary(Node cbNode) throws MarshalException {
    value = cbNode.getNodeValue();
    try {
        bigNum = Base64.decodeBigIntegerFromText((Text) cbNode);
    } catch (Exception ex) {
        throw new MarshalException(ex);
    }
}
 
Example 25
/**
 * Create a <code>DOMCryptoBinary</code> instance from the specified
 * <code>BigInteger</code>
 *
 * @param bigNum the arbitrary-length integer
 * @throws NullPointerException if <code>bigNum</code> is <code>null</code>
 */
public DOMCryptoBinary(BigInteger bigNum) {
    if (bigNum == null) {
        throw new NullPointerException("bigNum is null");
    }
    this.bigNum = bigNum;
    // convert to bitstring
    value = Base64.encode(bigNum);
}
 
Example 26
Source Project: jdk8u-dev-jdk   Source File: DOMX509Data.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a <code>DOMX509Data</code> from an element.
 *
 * @param xdElem an X509Data element
 * @throws MarshalException if there is an error while unmarshalling
 */
public DOMX509Data(Element xdElem) throws MarshalException {
    // get all children nodes
    NodeList nl = xdElem.getChildNodes();
    int length = nl.getLength();
    List<Object> content = new ArrayList<Object>(length);
    for (int i = 0; i < length; i++) {
        Node child = nl.item(i);
        // ignore all non-Element nodes
        if (child.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        Element childElem = (Element)child;
        String localName = childElem.getLocalName();
        if (localName.equals("X509Certificate")) {
            content.add(unmarshalX509Certificate(childElem));
        } else if (localName.equals("X509IssuerSerial")) {
            content.add(new DOMX509IssuerSerial(childElem));
        } else if (localName.equals("X509SubjectName")) {
            content.add(childElem.getFirstChild().getNodeValue());
        } else if (localName.equals("X509SKI")) {
            try {
                content.add(Base64.decode(childElem));
            } catch (Base64DecodingException bde) {
                throw new MarshalException("cannot decode X509SKI", bde);
            }
        } else if (localName.equals("X509CRL")) {
            content.add(unmarshalX509CRL(childElem));
        } else {
            content.add(new javax.xml.crypto.dom.DOMStructure(childElem));
        }
    }
    this.content = Collections.unmodifiableList(content);
}
 
Example 27
Source Project: openjdk-8-source   Source File: DOMPGPData.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
    throws MarshalException
{
    Document ownerDoc = DOMUtils.getOwnerDocument(parent);
    Element pdElem = DOMUtils.createElement(ownerDoc, "PGPData",
                                            XMLSignature.XMLNS, dsPrefix);

    // create and append PGPKeyID element
    if (keyId != null) {
        Element keyIdElem = DOMUtils.createElement(ownerDoc, "PGPKeyID",
                                                   XMLSignature.XMLNS,
                                                   dsPrefix);
        keyIdElem.appendChild
            (ownerDoc.createTextNode(Base64.encode(keyId)));
        pdElem.appendChild(keyIdElem);
    }

    // create and append PGPKeyPacket element
    if (keyPacket != null) {
        Element keyPktElem = DOMUtils.createElement(ownerDoc,
                                                    "PGPKeyPacket",
                                                    XMLSignature.XMLNS,
                                                    dsPrefix);
        keyPktElem.appendChild
            (ownerDoc.createTextNode(Base64.encode(keyPacket)));
        pdElem.appendChild(keyPktElem);
    }

    // create and append any elements
    for (XMLStructure extElem : externalElements) {
        DOMUtils.appendChild(pdElem, ((javax.xml.crypto.dom.DOMStructure)
            extElem).getNode());
    }

    parent.appendChild(pdElem);
}
 
Example 28
Source Project: hottub   Source File: DOMPGPData.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
    throws MarshalException
{
    Document ownerDoc = DOMUtils.getOwnerDocument(parent);
    Element pdElem = DOMUtils.createElement(ownerDoc, "PGPData",
                                            XMLSignature.XMLNS, dsPrefix);

    // create and append PGPKeyID element
    if (keyId != null) {
        Element keyIdElem = DOMUtils.createElement(ownerDoc, "PGPKeyID",
                                                   XMLSignature.XMLNS,
                                                   dsPrefix);
        keyIdElem.appendChild
            (ownerDoc.createTextNode(Base64.encode(keyId)));
        pdElem.appendChild(keyIdElem);
    }

    // create and append PGPKeyPacket element
    if (keyPacket != null) {
        Element keyPktElem = DOMUtils.createElement(ownerDoc,
                                                    "PGPKeyPacket",
                                                    XMLSignature.XMLNS,
                                                    dsPrefix);
        keyPktElem.appendChild
            (ownerDoc.createTextNode(Base64.encode(keyPacket)));
        pdElem.appendChild(keyPktElem);
    }

    // create and append any elements
    for (XMLStructure extElem : externalElements) {
        DOMUtils.appendChild(pdElem, ((javax.xml.crypto.dom.DOMStructure)
            extElem).getNode());
    }

    parent.appendChild(pdElem);
}
 
Example 29
Source Project: dragonwell8_jdk   Source File: DOMPGPData.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a <code>DOMPGPData</code> from an element.
 *
 * @param pdElem a PGPData element
 */
public DOMPGPData(Element pdElem) throws MarshalException {
    // get all children nodes
    byte[] keyId = null;
    byte[] keyPacket = null;
    NodeList nl = pdElem.getChildNodes();
    int length = nl.getLength();
    List<XMLStructure> other = new ArrayList<XMLStructure>(length);
    for (int x = 0; x < length; x++) {
        Node n = nl.item(x);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            Element childElem = (Element)n;
            String localName = childElem.getLocalName();
            try {
                if (localName.equals("PGPKeyID")) {
                    keyId = Base64.decode(childElem);
                } else if (localName.equals("PGPKeyPacket")){
                    keyPacket = Base64.decode(childElem);
                } else {
                    other.add
                        (new javax.xml.crypto.dom.DOMStructure(childElem));
                }
            } catch (Base64DecodingException bde) {
                throw new MarshalException(bde);
            }
        }
    }
    this.keyId = keyId;
    this.keyPacket = keyPacket;
    this.externalElements = Collections.unmodifiableList(other);
}
 
Example 30
Source Project: hottub   Source File: DOMX509Data.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void marshalSKI(byte[] skid, Node parent, Document doc,
                        String dsPrefix)
{
    Element skidElem = DOMUtils.createElement(doc, "X509SKI",
                                              XMLSignature.XMLNS, dsPrefix);
    skidElem.appendChild(doc.createTextNode(Base64.encode(skid)));
    parent.appendChild(skidElem);
}