src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMCanonicalXMLC14N11Method.java
author jlahoda
Tue, 24 Sep 2019 15:40:26 +0200
branchJDK-8226585-branch
changeset 58290 d885633d9de4
parent 53998 d870bb08194a
permissions -rw-r--r--
Converting the test to a combo-framework test.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
     1
/*
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
     2
 * reserved comment block
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
     4
 */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     5
/**
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     7
 * or more contributor license agreements. See the NOTICE file
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     8
 * distributed with this work for additional information
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     9
 * regarding copyright ownership. The ASF licenses this file
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    10
 * to you under the Apache License, Version 2.0 (the
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    11
 * "License"); you may not use this file except in compliance
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    12
 * with the License. You may obtain a copy of the License at
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    13
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    14
 * http://www.apache.org/licenses/LICENSE-2.0
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    15
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    16
 * Unless required by applicable law or agreed to in writing,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    17
 * software distributed under the License is distributed on an
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    18
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    19
 * KIND, either express or implied. See the License for the
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    20
 * specific language governing permissions and limitations
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    21
 * under the License.
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    22
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    23
/*
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    24
 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    25
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    26
/*
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    27
 * $Id$
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    28
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    29
package org.jcp.xml.dsig.internal.dom;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    30
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    31
import javax.xml.crypto.*;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    32
import javax.xml.crypto.dsig.*;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    33
import javax.xml.crypto.dsig.spec.TransformParameterSpec;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    34
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    35
import java.security.InvalidAlgorithmParameterException;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    36
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    37
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    38
import com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    39
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    40
/**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    41
 * DOM-based implementation of CanonicalizationMethod for Canonical XML 1.1
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    42
 * (with or without comments). Uses Apache XML-Sec Canonicalizer.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    43
 *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    44
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    45
public final class DOMCanonicalXMLC14N11Method extends ApacheCanonicalizer {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    46
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    47
    public static final String C14N_11 = "http://www.w3.org/2006/12/xml-c14n11";
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    48
    public static final String C14N_11_WITH_COMMENTS
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    49
        = "http://www.w3.org/2006/12/xml-c14n11#WithComments";
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    50
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    51
    public void init(TransformParameterSpec params)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    52
        throws InvalidAlgorithmParameterException {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    53
        if (params != null) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    54
            throw new InvalidAlgorithmParameterException("no parameters " +
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    55
                "should be specified for Canonical XML 1.1 algorithm");
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    56
        }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    57
    }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    58
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    59
    public Data transform(Data data, XMLCryptoContext xc)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    60
        throws TransformException {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    61
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    62
        // ignore comments if dereferencing same-document URI that requires
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    63
        // you to omit comments, even if the Transform says otherwise -
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    64
        // this is to be compliant with section 4.3.3.3 of W3C Rec.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    65
        if (data instanceof DOMSubTreeData) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    66
            DOMSubTreeData subTree = (DOMSubTreeData) data;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    67
            if (subTree.excludeComments()) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    68
                try {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    69
                    apacheCanonicalizer = Canonicalizer.getInstance(C14N_11);
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    70
                    boolean secVal = Utils.secureValidation(xc);
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    71
                    apacheCanonicalizer.setSecureValidation(secVal);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    72
                } catch (InvalidCanonicalizerException ice) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    73
                    throw new TransformException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    74
                        ("Couldn't find Canonicalizer for: " +
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    75
                         C14N_11 + ": " + ice.getMessage(), ice);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    76
                }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    77
            }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    78
        }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    79
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    80
        return canonicalize(data, xc);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    81
    }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents:
diff changeset
    82
}