Commit Graph

25 Commits

Author SHA1 Message Date
Frediano Ziglio
8e8476d932 ssl_verify: Fix build for newer LibreSSL
LibreSSL 2.7 defines ASN1_STRING_get0_data, like OpenSSL 1.1.
This fixes https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=229044.
Original patch from Piotr Kubaj.

Reported-by: Jack L. <xxjack12xx@gmail.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-06-26 18:30:58 +01:00
Frediano Ziglio
3f04e2649d Revert "ssl_verify: Fix build for newer LibreSSL"
This reverts commit 638c77f3e6.
Commit had a misleading comment.
2018-06-26 18:30:58 +01:00
Frediano Ziglio
638c77f3e6 ssl_verify: Fix build for newer LibreSSL
LibreSSL 2.7 does not define ASN1_STRING_get0_data, like OpenSSL 1.1.
This fixes https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=229044.
Original patch from Piotr Kubaj.

Reported-by: Jack L. <xxjack12xx@gmail.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-06-26 17:58:44 +01:00
Paweł Pękala
122be3d1f7 Fix build with LibreSSL
Some FreeBSD configurations can use LibreSSL instead of OpenSSL.
The two libraries are really similar but need some minimal adjustment.

Signed-off-by: Paweł Pękala <pawelbsd@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-01-23 10:23:43 +00:00
Sebastian Andrzej Siewior
ab7cae45bc ssl: Use ASN1_STRING_get0_data instead of ASN1_STRING_data
The latter is deprecated, so might be removed at  some point in the
future. This also adds a compatibility wrapper for OpenSSL < 1.1.0.

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-16 16:40:52 +01:00
Christophe Fergeau
47122befcd ssl-verify: Don't leak GInetAddress
GInetAddress is a GObject, so we must unref anything we create with
g_inet_address_new_*
2015-11-27 17:50:02 +01:00
Christophe Fergeau
9057e0aef3 ssl-verify: Handle NULL return from g_inet_address_new_from_string()
It will return NULL if the string we pass it cannot be parsed.
2015-11-27 17:50:02 +01:00
Lukas Venhoda
9749e7ed14 ssl-verify: Changed IPv4 hostname to IPv6
Change inet_aton function to glib functions.

inet_aton only supported IPv4 addresses, and wasn't available on windows
machines. GInetAddress functions support IPv6 natively, and requires less
boilerplate code then IPv6 gettaddrinfo().
2015-10-23 11:07:58 +02:00
Lukas Venhoda
fb6904f528 ssl-verify: Only check addr length when using IP addr
Only check for address length, when connecting through IP address.
It is not used, when connecting through DNS hostname.
2015-10-23 11:07:45 +02:00
Christophe Fergeau
6175014ed7 ssl: Don't use uninitialized variable in verify_subject()
If verify_subject() is called with a SpiceOpenSSLVerify struct containing a
non-NULL 'in_subject' member, it would try to use the local 'in_entries'
variable without having initialized it first. This could happen if
verify_subject() was called multiple time with the same SpiceOpenSSLVerify
context, which probably isn't occurring the way we are using it.

However, since verify_subject() is the only method which needs in_subject,
we don't need to have it stored in SpiceOpenSSLVerify, and we can
recreate it as needed locally in that method, which avoids that issue.
2014-01-07 13:55:58 +01:00
Christophe Fergeau
fa640286f4 ssl: Don't try hostname check if cert subject check fails
Currently, SSL verification of the peer certificate checks if
the certificate's subject CN or one of its subjectAltName match
the hostname. If this succeeds, then the verification succeeds.
Otherwise openssl_verify() checks the cert subject if this was set,
which means it checks the certificate's subject (not just its CN) matches
exactly the cert subject string that is set in SpiceSession.

Given that the cert subject is something the user specifies in addition
to the hostname, the cert subject check should have priority over the
hostname check, that is, when we have a cert subject set, the
success/failure of the cert subject cert should determine the
success/failure of openssl_verify(), and the hostname check
should only be carried out when no cert subject was set.

This fixes rhbz#871034
2013-10-11 10:21:54 +02:00
Christophe Fergeau
9b3e972cdc ssl: Log an error when peer certificate verification failed
We currently log an error when openssl_verify() is called with
preverify_ok set to 0 for all certificates in the certificate chain
except for the peer certificate (when 'depth' is 0).
This commit logs an error in the latter case as well.
2013-10-11 10:21:54 +02:00
Christophe Fergeau
b34169feb6 ssl: Improve error message in cert chain verification
It contains the same information as before, but should be more readable.
2013-10-11 10:21:54 +02:00
Marc-André Lureau
8543d04cd2 ssl-verify: use more explicit error message
When the server certificate is not being signed by the provided CA,
the SSL debug message is currently for example:

ssl_verify.c:428:openssl_verify: openssl verify:num=19:self signed
certificate in certificate chain:depth=1:/C=IL/L=Raanana/O=Red
Hat/CN=my CA

Add a more explicit debug message too, as requested in bug:

https://bugzilla.redhat.com/show_bug.cgi?id=846666
2012-10-18 21:20:54 +02:00
Marc-André Lureau
f8f6231ecd Fix a gcc warning
warning: suggest explicit braces to avoid ambiguous 'else'
2012-06-30 02:54:53 +02:00
Christophe Fergeau
bf5511033d ssl: more verbose output when SSL verification fails
This should make SSL connection failures easier to diagnose.
2012-06-25 14:59:59 +02:00
Marc-André Lureau
5f44094940 ssl-verify: add a bit of run-time checks
Even if they are not public functions, those conditions can be reached
in a invalid state.
2012-05-17 14:38:28 +02:00
Aric Stewart
6af29a97ac move variable decleration to head of code block
Signed-off-by: Aric Stewart <aric@codeweavers.com>
2012-04-18 17:53:05 +03:00
Marc-André Lureau
e3f6941895 Bypass certicate verification failure if PUBKEY check only
During switch-host migration, only PUBKEY verification is required.
Couldn't it just load the certificate again for the new session?
perhaps, but that's they way the code used to work until I introduced
a regression in spice commit d46f9d3f4e006d3bca9b99fac25169b17e7ac803.
2012-03-30 14:10:00 +02:00
Marc-André Lureau
a0339261d4 ssl-verify: improve logging report in case of errors
Use the log.h system, and report a bit more information in the debug level
2012-03-30 14:10:00 +02:00
Daniel P. Berrange
fbb6b9984a Add missing includes & make some functions static
A number of functions were used without prior declaration. In
some cases this was due to missing include files. In other cases
the functions should have just been static.

Ideally this would allow -Wmissing-declarations to be enabled, but
the files generated by spice_codegen.py will still trip up on this.
2012-03-20 15:30:24 +01:00
Daniel P. Berrange
3bc7d096b6 Avoid warnings about empty conditional statement bodies
Add extra {} braces around if/else statements which only
call SPICE_DEBUG to avoid:

../common/ssl_verify.c: In function 'verify_pubkey':
../common/ssl_verify.c:87:50: warning: suggest braces around empty body in an 'else' statement [-Wempty-body]
../common/ssl_verify.c: In function 'verify_hostname':
../common/ssl_verify.c:254:53: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
../common/ssl_verify.c: In function 'verify_subject':
../common/ssl_verify.c:381:41: warning: suggest braces around empty body in an 'else' statement [-Wempty-body]
2012-03-20 15:30:23 +01:00
Christophe Fergeau
c968e76f96 ssl_verify: include <string.h>
ssl_verify.c is using memcmp which comes from string.h, this was
breaking compilation with -Werror -Wall on Mac OS X
2012-03-20 15:30:23 +01:00
Arnon Gilboa
4cb26e06f7 common: fix ssl_verify windows build errors 2012-03-20 15:25:53 +01:00
Marc-André Lureau
5de42c768d common: add ssl_verify.c common code
Code adapter from RedPeer::ssl_verify_callback() and used by
spice-gtk.

Since v1:
 - fixed Makefile.am
 - added config.h include
 - autoconf alloca added in patch series
 - moved int escape inside for loop
 - added a failed case when missing assignment
 - replaced strlen () by -1
 - skip spaces after comma
 - c++ guards

I didn't use bool, because openSSL uses int, and it is more future
proof for error reporting.
2012-03-20 15:25:53 +01:00