Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/security/cert/X509Certificate/EmptySubject.java
47490 views
/*1* Copyright (c) 2001, 2002, 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* @test 1.2, 01/06/2725* @bug 447491426*27* @summary getSubjectDN and getSubjectX500Principal are underspecified28* if subject is empty29*/30import java.io.*;31import java.security.Principal;32import java.security.cert.*;33import javax.security.auth.x500.X500Principal;3435import sun.security.x509.*;3637public class EmptySubject {3839public static void main(String[] args) throws Exception {4041try {42File f = new File(System.getProperty("test.src", "."),43"emptySubjectCert");44CertificateFactory cf = CertificateFactory.getInstance("X.509");4546try {47X509Certificate cert = (X509Certificate)48cf.generateCertificate(new FileInputStream(f));49throw new Exception("Test 1 Failed - parsed invalid cert");50} catch (CertificateParsingException e) {51System.out.println("Test 1 passed: " + e.toString());52}5354f = new File(System.getProperty("test.src", "."),55"emptyIssuerCert");5657try {58X509Certificate cert2 = (X509Certificate)59cf.generateCertificate(new FileInputStream(f));60throw new Exception("Test 2 Failed - parsed invalid cert");61} catch (CertificateParsingException e) {62System.out.println("Test 2 passed: " + e.toString());63}64} catch (Exception e) {65SecurityException se = new SecurityException("Test Failed");66se.initCause(e);67throw se;68}69}70}717273