Created
February 3, 2015 17:49
-
-
Save polymorphic/5b1a2a5a48208b931141 to your computer and use it in GitHub Desktop.
Disable checks when using SSL w/ spray.io
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
/* | |
spray.io custom SSLContext to bypass security checks (when testing, etc.); see http://spray.io/documentation/1.2.2/spray-can/http-server/#ssl-support | |
Bringing it into scope removes errors | |
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target | |
*/ | |
implicit val trustfulSslContext: SSLContext = { | |
object NoCheckX509TrustManager extends X509TrustManager { | |
override def checkClientTrusted(chain: Array[X509Certificate], authType: String) = () | |
override def checkServerTrusted(chain: Array[X509Certificate], authType: String) = () | |
override def getAcceptedIssuers = Array[X509Certificate]() | |
} | |
val context = SSLContext.getInstance("TLS") | |
context.init(Array[KeyManager](), Array(NoCheckX509TrustManager), null) // Java API | |
context | |
} | |
private def buildControlUri(controlEndpoint: String, controlPort: Int, pool: String): Uri = { | |
val authority = Uri.Authority(Uri.Host(controlEndpoint), controlPort) | |
val path = Uri.Path(s"/api/tm/3.2/config/active/pools/$pool") | |
Uri(scheme = "https", authority = authority, path = path) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment