Home | History | Annotate | Line # | Download | only in sample
      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 /*
      5 Copyright (C) 2012, iSEC Partners.
      6 
      7 Permission is hereby granted, free of charge, to any person obtaining a copy of
      8 this software and associated documentation files (the "Software"), to deal in
      9 the Software without restriction, including without limitation the rights to
     10 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
     11 of the Software, and to permit persons to whom the Software is furnished to do
     12 so, subject to the following conditions:
     13 
     14 The above copyright notice and this permission notice shall be included in all
     15 copies or substantial portions of the Software.
     16 
     17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     23 SOFTWARE.
     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 
     38 typedef 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 */
     57 HostnameValidationResult validate_hostname(const char *hostname, const X509 *server_cert);
     58