Search in sources :

Example 1 with ExcC14NParameterSpec

use of javax.xml.crypto.dsig.spec.ExcC14NParameterSpec in project jdk8u_jdk by JetBrains.

the class DOMExcC14NMethod method unmarshalParams.

private void unmarshalParams(Element paramsElem) {
    String prefixListAttr = paramsElem.getAttributeNS(null, "PrefixList");
    this.inclusiveNamespaces = prefixListAttr;
    int begin = 0;
    int end = prefixListAttr.indexOf(' ');
    List<String> prefixList = new ArrayList<String>();
    while (end != -1) {
        prefixList.add(prefixListAttr.substring(begin, end));
        begin = end + 1;
        end = prefixListAttr.indexOf(' ', begin);
    }
    if (begin <= prefixListAttr.length()) {
        prefixList.add(prefixListAttr.substring(begin));
    }
    this.params = new ExcC14NParameterSpec(prefixList);
}
Also used : ExcC14NParameterSpec(javax.xml.crypto.dsig.spec.ExcC14NParameterSpec)

Example 2 with ExcC14NParameterSpec

use of javax.xml.crypto.dsig.spec.ExcC14NParameterSpec in project santuario-java by apache.

the class CanonicalizationMethodTest method testConstructor.

@org.junit.Test
public void testConstructor() throws Exception {
    // test newAlgorithmMethod(String algorithm,
    // AlgorithmParameterSpec params)
    // for generating CanonicalizationMethod objects
    CanonicalizationMethod cm;
    for (int i = 0; i < C14N_ALGOS.length; i++) {
        String algo = C14N_ALGOS[i];
        cm = factory.newCanonicalizationMethod(algo, (C14NMethodParameterSpec) null);
        assertNotNull(cm);
        assertEquals(cm.getAlgorithm(), algo);
        assertNull(cm.getParameterSpec());
        try {
            cm = factory.newCanonicalizationMethod(algo, new TestUtils.MyOwnC14nParameterSpec());
            fail("Should raise an IAPE for invalid c14n parameters");
        } catch (InvalidAlgorithmParameterException iape) {
        } catch (Exception ex) {
            fail("Should raise a IAPE instead of " + ex);
        }
        if (algo.equals(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS) || algo.equals(CanonicalizationMethod.EXCLUSIVE)) {
            cm = factory.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE, new ExcC14NParameterSpec());
            AlgorithmParameterSpec aps = cm.getParameterSpec();
            assertNotNull(aps);
            assertTrue(aps instanceof ExcC14NParameterSpec);
        }
    }
    try {
        cm = factory.newCanonicalizationMethod(null, (C14NMethodParameterSpec) null);
        fail("Should raise a NPE for null algo");
    } catch (NullPointerException npe) {
    } catch (Exception ex) {
        fail("Should raise a NPE instead of " + ex);
    }
    try {
        cm = factory.newCanonicalizationMethod("non-existent", (C14NMethodParameterSpec) null);
        fail("Should raise an NSAE for non-existent algos");
    } catch (NoSuchAlgorithmException nsae) {
    } catch (Exception ex) {
        fail("Should raise an NSAE instead of " + ex);
    }
}
Also used : ExcC14NParameterSpec(javax.xml.crypto.dsig.spec.ExcC14NParameterSpec) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) C14NMethodParameterSpec(javax.xml.crypto.dsig.spec.C14NMethodParameterSpec)

Example 3 with ExcC14NParameterSpec

use of javax.xml.crypto.dsig.spec.ExcC14NParameterSpec in project camel by apache.

the class XmlSignatureHelper method getCanonicalizationMethod.

/**
     * Returns a configuration for a canonicalization algorithm.
     * 
     * @param algorithm
     *            algorithm URI
     * @param inclusiveNamespacePrefixes
     *            namespace prefixes which should be treated like in the
     *            inclusive canonicalization, only relevant if the algorithm is
     *            exclusive
     * @return canonicalization
     * @throws IllegalArgumentException
     *             if <tt>algorithm</tt> is <code>null</code>
     */
public static AlgorithmMethod getCanonicalizationMethod(String algorithm, List<String> inclusiveNamespacePrefixes) {
    if (algorithm == null) {
        throw new IllegalArgumentException("algorithm is null");
    }
    XmlSignatureTransform canonicalizationMethod = new XmlSignatureTransform(algorithm);
    if (inclusiveNamespacePrefixes != null) {
        ExcC14NParameterSpec parameters = new ExcC14NParameterSpec(inclusiveNamespacePrefixes);
        canonicalizationMethod.setParameterSpec(parameters);
    }
    return canonicalizationMethod;
}
Also used : ExcC14NParameterSpec(javax.xml.crypto.dsig.spec.ExcC14NParameterSpec)

Example 4 with ExcC14NParameterSpec

use of javax.xml.crypto.dsig.spec.ExcC14NParameterSpec in project jdk8u_jdk by JetBrains.

the class DOMExcC14NMethod method marshalParams.

public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException {
    super.marshalParams(parent, context);
    AlgorithmParameterSpec spec = getParameterSpec();
    if (spec == null) {
        return;
    }
    String prefix = DOMUtils.getNSPrefix(context, CanonicalizationMethod.EXCLUSIVE);
    Element eElem = DOMUtils.createElement(ownerDoc, "InclusiveNamespaces", CanonicalizationMethod.EXCLUSIVE, prefix);
    if (prefix == null || prefix.length() == 0) {
        eElem.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", CanonicalizationMethod.EXCLUSIVE);
    } else {
        eElem.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + prefix, CanonicalizationMethod.EXCLUSIVE);
    }
    ExcC14NParameterSpec params = (ExcC14NParameterSpec) spec;
    StringBuffer prefixListAttr = new StringBuffer("");
    @SuppressWarnings("unchecked") List<String> prefixList = params.getPrefixList();
    for (int i = 0, size = prefixList.size(); i < size; i++) {
        prefixListAttr.append(prefixList.get(i));
        if (i < size - 1) {
            prefixListAttr.append(" ");
        }
    }
    DOMUtils.setAttribute(eElem, "PrefixList", prefixListAttr.toString());
    this.inclusiveNamespaces = prefixListAttr.toString();
    transformElem.appendChild(eElem);
}
Also used : ExcC14NParameterSpec(javax.xml.crypto.dsig.spec.ExcC14NParameterSpec) Element(org.w3c.dom.Element) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Example 5 with ExcC14NParameterSpec

use of javax.xml.crypto.dsig.spec.ExcC14NParameterSpec in project santuario-java by apache.

the class DOMExcC14NMethod method marshalParams.

@Override
public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException {
    super.marshalParams(parent, context);
    AlgorithmParameterSpec spec = getParameterSpec();
    if (spec == null) {
        return;
    }
    XmlWriterToTree xwriter = new XmlWriterToTree(Marshaller.getMarshallers(), transformElem);
    String prefix = DOMUtils.getNSPrefix(context, CanonicalizationMethod.EXCLUSIVE);
    xwriter.writeStartElement(prefix, "InclusiveNamespaces", CanonicalizationMethod.EXCLUSIVE);
    xwriter.writeNamespace(prefix, CanonicalizationMethod.EXCLUSIVE);
    ExcC14NParameterSpec params = (ExcC14NParameterSpec) spec;
    StringBuilder prefixListAttr = new StringBuilder("");
    List<String> prefixList = getParameterSpecPrefixList(params);
    for (int i = 0, size = prefixList.size(); i < size; i++) {
        prefixListAttr.append(prefixList.get(i));
        if (i < size - 1) {
            prefixListAttr.append(" ");
        }
    }
    xwriter.writeAttribute("", "", "PrefixList", prefixListAttr.toString());
    this.inclusiveNamespaces = prefixListAttr.toString();
    // "InclusiveNamespaces"
    xwriter.writeEndElement();
}
Also used : ExcC14NParameterSpec(javax.xml.crypto.dsig.spec.ExcC14NParameterSpec) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Aggregations

ExcC14NParameterSpec (javax.xml.crypto.dsig.spec.ExcC14NParameterSpec)7 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)3 C14NMethodParameterSpec (javax.xml.crypto.dsig.spec.C14NMethodParameterSpec)1 Element (org.w3c.dom.Element)1