CertificateException: No name matching ssl.someUrl.de found

后端 未结 7 1822
生来不讨喜
生来不讨喜 2020-11-29 21:22

I\'m trying to connect to one of my servers through ssl, with Java. I tried a lot of options here is my best try:

I generate a jssecacerts with the recommendet scrip

7条回答
  •  臣服心动
    2020-11-29 21:58

    In case, it helps someone:

    Use case: i am using a self-signed certificate for my development on localhost.

    Error: Caused by: java.security.cert.CertificateException: No name matching localhost found

    Solution: When you generate your self-signed certicate, make sure you answer this question like that(See Bruno's answer for the why):

    What is your first and last name?
      [Unknown]:  localhost
    



    As a bonus, here are my steps:
    1. Generate self-signed certificate:

    keytool -genkeypair -alias netty -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 4000
    Enter keystore password: ***
    Re-enter new password: ***
    What is your first and last name?
      [Unknown]:  localhost
    ...
    

    2. Copy the certificate in src/main/resources(if necessary)

    3. Update the cacerts
    keytool -v -importkeystore -srckeystore keystore.p12 -srcstoretype pkcs12 -destkeystore "%JAVA_HOME%\jre\lib\security\cacerts" -deststoretype jks

    4. Update your config(in my case application.properties):

    server.port=8443
    server.ssl.key-store=classpath:keystore.p12
    server.ssl.key-store-password=jumping_monkey
    server.ssl.key-store-type=pkcs12
    server.ssl.key-alias=netty
    



    Cheers

提交回复
热议问题