Пример #1
0
static void
seahorse_hkp_source_search_async (SeahorseServerSource *source,
                                  const gchar *match,
                                  GcrSimpleCollection *results,
                                  GCancellable *cancellable,
                                  GAsyncReadyCallback callback,
                                  gpointer user_data)
{
	SeahorseHKPSource *self = SEAHORSE_HKP_SOURCE (source);
	source_search_closure *closure;
	GSimpleAsyncResult *res;
	SoupMessage *message;
	GHashTable *form;
	SoupURI *uri;
	gchar hexfpr[11];

	res = g_simple_async_result_new (G_OBJECT (source), callback, user_data,
	                                 seahorse_hkp_source_search_async);
	closure = g_new0 (source_search_closure, 1);
	closure->source = g_object_ref (self);
	closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
	closure->session = create_hkp_soup_session ();
	closure->results = g_object_ref (results);
	g_simple_async_result_set_op_res_gpointer (res, closure, source_search_free);

	uri = get_http_server_uri (self, "/pks/lookup");
	g_return_if_fail (uri);

	form = g_hash_table_new (g_str_hash, g_str_equal);
	g_hash_table_insert (form, "op", "index");

	if (is_hex_keyid (match)) {
		strncpy (hexfpr, "0x", 3);
		strncpy (hexfpr + 2, match, 9);
		g_hash_table_insert (form, "search", hexfpr);
	} else {
		g_hash_table_insert (form, "search", (char *)match);
	}

	g_hash_table_insert (form, "fingerprint", "on");

	soup_uri_set_query_from_form (uri, form);
	g_hash_table_destroy (form);

	message = soup_message_new_from_uri ("GET", uri);
	soup_session_queue_message (closure->session, message,
	                            on_search_message_complete, g_object_ref (res));

	seahorse_progress_prep_and_begin (cancellable, message, NULL);

	if (cancellable)
		closure->cancelled_sig = g_cancellable_connect (cancellable,
		                                                G_CALLBACK (on_session_cancelled),
		                                                closure->session, NULL);

	soup_uri_free (uri);
	g_object_unref (res);
}
Пример #2
0
static SeahorseOperation*
seahorse_hkp_source_search (SeahorseSource *src, const gchar *match)
{
    SeahorseHKPOperation *hop;
    SoupMessage *message;
    GHashTable *form;
    gchar *t;
    SoupURI *uri;
    gchar hexfpr[11];
    
    g_assert (SEAHORSE_IS_SOURCE (src));
    g_assert (SEAHORSE_IS_HKP_SOURCE (src));

    hop = setup_hkp_operation (SEAHORSE_HKP_SOURCE (src));
    
    uri = get_http_server_uri (src, "/pks/lookup");
    g_return_val_if_fail (uri, FALSE);
    
    form = g_hash_table_new (g_str_hash, g_str_equal);
    g_hash_table_insert (form, "op", "index");
    
    if (is_hex_keyid (match)) {
        strncpy (hexfpr, "0x", 3);
        strncpy (hexfpr + 2, match, 9);
        
        g_hash_table_insert (form, "search", hexfpr);
    } else 
        g_hash_table_insert (form, "search", (char *)match);
        
    soup_uri_set_query_from_form (uri, form);
    g_hash_table_destroy (form);
    
    message = soup_message_new_from_uri ("GET", uri);
    
    soup_session_queue_message (hop->session, message, 
                                (SoupSessionCallback)refresh_callback, hop);

    hop->total = hop->requests = 1;
    t = g_strdup_printf (_("Searching for keys on: %s"), uri->host);
    seahorse_operation_mark_progress (SEAHORSE_OPERATION (hop), t, -1);
    g_free (t);

    soup_uri_free (uri);

    seahorse_server_source_take_operation (SEAHORSE_SERVER_SOURCE (src), 
                                           SEAHORSE_OPERATION (hop));
    g_object_ref (hop);
    return SEAHORSE_OPERATION (hop);
}
Пример #3
0
static void
seahorse_hkp_source_export_async (SeahorseServerSource *source,
                                  const gchar **keyids,
                                  GCancellable *cancellable,
                                  GAsyncReadyCallback callback,
                                  gpointer user_data)
{
    SeahorseHKPSource *self = SEAHORSE_HKP_SOURCE (source);
    ExportClosure *closure;
    g_autoptr(GTask) task = NULL;
    SoupURI *uri;
    g_autoptr(GHashTable) form = NULL;
    gchar hexfpr[11];
    gint i;

    task = g_task_new (self, cancellable, callback, user_data);
    closure = g_new0 (ExportClosure, 1);
    closure->source = g_object_ref (self);
    closure->data = g_string_sized_new (1024);
    closure->session = create_hkp_soup_session ();
    closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
    g_task_set_task_data (task, closure, export_closure_free);

    if (!keyids || !keyids[0]) {
        g_task_return_pointer (task, NULL, NULL);
        return;
    }

    uri = get_http_server_uri (self, "/pks/lookup");
    g_return_if_fail (uri);

    /* prepend the hex prefix (0x) to make keyservers happy */
    strncpy (hexfpr, "0x", 3);

    form = g_hash_table_new (g_str_hash, g_str_equal);
    for (i = 0; keyids[i] != NULL; i++) {
        const gchar *fpr = keyids[i];
        guint len;
        SoupMessage *message;

        g_hash_table_remove_all (form);

        /* Get the key id and limit it to 8 characters */
        len = strlen (fpr);
        if (len > 8)
            fpr += (len - 8);

        strncpy (hexfpr + 2, fpr, 9);

        /* The get key URI */
        g_hash_table_insert (form, "op", "get");
        g_hash_table_insert (form, "search", (char *)hexfpr);
        soup_uri_set_query_from_form (uri, form);

        message = soup_message_new_from_uri ("GET", uri);

        soup_session_queue_message (closure->session, message,
                                    on_export_message_complete,
                                    g_object_ref (task));

        closure->requests++;
        seahorse_progress_prep_and_begin (cancellable, message, NULL);
    }

    if (cancellable)
        closure->cancelled_sig = g_cancellable_connect (cancellable,
                                                        G_CALLBACK (on_session_cancelled),
                                                        closure->session, NULL);
}
Пример #4
0
static void
seahorse_hkp_source_import_async (SeahorseServerSource *source,
                                  GInputStream *input,
                                  GCancellable *cancellable,
                                  GAsyncReadyCallback callback,
                                  gpointer user_data)
{
    SeahorseHKPSource *self = SEAHORSE_HKP_SOURCE (source);
    g_autoptr(GTask) task = NULL;
    source_import_closure *closure;
    g_autoptr(GList) keydata = NULL;
    g_autoptr(GHashTable) form = NULL;
    g_autoptr(SoupURI) uri = NULL;
    GList *l;

    task = g_task_new (source, cancellable, callback, user_data);
    closure = g_new0 (source_import_closure, 1);
    closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
    closure->input = g_object_ref (input);
    closure->source = g_object_ref (self);
    closure->session = create_hkp_soup_session ();
    g_task_set_task_data (task, closure, source_import_free);

    for (;;) {
        g_autoptr(GString) buf = g_string_sized_new (2048);
        guint len;

        len = seahorse_util_read_data_block (buf, input,
                                             "-----BEGIN PGP PUBLIC KEY BLOCK-----",
                                             "-----END PGP PUBLIC KEY BLOCK-----");
        if (len <= 0)
            break;

        keydata = g_list_prepend (keydata,
                                  g_string_free (g_steal_pointer (&buf), FALSE));
    }

    if (g_list_length (keydata) == 0) {
        g_task_return_pointer (task, NULL, NULL);
        return;
    }

    /* Figure out the URI we're sending to */
    uri = get_http_server_uri (self, "/pks/add");
    g_return_if_fail (uri);

    /* New operation and away we go */
    keydata = g_list_reverse (keydata);

    form = g_hash_table_new (g_str_hash, g_str_equal);
    for (l = keydata; l; l = g_list_next (l)) {
        g_autoptr(SoupMessage) message = NULL;
        gchar *key;

        g_assert (l->data != NULL);
        g_hash_table_remove_all (form);

        g_hash_table_insert (form, "keytext", l->data);
        key = soup_form_encode_urlencoded (form);

        message = soup_message_new_from_uri ("POST", uri);
        soup_message_set_request (message, "application/x-www-form-urlencoded",
                                  SOUP_MEMORY_TAKE, key, strlen (key));

        soup_session_queue_message (closure->session,
                                    g_steal_pointer (&message),
                                    on_import_message_complete,
                                    g_object_ref (task));

        closure->requests++;
        seahorse_progress_prep_and_begin (cancellable, GUINT_TO_POINTER (closure->requests), NULL);
    }

    if (cancellable)
        closure->cancelled_sig = g_cancellable_connect (cancellable,
                                                        G_CALLBACK (on_session_cancelled),
                                                        closure->session, NULL);

    for (l = keydata; l != NULL; l = g_list_next (l))
        g_free (l->data);
}
Пример #5
0
/**
* sksrc: The HKP source to use
* input: The input stream to add
*
* Imports a list of keys from the input stream to the keyserver
**/
static void
seahorse_hkp_source_import_async (SeahorseServerSource *source,
                                  GInputStream *input,
                                  GCancellable *cancellable,
                                  GAsyncReadyCallback callback,
                                  gpointer user_data)
{
	SeahorseHKPSource *self = SEAHORSE_HKP_SOURCE (source);
	GSimpleAsyncResult *res;
	source_import_closure *closure;
	SoupMessage *message;
	GList *keydata = NULL;
	GString *buf = NULL;
	GHashTable *form;
	gchar *key;
	SoupURI *uri;
	GList *l;
	guint len;

	res = g_simple_async_result_new (G_OBJECT (source), callback, user_data,
	                                 seahorse_hkp_source_import_async);
	closure = g_new0 (source_import_closure, 1);
	closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
	closure->input = g_object_ref (input);
	closure->source = g_object_ref (self);
	closure->session = create_hkp_soup_session ();
	g_simple_async_result_set_op_res_gpointer (res, closure, source_import_free);

	for (;;) {

		buf = g_string_sized_new (2048);
		len = seahorse_util_read_data_block (buf, input,
		                                     "-----BEGIN PGP PUBLIC KEY BLOCK-----",
		                                     "-----END PGP PUBLIC KEY BLOCK-----");

		if (len > 0) {
			keydata = g_list_prepend (keydata, g_string_free (buf, FALSE));
		} else {
			g_string_free (buf, TRUE);
			break;
		}
	}

	if (g_list_length (keydata) == 0) {
		g_simple_async_result_complete_in_idle (res);
		g_object_unref (res);
		return;
	}

	/* Figure out the URI we're sending to */
	uri = get_http_server_uri (self, "/pks/add");
	g_return_if_fail (uri);

	/* New operation and away we go */
	keydata = g_list_reverse (keydata);

	form = g_hash_table_new (g_str_hash, g_str_equal);
	for (l = keydata; l; l = g_list_next (l)) {
		g_assert (l->data != NULL);
		g_hash_table_remove_all (form);

		g_hash_table_insert (form, "keytext", l->data);
		key = soup_form_encode_urlencoded (form);

		message = soup_message_new_from_uri ("POST", uri);
		soup_message_set_request (message, "application/x-www-form-urlencoded",
		                          SOUP_MEMORY_TAKE, key, strlen (key));

		soup_session_queue_message (closure->session, message,
		                            on_import_message_complete, g_object_ref (res));

		closure->requests++;
		seahorse_progress_prep_and_begin (cancellable, GUINT_TO_POINTER (closure->requests), NULL);
	}
	g_hash_table_destroy (form);

	if (cancellable)
		closure->cancelled_sig = g_cancellable_connect (cancellable,
		                                                G_CALLBACK (on_session_cancelled),
		                                                closure->session, NULL);

	soup_uri_free (uri);

	for (l = keydata; l != NULL; l = g_list_next (l))
		g_free (l->data);
	g_list_free (keydata);

	g_object_unref (res);
}
Пример #6
0
static SeahorseOperation*  
seahorse_hkp_source_export_raw (SeahorseSource *sksrc, GSList *keyids,
                                GOutputStream *output)
{
    SeahorseHKPOperation *hop;
    SeahorseHKPSource *hsrc;
    SoupMessage *message;
    gchar *t;
    SoupURI *uri;
    const gchar *fpr;
    gchar hexfpr[11];
    GHashTable *form;
    guint len;
    GSList *l;
    
    g_return_val_if_fail (SEAHORSE_IS_HKP_SOURCE (sksrc), NULL);
    g_return_val_if_fail (output == NULL || G_IS_OUTPUT_STREAM (output), NULL);

    hsrc = SEAHORSE_HKP_SOURCE (sksrc);
    
    if (g_slist_length (keyids) == 0)
        return seahorse_operation_new_complete (NULL);

    uri = get_http_server_uri (sksrc, "/pks/lookup");
    g_return_val_if_fail (uri, FALSE);

    /* New operation started */    
    hop = setup_hkp_operation (hsrc);

	g_object_ref (output);
	seahorse_operation_mark_result (SEAHORSE_OPERATION (hop), output, g_object_unref);

    /* prepend the hex prefix (0x) to make keyservers happy */
    strncpy(hexfpr, "0x", 3);

    form = g_hash_table_new (g_str_hash, g_str_equal);
    for (l = keyids; l; l = g_slist_next (l)) {

        /* Get the key id and limit it to 8 characters */
        fpr = seahorse_pgp_key_calc_rawid (GPOINTER_TO_UINT (l->data));
        len = strlen (fpr);
        if (len > 8)
            fpr += (len - 8);
	
        strncpy(hexfpr + 2, fpr, 9);

        /* The get key URI */
        g_hash_table_insert (form, "op", "get");
        g_hash_table_insert (form, "search", (char *)hexfpr);
        soup_uri_set_query_from_form (uri, form);

        message = soup_message_new_from_uri ("GET", uri);
        
        soup_session_queue_message (hop->session, message, 
                                    (SoupSessionCallback)get_callback, hop);

        hop->requests++;
    }
    g_hash_table_destroy (form);
    
    hop->total = hop->requests;
    t = g_strdup_printf (_("Connecting to: %s"), uri->host);
    seahorse_operation_mark_progress (SEAHORSE_OPERATION (hop), t, -1);
    g_free (t);

    soup_uri_free (uri);
    return SEAHORSE_OPERATION (hop);    
}
Пример #7
0
static SeahorseOperation* 
seahorse_hkp_source_import (SeahorseSource *sksrc, GInputStream *input)
{
    SeahorseHKPOperation *hop;
    SeahorseHKPSource *hsrc;
    SoupMessage *message;
    GSList *keydata = NULL;
    GString *buf = NULL;
    GHashTable *form;
    gchar *key, *t;
    SoupURI *uri;
    GSList *l;
    guint len;
    
    g_return_val_if_fail (SEAHORSE_IS_HKP_SOURCE (sksrc), NULL);
    hsrc = SEAHORSE_HKP_SOURCE (sksrc);
    
    g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
    g_object_ref (input);
    
    for (;;) {
     
        buf = g_string_sized_new (2048);
        len = seahorse_util_read_data_block (buf, input, "-----BEGIN PGP PUBLIC KEY BLOCK-----",
                                             "-----END PGP PUBLIC KEY BLOCK-----");
    
        if (len > 0) {
            keydata = g_slist_prepend (keydata, g_string_free (buf, FALSE));
        } else {
            g_string_free (buf, TRUE);
            break;
        }
    }
    
    	if (g_slist_length (keydata) == 0) {
    		g_object_unref (input);
    		return seahorse_operation_new_complete (NULL);
    	}
    
    /* Figure out the URI we're sending to */    
    uri = get_http_server_uri (sksrc, "/pks/add");
    g_return_val_if_fail (uri, FALSE);

    /* New operation and away we go */
    keydata = g_slist_reverse (keydata);   
    hop = setup_hkp_operation (hsrc);
    
    form = g_hash_table_new (g_str_hash, g_str_equal);
    for (l = keydata; l; l = g_slist_next (l)) {
        g_assert (l->data != NULL);

        g_hash_table_insert (form, "keytext", l->data);
        key = soup_form_encode_urlencoded (form);

        message = soup_message_new_from_uri ("POST", uri);
        soup_message_set_request (message, "application/x-www-form-urlencoded",
                                  SOUP_MEMORY_TAKE, key, strlen (key));
        
        soup_session_queue_message (hop->session, message, 
                                    (SoupSessionCallback)send_callback, hop);
        hop->requests++;
    }
    g_hash_table_destroy (form);

    hop->total = hop->requests;
    t = g_strdup_printf (_("Connecting to: %s"), uri->host);
    seahorse_operation_mark_progress (SEAHORSE_OPERATION (hop), t, -1);
    g_free (t);

    soup_uri_free (uri);
    
    	seahorse_util_string_slist_free (keydata);
    	g_object_unref (input);
    
    return SEAHORSE_OPERATION (hop);
}