1 /* 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.security.provider; 27 28 import java.io.*; 29 import java.security.*; 30 import java.security.cert.Certificate; 31 import java.security.cert.CertificateFactory; 32 import java.security.cert.CertificateException; 33 import java.util.*; 34 import sun.misc.IOUtils; 35 36 import sun.security.pkcs.EncryptedPrivateKeyInfo; 37 38 /** 39 * This class provides the keystore implementation referred to as "JKS". 40 * 41 * @author Jan Luehe 42 * @author David Brownell 43 * 44 * 45 * @see KeyProtector 46 * @see java.security.KeyStoreSpi 47 * @see KeyTool 48 * 49 * @since 1.2 50 */ 51 52 abstract class JavaKeyStore extends KeyStoreSpi { 53 54 // regular JKS 55 public static final class JKS extends JavaKeyStore { 56 String convertAlias(String alias) { 57 return alias.toLowerCase(Locale.ENGLISH); 58 } 59 } 60 61 // special JKS that uses case sensitive aliases 62 public static final class CaseExactJKS extends JavaKeyStore { 63 String convertAlias(String alias) { 64 return alias; 65 } 66 } 67 68 private static final int MAGIC = 0xfeedfeed; 69 private static final int VERSION_1 = 0x01; 70 private static final int VERSION_2 = 0x02; 71 72 // Private keys and their supporting certificate chains 73 private static class KeyEntry { 74 Date date; // the creation date of this entry 75 byte[] protectedPrivKey; 76 Certificate chain[]; 77 }; 78 79 // Trusted certificates 80 private static class TrustedCertEntry { 81 Date date; // the creation date of this entry 82 Certificate cert; 83 }; 84 85 /** 86 * Private keys and certificates are stored in a hashtable. | 1 /* 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.security.provider; 27 28 import java.io.*; 29 import java.security.*; 30 import java.security.cert.Certificate; 31 import java.security.cert.CertificateFactory; 32 import java.security.cert.CertificateException; 33 import java.util.*; 34 35 import sun.misc.IOUtils; 36 import sun.security.pkcs.EncryptedPrivateKeyInfo; 37 import sun.security.pkcs12.PKCS12KeyStore; 38 39 /** 40 * This class provides the keystore implementation referred to as "JKS". 41 * 42 * @author Jan Luehe 43 * @author David Brownell 44 * 45 * 46 * @see KeyProtector 47 * @see java.security.KeyStoreSpi 48 * @see KeyTool 49 * 50 * @since 1.2 51 */ 52 53 abstract class JavaKeyStore extends KeyStoreSpi { 54 55 // regular JKS 56 public static final class JKS extends JavaKeyStore { 57 String convertAlias(String alias) { 58 return alias.toLowerCase(Locale.ENGLISH); 59 } 60 } 61 62 // special JKS that uses case sensitive aliases 63 public static final class CaseExactJKS extends JavaKeyStore { 64 String convertAlias(String alias) { 65 return alias; 66 } 67 } 68 69 // special JKS that supports JKS and PKCS12 file formats 70 public static final class DualFormatJKS extends KeyStoreDelegator { 71 public DualFormatJKS() { 72 super("JKS", JKS.class, "PKCS12", PKCS12KeyStore.class); 73 } 74 } 75 76 private static final int MAGIC = 0xfeedfeed; 77 private static final int VERSION_1 = 0x01; 78 private static final int VERSION_2 = 0x02; 79 80 // Private keys and their supporting certificate chains 81 private static class KeyEntry { 82 Date date; // the creation date of this entry 83 byte[] protectedPrivKey; 84 Certificate chain[]; 85 }; 86 87 // Trusted certificates 88 private static class TrustedCertEntry { 89 Date date; // the creation date of this entry 90 Certificate cert; 91 }; 92 93 /** 94 * Private keys and certificates are stored in a hashtable. |