mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-05 08:53:39 +02:00
tls: expose SAN details on GTlsCertificate
This changeset exposes * `dns-names` * `ip-addresses` on GTlsCertificate provided by the underlying TLS Backend. See https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/165 for the corresponding glib-networking changes. Relates: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2113 Relates: https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/156/diffs Relates: https://github.com/microsoft/playwright/issues/6759
This commit is contained in:
committed by
Michael Catanzaro
parent
eff19df205
commit
4d3618cbd1
@@ -114,6 +114,8 @@ enum
|
||||
PROP_CERT_NOT_VALID_AFTER,
|
||||
PROP_CERT_SUBJECT_NAME,
|
||||
PROP_CERT_ISSUER_NAME,
|
||||
PROP_CERT_DNS_NAMES,
|
||||
PROP_CERT_IP_ADDRESSES,
|
||||
};
|
||||
|
||||
static void g_test_tls_certificate_initable_iface_init (GInitableIface *iface);
|
||||
@@ -139,6 +141,8 @@ g_test_tls_certificate_get_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GTestTlsCertificate *cert = (GTestTlsCertificate *) object;
|
||||
GPtrArray *data = NULL;
|
||||
const gchar *dns_name = "a.example.com";
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
@@ -172,6 +176,16 @@ g_test_tls_certificate_get_property (GObject *object,
|
||||
case PROP_CERT_ISSUER_NAME:
|
||||
g_value_set_string (value, "DC=COM,DC=EXAMPLE,OU=Certificate Authority,CN=ca.example.com,emailAddress=ca@example.com");
|
||||
break;
|
||||
case PROP_CERT_DNS_NAMES:
|
||||
data = g_ptr_array_new_with_free_func ((GDestroyNotify)g_bytes_unref);
|
||||
g_ptr_array_add (data, g_bytes_new_static (dns_name, strlen (dns_name)));
|
||||
g_value_take_boxed (value, data);
|
||||
break;
|
||||
case PROP_CERT_IP_ADDRESSES:
|
||||
data = g_ptr_array_new_with_free_func (g_object_unref);
|
||||
g_ptr_array_add (data, g_inet_address_new_from_string ("192.0.2.1"));
|
||||
g_value_take_boxed (value, data);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
@@ -250,6 +264,8 @@ g_test_tls_certificate_class_init (GTestTlsCertificateClass *test_class)
|
||||
g_object_class_override_property (gobject_class, PROP_CERT_NOT_VALID_AFTER, "not-valid-after");
|
||||
g_object_class_override_property (gobject_class, PROP_CERT_SUBJECT_NAME, "subject-name");
|
||||
g_object_class_override_property (gobject_class, PROP_CERT_ISSUER_NAME, "issuer-name");
|
||||
g_object_class_override_property (gobject_class, PROP_CERT_DNS_NAMES, "dns-names");
|
||||
g_object_class_override_property (gobject_class, PROP_CERT_IP_ADDRESSES, "ip-addresses");
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -548,6 +548,51 @@ issuer_name (void)
|
||||
g_object_unref (cert);
|
||||
}
|
||||
|
||||
static void
|
||||
dns_names (void)
|
||||
{
|
||||
GTlsCertificate *cert;
|
||||
GError *error = NULL;
|
||||
GPtrArray *actual;
|
||||
const gchar *dns_name = "a.example.com";
|
||||
GBytes *expected = g_bytes_new_static (dns_name, strlen (dns_name));
|
||||
|
||||
cert = g_tls_certificate_new_from_pkcs11_uris ("pkcs11:model=p11-kit-trust;manufacturer=PKCS%2311%20Kit;serial=1;token=ca-bundle.crt", NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_nonnull (cert);
|
||||
|
||||
actual = g_tls_certificate_get_dns_names (cert);
|
||||
g_assert_nonnull (actual);
|
||||
g_assert_cmpuint (actual->len, ==, 1);
|
||||
g_assert_true (g_ptr_array_find_with_equal_func (actual, expected, (GEqualFunc)g_bytes_equal, NULL));
|
||||
|
||||
g_ptr_array_free (actual, FALSE);
|
||||
g_bytes_unref (expected);
|
||||
g_object_unref (cert);
|
||||
}
|
||||
|
||||
static void
|
||||
ip_addresses (void)
|
||||
{
|
||||
GTlsCertificate *cert;
|
||||
GError *error = NULL;
|
||||
GPtrArray *actual;
|
||||
GInetAddress *expected = g_inet_address_new_from_string ("192.0.2.1");
|
||||
|
||||
cert = g_tls_certificate_new_from_pkcs11_uris ("pkcs11:model=p11-kit-trust;manufacturer=PKCS%2311%20Kit;serial=1;token=ca-bundle.crt", NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_nonnull (cert);
|
||||
|
||||
actual = g_tls_certificate_get_ip_addresses (cert);
|
||||
g_assert_nonnull (actual);
|
||||
g_assert_cmpuint (actual->len, ==, 1);
|
||||
g_assert_true (g_ptr_array_find_with_equal_func (actual, expected, (GEqualFunc)g_inet_address_equal, NULL));
|
||||
|
||||
g_ptr_array_free (actual, TRUE);
|
||||
g_object_unref (expected);
|
||||
g_object_unref (cert);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
@@ -626,6 +671,10 @@ main (int argc,
|
||||
subject_name);
|
||||
g_test_add_func ("/tls-certificate/issuer-name",
|
||||
issuer_name);
|
||||
g_test_add_func ("/tls-certificate/dns-names",
|
||||
dns_names);
|
||||
g_test_add_func ("/tls-certificate/ip-addresses",
|
||||
ip_addresses);
|
||||
g_test_add_func ("/tls-certificate/pem-parser-no-sentinel",
|
||||
pem_parser_no_sentinel);
|
||||
|
||||
|
Reference in New Issue
Block a user