Path: blob/master/test/jdk/sun/security/pkcs12/EmptyAlias.java
41152 views
/*1* Copyright (c) 2017, 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 817318126* @summary KeyStore regression due to default keystore being changed to PKCS1227*/2829import java.io.*;30import java.security.KeyStore;31import java.security.cert.Certificate;32import java.security.cert.CertificateFactory;33import java.security.cert.X509Certificate;3435/**36* Test that a PKCS12 keystore entry can be created with an empty alias name.37*/38public class EmptyAlias {3940private static final String DIR = System.getProperty("test.src", ".");41private static final String CERT = DIR + "/trusted.pem";42private static final String EMPTY_ALIAS = "";4344public static void main(String[] args) throws Exception {45KeyStore keystore = KeyStore.getInstance("PKCS12");46keystore.load(null, null);4748keystore.setCertificateEntry(EMPTY_ALIAS, loadCertificate(CERT));49KeyStore.Entry entry = keystore.getEntry(EMPTY_ALIAS, null);5051if (entry == null) {52throw new Exception(53"Error retrieving keystore entry using its (empty) alias");54}5556System.out.println("OK");57}5859private static Certificate loadCertificate(String certFile)60throws Exception {61X509Certificate cert = null;62try (FileInputStream certStream = new FileInputStream(certFile)) {63CertificateFactory factory =64CertificateFactory.getInstance("X.509");65return factory.generateCertificate(certStream);66}67}68}697071