2
votes

Although my site's certificate is fine, ("openssl verify mysite.com.cer" resulted in OK), and my site is ssl-certified including green lock in the url-bar, my site is generating a fatal alert: bad_certificate whenever a subscriber in my WSO2 app executes an api.

[2018-06-08 10:54:47,167] ERROR - SourceHandler I/O error: Received fatal alert: bad_certificate
javax.net.ssl.SSLException: Received fatal alert: bad_certificate
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
    at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1666)
    at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1634)
    at sun.security.ssl.SSLEngineImpl.recvAlert(SSLEngineImpl.java:1800)
    at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:1083)
    at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:907)
    at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:781)
    at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
    at org.apache.http.nio.reactor.ssl.SSLIOSession.doUnwrap(SSLIOSession.java:245)
    at org.apache.http.nio.reactor.ssl.SSLIOSession.decryptData(SSLIOSession.java:378)
    at org.apache.http.nio.reactor.ssl.SSLIOSession.isAppInputReady(SSLIOSession.java:413)
    at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:119)
    at org.apache.http.impl.nio.reactor.BaseIOReactor.validate(BaseIOReactor.java:218)
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:281)
    at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:105)
    at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:586)
    at java.lang.Thread.run(Thread.java:748)

I browsed through several stackoverflow-questions about 'bad_certificate' but found no solution.

To import my certificate I followed WSO2's docs:

 openssl pkcs12 -export -in SSL_certificate_www_mysite_com.crt -inkey www.mysite.com.key -name "mykeys" -certfile mysite.com.cer -out mykeys.pfx
 keytool -importkeystore -srckeystore mykeys.pfx -srcstoretype pkcs12 -destkeystore mykeys.jks -deststoretype JKS
 keytool -export -alias "mykeys" -keystore mykeys.jks -file mykeys.pem
 copied mykeys.pem and mykeys.jks to /usr/local/opt/wso2am-2.2.0/repository/resources/security/
 keytool -import -alias "mykeys" -file mykeys.pem -keystore client-truststore.jks -storepass wso2carbon and answered yes to include the certificate

Then I had to change several configuration files to use mykeys instead of wso2carbon. So I did.

Then I restarted wso2-carbon, logged in and checked that mykeys.JKS showed up in the list of keystores, it does.

My site is correctly ssl-certified, green lock showing in the url-bar. All works fine, upto the point that logged in as Subscriber I try to Execute an API, which results in the response "ERROR - SourceHandler I/O error: Received fatal alert: bad_certificate" and the above-mentioned log coming from sourcehandler

This error is logged in repository/logs/wso2-apigw-errors.log and wso2carbon.log, but only this message, nothing else.

Where to look next to find why my certificate is not getting validated correctly?

2
Could you please enable SSL debug logs and see what is happening? burnthecode.wordpress.com/2016/07/07/…Pubci
Nice one, For ssl only: wso2server.sh -Djavax.net.debug=ssl. Thanks. Got some logbrowsing to do now.Tim van Steenbergen
Interesting. I tried the above command too and it spits out a lot of info about the certs but it doesn't specify which the bad cert is. Is there a way to identify which the cert is as far as WSO2 APIM goes?perennial_noob

2 Answers

3
votes

the problem is in the self-signed certificate

assume your service published at this endpoint:

https://192.168.99.3:8243/first/1.0.0 

then you have to go into a new browser window

https://192.168.99.3:8243/

set browser to always accept the https certificate

after this the call in api console should work

0
votes

If you have separate Store and gateway instances, open the gateway:9443/carbon in browser and accept the self signed certificate. That should work.