Path: blob/master/test/jdk/sun/security/pkcs12/MixedcaseAlias.java
41149 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 817395626* @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 with mixed-case alias can be retrieved.37*/38public class MixedcaseAlias {39private static final String DIR = System.getProperty("test.src", ".");40private static final String CERT = DIR + "/trusted.pem";41private static final String ALIAS = "Mixed-case Alias";4243public static void main(String[] ignored) throws Exception {44KeyStore keystore = KeyStore.getInstance("PKCS12");45keystore.load(null, null);4647keystore.setCertificateEntry(ALIAS, loadCertificate(CERT));48KeyStore.Entry entry = keystore.getEntry(ALIAS, null);4950if (entry == null) {51throw new Exception(52"Error retrieving keystore entry using a mixed-case alias");53}5455System.out.println("OK");56}5758private static Certificate loadCertificate(String certFile)59throws Exception {60X509Certificate cert = null;61try (FileInputStream certStream = new FileInputStream(certFile)) {62CertificateFactory factory =63CertificateFactory.getInstance("X.509");64return factory.generateCertificate(certStream);65}66}67}686970