Improved client certificate and certificate chain support

Summary:
- openssl: add openssl support for specifying per key certificate chains
- libcore: properly implement client certificate request call back
- libcore: properly implement sending certificate chain
- libcore: properly implement retreiving local certificate chain
- libcore: added an SSLContext for non-OpenSSL SSLSocket creation

Details:

external/openssl

    Improve patch generate support by applying all other patches to
    baseline to remove cross polluting other patch changes into target
    patch. Move cleanup of ./Configure output to import script from
    openssl.config.

 	import_openssl.sh
	openssl.config

   Adding SSL_use_certificate_chain and SSL_get_certificate_chain to
   continue to finish most of remaining JSSE issues.

	include/openssl/ssl.h
	ssl/s3_both.c
	ssl/ssl.h
	ssl/ssl_locl.h
	ssl/ssl_rsa.c

   Updated patch (and list of input files to patch)

	patches/jsse.patch
	openssl.config

libcore

    Restoring SSLContextImpl as provider of non-OpenSSL SSLSocketImpl
    instances for interoperability testing. OpenSSLContextImpl is the
    new subclass that provides OpenSSLSocketImpl. JSSEProvider
    provides the old style SSLContexts, OpenSSLProvider provides the
    OpenSSL SSLContext, which includes the "default" context. Changed
    to register SSLContexts without aliases to match the RI.

	luni/src/main/java/org/apache/harmony/xnet/provider/jsse/JSSEProvider.java
	luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLProvider.java

	luni/src/main/java/org/apache/harmony/xnet/provider/jsse/DefaultSSLContextImpl.java
	luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLContextImpl.java
	luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLContextImpl.java

    Native interface updates to support OpenSSLSocketImpl improvements
    - KEY_TYPES now expanded based on what we are being provided by OpenSSL.
      keyType function now maps key type values received from
      clientCertificateRequested callback.
    - Removed remaining uses of string PEM encoding, now using ASN1 DER consistently
      Includes SSL_SESSION_get_peer_cert_chain, verifyCertificateChain
    - Fixed clientCertificateRequested to properly include all key
      types supported by server, not just the one from the cipher
      suite. We also now properly include the list of supported CAs to
      help the client select a certificate to use.
    - Fixed NativeCrypto.SSL_use_certificate implementation to use new
      SSL_use_certificate_chain function from openssl to pass chain to
      OpenSSL.
    - Added error handling of all uses of sk_*_push which can fail due to out of memory
    - Fixed compile warning due to missing JNI_TRACE argument
	luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java
	luni/src/main/native/NativeCrypto.cpp
	luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java

    Pass this into chooseServerAlias call as well in significantly revamped choseClientAlias

	luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java

    Minor code cleanup while reviewing diff between checkClientTrusted and checkServerTrusted

	luni/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerImpl.java

   Improvements to SSL test support to go along with client
   certificate and certificate chain changes. TestSSLContext now has
   separate contexts for the client and server (as well as seperate
   key stores information). TestKeyStore now is more realistic by
   default, creating a CA, intermediate CA, and separate client and
   server certificates, as well as a client keystore that simply
   contains the CA and no certificates.

	support/src/test/java/javax/net/ssl/TestKeyStore.java
	support/src/test/java/javax/net/ssl/TestSSLContext.java

     Tests tracking API changes. Tests involving cert chains now now
     updated to use TestKeyStore.assertChainLength to avoid hardwiring
     expected chain length in tests. These tests also now use
     TestSSLContext.assertClientCertificateChain to validate that the
     chain is properly constructed and trusted by a trust manager.

	luni/src/test/java/java/net/URLConnectionTest.java
	luni/src/test/java/javax/net/ssl/SSLContextTest.java
	luni/src/test/java/javax/net/ssl/SSLEngineTest.java
	luni/src/test/java/javax/net/ssl/SSLSessionContextTest.java
	luni/src/test/java/javax/net/ssl/SSLSessionTest.java
	luni/src/test/java/javax/net/ssl/SSLSocketTest.java
	support/src/test/java/java/security/StandardNames.java
	support/src/test/java/javax/net/ssl/TestSSLEnginePair.java
	support/src/test/java/javax/net/ssl/TestSSLSocketPair.java

frameworks/base

    Tracking change of SSLContextImpl to OpenSSLContextImpl

	core/java/android/net/SSLCertificateSocketFactory.java
	core/java/android/net/http/HttpsConnection.java
	tests/CoreTests/android/core/SSLPerformanceTest.java
	tests/CoreTests/android/core/SSLSocketTest.java

    Tracking changes to TestSSLContext

	core/tests/coretests/src/android/net/http/HttpsThroughHttpProxyTest.java

Change-Id: Ie35ebce89966dfce62c316f7fe7252bf06935680
20 files changed