--- embedaddon/strongswan/src/libstrongswan/credentials/certificates/certificate.c 2020/06/03 09:46:43 1.1.1.1 +++ embedaddon/strongswan/src/libstrongswan/credentials/certificates/certificate.c 2021/03/17 00:20:08 1.1.1.2 @@ -1,4 +1,5 @@ /* + * Copyright (C) 2020 Tobias Brunner * Copyright (C) 2007 Martin Willi * Copyright (C) 2015 Andreas Steffen * HSR Hochschule fuer Technik Rapperswil @@ -60,4 +61,41 @@ bool certificate_is_newer(certificate_t *this, certifi type, &this_update, FALSE, newer ? "newer" : "not newer", type, &that_update, FALSE, newer ? "replaced" : "retained"); return newer; +} + +/* + * Described in header + */ +bool certificate_matches(certificate_t *cert, certificate_type_t type, + key_type_t key, identification_t *id) +{ + public_key_t *public; + + if (type != CERT_ANY && type != cert->get_type(cert)) + { + return FALSE; + } + public = cert->get_public_key(cert); + if (public) + { + if (key == KEY_ANY || key == public->get_type(public)) + { + if (id && public->has_fingerprint(public, id->get_encoding(id))) + { + public->destroy(public); + return TRUE; + } + } + else + { + public->destroy(public); + return FALSE; + } + public->destroy(public); + } + else if (key != KEY_ANY) + { + return FALSE; + } + return !id || cert->has_subject(cert, id); }