Path: blob/master/test/jdk/sun/security/x509/X509CertImpl/GetFingerprintError.java
66646 views
/*1* Copyright (c) 2021, 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 827094626* @library /test/lib27* @modules java.base/sun.security.x50928* java.base/sun.security.util29* @summary Check that X509CertImpl.getFingerprint does not return null when30* there are errors calculating the fingerprint31*/3233import java.security.cert.CertificateEncodingException;34import java.security.cert.X509Certificate;35import sun.security.x509.X509CertImpl;36import sun.security.util.Debug;3738import jdk.test.lib.Asserts;39import jdk.test.lib.security.CertUtils;4041public class GetFingerprintError {4243private static final Debug dbg = Debug.getInstance("certpath");4445public static void main(String[] args) throws Exception {46X509Certificate cert = CertUtils.getCertFromString(CertUtils.RSA_CERT);4748// test invalid MessageDigest algorithm49Asserts.assertNull(X509CertImpl.getFingerprint("NoSuchAlg", cert, dbg));5051// test cert with bad encoding52X509Certificate fcert = new X509CertificateWithBadEncoding(cert);53Asserts.assertNull(X509CertImpl.getFingerprint("SHA-256", fcert, dbg));54}5556private static class X509CertificateWithBadEncoding57extends CertUtils.ForwardingX509Certificate {58private X509CertificateWithBadEncoding(X509Certificate cert) {59super(cert);60}61@Override62public byte[] getEncoded() throws CertificateEncodingException {63throw new CertificateEncodingException();64}65}66}676869