1/*	$NetBSD: openssl_hostname_validation.h,v 1.1.1.1 2017/01/31 21:14:53 christos Exp $	*/
2/* Obtained from: https://github.com/iSECPartners/ssl-conservatory */
3
4/*
5Copyright (C) 2012, iSEC Partners.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of
8this software and associated documentation files (the "Software"), to deal in
9the Software without restriction, including without limitation the rights to
10use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
11of the Software, and to permit persons to whom the Software is furnished to do
12so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24 */
25
26/*
27 * Helper functions to perform basic hostname validation using OpenSSL.
28 *
29 * Please read "everything-you-wanted-to-know-about-openssl.pdf" before
30 * attempting to use this code. This whitepaper describes how the code works,
31 * how it should be used, and what its limitations are.
32 *
33 * Author:  Alban Diquet
34 * License: See LICENSE
35 *
36 */
37
38typedef enum {
39        MatchFound,
40        MatchNotFound,
41        NoSANPresent,
42        MalformedCertificate,
43        Error
44} HostnameValidationResult;
45
46/**
47* Validates the server's identity by looking for the expected hostname in the
48* server's certificate. As described in RFC 6125, it first tries to find a match
49* in the Subject Alternative Name extension. If the extension is not present in
50* the certificate, it checks the Common Name instead.
51*
52* Returns MatchFound if a match was found.
53* Returns MatchNotFound if no matches were found.
54* Returns MalformedCertificate if any of the hostnames had a NUL character embedded in it.
55* Returns Error if there was an error.
56*/
57HostnameValidationResult validate_hostname(const char *hostname, const X509 *server_cert);
58