Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/provider/certpath/CertId/CheckCertId.java
38862 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 635529526* @summary Certificate validation using OCSP fails for a particular class of certificates27*/2829import java.io.*;30import java.security.MessageDigest;31import java.util.Arrays;32import sun.security.provider.certpath.CertId;33import sun.security.x509.X509CertImpl;3435/*36* Checks that the hash value for a certificate's issuer name is generated37* correctly. Requires any certificate that is not self-signed.38*39* NOTE: this test uses Sun private classes which are subject to change.40*/41public class CheckCertId {4243private static final String CERT_FILENAME = "interCA.der";4445public static void main(String[] args) throws Exception {4647X509CertImpl cert = loadCert(CERT_FILENAME);4849/* Compute the hash in the same way as CertId constructor */50MessageDigest hash = MessageDigest.getInstance("SHA1");51hash.update(cert.getSubjectX500Principal().getEncoded());52byte[] expectedHash = hash.digest();5354CertId certId = new CertId(cert, null);55byte[] receivedHash = certId.getIssuerNameHash();5657if (! Arrays.equals(expectedHash, receivedHash)) {58throw new59Exception("Bad hash value for issuer name in CertId object");60}61}6263/*64* Load an X.509 certificate from a file.65* Return it as a Sun private class.66*/67private static X509CertImpl loadCert(String filename) throws Exception {6869BufferedInputStream bis =70new BufferedInputStream(71new FileInputStream(72new File(System.getProperty("test.src", "."), filename)));7374return new X509CertImpl(bis);75}76}777879