|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2012 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Nikos Mavrogiannopoulos
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The GnuTLS is free software; you can redistribute it and/or
|
|
Packit Service |
4684c1 |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
4684c1 |
* the License, or (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This library is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* Lesser General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "gnutls_int.h"
|
|
Packit Service |
4684c1 |
#include "errors.h"
|
|
Packit Service |
4684c1 |
#include <libtasn1.h>
|
|
Packit Service |
4684c1 |
#include <global.h>
|
|
Packit Service |
4684c1 |
#include <num.h> /* MAX */
|
|
Packit Service |
4684c1 |
#include <tls-sig.h>
|
|
Packit Service |
4684c1 |
#include "str.h"
|
|
Packit Service |
4684c1 |
#include <datum.h>
|
|
Packit Service |
4684c1 |
#include "x509_int.h"
|
|
Packit Service |
4684c1 |
#include <nettle/base64.h>
|
|
Packit Service |
4684c1 |
#include <common.h>
|
|
Packit Service |
4684c1 |
#include <gnutls/abstract.h>
|
|
Packit Service |
4684c1 |
#include <system.h>
|
|
Packit Service |
4684c1 |
#include <locks.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
struct gnutls_tdb_int {
|
|
Packit Service |
4684c1 |
gnutls_tdb_store_func store;
|
|
Packit Service |
4684c1 |
gnutls_tdb_store_commitment_func cstore;
|
|
Packit Service |
4684c1 |
gnutls_tdb_verify_func verify;
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int raw_pubkey_to_base64(const gnutls_datum_t * raw,
|
|
Packit Service |
4684c1 |
gnutls_datum_t * b64);
|
|
Packit Service |
4684c1 |
static int verify_pubkey(const char *file, const char *host,
|
|
Packit Service |
4684c1 |
const char *service, const gnutls_datum_t * skey);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static
|
|
Packit Service |
4684c1 |
int store_commitment(const char *db_name, const char *host,
|
|
Packit Service |
4684c1 |
const char *service, time_t expiration,
|
|
Packit Service |
4684c1 |
gnutls_digest_algorithm_t hash_algo,
|
|
Packit Service |
4684c1 |
const gnutls_datum_t * hash);
|
|
Packit Service |
4684c1 |
static
|
|
Packit Service |
4684c1 |
int store_pubkey(const char *db_name, const char *host,
|
|
Packit Service |
4684c1 |
const char *service, time_t expiration,
|
|
Packit Service |
4684c1 |
const gnutls_datum_t * pubkey);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int find_config_file(char *file, size_t max_size);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
extern void *_gnutls_file_mutex;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
struct gnutls_tdb_int default_tdb = {
|
|
Packit Service |
4684c1 |
store_pubkey,
|
|
Packit Service |
4684c1 |
store_commitment,
|
|
Packit Service |
4684c1 |
verify_pubkey
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/**
|
|
Packit Service |
4684c1 |
* gnutls_verify_stored_pubkey:
|
|
Packit Service |
4684c1 |
* @db_name: A file specifying the stored keys (use NULL for the default)
|
|
Packit Service |
4684c1 |
* @tdb: A storage structure or NULL to use the default
|
|
Packit Service |
4684c1 |
* @host: The peer's name
|
|
Packit Service |
4684c1 |
* @service: non-NULL if this key is specific to a service (e.g. http)
|
|
Packit Service |
4684c1 |
* @cert_type: The type of the certificate
|
|
Packit Service |
4684c1 |
* @cert: The raw (der) data of the certificate
|
|
Packit Service |
4684c1 |
* @flags: should be 0.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This function will try to verify a raw public-key or a public-key provided via
|
|
Packit Service |
4684c1 |
* a raw (DER-encoded) certificate using a list of stored public keys.
|
|
Packit Service |
4684c1 |
* The @service field if non-NULL should be a port number.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The @db_name variable if non-null specifies a custom backend for
|
|
Packit Service |
4684c1 |
* the retrieval of entries. If it is NULL then the
|
|
Packit Service |
4684c1 |
* default file backend will be used. In POSIX-like systems the
|
|
Packit Service |
4684c1 |
* file backend uses the $HOME/.gnutls/known_hosts file.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Note that if the custom storage backend is provided the
|
|
Packit Service |
4684c1 |
* retrieval function should return %GNUTLS_E_CERTIFICATE_KEY_MISMATCH
|
|
Packit Service |
4684c1 |
* if the host/service pair is found but key doesn't match,
|
|
Packit Service |
4684c1 |
* %GNUTLS_E_NO_CERTIFICATE_FOUND if no such host/service with
|
|
Packit Service |
4684c1 |
* the given key is found, and 0 if it was found. The storage
|
|
Packit Service |
4684c1 |
* function should return 0 on success.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* As of GnuTLS 3.6.6 this function also verifies raw public keys.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Returns: If no associated public key is found
|
|
Packit Service |
4684c1 |
* then %GNUTLS_E_NO_CERTIFICATE_FOUND will be returned. If a key
|
|
Packit Service |
4684c1 |
* is found but does not match %GNUTLS_E_CERTIFICATE_KEY_MISMATCH
|
|
Packit Service |
4684c1 |
* is returned. On success, %GNUTLS_E_SUCCESS (0) is returned,
|
|
Packit Service |
4684c1 |
* or a negative error value on other errors.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Since: 3.0.13
|
|
Packit Service |
4684c1 |
**/
|
|
Packit Service |
4684c1 |
int
|
|
Packit Service |
4684c1 |
gnutls_verify_stored_pubkey(const char *db_name,
|
|
Packit Service |
4684c1 |
gnutls_tdb_t tdb,
|
|
Packit Service |
4684c1 |
const char *host,
|
|
Packit Service |
4684c1 |
const char *service,
|
|
Packit Service |
4684c1 |
gnutls_certificate_type_t cert_type,
|
|
Packit Service |
4684c1 |
const gnutls_datum_t * cert,
|
|
Packit Service |
4684c1 |
unsigned int flags)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
gnutls_datum_t pubkey = { NULL, 0 }; // Holds the pubkey in subjectPublicKeyInfo format (DER encoded)
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
char local_file[MAX_FILENAME];
|
|
Packit Service |
4684c1 |
bool need_free;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (db_name == NULL && tdb == NULL) {
|
|
Packit Service |
4684c1 |
ret = find_config_file(local_file, sizeof(local_file));
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
db_name = local_file;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (tdb == NULL)
|
|
Packit Service |
4684c1 |
tdb = &default_tdb;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Import the public key depending on the provided certificate type */
|
|
Packit Service |
4684c1 |
switch (cert_type) {
|
|
Packit Service |
4684c1 |
case GNUTLS_CRT_X509:
|
|
Packit Service |
4684c1 |
/* Extract the pubkey from the cert. This function does a malloc
|
|
Packit Service |
4684c1 |
* deep down the call chain. We are responsible for freeing. */
|
|
Packit Service |
4684c1 |
ret = _gnutls_x509_raw_crt_to_raw_pubkey(cert, &pubkey);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
_gnutls_free_datum(&pubkey);
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
need_free = true;
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
case GNUTLS_CRT_RAWPK:
|
|
Packit Service |
4684c1 |
pubkey.data = cert->data;
|
|
Packit Service |
4684c1 |
pubkey.size = cert->size;
|
|
Packit Service |
4684c1 |
need_free = false;
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
default:
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
// Verify our pubkey against the database
|
|
Packit Service |
4684c1 |
ret = tdb->verify(db_name, host, service, &pubkey);
|
|
Packit Service |
4684c1 |
if (ret < 0 && ret != GNUTLS_E_CERTIFICATE_KEY_MISMATCH)
|
|
Packit Service |
4684c1 |
ret = gnutls_assert_val(GNUTLS_E_NO_CERTIFICATE_FOUND);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (need_free) {
|
|
Packit Service |
4684c1 |
_gnutls_free_datum(&pubkey);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return ret;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int parse_commitment_line(char *line,
|
|
Packit Service |
4684c1 |
const char *host, size_t host_len,
|
|
Packit Service |
4684c1 |
const char *service, size_t service_len,
|
|
Packit Service |
4684c1 |
time_t now, const gnutls_datum_t * skey)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
char *p, *kp;
|
|
Packit Service |
4684c1 |
char *savep = NULL;
|
|
Packit Service |
4684c1 |
size_t kp_len, phash_size;
|
|
Packit Service |
4684c1 |
time_t expiration;
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
const mac_entry_st *hash_algo;
|
|
Packit Service |
4684c1 |
uint8_t phash[MAX_HASH_SIZE];
|
|
Packit Service |
4684c1 |
uint8_t hphash[MAX_HASH_SIZE * 2 + 1];
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* read host */
|
|
Packit Service |
4684c1 |
p = strtok_r(line, "|", &savep);
|
|
Packit Service |
4684c1 |
if (p == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (p[0] != '*' && host != NULL && strcmp(p, host) != 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* read service */
|
|
Packit Service |
4684c1 |
p = strtok_r(NULL, "|", &savep);
|
|
Packit Service |
4684c1 |
if (p == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (p[0] != '*' && service != NULL && strcmp(p, service) != 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* read expiration */
|
|
Packit Service |
4684c1 |
p = strtok_r(NULL, "|", &savep);
|
|
Packit Service |
4684c1 |
if (p == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
expiration = (time_t) atol(p);
|
|
Packit Service |
4684c1 |
if (expiration > 0 && now > expiration)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_EXPIRED);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* read hash algorithm */
|
|
Packit Service |
4684c1 |
p = strtok_r(NULL, "|", &savep);
|
|
Packit Service |
4684c1 |
if (p == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
hash_algo = mac_to_entry(atol(p));
|
|
Packit Service |
4684c1 |
if (_gnutls_digest_get_name(hash_algo) == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* read hash */
|
|
Packit Service |
4684c1 |
kp = strtok_r(NULL, "|", &savep);
|
|
Packit Service |
4684c1 |
if (kp == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
p = strpbrk(kp, "\n \r\t|");
|
|
Packit Service |
4684c1 |
if (p != NULL)
|
|
Packit Service |
4684c1 |
*p = 0;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* hash and hex encode */
|
|
Packit Service |
4684c1 |
ret =
|
|
Packit Service |
4684c1 |
_gnutls_hash_fast((gnutls_digest_algorithm_t)hash_algo->id,
|
|
Packit Service |
4684c1 |
skey->data, skey->size, phash);
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
phash_size = _gnutls_hash_get_algo_len(hash_algo);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
p = _gnutls_bin2hex(phash, phash_size, (void *) hphash,
|
|
Packit Service |
4684c1 |
sizeof(hphash), NULL);
|
|
Packit Service |
4684c1 |
if (p == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
kp_len = strlen(kp);
|
|
Packit Service |
4684c1 |
if (kp_len != phash_size * 2)
|
|
Packit Service |
4684c1 |
return
|
|
Packit Service |
4684c1 |
gnutls_assert_val(GNUTLS_E_CERTIFICATE_KEY_MISMATCH);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (memcmp(kp, hphash, kp_len) != 0)
|
|
Packit Service |
4684c1 |
return
|
|
Packit Service |
4684c1 |
gnutls_assert_val(GNUTLS_E_CERTIFICATE_KEY_MISMATCH);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* key found and matches */
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int parse_line(char *line,
|
|
Packit Service |
4684c1 |
const char *host, size_t host_len,
|
|
Packit Service |
4684c1 |
const char *service, size_t service_len,
|
|
Packit Service |
4684c1 |
time_t now,
|
|
Packit Service |
4684c1 |
const gnutls_datum_t * rawkey,
|
|
Packit Service |
4684c1 |
const gnutls_datum_t * b64key)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
char *p, *kp;
|
|
Packit Service |
4684c1 |
char *savep = NULL;
|
|
Packit Service |
4684c1 |
size_t kp_len;
|
|
Packit Service |
4684c1 |
time_t expiration;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* read version */
|
|
Packit Service |
4684c1 |
p = strtok_r(line, "|", &savep);
|
|
Packit Service |
4684c1 |
if (p == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (strncmp(p, "c0", 2) == 0)
|
|
Packit Service |
4684c1 |
return parse_commitment_line(p + 3, host, host_len,
|
|
Packit Service |
4684c1 |
service, service_len, now,
|
|
Packit Service |
4684c1 |
rawkey);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (strncmp(p, "g0", 2) != 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* read host */
|
|
Packit Service |
4684c1 |
p = strtok_r(NULL, "|", &savep);
|
|
Packit Service |
4684c1 |
if (p == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (p[0] != '*' && host != NULL && strcmp(p, host) != 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* read service */
|
|
Packit Service |
4684c1 |
p = strtok_r(NULL, "|", &savep);
|
|
Packit Service |
4684c1 |
if (p == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (p[0] != '*' && service != NULL && strcmp(p, service) != 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* read expiration */
|
|
Packit Service |
4684c1 |
p = strtok_r(NULL, "|", &savep);
|
|
Packit Service |
4684c1 |
if (p == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
expiration = (time_t) atol(p);
|
|
Packit Service |
4684c1 |
if (expiration > 0 && now > expiration)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_EXPIRED);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* read key */
|
|
Packit Service |
4684c1 |
kp = strtok_r(NULL, "|", &savep);
|
|
Packit Service |
4684c1 |
if (kp == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_PARSING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
p = strpbrk(kp, "\n \r\t|");
|
|
Packit Service |
4684c1 |
if (p != NULL)
|
|
Packit Service |
4684c1 |
*p = 0;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
kp_len = strlen(kp);
|
|
Packit Service |
4684c1 |
if (kp_len != b64key->size)
|
|
Packit Service |
4684c1 |
return
|
|
Packit Service |
4684c1 |
gnutls_assert_val(GNUTLS_E_CERTIFICATE_KEY_MISMATCH);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (memcmp(kp, b64key->data, b64key->size) != 0)
|
|
Packit Service |
4684c1 |
return
|
|
Packit Service |
4684c1 |
gnutls_assert_val(GNUTLS_E_CERTIFICATE_KEY_MISMATCH);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* key found and matches */
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Returns the base64 key if found
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
static int verify_pubkey(const char *file,
|
|
Packit Service |
4684c1 |
const char *host, const char *service,
|
|
Packit Service |
4684c1 |
const gnutls_datum_t * pubkey)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
FILE *fp;
|
|
Packit Service |
4684c1 |
char *line = NULL;
|
|
Packit Service |
4684c1 |
size_t line_size = 0;
|
|
Packit Service |
4684c1 |
int ret, l2, mismatch = 0;
|
|
Packit Service |
4684c1 |
size_t host_len = 0, service_len = 0;
|
|
Packit Service |
4684c1 |
time_t now = gnutls_time(0);
|
|
Packit Service |
4684c1 |
gnutls_datum_t b64key = { NULL, 0 };
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = raw_pubkey_to_base64(pubkey, &b64key);
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (host != NULL)
|
|
Packit Service |
4684c1 |
host_len = strlen(host);
|
|
Packit Service |
4684c1 |
if (service != NULL)
|
|
Packit Service |
4684c1 |
service_len = strlen(service);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
fp = fopen(file, "rbe");
|
|
Packit Service |
4684c1 |
if (fp == NULL) {
|
|
Packit Service |
4684c1 |
ret = gnutls_assert_val(GNUTLS_E_FILE_ERROR);
|
|
Packit Service |
4684c1 |
goto cleanup;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
do {
|
|
Packit Service |
4684c1 |
l2 = getline(&line, &line_size, fp);
|
|
Packit Service |
4684c1 |
if (l2 > 0) {
|
|
Packit Service |
4684c1 |
ret =
|
|
Packit Service |
4684c1 |
parse_line(line, host, host_len, service,
|
|
Packit Service |
4684c1 |
service_len, now, pubkey, &b64key);
|
|
Packit Service |
4684c1 |
if (ret == 0) { /* found */
|
|
Packit Service |
4684c1 |
goto cleanup;
|
|
Packit Service |
4684c1 |
} else if (ret ==
|
|
Packit Service |
4684c1 |
GNUTLS_E_CERTIFICATE_KEY_MISMATCH)
|
|
Packit Service |
4684c1 |
mismatch = 1;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
while (l2 >= 0);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (mismatch)
|
|
Packit Service |
4684c1 |
ret = GNUTLS_E_CERTIFICATE_KEY_MISMATCH;
|
|
Packit Service |
4684c1 |
else
|
|
Packit Service |
4684c1 |
ret = GNUTLS_E_NO_CERTIFICATE_FOUND;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
cleanup:
|
|
Packit Service |
4684c1 |
free(line);
|
|
Packit Service |
4684c1 |
if (fp != NULL)
|
|
Packit Service |
4684c1 |
fclose(fp);
|
|
Packit Service |
4684c1 |
gnutls_free(b64key.data);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return ret;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int raw_pubkey_to_base64(const gnutls_datum_t * raw,
|
|
Packit Service |
4684c1 |
gnutls_datum_t * b64)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
size_t size;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
size = BASE64_ENCODE_RAW_LENGTH(raw->size);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
b64->data = gnutls_malloc(size);
|
|
Packit Service |
4684c1 |
if (b64->data == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
base64_encode_raw((void*)b64->data, raw->size, raw->data);
|
|
Packit Service |
4684c1 |
b64->size = size;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static
|
|
Packit Service |
4684c1 |
int store_pubkey(const char *db_name, const char *host,
|
|
Packit Service |
4684c1 |
const char *service, time_t expiration,
|
|
Packit Service |
4684c1 |
const gnutls_datum_t * pubkey)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
FILE *fp = NULL;
|
|
Packit Service |
4684c1 |
gnutls_datum_t b64key = { NULL, 0 };
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = gnutls_mutex_lock(&_gnutls_file_mutex);
|
|
Packit Service |
4684c1 |
if (ret != 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_LOCKING_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = raw_pubkey_to_base64(pubkey, &b64key);
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
gnutls_assert();
|
|
Packit Service |
4684c1 |
goto cleanup;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
fp = fopen(db_name, "abe+");
|
|
Packit Service |
4684c1 |
if (fp == NULL) {
|
|
Packit Service |
4684c1 |
ret = gnutls_assert_val(GNUTLS_E_FILE_ERROR);
|
|
Packit Service |
4684c1 |
goto cleanup;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (service == NULL)
|
|
Packit Service |
4684c1 |
service = "*";
|
|
Packit Service |
4684c1 |
if (host == NULL)
|
|
Packit Service |
4684c1 |
host = "*";
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
fprintf(fp, "|g0|%s|%s|%lu|%.*s\n", host, service,
|
|
Packit Service |
4684c1 |
(unsigned long) expiration, b64key.size, b64key.data);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = 0;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
cleanup:
|
|
Packit Service |
4684c1 |
if (fp != NULL)
|
|
Packit Service |
4684c1 |
fclose(fp);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_mutex_unlock(&_gnutls_file_mutex);
|
|
Packit Service |
4684c1 |
gnutls_free(b64key.data);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return ret;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static
|
|
Packit Service |
4684c1 |
int store_commitment(const char *db_name, const char *host,
|
|
Packit Service |
4684c1 |
const char *service, time_t expiration,
|
|
Packit Service |
4684c1 |
gnutls_digest_algorithm_t hash_algo,
|
|
Packit Service |
4684c1 |
const gnutls_datum_t * hash)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
FILE *fp;
|
|
Packit Service |
4684c1 |
char buffer[MAX_HASH_SIZE * 2 + 1];
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
fp = fopen(db_name, "abe+");
|
|
Packit Service |
4684c1 |
if (fp == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_FILE_ERROR);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (service == NULL)
|
|
Packit Service |
4684c1 |
service = "*";
|
|
Packit Service |
4684c1 |
if (host == NULL)
|
|
Packit Service |
4684c1 |
host = "*";
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
fprintf(fp, "|c0|%s|%s|%lu|%u|%s\n", host, service,
|
|
Packit Service |
4684c1 |
(unsigned long) expiration, (unsigned) hash_algo,
|
|
Packit Service |
4684c1 |
_gnutls_bin2hex(hash->data, hash->size, buffer,
|
|
Packit Service |
4684c1 |
sizeof(buffer), NULL));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
fclose(fp);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/**
|
|
Packit Service |
4684c1 |
* gnutls_store_pubkey:
|
|
Packit Service |
4684c1 |
* @db_name: A file specifying the stored keys (use NULL for the default)
|
|
Packit Service |
4684c1 |
* @tdb: A storage structure or NULL to use the default
|
|
Packit Service |
4684c1 |
* @host: The peer's name
|
|
Packit Service |
4684c1 |
* @service: non-NULL if this key is specific to a service (e.g. http)
|
|
Packit Service |
4684c1 |
* @cert_type: The type of the certificate
|
|
Packit Service |
4684c1 |
* @cert: The data of the certificate
|
|
Packit Service |
4684c1 |
* @expiration: The expiration time (use 0 to disable expiration)
|
|
Packit Service |
4684c1 |
* @flags: should be 0.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This function will store a raw public-key or a public-key provided via
|
|
Packit Service |
4684c1 |
* a raw (DER-encoded) certificate to the list of stored public keys. The key
|
|
Packit Service |
4684c1 |
* will be considered valid until the provided expiration time.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The @tdb variable if non-null specifies a custom backend for
|
|
Packit Service |
4684c1 |
* the storage of entries. If it is NULL then the
|
|
Packit Service |
4684c1 |
* default file backend will be used.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Unless an alternative @tdb is provided, the storage format is a textual format
|
|
Packit Service |
4684c1 |
* consisting of a line for each host with fields separated by '|'. The contents of
|
|
Packit Service |
4684c1 |
* the fields are a format-identifier which is set to 'g0', the hostname that the
|
|
Packit Service |
4684c1 |
* rest of the data applies to, the numeric port or host name, the expiration
|
|
Packit Service |
4684c1 |
* time in seconds since the epoch (0 for no expiration), and a base64
|
|
Packit Service |
4684c1 |
* encoding of the raw (DER) public key information (SPKI) of the peer.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* As of GnuTLS 3.6.6 this function also accepts raw public keys.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
|
|
Packit Service |
4684c1 |
* negative error value.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Since: 3.0.13
|
|
Packit Service |
4684c1 |
**/
|
|
Packit Service |
4684c1 |
int
|
|
Packit Service |
4684c1 |
gnutls_store_pubkey(const char *db_name,
|
|
Packit Service |
4684c1 |
gnutls_tdb_t tdb,
|
|
Packit Service |
4684c1 |
const char *host,
|
|
Packit Service |
4684c1 |
const char *service,
|
|
Packit Service |
4684c1 |
gnutls_certificate_type_t cert_type,
|
|
Packit Service |
4684c1 |
const gnutls_datum_t * cert,
|
|
Packit Service |
4684c1 |
time_t expiration, unsigned int flags)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
gnutls_datum_t pubkey = { NULL, 0 }; // Holds the pubkey in subjectPublicKeyInfo format (DER encoded)
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
char local_file[MAX_FILENAME];
|
|
Packit Service |
4684c1 |
bool need_free;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (db_name == NULL && tdb == NULL) {
|
|
Packit Service |
4684c1 |
ret =
|
|
Packit Service |
4684c1 |
_gnutls_find_config_path(local_file,
|
|
Packit Service |
4684c1 |
sizeof(local_file));
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
_gnutls_debug_log("Configuration path: %s\n", local_file);
|
|
Packit Service |
4684c1 |
mkdir(local_file, 0700);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = find_config_file(local_file, sizeof(local_file));
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
db_name = local_file;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (tdb == NULL)
|
|
Packit Service |
4684c1 |
tdb = &default_tdb;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Import the public key depending on the provided certificate type */
|
|
Packit Service |
4684c1 |
switch (cert_type) {
|
|
Packit Service |
4684c1 |
case GNUTLS_CRT_X509:
|
|
Packit Service |
4684c1 |
/* Extract the pubkey from the cert. This function does a malloc
|
|
Packit Service |
4684c1 |
* deep down the call chain. We are responsible for freeing. */
|
|
Packit Service |
4684c1 |
ret = _gnutls_x509_raw_crt_to_raw_pubkey(cert, &pubkey);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
_gnutls_free_datum(&pubkey);
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
need_free = true;
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
case GNUTLS_CRT_RAWPK:
|
|
Packit Service |
4684c1 |
pubkey.data = cert->data;
|
|
Packit Service |
4684c1 |
pubkey.size = cert->size;
|
|
Packit Service |
4684c1 |
need_free = false;
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
default:
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
_gnutls_debug_log("Configuration file: %s\n", db_name);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
tdb->store(db_name, host, service, expiration, &pubkey);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (need_free) {
|
|
Packit Service |
4684c1 |
_gnutls_free_datum(&pubkey);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return GNUTLS_E_SUCCESS;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/**
|
|
Packit Service |
4684c1 |
* gnutls_store_commitment:
|
|
Packit Service |
4684c1 |
* @db_name: A file specifying the stored keys (use NULL for the default)
|
|
Packit Service |
4684c1 |
* @tdb: A storage structure or NULL to use the default
|
|
Packit Service |
4684c1 |
* @host: The peer's name
|
|
Packit Service |
4684c1 |
* @service: non-NULL if this key is specific to a service (e.g. http)
|
|
Packit Service |
4684c1 |
* @hash_algo: The hash algorithm type
|
|
Packit Service |
4684c1 |
* @hash: The raw hash
|
|
Packit Service |
4684c1 |
* @expiration: The expiration time (use 0 to disable expiration)
|
|
Packit Service |
4684c1 |
* @flags: should be 0 or %GNUTLS_SCOMMIT_FLAG_ALLOW_BROKEN.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This function will store the provided hash commitment to
|
|
Packit Service |
4684c1 |
* the list of stored public keys. The key with the given
|
|
Packit Service |
4684c1 |
* hash will be considered valid until the provided expiration time.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The @tdb variable if non-null specifies a custom backend for
|
|
Packit Service |
4684c1 |
* the storage of entries. If it is NULL then the
|
|
Packit Service |
4684c1 |
* default file backend will be used.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Note that this function is not thread safe with the default backend.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
|
|
Packit Service |
4684c1 |
* negative error value.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Since: 3.0
|
|
Packit Service |
4684c1 |
**/
|
|
Packit Service |
4684c1 |
int
|
|
Packit Service |
4684c1 |
gnutls_store_commitment(const char *db_name,
|
|
Packit Service |
4684c1 |
gnutls_tdb_t tdb,
|
|
Packit Service |
4684c1 |
const char *host,
|
|
Packit Service |
4684c1 |
const char *service,
|
|
Packit Service |
4684c1 |
gnutls_digest_algorithm_t hash_algo,
|
|
Packit Service |
4684c1 |
const gnutls_datum_t * hash,
|
|
Packit Service |
4684c1 |
time_t expiration, unsigned int flags)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
char local_file[MAX_FILENAME];
|
|
Packit Service |
4684c1 |
const mac_entry_st *me = hash_to_entry(hash_algo);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (me == NULL)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_ILLEGAL_PARAMETER);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (!(flags & GNUTLS_SCOMMIT_FLAG_ALLOW_BROKEN) && _gnutls_digest_is_secure(me) == 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_INSUFFICIENT_SECURITY);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (_gnutls_hash_get_algo_len(me) != hash->size)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (db_name == NULL && tdb == NULL) {
|
|
Packit Service |
4684c1 |
ret =
|
|
Packit Service |
4684c1 |
_gnutls_find_config_path(local_file,
|
|
Packit Service |
4684c1 |
sizeof(local_file));
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
_gnutls_debug_log("Configuration path: %s\n", local_file);
|
|
Packit Service |
4684c1 |
mkdir(local_file, 0700);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = find_config_file(local_file, sizeof(local_file));
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
db_name = local_file;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (tdb == NULL)
|
|
Packit Service |
4684c1 |
tdb = &default_tdb;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
_gnutls_debug_log("Configuration file: %s\n", db_name);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
tdb->cstore(db_name, host, service, expiration,
|
|
Packit Service |
4684c1 |
(gnutls_digest_algorithm_t)me->id, hash);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define CONFIG_FILE "known_hosts"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static int find_config_file(char *file, size_t max_size)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
char path[MAX_FILENAME];
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = _gnutls_find_config_path(path, sizeof(path));
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
return gnutls_assert_val(ret);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (path[0] == 0)
|
|
Packit Service |
4684c1 |
snprintf(file, max_size, "%s", CONFIG_FILE);
|
|
Packit Service |
4684c1 |
else
|
|
Packit Service |
4684c1 |
snprintf(file, max_size, "%s/%s", path, CONFIG_FILE);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/**
|
|
Packit Service |
4684c1 |
* gnutls_tdb_init:
|
|
Packit Service |
4684c1 |
* @tdb: A pointer to the type to be initialized
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This function will initialize a public key trust storage structure.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
|
|
Packit Service |
4684c1 |
* negative error value.
|
|
Packit Service |
4684c1 |
**/
|
|
Packit Service |
4684c1 |
int gnutls_tdb_init(gnutls_tdb_t * tdb)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
*tdb = gnutls_calloc(1, sizeof(struct gnutls_tdb_int));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (!*tdb)
|
|
Packit Service |
4684c1 |
return GNUTLS_E_MEMORY_ERROR;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
return 0;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/**
|
|
Packit Service |
4684c1 |
* gnutls_set_store_func:
|
|
Packit Service |
4684c1 |
* @tdb: The trust storage
|
|
Packit Service |
4684c1 |
* @store: The storage function
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This function will associate a storage function with the
|
|
Packit Service |
4684c1 |
* trust storage structure. The function is of the following form.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* int gnutls_tdb_store_func(const char* db_name, const char* host,
|
|
Packit Service |
4684c1 |
* const char* service, time_t expiration,
|
|
Packit Service |
4684c1 |
* const gnutls_datum_t* pubkey);
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The @db_name should be used to pass any private data to this function.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
**/
|
|
Packit Service |
4684c1 |
void gnutls_tdb_set_store_func(gnutls_tdb_t tdb,
|
|
Packit Service |
4684c1 |
gnutls_tdb_store_func store)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
tdb->store = store;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/**
|
|
Packit Service |
4684c1 |
* gnutls_set_store_commitment_func:
|
|
Packit Service |
4684c1 |
* @tdb: The trust storage
|
|
Packit Service |
4684c1 |
* @cstore: The commitment storage function
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This function will associate a commitment (hash) storage function with the
|
|
Packit Service |
4684c1 |
* trust storage structure. The function is of the following form.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* int gnutls_tdb_store_commitment_func(const char* db_name, const char* host,
|
|
Packit Service |
4684c1 |
* const char* service, time_t expiration,
|
|
Packit Service |
4684c1 |
* gnutls_digest_algorithm_t, const gnutls_datum_t* hash);
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The @db_name should be used to pass any private data to this function.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
**/
|
|
Packit Service |
4684c1 |
void gnutls_tdb_set_store_commitment_func(gnutls_tdb_t tdb,
|
|
Packit Service |
4684c1 |
gnutls_tdb_store_commitment_func
|
|
Packit Service |
4684c1 |
cstore)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
tdb->cstore = cstore;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/**
|
|
Packit Service |
4684c1 |
* gnutls_set_verify_func:
|
|
Packit Service |
4684c1 |
* @tdb: The trust storage
|
|
Packit Service |
4684c1 |
* @verify: The verification function
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This function will associate a retrieval function with the
|
|
Packit Service |
4684c1 |
* trust storage structure. The function is of the following form.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* int gnutls_tdb_verify_func(const char* db_name, const char* host,
|
|
Packit Service |
4684c1 |
* const char* service, const gnutls_datum_t* pubkey);
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The verify function should return zero on a match, %GNUTLS_E_CERTIFICATE_KEY_MISMATCH
|
|
Packit Service |
4684c1 |
* if there is a mismatch and any other negative error code otherwise.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The @db_name should be used to pass any private data to this function.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
**/
|
|
Packit Service |
4684c1 |
void gnutls_tdb_set_verify_func(gnutls_tdb_t tdb,
|
|
Packit Service |
4684c1 |
gnutls_tdb_verify_func verify)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
tdb->verify = verify;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/**
|
|
Packit Service |
4684c1 |
* gnutls_tdb_deinit:
|
|
Packit Service |
4684c1 |
* @tdb: The structure to be deinitialized
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This function will deinitialize a public key trust storage structure.
|
|
Packit Service |
4684c1 |
**/
|
|
Packit Service |
4684c1 |
void gnutls_tdb_deinit(gnutls_tdb_t tdb)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
gnutls_free(tdb);
|
|
Packit Service |
4684c1 |
}
|