author | jlaskey |
Thu, 14 Nov 2019 12:33:47 -0400 | |
branch | jlaskey-prng |
changeset 59084 | b8fb85ee91e9 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
7548
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
1 |
/* |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
4 |
* |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
8 |
* |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
13 |
* accompanied this code). |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
14 |
* |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
18 |
* |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
21 |
* questions. |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
22 |
*/ |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
23 |
|
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
24 |
/** |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
25 |
* @test |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
26 |
* @bug 6799854 |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
27 |
* @summary CodeSigner.hashCode() does not work with serialization |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
28 |
*/ |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
29 |
|
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
30 |
import java.io.*; |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
31 |
import java.security.CodeSigner; |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
32 |
import java.security.Timestamp; |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
33 |
import java.security.cert.*; |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
34 |
import java.util.Collections; |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
35 |
import java.util.Date; |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
36 |
|
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
37 |
public class Serialize { |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
38 |
|
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
39 |
public static void main(String[] args) throws Exception { |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
40 |
|
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
41 |
// Create a certpath consisting of one certificate |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
42 |
File f = new File(System.getProperty("test.src", "."), "cert_file"); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
43 |
FileInputStream fis = new FileInputStream(f); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
44 |
CertificateFactory cf = CertificateFactory.getInstance("X.509"); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
45 |
Certificate c = cf.generateCertificate(fis); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
46 |
fis.close(); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
47 |
CertPath cp = cf.generateCertPath(Collections.singletonList(c)); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
48 |
|
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
49 |
// Create a code signer |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
50 |
CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp)); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
51 |
|
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
52 |
// Serialize the code signer |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
53 |
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
54 |
ObjectOutputStream out = new ObjectOutputStream(byteOut); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
55 |
out.writeObject(cs); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
56 |
out.close(); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
57 |
|
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
58 |
// Deserialize the code signer |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
59 |
byte[] data = byteOut.toByteArray(); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
60 |
CodeSigner cs2 = (CodeSigner) new ObjectInputStream( |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
61 |
new ByteArrayInputStream(data)).readObject(); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
62 |
|
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
63 |
// Test for equality |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
64 |
if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) { |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
65 |
throw new Exception("CodeSigner serialization test FAILED"); |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
66 |
} |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
67 |
} |
1460351b32bc
6799854: CodeSigner.hashCode() does not work with serialization
vinnie
parents:
diff
changeset
|
68 |
} |