Commit 7cc2c800 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

gnutls: fix strict certificate checks and simplify

parent ff4c8fdf
...@@ -345,25 +345,17 @@ static int gnutls_CertSearch (vlc_tls_t *obj, const char *host, ...@@ -345,25 +345,17 @@ static int gnutls_CertSearch (vlc_tls_t *obj, const char *host,
static struct static struct
{ {
int flag; unsigned flag;
const char msg[43]; const char msg[29];
bool strict;
} cert_errs[] = } cert_errs[] =
{ {
{ GNUTLS_CERT_INVALID, { GNUTLS_CERT_INVALID, "Certificate not verified" },
"Certificate could not be verified", false }, { GNUTLS_CERT_REVOKED, "Certificate revoked" },
{ GNUTLS_CERT_REVOKED, { GNUTLS_CERT_SIGNER_NOT_FOUND, "Signer not found" },
"Certificate was revoked", true }, { GNUTLS_CERT_SIGNER_NOT_CA, "Signer not a CA" },
{ GNUTLS_CERT_SIGNER_NOT_FOUND, { GNUTLS_CERT_INSECURE_ALGORITHM, "Signature algorithm insecure" },
"Certificate's signer was not found", false }, { GNUTLS_CERT_NOT_ACTIVATED, "Certificate not activated" },
{ GNUTLS_CERT_SIGNER_NOT_CA, { GNUTLS_CERT_EXPIRED, "Certificate expired" },
"Certificate's signer is not a CA", true },
{ GNUTLS_CERT_INSECURE_ALGORITHM,
"Insecure certificate signature algorithm", true },
{ GNUTLS_CERT_NOT_ACTIVATED,
"Certificate is not yet activated", true },
{ GNUTLS_CERT_EXPIRED,
"Certificate has expired", true },
}; };
...@@ -386,25 +378,14 @@ static int gnutls_HandshakeAndValidate (vlc_tls_t *session, const char *host, ...@@ -386,25 +378,14 @@ static int gnutls_HandshakeAndValidate (vlc_tls_t *session, const char *host,
gnutls_strerror (val)); gnutls_strerror (val));
return -1; return -1;
} }
if (status) if (status)
{ {
msg_Err (session, "Certificate verification failure:"); msg_Err (session, "Certificate verification failure (0x%04X)", status);
for (size_t i = 0; i < sizeof (cert_errs) / sizeof (cert_errs[0]); i++) for (size_t i = 0; i < sizeof (cert_errs) / sizeof (cert_errs[0]); i++)
if (status & cert_errs[i].flag) if (status & cert_errs[i].flag)
{
msg_Err (session, " * %s", cert_errs[i].msg); msg_Err (session, " * %s", cert_errs[i].msg);
status &= ~cert_errs[i].flag; if (status & ~(GNUTLS_CERT_INVALID|GNUTLS_CERT_SIGNER_NOT_FOUND))
if (cert_errs[i].strict) return -1;
val = -1;
}
if (status)
{
msg_Err (session, " * Unknown verification error 0x%04X", status);
val = -1;
}
status = -1;
} }
/* certificate (host)name verification */ /* certificate (host)name verification */
...@@ -447,7 +428,7 @@ static int gnutls_HandshakeAndValidate (vlc_tls_t *session, const char *host, ...@@ -447,7 +428,7 @@ static int gnutls_HandshakeAndValidate (vlc_tls_t *session, const char *host,
} }
error: error:
gnutls_x509_crt_deinit (cert); gnutls_x509_crt_deinit (cert);
return val ? -1 : 0; return val;
} }
static int static int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment