|
| 1 | +/* |
| 2 | + * Copyright (c) 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. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8245679 |
| 27 | + * @summary KeyStore cannot probe PKCS12 keystore if BouncyCastle is the top security provider |
| 28 | + * @run main/othervm OneProbeOneNot |
| 29 | + */ |
| 30 | + |
| 31 | +import java.io.File; |
| 32 | +import java.io.InputStream; |
| 33 | +import java.io.OutputStream; |
| 34 | +import java.nio.file.Files; |
| 35 | +import java.nio.file.Path; |
| 36 | +import java.security.*; |
| 37 | +import java.security.cert.Certificate; |
| 38 | +import java.util.Date; |
| 39 | +import java.util.Enumeration; |
| 40 | + |
| 41 | +public class OneProbeOneNot { |
| 42 | + public static final void main(String[] args) throws Exception { |
| 43 | + Files.write(Path.of("ks"), "".getBytes()); |
| 44 | + // 1st provider do not support probe |
| 45 | + Security.insertProviderAt(new P1(), 1); |
| 46 | + // 2nd provider support probe |
| 47 | + Security.insertProviderAt(new P2(), 2); |
| 48 | + KeyStore ks = KeyStore.getInstance(new File("ks"), (char[])null); |
| 49 | + System.out.println(ks.getProvider().getName()); |
| 50 | + System.out.println(ks.getType()); |
| 51 | + } |
| 52 | + |
| 53 | + public static class P1 extends Provider { |
| 54 | + public P1() { |
| 55 | + super("P1", "P1", "P1"); |
| 56 | + putService(new Service(this, "KeyStore", "Oops", |
| 57 | + K1.class.getName(), null, null)); |
| 58 | + } |
| 59 | + } |
| 60 | + public static class P2 extends Provider { |
| 61 | + public P2() { |
| 62 | + super("P2", "P2", "P2"); |
| 63 | + putService(new Service(this, "KeyStore", "Oops", |
| 64 | + K2.class.getName(), null, null)); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + public static class K1 extends KeyStoreSpi { |
| 69 | + public Key engineGetKey(String a, char[] p) { return null; } |
| 70 | + public Certificate[] engineGetCertificateChain(String a) { return null; } |
| 71 | + public Certificate engineGetCertificate(String a) { return null; } |
| 72 | + public Date engineGetCreationDate(String a) { return null; } |
| 73 | + public void engineSetKeyEntry(String a, Key k, char[] p, Certificate[] c) { } |
| 74 | + public void engineSetKeyEntry(String a, byte[] k, Certificate[] c) { } |
| 75 | + public void engineSetCertificateEntry(String a, Certificate c) { } |
| 76 | + public void engineDeleteEntry(String a) { } |
| 77 | + public Enumeration<String> engineAliases() { return null; } |
| 78 | + public boolean engineContainsAlias(String a) { return false; } |
| 79 | + public int engineSize() { return 0; } |
| 80 | + public boolean engineIsKeyEntry(String a) { return false; } |
| 81 | + public boolean engineIsCertificateEntry(String a) { return false; } |
| 82 | + public String engineGetCertificateAlias(Certificate c) { return null; } |
| 83 | + public void engineStore(OutputStream stream, char[] password) { } |
| 84 | + public void engineLoad(InputStream stream, char[] password) { } |
| 85 | + } |
| 86 | + |
| 87 | + public static class K2 extends K1 { |
| 88 | + public boolean engineProbe(InputStream s) { |
| 89 | + return true; |
| 90 | + } |
| 91 | + } |
| 92 | +} |
0 commit comments