src/share/classes/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java

Print this page

        

*** 1,42 **** /* * reserved comment block * DO NOT REMOVE OR ALTER! */ ! /* ! * Copyright 2005 The Apache Software Foundation. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! * */ /* * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. */ /* ! * $Id: DOMXMLSignatureFactory.java,v 1.2 2008/07/24 15:20:32 mullan Exp $ */ package org.jcp.xml.dsig.internal.dom; import javax.xml.crypto.*; import javax.xml.crypto.dsig.*; import javax.xml.crypto.dsig.dom.DOMValidateContext; import javax.xml.crypto.dsig.keyinfo.*; import javax.xml.crypto.dsig.spec.*; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; - import java.security.spec.AlgorithmParameterSpec; import java.util.List; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; --- 1,44 ---- /* * reserved comment block * DO NOT REMOVE OR ALTER! */ ! /** ! * Licensed to the Apache Software Foundation (ASF) under one ! * or more contributor license agreements. See the NOTICE file ! * distributed with this work for additional information ! * regarding copyright ownership. The ASF licenses this file ! * to you under the Apache License, Version 2.0 (the ! * "License"); you may not use this file except in compliance ! * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * ! * Unless required by applicable law or agreed to in writing, ! * software distributed under the License is distributed on an ! * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ! * KIND, either express or implied. See the License for the ! * specific language governing permissions and limitations ! * under the License. */ /* * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. */ /* ! * $Id: DOMXMLSignatureFactory.java 1333869 2012-05-04 10:42:44Z coheigea $ */ package org.jcp.xml.dsig.internal.dom; import javax.xml.crypto.*; + import javax.xml.crypto.dom.DOMCryptoContext; import javax.xml.crypto.dsig.*; import javax.xml.crypto.dsig.dom.DOMValidateContext; import javax.xml.crypto.dsig.keyinfo.*; import javax.xml.crypto.dsig.spec.*; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import java.util.List; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node;
*** 54,77 **** --- 56,82 ---- public XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki) { return new DOMXMLSignature(si, ki, null, null, null); } + @SuppressWarnings("unchecked") public XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki, List objects, String id, String signatureValueId) { return new DOMXMLSignature(si, ki, objects, id, signatureValueId); } public Reference newReference(String uri, DigestMethod dm) { return newReference(uri, dm, null, null, null); } + @SuppressWarnings("unchecked") public Reference newReference(String uri, DigestMethod dm, List transforms, String type, String id) { return new DOMReference(uri, type, dm, transforms, id, getProvider()); } + @SuppressWarnings("unchecked") public Reference newReference(String uri, DigestMethod dm, List appliedTransforms, Data result, List transforms, String type, String id) { if (appliedTransforms == null) { throw new NullPointerException("appliedTransforms cannot be null");
*** 84,130 **** --- 89,143 ---- } return new DOMReference (uri, type, dm, appliedTransforms, result, transforms, id, getProvider()); } + @SuppressWarnings("unchecked") public Reference newReference(String uri, DigestMethod dm, List transforms, String type, String id, byte[] digestValue) { if (digestValue == null) { throw new NullPointerException("digestValue cannot be null"); } return new DOMReference (uri, type, dm, null, null, transforms, id, digestValue, getProvider()); } + @SuppressWarnings("unchecked") public SignedInfo newSignedInfo(CanonicalizationMethod cm, SignatureMethod sm, List references) { return newSignedInfo(cm, sm, references, null); } + @SuppressWarnings("unchecked") public SignedInfo newSignedInfo(CanonicalizationMethod cm, SignatureMethod sm, List references, String id) { return new DOMSignedInfo(cm, sm, references, id); } // Object factory methods + @SuppressWarnings("unchecked") public XMLObject newXMLObject(List content, String id, String mimeType, String encoding) { return new DOMXMLObject(content, id, mimeType, encoding); } + @SuppressWarnings("unchecked") public Manifest newManifest(List references) { return newManifest(references, null); } + @SuppressWarnings("unchecked") public Manifest newManifest(List references, String id) { return new DOMManifest(references, id); } + @SuppressWarnings("unchecked") public SignatureProperties newSignatureProperties(List props, String id) { return new DOMSignatureProperties(props, id); } + @SuppressWarnings("unchecked") public SignatureProperty newSignatureProperty (List info, String target, String id) { return new DOMSignatureProperty(info, target, id); }
*** 141,156 **** throws MarshalException { if (xmlStructure == null) { throw new NullPointerException("xmlStructure cannot be null"); } return unmarshal (((javax.xml.crypto.dom.DOMStructure) xmlStructure).getNode(), ! null); } ! private XMLSignature unmarshal(Node node, XMLValidateContext context) throws MarshalException { node.normalize(); Element element = null; --- 154,176 ---- throws MarshalException { if (xmlStructure == null) { throw new NullPointerException("xmlStructure cannot be null"); } + if (!(xmlStructure instanceof javax.xml.crypto.dom.DOMStructure)) { + throw new ClassCastException("xmlStructure must be of type DOMStructure"); + } return unmarshal (((javax.xml.crypto.dom.DOMStructure) xmlStructure).getNode(), ! new UnmarshalContext()); } ! private static class UnmarshalContext extends DOMCryptoContext { ! UnmarshalContext() {} ! } ! ! private XMLSignature unmarshal(Node node, XMLCryptoContext context) throws MarshalException { node.normalize(); Element element = null;
*** 219,261 **** return new DOMSignatureMethod.SHA512withRSA(params); } else if (algorithm.equals(SignatureMethod.DSA_SHA1)) { return new DOMSignatureMethod.SHA1withDSA(params); } else if (algorithm.equals(SignatureMethod.HMAC_SHA1)) { return new DOMHMACSignatureMethod.SHA1(params); ! } else if (algorithm.equals(DOMSignatureMethod.HMAC_SHA256)) { return new DOMHMACSignatureMethod.SHA256(params); ! } else if (algorithm.equals(DOMSignatureMethod.HMAC_SHA384)) { return new DOMHMACSignatureMethod.SHA384(params); ! } else if (algorithm.equals(DOMSignatureMethod.HMAC_SHA512)) { return new DOMHMACSignatureMethod.SHA512(params); } else { throw new NoSuchAlgorithmException("unsupported algorithm"); } } public Transform newTransform(String algorithm, TransformParameterSpec params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { TransformService spi; ! try { spi = TransformService.getInstance(algorithm, "DOM"); ! } catch (NoSuchAlgorithmException nsae) { spi = TransformService.getInstance(algorithm, "DOM", getProvider()); } spi.init(params); return new DOMTransform(spi); } public Transform newTransform(String algorithm, XMLStructure params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { TransformService spi; ! try { spi = TransformService.getInstance(algorithm, "DOM"); ! } catch (NoSuchAlgorithmException nsae) { spi = TransformService.getInstance(algorithm, "DOM", getProvider()); } if (params == null) { spi.init(null); } else { spi.init(params, null); } --- 239,300 ---- return new DOMSignatureMethod.SHA512withRSA(params); } else if (algorithm.equals(SignatureMethod.DSA_SHA1)) { return new DOMSignatureMethod.SHA1withDSA(params); } else if (algorithm.equals(SignatureMethod.HMAC_SHA1)) { return new DOMHMACSignatureMethod.SHA1(params); ! } else if (algorithm.equals(DOMHMACSignatureMethod.HMAC_SHA256)) { return new DOMHMACSignatureMethod.SHA256(params); ! } else if (algorithm.equals(DOMHMACSignatureMethod.HMAC_SHA384)) { return new DOMHMACSignatureMethod.SHA384(params); ! } else if (algorithm.equals(DOMHMACSignatureMethod.HMAC_SHA512)) { return new DOMHMACSignatureMethod.SHA512(params); + } else if (algorithm.equals(DOMSignatureMethod.ECDSA_SHA1)) { + return new DOMSignatureMethod.SHA1withECDSA(params); + } else if (algorithm.equals(DOMSignatureMethod.ECDSA_SHA256)) { + return new DOMSignatureMethod.SHA256withECDSA(params); + } else if (algorithm.equals(DOMSignatureMethod.ECDSA_SHA384)) { + return new DOMSignatureMethod.SHA384withECDSA(params); + } else if (algorithm.equals(DOMSignatureMethod.ECDSA_SHA512)) { + return new DOMSignatureMethod.SHA512withECDSA(params); } else { throw new NoSuchAlgorithmException("unsupported algorithm"); } } public Transform newTransform(String algorithm, TransformParameterSpec params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { + TransformService spi; ! if (getProvider() == null) { spi = TransformService.getInstance(algorithm, "DOM"); ! } else { ! try { spi = TransformService.getInstance(algorithm, "DOM", getProvider()); + } catch (NoSuchAlgorithmException nsae) { + spi = TransformService.getInstance(algorithm, "DOM"); + } } + spi.init(params); return new DOMTransform(spi); } public Transform newTransform(String algorithm, XMLStructure params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { TransformService spi; ! if (getProvider() == null) { spi = TransformService.getInstance(algorithm, "DOM"); ! } else { ! try { spi = TransformService.getInstance(algorithm, "DOM", getProvider()); + } catch (NoSuchAlgorithmException nsae) { + spi = TransformService.getInstance(algorithm, "DOM"); + } } + if (params == null) { spi.init(null); } else { spi.init(params, null); }
*** 264,296 **** public CanonicalizationMethod newCanonicalizationMethod(String algorithm, C14NMethodParameterSpec params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { TransformService spi; ! try { spi = TransformService.getInstance(algorithm, "DOM"); ! } catch (NoSuchAlgorithmException nsae) { spi = TransformService.getInstance(algorithm, "DOM", getProvider()); } spi.init(params); return new DOMCanonicalizationMethod(spi); } public CanonicalizationMethod newCanonicalizationMethod(String algorithm, XMLStructure params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { TransformService spi; ! try { spi = TransformService.getInstance(algorithm, "DOM"); ! } catch (NoSuchAlgorithmException nsae) { spi = TransformService.getInstance(algorithm, "DOM", getProvider()); } if (params == null) { spi.init(null); } else { spi.init(params, null); } return new DOMCanonicalizationMethod(spi); } public URIDereferencer getURIDereferencer() { return DOMURIDereferencer.INSTANCE; --- 303,345 ---- public CanonicalizationMethod newCanonicalizationMethod(String algorithm, C14NMethodParameterSpec params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { TransformService spi; ! if (getProvider() == null) { spi = TransformService.getInstance(algorithm, "DOM"); ! } else { ! try { spi = TransformService.getInstance(algorithm, "DOM", getProvider()); + } catch (NoSuchAlgorithmException nsae) { + spi = TransformService.getInstance(algorithm, "DOM"); } + } + spi.init(params); return new DOMCanonicalizationMethod(spi); } public CanonicalizationMethod newCanonicalizationMethod(String algorithm, XMLStructure params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { TransformService spi; ! if (getProvider() == null) { spi = TransformService.getInstance(algorithm, "DOM"); ! } else { ! try { spi = TransformService.getInstance(algorithm, "DOM", getProvider()); + } catch (NoSuchAlgorithmException nsae) { + spi = TransformService.getInstance(algorithm, "DOM"); + } } if (params == null) { spi.init(null); } else { spi.init(params, null); } + return new DOMCanonicalizationMethod(spi); } public URIDereferencer getURIDereferencer() { return DOMURIDereferencer.INSTANCE;