mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8302111: Serialization considerations
Reviewed-by: skoivu, rhalade, weijun, wetmore
This commit is contained in:
parent
df7d6e081f
commit
369c573383
21 changed files with 747 additions and 468 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -152,20 +152,20 @@ public final class SignedObject implements Serializable {
|
|||
*/
|
||||
public SignedObject(Serializable object, PrivateKey signingKey,
|
||||
Signature signingEngine)
|
||||
throws IOException, InvalidKeyException, SignatureException {
|
||||
// creating a stream pipe-line, from a to b
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
ObjectOutput a = new ObjectOutputStream(b);
|
||||
throws IOException, InvalidKeyException, SignatureException {
|
||||
// creating a stream pipe-line, from a to b
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
ObjectOutput a = new ObjectOutputStream(b);
|
||||
|
||||
// write and flush the object content to byte array
|
||||
a.writeObject(object);
|
||||
a.flush();
|
||||
a.close();
|
||||
this.content = b.toByteArray();
|
||||
b.close();
|
||||
// write and flush the object content to byte array
|
||||
a.writeObject(object);
|
||||
a.flush();
|
||||
a.close();
|
||||
this.content = b.toByteArray();
|
||||
b.close();
|
||||
|
||||
// now sign the encapsulated object
|
||||
this.sign(signingKey, signingEngine);
|
||||
// now sign the encapsulated object
|
||||
this.sign(signingKey, signingEngine);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,12 +245,12 @@ public final class SignedObject implements Serializable {
|
|||
* @throws SignatureException if signing fails.
|
||||
*/
|
||||
private void sign(PrivateKey signingKey, Signature signingEngine)
|
||||
throws InvalidKeyException, SignatureException {
|
||||
// initialize the signing engine
|
||||
signingEngine.initSign(signingKey);
|
||||
signingEngine.update(this.content.clone());
|
||||
this.signature = signingEngine.sign().clone();
|
||||
this.thealgorithm = signingEngine.getAlgorithm();
|
||||
throws InvalidKeyException, SignatureException {
|
||||
// initialize the signing engine
|
||||
signingEngine.initSign(signingKey);
|
||||
signingEngine.update(this.content.clone());
|
||||
this.signature = signingEngine.sign();
|
||||
this.thealgorithm = signingEngine.getAlgorithm();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -263,10 +263,16 @@ public final class SignedObject implements Serializable {
|
|||
*/
|
||||
@Serial
|
||||
private void readObject(ObjectInputStream s)
|
||||
throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream.GetField fields = s.readFields();
|
||||
content = ((byte[])fields.get("content", null)).clone();
|
||||
signature = ((byte[])fields.get("signature", null)).clone();
|
||||
thealgorithm = (String)fields.get("thealgorithm", null);
|
||||
throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream.GetField fields = s.readFields();
|
||||
byte[] c = (byte[]) fields.get("content", null);
|
||||
byte[] sig = (byte[]) fields.get("signature", null);
|
||||
String a = (String) fields.get("thealgorithm", null);
|
||||
if (c == null || sig == null || a == null) {
|
||||
throw new InvalidObjectException("One or more null fields");
|
||||
}
|
||||
content = c.clone();
|
||||
signature = sig.clone();
|
||||
thealgorithm = a;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue