blob: 8a6638d55543d6641536339aa1ef372c5f313471 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/**
25 * @test
26 * @bug 4404718
27 * @summary Make sure that a CertPath object can be serialized
28 */
29import java.io.*;
30import java.security.cert.*;
31import java.util.Collections;
32
33public class Serialize {
34
35 public static void main(String args[]) throws Exception {
36
37 // create a certpath consisting of one certificate
38 File f = new File(System.getProperty("test.src", "."), "cert_file");
39 FileInputStream fis = new FileInputStream(f);
40 CertificateFactory cf = CertificateFactory.getInstance("X.509");
41 Certificate c = cf.generateCertificate(fis);
42 fis.close();
43 CertPath outcp = cf.generateCertPath(Collections.singletonList(c));
44
45 // serialize certpath and write it out
46 FileOutputStream fos = new FileOutputStream("certpath.ser");
47 ObjectOutputStream oos = new ObjectOutputStream(fos);
48 oos.writeObject(outcp);
49 oos.flush();
50 oos.close();
51 fos.close();
52
53 // read certpath in and deserialize
54 FileInputStream cfis = new FileInputStream("certpath.ser");
55 ObjectInputStream ois = new ObjectInputStream(cfis);
56 CertPath incp = (CertPath)ois.readObject();
57 ois.close();
58 cfis.close();
59
60 if (!incp.equals(outcp))
61 throw new Exception("CertPath serialization test FAILED");
62 }
63}