Merge "Use private key context when necessary" into jb-dev
This commit is contained in:
@@ -56,6 +56,8 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.harmony.security.provider.cert.X509CertImpl;
|
import org.apache.harmony.security.provider.cert.X509CertImpl;
|
||||||
|
import org.apache.harmony.xnet.provider.jsse.OpenSSLDSAPrivateKey;
|
||||||
|
import org.apache.harmony.xnet.provider.jsse.OpenSSLRSAPrivateKey;
|
||||||
|
|
||||||
class BrowserFrame extends Handler {
|
class BrowserFrame extends Handler {
|
||||||
|
|
||||||
@@ -1104,12 +1106,23 @@ class BrowserFrame extends Handler {
|
|||||||
SslClientCertLookupTable table = SslClientCertLookupTable.getInstance();
|
SslClientCertLookupTable table = SslClientCertLookupTable.getInstance();
|
||||||
if (table.IsAllowed(hostAndPort)) {
|
if (table.IsAllowed(hostAndPort)) {
|
||||||
// previously allowed
|
// previously allowed
|
||||||
|
PrivateKey pkey = table.PrivateKey(hostAndPort);
|
||||||
|
if (pkey instanceof OpenSSLRSAPrivateKey) {
|
||||||
nativeSslClientCert(handle,
|
nativeSslClientCert(handle,
|
||||||
table.PrivateKey(hostAndPort),
|
((OpenSSLRSAPrivateKey)pkey).getPkeyContext(),
|
||||||
table.CertificateChain(hostAndPort));
|
table.CertificateChain(hostAndPort));
|
||||||
|
} else if (pkey instanceof OpenSSLDSAPrivateKey) {
|
||||||
|
nativeSslClientCert(handle,
|
||||||
|
((OpenSSLDSAPrivateKey)pkey).getPkeyContext(),
|
||||||
|
table.CertificateChain(hostAndPort));
|
||||||
|
} else {
|
||||||
|
nativeSslClientCert(handle,
|
||||||
|
pkey.getEncoded(),
|
||||||
|
table.CertificateChain(hostAndPort));
|
||||||
|
}
|
||||||
} else if (table.IsDenied(hostAndPort)) {
|
} else if (table.IsDenied(hostAndPort)) {
|
||||||
// previously denied
|
// previously denied
|
||||||
nativeSslClientCert(handle, null, null);
|
nativeSslClientCert(handle, 0, null);
|
||||||
} else {
|
} else {
|
||||||
// previously ignored or new
|
// previously ignored or new
|
||||||
mCallbackProxy.onReceivedClientCertRequest(
|
mCallbackProxy.onReceivedClientCertRequest(
|
||||||
@@ -1296,7 +1309,11 @@ class BrowserFrame extends Handler {
|
|||||||
private native void nativeSslCertErrorCancel(int handle, int certError);
|
private native void nativeSslCertErrorCancel(int handle, int certError);
|
||||||
|
|
||||||
native void nativeSslClientCert(int handle,
|
native void nativeSslClientCert(int handle,
|
||||||
byte[] pkcs8EncodedPrivateKey,
|
int ctx,
|
||||||
|
byte[][] asn1DerEncodedCertificateChain);
|
||||||
|
|
||||||
|
native void nativeSslClientCert(int handle,
|
||||||
|
byte[] pkey,
|
||||||
byte[][] asn1DerEncodedCertificateChain);
|
byte[][] asn1DerEncodedCertificateChain);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import java.security.PrivateKey;
|
|||||||
import java.security.cert.CertificateEncodingException;
|
import java.security.cert.CertificateEncodingException;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import org.apache.harmony.xnet.provider.jsse.NativeCrypto;
|
import org.apache.harmony.xnet.provider.jsse.NativeCrypto;
|
||||||
|
import org.apache.harmony.xnet.provider.jsse.OpenSSLDSAPrivateKey;
|
||||||
|
import org.apache.harmony.xnet.provider.jsse.OpenSSLRSAPrivateKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClientCertRequestHandler: class responsible for handling client
|
* ClientCertRequestHandler: class responsible for handling client
|
||||||
@@ -50,33 +52,58 @@ public final class ClientCertRequestHandler extends Handler {
|
|||||||
* Proceed with the specified private key and client certificate chain.
|
* Proceed with the specified private key and client certificate chain.
|
||||||
*/
|
*/
|
||||||
public void proceed(PrivateKey privateKey, X509Certificate[] chain) {
|
public void proceed(PrivateKey privateKey, X509Certificate[] chain) {
|
||||||
final byte[] privateKeyBytes = privateKey.getEncoded();
|
|
||||||
final byte[][] chainBytes;
|
|
||||||
try {
|
try {
|
||||||
chainBytes = NativeCrypto.encodeCertificates(chain);
|
byte[][] chainBytes = NativeCrypto.encodeCertificates(chain);
|
||||||
mTable.Allow(mHostAndPort, privateKeyBytes, chainBytes);
|
mTable.Allow(mHostAndPort, privateKey, chainBytes);
|
||||||
post(new Runnable() {
|
|
||||||
public void run() {
|
if (privateKey instanceof OpenSSLRSAPrivateKey) {
|
||||||
mBrowserFrame.nativeSslClientCert(mHandle, privateKeyBytes, chainBytes);
|
setSslClientCertFromCtx(((OpenSSLRSAPrivateKey)privateKey).getPkeyContext(),
|
||||||
|
chainBytes);
|
||||||
|
} else if (privateKey instanceof OpenSSLDSAPrivateKey) {
|
||||||
|
setSslClientCertFromCtx(((OpenSSLDSAPrivateKey)privateKey).getPkeyContext(),
|
||||||
|
chainBytes);
|
||||||
|
} else {
|
||||||
|
setSslClientCertFromPKCS8(privateKey.getEncoded(),chainBytes);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} catch (CertificateEncodingException e) {
|
} catch (CertificateEncodingException e) {
|
||||||
post(new Runnable() {
|
post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
mBrowserFrame.nativeSslClientCert(mHandle, null, null);
|
mBrowserFrame.nativeSslClientCert(mHandle, 0, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proceed with the specified private key bytes and client certificate chain.
|
||||||
|
*/
|
||||||
|
private void setSslClientCertFromCtx(final int ctx, final byte[][] chainBytes) {
|
||||||
|
post(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
mBrowserFrame.nativeSslClientCert(mHandle, ctx, chainBytes);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proceed with the specified private key context and client certificate chain.
|
||||||
|
*/
|
||||||
|
private void setSslClientCertFromPKCS8(final byte[] key, final byte[][] chainBytes) {
|
||||||
|
post(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
mBrowserFrame.nativeSslClientCert(mHandle, key, chainBytes);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Igore the request for now, the user may be prompted again.
|
* Igore the request for now, the user may be prompted again.
|
||||||
*/
|
*/
|
||||||
public void ignore() {
|
public void ignore() {
|
||||||
post(new Runnable() {
|
post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
mBrowserFrame.nativeSslClientCert(mHandle, null, null);
|
mBrowserFrame.nativeSslClientCert(mHandle, 0, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -88,7 +115,7 @@ public final class ClientCertRequestHandler extends Handler {
|
|||||||
mTable.Deny(mHostAndPort);
|
mTable.Deny(mHostAndPort);
|
||||||
post(new Runnable() {
|
post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
mBrowserFrame.nativeSslClientCert(mHandle, null, null);
|
mBrowserFrame.nativeSslClientCert(mHandle, 0, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package android.webkit;
|
package android.webkit;
|
||||||
|
|
||||||
|
import java.security.PrivateKey;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -26,7 +27,7 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
final class SslClientCertLookupTable {
|
final class SslClientCertLookupTable {
|
||||||
private static SslClientCertLookupTable sTable;
|
private static SslClientCertLookupTable sTable;
|
||||||
private final Map<String, byte[]> privateKeys;
|
private final Map<String, PrivateKey> privateKeys;
|
||||||
private final Map<String, byte[][]> certificateChains;
|
private final Map<String, byte[][]> certificateChains;
|
||||||
private final Set<String> denied;
|
private final Set<String> denied;
|
||||||
|
|
||||||
@@ -38,12 +39,12 @@ final class SslClientCertLookupTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private SslClientCertLookupTable() {
|
private SslClientCertLookupTable() {
|
||||||
privateKeys = new HashMap<String, byte[]>();
|
privateKeys = new HashMap<String, PrivateKey>();
|
||||||
certificateChains = new HashMap<String, byte[][]>();
|
certificateChains = new HashMap<String, byte[][]>();
|
||||||
denied = new HashSet<String>();
|
denied = new HashSet<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Allow(String host_and_port, byte[] privateKey, byte[][] chain) {
|
public void Allow(String host_and_port, PrivateKey privateKey, byte[][] chain) {
|
||||||
privateKeys.put(host_and_port, privateKey);
|
privateKeys.put(host_and_port, privateKey);
|
||||||
certificateChains.put(host_and_port, chain);
|
certificateChains.put(host_and_port, chain);
|
||||||
denied.remove(host_and_port);
|
denied.remove(host_and_port);
|
||||||
@@ -63,7 +64,7 @@ final class SslClientCertLookupTable {
|
|||||||
return denied.contains(host_and_port);
|
return denied.contains(host_and_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] PrivateKey(String host_and_port) {
|
public PrivateKey PrivateKey(String host_and_port) {
|
||||||
return privateKeys.get(host_and_port);
|
return privateKeys.get(host_and_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user