Exemplo n.º 1
0
static void
async_lookup_certificates_issued_by_thread (GSimpleAsyncResult *res,
                                            GObject            *object,
                                            GCancellable       *cancellable)
{
  AsyncLookupCertificatesIssuedBy *args = g_simple_async_result_get_op_res_gpointer (res);
  GError *error = NULL;

  args->results = g_tls_database_lookup_certificates_issued_by (G_TLS_DATABASE (object),
                                                                args->issuer,
                                                                args->interaction,
                                                                args->flags,
                                                                cancellable,
                                                                &error);

  if (error)
      g_simple_async_result_take_error (res, error);
}
Exemplo n.º 2
0
static GTlsCertificate *
lookup_client_certificate (GTlsClientConnection  *conn,
			   GError               **error)
{
  GList *l, *accepted;
  GList *c, *certificates;
  GTlsDatabase *database;
  GTlsCertificate *certificate = NULL;
  GTlsConnection *base;

  accepted = g_tls_client_connection_get_accepted_cas (conn);
  for (l = accepted; l != NULL; l = g_list_next (l))
    {
      base = G_TLS_CONNECTION (conn);
      database = g_tls_connection_get_database (base);
      certificates = g_tls_database_lookup_certificates_issued_by (database, l->data,
                                                                   g_tls_connection_get_interaction (base),
                                                                   G_TLS_DATABASE_LOOKUP_KEYPAIR,
                                                                   NULL, error);
      if (error && *error)
        break;

      if (certificates)
          certificate = g_object_ref (certificates->data);

      for (c = certificates; c != NULL; c = g_list_next (c))
        g_object_unref (c->data);
      g_list_free (certificates);
    }

  for (l = accepted; l != NULL; l = g_list_next (l))
    g_byte_array_unref (l->data);
  g_list_free (accepted);

  if (certificate == NULL && error && !*error)
    g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_CERTIFICATE_REQUIRED,
                         "Server requested a certificate, but could not find relevant certificate in database.");
  return certificate;
}