Android SSL - No Peer Certificate

前端 未结 10 700
鱼传尺愫
鱼传尺愫 2020-12-05 03:30

Whenever this code runs, I get a \'No Peer Certificate\' error.

SSL certificate is valid, bought from Namecheap (PositiveSSL). It has the CA crt before it, and opens

相关标签:
10条回答
  • 2020-12-05 03:56

    Even though this question has an accepted answer I thought it worthwhile to answer since I got the same error on an older Android device running 2.3.3:

    javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
    

    After reading several different related questions on SO I came to the conclusion that this can happen for two (maybe more?) reasons:

    • Improper installation of an intermediate certificate
    • Incorrect ordering of the certificate chain

    In my case it was an incorrect ordering of certificates. As an example I'm posting the cert order from this question with the insightful answer from user bdc. You can get the certificate ordering by doing the following from a terminal:

    openssl s_client -connect eu.battle.net:443
    

    (obviously replacing eu.battle.net with your own server). In the case of eu.battle.net at that time the order was:

    Certificate chain
     0 s:/C=US/ST=California/L=Irvine/O=Blizzard Entertainment, Inc./CN=*.battle.net
       i:/C=US/O=Thawte, Inc./CN=Thawte SSL CA
     1 s:/C=US/O=thawte, Inc./OU=Certification Services Division/OU=(c) 2006 thawte, Inc. - For authorized use only/CN=thawte Primary Root CA
       i:/C=ZA/ST=Western Cape/L=Cape Town/O=Thawte Consulting cc/OU=Certification Services Division/CN=Thawte Premium Server CA/emailAddress=premium-server@thawte.com
     2 s:/C=US/O=Thawte, Inc./CN=Thawte SSL CA
       i:/C=US/O=thawte, Inc./OU=Certification Services Division/OU=(c) 2006 thawte, Inc. - For authorized use only/CN=thawte Primary Root CA
    

    While it should have been:

    Certificate chain
     0 s:/C=US/ST=California/L=Irvine/O=Blizzard Entertainment, Inc./CN=*.battle.net
       i:/C=US/O=Thawte, Inc./CN=Thawte SSL CA
     1 s:/C=US/O=Thawte, Inc./CN=Thawte SSL CA
       i:/C=US/O=thawte, Inc./OU=Certification Services Division/OU=(c) 2006 thawte, Inc. - For authorized use only/CN=thawte Primary Root CA
     2 s:/C=US/O=thawte, Inc./OU=Certification Services Division/OU=(c) 2006 thawte, Inc. - For authorized use only/CN=thawte Primary Root CA
       i:/C=ZA/ST=Western Cape/L=Cape Town/O=Thawte Consulting cc/OU=Certification Services Division/CN=Thawte Premium Server CA/emailAddress=premium-server@thawte.com
    

    The rule is that the issuer of cert "n" in the chain should match the subject of cert "n+1".

    Once I found the problem it was trivial to change the cert order on the server and things immediately started working on the Android 2.3.3 device. I guess it's good that older Android versions are a bit pesky about cert order, but it was also a nightmare since newer Android versions reorder the certs automatically. Hell, even an old iPhone 3GS worked with certs out of order.

    0 讨论(0)
  • 2020-12-05 03:58

    Because certificate is valid you should not use custom SchemeRegistry, you should just rely on default android certificate validation mechanism.

    0 讨论(0)
  • 2020-12-05 03:59

    This white paper may summarize everything you need to know to get your SSL working on Android. Based on my recent experience, the best approach is to get a SSL certificate that Android likes.

    0 讨论(0)
  • 2020-12-05 04:02

    I tried to fix this from android code by adding an "accept all certificate" rule. But all the effort from android side was worthless. Finally making a CNAME in registrar entry that ensured that all requests go to the same IP address fixed the problem

    0 讨论(0)
提交回复
热议问题