diff options
author | Stef Walter <stefw@collabora.co.uk> | 2011-03-19 01:42:55 +0800 |
---|---|---|
committer | Stef Walter <stefw@collabora.co.uk> | 2011-03-22 23:00:12 +0800 |
commit | 8b18f92aedef75ae557e879ddc4a60ce833d50d3 (patch) | |
tree | 9a2196c1fa0283a723112ed672d3a6edbb8631be /libempathy/empathy-tls-verifier.c | |
parent | 19d3ea612850bc3e2fabc387997e97ea11c89645 (diff) | |
download | gsoc2013-empathy-8b18f92aedef75ae557e879ddc4a60ce833d50d3.tar gsoc2013-empathy-8b18f92aedef75ae557e879ddc4a60ce833d50d3.tar.gz gsoc2013-empathy-8b18f92aedef75ae557e879ddc4a60ce833d50d3.tar.bz2 gsoc2013-empathy-8b18f92aedef75ae557e879ddc4a60ce833d50d3.tar.lz gsoc2013-empathy-8b18f92aedef75ae557e879ddc4a60ce833d50d3.tar.xz gsoc2013-empathy-8b18f92aedef75ae557e879ddc4a60ce833d50d3.tar.zst gsoc2013-empathy-8b18f92aedef75ae557e879ddc4a60ce833d50d3.zip |
Use ServerTLSConnection.ReferenceIdentities to check cert identity.
The certificate identity can be checked against more than just
one piece of information. Load and use all the reference identities
to check the identity of the certificate.
https://bugzilla.gnome.org/show_bug.cgi?id=645119
Diffstat (limited to 'libempathy/empathy-tls-verifier.c')
-rw-r--r-- | libempathy/empathy-tls-verifier.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/libempathy/empathy-tls-verifier.c b/libempathy/empathy-tls-verifier.c index 224150533..7b9c94c94 100644 --- a/libempathy/empathy-tls-verifier.c +++ b/libempathy/empathy-tls-verifier.c @@ -39,6 +39,7 @@ G_DEFINE_TYPE (EmpathyTLSVerifier, empathy_tls_verifier, enum { PROP_TLS_CERTIFICATE = 1, PROP_HOSTNAME, + PROP_REFERENCE_IDENTITIES, LAST_PROPERTY, }; @@ -58,6 +59,7 @@ typedef struct { EmpathyTLSCertificate *certificate; gchar *hostname; + gchar **reference_identities; GSimpleAsyncResult *verify_result; GHashTable *details; @@ -229,13 +231,28 @@ real_start_verification (EmpathyTLSVerifier *self) gint num_certs; EmpTLSCertificateRejectReason reason = EMP_TLS_CERTIFICATE_REJECT_REASON_UNKNOWN; + gint i; + gboolean matched; EmpathyTLSVerifierPriv *priv = GET_PRIV (self); DEBUG ("Starting verification"); - /* check if the certificate matches the hostname first. */ + /* check if the certificate matches one of the reference identities. */ first_cert = g_ptr_array_index (priv->cert_chain, 0); - if (gnutls_x509_crt_check_hostname (first_cert, priv->hostname) == 0) + if (priv->reference_identities != NULL) + { + for (i = 0, matched = FALSE; priv->reference_identities[i] != NULL; ++i) + { + if (gnutls_x509_crt_check_hostname (first_cert, + priv->reference_identities[i]) == 1) + { + matched = TRUE; + break; + } + } + } + + if (!matched) { gchar *certified_hostname; @@ -539,6 +556,9 @@ empathy_tls_verifier_get_property (GObject *object, case PROP_HOSTNAME: g_value_set_string (value, priv->hostname); break; + case PROP_REFERENCE_IDENTITIES: + g_value_set_boxed (value, priv->reference_identities); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -561,6 +581,9 @@ empathy_tls_verifier_set_property (GObject *object, case PROP_HOSTNAME: priv->hostname = g_value_dup_string (value); break; + case PROP_REFERENCE_IDENTITIES: + priv->reference_identities = g_value_dup_boxed (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -593,6 +616,7 @@ empathy_tls_verifier_finalize (GObject *object) tp_clear_pointer (&priv->cert_chain, g_ptr_array_unref); tp_clear_boxed (G_TYPE_HASH_TABLE, &priv->details); g_free (priv->hostname); + g_strfreev (priv->reference_identities); G_OBJECT_CLASS (empathy_tls_verifier_parent_class)->finalize (object); } @@ -639,22 +663,32 @@ empathy_tls_verifier_class_init (EmpathyTLSVerifierClass *klass) g_object_class_install_property (oclass, PROP_TLS_CERTIFICATE, pspec); pspec = g_param_spec_string ("hostname", "The hostname", - "The hostname which should be certified by the certificate.", + "The hostname which is certified by the certificate.", NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (oclass, PROP_HOSTNAME, pspec); + + pspec = g_param_spec_boxed ("reference-identities", + "The reference identities", + "The certificate should certify one of these identities.", + G_TYPE_STRV, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (oclass, PROP_REFERENCE_IDENTITIES, pspec); } EmpathyTLSVerifier * empathy_tls_verifier_new (EmpathyTLSCertificate *certificate, - const gchar *hostname) + const gchar *hostname, + const gchar **reference_identities) { g_assert (EMPATHY_IS_TLS_CERTIFICATE (certificate)); g_assert (hostname != NULL); + g_assert (reference_identities != NULL); return g_object_new (EMPATHY_TYPE_TLS_VERIFIER, "certificate", certificate, "hostname", hostname, + "reference-identities", reference_identities, NULL); } |