Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/xml/crypto/dsig/XMLSignature.java
38918 views
/*1* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* ===========================================================================27*28* (C) Copyright IBM Corp. 2003 All Rights Reserved.29*30* ===========================================================================31*/32/*33* $Id: XMLSignature.java,v 1.10 2005/05/10 16:03:48 mullan Exp $34*/35package javax.xml.crypto.dsig;3637import javax.xml.crypto.KeySelector;38import javax.xml.crypto.KeySelectorResult;39import javax.xml.crypto.MarshalException;40import javax.xml.crypto.XMLStructure;41import javax.xml.crypto.dsig.keyinfo.KeyInfo;42import java.security.Signature;43import java.util.List;4445/**46* A representation of the XML <code>Signature</code> element as47* defined in the <a href="http://www.w3.org/TR/xmldsig-core/">48* W3C Recommendation for XML-Signature Syntax and Processing</a>.49* This class contains methods for signing and validating XML signatures50* with behavior as defined by the W3C specification. The XML Schema Definition51* is defined as:52* <pre><code>53* <element name="Signature" type="ds:SignatureType"/>54* <complexType name="SignatureType">55* <sequence>56* <element ref="ds:SignedInfo"/>57* <element ref="ds:SignatureValue"/>58* <element ref="ds:KeyInfo" minOccurs="0"/>59* <element ref="ds:Object" minOccurs="0" maxOccurs="unbounded"/>60* </sequence>61* <attribute name="Id" type="ID" use="optional"/>62* </complexType>63* </code></pre>64* <p>65* An <code>XMLSignature</code> instance may be created by invoking one of the66* {@link XMLSignatureFactory#newXMLSignature newXMLSignature} methods of the67* {@link XMLSignatureFactory} class.68*69* <p>If the contents of the underlying document containing the70* <code>XMLSignature</code> are subsequently modified, the behavior is71* undefined.72*73* <p>Note that this class is named <code>XMLSignature</code> rather than74* <code>Signature</code> to avoid naming clashes with the existing75* {@link Signature java.security.Signature} class.76*77* @see XMLSignatureFactory#newXMLSignature(SignedInfo, KeyInfo)78* @see XMLSignatureFactory#newXMLSignature(SignedInfo, KeyInfo, List, String, String)79* @author Joyce L. Leung80* @author Sean Mullan81* @author Erwin van der Koogh82* @author JSR 105 Expert Group83* @since 1.684*/85public interface XMLSignature extends XMLStructure {8687/**88* The XML Namespace URI of the W3C Recommendation for XML-Signature89* Syntax and Processing.90*/91final static String XMLNS = "http://www.w3.org/2000/09/xmldsig#";9293/**94* Validates the signature according to the95* <a href="http://www.w3.org/TR/xmldsig-core/#sec-CoreValidation">96* core validation processing rules</a>. This method validates the97* signature using the existing state, it does not unmarshal and98* reinitialize the contents of the <code>XMLSignature</code> using the99* location information specified in the context.100*101* <p>This method only validates the signature the first time it is102* invoked. On subsequent invocations, it returns a cached result.103*104* @param validateContext the validating context105* @return <code>true</code> if the signature passed core validation,106* otherwise <code>false</code>107* @throws ClassCastException if the type of <code>validateContext</code>108* is not compatible with this <code>XMLSignature</code>109* @throws NullPointerException if <code>validateContext</code> is110* <code>null</code>111* @throws XMLSignatureException if an unexpected error occurs during112* validation that prevented the validation operation from completing113*/114boolean validate(XMLValidateContext validateContext)115throws XMLSignatureException;116117/**118* Returns the key info of this <code>XMLSignature</code>.119*120* @return the key info (may be <code>null</code> if not specified)121*/122KeyInfo getKeyInfo();123124/**125* Returns the signed info of this <code>XMLSignature</code>.126*127* @return the signed info (never <code>null</code>)128*/129SignedInfo getSignedInfo();130131/**132* Returns an {@link java.util.Collections#unmodifiableList unmodifiable133* list} of {@link XMLObject}s contained in this <code>XMLSignature</code>.134*135* @return an unmodifiable list of <code>XMLObject</code>s (may be empty136* but never <code>null</code>)137*/138@SuppressWarnings("rawtypes")139List getObjects();140141/**142* Returns the optional Id of this <code>XMLSignature</code>.143*144* @return the Id (may be <code>null</code> if not specified)145*/146String getId();147148/**149* Returns the signature value of this <code>XMLSignature</code>.150*151* @return the signature value152*/153SignatureValue getSignatureValue();154155/**156* Signs this <code>XMLSignature</code>.157*158* <p>If this method throws an exception, this <code>XMLSignature</code> and159* the <code>signContext</code> parameter will be left in the state that160* it was in prior to the invocation.161*162* @param signContext the signing context163* @throws ClassCastException if the type of <code>signContext</code> is164* not compatible with this <code>XMLSignature</code>165* @throws NullPointerException if <code>signContext</code> is166* <code>null</code>167* @throws MarshalException if an exception occurs while marshalling168* @throws XMLSignatureException if an unexpected exception occurs while169* generating the signature170*/171void sign(XMLSignContext signContext) throws MarshalException,172XMLSignatureException;173174/**175* Returns the result of the {@link KeySelector}, if specified, after176* this <code>XMLSignature</code> has been signed or validated.177*178* @return the key selector result, or <code>null</code> if a key179* selector has not been specified or this <code>XMLSignature</code>180* has not been signed or validated181*/182KeySelectorResult getKeySelectorResult();183184/**185* A representation of the XML <code>SignatureValue</code> element as186* defined in the <a href="http://www.w3.org/TR/xmldsig-core/">187* W3C Recommendation for XML-Signature Syntax and Processing</a>.188* The XML Schema Definition is defined as:189* <p>190* <pre>191* <element name="SignatureValue" type="ds:SignatureValueType"/>192* <complexType name="SignatureValueType">193* <simpleContent>194* <extension base="base64Binary">195* <attribute name="Id" type="ID" use="optional"/>196* </extension>197* </simpleContent>198* </complexType>199* </pre>200*201* @author Sean Mullan202* @author JSR 105 Expert Group203*/204public interface SignatureValue extends XMLStructure {205/**206* Returns the optional <code>Id</code> attribute of this207* <code>SignatureValue</code>, which permits this element to be208* referenced from elsewhere.209*210* @return the <code>Id</code> attribute (may be <code>null</code> if211* not specified)212*/213String getId();214215/**216* Returns the signature value of this <code>SignatureValue</code>.217*218* @return the signature value (may be <code>null</code> if the219* <code>XMLSignature</code> has not been signed yet). Each220* invocation of this method returns a new clone of the array to221* prevent subsequent modification.222*/223byte[] getValue();224225/**226* Validates the signature value. This method performs a227* cryptographic validation of the signature calculated over the228* <code>SignedInfo</code> of the <code>XMLSignature</code>.229*230* <p>This method only validates the signature the first231* time it is invoked. On subsequent invocations, it returns a cached232* result.233*234* @return <code>true</code> if the signature was235* validated successfully; <code>false</code> otherwise236* @param validateContext the validating context237* @throws NullPointerException if <code>validateContext</code> is238* <code>null</code>239* @throws XMLSignatureException if an unexpected exception occurs while240* validating the signature241*/242boolean validate(XMLValidateContext validateContext)243throws XMLSignatureException;244}245}246247248