OpenVPN
ssl_verify.h
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2024 OpenVPN Inc <sales@openvpn.net>
9 * Copyright (C) 2010-2021 Fox Crypto B.V. <openvpn@foxcrypto.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24
30#ifndef SSL_VERIFY_H_
31#define SSL_VERIFY_H_
32
33#include "syshead.h"
34#include "misc.h"
35#include "ssl_common.h"
36
37/* Include OpenSSL-specific code */
38#ifdef ENABLE_CRYPTO_OPENSSL
39#include "ssl_verify_openssl.h"
40#endif
41#ifdef ENABLE_CRYPTO_MBEDTLS
42#include "ssl_verify_mbedtls.h"
43#endif
44
45#include "ssl_verify_backend.h"
46
47/*
48 * Keep track of certificate hashes at various depths
49 */
50
52#define MAX_CERT_DEPTH 16
53
55struct cert_hash {
56 unsigned char sha256_hash[256/8];
57};
58
63
64#define VERIFY_X509_NONE 0
65#define VERIFY_X509_SUBJECT_DN 1
66#define VERIFY_X509_SUBJECT_RDN 2
67#define VERIFY_X509_SUBJECT_RDN_PREFIX 3
68
75
94
110#define TLS_AUTHENTICATED(multi, ks) ((ks)->state >= (S_GOT_KEY - (multi)->opt.server))
111
119
125void cert_hash_free(struct cert_hash_set *chs);
126
132void tls_lock_cert_hash_set(struct tls_multi *multi);
133
139void tls_lock_common_name(struct tls_multi *multi);
140
147const char *tls_common_name(const struct tls_multi *multi, const bool null);
148
155const char *tls_username(const struct tls_multi *multi, const bool null);
156
163bool cert_hash_compare(const struct cert_hash_set *chs1, const struct cert_hash_set *chs2);
164
178void verify_user_pass(struct user_pass *up, struct tls_multi *multi,
179 struct tls_session *session);
180
181
182
191void
192verify_crresponse_script(struct tls_multi *multi, const char *cr_response);
193
201void
202verify_crresponse_plugin(struct tls_multi *multi, const char *cr_response);
203
213void verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session);
214
216{
217 const struct x509_track *next;
218 const char *name;
219#define XT_FULL_CHAIN (1<<0)
220 unsigned int flags;
221 int nid;
222};
223
224/*
225 * Certificate checking for verify_nsCertType
226 */
228#define NS_CERT_CHECK_NONE (0)
230#define NS_CERT_CHECK_SERVER (1<<0)
232#define NS_CERT_CHECK_CLIENT (1<<1)
233
235#define OPENVPN_KU_REQUIRED (0xFFFF)
236
237/*
238 * TODO: document
239 */
240#ifdef ENABLE_MANAGEMENT
241bool tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, const bool auth, const char *client_reason);
242
243#endif
244
252void auth_set_client_reason(struct tls_multi *multi, const char *client_reason);
253
254static inline const char *
256{
257 return multi->client_reason;
258}
259
261void tls_x509_clear_env(struct env_set *es);
262
263#endif /* SSL_VERIFY_H_ */
Control Channel Common Data Structures.
void key_state_rm_auth_control_files(struct auth_deferred_status *ads)
Remove the given key state's auth deferred status auth control file, if it exists.
Definition ssl_verify.c:958
tls_auth_status
Definition ssl_verify.h:70
@ TLS_AUTHENTICATION_DEFERRED
Definition ssl_verify.h:73
@ TLS_AUTHENTICATION_SUCCEEDED
Definition ssl_verify.h:71
@ TLS_AUTHENTICATION_FAILED
Definition ssl_verify.h:72
static const char * tls_client_reason(struct tls_multi *multi)
Definition ssl_verify.h:255
bool tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, const bool auth, const char *client_reason)
void verify_crresponse_plugin(struct tls_multi *multi, const char *cr_response)
Call the plugin OPENVPN_PLUGIN_CLIENT_CRRESPONSE.
bool cert_hash_compare(const struct cert_hash_set *chs1, const struct cert_hash_set *chs2)
Compares certificates hashes, returns true if hashes are equal.
Definition ssl_verify.c:232
void tls_x509_clear_env(struct env_set *es)
Remove any X509_ env variables from env_set es.
void tls_lock_cert_hash_set(struct tls_multi *multi)
Locks the certificate hash set used in the given tunnel.
Definition ssl_verify.c:290
void tls_lock_common_name(struct tls_multi *multi)
Locks the common name field for the given tunnel.
Definition ssl_verify.c:139
void verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
Perform final authentication checks, including locking of the cn, the allowed certificate hashes,...
const char * tls_username(const struct tls_multi *multi, const bool null)
Returns the username field for the given tunnel.
Definition ssl_verify.c:175
void auth_set_client_reason(struct tls_multi *multi, const char *client_reason)
Sets the reason why authentication of a client failed.
Definition ssl_verify.c:808
enum tls_auth_status tls_authentication_status(struct tls_multi *multi)
Return current session authentication state of the tls_multi structure This will return TLS_AUTHENTIC...
void verify_user_pass(struct user_pass *up, struct tls_multi *multi, struct tls_session *session)
Verify the given username and password, using either an external script, a plugin,...
#define MAX_CERT_DEPTH
Maximum certificate depth we will allow.
Definition ssl_verify.h:52
void verify_crresponse_script(struct tls_multi *multi, const char *cr_response)
Runs the –client-crresponse script if one is defined.
const char * tls_common_name(const struct tls_multi *multi, const bool null)
Returns the common name field for the given tunnel.
Definition ssl_verify.c:114
void cert_hash_free(struct cert_hash_set *chs)
Frees the given set of certificate hashes.
Definition ssl_verify.c:218
Control Channel Verification Module library-specific backend interface.
Control Channel Verification Module mbed TLS backend.
Control Channel Verification Module OpenSSL backend.
Structure containing the hashes for a full certificate chain.
Definition ssl_verify.h:60
struct cert_hash * ch[MAX_CERT_DEPTH]
Array of certificate hashes.
Definition ssl_verify.h:61
Structure containing the hash for a single certificate.
Definition ssl_verify.h:55
unsigned char sha256_hash[256/8]
Definition ssl_verify.h:56
Security parameter state for a single VPN tunnel.
Definition ssl_common.h:597
char * client_reason
Definition ssl_common.h:643
Security parameter state of a single session within a VPN tunnel.
Definition ssl_common.h:480
unsigned int flags
Definition ssl_verify.h:220
const struct x509_track * next
Definition ssl_verify.h:217
const char * name
Definition ssl_verify.h:218
struct env_set * es