Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QSslError: The certificate is self-signed, and untrusted

I'm trying send a rest request to a webservice where the certificate is selfsigned. At the moment I'm creating a request, setting the url and the auth. key as headers. Then I tell the reply to ignore this ssl error:

QSslError error(QSslError::SelfSignedCertificate);
QList<QSslError> expectedSslErrors;
expectedSslErrors.append(error);

QNetworkReply *reply = _accessManager.put(request, ""); // no requestbody
reply->ignoreSslErrors(expectedSslErrors);

When I run it I get the following ssl error:

9 - The certificate is self-signed, and untrusted

followed by network error nr 6:

Request failed with message: SSL handshake failed

At the moment I'm ignoring ALL errors since it seems to be the only thing that works. Feel dirty.

Would be really grateful if anyone know what I'm doing wrong!

EDIT:

Changed to:

QList<QSslError> expectedSslErrors;
expectedSslErrors.append(QSslError::SelfSignedCertificate);
expectedSslErrors.append(QSslError::CertificateUntrusted);
reply->ignoreSslErrors(expectedSslErrors);

But still getting the same error...

like image 573
chikuba Avatar asked Apr 10 '12 22:04

chikuba


People also ask

How do you fix the certificate is not trusted because it is self-signed?

You will need to have a self-signed certificate removed and a trusted one reinstalled for everything to work properly. Note, if your server supports SNI technology, you will not need a dedicated IP address for every certificate installed on the server. You need to discuss this with your hosting provider.

How do I get Chrome to recognize a self-signed certificate?

Navigate to the site with the cert you want to trust, and click through the usual warnings for untrusted certificates. In the address bar, right click on the red warning triangle and "Not secure" message and, from the resulting menu, select "Certificate" to show the certificate.


1 Answers

The certificate is self-signed, and untrusted

The problem is the "untrusted" part. You have to provide the self signed certificate, as second parameter of QSslError.

Edit: Based on the source code, the comparison between the actually received SSL errors and the errors passed to ignoreSslErrors is done by comparing both the error code, and the certificate.
So if the error returned by OpenSSL would contain a certificate, like with QSslError::SelfSignedCertificate, you must always pass a certificate to QSslError constructor, or the comparison would fail.

But you can also ignore the error manually by connecting the signal sslError() to a slot where you check that the error list contains only a self signed certificate error, and then call ignoreSslErrors() (without any parameter).

like image 146
alexisdm Avatar answered Nov 15 '22 05:11

alexisdm