2 * Copyright (C) 2002-2012 Free Software Foundation, Inc.
4 * Author: Timo Schulz, Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 /* Compatibility functions on OpenPGP key parsing.
26 #include <gnutls_int.h>
27 #include <gnutls_errors.h>
28 #include <gnutls_openpgp.h>
29 #include <openpgp_int.h>
32 * gnutls_openpgp_verify_key:
33 * @hostname: the name of the certificate holder
34 * @cert_list: the structure that holds the certificates.
35 * @cert_list_lenght: the items in the cert_list.
36 * @status: the output of the verification function
38 * Verify all signatures in the certificate list. When the key
39 * is not available, the signature is skipped.
41 * The return value is one of the CertificateStatus entries.
43 * NOTE: this function does not verify using any "web of trust". You
44 * may use GnuPG for that purpose, or any other external PGP application.
47 _gnutls_openpgp_verify_key (const gnutls_certificate_credentials_t cred
,
49 const gnutls_datum_t
* cert_list
,
50 int cert_list_length
, unsigned int *status
)
53 gnutls_openpgp_crt_t key
= NULL
;
54 unsigned int verify
= 0, verify_self
= 0;
56 if (!cert_list
|| cert_list_length
!= 1)
59 return GNUTLS_E_NO_CERTIFICATE_FOUND
;
62 ret
= gnutls_openpgp_crt_init (&key
);
70 gnutls_openpgp_crt_import (key
, &cert_list
[0], GNUTLS_OPENPGP_FMT_RAW
);
77 if (cred
->keyring
!= NULL
)
79 ret
= gnutls_openpgp_crt_verify_ring (key
, cred
->keyring
, 0, &verify
);
87 /* Now try the self signature. */
88 ret
= gnutls_openpgp_crt_verify_self (key
, 0, &verify_self
);
95 *status
= verify_self
| verify
;
97 /* If we only checked the self signature. */
99 *status
|= GNUTLS_CERT_SIGNER_NOT_FOUND
;
103 ret
= gnutls_openpgp_crt_check_hostname(key
, hostname
);
105 *status
|= GNUTLS_CERT_UNEXPECTED_OWNER
;
111 gnutls_openpgp_crt_deinit (key
);
117 * gnutls_openpgp_fingerprint:
118 * @cert: the raw data that contains the OpenPGP public key.
119 * @fpr: the buffer to save the fingerprint.
120 * @fprlen: the integer to save the length of the fingerprint.
122 * Returns the fingerprint of the OpenPGP key. Depence on the algorithm,
123 * the fingerprint can be 16 or 20 bytes.
126 _gnutls_openpgp_fingerprint (const gnutls_datum_t
* cert
,
127 unsigned char *fpr
, size_t * fprlen
)
129 gnutls_openpgp_crt_t key
;
132 ret
= gnutls_openpgp_crt_init (&key
);
139 ret
= gnutls_openpgp_crt_import (key
, cert
, GNUTLS_OPENPGP_FMT_RAW
);
146 ret
= gnutls_openpgp_crt_get_fingerprint (key
, fpr
, fprlen
);
147 gnutls_openpgp_crt_deinit (key
);
158 * gnutls_openpgp_get_raw_key_creation_time:
159 * @cert: the raw data that contains the OpenPGP public key.
161 * Returns the timestamp when the OpenPGP key was created.
164 _gnutls_openpgp_get_raw_key_creation_time (const gnutls_datum_t
* cert
)
166 gnutls_openpgp_crt_t key
;
170 ret
= gnutls_openpgp_crt_init (&key
);
177 ret
= gnutls_openpgp_crt_import (key
, cert
, GNUTLS_OPENPGP_FMT_RAW
);
184 tim
= gnutls_openpgp_crt_get_creation_time (key
);
186 gnutls_openpgp_crt_deinit (key
);
193 * gnutls_openpgp_get_raw_key_expiration_time:
194 * @cert: the raw data that contains the OpenPGP public key.
196 * Returns the time when the OpenPGP key expires. A value of '0' means
197 * that the key doesn't expire at all.
200 _gnutls_openpgp_get_raw_key_expiration_time (const gnutls_datum_t
* cert
)
202 gnutls_openpgp_crt_t key
;
206 ret
= gnutls_openpgp_crt_init (&key
);
213 ret
= gnutls_openpgp_crt_import (key
, cert
, GNUTLS_OPENPGP_FMT_RAW
);
220 tim
= gnutls_openpgp_crt_get_expiration_time (key
);
222 gnutls_openpgp_crt_deinit (key
);