src/java.base/share/classes/java/security/SignedObject.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 47216 71c04702a3d5
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   116  * @since 1.2
   116  * @since 1.2
   117  */
   117  */
   118 
   118 
   119 public final class SignedObject implements Serializable {
   119 public final class SignedObject implements Serializable {
   120 
   120 
       
   121     @java.io.Serial
   121     private static final long serialVersionUID = 720502720485447167L;
   122     private static final long serialVersionUID = 720502720485447167L;
   122 
   123 
   123     /*
   124     /*
   124      * The original content is "deep copied" in its serialized format
   125      * The original content is "deep copied" in its serialized format
   125      * and stored in a byte array.  The signature field is also in the
   126      * and stored in a byte array.  The signature field is also in the
   137      *
   138      *
   138      * @param object the object to be signed.
   139      * @param object the object to be signed.
   139      * @param signingKey the private key for signing.
   140      * @param signingKey the private key for signing.
   140      * @param signingEngine the signature signing engine.
   141      * @param signingEngine the signature signing engine.
   141      *
   142      *
   142      * @exception IOException if an error occurs during serialization
   143      * @throws    IOException if an error occurs during serialization
   143      * @exception InvalidKeyException if the key is invalid.
   144      * @throws    InvalidKeyException if the key is invalid.
   144      * @exception SignatureException if signing fails.
   145      * @throws    SignatureException if signing fails.
   145      */
   146      */
   146     public SignedObject(Serializable object, PrivateKey signingKey,
   147     public SignedObject(Serializable object, PrivateKey signingKey,
   147                         Signature signingEngine)
   148                         Signature signingEngine)
   148         throws IOException, InvalidKeyException, SignatureException {
   149         throws IOException, InvalidKeyException, SignatureException {
   149             // creating a stream pipe-line, from a to b
   150             // creating a stream pipe-line, from a to b
   165      * Retrieves the encapsulated object.
   166      * Retrieves the encapsulated object.
   166      * The encapsulated object is de-serialized before it is returned.
   167      * The encapsulated object is de-serialized before it is returned.
   167      *
   168      *
   168      * @return the encapsulated object.
   169      * @return the encapsulated object.
   169      *
   170      *
   170      * @exception IOException if an error occurs during de-serialization
   171      * @throws    IOException if an error occurs during de-serialization
   171      * @exception ClassNotFoundException if an error occurs during
   172      * @throws    ClassNotFoundException if an error occurs during
   172      * de-serialization
   173      * de-serialization
   173      */
   174      */
   174     public Object getObject()
   175     public Object getObject()
   175         throws IOException, ClassNotFoundException
   176         throws IOException, ClassNotFoundException
   176     {
   177     {
   209      * verification key, using the designated verification engine.
   210      * verification key, using the designated verification engine.
   210      *
   211      *
   211      * @param verificationKey the public key for verification.
   212      * @param verificationKey the public key for verification.
   212      * @param verificationEngine the signature verification engine.
   213      * @param verificationEngine the signature verification engine.
   213      *
   214      *
   214      * @exception SignatureException if signature verification failed (an
   215      * @throws    SignatureException if signature verification failed (an
   215      *     exception prevented the signature verification engine from completing
   216      *     exception prevented the signature verification engine from completing
   216      *     normally).
   217      *     normally).
   217      * @exception InvalidKeyException if the verification key is invalid.
   218      * @throws    InvalidKeyException if the verification key is invalid.
   218      *
   219      *
   219      * @return {@code true} if the signature
   220      * @return {@code true} if the signature
   220      * is valid, {@code false} otherwise
   221      * is valid, {@code false} otherwise
   221      */
   222      */
   222     public boolean verify(PublicKey verificationKey,
   223     public boolean verify(PublicKey verificationKey,
   232      * designated signature engine.
   233      * designated signature engine.
   233      *
   234      *
   234      * @param signingKey the private key for signing.
   235      * @param signingKey the private key for signing.
   235      * @param signingEngine the signature signing engine.
   236      * @param signingEngine the signature signing engine.
   236      *
   237      *
   237      * @exception InvalidKeyException if the key is invalid.
   238      * @throws    InvalidKeyException if the key is invalid.
   238      * @exception SignatureException if signing fails.
   239      * @throws    SignatureException if signing fails.
   239      */
   240      */
   240     private void sign(PrivateKey signingKey, Signature signingEngine)
   241     private void sign(PrivateKey signingKey, Signature signingEngine)
   241         throws InvalidKeyException, SignatureException {
   242         throws InvalidKeyException, SignatureException {
   242             // initialize the signing engine
   243             // initialize the signing engine
   243             signingEngine.initSign(signingKey);
   244             signingEngine.initSign(signingKey);
   248 
   249 
   249     /**
   250     /**
   250      * readObject is called to restore the state of the SignedObject from
   251      * readObject is called to restore the state of the SignedObject from
   251      * a stream.
   252      * a stream.
   252      */
   253      */
       
   254     @java.io.Serial
   253     private void readObject(java.io.ObjectInputStream s)
   255     private void readObject(java.io.ObjectInputStream s)
   254         throws java.io.IOException, ClassNotFoundException {
   256         throws java.io.IOException, ClassNotFoundException {
   255             java.io.ObjectInputStream.GetField fields = s.readFields();
   257             java.io.ObjectInputStream.GetField fields = s.readFields();
   256             content = ((byte[])fields.get("content", null)).clone();
   258             content = ((byte[])fields.get("content", null)).clone();
   257             signature = ((byte[])fields.get("signature", null)).clone();
   259             signature = ((byte[])fields.get("signature", null)).clone();