2121import java .security .cert .CertificateEncodingException ;
2222import java .security .cert .X509Certificate ;
2323import org .apache .harmony .xnet .provider .jsse .NativeCrypto ;
24+ import org .apache .harmony .xnet .provider .jsse .OpenSSLDSAPrivateKey ;
25+ import org .apache .harmony .xnet .provider .jsse .OpenSSLRSAPrivateKey ;
2426
2527/**
2628 * ClientCertRequestHandler: class responsible for handling client
@@ -50,33 +52,58 @@ public final class ClientCertRequestHandler extends Handler {
5052 * Proceed with the specified private key and client certificate chain.
5153 */
5254 public void proceed (PrivateKey privateKey , X509Certificate [] chain ) {
53- final byte [] privateKeyBytes = privateKey .getEncoded ();
54- final byte [][] chainBytes ;
5555 try {
56- chainBytes = NativeCrypto .encodeCertificates (chain );
57- mTable .Allow (mHostAndPort , privateKeyBytes , chainBytes );
58- post (new Runnable () {
59- public void run () {
60- mBrowserFrame .nativeSslClientCert (mHandle , privateKeyBytes , chainBytes );
61- }
62- });
56+ byte [][] chainBytes = NativeCrypto .encodeCertificates (chain );
57+ mTable .Allow (mHostAndPort , privateKey , chainBytes );
58+
59+ if (privateKey instanceof OpenSSLRSAPrivateKey ) {
60+ setSslClientCertFromCtx (((OpenSSLRSAPrivateKey )privateKey ).getPkeyContext (),
61+ chainBytes );
62+ } else if (privateKey instanceof OpenSSLDSAPrivateKey ) {
63+ setSslClientCertFromCtx (((OpenSSLDSAPrivateKey )privateKey ).getPkeyContext (),
64+ chainBytes );
65+ } else {
66+ setSslClientCertFromPKCS8 (privateKey .getEncoded (),chainBytes );
67+ }
6368 } catch (CertificateEncodingException e ) {
6469 post (new Runnable () {
6570 public void run () {
66- mBrowserFrame .nativeSslClientCert (mHandle , null , null );
71+ mBrowserFrame .nativeSslClientCert (mHandle , 0 , null );
6772 return ;
6873 }
6974 });
7075 }
7176 }
7277
78+ /**
79+ * Proceed with the specified private key bytes and client certificate chain.
80+ */
81+ private void setSslClientCertFromCtx (final int ctx , final byte [][] chainBytes ) {
82+ post (new Runnable () {
83+ public void run () {
84+ mBrowserFrame .nativeSslClientCert (mHandle , ctx , chainBytes );
85+ }
86+ });
87+ }
88+
89+ /**
90+ * Proceed with the specified private key context and client certificate chain.
91+ */
92+ private void setSslClientCertFromPKCS8 (final byte [] key , final byte [][] chainBytes ) {
93+ post (new Runnable () {
94+ public void run () {
95+ mBrowserFrame .nativeSslClientCert (mHandle , key , chainBytes );
96+ }
97+ });
98+ }
99+
73100 /**
74101 * Igore the request for now, the user may be prompted again.
75102 */
76103 public void ignore () {
77104 post (new Runnable () {
78105 public void run () {
79- mBrowserFrame .nativeSslClientCert (mHandle , null , null );
106+ mBrowserFrame .nativeSslClientCert (mHandle , 0 , null );
80107 }
81108 });
82109 }
@@ -88,7 +115,7 @@ public void cancel() {
88115 mTable .Deny (mHostAndPort );
89116 post (new Runnable () {
90117 public void run () {
91- mBrowserFrame .nativeSslClientCert (mHandle , null , null );
118+ mBrowserFrame .nativeSslClientCert (mHandle , 0 , null );
92119 }
93120 });
94121 }
0 commit comments