Ошибка ssl peer certificate or ssh remote key was not ok

I’m testing an API that uses curl_exec php function and a CA certificate but something is going wrong and I’m a little lost.

I have configured SSL on my apache VirtualHost and looks ok ( opening https:://[myVHost]… works ).

However the API curl call give me back this message:

  • SSL peer certificate or SSH remote key was not OK

I’m not very experienced with SSL so I have few ideas about the cause of that.

UPDATE:

This is the code I’m using in my cURL request, I have commented 2 lines and changes their value (look at ‘TODO’ line ) and in this way it is working, however this is just a work arround …

$opts[CURLOPT_URL] = $url;
    $opts[CURLOPT_RETURNTRANSFER] = true;
    $opts[CURLOPT_CONNECTTIMEOUT] = 50;
    $opts[CURLOPT_TIMEOUT] = 100;
    $headers = array(
        'Accept: application/json',
        "User-Agent: APIXXX-PHP-Client");
    $opts[CURLOPT_HTTPHEADER] = $headers;
    $opts[CURLOPT_USERPWD] = $env->getApiKey() . ':';
    if (certificatePresent()) {

        //  $opts[CURLOPT_SSL_VERIFYPEER] = true;
        //  $opts[CURLOPT_SSL_VERIFYHOST] = 2;

        // TODO: SET IT BACK
        $opts[CURLOPT_SSL_VERIFYPEER] = 0;
        $opts[CURLOPT_SSL_VERIFYHOST] = 0;

        $opts[CURLOPT_CAINFO] = $path

      }

    curl_setopt_array($curl, $opts);

    $response = curl_exec($curl);

Caerulius's user avatar

asked Jan 7, 2013 at 9:11

WonderLand's user avatar

4

You are probably using self-signed SSL certifiacate, which will not pass when the CURLOPT_SSL_VERIFYPEER options is set.

There are two solutions:

  1. Set up valid SSL certificate.
  2. Disable SSL verification in Curl. (add —insecure option)

If you disable verification, you can’t be sure if you are really communicating with your host.
So it depends on level of security you need.

Ben Butterworth's user avatar

answered Dec 29, 2013 at 13:18

Daniel Milde's user avatar

Daniel MildeDaniel Milde

1,0661 gold badge12 silver badges15 bronze badges

0

Beside CURLOPT_SSL_VERIFYPEER there are two other settings which might be changed to false/0:

CURLOPT_SSL_VERIFYHOST
CURLOPT_SSL_VERIFYSTATUS

Beware that you should fix your SSL certificates & settings instead of disable security!

answered Sep 21, 2017 at 9:50

waibelp's user avatar

waibelpwaibelp

611 silver badge3 bronze badges

Although I am answering an old post, I think it will help the new viewers-

You can check the problem by adding

$opts[CURLOPT_VERBOSE] = 1

For self signed certificate your client may connect with the server using IP address, because the host name is not available in DNS cache. In that case the COMMON NAME(CN) of your server certificate needs to match with the Server IP (put IP address as common name when generating the server certificate). When you do it correctly, you can see this message:

common name: 192.168.0.1 (matched)

Here 192.168.0.1 is an example.

answered Mar 8, 2017 at 13:45

rrsuj's user avatar

rrsujrrsuj

4096 silver badges10 bronze badges

You’re right to want to enable SSL_VERIFYPEER if you are worried about man-in-the-middle attacks.

Is your $path set to point to the certificate (or certificate bundle) provided by the API owner? Is that certificate readable by the web server user? If so, have you verified that the certificate(s) is the same as when you visit the https address manually in a browser and inspect the certificate?

If you can’t get it to work, and the API you are connecting to has a SSL certificate that works in your normal browser without warnings, you should be able to set $path to your CA root bundle on your server.

answered May 19, 2014 at 4:10

Jhong's user avatar

JhongJhong

2,69421 silver badges19 bronze badges

You can build a valid SSL certificate and ensure that it is stored in the trusted folder.

Valid SSL certificate can be created by including the following command in the developer command prompt of VS2012. (This can be obtained by typing developer in the start)

The following command creates a self-signed certificate that can be used to test a web application that uses Secure Sockets Layer (SSL) on a web server whose URL is www.example.com. The OID defined by the -eku option identifies that certificate as an SSL server certificate. The certificate is stored in the my store and is available at the machine (rather than user) level. The certificate’s private key is exportable, and the certificate is valid from May 10, 2010 through December 22, 2011.

Makecert -r -pe -n CN=»www.example.com» -b 05/10/2010 -e 12/22/2011 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localmachine -sky exchange -sp «Microsoft RSA SChannel Cryptographic Provider» -sy 12

For more on how to create the SSL certificate

Now make sure that this certificate is trusted, this can be done by typing CERTMGR in the cmd..

now the cert created is in the PERSONAL folder.. copy it and paste it to the TRUSTED PEOPLE FOLDER.

This should do the trick. Let me know if that doesn’t work.

chriz's user avatar

chriz

1,3392 gold badges16 silver badges32 bronze badges

answered May 19, 2014 at 13:04

Abhishek's user avatar

AbhishekAbhishek

211 silver badge7 bronze badges

This error can also occur if you update packages on a linux server that has a self-signed certificate.

Solution:
Stop your existing Apache/nginx server.
Run certbot (if you are using lets encrypt)

Restart your Apache/nginx server.

Note: If you’re using Springboot, add System.setProperty(«https.protocols», «TLSv1,TLSv1.1,TLSv1.2,TLSv1.3»); to your application.properties file

Voila!

answered Jun 22, 2021 at 13:26

inspiredMichael's user avatar

I spent almost all day for this error, and problem was in using ipv6, and called api server does not support ipv6.
Solution:
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_VERSION_IPV4);

answered Nov 18, 2021 at 11:19

Oleh Diachenko's user avatar

Oleh DiachenkoOleh Diachenko

6021 gold badge7 silver badges9 bronze badges

I’m testing an API that uses curl_exec php function and a CA certificate but something is going wrong and I’m a little lost.

I have configured SSL on my apache VirtualHost and looks ok ( opening https:://[myVHost]… works ).

However the API curl call give me back this message:

  • SSL peer certificate or SSH remote key was not OK

I’m not very experienced with SSL so I have few ideas about the cause of that.

UPDATE:

This is the code I’m using in my cURL request, I have commented 2 lines and changes their value (look at ‘TODO’ line ) and in this way it is working, however this is just a work arround …

$opts[CURLOPT_URL] = $url;
    $opts[CURLOPT_RETURNTRANSFER] = true;
    $opts[CURLOPT_CONNECTTIMEOUT] = 50;
    $opts[CURLOPT_TIMEOUT] = 100;
    $headers = array(
        'Accept: application/json',
        "User-Agent: APIXXX-PHP-Client");
    $opts[CURLOPT_HTTPHEADER] = $headers;
    $opts[CURLOPT_USERPWD] = $env->getApiKey() . ':';
    if (certificatePresent()) {

        //  $opts[CURLOPT_SSL_VERIFYPEER] = true;
        //  $opts[CURLOPT_SSL_VERIFYHOST] = 2;

        // TODO: SET IT BACK
        $opts[CURLOPT_SSL_VERIFYPEER] = 0;
        $opts[CURLOPT_SSL_VERIFYHOST] = 0;

        $opts[CURLOPT_CAINFO] = $path

      }

    curl_setopt_array($curl, $opts);

    $response = curl_exec($curl);

Caerulius's user avatar

asked Jan 7, 2013 at 9:11

WonderLand's user avatar

4

You are probably using self-signed SSL certifiacate, which will not pass when the CURLOPT_SSL_VERIFYPEER options is set.

There are two solutions:

  1. Set up valid SSL certificate.
  2. Disable SSL verification in Curl. (add —insecure option)

If you disable verification, you can’t be sure if you are really communicating with your host.
So it depends on level of security you need.

Ben Butterworth's user avatar

answered Dec 29, 2013 at 13:18

Daniel Milde's user avatar

Daniel MildeDaniel Milde

1,0661 gold badge12 silver badges15 bronze badges

0

Beside CURLOPT_SSL_VERIFYPEER there are two other settings which might be changed to false/0:

CURLOPT_SSL_VERIFYHOST
CURLOPT_SSL_VERIFYSTATUS

Beware that you should fix your SSL certificates & settings instead of disable security!

answered Sep 21, 2017 at 9:50

waibelp's user avatar

waibelpwaibelp

611 silver badge3 bronze badges

Although I am answering an old post, I think it will help the new viewers-

You can check the problem by adding

$opts[CURLOPT_VERBOSE] = 1

For self signed certificate your client may connect with the server using IP address, because the host name is not available in DNS cache. In that case the COMMON NAME(CN) of your server certificate needs to match with the Server IP (put IP address as common name when generating the server certificate). When you do it correctly, you can see this message:

common name: 192.168.0.1 (matched)

Here 192.168.0.1 is an example.

answered Mar 8, 2017 at 13:45

rrsuj's user avatar

rrsujrrsuj

4096 silver badges10 bronze badges

You’re right to want to enable SSL_VERIFYPEER if you are worried about man-in-the-middle attacks.

Is your $path set to point to the certificate (or certificate bundle) provided by the API owner? Is that certificate readable by the web server user? If so, have you verified that the certificate(s) is the same as when you visit the https address manually in a browser and inspect the certificate?

If you can’t get it to work, and the API you are connecting to has a SSL certificate that works in your normal browser without warnings, you should be able to set $path to your CA root bundle on your server.

answered May 19, 2014 at 4:10

Jhong's user avatar

JhongJhong

2,69421 silver badges19 bronze badges

You can build a valid SSL certificate and ensure that it is stored in the trusted folder.

Valid SSL certificate can be created by including the following command in the developer command prompt of VS2012. (This can be obtained by typing developer in the start)

The following command creates a self-signed certificate that can be used to test a web application that uses Secure Sockets Layer (SSL) on a web server whose URL is www.example.com. The OID defined by the -eku option identifies that certificate as an SSL server certificate. The certificate is stored in the my store and is available at the machine (rather than user) level. The certificate’s private key is exportable, and the certificate is valid from May 10, 2010 through December 22, 2011.

Makecert -r -pe -n CN=»www.example.com» -b 05/10/2010 -e 12/22/2011 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localmachine -sky exchange -sp «Microsoft RSA SChannel Cryptographic Provider» -sy 12

For more on how to create the SSL certificate

Now make sure that this certificate is trusted, this can be done by typing CERTMGR in the cmd..

now the cert created is in the PERSONAL folder.. copy it and paste it to the TRUSTED PEOPLE FOLDER.

This should do the trick. Let me know if that doesn’t work.

chriz's user avatar

chriz

1,3392 gold badges16 silver badges32 bronze badges

answered May 19, 2014 at 13:04

Abhishek's user avatar

AbhishekAbhishek

211 silver badge7 bronze badges

This error can also occur if you update packages on a linux server that has a self-signed certificate.

Solution:
Stop your existing Apache/nginx server.
Run certbot (if you are using lets encrypt)

Restart your Apache/nginx server.

Note: If you’re using Springboot, add System.setProperty(«https.protocols», «TLSv1,TLSv1.1,TLSv1.2,TLSv1.3»); to your application.properties file

Voila!

answered Jun 22, 2021 at 13:26

inspiredMichael's user avatar

I spent almost all day for this error, and problem was in using ipv6, and called api server does not support ipv6.
Solution:
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_VERSION_IPV4);

answered Nov 18, 2021 at 11:19

Oleh Diachenko's user avatar

Oleh DiachenkoOleh Diachenko

6021 gold badge7 silver badges9 bronze badges

Published: 29 Apr 2014
Last Modified Date: 28 Sep 2022

Issue

When you try to sign in to Tableau Server from Tableau Desktop, the following error might occur: 

Cannot connect to Tableau Server. Please check the server name and port and try again.

Internet communication error: SSL peer certificate or SSH remote key was not OK <server name or IP>.

Environment

  • Tableau Server 
  • Tableau Desktop 
  • SSL

Resolution

Option 1

Verify that the Common Name defined in the SSL certificate matches the server name in the Tableau Server Sign In dialog box.

Option 2

If Tableau Server is configured for Mutual SSL:

  • Work with your IT Team to configure the proper client certificates on the computer running Tableau Desktop or
  • As a Tableau Server administrator, open the «Configure Tableau Server» menu, and disable the «Mutual SSL» option listed on the SSL tab.

Cause

The server name used in the Server field of the Tableau Desktop connection dialog box does not match the Common Name defined in the SSL certificate.
OR
If your Tableau Server administrator has enabled Mutual SSL, then Tableau Server is looking for a «client certificate» on your Tableau Desktop computer.  If that client certificate is missing or malformed, it will return the same «SSL peer certificate or SSH remote key was not OK» error.

Additional Information

  • Tableau Desktop cannot append domains in the URL when using SSL to connect to Tableau Server.  It will only use the common name as defined in the certificate to connect.
  • SSL Knowledge Base: What is the Common Name?




New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

Closed

CEHitchens opened this issue

Oct 2, 2021

· 16 comments

Comments

@CEHitchens

Description

Receiving STK news on the main menu does not work. Logging in to STK Online ‘service’ is not possible.
Running STK 1.3 on LinuxMint 20.2 using the «http://ppa.launchpad.net/stk/dev/ubuntu focal main» PPA

Steps to reproduce

  • Launch game
  • Notice the «Error downloading news ‘SSL peer certificate or SSH remote key was not OK’ on the main menu
  • Try to log in to the STK service, enter username, see some error message telling you that the connection to the server wasn’t possible or to check the internet connection (which works.)

Configuration

STK 1.3 (updated from 1.3rc1 today; thought it may be linked; rolled back that update; problem persists)
Linux Mint 20.2 Cinnamon

http://ppa.launchpad.net/stk/dev/ubuntu focal main

Additional information

Please provide stdout.log, it is located in:
~/.config/supertuxkart/config-0.10 (Linux and other unix based systems)

stdout.log:
excerpt, related to error:
[info ] HTTPRequest: Sending userid=XXXXXX&token=************************ to https://online.supertuxkart.net/api/v2/user/saved-session/
[info ] HTTPRequest: Downloading https://online.supertuxkart.net/dl/xml/online_news.xml
[error ] XMLRequest::afterOperation: curl_easy_perform() failed: SSL peer certificate or SSH remote key was not OK
[info ] HTTPRequest: Downloading https://online.supertuxkart.net/dl/xml/online_news.xml
[error ] news: Error downloading news: ‘SSL peer certificate or SSH remote key was not OK’.
[info ] addons: Using cached addons.xml.

@Benau

@Benau

or rebuild ppa with latest curl + openssl 3

@CEHitchens

1st things 1st — thanks for your reply.

What I find strange though is that this is only a recent issue; last 1-3 days.
For at least 1 year (likely closer to 2) there had been no issue running it with this setup. Like I said, I just updated from 1.3rc1 to 1.3 today/yesterday which is why I rolled back the system to a state from right before the most recent update where the 1.3rc1 had no connectivity issues. I also looked at the apt installation history to see whether something related to this may have changed, I could not spot anything obvious.

I’ll roll back the system a whole week, which would be a state where I know that STK1.3rc1 worked. And if it won’t work having rolled back that one full week, somehow I would deduce from that, that it isn’t a local problem, unless it were some change in ~/.config/supertuxkart/ (i.e. the latest STK1.3 update broke some configuration). My ~ is exempt from my system rollback. Wouldn’t you agree?

@Benau

no it wont work, just try the tarball i mentioned or switch to a distro which ship openssl 3

@Benau

There is nothing wrong with local problem

@CEHitchens

Benau, thanks for your efforts.
Somehow though you totally skipped over the fact that things on the very same distro worked fine for 1+ to 2 years using the very same PPA until 1 or 2 days ago.

I’ll just wait and see what other suggestions / ideas may be shared here.

@Benau

@Benau

There is no way to fix your issue if you intended to keep existing stk ppa

@Benau

or if you don’t want to try anything just wait until the ppa is rebuilt with latest curl + openssl (don’t use system curl + openssl), @qwertychouskie maintain the ppa

@jhonny-oliveira

Hi!

My case scenario and experiments:
Build in Ubuntu Focal (20.04).
Build in Ubuntu Hirsute (21.04).
Install package built on Focal in Focal: SSL error.
Install package built on Focal in Hirsute: no SSL error.
Install package built on Hirsute in Focal: fails to install — libc version.
Install package built on Hirsute in Hirsute: no SSL error.

At this point, it seems clear that the problem only happens in Ubuntu Focal. Therefore the remaining tests were done in Focal.

I tried downloading the xml with curl and it succeeds. Please, check the attached log: SSL_validation_steps.log.
curl -L -v https://online.supertuxkart.net/dl/xml/online_news.xml

Just to double check, I have also reviewed the system. Both Let’s Encrypt root/intermediate CAs and they are fine:
trust dump —filter «pkcs11:id=%C1%F1%26%BA%A0%2D%AE%85%81%CF%D3%F1%2A%12%BD%B8%0A%67%FD%BC;type=cert» | openssl x509 -text

At of today, the system only has two trusted root CAs expired, but they not related to the certificate used in https://online.supertuxkart.net.

Is it possible that the game is using some dependency library that drags along their own certs and it happens that this dependency has outdated trusted root CAs in LinuxMint 20.2 and Ubuntu Focal?

@Benau , any ideas?

Thank you!
Jhonny

@Benau

you can try copy latest https://github.com/supertuxkart/stk-code/blob/master/data/cacert.pem to installed 1.3 stk location and see if it works

the above method fixed windows stk binary at least

And if curl -L https://online.supertuxkart.net/dl/xml/online_news.xml fails for you, try:

sudo mv /usr/share/ca-certificates/mozilla/DST_Root_CA_X3.crt /root
sudo sed -i 's#mozilla/DST_Root_CA_X3.crt##mozilla/DST_Root_CA_X3.crt#' /etc/ca-certificates.conf
sudo update-ca-certificates

basically try remove the expired certificate from the bundled list

@jhonny-oliveira

@qwertychouskie

@Benau If you push that commit to the 1.3 branch I’ll update the packages in the PPA

@Benau

@qwertychouskie

The PPA is now updated and should connect successfully. If you encounter any more issues, let me know!

@CEHitchens

@CEHitchens
CEHitchens

changed the title
STK 1.3 «SSL peer certificate or SSH remote key was not OK»

[SOLVED] STK 1.3 «SSL peer certificate or SSH remote key was not OK»

Oct 5, 2021

This is an issue I’m having with a specific package but it looks like the software is using a version of CURL for windows or something. I want to understand this specific behavior because it doesnt make sense to me.

Im using this software which is a custom distro of clamav for windows: https://oss.netfarm.it/clamav/

Specifically this version: https://oss.netfarm.it/clamav/files/clamav-x64-0.102.1.7z

I call an exe in that package: & 'c:clamavfreshclam.exe'
And I get the following error:

Trying again in 5 secs...
daily database available for download (remote version: 25759)
ERROR: Download failed (60) ERROR:  Message: SSL peer certificate or SSH remote key was not OK
ERROR: getcvd: Can't download daily.cvd from https://database.clamav.net/daily.cvd
Giving up on https://database.clamav.net...
ERROR: Update failed for database: daily
WARNING: fc_update_databases: fc_update_database failed: Connection failed (5)
ERROR: Database update process failed: Connection failed (5)
ERROR: Update failed.

Dont get it because I can access that URL without issue. I then found if I run HEAD against that URL first before running the exe it works:

Invoke-WebRequest -Uri 'https://database.clamav.net/daily.cvd' -Method HEAD
# Now this will work
& 'c:clamavfreshclam.exe'

I think they might have implemented curl libs wrong or something? I dont understand what could even cause this. Does invoke-webquest fetch and cache certs but curl (or the apps use of it) does not do that?

  • Ошибка ssl opera ваше подключение не является приватным opera
  • Ошибка ssl chrome как исправить
  • Ошибка ssl certificate problem self signed certificate in certificate chain
  • Ошибка ssl 61 citrix linux
  • Ошибка ssl 500 на терминале ingenico