2016-01-21 134 views
6

我在客戶端使用Akka http配置時遇到了一些問題。我試圖連接到不提供的服務器: - 公共簽名證書 - 與主機名相對應的證書 我沒有這個nginx的手,所以我無法更改服務器端配置。我只能改變客戶端。akka http SSLConfig與主機名驗證和證書驗證問題

經過大量的調查上配置SSL,我發現,我需要在兩個不同級別來配置application.conf SSL選項:

akka.ssl-config.ssl.loose.acceptAnyCertificate=true 
akka.ssl-config.loose.disableHostnameVerification = true 

ssl-config.loose.acceptAnyCertificate=true 
ssl-config.loose.disableHostnameVerification = true 

我有檢查配置是否正常

log-config-on-start = "on" 

的問題是,我仍然在阿卡調試級別(不是很清楚)得到錯誤

[ingestionApiClient-akka.actor.default-dispatcher-13] [akka://ingestionApiClient/user/StreamSupervisor-0/flow-216-1-unknown-operation] closing output 

看着Wireshark的,我發現這是證書驗證的問題

TLSv1 Record Layer: Alert (Level: Fatal, Description: Certificate Unknown) 

我假設JVM配置是overiding所有我已經這樣做了我也試圖按照這種方法來修改JVM SSL配置: Java SSL: how to disable hostname verification

與配置的SSLContext並將它傳遞給阿卡HTTP,因爲我沒問題可以設置默認HttpsContext與

val sc = SSLContext.getInstance("TLS") 
*...configuration...* 
val customContext =HttpsContext(sc, sslParameters = Some(params)) 
Http().setDefaultClientHttpsContext(customHttpsContext) 

但我無法找到配置默認主機名驗證。在HTTP類沒有像Http().setDefaultHostnameVerifier

任何方法這個我如何連接到服務器

val dataIngestFlow = Http().outgoingConnectionTls(config.httpEndpointHost,config.httpEndpointPort) 

我怎樣才能做到這一點?非常感謝您的幫助

回答

0

我不知道是哪的akka版本和akka-http您使用,但你有沒有試過配置字段akka.ssl-config.hostnameVerifierClass設爲您的具體實施HostNameVerifier接口的?

它接受一切的最簡單的驗證是這樣的:

public static class AcceptAllHostNameVerifier implements HostnameVerifier { 
    @Override 
    public boolean verify(String s, SSLSession sslSession) { 
    return true; 
    } 
} 
0

我也陷入了類似的issue並得到類似errors。用以下代碼我能夠通過:

val trustStoreConfig = TrustStoreConfig(None, Some("/etc/Project/keystore/my.cer")).withStoreType("PEM") 
val trustManagerConfig = TrustManagerConfig().withTrustStoreConfigs(List(trustStoreConfig)) 

val badSslConfig = AkkaSSLConfig().mapSettings(s => s.withLoose(s.loose 
    .withAcceptAnyCertificate(true) 
    .withDisableHostnameVerification(true) 
).withTrustManagerConfig(trustManagerConfig)) 

val badCtx = Http().createClientHttpsContext(badSslConfig) 

Http().superPool[RequestTracker](badCtx)(httpMat)