Skip to content

Instantly share code, notes, and snippets.

@eed3si9n
Created March 13, 2011 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eed3si9n/867849 to your computer and use it in GitHub Desktop.
Save eed3si9n/867849 to your computer and use it in GitHub Desktop.
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