• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 (C) Ruslan N. Marchenko <me@ruff.mobi>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  */
6 
7 #include "config.h"
8 
9 #include <gio/gio.h>
10 
11 #include "gtesttlsbackend.h"
12 
13 static void
get_tls_channel_binding(void)14 get_tls_channel_binding (void)
15 {
16   GTlsBackend *backend;
17   gchar *not_null = "NOT_NULL";
18   GTlsConnection *tls = NULL;
19   GError *error = NULL;
20 
21   backend = g_tls_backend_get_default ();
22   g_assert_nonnull (backend);
23 
24   /* check unimplemented GTlsConnection API sanity */
25   tls = G_TLS_CONNECTION (g_object_new (
26           g_tls_backend_get_client_connection_type (backend), NULL));
27   g_assert_nonnull (tls);
28 
29   g_assert_false (g_tls_connection_get_channel_binding_data (tls,
30           G_TLS_CHANNEL_BINDING_TLS_UNIQUE, NULL, NULL));
31 
32   g_assert_false (g_tls_connection_get_channel_binding_data (tls,
33           G_TLS_CHANNEL_BINDING_TLS_UNIQUE, NULL, &error));
34   g_assert_error (error, G_TLS_CHANNEL_BINDING_ERROR,
35                          G_TLS_CHANNEL_BINDING_ERROR_NOT_IMPLEMENTED);
36   g_clear_error (&error);
37 
38   if (g_test_subprocess ())
39     g_assert_false (g_tls_connection_get_channel_binding_data (tls,
40             G_TLS_CHANNEL_BINDING_TLS_UNIQUE, NULL, (GError **)&not_null));
41 
42   g_object_unref (tls);
43   g_test_trap_subprocess (NULL, 0, 0);
44   g_test_trap_assert_failed ();
45   g_test_trap_assert_stderr ("*GLib-GIO-CRITICAL*");
46 }
47 
48 static void
get_dtls_channel_binding(void)49 get_dtls_channel_binding (void)
50 {
51   GTlsBackend *backend;
52   gchar *not_null = "NOT_NULL";
53   GDtlsConnection *dtls = NULL;
54   GError *error = NULL;
55 
56   backend = g_tls_backend_get_default ();
57   g_assert_nonnull (backend);
58 
59   /* repeat for the dtls now */
60   dtls = G_DTLS_CONNECTION (g_object_new (
61           g_tls_backend_get_dtls_client_connection_type (backend), NULL));
62   g_assert_nonnull (dtls);
63 
64   g_assert_false (g_dtls_connection_get_channel_binding_data (dtls,
65           G_TLS_CHANNEL_BINDING_TLS_UNIQUE, NULL, NULL));
66 
67   g_assert_false (g_dtls_connection_get_channel_binding_data (dtls,
68           G_TLS_CHANNEL_BINDING_TLS_UNIQUE, NULL, &error));
69   g_assert_error (error, G_TLS_CHANNEL_BINDING_ERROR,
70                          G_TLS_CHANNEL_BINDING_ERROR_NOT_IMPLEMENTED);
71   g_clear_error (&error);
72 
73   if (g_test_subprocess ())
74     g_assert_false (g_dtls_connection_get_channel_binding_data (dtls,
75             G_TLS_CHANNEL_BINDING_TLS_UNIQUE, NULL, (GError **)&not_null));
76 
77   g_object_unref (dtls);
78   g_test_trap_subprocess (NULL, 0, 0);
79   g_test_trap_assert_failed ();
80   g_test_trap_assert_stderr ("*GLib-GIO-CRITICAL*");
81 }
82 
83 int
main(int argc,char * argv[])84 main (int   argc,
85       char *argv[])
86 {
87   g_test_init (&argc, &argv, NULL);
88 
89   _g_test_tls_backend_get_type ();
90 
91   g_test_add_func ("/tls-connection/get-tls-channel-binding", get_tls_channel_binding);
92   g_test_add_func ("/tls-connection/get-dtls-channel-binding", get_dtls_channel_binding);
93 
94   return g_test_run ();
95 }
96