Path: blob/master/test/jdk/java/security/cert/X509Certificate/EmptySubject.java
41152 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;3435public class EmptySubject {3637public static void main(String[] args) throws Exception {3839try {40File f = new File(System.getProperty("test.src", "."),41"emptySubjectCert");42CertificateFactory cf = CertificateFactory.getInstance("X.509");4344try {45X509Certificate cert = (X509Certificate)46cf.generateCertificate(new FileInputStream(f));47throw new Exception("Test 1 Failed - parsed invalid cert");48} catch (CertificateParsingException e) {49System.out.println("Test 1 passed: " + e.toString());50}5152f = new File(System.getProperty("test.src", "."),53"emptyIssuerCert");5455try {56X509Certificate cert2 = (X509Certificate)57cf.generateCertificate(new FileInputStream(f));58throw new Exception("Test 2 Failed - parsed invalid cert");59} catch (CertificateParsingException e) {60System.out.println("Test 2 passed: " + e.toString());61}62} catch (Exception e) {63SecurityException se = new SecurityException("Test Failed");64se.initCause(e);65throw se;66}67}68}697071