2 * GnuTLS PKCS#11 support
3 * Copyright (C) 2010-2012 Free Software Foundation, Inc.
5 * Author: Nikos Mavrogiannopoulos
7 * The GnuTLS is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 3 of
10 * the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>
21 #include <gnutls_int.h>
22 #include <gnutls/pkcs11.h>
25 #include <gnutls_errors.h>
26 #include <gnutls_datum.h>
27 #include <pkcs11_int.h>
28 #include <gnutls/abstract.h>
29 #include <gnutls_pk.h>
31 #include <openpgp/openpgp_int.h>
32 #include <openpgp/gnutls_openpgp.h>
33 #include <gnutls_sig.h>
34 #include <abstract_int.h>
36 struct gnutls_privkey_st
38 gnutls_privkey_type_t type
;
39 gnutls_pk_algorithm_t pk_algorithm
;
43 gnutls_x509_privkey_t x509
;
45 gnutls_pkcs11_privkey_t pkcs11
;
48 gnutls_openpgp_privkey_t openpgp
;
51 gnutls_privkey_sign_func sign_func
;
52 gnutls_privkey_decrypt_func decrypt_func
;
53 gnutls_privkey_deinit_func deinit_func
;
62 * gnutls_privkey_get_type:
63 * @key: should contain a #gnutls_privkey_t structure
65 * This function will return the type of the private key. This is
66 * actually the type of the subsystem used to set this private key.
68 * Returns: a member of the #gnutls_privkey_type_t enumeration on
69 * success, or a negative error code on error.
74 gnutls_privkey_get_type (gnutls_privkey_t key
)
80 * gnutls_privkey_get_pk_algorithm:
81 * @key: should contain a #gnutls_privkey_t structure
82 * @bits: If set will return the number of bits of the parameters (may be NULL)
84 * This function will return the public key algorithm of a private
85 * key and if possible will return a number of bits that indicates
86 * the security parameter of the key.
88 * Returns: a member of the #gnutls_pk_algorithm_t enumeration on
89 * success, or a negative error code on error.
94 gnutls_privkey_get_pk_algorithm (gnutls_privkey_t key
, unsigned int *bits
)
99 case GNUTLS_PRIVKEY_OPENPGP
:
100 return gnutls_openpgp_privkey_get_pk_algorithm (key
->key
.openpgp
, bits
);
103 case GNUTLS_PRIVKEY_PKCS11
:
104 return gnutls_pkcs11_privkey_get_pk_algorithm (key
->key
.pkcs11
, bits
);
106 case GNUTLS_PRIVKEY_X509
:
108 *bits
= _gnutls_mpi_get_nbits (key
->key
.x509
->params
.params
[0]);
109 return gnutls_x509_privkey_get_pk_algorithm (key
->key
.x509
);
110 case GNUTLS_PRIVKEY_EXT
:
113 return key
->pk_algorithm
;
116 return GNUTLS_E_INVALID_REQUEST
;
122 privkey_to_pubkey (gnutls_pk_algorithm_t pk
,
123 const gnutls_pk_params_st
* priv
,
124 gnutls_pk_params_st
* pub
)
131 pub
->params
[0] = _gnutls_mpi_copy (priv
->params
[0]);
132 pub
->params
[1] = _gnutls_mpi_copy (priv
->params
[1]);
134 pub
->params_nr
= RSA_PUBLIC_PARAMS
;
136 if (pub
->params
[0] == NULL
|| pub
->params
[1] == NULL
)
139 ret
= GNUTLS_E_MEMORY_ERROR
;
145 pub
->params
[0] = _gnutls_mpi_copy (priv
->params
[0]);
146 pub
->params
[1] = _gnutls_mpi_copy (priv
->params
[1]);
147 pub
->params
[2] = _gnutls_mpi_copy (priv
->params
[2]);
148 pub
->params
[3] = _gnutls_mpi_copy (priv
->params
[3]);
150 pub
->params_nr
= DSA_PUBLIC_PARAMS
;
152 if (pub
->params
[0] == NULL
|| pub
->params
[1] == NULL
||
153 pub
->params
[2] == NULL
|| pub
->params
[3] == NULL
)
156 ret
= GNUTLS_E_MEMORY_ERROR
;
162 pub
->params
[0] = _gnutls_mpi_copy (priv
->params
[0]);
163 pub
->params
[1] = _gnutls_mpi_copy (priv
->params
[1]);
164 pub
->params
[2] = _gnutls_mpi_copy (priv
->params
[2]);
165 pub
->params
[3] = _gnutls_mpi_copy (priv
->params
[3]);
166 pub
->params
[4] = _gnutls_mpi_copy (priv
->params
[4]);
167 pub
->params
[5] = _gnutls_mpi_copy (priv
->params
[5]);
168 pub
->params
[6] = _gnutls_mpi_copy (priv
->params
[6]);
169 pub
->params
[7] = _gnutls_mpi_copy (priv
->params
[7]);
171 pub
->params_nr
= ECC_PUBLIC_PARAMS
;
172 pub
->flags
= priv
->flags
;
174 if (pub
->params
[0] == NULL
|| pub
->params
[1] == NULL
||
175 pub
->params
[2] == NULL
|| pub
->params
[3] == NULL
||
176 pub
->params
[4] == NULL
|| pub
->params
[5] == NULL
||
177 pub
->params
[6] == NULL
|| pub
->params
[7] == NULL
)
180 ret
= GNUTLS_E_MEMORY_ERROR
;
187 return GNUTLS_E_INVALID_REQUEST
;
192 gnutls_pk_params_release(pub
);
197 /* Returns the public key of the private key (if possible)
200 _gnutls_privkey_get_public_mpis (gnutls_privkey_t key
,
201 gnutls_pk_params_st
* params
)
204 gnutls_pk_algorithm_t pk
= gnutls_privkey_get_pk_algorithm (key
, NULL
);
208 #ifdef ENABLE_OPENPGP
209 case GNUTLS_PRIVKEY_OPENPGP
:
211 gnutls_pk_params_st tmp_params
;
213 uint8_t keyid
[GNUTLS_OPENPGP_KEYID_SIZE
];
216 gnutls_openpgp_privkey_get_preferred_key_id (key
->key
.openpgp
,
220 KEYID_IMPORT (kid
, keyid
);
221 ret
= _gnutls_openpgp_privkey_get_mpis (key
->key
.openpgp
, kid
,
225 ret
= _gnutls_openpgp_privkey_get_mpis (key
->key
.openpgp
, NULL
,
234 ret
= privkey_to_pubkey (pk
,
238 gnutls_pk_params_release(&tmp_params
);
243 case GNUTLS_PRIVKEY_X509
:
244 ret
= privkey_to_pubkey (pk
,
245 &key
->key
.x509
->params
,
250 return GNUTLS_E_INVALID_REQUEST
;
257 * gnutls_privkey_init:
258 * @key: The structure to be initialized
260 * This function will initialize an private key structure.
262 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
263 * negative error value.
268 gnutls_privkey_init (gnutls_privkey_t
* key
)
270 *key
= gnutls_calloc (1, sizeof (struct gnutls_privkey_st
));
274 return GNUTLS_E_MEMORY_ERROR
;
281 * gnutls_privkey_deinit:
282 * @key: The structure to be deinitialized
284 * This function will deinitialize a private key structure.
289 gnutls_privkey_deinit (gnutls_privkey_t key
)
291 if (key
== NULL
) return;
293 if (key
->flags
& GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE
|| key
->flags
& GNUTLS_PRIVKEY_IMPORT_COPY
)
296 #ifdef ENABLE_OPENPGP
297 case GNUTLS_PRIVKEY_OPENPGP
:
298 gnutls_openpgp_privkey_deinit (key
->key
.openpgp
);
302 case GNUTLS_PRIVKEY_PKCS11
:
303 gnutls_pkcs11_privkey_deinit (key
->key
.pkcs11
);
306 case GNUTLS_PRIVKEY_X509
:
307 gnutls_x509_privkey_deinit (key
->key
.x509
);
309 case GNUTLS_PRIVKEY_EXT
:
310 if (key
->key
.ext
.deinit_func
!= NULL
)
311 key
->key
.ext
.deinit_func(key
, key
->key
.ext
.userdata
);
319 /* will fail if the private key contains an actual key.
321 static int check_if_clean(gnutls_privkey_t key
)
324 return GNUTLS_E_INVALID_REQUEST
;
332 * gnutls_privkey_import_pkcs11:
333 * @pkey: The private key
334 * @key: The private key to be imported
335 * @flags: Flags for the import
337 * This function will import the given private key to the abstract
338 * #gnutls_privkey_t structure.
340 * The #gnutls_pkcs11_privkey_t object must not be deallocated
341 * during the lifetime of this structure.
343 * @flags might be zero or one of %GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE
344 * and %GNUTLS_PRIVKEY_IMPORT_COPY.
346 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
347 * negative error value.
352 gnutls_privkey_import_pkcs11 (gnutls_privkey_t pkey
,
353 gnutls_pkcs11_privkey_t key
, unsigned int flags
)
357 ret
= check_if_clean(pkey
);
364 if (flags
& GNUTLS_PRIVKEY_IMPORT_COPY
)
365 return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST
);
367 pkey
->key
.pkcs11
= key
;
368 pkey
->type
= GNUTLS_PRIVKEY_PKCS11
;
369 pkey
->pk_algorithm
= gnutls_pkcs11_privkey_get_pk_algorithm (key
, NULL
);
375 #endif /* ENABLE_PKCS11 */
378 * gnutls_privkey_import_ext:
379 * @pkey: The private key
380 * @pk: The public key algorithm
381 * @userdata: private data to be provided to the callbacks
382 * @sign_func: callback for signature operations
383 * @decrypt_func: callback for decryption operations
384 * @flags: Flags for the import
386 * This function will associate the given callbacks with the
387 * #gnutls_privkey_t structure. At least one of the two callbacks
390 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
391 * negative error value.
396 gnutls_privkey_import_ext (gnutls_privkey_t pkey
,
397 gnutls_pk_algorithm_t pk
,
399 gnutls_privkey_sign_func sign_func
,
400 gnutls_privkey_decrypt_func decrypt_func
,
405 ret
= check_if_clean(pkey
);
412 if (sign_func
== NULL
&& decrypt_func
== NULL
)
413 return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST
);
415 pkey
->key
.ext
.sign_func
= sign_func
;
416 pkey
->key
.ext
.decrypt_func
= decrypt_func
;
417 pkey
->key
.ext
.deinit_func
= NULL
;
418 pkey
->key
.ext
.userdata
= userdata
;
419 pkey
->type
= GNUTLS_PRIVKEY_EXT
;
420 pkey
->pk_algorithm
= pk
;
427 * gnutls_privkey_import_ext2:
428 * @pkey: The private key
429 * @pk: The public key algorithm
430 * @userdata: private data to be provided to the callbacks
431 * @sign_func: callback for signature operations
432 * @decrypt_func: callback for decryption operations
433 * @deinit_func: a deinitialization function
434 * @flags: Flags for the import
436 * This function will associate the given callbacks with the
437 * #gnutls_privkey_t structure. At least one of the two callbacks
440 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
441 * negative error value.
446 gnutls_privkey_import_ext2 (gnutls_privkey_t pkey
,
447 gnutls_pk_algorithm_t pk
,
449 gnutls_privkey_sign_func sign_func
,
450 gnutls_privkey_decrypt_func decrypt_func
,
451 gnutls_privkey_deinit_func deinit_func
,
456 ret
= check_if_clean(pkey
);
463 if (sign_func
== NULL
&& decrypt_func
== NULL
)
464 return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST
);
466 pkey
->key
.ext
.sign_func
= sign_func
;
467 pkey
->key
.ext
.decrypt_func
= decrypt_func
;
468 pkey
->key
.ext
.deinit_func
= deinit_func
;
469 pkey
->key
.ext
.userdata
= userdata
;
470 pkey
->type
= GNUTLS_PRIVKEY_EXT
;
471 pkey
->pk_algorithm
= pk
;
478 * gnutls_privkey_import_x509:
479 * @pkey: The private key
480 * @key: The private key to be imported
481 * @flags: Flags for the import
483 * This function will import the given private key to the abstract
484 * #gnutls_privkey_t structure.
486 * The #gnutls_x509_privkey_t object must not be deallocated
487 * during the lifetime of this structure.
489 * @flags might be zero or one of %GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE
490 * and %GNUTLS_PRIVKEY_IMPORT_COPY.
492 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
493 * negative error value.
498 gnutls_privkey_import_x509 (gnutls_privkey_t pkey
,
499 gnutls_x509_privkey_t key
, unsigned int flags
)
503 ret
= check_if_clean(pkey
);
510 if (flags
& GNUTLS_PRIVKEY_IMPORT_COPY
)
512 ret
= gnutls_x509_privkey_init(&pkey
->key
.x509
);
514 return gnutls_assert_val(ret
);
516 ret
= gnutls_x509_privkey_cpy(pkey
->key
.x509
, key
);
519 gnutls_x509_privkey_deinit(pkey
->key
.x509
);
520 return gnutls_assert_val(ret
);
524 pkey
->key
.x509
= key
;
526 pkey
->type
= GNUTLS_PRIVKEY_X509
;
527 pkey
->pk_algorithm
= gnutls_x509_privkey_get_pk_algorithm (key
);
533 #ifdef ENABLE_OPENPGP
535 * gnutls_privkey_import_openpgp:
536 * @pkey: The private key
537 * @key: The private key to be imported
538 * @flags: Flags for the import
540 * This function will import the given private key to the abstract
541 * #gnutls_privkey_t structure.
543 * The #gnutls_openpgp_privkey_t object must not be deallocated
544 * during the lifetime of this structure. The subkey set as
545 * preferred will be used, or the master key otherwise.
547 * @flags might be zero or one of %GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE
548 * and %GNUTLS_PRIVKEY_IMPORT_COPY.
550 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
551 * negative error value.
556 gnutls_privkey_import_openpgp (gnutls_privkey_t pkey
,
557 gnutls_openpgp_privkey_t key
,
561 uint8_t keyid
[GNUTLS_OPENPGP_KEYID_SIZE
];
563 ret
= check_if_clean(pkey
);
570 if (flags
& GNUTLS_PRIVKEY_IMPORT_COPY
)
572 ret
= gnutls_openpgp_privkey_init(&pkey
->key
.openpgp
);
574 return gnutls_assert_val(ret
);
576 ret
= _gnutls_openpgp_privkey_cpy(pkey
->key
.openpgp
, key
);
579 gnutls_openpgp_privkey_deinit(pkey
->key
.openpgp
);
580 return gnutls_assert_val(ret
);
584 pkey
->key
.openpgp
= key
;
586 pkey
->type
= GNUTLS_PRIVKEY_OPENPGP
;
588 ret
= gnutls_openpgp_privkey_get_preferred_key_id (key
, keyid
);
589 if (ret
== GNUTLS_E_OPENPGP_PREFERRED_KEY_ERROR
)
591 pkey
->pk_algorithm
= gnutls_openpgp_privkey_get_pk_algorithm(key
, NULL
);
596 return gnutls_assert_val(ret
);
598 idx
= gnutls_openpgp_privkey_get_subkey_idx (key
, keyid
);
600 pkey
->pk_algorithm
= gnutls_openpgp_privkey_get_subkey_pk_algorithm (key
, idx
, NULL
);
610 * gnutls_privkey_sign_data:
611 * @signer: Holds the key
612 * @hash: should be a digest algorithm
613 * @flags: should be 0 for now
614 * @data: holds the data to be signed
615 * @signature: will contain the signature allocate with gnutls_malloc()
617 * This function will sign the given data using a signature algorithm
618 * supported by the private key. Signature algorithms are always used
619 * together with a hash functions. Different hash functions may be
620 * used for the RSA algorithm, but only the SHA family for the DSA keys.
622 * You may use gnutls_pubkey_get_preferred_hash_algorithm() to determine
623 * the hash algorithm.
625 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
626 * negative error value.
631 gnutls_privkey_sign_data (gnutls_privkey_t signer
,
632 gnutls_digest_algorithm_t hash
,
634 const gnutls_datum_t
* data
,
635 gnutls_datum_t
* signature
)
638 gnutls_datum_t digest
;
640 ret
= pk_hash_data (signer
->pk_algorithm
, hash
, NULL
, data
, &digest
);
647 ret
= pk_prepare_hash (signer
->pk_algorithm
, hash
, &digest
);
654 ret
= _gnutls_privkey_sign_hash (signer
, &digest
, signature
);
655 _gnutls_free_datum (&digest
);
666 _gnutls_free_datum (&digest
);
671 * gnutls_privkey_sign_hash:
672 * @signer: Holds the signer's key
673 * @hash_algo: The hash algorithm used
674 * @flags: zero for now
675 * @hash_data: holds the data to be signed
676 * @signature: will contain newly allocated signature
678 * This function will sign the given hashed data using a signature algorithm
679 * supported by the private key. Signature algorithms are always used
680 * together with a hash functions. Different hash functions may be
681 * used for the RSA algorithm, but only SHA-XXX for the DSA keys.
683 * You may use gnutls_pubkey_get_preferred_hash_algorithm() to determine
684 * the hash algorithm.
686 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
687 * negative error value.
692 gnutls_privkey_sign_hash (gnutls_privkey_t signer
,
693 gnutls_digest_algorithm_t hash_algo
,
695 const gnutls_datum_t
* hash_data
,
696 gnutls_datum_t
* signature
)
699 gnutls_datum_t digest
;
701 digest
.data
= gnutls_malloc (hash_data
->size
);
702 if (digest
.data
== NULL
)
705 return GNUTLS_E_MEMORY_ERROR
;
707 digest
.size
= hash_data
->size
;
708 memcpy (digest
.data
, hash_data
->data
, digest
.size
);
710 ret
= pk_prepare_hash (signer
->pk_algorithm
, hash_algo
, &digest
);
717 ret
= _gnutls_privkey_sign_hash (signer
, &digest
, signature
);
727 _gnutls_free_datum (&digest
);
732 * _gnutls_privkey_sign_hash:
733 * @key: Holds the key
734 * @data: holds the data to be signed
735 * @signature: will contain the signature allocate with gnutls_malloc()
737 * This function will sign the given data using a signature algorithm
738 * supported by the private key.
740 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
741 * negative error value.
744 _gnutls_privkey_sign_hash (gnutls_privkey_t key
,
745 const gnutls_datum_t
* hash
,
746 gnutls_datum_t
* signature
)
750 #ifdef ENABLE_OPENPGP
751 case GNUTLS_PRIVKEY_OPENPGP
:
752 return gnutls_openpgp_privkey_sign_hash (key
->key
.openpgp
,
756 case GNUTLS_PRIVKEY_PKCS11
:
757 return _gnutls_pkcs11_privkey_sign_hash (key
->key
.pkcs11
,
760 case GNUTLS_PRIVKEY_X509
:
761 return _gnutls_pk_sign (key
->key
.x509
->pk_algorithm
,
762 signature
, hash
, &key
->key
.x509
->params
);
763 case GNUTLS_PRIVKEY_EXT
:
764 if (key
->key
.ext
.sign_func
== NULL
)
765 return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST
);
766 return key
->key
.ext
.sign_func(key
, key
->key
.ext
.userdata
, hash
, signature
);
769 return GNUTLS_E_INVALID_REQUEST
;
774 * gnutls_privkey_decrypt_data:
775 * @key: Holds the key
776 * @flags: zero for now
777 * @ciphertext: holds the data to be decrypted
778 * @plaintext: will contain the decrypted data, allocated with gnutls_malloc()
780 * This function will decrypt the given data using the algorithm
781 * supported by the private key.
783 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
784 * negative error value.
789 gnutls_privkey_decrypt_data (gnutls_privkey_t key
,
791 const gnutls_datum_t
* ciphertext
,
792 gnutls_datum_t
* plaintext
)
796 #ifdef ENABLE_OPENPGP
797 case GNUTLS_PRIVKEY_OPENPGP
:
798 return _gnutls_openpgp_privkey_decrypt_data (key
->key
.openpgp
, flags
,
799 ciphertext
, plaintext
);
801 case GNUTLS_PRIVKEY_X509
:
802 return _gnutls_pk_decrypt (key
->pk_algorithm
, plaintext
, ciphertext
,
803 &key
->key
.x509
->params
);
805 case GNUTLS_PRIVKEY_PKCS11
:
806 return _gnutls_pkcs11_privkey_decrypt_data (key
->key
.pkcs11
,
808 ciphertext
, plaintext
);
810 case GNUTLS_PRIVKEY_EXT
:
811 if (key
->key
.ext
.decrypt_func
== NULL
)
812 return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST
);
814 return key
->key
.ext
.decrypt_func(key
, key
->key
.ext
.userdata
, ciphertext
, plaintext
);
817 return GNUTLS_E_INVALID_REQUEST
;
822 * gnutls_privkey_import_x509_raw:
823 * @pkey: The private key
824 * @data: The private key data to be imported
825 * @format: The format of the private key
826 * @password: A password (optional)
828 * This function will import the given private key to the abstract
829 * #gnutls_privkey_t structure.
831 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
832 * negative error value.
836 int gnutls_privkey_import_x509_raw (gnutls_privkey_t pkey
,
837 const gnutls_datum_t
* data
,
838 gnutls_x509_crt_fmt_t format
,
839 const char* password
)
841 gnutls_x509_privkey_t xpriv
;
844 ret
= gnutls_x509_privkey_init(&xpriv
);
846 return gnutls_assert_val(ret
);
848 ret
= gnutls_x509_privkey_import2(xpriv
, data
, format
, password
);
855 ret
= gnutls_privkey_import_x509(pkey
, xpriv
, GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE
);
865 gnutls_x509_privkey_deinit(xpriv
);
871 * gnutls_privkey_import_openpgp_raw:
872 * @pkey: The private key
873 * @data: The private key data to be imported
874 * @format: The format of the private key
875 * @keyid: The key id to use (optional)
876 * @password: A password (optional)
878 * This function will import the given private key to the abstract
879 * #gnutls_privkey_t structure.
881 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
882 * negative error value.
886 int gnutls_privkey_import_openpgp_raw (gnutls_privkey_t pkey
,
887 const gnutls_datum_t
* data
,
888 gnutls_openpgp_crt_fmt_t format
,
889 const gnutls_openpgp_keyid_t keyid
,
890 const char* password
)
892 gnutls_openpgp_privkey_t xpriv
;
895 ret
= gnutls_openpgp_privkey_init(&xpriv
);
897 return gnutls_assert_val(ret
);
899 ret
= gnutls_openpgp_privkey_import(xpriv
, data
, format
, password
, 0);
908 ret
= gnutls_openpgp_privkey_set_preferred_key_id(xpriv
, keyid
);
916 ret
= gnutls_privkey_import_openpgp(pkey
, xpriv
, GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE
);
926 gnutls_openpgp_privkey_deinit(xpriv
);
932 * gnutls_privkey_import_pkcs11_url:
933 * @key: A key of type #gnutls_pubkey_t
934 * @url: A PKCS 11 url
935 * @flags: One of GNUTLS_PKCS11_OBJ_* flags
937 * This function will import a PKCS 11 certificate to a #gnutls_pubkey_t
940 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
941 * negative error value.
946 gnutls_privkey_import_pkcs11_url (gnutls_privkey_t key
, const char *url
)
948 gnutls_pkcs11_privkey_t pkey
;
951 ret
= gnutls_pkcs11_privkey_init (&pkey
);
958 ret
= gnutls_pkcs11_privkey_import_url (pkey
, url
, 0);
965 ret
= gnutls_privkey_import_pkcs11 (key
, pkey
, GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE
);
975 gnutls_pkcs11_privkey_deinit (pkey
);