3233N/A/*
3233N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3233N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3233N/A *
3233N/A * This code is free software; you can redistribute it and/or modify it
3233N/A * under the terms of the GNU General Public License version 2 only, as
3233N/A * published by the Free Software Foundation.
3233N/A *
3233N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3233N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3233N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3233N/A * version 2 for more details (a copy is included in the LICENSE file that
3233N/A * accompanied this code).
3233N/A *
3233N/A * You should have received a copy of the GNU General Public License version
3233N/A * 2 along with this work; if not, write to the Free Software Foundation,
3233N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3233N/A *
3233N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3233N/A * or visit www.oracle.com if you need additional information or have any
3233N/A * questions.
3233N/A */
3233N/A
3233N/A/**
3233N/A * @test
3233N/A * @bug 6799854
3233N/A * @summary CodeSigner.hashCode() does not work with serialization
3233N/A */
3233N/A
3233N/Aimport java.io.*;
3233N/Aimport java.security.CodeSigner;
3233N/Aimport java.security.Timestamp;
3233N/Aimport java.security.cert.*;
3233N/Aimport java.util.Collections;
3233N/Aimport java.util.Date;
3233N/A
3233N/Apublic class Serialize {
3233N/A
3233N/A public static void main(String[] args) throws Exception {
3233N/A
3233N/A // Create a certpath consisting of one certificate
3233N/A File f = new File(System.getProperty("test.src", "."), "cert_file");
3233N/A FileInputStream fis = new FileInputStream(f);
3233N/A CertificateFactory cf = CertificateFactory.getInstance("X.509");
3233N/A Certificate c = cf.generateCertificate(fis);
3233N/A fis.close();
3233N/A CertPath cp = cf.generateCertPath(Collections.singletonList(c));
3233N/A
3233N/A // Create a code signer
3233N/A CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));
3233N/A
3233N/A // Serialize the code signer
3233N/A ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
3233N/A ObjectOutputStream out = new ObjectOutputStream(byteOut);
3233N/A out.writeObject(cs);
3233N/A out.close();
3233N/A
3233N/A // Deserialize the code signer
3233N/A byte[] data = byteOut.toByteArray();
3233N/A CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
3233N/A new ByteArrayInputStream(data)).readObject();
3233N/A
3233N/A // Test for equality
3233N/A if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
3233N/A throw new Exception("CodeSigner serialization test FAILED");
3233N/A }
3233N/A }
3233N/A}