~ubuntu-branches/ubuntu/natty/gnome-keyring/natty

« back to all changes in this revision

Viewing changes to gp11/tests/unit-test-gp11-crypto.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-02-16 19:00:06 UTC
  • mfrom: (1.1.58 upstream)
  • Revision ID: james.westby@ubuntu.com-20100216190006-cqpnic4zxlkmmi0o
Tags: 2.29.90git20100218-0ubuntu1
Updated to a git snapshot version

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        
60
60
        for (l = objects; l; l = g_list_next (l)) {
61
61
                gp11_object_set_session (l->data, session);
62
 
                mechs = gp11_object_get_data (l->data, CKA_ALLOWED_MECHANISMS, &n_mechs, NULL);
63
 
                g_assert (mechs);
64
 
                g_assert (n_mechs == sizeof (CK_MECHANISM_TYPE));
65
 
                
66
 
                /* We know all of them only have one allowed mech */
67
 
                if (*mechs == mech) {
68
 
                        object = l->data;
69
 
                        g_object_ref (object);
70
 
                        break;
 
62
                if (mech) {
 
63
                        mechs = gp11_object_get_data (l->data, CKA_ALLOWED_MECHANISMS, &n_mechs, NULL);
 
64
                        g_assert (mechs);
 
65
                        g_assert (n_mechs == sizeof (CK_MECHANISM_TYPE));
 
66
                        /* We know all of them only have one allowed mech */
 
67
                        if (*mechs != mech)
 
68
                                continue;
71
69
                }
 
70
                object = l->data;
 
71
                g_object_ref (object);
 
72
                break;
72
73
        }
73
74
        
74
75
        gp11_list_unref_free (objects);
75
76
        return object;
76
77
}
77
78
 
 
79
static GP11Object*
 
80
find_key_with_value (GP11Session *session, const gchar *value)
 
81
{
 
82
        GList *objects;
 
83
        GP11Object *object;
 
84
 
 
85
        objects = gp11_session_find_objects (session, NULL, CKA_VALUE, GP11_STRING, value, GP11_INVALID);
 
86
        g_assert (objects);
 
87
 
 
88
        object = g_object_ref (objects->data);
 
89
        gp11_list_unref_free (objects);
 
90
        return object;
 
91
}
 
92
 
 
93
static void
 
94
check_key_with_value (GP11Session *session, GP11Object *key, CK_OBJECT_CLASS klass, const gchar *value)
 
95
{
 
96
        GP11Attributes *attrs;
 
97
        GP11Attribute *attr;
 
98
        gulong check;
 
99
 
 
100
        gp11_object_set_session (key, session);
 
101
        attrs = gp11_object_get (key, NULL, CKA_CLASS, CKA_VALUE, GP11_INVALID);
 
102
        g_assert (attrs);
 
103
 
 
104
        if (!gp11_attributes_find_ulong (attrs, CKA_CLASS, &check))
 
105
                g_assert_not_reached ();
 
106
        g_assert (check == klass);
 
107
 
 
108
        attr = gp11_attributes_find (attrs, CKA_VALUE);
 
109
        g_assert (attr);
 
110
        g_assert (!gp11_attribute_is_invalid (attr));
 
111
        g_assert_cmpsize (attr->length, ==, strlen (value));
 
112
        g_assert (memcmp (attr->value, value, attr->length) == 0);
 
113
 
 
114
        gp11_attributes_unref (attrs);
 
115
}
 
116
 
78
117
static gboolean
79
118
authenticate_object (GP11Slot *module, GP11Object *object, gchar *label, gchar **password)
80
119
{
89
128
 
90
129
DEFINE_TEST(encrypt)
91
130
{
92
 
        GP11Mechanism mech;
 
131
        GP11Mechanism *mech;
93
132
        GError *error = NULL;
94
133
        GAsyncResult *result = NULL;
95
134
        GP11Object *key;
96
135
        guchar *output;
97
136
        gsize n_output;
98
137
 
99
 
        mech.type = CKM_CAPITALIZE;
100
 
        mech.n_parameter = 0;
101
 
        mech.parameter = NULL;
 
138
        mech = gp11_mechanism_new (CKM_CAPITALIZE);
102
139
 
103
140
        /* Find the right key */
104
141
        key = find_key (session, CKA_ENCRYPT, CKM_CAPITALIZE);
112
149
        g_free (output);
113
150
        
114
151
        /* Full one */
115
 
        output = gp11_session_encrypt_full (session, key, &mech, (const guchar*)"blah blah", 10, &n_output, NULL, &error);
 
152
        output = gp11_session_encrypt_full (session, key, mech, (const guchar*)"blah blah", 10, &n_output, NULL, &error);
116
153
        SUCCESS_RES (output, error);
117
154
        g_assert (n_output == 10);
118
155
        g_assert_cmpstr ((gchar*)output, ==, "BLAH BLAH");
119
156
        g_free (output);
120
157
        
121
158
        /* Asynchronous one */
122
 
        gp11_session_encrypt_async (session, key, &mech, (const guchar*)"second chance", 14, NULL, fetch_async_result, &result);
 
159
        gp11_session_encrypt_async (session, key, mech, (const guchar*)"second chance", 14, NULL, fetch_async_result, &result);
123
160
 
124
161
        WAIT_UNTIL (result);
125
162
        g_assert (result != NULL);
131
168
        g_assert_cmpstr ((gchar*)output, ==, "SECOND CHANCE");
132
169
        g_free (output);
133
170
 
 
171
        gp11_mechanism_unref (mech);
134
172
        g_object_unref (result);
135
173
        g_object_unref (key);
136
174
}
137
175
 
138
176
DEFINE_TEST(decrypt)
139
177
{
140
 
        GP11Mechanism mech;
 
178
        GP11Mechanism *mech;
141
179
        GError *error = NULL;
142
180
        GAsyncResult *result = NULL;
143
181
        GP11Object *key;
144
182
        guchar *output;
145
183
        gsize n_output;
146
184
 
147
 
        mech.type = CKM_CAPITALIZE;
148
 
        mech.n_parameter = 0;
149
 
        mech.parameter = NULL;
 
185
        mech = gp11_mechanism_new (CKM_CAPITALIZE);
150
186
 
151
187
        /* Find the right key */
152
188
        key = find_key (session, CKA_DECRYPT, CKM_CAPITALIZE);
160
196
        g_free (output);
161
197
        
162
198
        /* Full one */
163
 
        output = gp11_session_decrypt_full (session, key, &mech, (const guchar*)"TENNIS instructor", 18, &n_output, NULL, &error);
 
199
        output = gp11_session_decrypt_full (session, key, mech, (const guchar*)"TENNIS instructor", 18, &n_output, NULL, &error);
164
200
        SUCCESS_RES (output, error);
165
201
        g_assert (n_output == 18);
166
202
        g_assert_cmpstr ((gchar*)output, ==, "tennis instructor");
167
203
        g_free (output);
168
204
        
169
205
        /* Asynchronous one */
170
 
        gp11_session_decrypt_async (session, key, &mech, (const guchar*)"FAT CHANCE", 11, NULL, fetch_async_result, &result);
 
206
        gp11_session_decrypt_async (session, key, mech, (const guchar*)"FAT CHANCE", 11, NULL, fetch_async_result, &result);
171
207
 
172
208
        WAIT_UNTIL (result);
173
209
        g_assert (result != NULL);
179
215
        g_assert_cmpstr ((gchar*)output, ==, "fat chance");
180
216
        g_free (output);
181
217
 
 
218
        gp11_mechanism_unref (mech);
182
219
        g_object_unref (result);
183
220
        g_object_unref (key);
184
221
}
207
244
 
208
245
DEFINE_TEST(sign)
209
246
{
210
 
        GP11Mechanism mech;
 
247
        GP11Mechanism *mech;
211
248
        GError *error = NULL;
212
249
        GAsyncResult *result = NULL;
213
250
        GP11Object *key;
214
251
        guchar *output;
215
252
        gsize n_output;
216
253
 
217
 
        mech.type = CKM_PREFIX;
218
 
        mech.n_parameter = 10;
219
 
        mech.parameter = "my-prefix:";
220
 
        
 
254
        mech = gp11_mechanism_new_with_param (CKM_PREFIX, "my-prefix:", 10);
 
255
 
221
256
        /* Enable auto-login on this session, see previous test */
222
257
        gp11_module_set_auto_authenticate (module, TRUE);
223
258
        g_signal_connect (module, "authenticate-object", G_CALLBACK (authenticate_object), NULL);
234
269
        g_free (output);
235
270
        
236
271
        /* Full one */
237
 
        output = gp11_session_sign_full (session, key, &mech, (const guchar*)"Labarbara", 10, &n_output, NULL, &error);
 
272
        output = gp11_session_sign_full (session, key, mech, (const guchar*)"Labarbara", 10, &n_output, NULL, &error);
238
273
        SUCCESS_RES (output, error);
239
274
        g_assert_cmpuint (n_output, ==, 20);
240
275
        g_assert_cmpstr ((gchar*)output, ==, "my-prefix:Labarbara");
241
276
        g_free (output);
242
277
        
243
278
        /* Asynchronous one */
244
 
        gp11_session_sign_async (session, key, &mech, (const guchar*)"Conrad", 7, NULL, fetch_async_result, &result);
 
279
        gp11_session_sign_async (session, key, mech, (const guchar*)"Conrad", 7, NULL, fetch_async_result, &result);
245
280
 
246
281
        WAIT_UNTIL (result);
247
282
        g_assert (result != NULL);
253
288
        g_assert_cmpstr ((gchar*)output, ==, "my-prefix:Conrad");
254
289
        g_free (output);
255
290
 
 
291
        gp11_mechanism_unref (mech);
256
292
        g_object_unref (result);
257
293
        g_object_unref (key);
258
294
}
259
295
 
260
296
DEFINE_TEST(verify)
261
297
{
262
 
        GP11Mechanism mech;
 
298
        GP11Mechanism *mech;
263
299
        GError *error = NULL;
264
300
        GAsyncResult *result = NULL;
265
301
        GP11Object *key;
266
302
        gboolean ret;
267
303
 
268
 
        mech.type = CKM_PREFIX;
269
 
        mech.n_parameter = 10;
270
 
        mech.parameter = "my-prefix:";
271
 
        
 
304
        mech = gp11_mechanism_new_with_param (CKM_PREFIX, "my-prefix:", 10);
 
305
 
272
306
        /* Enable auto-login on this session, shouldn't be needed */
273
307
        gp11_module_set_auto_authenticate (module, TRUE);
274
308
        g_signal_connect (module, "authenticate-object", G_CALLBACK (authenticate_object), NULL);
283
317
        SUCCESS_RES (ret, error);
284
318
        
285
319
        /* Full one */
286
 
        ret = gp11_session_verify_full (session, key, &mech, (const guchar*)"Labarbara", 10, 
 
320
        ret = gp11_session_verify_full (session, key, mech, (const guchar*)"Labarbara", 10,
287
321
                                        (const guchar*)"my-prefix:Labarbara", 20, NULL, &error);
288
322
        SUCCESS_RES (ret, error);
289
323
 
290
324
        /* Failure one */
291
 
        ret = gp11_session_verify_full (session, key, &mech, (const guchar*)"Labarbara", 10, 
 
325
        ret = gp11_session_verify_full (session, key, mech, (const guchar*)"Labarbara", 10,
292
326
                                        (const guchar*)"my-prefix:Loborboro", 20, NULL, &error);
293
327
        FAIL_RES (ret, error);
294
328
 
295
329
        /* Asynchronous one */
296
 
        gp11_session_verify_async (session, key, &mech, (const guchar*)"Labarbara", 10, 
 
330
        gp11_session_verify_async (session, key, mech, (const guchar*)"Labarbara", 10,
297
331
                                   (const guchar*)"my-prefix:Labarbara", 20, NULL, fetch_async_result, &result);
298
332
        WAIT_UNTIL (result);
299
333
        g_assert (result != NULL);
303
337
        
304
338
        /* Asynchronous failure */
305
339
        result = NULL;
306
 
        gp11_session_verify_async (session, key, &mech, (const guchar*)"Labarbara", 10, 
 
340
        gp11_session_verify_async (session, key, mech, (const guchar*)"Labarbara", 10,
307
341
                                   (const guchar*)"my-prefix:Labarxoro", 20, NULL, fetch_async_result, &result);
308
342
        WAIT_UNTIL (result);
309
343
        g_assert (result != NULL);
311
345
        FAIL_RES (ret, error);
312
346
        g_object_unref (result);
313
347
 
 
348
        gp11_mechanism_unref (mech);
314
349
        g_object_unref (key);
315
350
}
 
351
 
 
352
DEFINE_TEST(generate_key_pair)
 
353
{
 
354
        GP11Attributes *pub_attrs, *prv_attrs;
 
355
        GP11Mechanism *mech;
 
356
        GError *error = NULL;
 
357
        GAsyncResult *result = NULL;
 
358
        GP11Object *pub_key, *prv_key;
 
359
        gboolean ret;
 
360
 
 
361
        mech = gp11_mechanism_new_with_param (CKM_GENERATE, "generate", 9);
 
362
 
 
363
        pub_attrs = gp11_attributes_new ();
 
364
        gp11_attributes_add_ulong (pub_attrs, CKA_CLASS, CKO_PUBLIC_KEY);
 
365
        prv_attrs = gp11_attributes_new ();
 
366
        gp11_attributes_add_ulong (prv_attrs, CKA_CLASS, CKO_PRIVATE_KEY);
 
367
 
 
368
        /* Full One*/
 
369
        ret = gp11_session_generate_key_pair_full (session, mech, pub_attrs, prv_attrs,
 
370
                                                   &pub_key, &prv_key, NULL, &error);
 
371
        SUCCESS_RES (ret, error);
 
372
        g_object_unref (pub_key);
 
373
        g_object_unref (prv_key);
 
374
 
 
375
        /* Failure one */
 
376
        mech->type = 0;
 
377
        pub_key = prv_key = NULL;
 
378
        ret = gp11_session_generate_key_pair_full (session, mech, pub_attrs, prv_attrs,
 
379
                                                   &pub_key, &prv_key, NULL, &error);
 
380
        FAIL_RES (ret, error);
 
381
        g_assert (pub_key == NULL);
 
382
        g_assert (prv_key == NULL);
 
383
 
 
384
        /* Asynchronous one */
 
385
        mech->type = CKM_GENERATE;
 
386
        gp11_session_generate_key_pair_async (session, mech, pub_attrs, prv_attrs, NULL, fetch_async_result, &result);
 
387
        WAIT_UNTIL (result);
 
388
        g_assert (result != NULL);
 
389
        ret = gp11_session_generate_key_pair_finish (session, result, &pub_key, &prv_key, &error);
 
390
        SUCCESS_RES (ret, error);
 
391
        g_object_unref (result);
 
392
        g_object_unref (pub_key);
 
393
        g_object_unref (prv_key);
 
394
 
 
395
        /* Asynchronous failure */
 
396
        result = NULL;
 
397
        mech->type = 0;
 
398
        pub_key = prv_key = NULL;
 
399
        gp11_session_generate_key_pair_async (session, mech, pub_attrs, prv_attrs, NULL, fetch_async_result, &result);
 
400
        WAIT_UNTIL (result);
 
401
        g_assert (result != NULL);
 
402
        ret = gp11_session_generate_key_pair_finish (session, result, &pub_key, &prv_key, &error);
 
403
        FAIL_RES (ret, error);
 
404
        g_object_unref (result);
 
405
        g_assert (pub_key == NULL);
 
406
        g_assert (prv_key == NULL);
 
407
 
 
408
        gp11_mechanism_unref (mech);
 
409
        gp11_attributes_unref (pub_attrs);
 
410
        gp11_attributes_unref (prv_attrs);
 
411
}
 
412
 
 
413
DEFINE_TEST(wrap_key)
 
414
{
 
415
        GP11Mechanism *mech;
 
416
        GError *error = NULL;
 
417
        GAsyncResult *result = NULL;
 
418
        GP11Object *wrapper, *wrapped;
 
419
        gpointer output;
 
420
        gsize n_output;
 
421
 
 
422
        mech = gp11_mechanism_new_with_param (CKM_WRAP, "wrap", 4);
 
423
        wrapper = find_key (session, CKA_WRAP, 0);
 
424
        wrapped = find_key_with_value (session, "value");
 
425
 
 
426
        /* Simple One */
 
427
        output = gp11_session_wrap_key (session, wrapper, CKM_WRAP, wrapped, &n_output, &error);
 
428
        SUCCESS_RES (output, error);
 
429
        g_assert (output);
 
430
        g_assert_cmpsize (n_output, ==, 5);
 
431
        g_assert (memcmp (output, "value", 5) == 0);
 
432
        g_free (output);
 
433
 
 
434
        /* Full One*/
 
435
        output = gp11_session_wrap_key_full (session, wrapper, mech, wrapped, &n_output, NULL, &error);
 
436
        SUCCESS_RES (output, error);
 
437
        g_assert_cmpsize (n_output, ==, 5);
 
438
        g_assert (memcmp (output, "value", 5) == 0);
 
439
        g_free (output);
 
440
 
 
441
        /* Failure one */
 
442
        mech->type = 0;
 
443
        n_output = 0;
 
444
        output = gp11_session_wrap_key_full (session, wrapper, mech, wrapped, &n_output, NULL, &error);
 
445
        FAIL_RES (output, error);
 
446
        g_assert_cmpsize (n_output, ==, 0);
 
447
 
 
448
        /* Asynchronous one */
 
449
        mech->type = CKM_WRAP;
 
450
        gp11_session_wrap_key_async (session, wrapper, mech, wrapped, NULL, fetch_async_result, &result);
 
451
        WAIT_UNTIL (result);
 
452
        g_assert (result != NULL);
 
453
        output = gp11_session_wrap_key_finish (session, result, &n_output, &error);
 
454
        SUCCESS_RES (output, error);
 
455
        g_assert_cmpsize (n_output, ==, 5);
 
456
        g_assert (memcmp (output, "value", 5) == 0);
 
457
        g_object_unref (result);
 
458
        g_free (output);
 
459
 
 
460
        /* Asynchronous failure */
 
461
        result = NULL;
 
462
        mech->type = 0;
 
463
        n_output = 0;
 
464
        gp11_session_wrap_key_async (session, wrapper, mech, wrapped, NULL, fetch_async_result, &result);
 
465
        WAIT_UNTIL (result);
 
466
        g_assert (result != NULL);
 
467
        output = gp11_session_wrap_key_finish (session, result, &n_output, &error);
 
468
        FAIL_RES (output, error);
 
469
        g_assert_cmpsize (n_output, ==, 0);
 
470
        g_object_unref (result);
 
471
 
 
472
        g_object_unref (wrapper);
 
473
        g_object_unref (wrapped);
 
474
        gp11_mechanism_unref (mech);
 
475
}
 
476
 
 
477
DEFINE_TEST(unwrap_key)
 
478
{
 
479
        GP11Mechanism *mech;
 
480
        GError *error = NULL;
 
481
        GAsyncResult *result = NULL;
 
482
        GP11Object *wrapper, *unwrapped;
 
483
        GP11Attributes *attrs;
 
484
 
 
485
        mech = gp11_mechanism_new_with_param (CKM_WRAP, "wrap", 4);
 
486
        wrapper = find_key (session, CKA_UNWRAP, 0);
 
487
        attrs = gp11_attributes_newv (CKA_CLASS, GP11_ULONG, CKO_SECRET_KEY, GP11_INVALID);
 
488
 
 
489
        /* Simple One */
 
490
        unwrapped = gp11_session_unwrap_key (session, wrapper, CKM_WRAP, "special", 7, &error,
 
491
                                             CKA_CLASS, GP11_ULONG, CKO_SECRET_KEY, GP11_INVALID);
 
492
        SUCCESS_RES (unwrapped, error);
 
493
        g_assert (GP11_IS_OBJECT (unwrapped));
 
494
        check_key_with_value (session, unwrapped, CKO_SECRET_KEY, "special");
 
495
        g_object_unref (unwrapped);
 
496
 
 
497
        /* Full One*/
 
498
        unwrapped = gp11_session_unwrap_key_full (session, wrapper, mech, "special", 7, attrs, NULL, &error);
 
499
        SUCCESS_RES (unwrapped, error);
 
500
        g_assert (GP11_IS_OBJECT (unwrapped));
 
501
        check_key_with_value (session, unwrapped, CKO_SECRET_KEY, "special");
 
502
        g_object_unref (unwrapped);
 
503
 
 
504
        /* Failure one */
 
505
        mech->type = 0;
 
506
        unwrapped = gp11_session_unwrap_key_full (session, wrapper, mech, "special", 7, attrs, NULL, &error);
 
507
        FAIL_RES (unwrapped, error);
 
508
 
 
509
        /* Asynchronous one */
 
510
        mech->type = CKM_WRAP;
 
511
        gp11_session_unwrap_key_async (session, wrapper, mech, "special", 7, attrs, NULL, fetch_async_result, &result);
 
512
        WAIT_UNTIL (result);
 
513
        g_assert (result != NULL);
 
514
        unwrapped = gp11_session_unwrap_key_finish (session, result, &error);
 
515
        SUCCESS_RES (unwrapped, error);
 
516
        g_assert (GP11_IS_OBJECT (unwrapped));
 
517
        check_key_with_value (session, unwrapped, CKO_SECRET_KEY, "special");
 
518
        g_object_unref (unwrapped);
 
519
        g_object_unref (result);
 
520
 
 
521
        /* Asynchronous failure */
 
522
        result = NULL;
 
523
        mech->type = 0;
 
524
        gp11_session_unwrap_key_async (session, wrapper, mech, "special", 6, attrs, NULL, fetch_async_result, &result);
 
525
        WAIT_UNTIL (result);
 
526
        g_assert (result != NULL);
 
527
        unwrapped = gp11_session_unwrap_key_finish (session, result, &error);
 
528
        FAIL_RES (unwrapped, error);
 
529
        g_object_unref (result);
 
530
 
 
531
        g_object_unref (wrapper);
 
532
        gp11_attributes_unref (attrs);
 
533
        gp11_mechanism_unref (mech);
 
534
}
 
535
 
 
536
DEFINE_TEST(derive_key)
 
537
{
 
538
        GP11Mechanism *mech;
 
539
        GError *error = NULL;
 
540
        GAsyncResult *result = NULL;
 
541
        GP11Object *wrapper, *derived;
 
542
        GP11Attributes *attrs;
 
543
 
 
544
        mech = gp11_mechanism_new_with_param (CKM_DERIVE, "derive", 6);
 
545
        wrapper = find_key (session, CKA_DERIVE, 0);
 
546
        attrs = gp11_attributes_newv (CKA_CLASS, GP11_ULONG, CKO_SECRET_KEY, GP11_INVALID);
 
547
 
 
548
        /* Simple One */
 
549
        derived = gp11_session_derive_key (session, wrapper, CKM_DERIVE, &error,
 
550
                                           CKA_CLASS, GP11_ULONG, CKO_SECRET_KEY, GP11_INVALID);
 
551
        SUCCESS_RES (derived, error);
 
552
        g_assert (GP11_IS_OBJECT (derived));
 
553
g_printerr ("derived is: %lu", gp11_object_get_handle (derived));
 
554
        check_key_with_value (session, derived, CKO_SECRET_KEY, "derived");
 
555
        g_object_unref (derived);
 
556
 
 
557
        /* Full One*/
 
558
        derived = gp11_session_derive_key_full (session, wrapper, mech, attrs, NULL, &error);
 
559
        SUCCESS_RES (derived, error);
 
560
        g_assert (GP11_IS_OBJECT (derived));
 
561
        check_key_with_value (session, derived, CKO_SECRET_KEY, "derived");
 
562
        g_object_unref (derived);
 
563
 
 
564
        /* Failure one */
 
565
        mech->type = 0;
 
566
        derived = gp11_session_derive_key_full (session, wrapper, mech, attrs, NULL, &error);
 
567
        FAIL_RES (derived, error);
 
568
 
 
569
        /* Asynchronous one */
 
570
        mech->type = CKM_DERIVE;
 
571
        gp11_session_derive_key_async (session, wrapper, mech, attrs, NULL, fetch_async_result, &result);
 
572
        WAIT_UNTIL (result);
 
573
        g_assert (result != NULL);
 
574
        derived = gp11_session_derive_key_finish (session, result, &error);
 
575
        SUCCESS_RES (derived, error);
 
576
        g_assert (GP11_IS_OBJECT (derived));
 
577
        check_key_with_value (session, derived, CKO_SECRET_KEY, "derived");
 
578
        g_object_unref (derived);
 
579
        g_object_unref (result);
 
580
 
 
581
        /* Asynchronous failure */
 
582
        result = NULL;
 
583
        mech->type = 0;
 
584
        gp11_session_derive_key_async (session, wrapper, mech, attrs, NULL, fetch_async_result, &result);
 
585
        WAIT_UNTIL (result);
 
586
        g_assert (result != NULL);
 
587
        derived = gp11_session_derive_key_finish (session, result, &error);
 
588
        FAIL_RES (derived, error);
 
589
        g_object_unref (result);
 
590
 
 
591
        g_object_unref (wrapper);
 
592
        gp11_attributes_unref (attrs);
 
593
        gp11_mechanism_unref (mech);
 
594
}