1 /*
2 * Copyright (c) 2011, 2020, 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
809
810 int uniqueVal = 1;
811 String originalAlias = alias;
812
813 while (entries.containsKey(alias.toLowerCase())) {
814 alias = originalAlias + " " + uniqueVal;
815 uniqueVal++;
816 }
817
818 entries.put(alias.toLowerCase(), tce);
819 } catch (Exception e) {
820 // The certificate will be skipped.
821 System.err.println("KeychainStore Ignored Exception: " + e);
822 }
823 }
824
825 /**
826 * Callback method from _scanKeychain. If an identity is found, this method will be called to create Java certificate
827 * and private key objects from the keychain data.
828 */
829 private void createKeyEntry(String alias, long creationDate, long secKeyRef, long[] secCertificateRefs, byte[][] rawCertData)
830 throws IOException, NoSuchAlgorithmException, UnrecoverableKeyException {
831 KeyEntry ke = new KeyEntry();
832
833 // First, store off the private key information. This is the easy part.
834 ke.protectedPrivKey = null;
835 ke.keyRef = secKeyRef;
836
837 // Make a creation date.
838 if (creationDate != 0)
839 ke.date = new Date(creationDate);
840 else
841 ke.date = new Date();
842
843 // Next, create X.509 Certificate objects from the raw data. This is complicated
844 // because a certificate's public key may be too long for Java's default encryption strength.
845 List<CertKeychainItemPair> createdCerts = new ArrayList<>();
846
847 try {
848 CertificateFactory cf = CertificateFactory.getInstance("X.509");
849
850 for (int i = 0; i < rawCertData.length; i++) {
|
1 /*
2 * Copyright (c) 2011, 2021, 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
809
810 int uniqueVal = 1;
811 String originalAlias = alias;
812
813 while (entries.containsKey(alias.toLowerCase())) {
814 alias = originalAlias + " " + uniqueVal;
815 uniqueVal++;
816 }
817
818 entries.put(alias.toLowerCase(), tce);
819 } catch (Exception e) {
820 // The certificate will be skipped.
821 System.err.println("KeychainStore Ignored Exception: " + e);
822 }
823 }
824
825 /**
826 * Callback method from _scanKeychain. If an identity is found, this method will be called to create Java certificate
827 * and private key objects from the keychain data.
828 */
829 private void createKeyEntry(String alias, long creationDate, long secKeyRef,
830 long[] secCertificateRefs, byte[][] rawCertData) {
831 KeyEntry ke = new KeyEntry();
832
833 // First, store off the private key information. This is the easy part.
834 ke.protectedPrivKey = null;
835 ke.keyRef = secKeyRef;
836
837 // Make a creation date.
838 if (creationDate != 0)
839 ke.date = new Date(creationDate);
840 else
841 ke.date = new Date();
842
843 // Next, create X.509 Certificate objects from the raw data. This is complicated
844 // because a certificate's public key may be too long for Java's default encryption strength.
845 List<CertKeychainItemPair> createdCerts = new ArrayList<>();
846
847 try {
848 CertificateFactory cf = CertificateFactory.getInstance("X.509");
849
850 for (int i = 0; i < rawCertData.length; i++) {
|