package play.api.libs.ws.ssl
import play.api.libs.ws.WSClientConfig
import java.security.Security
class SystemConfiguration {
val logger = org.slf4j.LoggerFactory.getLogger(getClass)
def configure(config: WSClientConfig) {
config.ssl.loose.allowUnsafeRenegotiation.map(configureUnsafeRenegotiation)
config.ssl.loose.allowLegacyHelloMessages.map(configureAllowLegacyHelloMessages)
config.ssl.checkRevocation.map(configureCheckRevocation)
}
def configureUnsafeRenegotiation(allowUnsafeRenegotiation: Boolean) {
System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", allowUnsafeRenegotiation.toString)
logger.debug("configureUnsafeRenegotiation: sun.security.ssl.allowUnsafeRenegotiation = {}", allowUnsafeRenegotiation.toString)
}
def configureAllowLegacyHelloMessages(allowLegacyHelloMessages: Boolean) {
System.setProperty("sun.security.ssl.allowLegacyHelloMessages", allowLegacyHelloMessages.toString)
logger.debug("configureAllowLegacyHelloMessages: sun.security.ssl.allowLegacyHelloMessages = {}", allowLegacyHelloMessages.toString)
}
def configureCheckRevocation(checkRevocation: Boolean) {
Security.setProperty("ocsp.enable", checkRevocation.toString)
logger.debug("configureCheckRevocation: ocsp.enable = {}", checkRevocation.toString)
System.setProperty("com.sun.security.enableCRLDP", checkRevocation.toString)
logger.debug("configureCheckRevocation: com.sun.security.enableCRLDP = {}", checkRevocation.toString)
System.setProperty("com.sun.net.ssl.checkRevocation", checkRevocation.toString)
}
def clearProperties() {
Security.setProperty("ocsp.enable", "false")
System.clearProperty("com.sun.security.enableCRLDP")
System.clearProperty("com.sun.net.ssl.checkRevocation")
System.clearProperty("sun.security.ssl.allowLegacyHelloMessages")
System.clearProperty("sun.security.ssl.allowUnsafeRenegotiation")
}
}