Created
March 13, 2011 03:56
-
-
Save eed3si9n/867849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dispatch | |
class HttpInsecure extends Http { | |
override def make_client = { | |
import java.net.{Socket} | |
import javax.net.ssl.{X509TrustManager, SSLContext} | |
import java.security.{KeyStore} | |
import java.security.cert.{X509Certificate} | |
import org.apache.http.conn.scheme.{Scheme} | |
import org.apache.http.conn.ssl.{SSLSocketFactory} | |
val client = new ConfiguredHttpClient() | |
val truststore = KeyStore.getInstance(KeyStore.getDefaultType()) | |
truststore.load(null, null) | |
val socket_factory = new SSLSocketFactory(truststore) { | |
val context = SSLContext.getInstance("TLS") | |
val manager = new X509TrustManager() { | |
def checkClientTrusted(xcs: Array[X509Certificate], string: String) {} | |
def checkServerTrusted(xcs: Array[X509Certificate], string: String) {} | |
def getAcceptedIssuers() = { null } | |
} | |
context.init(null, Array(manager), null) | |
override def createSocket(socket: Socket, host: String, port: Int, autoClose: Boolean) = | |
context.getSocketFactory.createSocket(socket, host, port, autoClose) | |
override def createSocket() = | |
context.getSocketFactory.createSocket | |
} | |
socket_factory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) | |
val manager = client.getConnectionManager | |
manager.getSchemeRegistry.register(new Scheme("https", socket_factory, 443)) | |
client | |
} | |
} | |
object HttpInsecure { | |
def apply[T](hand: Handler[T]) = new HttpInsecure().apply(hand) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment