summaryrefslogtreecommitdiff
path: root/libsylph/ssl_hostname_validation.h
diff options
context:
space:
mode:
authorSimeon Simeonov2018-02-26 11:23:00 +0100
committerSimeon Simeonov2018-02-26 11:23:00 +0100
commit0b3cbf57875fd692e4ba0b336fefa4bee1ed00dc (patch)
treeaf916a30553c78ce9d4f2d8658656a175c5b6921 /libsylph/ssl_hostname_validation.h
Initial commit for sylpheed 3.7.0
Diffstat (limited to 'libsylph/ssl_hostname_validation.h')
-rw-r--r--libsylph/ssl_hostname_validation.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/libsylph/ssl_hostname_validation.h b/libsylph/ssl_hostname_validation.h
new file mode 100644
index 0000000..4a24ae3
--- /dev/null
+++ b/libsylph/ssl_hostname_validation.h
@@ -0,0 +1,66 @@
1/*
2 * Helper functions to perform basic hostname validation using OpenSSL.
3 *
4 * Copyright (C) 2012, iSEC Partners.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy of
7 * this software and associated documentation files (the "Software"), to deal in
8 * the Software without restriction, including without limitation the rights to
9 + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is furnished to do
11 + so, subject to the following conditions:
12 +
13 + The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 * Author: Alban Diquet
25 *
26 * https://github.com/iSECPartners/ssl-conservatory
27 *
28 * Modified naming convention to match LibSylph.
29 *
30 */
31
32#ifndef __SSL_HOSTNAME_VALIDATION_H__
33#define __SSL_HOSTNAME_VALIDATION_H__
34
35#ifdef HAVE_CONFIG_H
36# include "config.h"
37#endif
38
39#if USE_SSL
40
41#include <openssl/x509.h>
42
43typedef enum {
44 SSL_HOSTNAME_MATCH_FOUND,
45 SSL_HOSTNAME_MATCH_NOT_FOUND,
46 SSL_HOSTNAME_NO_SAN_PRESENT,
47 SSL_HOSTNAME_MALFORMED_CERTIFICATE,
48 SSL_HOSTNAME_ERROR
49} SSLHostnameValidationResult;
50
51/**
52* Validates the server's identity by looking for the expected hostname in the
53* server's certificate. As described in RFC 6125, it first tries to find a match
54* in the Subject Alternative Name extension. If the extension is not present in
55* the certificate, it checks the Common Name instead.
56*
57* Returns MatchFound if a match was found.
58* Returns MatchNotFound if no matches were found.
59* Returns MalformedCertificate if any of the hostnames had a NUL character embedded in it.
60* Returns Error if there was an error.
61*/
62SSLHostnameValidationResult ssl_validate_hostname(const char *hostname, const X509 *server_cert);
63
64#endif /* USE_SSL */
65
66#endif /* __SSL_HOSTNAME_VALIDATION_H__ */