1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci#include <stdio.h> 11e1051a39Sopenharmony_ci#include <time.h> 12e1051a39Sopenharmony_ci#include <errno.h> 13e1051a39Sopenharmony_ci 14e1051a39Sopenharmony_ci#include "internal/cryptlib.h" 15e1051a39Sopenharmony_ci#include <openssl/asn1.h> 16e1051a39Sopenharmony_ci#include <openssl/x509.h> 17e1051a39Sopenharmony_ci#include <openssl/types.h> 18e1051a39Sopenharmony_ci#include "x509_local.h" 19e1051a39Sopenharmony_ci 20e1051a39Sopenharmony_ciX509_LOOKUP_METHOD *X509_LOOKUP_meth_new(const char *name) 21e1051a39Sopenharmony_ci{ 22e1051a39Sopenharmony_ci X509_LOOKUP_METHOD *method = OPENSSL_zalloc(sizeof(X509_LOOKUP_METHOD)); 23e1051a39Sopenharmony_ci 24e1051a39Sopenharmony_ci if (method != NULL) { 25e1051a39Sopenharmony_ci method->name = OPENSSL_strdup(name); 26e1051a39Sopenharmony_ci if (method->name == NULL) { 27e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_X509, ERR_R_MALLOC_FAILURE); 28e1051a39Sopenharmony_ci goto err; 29e1051a39Sopenharmony_ci } 30e1051a39Sopenharmony_ci } 31e1051a39Sopenharmony_ci 32e1051a39Sopenharmony_ci return method; 33e1051a39Sopenharmony_ci 34e1051a39Sopenharmony_cierr: 35e1051a39Sopenharmony_ci OPENSSL_free(method); 36e1051a39Sopenharmony_ci return NULL; 37e1051a39Sopenharmony_ci} 38e1051a39Sopenharmony_ci 39e1051a39Sopenharmony_civoid X509_LOOKUP_meth_free(X509_LOOKUP_METHOD *method) 40e1051a39Sopenharmony_ci{ 41e1051a39Sopenharmony_ci if (method != NULL) 42e1051a39Sopenharmony_ci OPENSSL_free(method->name); 43e1051a39Sopenharmony_ci OPENSSL_free(method); 44e1051a39Sopenharmony_ci} 45e1051a39Sopenharmony_ci 46e1051a39Sopenharmony_ciint X509_LOOKUP_meth_set_new_item(X509_LOOKUP_METHOD *method, 47e1051a39Sopenharmony_ci int (*new_item) (X509_LOOKUP *ctx)) 48e1051a39Sopenharmony_ci{ 49e1051a39Sopenharmony_ci method->new_item = new_item; 50e1051a39Sopenharmony_ci return 1; 51e1051a39Sopenharmony_ci} 52e1051a39Sopenharmony_ci 53e1051a39Sopenharmony_ciint (*X509_LOOKUP_meth_get_new_item(const X509_LOOKUP_METHOD* method)) 54e1051a39Sopenharmony_ci (X509_LOOKUP *ctx) 55e1051a39Sopenharmony_ci{ 56e1051a39Sopenharmony_ci return method->new_item; 57e1051a39Sopenharmony_ci} 58e1051a39Sopenharmony_ci 59e1051a39Sopenharmony_ciint X509_LOOKUP_meth_set_free( 60e1051a39Sopenharmony_ci X509_LOOKUP_METHOD *method, 61e1051a39Sopenharmony_ci void (*free_fn) (X509_LOOKUP *ctx)) 62e1051a39Sopenharmony_ci{ 63e1051a39Sopenharmony_ci method->free = free_fn; 64e1051a39Sopenharmony_ci return 1; 65e1051a39Sopenharmony_ci} 66e1051a39Sopenharmony_ci 67e1051a39Sopenharmony_civoid (*X509_LOOKUP_meth_get_free(const X509_LOOKUP_METHOD* method)) 68e1051a39Sopenharmony_ci (X509_LOOKUP *ctx) 69e1051a39Sopenharmony_ci{ 70e1051a39Sopenharmony_ci return method->free; 71e1051a39Sopenharmony_ci} 72e1051a39Sopenharmony_ci 73e1051a39Sopenharmony_ciint X509_LOOKUP_meth_set_init(X509_LOOKUP_METHOD *method, 74e1051a39Sopenharmony_ci int (*init) (X509_LOOKUP *ctx)) 75e1051a39Sopenharmony_ci{ 76e1051a39Sopenharmony_ci method->init = init; 77e1051a39Sopenharmony_ci return 1; 78e1051a39Sopenharmony_ci} 79e1051a39Sopenharmony_ci 80e1051a39Sopenharmony_ciint (*X509_LOOKUP_meth_get_init(const X509_LOOKUP_METHOD* method)) 81e1051a39Sopenharmony_ci (X509_LOOKUP *ctx) 82e1051a39Sopenharmony_ci{ 83e1051a39Sopenharmony_ci return method->init; 84e1051a39Sopenharmony_ci} 85e1051a39Sopenharmony_ci 86e1051a39Sopenharmony_ciint X509_LOOKUP_meth_set_shutdown( 87e1051a39Sopenharmony_ci X509_LOOKUP_METHOD *method, 88e1051a39Sopenharmony_ci int (*shutdown) (X509_LOOKUP *ctx)) 89e1051a39Sopenharmony_ci{ 90e1051a39Sopenharmony_ci method->shutdown = shutdown; 91e1051a39Sopenharmony_ci return 1; 92e1051a39Sopenharmony_ci} 93e1051a39Sopenharmony_ci 94e1051a39Sopenharmony_ciint (*X509_LOOKUP_meth_get_shutdown(const X509_LOOKUP_METHOD* method)) 95e1051a39Sopenharmony_ci (X509_LOOKUP *ctx) 96e1051a39Sopenharmony_ci{ 97e1051a39Sopenharmony_ci return method->shutdown; 98e1051a39Sopenharmony_ci} 99e1051a39Sopenharmony_ci 100e1051a39Sopenharmony_ciint X509_LOOKUP_meth_set_ctrl( 101e1051a39Sopenharmony_ci X509_LOOKUP_METHOD *method, 102e1051a39Sopenharmony_ci X509_LOOKUP_ctrl_fn ctrl) 103e1051a39Sopenharmony_ci{ 104e1051a39Sopenharmony_ci method->ctrl = ctrl; 105e1051a39Sopenharmony_ci return 1; 106e1051a39Sopenharmony_ci} 107e1051a39Sopenharmony_ci 108e1051a39Sopenharmony_ciX509_LOOKUP_ctrl_fn X509_LOOKUP_meth_get_ctrl(const X509_LOOKUP_METHOD *method) 109e1051a39Sopenharmony_ci{ 110e1051a39Sopenharmony_ci return method->ctrl; 111e1051a39Sopenharmony_ci} 112e1051a39Sopenharmony_ci 113e1051a39Sopenharmony_ciint X509_LOOKUP_meth_set_get_by_subject(X509_LOOKUP_METHOD *method, 114e1051a39Sopenharmony_ci X509_LOOKUP_get_by_subject_fn get_by_subject) 115e1051a39Sopenharmony_ci{ 116e1051a39Sopenharmony_ci method->get_by_subject = get_by_subject; 117e1051a39Sopenharmony_ci return 1; 118e1051a39Sopenharmony_ci} 119e1051a39Sopenharmony_ci 120e1051a39Sopenharmony_ciX509_LOOKUP_get_by_subject_fn X509_LOOKUP_meth_get_get_by_subject( 121e1051a39Sopenharmony_ci const X509_LOOKUP_METHOD *method) 122e1051a39Sopenharmony_ci{ 123e1051a39Sopenharmony_ci return method->get_by_subject; 124e1051a39Sopenharmony_ci} 125e1051a39Sopenharmony_ci 126e1051a39Sopenharmony_ci 127e1051a39Sopenharmony_ciint X509_LOOKUP_meth_set_get_by_issuer_serial(X509_LOOKUP_METHOD *method, 128e1051a39Sopenharmony_ci X509_LOOKUP_get_by_issuer_serial_fn get_by_issuer_serial) 129e1051a39Sopenharmony_ci{ 130e1051a39Sopenharmony_ci method->get_by_issuer_serial = get_by_issuer_serial; 131e1051a39Sopenharmony_ci return 1; 132e1051a39Sopenharmony_ci} 133e1051a39Sopenharmony_ci 134e1051a39Sopenharmony_ciX509_LOOKUP_get_by_issuer_serial_fn 135e1051a39Sopenharmony_ci X509_LOOKUP_meth_get_get_by_issuer_serial(const X509_LOOKUP_METHOD *method) 136e1051a39Sopenharmony_ci{ 137e1051a39Sopenharmony_ci return method->get_by_issuer_serial; 138e1051a39Sopenharmony_ci} 139e1051a39Sopenharmony_ci 140e1051a39Sopenharmony_ci 141e1051a39Sopenharmony_ciint X509_LOOKUP_meth_set_get_by_fingerprint(X509_LOOKUP_METHOD *method, 142e1051a39Sopenharmony_ci X509_LOOKUP_get_by_fingerprint_fn get_by_fingerprint) 143e1051a39Sopenharmony_ci{ 144e1051a39Sopenharmony_ci method->get_by_fingerprint = get_by_fingerprint; 145e1051a39Sopenharmony_ci return 1; 146e1051a39Sopenharmony_ci} 147e1051a39Sopenharmony_ci 148e1051a39Sopenharmony_ciX509_LOOKUP_get_by_fingerprint_fn X509_LOOKUP_meth_get_get_by_fingerprint( 149e1051a39Sopenharmony_ci const X509_LOOKUP_METHOD *method) 150e1051a39Sopenharmony_ci{ 151e1051a39Sopenharmony_ci return method->get_by_fingerprint; 152e1051a39Sopenharmony_ci} 153e1051a39Sopenharmony_ci 154e1051a39Sopenharmony_ciint X509_LOOKUP_meth_set_get_by_alias(X509_LOOKUP_METHOD *method, 155e1051a39Sopenharmony_ci X509_LOOKUP_get_by_alias_fn get_by_alias) 156e1051a39Sopenharmony_ci{ 157e1051a39Sopenharmony_ci method->get_by_alias = get_by_alias; 158e1051a39Sopenharmony_ci return 1; 159e1051a39Sopenharmony_ci} 160e1051a39Sopenharmony_ci 161e1051a39Sopenharmony_ciX509_LOOKUP_get_by_alias_fn X509_LOOKUP_meth_get_get_by_alias( 162e1051a39Sopenharmony_ci const X509_LOOKUP_METHOD *method) 163e1051a39Sopenharmony_ci{ 164e1051a39Sopenharmony_ci return method->get_by_alias; 165e1051a39Sopenharmony_ci} 166e1051a39Sopenharmony_ci 167