mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
Merge
This commit is contained in:
commit
76879aa9c6
6 changed files with 142 additions and 47 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -1762,35 +1762,33 @@ public class KeyStore {
|
|||
dataStream.mark(Integer.MAX_VALUE);
|
||||
|
||||
// Detect the keystore type
|
||||
for (String type : Security.getAlgorithms("KeyStore")) {
|
||||
Object[] objs = null;
|
||||
|
||||
try {
|
||||
objs = Security.getImpl(type, "KeyStore", (String)null);
|
||||
|
||||
KeyStoreSpi impl = (KeyStoreSpi)objs[0];
|
||||
if (impl.engineProbe(dataStream)) {
|
||||
|
||||
if (kdebug != null) {
|
||||
kdebug.println(type + " keystore detected: " +
|
||||
file);
|
||||
for (Provider p : Security.getProviders()) {
|
||||
for (Provider.Service s : p.getServices()) {
|
||||
if (s.getType().equals("KeyStore")) {
|
||||
try {
|
||||
KeyStoreSpi impl = (KeyStoreSpi) s.newInstance(null);
|
||||
if (impl.engineProbe(dataStream)) {
|
||||
if (kdebug != null) {
|
||||
kdebug.println(s.getAlgorithm()
|
||||
+ " keystore detected: " + file);
|
||||
}
|
||||
keystore = new KeyStore(impl, p, s.getAlgorithm());
|
||||
break;
|
||||
}
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// ignore
|
||||
if (kdebug != null) {
|
||||
kdebug.println("not found - " + e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
if (kdebug != null) {
|
||||
kdebug.println("I/O error in " + file + " - " + e);
|
||||
}
|
||||
}
|
||||
|
||||
keystore = new KeyStore(impl, (Provider)objs[1], type);
|
||||
break;
|
||||
}
|
||||
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
|
||||
// ignore
|
||||
if (kdebug != null) {
|
||||
kdebug.println(type + " not found - " + e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
if (kdebug != null) {
|
||||
kdebug.println("I/O error in " + file + " - " + e);
|
||||
dataStream.reset(); // prepare the stream for the next probe
|
||||
}
|
||||
}
|
||||
dataStream.reset(); // prepare the stream for the next probe
|
||||
}
|
||||
|
||||
// Load the keystore data
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -75,6 +75,22 @@ public abstract class JavaKeyStore extends KeyStoreSpi {
|
|||
public DualFormatJKS() {
|
||||
super("JKS", JKS.class, "PKCS12", PKCS12KeyStore.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Probe the first few bytes of the keystore data stream for a valid
|
||||
* JKS keystore encoding.
|
||||
*/
|
||||
@Override
|
||||
public boolean engineProbe(InputStream stream) throws IOException {
|
||||
DataInputStream dataStream;
|
||||
if (stream instanceof DataInputStream) {
|
||||
dataStream = (DataInputStream)stream;
|
||||
} else {
|
||||
dataStream = new DataInputStream(stream);
|
||||
}
|
||||
|
||||
return MAGIC == dataStream.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
private static final Debug debug = Debug.getInstance("keystore");
|
||||
|
@ -828,20 +844,4 @@ public abstract class JavaKeyStore extends KeyStoreSpi {
|
|||
}
|
||||
return passwdBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Probe the first few bytes of the keystore data stream for a valid
|
||||
* JKS keystore encoding.
|
||||
*/
|
||||
@Override
|
||||
public boolean engineProbe(InputStream stream) throws IOException {
|
||||
DataInputStream dataStream;
|
||||
if (stream instanceof DataInputStream) {
|
||||
dataStream = (DataInputStream)stream;
|
||||
} else {
|
||||
dataStream = new DataInputStream(stream);
|
||||
}
|
||||
|
||||
return MAGIC == dataStream.readInt();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue