first commit
Some checks failed
/ buid (push) Has been cancelled

This commit is contained in:
2026-04-16 14:48:09 +07:00
commit 4b968a3347
5625 changed files with 1685474 additions and 0 deletions

View File

@ -0,0 +1,686 @@
/*
* Copyright (C) 2010-2012 Free Software Foundation, Inc.
* Copyright (C) 2015-2017 Red Hat, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLS_ABSTRACT_H
#define GNUTLS_ABSTRACT_H
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#include <gnutls/pkcs11.h>
#include <gnutls/openpgp.h>
#include <gnutls/tpm.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Public key operations */
#define GNUTLS_PUBKEY_VERIFY_FLAG_TLS_RSA GNUTLS_PUBKEY_VERIFY_FLAG_TLS1_RSA
/**
* gnutls_pubkey_flags:
* @GNUTLS_PUBKEY_DISABLE_CALLBACKS: The following flag disables call to PIN callbacks. Only
* relevant to TPM keys.
* @GNUTLS_PUBKEY_GET_OPENPGP_FINGERPRINT: request an OPENPGP fingerprint instead of the default.
*
* Enumeration of different certificate import flags.
*/
typedef enum gnutls_pubkey_flags {
GNUTLS_PUBKEY_DISABLE_CALLBACKS = 1 << 2,
GNUTLS_PUBKEY_GET_OPENPGP_FINGERPRINT = 1 << 3
} gnutls_pubkey_flags_t;
/**
* gnutls_abstract_export_flags:
* @GNUTLS_EXPORT_FLAG_NO_LZ: do not prepend a leading zero to exported values
*
* Enumeration of different certificate import flags.
*/
typedef enum gnutls_abstract_export_flags {
GNUTLS_EXPORT_FLAG_NO_LZ = 1
} gnutls_abstract_export_flags_t;
#define GNUTLS_PUBKEY_VERIFY_FLAG_TLS1_RSA GNUTLS_VERIFY_USE_TLS1_RSA
typedef int (*gnutls_privkey_sign_func)(gnutls_privkey_t key, void *userdata,
const gnutls_datum_t *raw_data,
gnutls_datum_t *signature);
typedef int (*gnutls_privkey_decrypt_func)(gnutls_privkey_t key, void *userdata,
const gnutls_datum_t *ciphertext,
gnutls_datum_t *plaintext);
typedef int (*gnutls_privkey_decrypt_func2)(gnutls_privkey_t key,
void *userdata,
const gnutls_datum_t *ciphertext,
unsigned char *plaintext,
size_t plaintext_size);
/* to be called to sign pre-hashed data. The input will be
* the output of the hash (such as SHA256) corresponding to
* the signature algorithm. The algorithm GNUTLS_SIGN_RSA_RAW
* will be provided when RSA PKCS#1 DigestInfo structure is provided
* as data (when this is called from a TLS 1.0 or 1.1 session).
*/
typedef int (*gnutls_privkey_sign_hash_func)(gnutls_privkey_t key,
gnutls_sign_algorithm_t algo,
void *userdata, unsigned int flags,
const gnutls_datum_t *hash,
gnutls_datum_t *signature);
/* to be called to sign data. The input data will be
* the data to be signed (and hashed), with the provided
* signature algorithm. This function is used for algorithms
* like ed25519 which cannot take pre-hashed data as input.
*/
typedef int (*gnutls_privkey_sign_data_func)(gnutls_privkey_t key,
gnutls_sign_algorithm_t algo,
void *userdata, unsigned int flags,
const gnutls_datum_t *data,
gnutls_datum_t *signature);
typedef void (*gnutls_privkey_deinit_func)(gnutls_privkey_t key,
void *userdata);
#define GNUTLS_SIGN_ALGO_TO_FLAGS(sig) (unsigned int)((sig) << 20)
#define GNUTLS_FLAGS_TO_SIGN_ALGO(flags) (unsigned int)((flags) >> 20)
/* Should return the public key algorithm (gnutls_pk_algorithm_t) */
#define GNUTLS_PRIVKEY_INFO_PK_ALGO 1
/* Should return the preferred signature algorithm (gnutls_sign_algorithm_t) or 0. */
#define GNUTLS_PRIVKEY_INFO_SIGN_ALGO (1 << 1)
/* Should return true (1) or false (0) if the provided sign algorithm
* (obtained with GNUTLS_FLAGS_TO_SIGN_ALGO) is supported.
*/
#define GNUTLS_PRIVKEY_INFO_HAVE_SIGN_ALGO (1 << 2)
/* Should return the number of bits of the public key algorithm (required for RSA-PSS)
* It is the value that should be returned by gnutls_pubkey_get_pk_algorithm() */
#define GNUTLS_PRIVKEY_INFO_PK_ALGO_BITS (1 << 3)
/* returns information on the public key associated with userdata */
typedef int (*gnutls_privkey_info_func)(gnutls_privkey_t key,
unsigned int flags, void *userdata);
int gnutls_pubkey_init(gnutls_pubkey_t *key);
void gnutls_pubkey_deinit(gnutls_pubkey_t key);
int gnutls_pubkey_verify_params(gnutls_pubkey_t key);
void gnutls_pubkey_set_pin_function(gnutls_pubkey_t key,
gnutls_pin_callback_t fn, void *userdata);
int gnutls_pubkey_get_pk_algorithm(gnutls_pubkey_t key, unsigned int *bits);
int gnutls_pubkey_set_spki(gnutls_pubkey_t key, const gnutls_x509_spki_t spki,
unsigned int flags);
int gnutls_pubkey_get_spki(gnutls_pubkey_t key, const gnutls_x509_spki_t spki,
unsigned int flags);
int gnutls_pubkey_import_x509(gnutls_pubkey_t key, gnutls_x509_crt_t crt,
unsigned int flags);
int gnutls_pubkey_import_x509_crq(gnutls_pubkey_t key, gnutls_x509_crq_t crq,
unsigned int flags);
int gnutls_pubkey_import_pkcs11(gnutls_pubkey_t key, gnutls_pkcs11_obj_t obj,
unsigned int flags);
int gnutls_pubkey_import_openpgp(gnutls_pubkey_t key, gnutls_openpgp_crt_t crt,
unsigned int flags);
int gnutls_pubkey_import_openpgp_raw(gnutls_pubkey_t pkey,
const gnutls_datum_t *data,
gnutls_openpgp_crt_fmt_t format,
const gnutls_openpgp_keyid_t keyid,
unsigned int flags);
int gnutls_pubkey_import_x509_raw(gnutls_pubkey_t pkey,
const gnutls_datum_t *data,
gnutls_x509_crt_fmt_t format,
unsigned int flags);
int gnutls_pubkey_import_privkey(gnutls_pubkey_t key, gnutls_privkey_t pkey,
unsigned int usage, unsigned int flags);
int gnutls_pubkey_import_tpm_url(gnutls_pubkey_t pkey, const char *url,
const char *srk_password, unsigned int flags);
int gnutls_pubkey_import_url(gnutls_pubkey_t key, const char *url,
unsigned int flags);
int gnutls_pubkey_import_tpm_raw(gnutls_pubkey_t pkey,
const gnutls_datum_t *fdata,
gnutls_tpmkey_fmt_t format,
const char *srk_password, unsigned int flags);
int gnutls_pubkey_get_preferred_hash_algorithm(gnutls_pubkey_t key,
gnutls_digest_algorithm_t *hash,
unsigned int *mand);
#define gnutls_pubkey_get_pk_rsa_raw gnutls_pubkey_export_rsa_raw
int gnutls_pubkey_export_rsa_raw(gnutls_pubkey_t key, gnutls_datum_t *m,
gnutls_datum_t *e);
int gnutls_pubkey_export_rsa_raw2(gnutls_pubkey_t key, gnutls_datum_t *m,
gnutls_datum_t *e, unsigned flags);
#define gnutls_pubkey_get_pk_dsa_raw gnutls_pubkey_export_dsa_raw
int gnutls_pubkey_export_dsa_raw(gnutls_pubkey_t key, gnutls_datum_t *p,
gnutls_datum_t *q, gnutls_datum_t *g,
gnutls_datum_t *y);
int gnutls_pubkey_export_dsa_raw2(gnutls_pubkey_t key, gnutls_datum_t *p,
gnutls_datum_t *q, gnutls_datum_t *g,
gnutls_datum_t *y, unsigned flags);
int gnutls_pubkey_export_dh_raw(gnutls_pubkey_t key, gnutls_dh_params_t params,
gnutls_datum_t *y, unsigned flags);
int gnutls_pubkey_export_ecc_raw2(gnutls_pubkey_t key,
gnutls_ecc_curve_t *curve, gnutls_datum_t *x,
gnutls_datum_t *y, unsigned flags);
int gnutls_pubkey_export_gost_raw2(gnutls_pubkey_t key,
gnutls_ecc_curve_t *curve,
gnutls_digest_algorithm_t *digest,
gnutls_gost_paramset_t *paramset,
gnutls_datum_t *x, gnutls_datum_t *y,
unsigned int flags);
#define gnutls_pubkey_get_pk_ecc_raw gnutls_pubkey_export_ecc_raw
int gnutls_pubkey_export_ecc_raw(gnutls_pubkey_t key, gnutls_ecc_curve_t *curve,
gnutls_datum_t *x, gnutls_datum_t *y);
#define gnutls_pubkey_get_pk_ecc_x962 gnutls_pubkey_export_ecc_x962
int gnutls_pubkey_export_ecc_x962(gnutls_pubkey_t key,
gnutls_datum_t *parameters,
gnutls_datum_t *ecpoint);
int gnutls_pubkey_export(gnutls_pubkey_t key, gnutls_x509_crt_fmt_t format,
void *output_data, size_t *output_data_size);
int gnutls_pubkey_export2(gnutls_pubkey_t key, gnutls_x509_crt_fmt_t format,
gnutls_datum_t *out);
int gnutls_pubkey_get_key_id(gnutls_pubkey_t key, unsigned int flags,
unsigned char *output_data,
size_t *output_data_size);
int gnutls_pubkey_get_openpgp_key_id(gnutls_pubkey_t key, unsigned int flags,
unsigned char *output_data,
size_t *output_data_size,
unsigned int *subkey);
int gnutls_pubkey_get_key_usage(gnutls_pubkey_t key, unsigned int *usage);
int gnutls_pubkey_set_key_usage(gnutls_pubkey_t key, unsigned int usage);
int gnutls_pubkey_import(gnutls_pubkey_t key, const gnutls_datum_t *data,
gnutls_x509_crt_fmt_t format);
#define gnutls_pubkey_import_pkcs11_url(key, url, flags) \
gnutls_pubkey_import_url(key, url, flags)
int gnutls_pubkey_import_dsa_raw(gnutls_pubkey_t key, const gnutls_datum_t *p,
const gnutls_datum_t *q,
const gnutls_datum_t *g,
const gnutls_datum_t *y);
int gnutls_pubkey_import_dh_raw(gnutls_pubkey_t key,
const gnutls_dh_params_t params,
const gnutls_datum_t *y);
int gnutls_pubkey_import_rsa_raw(gnutls_pubkey_t key, const gnutls_datum_t *m,
const gnutls_datum_t *e);
int gnutls_pubkey_import_ecc_x962(gnutls_pubkey_t key,
const gnutls_datum_t *parameters,
const gnutls_datum_t *ecpoint);
int gnutls_pubkey_import_ecc_raw(gnutls_pubkey_t key, gnutls_ecc_curve_t curve,
const gnutls_datum_t *x,
const gnutls_datum_t *y);
int gnutls_pubkey_import_gost_raw(gnutls_pubkey_t key, gnutls_ecc_curve_t curve,
gnutls_digest_algorithm_t digest,
gnutls_gost_paramset_t paramset,
const gnutls_datum_t *x,
const gnutls_datum_t *y);
int gnutls_pubkey_encrypt_data(gnutls_pubkey_t key, unsigned int flags,
const gnutls_datum_t *plaintext,
gnutls_datum_t *ciphertext);
int gnutls_x509_crt_set_pubkey(gnutls_x509_crt_t crt, gnutls_pubkey_t key);
int gnutls_x509_crq_set_pubkey(gnutls_x509_crq_t crq, gnutls_pubkey_t key);
int gnutls_pubkey_verify_hash2(gnutls_pubkey_t key,
gnutls_sign_algorithm_t algo, unsigned int flags,
const gnutls_datum_t *hash,
const gnutls_datum_t *signature);
int gnutls_pubkey_verify_data2(gnutls_pubkey_t pubkey,
gnutls_sign_algorithm_t algo, unsigned int flags,
const gnutls_datum_t *data,
const gnutls_datum_t *signature);
/* Private key operations */
int gnutls_privkey_init(gnutls_privkey_t *key);
void gnutls_privkey_deinit(gnutls_privkey_t key);
/* macros to allow specifying a subgroup and group size in gnutls_privkey_generate()
* and gnutls_x509_privkey_generate() */
#define GNUTLS_SUBGROUP_TO_BITS(group, subgroup) \
(unsigned int)((subgroup << 16) | (group))
#define GNUTLS_BITS_TO_SUBGROUP(bits) ((bits >> 16) & 0xFFFF)
#define GNUTLS_BITS_TO_GROUP(bits) (bits & 0xFFFF)
#define GNUTLS_BITS_HAVE_SUBGROUP(bits) ((bits)&0xFFFF0000)
int gnutls_privkey_generate(gnutls_privkey_t key, gnutls_pk_algorithm_t algo,
unsigned int bits, unsigned int flags);
int gnutls_privkey_generate2(gnutls_privkey_t pkey, gnutls_pk_algorithm_t algo,
unsigned int bits, unsigned int flags,
const gnutls_keygen_data_st *data,
unsigned data_size);
int gnutls_privkey_set_spki(gnutls_privkey_t key, const gnutls_x509_spki_t spki,
unsigned int flags);
int gnutls_privkey_get_spki(gnutls_privkey_t key, const gnutls_x509_spki_t spki,
unsigned int flags);
int gnutls_privkey_verify_seed(gnutls_privkey_t key, gnutls_digest_algorithm_t,
const void *seed, size_t seed_size);
int gnutls_privkey_get_seed(gnutls_privkey_t key, gnutls_digest_algorithm_t *,
void *seed, size_t *seed_size);
int gnutls_privkey_verify_params(gnutls_privkey_t key);
void gnutls_privkey_set_flags(gnutls_privkey_t key, unsigned int flags);
void gnutls_privkey_set_pin_function(gnutls_privkey_t key,
gnutls_pin_callback_t fn, void *userdata);
int gnutls_privkey_get_pk_algorithm(gnutls_privkey_t key, unsigned int *bits);
gnutls_privkey_type_t gnutls_privkey_get_type(gnutls_privkey_t key);
int gnutls_privkey_status(gnutls_privkey_t key);
/**
* gnutls_privkey_flags:
* @GNUTLS_PRIVKEY_SIGN_FLAG_TLS1_RSA: Make an RSA signature on the hashed data as in the TLS protocol.
* @GNUTLS_PRIVKEY_SIGN_FLAG_RSA_PSS: Make an RSA signature on the hashed data with the PSS padding.
* @GNUTLS_PRIVKEY_FLAG_REPRODUCIBLE: Make a signature on the hashed data with reproducible parameters.
* For RSA-PSS, that means to use empty salt instead of random value. To
* verify a signature created using this flag, the corresponding SPKI needs
* to be set on the public key. Use gnutls_pubkey_set_spki() for that.
* For ECDSA/DSA, it uses the deterministic construction of random parameter
* according to RFC 6979. Note that this only supports the NIST curves and DSA
* subgroup bits up to 512.
* @GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE: When importing a private key, automatically
* release it when the structure it was imported is released.
* @GNUTLS_PRIVKEY_IMPORT_COPY: Copy required values during import.
* @GNUTLS_PRIVKEY_DISABLE_CALLBACKS: The following flag disables call to PIN callbacks etc.
* Only relevant to TPM keys.
* @GNUTLS_PRIVKEY_FLAG_PROVABLE: When generating a key involving prime numbers, use provable primes; a seed may be required.
* @GNUTLS_PRIVKEY_FLAG_CA: The generated private key is going to be used as a CA (relevant for RSA-PSS keys).
* @GNUTLS_PRIVKEY_FLAG_EXPORT_COMPAT: Keys generated or imported as provable require an extended format which cannot be read by previous versions
* of gnutls or other applications. By setting this flag the key will be exported in a backwards compatible way,
* even if the information about the seed used will be lost.
* @GNUTLS_PRIVKEY_FLAG_RSA_PSS_FIXED_SALT_LENGTH: When making an RSA-PSS
* signature, use the salt whose length is equal to the digest length, as
* mandated in RFC 8446 4.2.3.
*
* Enumeration of different certificate import flags.
*/
typedef enum gnutls_privkey_flags {
GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE = 1,
GNUTLS_PRIVKEY_IMPORT_COPY = 1 << 1,
GNUTLS_PRIVKEY_DISABLE_CALLBACKS = 1 << 2,
GNUTLS_PRIVKEY_SIGN_FLAG_TLS1_RSA = 1 << 4,
GNUTLS_PRIVKEY_FLAG_PROVABLE = 1 << 5,
GNUTLS_PRIVKEY_FLAG_EXPORT_COMPAT = 1 << 6,
GNUTLS_PRIVKEY_SIGN_FLAG_RSA_PSS = 1 << 7,
GNUTLS_PRIVKEY_FLAG_REPRODUCIBLE = 1 << 8,
GNUTLS_PRIVKEY_FLAG_CA = 1 << 9,
GNUTLS_PRIVKEY_FLAG_RSA_PSS_FIXED_SALT_LENGTH = 1 << 10
} gnutls_privkey_flags_t;
int gnutls_privkey_import_pkcs11(gnutls_privkey_t pkey,
gnutls_pkcs11_privkey_t key,
unsigned int flags);
int gnutls_privkey_import_x509(gnutls_privkey_t pkey, gnutls_x509_privkey_t key,
unsigned int flags);
int gnutls_privkey_import_openpgp(gnutls_privkey_t pkey,
gnutls_openpgp_privkey_t key,
unsigned int flags);
int gnutls_privkey_export_x509(gnutls_privkey_t pkey,
gnutls_x509_privkey_t *key);
int gnutls_privkey_export_openpgp(gnutls_privkey_t pkey,
gnutls_openpgp_privkey_t *key);
int gnutls_privkey_export_pkcs11(gnutls_privkey_t pkey,
gnutls_pkcs11_privkey_t *key);
int gnutls_privkey_import_openpgp_raw(gnutls_privkey_t pkey,
const gnutls_datum_t *data,
gnutls_openpgp_crt_fmt_t format,
const gnutls_openpgp_keyid_t keyid,
const char *password);
int gnutls_privkey_import_x509_raw(gnutls_privkey_t pkey,
const gnutls_datum_t *data,
gnutls_x509_crt_fmt_t format,
const char *password, unsigned int flags);
int gnutls_privkey_import_tpm_raw(gnutls_privkey_t pkey,
const gnutls_datum_t *fdata,
gnutls_tpmkey_fmt_t format,
const char *srk_password,
const char *key_password, unsigned int flags);
int gnutls_privkey_import_tpm_url(gnutls_privkey_t pkey, const char *url,
const char *srk_password,
const char *key_password, unsigned int flags);
int gnutls_privkey_import_url(gnutls_privkey_t key, const char *url,
unsigned int flags);
#if 0
/* for documentation purposes */
int gnutls_privkey_import_pkcs11_url(gnutls_privkey_t key, const char *url);
#endif
#define gnutls_privkey_import_pkcs11_url(key, url) \
gnutls_privkey_import_url(key, url, 0)
int gnutls_privkey_import_ext(gnutls_privkey_t pkey, gnutls_pk_algorithm_t pk,
void *userdata,
gnutls_privkey_sign_func sign_func,
gnutls_privkey_decrypt_func decrypt_func,
unsigned int flags);
int gnutls_privkey_import_ext2(gnutls_privkey_t pkey, gnutls_pk_algorithm_t pk,
void *userdata,
gnutls_privkey_sign_func sign_func,
gnutls_privkey_decrypt_func decrypt_func,
gnutls_privkey_deinit_func deinit_func,
unsigned int flags);
int gnutls_privkey_import_ext3(gnutls_privkey_t pkey, void *userdata,
gnutls_privkey_sign_func sign_func,
gnutls_privkey_decrypt_func decrypt_func,
gnutls_privkey_deinit_func deinit_func,
gnutls_privkey_info_func info_func,
unsigned int flags);
int gnutls_privkey_import_ext4(gnutls_privkey_t pkey, void *userdata,
gnutls_privkey_sign_data_func sign_data_func,
gnutls_privkey_sign_hash_func sign_hash_func,
gnutls_privkey_decrypt_func decrypt_func,
gnutls_privkey_deinit_func deinit_func,
gnutls_privkey_info_func info_func,
unsigned int flags);
int gnutls_privkey_import_dsa_raw(gnutls_privkey_t key, const gnutls_datum_t *p,
const gnutls_datum_t *q,
const gnutls_datum_t *g,
const gnutls_datum_t *y,
const gnutls_datum_t *x);
int gnutls_privkey_import_dh_raw(gnutls_privkey_t key,
const gnutls_dh_params_t params,
const gnutls_datum_t *y,
const gnutls_datum_t *x);
int gnutls_privkey_import_rsa_raw(
gnutls_privkey_t key, const gnutls_datum_t *m, const gnutls_datum_t *e,
const gnutls_datum_t *d, const gnutls_datum_t *p,
const gnutls_datum_t *q, const gnutls_datum_t *u,
const gnutls_datum_t *e1, const gnutls_datum_t *e2);
int gnutls_privkey_import_ecc_raw(gnutls_privkey_t key,
gnutls_ecc_curve_t curve,
const gnutls_datum_t *x,
const gnutls_datum_t *y,
const gnutls_datum_t *k);
int gnutls_privkey_import_gost_raw(gnutls_privkey_t key,
gnutls_ecc_curve_t curve,
gnutls_digest_algorithm_t digest,
gnutls_gost_paramset_t paramset,
const gnutls_datum_t *x,
const gnutls_datum_t *y,
const gnutls_datum_t *k);
int gnutls_privkey_sign_data(gnutls_privkey_t signer,
gnutls_digest_algorithm_t hash, unsigned int flags,
const gnutls_datum_t *data,
gnutls_datum_t *signature);
int gnutls_privkey_sign_data2(gnutls_privkey_t signer,
gnutls_sign_algorithm_t algo, unsigned int flags,
const gnutls_datum_t *data,
gnutls_datum_t *signature);
#define gnutls_privkey_sign_raw_data(key, flags, data, sig) \
gnutls_privkey_sign_hash(key, 0, GNUTLS_PRIVKEY_SIGN_FLAG_TLS1_RSA, \
data, sig)
int gnutls_privkey_sign_hash(gnutls_privkey_t signer,
gnutls_digest_algorithm_t hash_algo,
unsigned int flags,
const gnutls_datum_t *hash_data,
gnutls_datum_t *signature);
int gnutls_privkey_sign_hash2(gnutls_privkey_t signer,
gnutls_sign_algorithm_t algo, unsigned int flags,
const gnutls_datum_t *hash_data,
gnutls_datum_t *signature);
int gnutls_privkey_decrypt_data(gnutls_privkey_t key, unsigned int flags,
const gnutls_datum_t *ciphertext,
gnutls_datum_t *plaintext);
int gnutls_privkey_decrypt_data2(gnutls_privkey_t key, unsigned int flags,
const gnutls_datum_t *ciphertext,
unsigned char *plaintext,
size_t plaintext_size);
int gnutls_privkey_export_rsa_raw(gnutls_privkey_t key, gnutls_datum_t *m,
gnutls_datum_t *e, gnutls_datum_t *d,
gnutls_datum_t *p, gnutls_datum_t *q,
gnutls_datum_t *u, gnutls_datum_t *e1,
gnutls_datum_t *e2);
int gnutls_privkey_export_rsa_raw2(gnutls_privkey_t key, gnutls_datum_t *m,
gnutls_datum_t *e, gnutls_datum_t *d,
gnutls_datum_t *p, gnutls_datum_t *q,
gnutls_datum_t *u, gnutls_datum_t *e1,
gnutls_datum_t *e2, unsigned flags);
int gnutls_privkey_export_dsa_raw(gnutls_privkey_t key, gnutls_datum_t *p,
gnutls_datum_t *q, gnutls_datum_t *g,
gnutls_datum_t *y, gnutls_datum_t *x);
int gnutls_privkey_export_dsa_raw2(gnutls_privkey_t key, gnutls_datum_t *p,
gnutls_datum_t *q, gnutls_datum_t *g,
gnutls_datum_t *y, gnutls_datum_t *x,
unsigned flags);
int gnutls_privkey_export_dh_raw(gnutls_privkey_t key,
gnutls_dh_params_t params, gnutls_datum_t *y,
gnutls_datum_t *x, unsigned int flags);
int gnutls_privkey_export_ecc_raw(gnutls_privkey_t key,
gnutls_ecc_curve_t *curve, gnutls_datum_t *x,
gnutls_datum_t *y, gnutls_datum_t *k);
int gnutls_privkey_export_ecc_raw2(gnutls_privkey_t key,
gnutls_ecc_curve_t *curve, gnutls_datum_t *x,
gnutls_datum_t *y, gnutls_datum_t *k,
unsigned flags);
int gnutls_privkey_export_gost_raw2(gnutls_privkey_t key,
gnutls_ecc_curve_t *curve,
gnutls_digest_algorithm_t *digest,
gnutls_gost_paramset_t *paramset,
gnutls_datum_t *x, gnutls_datum_t *y,
gnutls_datum_t *k, unsigned flags);
int gnutls_privkey_derive_secret(gnutls_privkey_t privkey,
gnutls_pubkey_t pubkey,
const gnutls_datum_t *nonce,
gnutls_datum_t *secret, unsigned int flags);
int gnutls_x509_crt_privkey_sign(gnutls_x509_crt_t crt,
gnutls_x509_crt_t issuer,
gnutls_privkey_t issuer_key,
gnutls_digest_algorithm_t dig,
unsigned int flags);
int gnutls_x509_crl_privkey_sign(gnutls_x509_crl_t crl,
gnutls_x509_crt_t issuer,
gnutls_privkey_t issuer_key,
gnutls_digest_algorithm_t dig,
unsigned int flags);
int gnutls_x509_crq_privkey_sign(gnutls_x509_crq_t crq, gnutls_privkey_t key,
gnutls_digest_algorithm_t dig,
unsigned int flags);
/**
* gnutls_pcert_st:
* @pubkey: public key of parsed certificate.
* @cert: certificate itself of parsed certificate
* @type: type of certificate, a #gnutls_certificate_type_t type.
*
* A parsed certificate.
*/
typedef struct gnutls_pcert_st {
gnutls_pubkey_t pubkey;
gnutls_datum_t cert;
gnutls_certificate_type_t type;
} gnutls_pcert_st;
/* This flag is unused/ignored */
#define GNUTLS_PCERT_NO_CERT 1
int gnutls_pcert_import_x509(gnutls_pcert_st *pcert, gnutls_x509_crt_t crt,
unsigned int flags);
int gnutls_pcert_import_x509_list(gnutls_pcert_st *pcert,
gnutls_x509_crt_t *crt, unsigned *ncrt,
unsigned int flags);
int gnutls_pcert_export_x509(gnutls_pcert_st *pcert, gnutls_x509_crt_t *crt);
int gnutls_pcert_list_import_x509_raw(gnutls_pcert_st *pcerts,
unsigned int *pcert_max,
const gnutls_datum_t *data,
gnutls_x509_crt_fmt_t format,
unsigned int flags);
int gnutls_pcert_list_import_x509_file(gnutls_pcert_st *pcert_list,
unsigned *pcert_list_size,
const char *file,
gnutls_x509_crt_fmt_t format,
gnutls_pin_callback_t pin_fn,
void *pin_fn_userdata,
unsigned int flags);
int gnutls_pcert_import_x509_raw(gnutls_pcert_st *pcert,
const gnutls_datum_t *cert,
gnutls_x509_crt_fmt_t format,
unsigned int flags);
int gnutls_pcert_import_openpgp_raw(gnutls_pcert_st *pcert,
const gnutls_datum_t *cert,
gnutls_openpgp_crt_fmt_t format,
gnutls_openpgp_keyid_t keyid,
unsigned int flags);
int gnutls_pcert_import_openpgp(gnutls_pcert_st *pcert,
gnutls_openpgp_crt_t crt, unsigned int flags);
int gnutls_pcert_export_openpgp(gnutls_pcert_st *pcert,
gnutls_openpgp_crt_t *crt);
void gnutls_pcert_deinit(gnutls_pcert_st *pcert);
int gnutls_pcert_import_rawpk(gnutls_pcert_st *pcert, gnutls_pubkey_t key,
unsigned int flags);
int gnutls_pcert_import_rawpk_raw(gnutls_pcert_st *pcert,
const gnutls_datum_t *rawpubkey,
gnutls_x509_crt_fmt_t format,
unsigned int key_usage, unsigned int flags);
/* For certificate credentials */
/* This is the same as gnutls_certificate_retrieve_function()
* but retrieves a gnutls_pcert_st which requires much less processing
* within the library.
*/
typedef int gnutls_certificate_retrieve_function2(
gnutls_session_t, const gnutls_datum_t *req_ca_rdn, int nreqs,
const gnutls_pk_algorithm_t *pk_algos, int pk_algos_length,
gnutls_pcert_st **, unsigned int *pcert_length,
gnutls_privkey_t *privkey);
void gnutls_certificate_set_retrieve_function2(
gnutls_certificate_credentials_t cred,
gnutls_certificate_retrieve_function2 *func);
struct gnutls_cert_retr_st {
unsigned version; /* set to 1 */
gnutls_certificate_credentials_t cred;
const gnutls_datum_t *req_ca_rdn;
unsigned nreqs;
const gnutls_pk_algorithm_t *pk_algos;
unsigned pk_algos_length;
/* other fields may be added if version is > 1 */
unsigned char padding[64];
};
/* When the callback sets this value, gnutls will deinitialize the given
* values after use */
#define GNUTLS_CERT_RETR_DEINIT_ALL 1
typedef int gnutls_certificate_retrieve_function3(
gnutls_session_t, const struct gnutls_cert_retr_st *info,
gnutls_pcert_st **certs, unsigned int *certs_length,
gnutls_ocsp_data_st **ocsp, unsigned int *ocsp_length,
gnutls_privkey_t *privkey, unsigned int *flags);
void gnutls_certificate_set_retrieve_function3(
gnutls_certificate_credentials_t cred,
gnutls_certificate_retrieve_function3 *func);
int gnutls_certificate_set_key(gnutls_certificate_credentials_t res,
const char **names, int names_size,
gnutls_pcert_st *pcert_list, int pcert_list_size,
gnutls_privkey_t key);
int gnutls_pubkey_print(gnutls_pubkey_t pubkey,
gnutls_certificate_print_formats_t format,
gnutls_datum_t *out);
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_ABSTRACT_H */

View File

@ -0,0 +1,228 @@
/*
* Copyright (C) 2008-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
/* Typedefs for more compatibility with older GnuTLS. */
#ifndef GNUTLS_COMPAT_H
#define GNUTLS_COMPAT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __GNUC__
#define _GNUTLS_GCC_VERSION \
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#if !defined GNUTLS_INTERNAL_BUILD
#if _GNUTLS_GCC_VERSION >= 30100
#define _GNUTLS_GCC_ATTR_DEPRECATED __attribute__((__deprecated__))
#endif
#endif
#endif /* __GNUC__ */
#ifndef _GNUTLS_GCC_ATTR_DEPRECATED
#define _GNUTLS_GCC_ATTR_DEPRECATED
#endif
/* gnutls_connection_end_t was made redundant in 2.99.0 */
typedef unsigned int gnutls_connection_end_t _GNUTLS_GCC_ATTR_DEPRECATED;
/* Stuff deprecated in 2.x */
typedef gnutls_cipher_algorithm_t gnutls_cipher_algorithm
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_kx_algorithm_t gnutls_kx_algorithm _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_mac_algorithm_t gnutls_mac_algorithm _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_digest_algorithm_t gnutls_digest_algorithm
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_compression_method_t gnutls_compression_method
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_connection_end_t gnutls_connection_end
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_x509_crt_fmt_t gnutls_x509_crt_fmt _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_pk_algorithm_t gnutls_pk_algorithm _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_sign_algorithm_t gnutls_sign_algorithm
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_close_request_t gnutls_close_request _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_certificate_request_t gnutls_certificate_request
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_certificate_status_t gnutls_certificate_status
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_session_t gnutls_session _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_alert_level_t gnutls_alert_level _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_alert_description_t gnutls_alert_description
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_x509_subject_alt_name_t gnutls_x509_subject_alt_name
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_openpgp_privkey_t gnutls_openpgp_privkey
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_openpgp_keyring_t gnutls_openpgp_keyring
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_x509_crt_t gnutls_x509_crt _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_x509_privkey_t gnutls_x509_privkey _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_x509_crl_t gnutls_x509_crl _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_x509_crq_t gnutls_x509_crq _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_certificate_credentials_t gnutls_certificate_credentials
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_anon_server_credentials_t gnutls_anon_server_credentials
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_anon_client_credentials_t gnutls_anon_client_credentials
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_srp_client_credentials_t gnutls_srp_client_credentials
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_srp_server_credentials_t gnutls_srp_server_credentials
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_dh_params_t gnutls_dh_params _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_rsa_params_t gnutls_rsa_params _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_params_type_t gnutls_params_type _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_credentials_type_t gnutls_credentials_type
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_certificate_type_t gnutls_certificate_type
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_datum_t gnutls_datum _GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_transport_ptr_t gnutls_transport_ptr _GNUTLS_GCC_ATTR_DEPRECATED;
/* Old verification flags */
#define GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT (0)
/* Old SRP alerts removed in 2.1.x because the TLS-SRP RFC was
modified to use the PSK alert. */
#define GNUTLS_A_MISSING_SRP_USERNAME GNUTLS_A_UNKNOWN_PSK_IDENTITY
#define GNUTLS_A_UNKNOWN_SRP_USERNAME GNUTLS_A_UNKNOWN_PSK_IDENTITY
/* OpenPGP stuff renamed in 2.1.x. */
#define GNUTLS_OPENPGP_KEY GNUTLS_OPENPGP_CERT
#define GNUTLS_OPENPGP_KEY_FINGERPRINT GNUTLS_OPENPGP_CERT_FINGERPRINT
#define gnutls_openpgp_send_key gnutls_openpgp_send_cert
typedef gnutls_openpgp_crt_status_t gnutls_openpgp_key_status_t
_GNUTLS_GCC_ATTR_DEPRECATED;
typedef gnutls_openpgp_crt_t gnutls_openpgp_key_t _GNUTLS_GCC_ATTR_DEPRECATED;
#define gnutls_openpgp_key_init gnutls_openpgp_crt_init
#define gnutls_openpgp_key_deinit gnutls_openpgp_crt_deinit
#define gnutls_openpgp_key_import gnutls_openpgp_crt_import
#define gnutls_openpgp_key_export gnutls_openpgp_crt_export
#define gnutls_openpgp_key_get_key_usage gnutls_openpgp_crt_get_key_usage
#define gnutls_openpgp_key_get_fingerprint gnutls_openpgp_crt_get_fingerprint
#define gnutls_openpgp_key_get_pk_algorithm gnutls_openpgp_crt_get_pk_algorithm
#define gnutls_openpgp_key_get_name gnutls_openpgp_crt_get_name
#define gnutls_openpgp_key_get_version gnutls_openpgp_crt_get_version
#define gnutls_openpgp_key_get_creation_time \
gnutls_openpgp_crt_get_creation_time
#define gnutls_openpgp_key_get_expiration_time \
gnutls_openpgp_crt_get_expiration_time
#define gnutls_openpgp_key_get_id gnutls_openpgp_crt_get_id
#define gnutls_openpgp_key_check_hostname gnutls_openpgp_crt_check_hostname
/* OpenPGP stuff renamed in 2.3.x. */
#define gnutls_openpgp_crt_get_id gnutls_openpgp_crt_get_key_id
/* New better names renamed in 2.3.x, add these for backwards
compatibility with old poor names.*/
#define GNUTLS_X509_CRT_FULL GNUTLS_CRT_PRINT_FULL
#define GNUTLS_X509_CRT_ONELINE GNUTLS_CRT_PRINT_ONELINE
#define GNUTLS_X509_CRT_UNSIGNED_FULL GNUTLS_CRT_PRINT_UNSIGNED_FULL
/* Namespace problems. */
#define LIBGNUTLS_VERSION GNUTLS_VERSION
#define LIBGNUTLS_VERSION_MAJOR GNUTLS_VERSION_MAJOR
#define LIBGNUTLS_VERSION_MINOR GNUTLS_VERSION_MINOR
#define LIBGNUTLS_VERSION_PATCH GNUTLS_VERSION_PATCH
#define LIBGNUTLS_VERSION_NUMBER GNUTLS_VERSION_NUMBER
#define LIBGNUTLS_EXTRA_VERSION GNUTLS_VERSION
/* This is a very dangerous and error-prone function.
* Use gnutls_privkey_sign_hash() instead.
*/
int gnutls_x509_privkey_sign_hash(
gnutls_x509_privkey_t key, const gnutls_datum_t *hash,
gnutls_datum_t *signature) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_sign_hash(
gnutls_openpgp_privkey_t key, const gnutls_datum_t *hash,
gnutls_datum_t *signature) _GNUTLS_GCC_ATTR_DEPRECATED;
/* gnutls_pubkey_get_preferred_hash_algorithm() */
int gnutls_x509_crt_get_preferred_hash_algorithm(
gnutls_x509_crt_t crt, gnutls_digest_algorithm_t *hash,
unsigned int *mand) _GNUTLS_GCC_ATTR_DEPRECATED;
/* use gnutls_privkey_sign_hash() with the GNUTLS_PRIVKEY_SIGN_FLAG_TLS1_RSA flag */
#ifdef _ISOC99_SOURCE
/* we provide older functions for compatibility as inline functions that
* depend on gnutls_session_get_random. */
static inline const void *gnutls_session_get_server_random(
gnutls_session_t session) _GNUTLS_GCC_ATTR_DEPRECATED;
static inline const void *
gnutls_session_get_server_random(gnutls_session_t session)
{
gnutls_datum_t rnd;
gnutls_session_get_random(session, NULL, &rnd); /*doc-skip */
return rnd.data;
}
static inline const void *gnutls_session_get_client_random(
gnutls_session_t session) _GNUTLS_GCC_ATTR_DEPRECATED;
static inline const void *
gnutls_session_get_client_random(gnutls_session_t session)
{
gnutls_datum_t rnd;
gnutls_session_get_random(session, &rnd, NULL); /*doc-skip */
return rnd.data;
}
#endif
void gnutls_global_set_mem_functions(gnutls_alloc_function alloc_func,
gnutls_alloc_function secure_alloc_func,
gnutls_is_secure_function is_secure_func,
gnutls_realloc_function realloc_func,
gnutls_free_function free_func)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* defined in old headers - unused nevertheless */
#define GNUTLS_SUPPLEMENTAL_USER_MAPPING_DATA 0
/* old compression related functions */
gnutls_compression_method_t
gnutls_compression_get(gnutls_session_t session) _GNUTLS_GCC_ATTR_DEPRECATED;
const char *gnutls_compression_get_name(gnutls_compression_method_t algorithm)
__GNUTLS_CONST__ _GNUTLS_GCC_ATTR_DEPRECATED;
gnutls_compression_method_t gnutls_compression_get_id(const char *name)
__GNUTLS_CONST__ _GNUTLS_GCC_ATTR_DEPRECATED;
const gnutls_compression_method_t *
gnutls_compression_list(void) __GNUTLS_PURE__ _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_priority_compression_list(gnutls_priority_t pcache,
const unsigned int **list)
_GNUTLS_GCC_ATTR_DEPRECATED;
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_COMPAT_H */

View File

@ -0,0 +1,305 @@
/*
* Copyright (C) 2008-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLS_CRYPTO_H
#define GNUTLS_CRYPTO_H
#include <gnutls/gnutls.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct api_cipher_hd_st *gnutls_cipher_hd_t;
int gnutls_cipher_init(gnutls_cipher_hd_t *handle,
gnutls_cipher_algorithm_t cipher,
const gnutls_datum_t *key, const gnutls_datum_t *iv);
int gnutls_cipher_encrypt(const gnutls_cipher_hd_t handle, void *text,
size_t textlen);
int gnutls_cipher_decrypt(const gnutls_cipher_hd_t handle, void *ciphertext,
size_t ciphertextlen);
int gnutls_cipher_decrypt2(gnutls_cipher_hd_t handle, const void *ciphertext,
size_t ciphertextlen, void *text, size_t textlen);
int gnutls_cipher_encrypt2(gnutls_cipher_hd_t handle, const void *text,
size_t textlen, void *ciphertext,
size_t ciphertextlen);
/**
* gnutls_cipher_flags_t:
* @GNUTLS_CIPHER_PADDING_PKCS7: Flag to indicate PKCS#7 padding
*
* Enumeration of flags to control block cipher padding, used by
* gnutls_cipher_encrypt3() and gnutls_cipher_decrypt3().
*
* Since: 3.7.7
*/
typedef enum gnutls_cipher_flags_t {
GNUTLS_CIPHER_PADDING_PKCS7 = 1
} gnutls_cipher_flags_t;
int gnutls_cipher_encrypt3(gnutls_cipher_hd_t handle, const void *ptext,
size_t ptext_len, void *ctext, size_t *ctext_len,
unsigned flags);
int gnutls_cipher_decrypt3(gnutls_cipher_hd_t handle, const void *ctext,
size_t ctext_len, void *ptext, size_t *ptext_len,
unsigned flags);
void gnutls_cipher_set_iv(gnutls_cipher_hd_t handle, void *iv, size_t ivlen);
int gnutls_cipher_tag(gnutls_cipher_hd_t handle, void *tag, size_t tag_size);
int gnutls_cipher_add_auth(gnutls_cipher_hd_t handle, const void *text,
size_t text_size);
void gnutls_cipher_deinit(gnutls_cipher_hd_t handle);
unsigned gnutls_cipher_get_block_size(gnutls_cipher_algorithm_t algorithm)
__GNUTLS_CONST__;
unsigned
gnutls_cipher_get_iv_size(gnutls_cipher_algorithm_t algorithm) __GNUTLS_CONST__;
unsigned gnutls_cipher_get_tag_size(gnutls_cipher_algorithm_t algorithm)
__GNUTLS_CONST__;
/* AEAD API
*/
typedef struct api_aead_cipher_hd_st *gnutls_aead_cipher_hd_t;
int gnutls_aead_cipher_init(gnutls_aead_cipher_hd_t *handle,
gnutls_cipher_algorithm_t cipher,
const gnutls_datum_t *key);
int gnutls_aead_cipher_set_key(gnutls_aead_cipher_hd_t handle,
const gnutls_datum_t *key);
int gnutls_aead_cipher_decrypt(gnutls_aead_cipher_hd_t handle,
const void *nonce, size_t nonce_len,
const void *auth, size_t auth_len,
size_t tag_size, const void *ctext,
size_t ctext_len, void *ptext,
size_t *ptext_len);
int gnutls_aead_cipher_encrypt(gnutls_aead_cipher_hd_t handle,
const void *nonce, size_t nonce_len,
const void *auth, size_t auth_len,
size_t tag_size, const void *ptext,
size_t ptext_len, void *ctext,
size_t *ctext_len);
int gnutls_aead_cipher_encryptv(gnutls_aead_cipher_hd_t handle,
const void *nonce, size_t nonce_len,
const giovec_t *auth_iov, int auth_iovcnt,
size_t tag_size, const giovec_t *iov,
int iovcnt, void *ctext, size_t *ctext_len);
int gnutls_aead_cipher_encryptv2(gnutls_aead_cipher_hd_t handle,
const void *nonce, size_t nonce_len,
const giovec_t *auth_iov, int auth_iovcnt,
const giovec_t *iov, int iovcnt, void *tag,
size_t *tag_size);
int gnutls_aead_cipher_decryptv2(gnutls_aead_cipher_hd_t handle,
const void *nonce, size_t nonce_len,
const giovec_t *auth_iov, int auth_iovcnt,
const giovec_t *iov, int iovcnt, void *tag,
size_t tag_size);
void gnutls_aead_cipher_deinit(gnutls_aead_cipher_hd_t handle);
/* Hash - MAC API */
typedef struct hash_hd_st *gnutls_hash_hd_t;
typedef struct hmac_hd_st *gnutls_hmac_hd_t;
size_t
gnutls_mac_get_nonce_size(gnutls_mac_algorithm_t algorithm) __GNUTLS_CONST__;
int gnutls_hmac_init(gnutls_hmac_hd_t *dig, gnutls_mac_algorithm_t algorithm,
const void *key, size_t keylen);
void gnutls_hmac_set_nonce(gnutls_hmac_hd_t handle, const void *nonce,
size_t nonce_len);
int gnutls_hmac(gnutls_hmac_hd_t handle, const void *text, size_t textlen);
void gnutls_hmac_output(gnutls_hmac_hd_t handle, void *digest);
void gnutls_hmac_deinit(gnutls_hmac_hd_t handle, void *digest);
unsigned gnutls_hmac_get_len(gnutls_mac_algorithm_t algorithm) __GNUTLS_CONST__;
unsigned
gnutls_hmac_get_key_size(gnutls_mac_algorithm_t algorithm) __GNUTLS_CONST__;
int gnutls_hmac_fast(gnutls_mac_algorithm_t algorithm, const void *key,
size_t keylen, const void *text, size_t textlen,
void *digest);
gnutls_hmac_hd_t gnutls_hmac_copy(gnutls_hmac_hd_t handle);
int gnutls_hash_init(gnutls_hash_hd_t *dig,
gnutls_digest_algorithm_t algorithm);
int gnutls_hash(gnutls_hash_hd_t handle, const void *text, size_t textlen);
void gnutls_hash_output(gnutls_hash_hd_t handle, void *digest);
void gnutls_hash_deinit(gnutls_hash_hd_t handle, void *digest);
unsigned
gnutls_hash_get_len(gnutls_digest_algorithm_t algorithm) __GNUTLS_CONST__;
int gnutls_hash_fast(gnutls_digest_algorithm_t algorithm, const void *text,
size_t textlen, void *digest);
gnutls_hash_hd_t gnutls_hash_copy(gnutls_hash_hd_t handle);
/* KDF API */
int gnutls_hkdf_extract(gnutls_mac_algorithm_t mac, const gnutls_datum_t *key,
const gnutls_datum_t *salt, void *output);
int gnutls_hkdf_expand(gnutls_mac_algorithm_t mac, const gnutls_datum_t *key,
const gnutls_datum_t *info, void *output, size_t length);
int gnutls_pbkdf2(gnutls_mac_algorithm_t mac, const gnutls_datum_t *key,
const gnutls_datum_t *salt, unsigned iter_count, void *output,
size_t length);
/* register ciphers */
/**
* gnutls_rnd_level_t:
* @GNUTLS_RND_NONCE: Non-predictable random number. Fatal in parts
* of session if broken, i.e., vulnerable to statistical analysis.
* @GNUTLS_RND_RANDOM: Pseudo-random cryptographic random number.
* Fatal in session if broken. Example use: temporal keys.
* @GNUTLS_RND_KEY: Fatal in many sessions if broken. Example use:
* Long-term keys.
*
* Enumeration of random quality levels.
*/
typedef enum gnutls_rnd_level {
GNUTLS_RND_NONCE = 0,
GNUTLS_RND_RANDOM = 1,
GNUTLS_RND_KEY = 2
} gnutls_rnd_level_t;
int gnutls_rnd(gnutls_rnd_level_t level, void *data, size_t len);
void gnutls_rnd_refresh(void);
/* API to override ciphers and MAC algorithms
*/
typedef int (*gnutls_cipher_init_func)(gnutls_cipher_algorithm_t, void **ctx,
int enc);
typedef int (*gnutls_cipher_setkey_func)(void *ctx, const void *key,
size_t keysize);
/* old style ciphers */
typedef int (*gnutls_cipher_setiv_func)(void *ctx, const void *iv,
size_t ivsize);
typedef int (*gnutls_cipher_getiv_func)(void *ctx, void *iv, size_t ivsize);
typedef int (*gnutls_cipher_encrypt_func)(void *ctx, const void *plain,
size_t plainsize, void *encr,
size_t encrsize);
typedef int (*gnutls_cipher_decrypt_func)(void *ctx, const void *encr,
size_t encrsize, void *plain,
size_t plainsize);
/* aead ciphers */
typedef int (*gnutls_cipher_auth_func)(void *ctx, const void *data,
size_t datasize);
typedef void (*gnutls_cipher_tag_func)(void *ctx, void *tag, size_t tagsize);
typedef int (*gnutls_cipher_aead_encrypt_func)(
void *ctx, const void *nonce, size_t noncesize, const void *auth,
size_t authsize, size_t tag_size, const void *plain, size_t plainsize,
void *encr, size_t encrsize);
typedef int (*gnutls_cipher_aead_decrypt_func)(
void *ctx, const void *nonce, size_t noncesize, const void *auth,
size_t authsize, size_t tag_size, const void *encr, size_t encrsize,
void *plain, size_t plainsize);
typedef void (*gnutls_cipher_deinit_func)(void *ctx);
int gnutls_crypto_register_cipher(
gnutls_cipher_algorithm_t algorithm, int priority,
gnutls_cipher_init_func init, gnutls_cipher_setkey_func setkey,
gnutls_cipher_setiv_func setiv, gnutls_cipher_encrypt_func encrypt,
gnutls_cipher_decrypt_func decrypt,
gnutls_cipher_deinit_func deinit) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_crypto_register_aead_cipher(
gnutls_cipher_algorithm_t algorithm, int priority,
gnutls_cipher_init_func init, gnutls_cipher_setkey_func setkey,
gnutls_cipher_aead_encrypt_func aead_encrypt,
gnutls_cipher_aead_decrypt_func aead_decrypt,
gnutls_cipher_deinit_func deinit) _GNUTLS_GCC_ATTR_DEPRECATED;
typedef int (*gnutls_mac_init_func)(gnutls_mac_algorithm_t, void **ctx);
typedef int (*gnutls_mac_setkey_func)(void *ctx, const void *key,
size_t keysize);
typedef int (*gnutls_mac_setnonce_func)(void *ctx, const void *nonce,
size_t noncesize);
typedef int (*gnutls_mac_hash_func)(void *ctx, const void *text,
size_t textsize);
typedef int (*gnutls_mac_output_func)(void *src_ctx, void *digest,
size_t digestsize);
typedef void (*gnutls_mac_deinit_func)(void *ctx);
typedef int (*gnutls_mac_fast_func)(gnutls_mac_algorithm_t, const void *nonce,
size_t nonce_size, const void *key,
size_t keysize, const void *text,
size_t textsize, void *digest);
typedef void *(*gnutls_mac_copy_func)(const void *ctx);
int gnutls_crypto_register_mac(
gnutls_mac_algorithm_t mac, int priority, gnutls_mac_init_func init,
gnutls_mac_setkey_func setkey, gnutls_mac_setnonce_func setnonce,
gnutls_mac_hash_func hash, gnutls_mac_output_func output,
gnutls_mac_deinit_func deinit,
gnutls_mac_fast_func hash_fast) _GNUTLS_GCC_ATTR_DEPRECATED;
typedef int (*gnutls_digest_init_func)(gnutls_digest_algorithm_t, void **ctx);
typedef int (*gnutls_digest_hash_func)(void *ctx, const void *text,
size_t textsize);
typedef int (*gnutls_digest_output_func)(void *src_ctx, void *digest,
size_t digestsize);
typedef void (*gnutls_digest_deinit_func)(void *ctx);
typedef int (*gnutls_digest_fast_func)(gnutls_digest_algorithm_t,
const void *text, size_t textsize,
void *digest);
typedef void *(*gnutls_digest_copy_func)(const void *ctx);
int gnutls_crypto_register_digest(
gnutls_digest_algorithm_t digest, int priority,
gnutls_digest_init_func init, gnutls_digest_hash_func hash,
gnutls_digest_output_func output, gnutls_digest_deinit_func deinit,
gnutls_digest_fast_func hash_fast) _GNUTLS_GCC_ATTR_DEPRECATED;
/* RSA-PKCS#1 1.5 helper functions */
int gnutls_encode_ber_digest_info(gnutls_digest_algorithm_t hash,
const gnutls_datum_t *digest,
gnutls_datum_t *output);
int gnutls_decode_ber_digest_info(const gnutls_datum_t *info,
gnutls_digest_algorithm_t *hash,
unsigned char *digest,
unsigned int *digest_size);
int gnutls_decode_rs_value(const gnutls_datum_t *sig_value, gnutls_datum_t *r,
gnutls_datum_t *s);
int gnutls_encode_rs_value(gnutls_datum_t *sig_value, const gnutls_datum_t *r,
const gnutls_datum_t *s);
int gnutls_encode_gost_rs_value(gnutls_datum_t *sig_value,
const gnutls_datum_t *r,
const gnutls_datum_t *s);
int gnutls_decode_gost_rs_value(const gnutls_datum_t *sig_value,
gnutls_datum_t *r, gnutls_datum_t *s);
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_CRYPTO_H */

View File

@ -0,0 +1,87 @@
/*
* Copyright (C) 2011-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
/* This file contains the types and prototypes for the X.509
* certificate and CRL handling functions.
*/
#ifndef GNUTLS_DTLS_H
#define GNUTLS_DTLS_H
#include <gnutls/gnutls.h>
#ifdef __cplusplus
extern "C" {
#endif
#define GNUTLS_COOKIE_KEY_SIZE 16
void gnutls_dtls_set_timeouts(gnutls_session_t session,
unsigned int retrans_timeout,
unsigned int total_timeout);
unsigned int gnutls_dtls_get_mtu(gnutls_session_t session);
unsigned int gnutls_dtls_get_data_mtu(gnutls_session_t session);
void gnutls_dtls_set_mtu(gnutls_session_t session, unsigned int mtu);
int gnutls_dtls_set_data_mtu(gnutls_session_t session, unsigned int mtu);
unsigned int gnutls_dtls_get_timeout(gnutls_session_t session);
/**
* gnutls_dtls_prestate_st:
* @record_seq: record sequence number
* @hsk_read_seq: handshake read sequence number
* @hsk_write_seq: handshake write sequence number
*
* DTLS cookie prestate struct. This is usually never modified by
* the application, it is used to carry the cookie data between
* gnutls_dtls_cookie_send(), gnutls_dtls_cookie_verify() and
* gnutls_dtls_prestate_set().
*/
typedef struct {
unsigned int record_seq;
unsigned int hsk_read_seq;
unsigned int hsk_write_seq;
} gnutls_dtls_prestate_st;
int gnutls_dtls_cookie_send(gnutls_datum_t *key, void *client_data,
size_t client_data_size,
gnutls_dtls_prestate_st *prestate,
gnutls_transport_ptr_t ptr,
gnutls_push_func push_func);
int gnutls_dtls_cookie_verify(gnutls_datum_t *key, void *client_data,
size_t client_data_size, void *_msg,
size_t msg_size,
gnutls_dtls_prestate_st *prestate);
void gnutls_dtls_prestate_set(gnutls_session_t session,
gnutls_dtls_prestate_st *prestate);
unsigned int gnutls_record_get_discarded(gnutls_session_t session);
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_DTLS_H */

View File

@ -0,0 +1,261 @@
/*
* Copyright (C) 2011-2012 Free Software Foundation, Inc.
*
* Author: Simon Josefsson
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
/* Online Certificate Status Protocol - RFC 2560
*/
#ifndef GNUTLS_OCSP_H
#define GNUTLS_OCSP_H
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#ifdef __cplusplus
extern "C" {
#endif
#define GNUTLS_OCSP_NONCE "1.3.6.1.5.5.7.48.1.2"
/**
* gnutls_ocsp_print_formats_t:
* @GNUTLS_OCSP_PRINT_FULL: Full information about OCSP request/response.
* @GNUTLS_OCSP_PRINT_COMPACT: More compact information about OCSP request/response.
*
* Enumeration of different OCSP printing variants.
*/
typedef enum gnutls_ocsp_print_formats_t {
GNUTLS_OCSP_PRINT_FULL = 0,
GNUTLS_OCSP_PRINT_COMPACT = 1
} gnutls_ocsp_print_formats_t;
/**
* gnutls_ocsp_resp_status_t:
* @GNUTLS_OCSP_RESP_SUCCESSFUL: Response has valid confirmations.
* @GNUTLS_OCSP_RESP_MALFORMEDREQUEST: Illegal confirmation request
* @GNUTLS_OCSP_RESP_INTERNALERROR: Internal error in issuer
* @GNUTLS_OCSP_RESP_TRYLATER: Try again later
* @GNUTLS_OCSP_RESP_SIGREQUIRED: Must sign the request
* @GNUTLS_OCSP_RESP_UNAUTHORIZED: Request unauthorized
*
* Enumeration of different OCSP response status codes.
*/
typedef enum gnutls_ocsp_resp_status_t {
GNUTLS_OCSP_RESP_SUCCESSFUL = 0,
GNUTLS_OCSP_RESP_MALFORMEDREQUEST = 1,
GNUTLS_OCSP_RESP_INTERNALERROR = 2,
GNUTLS_OCSP_RESP_TRYLATER = 3,
GNUTLS_OCSP_RESP_SIGREQUIRED = 5,
GNUTLS_OCSP_RESP_UNAUTHORIZED = 6
} gnutls_ocsp_resp_status_t;
/**
* gnutls_ocsp_cert_status_t:
* @GNUTLS_OCSP_CERT_GOOD: Positive response to status inquiry.
* @GNUTLS_OCSP_CERT_REVOKED: Certificate has been revoked.
* @GNUTLS_OCSP_CERT_UNKNOWN: The responder doesn't know about the
* certificate.
*
* Enumeration of different OCSP response certificate status codes.
*/
typedef enum gnutls_ocsp_cert_status_t {
GNUTLS_OCSP_CERT_GOOD = 0,
GNUTLS_OCSP_CERT_REVOKED = 1,
GNUTLS_OCSP_CERT_UNKNOWN = 2
} gnutls_ocsp_cert_status_t;
/**
* gnutls_x509_crl_reason_t:
* @GNUTLS_X509_CRLREASON_UNSPECIFIED: Unspecified reason.
* @GNUTLS_X509_CRLREASON_KEYCOMPROMISE: Private key compromised.
* @GNUTLS_X509_CRLREASON_CACOMPROMISE: CA compromised.
* @GNUTLS_X509_CRLREASON_AFFILIATIONCHANGED: Affiliation has changed.
* @GNUTLS_X509_CRLREASON_SUPERSEDED: Certificate superseded.
* @GNUTLS_X509_CRLREASON_CESSATIONOFOPERATION: Operation has ceased.
* @GNUTLS_X509_CRLREASON_CERTIFICATEHOLD: Certificate is on hold.
* @GNUTLS_X509_CRLREASON_REMOVEFROMCRL: Will be removed from delta CRL.
* @GNUTLS_X509_CRLREASON_PRIVILEGEWITHDRAWN: Privilege withdrawn.
* @GNUTLS_X509_CRLREASON_AACOMPROMISE: AA compromised.
*
* Enumeration of different reason codes. Note that this
* corresponds to the CRLReason ASN.1 enumeration type, and not the
* ReasonFlags ASN.1 bit string.
*/
typedef enum gnutls_x509_crl_reason_t {
GNUTLS_X509_CRLREASON_UNSPECIFIED = 0,
GNUTLS_X509_CRLREASON_KEYCOMPROMISE = 1,
GNUTLS_X509_CRLREASON_CACOMPROMISE = 2,
GNUTLS_X509_CRLREASON_AFFILIATIONCHANGED = 3,
GNUTLS_X509_CRLREASON_SUPERSEDED = 4,
GNUTLS_X509_CRLREASON_CESSATIONOFOPERATION = 5,
GNUTLS_X509_CRLREASON_CERTIFICATEHOLD = 6,
GNUTLS_X509_CRLREASON_REMOVEFROMCRL = 8,
GNUTLS_X509_CRLREASON_PRIVILEGEWITHDRAWN = 9,
GNUTLS_X509_CRLREASON_AACOMPROMISE = 10
} gnutls_x509_crl_reason_t;
/* When adding a verify failure reason update:
* _gnutls_ocsp_verify_status_to_str()
*/
/**
* gnutls_ocsp_verify_reason_t:
* @GNUTLS_OCSP_VERIFY_SIGNER_NOT_FOUND: Signer cert not found.
* @GNUTLS_OCSP_VERIFY_SIGNER_KEYUSAGE_ERROR: Signer keyusage bits incorrect.
* @GNUTLS_OCSP_VERIFY_UNTRUSTED_SIGNER: Signer is not trusted.
* @GNUTLS_OCSP_VERIFY_INSECURE_ALGORITHM: Signature using insecure algorithm.
* @GNUTLS_OCSP_VERIFY_SIGNATURE_FAILURE: Signature mismatch.
* @GNUTLS_OCSP_VERIFY_CERT_NOT_ACTIVATED: Signer cert is not yet activated.
* @GNUTLS_OCSP_VERIFY_CERT_EXPIRED: Signer cert has expired.
*
* Enumeration of OCSP verify status codes, used by
* gnutls_ocsp_resp_verify() and gnutls_ocsp_resp_verify_direct().
*/
typedef enum gnutls_ocsp_verify_reason_t {
GNUTLS_OCSP_VERIFY_SIGNER_NOT_FOUND = 1,
GNUTLS_OCSP_VERIFY_SIGNER_KEYUSAGE_ERROR = 2,
GNUTLS_OCSP_VERIFY_UNTRUSTED_SIGNER = 4,
GNUTLS_OCSP_VERIFY_INSECURE_ALGORITHM = 8,
GNUTLS_OCSP_VERIFY_SIGNATURE_FAILURE = 16,
GNUTLS_OCSP_VERIFY_CERT_NOT_ACTIVATED = 32,
GNUTLS_OCSP_VERIFY_CERT_EXPIRED = 64
} gnutls_ocsp_verify_reason_t;
struct gnutls_ocsp_req_int;
typedef struct gnutls_ocsp_req_int *gnutls_ocsp_req_t;
typedef const struct gnutls_ocsp_req_int *gnutls_ocsp_req_const_t;
int gnutls_ocsp_req_init(gnutls_ocsp_req_t *req);
void gnutls_ocsp_req_deinit(gnutls_ocsp_req_t req);
int gnutls_ocsp_req_import(gnutls_ocsp_req_t req, const gnutls_datum_t *data);
int gnutls_ocsp_req_export(gnutls_ocsp_req_const_t req, gnutls_datum_t *data);
int gnutls_ocsp_req_print(gnutls_ocsp_req_const_t req,
gnutls_ocsp_print_formats_t format,
gnutls_datum_t *out);
int gnutls_ocsp_req_get_version(gnutls_ocsp_req_const_t req);
int gnutls_ocsp_req_get_cert_id(gnutls_ocsp_req_const_t req, unsigned indx,
gnutls_digest_algorithm_t *digest,
gnutls_datum_t *issuer_name_hash,
gnutls_datum_t *issuer_key_hash,
gnutls_datum_t *serial_number);
int gnutls_ocsp_req_add_cert_id(gnutls_ocsp_req_t req,
gnutls_digest_algorithm_t digest,
const gnutls_datum_t *issuer_name_hash,
const gnutls_datum_t *issuer_key_hash,
const gnutls_datum_t *serial_number);
int gnutls_ocsp_req_add_cert(gnutls_ocsp_req_t req,
gnutls_digest_algorithm_t digest,
gnutls_x509_crt_t issuer, gnutls_x509_crt_t cert);
int gnutls_ocsp_req_get_extension(gnutls_ocsp_req_const_t req, unsigned indx,
gnutls_datum_t *oid, unsigned int *critical,
gnutls_datum_t *data);
int gnutls_ocsp_req_set_extension(gnutls_ocsp_req_t req, const char *oid,
unsigned int critical,
const gnutls_datum_t *data);
int gnutls_ocsp_req_get_nonce(gnutls_ocsp_req_const_t req,
unsigned int *critical, gnutls_datum_t *nonce);
int gnutls_ocsp_req_set_nonce(gnutls_ocsp_req_t req, unsigned int critical,
const gnutls_datum_t *nonce);
int gnutls_ocsp_req_randomize_nonce(gnutls_ocsp_req_t req);
struct gnutls_ocsp_resp_int;
typedef struct gnutls_ocsp_resp_int *gnutls_ocsp_resp_t;
typedef const struct gnutls_ocsp_resp_int *gnutls_ocsp_resp_const_t;
int gnutls_ocsp_resp_init(gnutls_ocsp_resp_t *resp);
void gnutls_ocsp_resp_deinit(gnutls_ocsp_resp_t resp);
int gnutls_ocsp_resp_import(gnutls_ocsp_resp_t resp,
const gnutls_datum_t *data);
int gnutls_ocsp_resp_import2(gnutls_ocsp_resp_t resp,
const gnutls_datum_t *data,
gnutls_x509_crt_fmt_t fmt);
int gnutls_ocsp_resp_export(gnutls_ocsp_resp_const_t resp,
gnutls_datum_t *data);
int gnutls_ocsp_resp_export2(gnutls_ocsp_resp_const_t resp,
gnutls_datum_t *data, gnutls_x509_crt_fmt_t fmt);
int gnutls_ocsp_resp_print(gnutls_ocsp_resp_const_t resp,
gnutls_ocsp_print_formats_t format,
gnutls_datum_t *out);
int gnutls_ocsp_resp_get_status(gnutls_ocsp_resp_const_t resp);
int gnutls_ocsp_resp_get_response(gnutls_ocsp_resp_const_t resp,
gnutls_datum_t *response_type_oid,
gnutls_datum_t *response);
int gnutls_ocsp_resp_get_version(gnutls_ocsp_resp_const_t resp);
int gnutls_ocsp_resp_get_responder(gnutls_ocsp_resp_const_t resp,
gnutls_datum_t *dn);
int gnutls_ocsp_resp_get_responder2(gnutls_ocsp_resp_const_t resp,
gnutls_datum_t *dn, unsigned flags);
/* the raw key ID of the responder */
#define GNUTLS_OCSP_RESP_ID_KEY 1
/* the raw DN of the responder */
#define GNUTLS_OCSP_RESP_ID_DN 2
int gnutls_ocsp_resp_get_responder_raw_id(gnutls_ocsp_resp_const_t resp,
unsigned type, gnutls_datum_t *raw);
time_t gnutls_ocsp_resp_get_produced(gnutls_ocsp_resp_const_t resp);
int gnutls_ocsp_resp_get_single(gnutls_ocsp_resp_const_t resp, unsigned indx,
gnutls_digest_algorithm_t *digest,
gnutls_datum_t *issuer_name_hash,
gnutls_datum_t *issuer_key_hash,
gnutls_datum_t *serial_number,
unsigned int *cert_status, time_t *this_update,
time_t *next_update, time_t *revocation_time,
unsigned int *revocation_reason);
int gnutls_ocsp_resp_get_extension(gnutls_ocsp_resp_const_t resp, unsigned indx,
gnutls_datum_t *oid, unsigned int *critical,
gnutls_datum_t *data);
int gnutls_ocsp_resp_get_nonce(gnutls_ocsp_resp_const_t resp,
unsigned int *critical, gnutls_datum_t *nonce);
int gnutls_ocsp_resp_get_signature_algorithm(gnutls_ocsp_resp_const_t resp);
int gnutls_ocsp_resp_get_signature(gnutls_ocsp_resp_const_t resp,
gnutls_datum_t *sig);
int gnutls_ocsp_resp_get_certs(gnutls_ocsp_resp_const_t resp,
gnutls_x509_crt_t **certs, size_t *ncerts);
int gnutls_ocsp_resp_verify_direct(gnutls_ocsp_resp_const_t resp,
gnutls_x509_crt_t issuer,
unsigned int *verify, unsigned int flags);
int gnutls_ocsp_resp_verify(gnutls_ocsp_resp_const_t resp,
gnutls_x509_trust_list_t trustlist,
unsigned int *verify, unsigned int flags);
int gnutls_ocsp_resp_check_crt(gnutls_ocsp_resp_const_t resp, unsigned int indx,
gnutls_x509_crt_t crt);
int gnutls_ocsp_resp_list_import2(gnutls_ocsp_resp_t **ocsps,
unsigned int *size,
const gnutls_datum_t *resp_data,
gnutls_x509_crt_fmt_t format,
unsigned int flags);
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_OCSP_H */

View File

@ -0,0 +1,366 @@
/*
* Copyright (C) 2003-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
/* This file contains the types and prototypes for the OpenPGP
* key and private key parsing functions.
*/
#ifndef GNUTLS_OPENPGP_H
#define GNUTLS_OPENPGP_H
#include <gnutls/gnutls.h>
#include <limits.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Openpgp certificate stuff
*/
/**
* gnutls_openpgp_crt_fmt_t:
* @GNUTLS_OPENPGP_FMT_RAW: OpenPGP certificate in raw format.
* @GNUTLS_OPENPGP_FMT_BASE64: OpenPGP certificate in base64 format.
*
* Enumeration of different OpenPGP key formats.
*/
typedef enum gnutls_openpgp_crt_fmt {
GNUTLS_OPENPGP_FMT_RAW,
GNUTLS_OPENPGP_FMT_BASE64
} gnutls_openpgp_crt_fmt_t;
#define GNUTLS_OPENPGP_KEYID_SIZE 8
#define GNUTLS_OPENPGP_V4_FINGERPRINT_SIZE 20
typedef unsigned char gnutls_openpgp_keyid_t[GNUTLS_OPENPGP_KEYID_SIZE];
/* gnutls_openpgp_cert_t should be defined in gnutls.h
*/
/* initializes the memory for gnutls_openpgp_crt_t struct */
int gnutls_openpgp_crt_init(gnutls_openpgp_crt_t *key)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* frees all memory */
void gnutls_openpgp_crt_deinit(gnutls_openpgp_crt_t key)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_import(
gnutls_openpgp_crt_t key, const gnutls_datum_t *data,
gnutls_openpgp_crt_fmt_t format) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_export(gnutls_openpgp_crt_t key,
gnutls_openpgp_crt_fmt_t format,
void *output_data, size_t *output_data_size)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_export2(gnutls_openpgp_crt_t key,
gnutls_openpgp_crt_fmt_t format,
gnutls_datum_t *out) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_print(gnutls_openpgp_crt_t cert,
gnutls_certificate_print_formats_t format,
gnutls_datum_t *out) _GNUTLS_GCC_ATTR_DEPRECATED;
/* The key_usage flags are defined in gnutls.h. They are
* the GNUTLS_KEY_* definitions.
*/
#define GNUTLS_OPENPGP_MASTER_KEYID_IDX INT_MAX
int gnutls_openpgp_crt_get_key_usage(gnutls_openpgp_crt_t key,
unsigned int *key_usage)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_fingerprint(gnutls_openpgp_crt_t key, void *fpr,
size_t *fprlen)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_subkey_fingerprint(
gnutls_openpgp_crt_t key, unsigned int idx, void *fpr,
size_t *fprlen) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_name(gnutls_openpgp_crt_t key, int idx, char *buf,
size_t *sizeof_buf) _GNUTLS_GCC_ATTR_DEPRECATED;
gnutls_pk_algorithm_t gnutls_openpgp_crt_get_pk_algorithm(
gnutls_openpgp_crt_t key,
unsigned int *bits) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_version(gnutls_openpgp_crt_t key)
_GNUTLS_GCC_ATTR_DEPRECATED;
time_t gnutls_openpgp_crt_get_creation_time(gnutls_openpgp_crt_t key)
_GNUTLS_GCC_ATTR_DEPRECATED;
time_t gnutls_openpgp_crt_get_expiration_time(gnutls_openpgp_crt_t key)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_key_id(gnutls_openpgp_crt_t key,
gnutls_openpgp_keyid_t keyid)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_check_hostname(gnutls_openpgp_crt_t key,
const char *hostname)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_check_hostname2(gnutls_openpgp_crt_t key,
const char *hostname, unsigned int flags)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_check_email(gnutls_openpgp_crt_t key, const char *email,
unsigned flags) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_revoked_status(gnutls_openpgp_crt_t key)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_subkey_count(gnutls_openpgp_crt_t key)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_subkey_idx(gnutls_openpgp_crt_t key,
const gnutls_openpgp_keyid_t keyid)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_subkey_revoked_status(
gnutls_openpgp_crt_t key, unsigned int idx) _GNUTLS_GCC_ATTR_DEPRECATED;
gnutls_pk_algorithm_t gnutls_openpgp_crt_get_subkey_pk_algorithm(
gnutls_openpgp_crt_t key, unsigned int idx,
unsigned int *bits) _GNUTLS_GCC_ATTR_DEPRECATED;
time_t gnutls_openpgp_crt_get_subkey_creation_time(
gnutls_openpgp_crt_t key, unsigned int idx) _GNUTLS_GCC_ATTR_DEPRECATED;
time_t gnutls_openpgp_crt_get_subkey_expiration_time(
gnutls_openpgp_crt_t key, unsigned int idx) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_subkey_id(gnutls_openpgp_crt_t key, unsigned int idx,
gnutls_openpgp_keyid_t keyid)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_subkey_usage(
gnutls_openpgp_crt_t key, unsigned int idx,
unsigned int *key_usage) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_subkey_pk_dsa_raw(
gnutls_openpgp_crt_t crt, unsigned int idx, gnutls_datum_t *p,
gnutls_datum_t *q, gnutls_datum_t *g,
gnutls_datum_t *y) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_subkey_pk_rsa_raw(
gnutls_openpgp_crt_t crt, unsigned int idx, gnutls_datum_t *m,
gnutls_datum_t *e) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_pk_dsa_raw(
gnutls_openpgp_crt_t crt, gnutls_datum_t *p, gnutls_datum_t *q,
gnutls_datum_t *g, gnutls_datum_t *y) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_pk_rsa_raw(gnutls_openpgp_crt_t crt,
gnutls_datum_t *m, gnutls_datum_t *e)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_preferred_key_id(gnutls_openpgp_crt_t key,
gnutls_openpgp_keyid_t keyid)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_set_preferred_key_id(gnutls_openpgp_crt_t key,
const gnutls_openpgp_keyid_t keyid)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* privkey stuff.
*/
int gnutls_openpgp_privkey_init(gnutls_openpgp_privkey_t *key)
_GNUTLS_GCC_ATTR_DEPRECATED;
void gnutls_openpgp_privkey_deinit(gnutls_openpgp_privkey_t key)
_GNUTLS_GCC_ATTR_DEPRECATED;
gnutls_pk_algorithm_t gnutls_openpgp_privkey_get_pk_algorithm(
gnutls_openpgp_privkey_t key,
unsigned int *bits) _GNUTLS_GCC_ATTR_DEPRECATED;
gnutls_sec_param_t gnutls_openpgp_privkey_sec_param(
gnutls_openpgp_privkey_t key) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_import(
gnutls_openpgp_privkey_t key, const gnutls_datum_t *data,
gnutls_openpgp_crt_fmt_t format, const char *password,
unsigned int flags) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_get_fingerprint(gnutls_openpgp_privkey_t key,
void *fpr, size_t *fprlen)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_get_subkey_fingerprint(
gnutls_openpgp_privkey_t key, unsigned int idx, void *fpr,
size_t *fprlen) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_get_key_id(gnutls_openpgp_privkey_t key,
gnutls_openpgp_keyid_t keyid)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_get_subkey_count(gnutls_openpgp_privkey_t key)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_get_subkey_idx(gnutls_openpgp_privkey_t key,
const gnutls_openpgp_keyid_t keyid)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_get_subkey_revoked_status(
gnutls_openpgp_privkey_t key,
unsigned int idx) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_get_revoked_status(gnutls_openpgp_privkey_t key)
_GNUTLS_GCC_ATTR_DEPRECATED;
gnutls_pk_algorithm_t gnutls_openpgp_privkey_get_subkey_pk_algorithm(
gnutls_openpgp_privkey_t key, unsigned int idx,
unsigned int *bits) _GNUTLS_GCC_ATTR_DEPRECATED;
time_t gnutls_openpgp_privkey_get_subkey_expiration_time(
gnutls_openpgp_privkey_t key,
unsigned int idx) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_get_subkey_id(
gnutls_openpgp_privkey_t key, unsigned int idx,
gnutls_openpgp_keyid_t keyid) _GNUTLS_GCC_ATTR_DEPRECATED;
time_t gnutls_openpgp_privkey_get_subkey_creation_time(
gnutls_openpgp_privkey_t key,
unsigned int idx) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_export_subkey_dsa_raw(
gnutls_openpgp_privkey_t pkey, unsigned int idx, gnutls_datum_t *p,
gnutls_datum_t *q, gnutls_datum_t *g, gnutls_datum_t *y,
gnutls_datum_t *x) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_export_subkey_rsa_raw(
gnutls_openpgp_privkey_t pkey, unsigned int idx, gnutls_datum_t *m,
gnutls_datum_t *e, gnutls_datum_t *d, gnutls_datum_t *p,
gnutls_datum_t *q, gnutls_datum_t *u) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_export_dsa_raw(
gnutls_openpgp_privkey_t pkey, gnutls_datum_t *p, gnutls_datum_t *q,
gnutls_datum_t *g, gnutls_datum_t *y,
gnutls_datum_t *x) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_export_rsa_raw(
gnutls_openpgp_privkey_t pkey, gnutls_datum_t *m, gnutls_datum_t *e,
gnutls_datum_t *d, gnutls_datum_t *p, gnutls_datum_t *q,
gnutls_datum_t *u) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_export(
gnutls_openpgp_privkey_t key, gnutls_openpgp_crt_fmt_t format,
const char *password, unsigned int flags, void *output_data,
size_t *output_data_size) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_export2(
gnutls_openpgp_privkey_t key, gnutls_openpgp_crt_fmt_t format,
const char *password, unsigned int flags,
gnutls_datum_t *out) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_set_preferred_key_id(
gnutls_openpgp_privkey_t key,
const gnutls_openpgp_keyid_t keyid) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_privkey_get_preferred_key_id(gnutls_openpgp_privkey_t key,
gnutls_openpgp_keyid_t keyid)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_get_auth_subkey(
gnutls_openpgp_crt_t crt, gnutls_openpgp_keyid_t keyid,
unsigned int flag) _GNUTLS_GCC_ATTR_DEPRECATED;
/* Keyring stuff.
*/
int gnutls_openpgp_keyring_init(gnutls_openpgp_keyring_t *keyring)
_GNUTLS_GCC_ATTR_DEPRECATED;
void gnutls_openpgp_keyring_deinit(gnutls_openpgp_keyring_t keyring)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_keyring_import(
gnutls_openpgp_keyring_t keyring, const gnutls_datum_t *data,
gnutls_openpgp_crt_fmt_t format) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_keyring_check_id(
gnutls_openpgp_keyring_t ring, const gnutls_openpgp_keyid_t keyid,
unsigned int flags) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_verify_ring(gnutls_openpgp_crt_t key,
gnutls_openpgp_keyring_t keyring,
unsigned int flags, unsigned int *verify
/* the output of the verification */
) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_crt_verify_self(gnutls_openpgp_crt_t key, unsigned int flags,
unsigned int *verify)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_keyring_get_crt(gnutls_openpgp_keyring_t ring,
unsigned int idx, gnutls_openpgp_crt_t *cert)
_GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_openpgp_keyring_get_crt_count(gnutls_openpgp_keyring_t ring)
_GNUTLS_GCC_ATTR_DEPRECATED;
/**
* gnutls_openpgp_recv_key_func:
* @session: a TLS session
* @keyfpr: key fingerprint
* @keyfpr_length: length of key fingerprint
* @key: output key.
*
* A callback of this type is used to retrieve OpenPGP keys. Only
* useful on the server, and will only be used if the peer send a key
* fingerprint instead of a full key. See also
* gnutls_openpgp_set_recv_key_function().
*
* The variable @key must be allocated using gnutls_malloc().
*
* Returns: On success, %GNUTLS_E_SUCCESS (zero) is returned,
* otherwise an error code is returned.
*/
typedef int (*gnutls_openpgp_recv_key_func)(gnutls_session_t session,
const unsigned char *keyfpr,
unsigned int keyfpr_length,
gnutls_datum_t *key);
void gnutls_openpgp_set_recv_key_function(gnutls_session_t session,
gnutls_openpgp_recv_key_func func)
_GNUTLS_GCC_ATTR_DEPRECATED;
/* certificate authentication stuff.
*/
int gnutls_certificate_set_openpgp_key(
gnutls_certificate_credentials_t res, gnutls_openpgp_crt_t crt,
gnutls_openpgp_privkey_t pkey) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_certificate_get_openpgp_key(
gnutls_certificate_credentials_t res, unsigned index,
gnutls_openpgp_privkey_t *key) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_certificate_get_openpgp_crt(
gnutls_certificate_credentials_t res, unsigned index,
gnutls_openpgp_crt_t **crt_list,
unsigned *crt_list_size) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_certificate_set_openpgp_key_file(
gnutls_certificate_credentials_t res, const char *certfile,
const char *keyfile,
gnutls_openpgp_crt_fmt_t format) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_certificate_set_openpgp_key_mem(
gnutls_certificate_credentials_t res, const gnutls_datum_t *cert,
const gnutls_datum_t *key,
gnutls_openpgp_crt_fmt_t format) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_certificate_set_openpgp_key_file2(
gnutls_certificate_credentials_t res, const char *certfile,
const char *keyfile, const char *subkey_id,
gnutls_openpgp_crt_fmt_t format) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_certificate_set_openpgp_key_mem2(
gnutls_certificate_credentials_t res, const gnutls_datum_t *cert,
const gnutls_datum_t *key, const char *subkey_id,
gnutls_openpgp_crt_fmt_t format) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_certificate_set_openpgp_keyring_mem(
gnutls_certificate_credentials_t c, const unsigned char *data,
size_t dlen,
gnutls_openpgp_crt_fmt_t format) _GNUTLS_GCC_ATTR_DEPRECATED;
int gnutls_certificate_set_openpgp_keyring_file(
gnutls_certificate_credentials_t c, const char *file,
gnutls_openpgp_crt_fmt_t format) _GNUTLS_GCC_ATTR_DEPRECATED;
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_OPENPGP_H */

View File

@ -0,0 +1,491 @@
/*
* Copyright (C) 2010-2012 Free Software Foundation, Inc.
* Copyright (C) 2016-2018 Red Hat, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLS_PKCS11_H
#define GNUTLS_PKCS11_H
#include <stdarg.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#ifdef __cplusplus
extern "C" {
#endif
#define GNUTLS_PKCS11_MAX_PIN_LEN 256
/**
* gnutls_pkcs11_token_callback_t:
* @userdata: user-controlled data from gnutls_pkcs11_set_token_function().
* @label: token label.
* @retry: retry counter, initially 0.
*
* Token callback function. The callback will be used to ask the user
* to re-insert the token with given (null terminated) label. The
* callback should return zero if token has been inserted by user and
* a negative error code otherwise. It might be called multiple times
* if the token is not detected and the retry counter will be
* increased.
*
* Returns: %GNUTLS_E_SUCCESS (0) on success or a negative error code
* on error.
*
* Since: 2.12.0
**/
typedef int (*gnutls_pkcs11_token_callback_t)(void *const userdata,
const char *const label,
unsigned retry);
struct gnutls_pkcs11_obj_st;
typedef struct gnutls_pkcs11_obj_st *gnutls_pkcs11_obj_t;
#define GNUTLS_PKCS11_FLAG_MANUAL 0 /* Manual loading of libraries */
#define GNUTLS_PKCS11_FLAG_AUTO \
1 /* Automatically load libraries by reading /etc/gnutls/pkcs11.conf */
#define GNUTLS_PKCS11_FLAG_AUTO_TRUSTED \
(1 \
<< 1) /* Automatically load trusted libraries by reading /etc/gnutls/pkcs11.conf */
/* pkcs11.conf format:
* load = /lib/xxx-pkcs11.so
* load = /lib/yyy-pkcs11.so
*/
int gnutls_pkcs11_init(unsigned int flags, const char *deprecated_config_file);
int gnutls_pkcs11_reinit(void);
void gnutls_pkcs11_deinit(void);
void gnutls_pkcs11_set_token_function(gnutls_pkcs11_token_callback_t fn,
void *userdata);
void gnutls_pkcs11_set_pin_function(gnutls_pin_callback_t fn, void *userdata);
gnutls_pin_callback_t gnutls_pkcs11_get_pin_function(void **userdata);
int gnutls_pkcs11_add_provider(const char *name, const char *params);
int gnutls_pkcs11_obj_init(gnutls_pkcs11_obj_t *obj);
void gnutls_pkcs11_obj_set_pin_function(gnutls_pkcs11_obj_t obj,
gnutls_pin_callback_t fn,
void *userdata);
/**
* gnutls_pkcs11_obj_flags:
* @GNUTLS_PKCS11_OBJ_FLAG_LOGIN: Force login in the token for the operation (seek+store).
* @GNUTLS_PKCS11_OBJ_FLAG_MARK_TRUSTED: object marked as trusted (seek+store).
* @GNUTLS_PKCS11_OBJ_FLAG_MARK_SENSITIVE: object is explicitly marked as sensitive -unexportable (store).
* @GNUTLS_PKCS11_OBJ_FLAG_LOGIN_SO: force login as a security officer in the token for the operation (seek+store).
* @GNUTLS_PKCS11_OBJ_FLAG_MARK_PRIVATE: marked as private -requires PIN to access (store).
* @GNUTLS_PKCS11_OBJ_FLAG_MARK_NOT_PRIVATE: marked as not private (store).
* @GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_ANY: When retrieving an object, do not set any requirements (store).
* @GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_TRUSTED: When retrieving an object, only retrieve the marked as trusted (alias to %GNUTLS_PKCS11_OBJ_FLAG_MARK_TRUSTED).
* In gnutls_pkcs11_crt_is_known() it implies %GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_COMPARE if %GNUTLS_PKCS11_OBJ_FLAG_COMPARE_KEY is not given.
* @GNUTLS_PKCS11_OBJ_FLAG_MARK_DISTRUSTED: When writing an object, mark it as distrusted (store).
* @GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_DISTRUSTED: When retrieving an object, only retrieve the marked as distrusted (seek).
* @GNUTLS_PKCS11_OBJ_FLAG_COMPARE: When checking an object's presence, fully compare it before returning any result (seek).
* @GNUTLS_PKCS11_OBJ_FLAG_COMPARE_KEY: When checking an object's presence, compare the key before returning any result (seek).
* @GNUTLS_PKCS11_OBJ_FLAG_PRESENT_IN_TRUSTED_MODULE: The object must be present in a marked as trusted module (seek).
* @GNUTLS_PKCS11_OBJ_FLAG_MARK_CA: Mark the object as a CA (seek+store).
* @GNUTLS_PKCS11_OBJ_FLAG_MARK_KEY_WRAP: Mark the generated key pair as wrapping and unwrapping keys (store).
* @GNUTLS_PKCS11_OBJ_FLAG_OVERWRITE_TRUSTMOD_EXT: When an issuer is requested, override its extensions with the ones present in the trust module (seek).
* @GNUTLS_PKCS11_OBJ_FLAG_MARK_ALWAYS_AUTH: Mark the key pair as requiring authentication (pin entry) before every operation (seek+store).
* @GNUTLS_PKCS11_OBJ_FLAG_MARK_EXTRACTABLE: Mark the key pair as being extractable (store).
* @GNUTLS_PKCS11_OBJ_FLAG_NEVER_EXTRACTABLE: If set, the object was never marked as extractable (store).
* @GNUTLS_PKCS11_OBJ_FLAG_CRT: When searching, restrict to certificates only (seek).
* @GNUTLS_PKCS11_OBJ_FLAG_PUBKEY: When searching, restrict to public key objects only (seek).
* @GNUTLS_PKCS11_OBJ_FLAG_PRIVKEY: When searching, restrict to private key objects only (seek).
* @GNUTLS_PKCS11_OBJ_FLAG_NO_STORE_PUBKEY: When generating a keypair don't store the public key (store).
* @GNUTLS_PKCS11_OBJ_FLAG_MARK_NOT_SENSITIVE: object marked as not sensitive -exportable (store).
*
* Enumeration of different PKCS #11 object flags. Some flags are used
* to mark objects when storing, while others are also used while seeking
* or retrieving objects.
*/
typedef enum gnutls_pkcs11_obj_flags {
GNUTLS_PKCS11_OBJ_FLAG_LOGIN = (1 << 0),
GNUTLS_PKCS11_OBJ_FLAG_MARK_TRUSTED = (1 << 1),
GNUTLS_PKCS11_OBJ_FLAG_MARK_SENSITIVE = (1 << 2),
GNUTLS_PKCS11_OBJ_FLAG_LOGIN_SO = (1 << 3),
GNUTLS_PKCS11_OBJ_FLAG_MARK_PRIVATE = (1 << 4),
GNUTLS_PKCS11_OBJ_FLAG_MARK_NOT_PRIVATE = (1 << 5),
GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_ANY = (1 << 6),
GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_TRUSTED =
GNUTLS_PKCS11_OBJ_FLAG_MARK_TRUSTED,
GNUTLS_PKCS11_OBJ_FLAG_MARK_DISTRUSTED = (1 << 8),
GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_DISTRUSTED =
GNUTLS_PKCS11_OBJ_FLAG_MARK_DISTRUSTED,
GNUTLS_PKCS11_OBJ_FLAG_COMPARE = (1 << 9),
GNUTLS_PKCS11_OBJ_FLAG_PRESENT_IN_TRUSTED_MODULE = (1 << 10),
GNUTLS_PKCS11_OBJ_FLAG_MARK_CA = (1 << 11),
GNUTLS_PKCS11_OBJ_FLAG_MARK_KEY_WRAP = (1 << 12),
GNUTLS_PKCS11_OBJ_FLAG_COMPARE_KEY = (1 << 13),
GNUTLS_PKCS11_OBJ_FLAG_OVERWRITE_TRUSTMOD_EXT = (1 << 14),
GNUTLS_PKCS11_OBJ_FLAG_MARK_ALWAYS_AUTH = (1 << 15),
GNUTLS_PKCS11_OBJ_FLAG_MARK_EXTRACTABLE = (1 << 16),
GNUTLS_PKCS11_OBJ_FLAG_NEVER_EXTRACTABLE = (1 << 17),
GNUTLS_PKCS11_OBJ_FLAG_CRT = (1 << 18),
GNUTLS_PKCS11_OBJ_FLAG_WITH_PRIVKEY = (1 << 19),
GNUTLS_PKCS11_OBJ_FLAG_PUBKEY = (1 << 20),
GNUTLS_PKCS11_OBJ_FLAG_NO_STORE_PUBKEY = GNUTLS_PKCS11_OBJ_FLAG_PUBKEY,
GNUTLS_PKCS11_OBJ_FLAG_PRIVKEY = (1 << 21),
GNUTLS_PKCS11_OBJ_FLAG_MARK_NOT_SENSITIVE = (1 << 22),
/* flags 1<<29 and later are reserved - see pkcs11_int.h */
} gnutls_pkcs11_obj_flags;
#define gnutls_pkcs11_obj_attr_t gnutls_pkcs11_obj_flags
/**
* gnutls_pkcs11_url_type_t:
* @GNUTLS_PKCS11_URL_GENERIC: A generic-purpose URL.
* @GNUTLS_PKCS11_URL_LIB: A URL that specifies the library used as well.
* @GNUTLS_PKCS11_URL_LIB_VERSION: A URL that specifies the library and its version.
*
* Enumeration of different URL extraction flags.
*/
typedef enum {
GNUTLS_PKCS11_URL_GENERIC, /* URL specifies the object on token level */
GNUTLS_PKCS11_URL_LIB, /* URL specifies the object on module level */
GNUTLS_PKCS11_URL_LIB_VERSION /* URL specifies the object on module and version level */
} gnutls_pkcs11_url_type_t;
int gnutls_pkcs11_obj_import_url(gnutls_pkcs11_obj_t obj, const char *url,
unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */);
int gnutls_pkcs11_obj_export_url(gnutls_pkcs11_obj_t obj,
gnutls_pkcs11_url_type_t detailed, char **url);
void gnutls_pkcs11_obj_deinit(gnutls_pkcs11_obj_t obj);
int gnutls_pkcs11_obj_export(gnutls_pkcs11_obj_t obj, void *output_data,
size_t *output_data_size);
int gnutls_pkcs11_obj_export2(gnutls_pkcs11_obj_t obj, gnutls_datum_t *out);
int gnutls_pkcs11_obj_export3(gnutls_pkcs11_obj_t obj,
gnutls_x509_crt_fmt_t fmt, gnutls_datum_t *out);
int gnutls_pkcs11_get_raw_issuer(const char *url, gnutls_x509_crt_t cert,
gnutls_datum_t *issuer,
gnutls_x509_crt_fmt_t fmt, unsigned int flags);
int gnutls_pkcs11_get_raw_issuer_by_dn(const char *url,
const gnutls_datum_t *dn,
gnutls_datum_t *issuer,
gnutls_x509_crt_fmt_t fmt,
unsigned int flags);
int gnutls_pkcs11_get_raw_issuer_by_subject_key_id(
const char *url, const gnutls_datum_t *dn, const gnutls_datum_t *spki,
gnutls_datum_t *issuer, gnutls_x509_crt_fmt_t fmt, unsigned int flags);
unsigned gnutls_pkcs11_crt_is_known(const char *url, gnutls_x509_crt_t cert,
unsigned int flags);
#if 0
/* for documentation */
int gnutls_pkcs11_copy_x509_crt(const char *token_url,
gnutls_x509_crt_t crt,
const char *label, unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */ );
int gnutls_pkcs11_copy_x509_privkey(const char *token_url,
gnutls_x509_privkey_t key,
const char *label,
unsigned int key_usage, unsigned int flags);
int
gnutls_pkcs11_privkey_generate2(const char *url, gnutls_pk_algorithm_t pk,
unsigned int bits, const char *label,
gnutls_x509_crt_fmt_t fmt,
gnutls_datum_t * pubkey, unsigned int flags);
int
gnutls_pkcs11_privkey_generate(const char *url, gnutls_pk_algorithm_t pk,
unsigned int bits, const char *label,
unsigned int flags);
#endif
int gnutls_pkcs11_copy_pubkey(const char *token_url, gnutls_pubkey_t crt,
const char *label, const gnutls_datum_t *cid,
unsigned int key_usage, unsigned int flags);
#define gnutls_pkcs11_copy_x509_crt(url, crt, label, flags) \
gnutls_pkcs11_copy_x509_crt2(url, crt, label, NULL, flags)
int gnutls_pkcs11_copy_x509_crt2(const char *token_url, gnutls_x509_crt_t crt,
const char *label, const gnutls_datum_t *id,
unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */);
#define gnutls_pkcs11_copy_x509_privkey(url, key, label, usage, flags) \
gnutls_pkcs11_copy_x509_privkey2(url, key, label, NULL, usage, flags)
int gnutls_pkcs11_copy_x509_privkey2(const char *token_url,
gnutls_x509_privkey_t key,
const char *label,
const gnutls_datum_t *cid,
unsigned int key_usage
/*GNUTLS_KEY_* */,
unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */
);
int gnutls_pkcs11_delete_url(const char *object_url, unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */);
int gnutls_pkcs11_copy_secret_key(const char *token_url, gnutls_datum_t *key,
const char *label,
unsigned int key_usage
/* GNUTLS_KEY_* */,
unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */);
/**
* gnutls_pkcs11_obj_info_t:
* @GNUTLS_PKCS11_OBJ_ID_HEX: The object ID in hex. Null-terminated text.
* @GNUTLS_PKCS11_OBJ_LABEL: The object label. Null-terminated text.
* @GNUTLS_PKCS11_OBJ_TOKEN_LABEL: The token's label. Null-terminated text.
* @GNUTLS_PKCS11_OBJ_TOKEN_SERIAL: The token's serial number. Null-terminated text.
* @GNUTLS_PKCS11_OBJ_TOKEN_MANUFACTURER: The token's manufacturer. Null-terminated text.
* @GNUTLS_PKCS11_OBJ_TOKEN_MODEL: The token's model. Null-terminated text.
* @GNUTLS_PKCS11_OBJ_ID: The object ID. Raw bytes.
* @GNUTLS_PKCS11_OBJ_LIBRARY_VERSION: The library's version. Null-terminated text.
* @GNUTLS_PKCS11_OBJ_LIBRARY_DESCRIPTION: The library's description. Null-terminated text.
* @GNUTLS_PKCS11_OBJ_LIBRARY_MANUFACTURER: The library's manufacturer name. Null-terminated text.
*
* Enumeration of several object information types.
*/
typedef enum {
GNUTLS_PKCS11_OBJ_ID_HEX = 1,
GNUTLS_PKCS11_OBJ_LABEL,
GNUTLS_PKCS11_OBJ_TOKEN_LABEL,
GNUTLS_PKCS11_OBJ_TOKEN_SERIAL,
GNUTLS_PKCS11_OBJ_TOKEN_MANUFACTURER,
GNUTLS_PKCS11_OBJ_TOKEN_MODEL,
GNUTLS_PKCS11_OBJ_ID,
/* the pkcs11 provider library info */
GNUTLS_PKCS11_OBJ_LIBRARY_VERSION,
GNUTLS_PKCS11_OBJ_LIBRARY_DESCRIPTION,
GNUTLS_PKCS11_OBJ_LIBRARY_MANUFACTURER
} gnutls_pkcs11_obj_info_t;
int gnutls_pkcs11_obj_get_ptr(gnutls_pkcs11_obj_t obj, void **ptr,
void **session, void **ohandle,
unsigned long *slot_id, unsigned int flags);
int gnutls_pkcs11_obj_get_info(gnutls_pkcs11_obj_t obj,
gnutls_pkcs11_obj_info_t itype, void *output,
size_t *output_size);
int gnutls_pkcs11_obj_set_info(gnutls_pkcs11_obj_t obj,
gnutls_pkcs11_obj_info_t itype, const void *data,
size_t data_size, unsigned flags);
#define GNUTLS_PKCS11_OBJ_ATTR_CRT_ALL GNUTLS_PKCS11_OBJ_FLAG_CRT
#define GNUTLS_PKCS11_OBJ_ATTR_MATCH 0 /* always match the given URL */
#define GNUTLS_PKCS11_OBJ_ATTR_ALL 0 /* match everything! */
#define GNUTLS_PKCS11_OBJ_ATTR_CRT_TRUSTED \
(GNUTLS_PKCS11_OBJ_FLAG_CRT | GNUTLS_PKCS11_OBJ_FLAG_MARK_TRUSTED)
#define GNUTLS_PKCS11_OBJ_ATTR_CRT_WITH_PRIVKEY \
(GNUTLS_PKCS11_OBJ_FLAG_CRT | GNUTLS_PKCS11_OBJ_FLAG_WITH_PRIVKEY)
#define GNUTLS_PKCS11_OBJ_ATTR_CRT_TRUSTED_CA \
(GNUTLS_PKCS11_OBJ_FLAG_CRT | GNUTLS_PKCS11_OBJ_FLAG_MARK_CA | \
GNUTLS_PKCS11_OBJ_FLAG_MARK_TRUSTED)
#define GNUTLS_PKCS11_OBJ_ATTR_PUBKEY GNUTLS_PKCS11_OBJ_FLAG_PUBKEY
#define GNUTLS_PKCS11_OBJ_ATTR_PRIVKEY GNUTLS_PKCS11_OBJ_FLAG_PRIVKEY
/**
* gnutls_pkcs11_token_info_t:
* @GNUTLS_PKCS11_TOKEN_LABEL: The token's label (string)
* @GNUTLS_PKCS11_TOKEN_SERIAL: The token's serial number (string)
* @GNUTLS_PKCS11_TOKEN_MANUFACTURER: The token's manufacturer (string)
* @GNUTLS_PKCS11_TOKEN_MODEL: The token's model (string)
* @GNUTLS_PKCS11_TOKEN_MODNAME: The token's module name (string - since 3.4.3). This value is
* unavailable for providers which were manually loaded.
*
* Enumeration of types for retrieving token information.
*/
typedef enum {
GNUTLS_PKCS11_TOKEN_LABEL,
GNUTLS_PKCS11_TOKEN_SERIAL,
GNUTLS_PKCS11_TOKEN_MANUFACTURER,
GNUTLS_PKCS11_TOKEN_MODEL,
GNUTLS_PKCS11_TOKEN_MODNAME
} gnutls_pkcs11_token_info_t;
/**
* gnutls_pkcs11_obj_type_t:
* @GNUTLS_PKCS11_OBJ_UNKNOWN: Unknown PKCS11 object.
* @GNUTLS_PKCS11_OBJ_X509_CRT: X.509 certificate.
* @GNUTLS_PKCS11_OBJ_PUBKEY: Public key.
* @GNUTLS_PKCS11_OBJ_PRIVKEY: Private key.
* @GNUTLS_PKCS11_OBJ_SECRET_KEY: Secret key.
* @GNUTLS_PKCS11_OBJ_DATA: Data object.
* @GNUTLS_PKCS11_OBJ_X509_CRT_EXTENSION: X.509 certificate extension (supported by p11-kit trust module only).
*
* Enumeration of object types.
*/
typedef enum {
GNUTLS_PKCS11_OBJ_UNKNOWN,
GNUTLS_PKCS11_OBJ_X509_CRT,
GNUTLS_PKCS11_OBJ_PUBKEY,
GNUTLS_PKCS11_OBJ_PRIVKEY,
GNUTLS_PKCS11_OBJ_SECRET_KEY,
GNUTLS_PKCS11_OBJ_DATA,
GNUTLS_PKCS11_OBJ_X509_CRT_EXTENSION
} gnutls_pkcs11_obj_type_t;
int gnutls_pkcs11_token_init(const char *token_url, const char *so_pin,
const char *label);
int gnutls_pkcs11_token_get_ptr(const char *url, void **ptr,
unsigned long *slot_id, unsigned int flags);
int gnutls_pkcs11_token_get_mechanism(const char *url, unsigned int idx,
unsigned long *mechanism);
unsigned gnutls_pkcs11_token_check_mechanism(const char *url,
unsigned long mechanism, void *ptr,
unsigned psize, unsigned flags);
int gnutls_pkcs11_token_set_pin(const char *token_url, const char *oldpin,
const char *newpin,
unsigned int flags /*gnutls_pin_flag_t */);
int gnutls_pkcs11_token_get_url(unsigned int seq,
gnutls_pkcs11_url_type_t detailed, char **url);
int gnutls_pkcs11_token_get_info(const char *url,
gnutls_pkcs11_token_info_t ttype, void *output,
size_t *output_size);
#define GNUTLS_PKCS11_TOKEN_HW 1
#define GNUTLS_PKCS11_TOKEN_TRUSTED (1 << 1) /* p11-kit trusted */
#define GNUTLS_PKCS11_TOKEN_RNG (1 << 2) /* CKF_RNG */
#define GNUTLS_PKCS11_TOKEN_LOGIN_REQUIRED (1 << 3) /* CKF_LOGIN_REQUIRED */
#define GNUTLS_PKCS11_TOKEN_PROTECTED_AUTHENTICATION_PATH \
(1 << 4) /* CKF_PROTECTED_AUTHENTICATION_PATH */
#define GNUTLS_PKCS11_TOKEN_INITIALIZED (1 << 5) /* CKF_TOKEN_INITIALIZED */
#define GNUTLS_PKCS11_TOKEN_USER_PIN_COUNT_LOW \
(1 << 6) /* CKF_USER_PIN_COUNT_LOW */
#define GNUTLS_PKCS11_TOKEN_USER_PIN_FINAL_TRY \
(1 << 7) /* CKF_USER_PIN_FINAL_TRY */
#define GNUTLS_PKCS11_TOKEN_USER_PIN_LOCKED (1 << 8) /* CKF_USER_PIN_LOCKED */
#define GNUTLS_PKCS11_TOKEN_SO_PIN_COUNT_LOW (1 << 9) /* CKF_SO_PIN_COUNT_LOW */
#define GNUTLS_PKCS11_TOKEN_SO_PIN_FINAL_TRY \
(1 << 10) /* CKF_SO_PIN_FINAL_TRY */
#define GNUTLS_PKCS11_TOKEN_SO_PIN_LOCKED (1 << 11) /* CKF_SO_PIN_LOCKED */
#define GNUTLS_PKCS11_TOKEN_USER_PIN_INITIALIZED \
(1 << 12) /* CKF_USER_PIN_INITIALIZED */
#define GNUTLS_PKCS11_TOKEN_ERROR_STATE (1 << 13) /* CKF_ERROR_STATE */
int gnutls_pkcs11_token_get_flags(const char *url, unsigned int *flags);
#define gnutls_pkcs11_obj_list_import_url(p_list, n_list, url, attrs, flags) \
gnutls_pkcs11_obj_list_import_url3(p_list, n_list, url, attrs | flags)
#define gnutls_pkcs11_obj_list_import_url2(p_list, n_list, url, attrs, flags) \
gnutls_pkcs11_obj_list_import_url4(p_list, n_list, url, attrs | flags)
int gnutls_pkcs11_obj_list_import_url3(gnutls_pkcs11_obj_t *p_list,
unsigned int *const n_list,
const char *url, unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */
);
int gnutls_pkcs11_obj_list_import_url4(gnutls_pkcs11_obj_t **p_list,
unsigned int *n_list, const char *url,
unsigned int flags
/* GNUTLS_PKCS11_OBJ_FLAG_* */
);
int gnutls_x509_crt_import_pkcs11(gnutls_x509_crt_t crt,
gnutls_pkcs11_obj_t pkcs11_crt);
gnutls_pkcs11_obj_type_t gnutls_pkcs11_obj_get_type(gnutls_pkcs11_obj_t obj);
const char *gnutls_pkcs11_type_get_name(gnutls_pkcs11_obj_type_t type);
int gnutls_pkcs11_obj_get_exts(gnutls_pkcs11_obj_t obj,
struct gnutls_x509_ext_st **exts,
unsigned int *exts_size, unsigned int flags);
int gnutls_pkcs11_obj_get_flags(gnutls_pkcs11_obj_t obj, unsigned int *oflags);
char *gnutls_pkcs11_obj_flags_get_str(unsigned int flags);
int gnutls_x509_crt_list_import_pkcs11(gnutls_x509_crt_t *certs,
unsigned int cert_max,
gnutls_pkcs11_obj_t *const objs,
unsigned int flags
/* must be zero */);
/* private key functions...*/
int gnutls_pkcs11_privkey_init(gnutls_pkcs11_privkey_t *key);
int gnutls_pkcs11_privkey_cpy(gnutls_pkcs11_privkey_t dst,
gnutls_pkcs11_privkey_t src);
void gnutls_pkcs11_privkey_set_pin_function(gnutls_pkcs11_privkey_t key,
gnutls_pin_callback_t fn,
void *userdata);
void gnutls_pkcs11_privkey_deinit(gnutls_pkcs11_privkey_t key);
int gnutls_pkcs11_privkey_get_pk_algorithm(gnutls_pkcs11_privkey_t key,
unsigned int *bits);
int gnutls_pkcs11_privkey_get_info(gnutls_pkcs11_privkey_t pkey,
gnutls_pkcs11_obj_info_t itype, void *output,
size_t *output_size);
int gnutls_pkcs11_privkey_import_url(gnutls_pkcs11_privkey_t pkey,
const char *url, unsigned int flags);
int gnutls_pkcs11_privkey_export_url(gnutls_pkcs11_privkey_t key,
gnutls_pkcs11_url_type_t detailed,
char **url);
unsigned gnutls_pkcs11_privkey_status(gnutls_pkcs11_privkey_t key);
#define gnutls_pkcs11_privkey_generate(url, pk, bits, label, flags) \
gnutls_pkcs11_privkey_generate3(url, pk, bits, label, NULL, 0, NULL, \
0, flags)
#define gnutls_pkcs11_privkey_generate2(url, pk, bits, label, fmt, pubkey, \
flags) \
gnutls_pkcs11_privkey_generate3(url, pk, bits, label, NULL, fmt, \
pubkey, 0, flags)
int gnutls_pkcs11_privkey_generate3(const char *url, gnutls_pk_algorithm_t pk,
unsigned int bits, const char *label,
const gnutls_datum_t *cid,
gnutls_x509_crt_fmt_t fmt,
gnutls_datum_t *pubkey,
unsigned int key_usage, unsigned int flags);
int gnutls_pkcs11_privkey_export_pubkey(gnutls_pkcs11_privkey_t pkey,
gnutls_x509_crt_fmt_t fmt,
gnutls_datum_t *pubkey,
unsigned int flags);
int gnutls_pkcs11_token_get_random(const char *token_url, void *data,
size_t len);
int gnutls_pkcs11_copy_attached_extension(const char *token_url,
gnutls_x509_crt_t crt,
gnutls_datum_t *data,
const char *label,
unsigned int flags);
#define gnutls_x509_crt_import_pkcs11_url gnutls_x509_crt_import_url
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_PKCS11_H */

View File

@ -0,0 +1,138 @@
/*
* Copyright (C) 2003-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLS_PKCS12_H
#define GNUTLS_PKCS12_H
#include <gnutls/x509.h>
#ifdef __cplusplus
extern "C" {
#endif
/* PKCS12 structures handling
*/
struct gnutls_pkcs12_int;
typedef struct gnutls_pkcs12_int *gnutls_pkcs12_t;
struct gnutls_pkcs12_bag_int;
typedef struct gnutls_pkcs12_bag_int *gnutls_pkcs12_bag_t;
int gnutls_pkcs12_init(gnutls_pkcs12_t *pkcs12);
void gnutls_pkcs12_deinit(gnutls_pkcs12_t pkcs12);
int gnutls_pkcs12_import(gnutls_pkcs12_t pkcs12, const gnutls_datum_t *data,
gnutls_x509_crt_fmt_t format, unsigned int flags);
int gnutls_pkcs12_export(gnutls_pkcs12_t pkcs12, gnutls_x509_crt_fmt_t format,
void *output_data, size_t *output_data_size);
int gnutls_pkcs12_export2(gnutls_pkcs12_t pkcs12, gnutls_x509_crt_fmt_t format,
gnutls_datum_t *out);
int gnutls_pkcs12_get_bag(gnutls_pkcs12_t pkcs12, int indx,
gnutls_pkcs12_bag_t bag);
int gnutls_pkcs12_set_bag(gnutls_pkcs12_t pkcs12, gnutls_pkcs12_bag_t bag);
int gnutls_pkcs12_generate_mac(gnutls_pkcs12_t pkcs12, const char *pass);
int gnutls_pkcs12_generate_mac2(gnutls_pkcs12_t pkcs12,
gnutls_mac_algorithm_t mac, const char *pass);
int gnutls_pkcs12_verify_mac(gnutls_pkcs12_t pkcs12, const char *pass);
int gnutls_pkcs12_bag_decrypt(gnutls_pkcs12_bag_t bag, const char *pass);
int gnutls_pkcs12_bag_encrypt(gnutls_pkcs12_bag_t bag, const char *pass,
unsigned int flags);
int gnutls_pkcs12_bag_enc_info(gnutls_pkcs12_bag_t bag, unsigned int *schema,
unsigned int *cipher, void *salt,
unsigned int *salt_size,
unsigned int *iter_count, char **oid);
int gnutls_pkcs12_mac_info(gnutls_pkcs12_t pkcs12, unsigned int *mac,
void *salt, unsigned int *salt_size,
unsigned int *iter_count, char **oid);
#define GNUTLS_PKCS12_SP_INCLUDE_SELF_SIGNED 1
int gnutls_pkcs12_simple_parse(gnutls_pkcs12_t p12, const char *password,
gnutls_x509_privkey_t *key,
gnutls_x509_crt_t **chain,
unsigned int *chain_len,
gnutls_x509_crt_t **extra_certs,
unsigned int *extra_certs_len,
gnutls_x509_crl_t *crl, unsigned int flags);
/**
* gnutls_pkcs12_bag_type_t:
* @GNUTLS_BAG_EMPTY: Empty PKCS-12 bag.
* @GNUTLS_BAG_PKCS8_ENCRYPTED_KEY: PKCS-12 bag with PKCS-8 encrypted key.
* @GNUTLS_BAG_PKCS8_KEY: PKCS-12 bag with PKCS-8 key.
* @GNUTLS_BAG_CERTIFICATE: PKCS-12 bag with certificate.
* @GNUTLS_BAG_CRL: PKCS-12 bag with CRL.
* @GNUTLS_BAG_SECRET: PKCS-12 bag with secret PKCS-9 keys.
* @GNUTLS_BAG_ENCRYPTED: Encrypted PKCS-12 bag.
* @GNUTLS_BAG_UNKNOWN: Unknown PKCS-12 bag.
*
* Enumeration of different PKCS 12 bag types.
*/
typedef enum gnutls_pkcs12_bag_type_t {
GNUTLS_BAG_EMPTY = 0,
GNUTLS_BAG_PKCS8_ENCRYPTED_KEY = 1,
GNUTLS_BAG_PKCS8_KEY = 2,
GNUTLS_BAG_CERTIFICATE = 3,
GNUTLS_BAG_CRL = 4,
GNUTLS_BAG_SECRET = 5, /* Secret data. Underspecified in pkcs-12,
* gnutls extension. We use the PKCS-9
* random nonce ID 1.2.840.113549.1.9.25.3
* to store randomly generated keys.
*/
GNUTLS_BAG_ENCRYPTED = 10,
GNUTLS_BAG_UNKNOWN = 20
} gnutls_pkcs12_bag_type_t;
int gnutls_pkcs12_bag_get_type(gnutls_pkcs12_bag_t bag, unsigned indx);
int gnutls_pkcs12_bag_get_data(gnutls_pkcs12_bag_t bag, unsigned indx,
gnutls_datum_t *data);
int gnutls_pkcs12_bag_set_data(gnutls_pkcs12_bag_t bag,
gnutls_pkcs12_bag_type_t type,
const gnutls_datum_t *data);
int gnutls_pkcs12_bag_set_crl(gnutls_pkcs12_bag_t bag, gnutls_x509_crl_t crl);
int gnutls_pkcs12_bag_set_crt(gnutls_pkcs12_bag_t bag, gnutls_x509_crt_t crt);
int gnutls_pkcs12_bag_set_privkey(gnutls_pkcs12_bag_t bag,
gnutls_x509_privkey_t privkey,
const char *password, unsigned flags);
int gnutls_pkcs12_bag_init(gnutls_pkcs12_bag_t *bag);
void gnutls_pkcs12_bag_deinit(gnutls_pkcs12_bag_t bag);
int gnutls_pkcs12_bag_get_count(gnutls_pkcs12_bag_t bag);
int gnutls_pkcs12_bag_get_key_id(gnutls_pkcs12_bag_t bag, unsigned indx,
gnutls_datum_t *id);
int gnutls_pkcs12_bag_set_key_id(gnutls_pkcs12_bag_t bag, unsigned indx,
const gnutls_datum_t *id);
int gnutls_pkcs12_bag_get_friendly_name(gnutls_pkcs12_bag_t bag, unsigned indx,
char **name);
int gnutls_pkcs12_bag_set_friendly_name(gnutls_pkcs12_bag_t bag, unsigned indx,
const char *name);
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_PKCS12_H */

View File

@ -0,0 +1,148 @@
/*
* Copyright (C) 2003-2012 Free Software Foundation, Inc.
* Copyright (C) 2015 Red Hat, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
/* This file contains the types and prototypes for the X.509
* certificate and CRL handling functions.
*/
#ifndef GNUTLS_PKCS7_H
#define GNUTLS_PKCS7_H
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#ifdef __cplusplus
extern "C" {
#endif
/* PKCS7 structures handling
*/
struct gnutls_pkcs7_int;
typedef struct gnutls_pkcs7_int *gnutls_pkcs7_t;
int gnutls_pkcs7_init(gnutls_pkcs7_t *pkcs7);
void gnutls_pkcs7_deinit(gnutls_pkcs7_t pkcs7);
int gnutls_pkcs7_import(gnutls_pkcs7_t pkcs7, const gnutls_datum_t *data,
gnutls_x509_crt_fmt_t format);
int gnutls_pkcs7_export(gnutls_pkcs7_t pkcs7, gnutls_x509_crt_fmt_t format,
void *output_data, size_t *output_data_size);
int gnutls_pkcs7_export2(gnutls_pkcs7_t pkcs7, gnutls_x509_crt_fmt_t format,
gnutls_datum_t *out);
int gnutls_pkcs7_get_signature_count(gnutls_pkcs7_t pkcs7);
#define GNUTLS_PKCS7_EDATA_GET_RAW (1 << 24)
int gnutls_pkcs7_get_embedded_data(gnutls_pkcs7_t pkcs7, unsigned flags,
gnutls_datum_t *data);
const char *gnutls_pkcs7_get_embedded_data_oid(gnutls_pkcs7_t pkcs7);
int gnutls_pkcs7_get_crt_count(gnutls_pkcs7_t pkcs7);
int gnutls_pkcs7_get_crt_raw(gnutls_pkcs7_t pkcs7, unsigned indx,
void *certificate, size_t *certificate_size);
int gnutls_pkcs7_set_crt_raw(gnutls_pkcs7_t pkcs7, const gnutls_datum_t *crt);
int gnutls_pkcs7_set_crt(gnutls_pkcs7_t pkcs7, gnutls_x509_crt_t crt);
int gnutls_pkcs7_delete_crt(gnutls_pkcs7_t pkcs7, int indx);
int gnutls_pkcs7_get_crl_raw(gnutls_pkcs7_t pkcs7, unsigned indx, void *crl,
size_t *crl_size);
int gnutls_pkcs7_get_crl_count(gnutls_pkcs7_t pkcs7);
int gnutls_pkcs7_set_crl_raw(gnutls_pkcs7_t pkcs7, const gnutls_datum_t *crl);
int gnutls_pkcs7_set_crl(gnutls_pkcs7_t pkcs7, gnutls_x509_crl_t crl);
int gnutls_pkcs7_delete_crl(gnutls_pkcs7_t pkcs7, int indx);
typedef struct gnutls_pkcs7_attrs_st *gnutls_pkcs7_attrs_t;
typedef struct gnutls_pkcs7_signature_info_st {
gnutls_sign_algorithm_t algo;
gnutls_datum_t sig;
gnutls_datum_t issuer_dn;
gnutls_datum_t signer_serial;
gnutls_datum_t issuer_keyid;
time_t signing_time;
gnutls_pkcs7_attrs_t signed_attrs;
gnutls_pkcs7_attrs_t unsigned_attrs;
char pad[64];
} gnutls_pkcs7_signature_info_st;
void gnutls_pkcs7_signature_info_deinit(gnutls_pkcs7_signature_info_st *info);
int gnutls_pkcs7_get_signature_info(gnutls_pkcs7_t pkcs7, unsigned idx,
gnutls_pkcs7_signature_info_st *info);
int gnutls_pkcs7_verify_direct(gnutls_pkcs7_t pkcs7, gnutls_x509_crt_t signer,
unsigned idx, const gnutls_datum_t *data,
unsigned flags);
int gnutls_pkcs7_verify(gnutls_pkcs7_t pkcs7, gnutls_x509_trust_list_t tl,
gnutls_typed_vdata_st *vdata, unsigned int vdata_size,
unsigned idx, const gnutls_datum_t *data,
unsigned flags);
#define GNUTLS_PKCS7_ATTR_ENCODE_OCTET_STRING 1
int gnutls_pkcs7_add_attr(gnutls_pkcs7_attrs_t *list, const char *oid,
gnutls_datum_t *data, unsigned flags);
void gnutls_pkcs7_attrs_deinit(gnutls_pkcs7_attrs_t list);
int gnutls_pkcs7_get_attr(gnutls_pkcs7_attrs_t list, unsigned idx, char **oid,
gnutls_datum_t *data, unsigned flags);
/**
* gnutls_pkcs7_sign_flags:
* @GNUTLS_PKCS7_EMBED_DATA: The signed data will be embedded in the structure.
* @GNUTLS_PKCS7_INCLUDE_TIME: The signing time will be included in the structure.
* @GNUTLS_PKCS7_INCLUDE_CERT: The signer's certificate will be included in the cert list.
* @GNUTLS_PKCS7_WRITE_SPKI: Use the signer's key identifier instead of name.
*
* Enumeration of the different PKCS #7 signature flags.
*/
typedef enum gnutls_pkcs7_sign_flags {
GNUTLS_PKCS7_EMBED_DATA = 1,
GNUTLS_PKCS7_INCLUDE_TIME = (1 << 1),
GNUTLS_PKCS7_INCLUDE_CERT = (1 << 2),
GNUTLS_PKCS7_WRITE_SPKI = (1 << 3)
} gnutls_pkcs7_sign_flags;
int gnutls_pkcs7_sign(gnutls_pkcs7_t pkcs7, gnutls_x509_crt_t signer,
gnutls_privkey_t signer_key, const gnutls_datum_t *data,
gnutls_pkcs7_attrs_t signed_attrs,
gnutls_pkcs7_attrs_t unsigned_attrs,
gnutls_digest_algorithm_t dig, unsigned flags);
int gnutls_pkcs7_get_crt_raw2(gnutls_pkcs7_t pkcs7, unsigned indx,
gnutls_datum_t *cert);
int gnutls_pkcs7_get_crl_raw2(gnutls_pkcs7_t pkcs7, unsigned indx,
gnutls_datum_t *crl);
int gnutls_pkcs7_print(gnutls_pkcs7_t pkcs7,
gnutls_certificate_print_formats_t format,
gnutls_datum_t *out);
int gnutls_pkcs7_print_signature_info(gnutls_pkcs7_signature_info_st *info,
gnutls_certificate_print_formats_t format,
gnutls_datum_t *out);
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_PKCS7_H */

View File

@ -0,0 +1,41 @@
/*
* Copyright (C) 2014 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLS_SELF_TEST_H
#define GNUTLS_SELF_TEST_H
#include <gnutls/gnutls.h>
/* Self checking functions */
#define GNUTLS_SELF_TEST_FLAG_ALL 1
#define GNUTLS_SELF_TEST_FLAG_NO_COMPAT (1 << 1)
int gnutls_cipher_self_test(unsigned flags, gnutls_cipher_algorithm_t cipher);
int gnutls_mac_self_test(unsigned flags, gnutls_mac_algorithm_t mac);
int gnutls_digest_self_test(unsigned flags, gnutls_digest_algorithm_t digest);
int gnutls_pk_self_test(unsigned flags, gnutls_pk_algorithm_t pk);
int gnutls_hkdf_self_test(unsigned flags, gnutls_mac_algorithm_t mac);
int gnutls_pbkdf2_self_test(unsigned flags, gnutls_mac_algorithm_t mac);
int gnutls_tlsprf_self_test(unsigned flags, gnutls_mac_algorithm_t mac);
#endif /* GNUTLS_SELF_TEST_H */

View File

@ -0,0 +1,47 @@
/*
* Copyright (C) 2016 Free Software Foundation, Inc.
*
* Author: Tim Ruehsen
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
/* This file contains socket related types, prototypes and includes.
*/
#ifndef GNUTLS_SOCKET_H
#define GNUTLS_SOCKET_H
#include <gnutls/gnutls.h>
/* Get socklen_t */
#include <sys/socket.h>
#ifdef __cplusplus
extern "C" {
#endif
void gnutls_transport_set_fastopen(gnutls_session_t session, int fd,
struct sockaddr *connect_addr,
socklen_t connect_addrlen,
unsigned int flags);
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_SOCKET_H */

View File

@ -0,0 +1,59 @@
/*
* Copyright (C) 2014 Red Hat, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLS_SYSTEM_KEYS_H
#define GNUTLS_SYSTEM_KEYS_H
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
/* This API allows to access user key and certificate pairs that are
* available in the current system. If any passwords are required,
* they will be requested through the pin callbacks.
*/
#ifdef __cplusplus
extern "C" {
#endif
struct system_key_iter_st;
typedef struct system_key_iter_st *gnutls_system_key_iter_t;
void gnutls_system_key_iter_deinit(gnutls_system_key_iter_t iter);
int gnutls_system_key_iter_get_info(gnutls_system_key_iter_t *iter,
unsigned cert_type
/* gnutls_certificate_type_t */,
char **cert_url, char **key_url,
char **label, gnutls_datum_t *der,
unsigned int flags);
int gnutls_system_key_delete(const char *cert_url, const char *key_url);
int gnutls_system_key_add_x509(gnutls_x509_crt_t crt,
gnutls_x509_privkey_t privkey, const char *label,
char **cert_url, char **key_url);
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_SYSTEM_KEYS_H */

View File

@ -0,0 +1,72 @@
/*
* Copyright (C) 2010-2012 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLS_TPM_H
#define GNUTLS_TPM_H
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#ifdef __cplusplus
extern "C" {
#endif
struct tpm_key_list_st;
typedef struct tpm_key_list_st *gnutls_tpm_key_list_t;
#define GNUTLS_TPM_KEY_SIGNING (1 << 1)
#define GNUTLS_TPM_REGISTER_KEY (1 << 2)
#define GNUTLS_TPM_KEY_USER (1 << 3)
/**
* gnutls_tpmkey_fmt_t:
* @GNUTLS_TPMKEY_FMT_RAW: The portable data format.
* @GNUTLS_TPMKEY_FMT_DER: An alias for the raw format.
* @GNUTLS_TPMKEY_FMT_CTK_PEM: A custom data format used by some TPM tools.
*
* Enumeration of different certificate encoding formats.
*/
typedef enum {
GNUTLS_TPMKEY_FMT_RAW = 0,
GNUTLS_TPMKEY_FMT_DER = GNUTLS_TPMKEY_FMT_RAW,
GNUTLS_TPMKEY_FMT_CTK_PEM = 1
} gnutls_tpmkey_fmt_t;
int gnutls_tpm_privkey_generate(gnutls_pk_algorithm_t pk, unsigned int bits,
const char *srk_password,
const char *key_password,
gnutls_tpmkey_fmt_t format,
gnutls_x509_crt_fmt_t pub_format,
gnutls_datum_t *privkey, gnutls_datum_t *pubkey,
unsigned int flags);
void gnutls_tpm_key_list_deinit(gnutls_tpm_key_list_t list);
int gnutls_tpm_key_list_get_url(gnutls_tpm_key_list_t list, unsigned int idx,
char **url, unsigned int flags);
int gnutls_tpm_get_registered(gnutls_tpm_key_list_t *list);
int gnutls_tpm_privkey_delete(const char *url, const char *srk_password);
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_TPM_H */

View File

@ -0,0 +1,76 @@
/*
* Copyright (C) 2014 Red Hat, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
#ifndef GNUTLS_URLS_H
#define GNUTLS_URLS_H
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#include <gnutls/abstract.h>
/* This API allows to register application specific URLs for
* keys and certificates.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*gnutls_privkey_import_url_func)(gnutls_privkey_t pkey,
const char *url, unsigned flags);
typedef int (*gnutls_x509_crt_import_url_func)(gnutls_x509_crt_t pkey,
const char *url, unsigned flags);
/* The following callbacks are optional */
/* This is to enable gnutls_pubkey_import_url() */
typedef int (*gnutls_pubkey_import_url_func)(gnutls_pubkey_t pkey,
const char *url, unsigned flags);
/* This is to allow constructing a certificate chain. It will be provided
* the initial certificate URL and the certificate to find its issuer, and must
* return zero and the DER encoding of the issuer's certificate. If not available,
* it should return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE. */
typedef int (*gnutls_get_raw_issuer_func)(const char *url,
gnutls_x509_crt_t crt,
gnutls_datum_t *issuer_der,
unsigned flags);
typedef struct gnutls_custom_url_st {
const char *name;
unsigned name_size;
gnutls_privkey_import_url_func import_key;
gnutls_x509_crt_import_url_func import_crt;
gnutls_pubkey_import_url_func import_pubkey;
gnutls_get_raw_issuer_func get_issuer;
void *future1; /* replace in a future extension */
void *future2; /* replace in a future extension */
} gnutls_custom_url_st;
int gnutls_register_custom_url(const gnutls_custom_url_st *st);
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_URLS_H */

View File

@ -0,0 +1,220 @@
/*
* Copyright (C) 2014 Free Software Foundation, Inc.
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* The GnuTLS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*
*/
/* Prototypes for direct handling of extension data */
#ifndef GNUTLS_X509_EXT_H
#define GNUTLS_X509_EXT_H
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct gnutls_subject_alt_names_st *gnutls_subject_alt_names_t;
int gnutls_subject_alt_names_init(gnutls_subject_alt_names_t *);
void gnutls_subject_alt_names_deinit(gnutls_subject_alt_names_t sans);
int gnutls_subject_alt_names_get(gnutls_subject_alt_names_t sans,
unsigned int seq, unsigned int *san_type,
gnutls_datum_t *san,
gnutls_datum_t *othername_oid);
int gnutls_subject_alt_names_set(gnutls_subject_alt_names_t sans,
unsigned int san_type,
const gnutls_datum_t *san,
const char *othername_oid);
int gnutls_x509_ext_import_subject_alt_names(const gnutls_datum_t *ext,
gnutls_subject_alt_names_t,
unsigned int flags);
int gnutls_x509_ext_export_subject_alt_names(gnutls_subject_alt_names_t,
gnutls_datum_t *ext);
/* They are exactly the same */
#define gnutls_x509_ext_import_issuer_alt_name \
gnutls_x509_ext_import_subject_alt_name
#define gnutls_x509_ext_export_issuer_alt_name \
gnutls_x509_ext_export_subject_alt_name
typedef struct gnutls_x509_crl_dist_points_st *gnutls_x509_crl_dist_points_t;
int gnutls_x509_crl_dist_points_init(gnutls_x509_crl_dist_points_t *);
void gnutls_x509_crl_dist_points_deinit(gnutls_x509_crl_dist_points_t);
int gnutls_x509_crl_dist_points_get(gnutls_x509_crl_dist_points_t,
unsigned int seq, unsigned int *type,
gnutls_datum_t *dist,
unsigned int *reason_flags);
int gnutls_x509_crl_dist_points_set(gnutls_x509_crl_dist_points_t,
gnutls_x509_subject_alt_name_t type,
const gnutls_datum_t *dist,
unsigned int reason_flags);
int gnutls_x509_ext_import_crl_dist_points(const gnutls_datum_t *ext,
gnutls_x509_crl_dist_points_t dp,
unsigned int flags);
int gnutls_x509_ext_export_crl_dist_points(gnutls_x509_crl_dist_points_t dp,
gnutls_datum_t *ext);
int gnutls_x509_ext_import_name_constraints(const gnutls_datum_t *ext,
gnutls_x509_name_constraints_t nc,
unsigned int flags);
int gnutls_x509_ext_export_name_constraints(gnutls_x509_name_constraints_t nc,
gnutls_datum_t *ext);
typedef struct gnutls_x509_aia_st *gnutls_x509_aia_t;
int gnutls_x509_aia_init(gnutls_x509_aia_t *);
void gnutls_x509_aia_deinit(gnutls_x509_aia_t);
int gnutls_x509_aia_get(gnutls_x509_aia_t aia, unsigned int seq,
gnutls_datum_t *oid, unsigned *san_type,
gnutls_datum_t *san);
int gnutls_x509_aia_set(gnutls_x509_aia_t aia, const char *oid,
unsigned san_type, const gnutls_datum_t *san);
int gnutls_x509_ext_import_aia(const gnutls_datum_t *ext, gnutls_x509_aia_t,
unsigned int flags);
int gnutls_x509_ext_export_aia(gnutls_x509_aia_t aia, gnutls_datum_t *ext);
int gnutls_x509_ext_import_subject_key_id(const gnutls_datum_t *ext,
gnutls_datum_t *id);
int gnutls_x509_ext_export_subject_key_id(const gnutls_datum_t *id,
gnutls_datum_t *ext);
typedef struct gnutls_x509_aki_st *gnutls_x509_aki_t;
int gnutls_x509_ext_export_authority_key_id(gnutls_x509_aki_t,
gnutls_datum_t *ext);
int gnutls_x509_ext_import_authority_key_id(const gnutls_datum_t *ext,
gnutls_x509_aki_t,
unsigned int flags);
int gnutls_x509_othername_to_virtual(const char *oid,
const gnutls_datum_t *othername,
unsigned int *virt_type,
gnutls_datum_t *virt);
int gnutls_x509_aki_init(gnutls_x509_aki_t *);
int gnutls_x509_aki_get_id(gnutls_x509_aki_t, gnutls_datum_t *id);
int gnutls_x509_aki_get_cert_issuer(gnutls_x509_aki_t aki, unsigned int seq,
unsigned int *san_type, gnutls_datum_t *san,
gnutls_datum_t *othername_oid,
gnutls_datum_t *serial);
int gnutls_x509_aki_set_id(gnutls_x509_aki_t aki, const gnutls_datum_t *id);
int gnutls_x509_aki_set_cert_issuer(gnutls_x509_aki_t aki,
unsigned int san_type,
const gnutls_datum_t *san,
const char *othername_oid,
const gnutls_datum_t *serial);
void gnutls_x509_aki_deinit(gnutls_x509_aki_t);
int gnutls_x509_ext_import_private_key_usage_period(const gnutls_datum_t *ext,
time_t *activation,
time_t *expiration);
int gnutls_x509_ext_export_private_key_usage_period(time_t activation,
time_t expiration,
gnutls_datum_t *ext);
int gnutls_x509_ext_import_basic_constraints(const gnutls_datum_t *ext,
unsigned int *ca, int *pathlen);
int gnutls_x509_ext_export_basic_constraints(unsigned int ca, int pathlen,
gnutls_datum_t *ext);
typedef struct gnutls_x509_key_purposes_st *gnutls_x509_key_purposes_t;
int gnutls_x509_key_purpose_init(gnutls_x509_key_purposes_t *p);
void gnutls_x509_key_purpose_deinit(gnutls_x509_key_purposes_t p);
int gnutls_x509_key_purpose_set(gnutls_x509_key_purposes_t p, const char *oid);
int gnutls_x509_key_purpose_get(gnutls_x509_key_purposes_t p, unsigned idx,
gnutls_datum_t *oid);
int gnutls_x509_ext_import_key_purposes(const gnutls_datum_t *ext,
gnutls_x509_key_purposes_t,
unsigned int flags);
int gnutls_x509_ext_export_key_purposes(gnutls_x509_key_purposes_t,
gnutls_datum_t *ext);
int gnutls_x509_ext_import_key_usage(const gnutls_datum_t *ext,
unsigned int *key_usage);
int gnutls_x509_ext_export_key_usage(unsigned int key_usage,
gnutls_datum_t *ext);
int gnutls_x509_ext_import_inhibit_anypolicy(const gnutls_datum_t *ext,
unsigned int *skipcerts);
int gnutls_x509_ext_export_inhibit_anypolicy(unsigned int skipcerts,
gnutls_datum_t *ext);
int gnutls_x509_ext_import_proxy(const gnutls_datum_t *ext, int *pathlen,
char **policyLanguage, char **policy,
size_t *sizeof_policy);
int gnutls_x509_ext_export_proxy(int pathLenConstraint,
const char *policyLanguage, const char *policy,
size_t sizeof_policy, gnutls_datum_t *ext);
typedef struct gnutls_x509_policies_st *gnutls_x509_policies_t;
int gnutls_x509_policies_init(gnutls_x509_policies_t *);
void gnutls_x509_policies_deinit(gnutls_x509_policies_t);
int gnutls_x509_policies_get(gnutls_x509_policies_t policies, unsigned int seq,
struct gnutls_x509_policy_st *policy);
int gnutls_x509_policies_set(gnutls_x509_policies_t policies,
const struct gnutls_x509_policy_st *policy);
int gnutls_x509_ext_import_policies(const gnutls_datum_t *ext,
gnutls_x509_policies_t policies,
unsigned int flags);
int gnutls_x509_ext_export_policies(gnutls_x509_policies_t policies,
gnutls_datum_t *ext);
int gnutls_x509_ext_import_tlsfeatures(const gnutls_datum_t *ext,
gnutls_x509_tlsfeatures_t,
unsigned int flags);
int gnutls_x509_ext_export_tlsfeatures(gnutls_x509_tlsfeatures_t f,
gnutls_datum_t *ext);
int gnutls_x509_tlsfeatures_add(gnutls_x509_tlsfeatures_t f,
unsigned int feature);
typedef struct gnutls_x509_ct_scts_st *gnutls_x509_ct_scts_t;
int gnutls_x509_ext_ct_scts_init(gnutls_x509_ct_scts_t *scts);
void gnutls_x509_ext_ct_scts_deinit(gnutls_x509_ct_scts_t scts);
int gnutls_x509_ext_ct_import_scts(const gnutls_datum_t *ext,
gnutls_x509_ct_scts_t scts,
unsigned int flags);
int gnutls_x509_ext_ct_export_scts(const gnutls_x509_ct_scts_t scts,
gnutls_datum_t *ext);
int gnutls_x509_ct_sct_get_version(const gnutls_x509_ct_scts_t scts,
unsigned idx, unsigned int *version_out);
int gnutls_x509_ct_sct_get(const gnutls_x509_ct_scts_t scts, unsigned idx,
time_t *timestamp, gnutls_datum_t *logid,
gnutls_sign_algorithm_t *sigalg,
gnutls_datum_t *signature);
#ifdef __cplusplus
}
#endif
#endif /* GNUTLS_X509_EXT_H */

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>gnutls</string>
<key>CFBundleIdentifier</key>
<string>com.kintan.ksplayer.gnutls</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>gnutls</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>87.88.520</string>
<key>CFBundleVersion</key>
<string>87.88.520</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>MinimumOSVersion</key>
<string>14.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@ -0,0 +1,4 @@
framework module gnutls [system] {
umbrella "."
export *
}