OpenVPN
Macros | Functions
ssl_verify.c File Reference
#include "syshead.h"
#include "base64.h"
#include "manage.h"
#include "otime.h"
#include "run_command.h"
#include "ssl_verify.h"
#include "ssl_verify_backend.h"
#include "ssl_verify_openssl.h"
#include "auth_token.h"
#include "push.h"
#include "ssl_util.h"
Include dependency graph for ssl_verify.c:

Go to the source code of this file.

Macros

#define TLS_USERNAME_LEN   64
 Maximum length of common name. More...
 
#define ACF_UNDEFINED   0
 
#define ACF_SUCCEEDED   1
 
#define ACF_DISABLED   2
 
#define ACF_FAILED   3
 
#define KMDA_ERROR   0
 
#define KMDA_SUCCESS   1
 
#define KMDA_UNDEF   2
 
#define KMDA_DEF   3
 

Functions

static void string_mod_remap_name (char *str)
 
static void setenv_untrusted (struct tls_session *session)
 
static void tls_deauthenticate (struct tls_multi *multi)
 
static void set_common_name (struct tls_session *session, const char *common_name)
 
const char * tls_common_name (const struct tls_multi *multi, const bool null)
 Returns the common name field for the given tunnel. More...
 
void tls_lock_common_name (struct tls_multi *multi)
 Locks the common name field for the given tunnel. More...
 
static bool tls_lock_username (struct tls_multi *multi, const char *username)
 
const char * tls_username (const struct tls_multi *multi, const bool null)
 Returns the username field for the given tunnel. More...
 
void cert_hash_remember (struct tls_session *session, const int error_depth, const struct buffer *cert_hash)
 
void cert_hash_free (struct cert_hash_set *chs)
 Frees the given set of certificate hashes. More...
 
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. More...
 
static struct cert_hash_setcert_hash_copy (const struct cert_hash_set *chs)
 
void tls_lock_cert_hash_set (struct tls_multi *multi)
 Locks the certificate hash set used in the given tunnel. More...
 
static const char * print_nsCertType (int type)
 
static result_t verify_peer_cert (const struct tls_options *opt, openvpn_x509_cert_t *peer_cert, const char *subject, const char *common_name)
 
static void verify_cert_set_env (struct env_set *es, openvpn_x509_cert_t *peer_cert, int cert_depth, const char *subject, const char *common_name, const struct x509_track *x509_track)
 
static result_t verify_cert_call_plugin (const struct plugin_list *plugins, struct env_set *es, int cert_depth, openvpn_x509_cert_t *cert, char *subject)
 
static const char * verify_cert_export_cert (openvpn_x509_cert_t *peercert, const char *tmp_dir, struct gc_arena *gc)
 
static result_t verify_cert_call_command (const char *verify_command, struct env_set *es, int cert_depth, openvpn_x509_cert_t *cert, char *subject, const char *verify_export_cert)
 
static result_t verify_check_crl_dir (const char *crl_dir, openvpn_x509_cert_t *cert, const char *subject, int cert_depth)
 
result_t verify_cert (struct tls_session *session, openvpn_x509_cert_t *cert, int cert_depth)
 
void auth_set_client_reason (struct tls_multi *multi, const char *client_reason)
 Sets the reason why authentication of a client failed. More...
 
static unsigned int man_def_auth_test (const struct key_state *ks)
 
static void key_state_rm_auth_pending_file (struct auth_deferred_status *ads)
 Removes auth_pending file from the file system and key_state structure. More...
 
static bool check_auth_pending_method (const char *peer_info, const char *method)
 Check peer_info if the client supports the requested pending auth method. More...
 
static bool key_state_check_auth_pending_file (struct auth_deferred_status *ads, struct tls_multi *multi)
 Checks if the deferred state should also send auth pending request to the client. More...
 
void key_state_rm_auth_control_files (struct auth_deferred_status *ads)
 Removes auth_pending and auth_control files from file system and key_state structure. More...
 
static bool key_state_gen_auth_control_files (struct auth_deferred_status *ads, const struct tls_options *opt)
 Generates and creates the control files used for deferred authentification in the temporary directory. More...
 
static unsigned int key_state_test_auth_control_file (struct auth_deferred_status *ads)
 
enum tls_auth_status tls_authentication_status (struct tls_multi *multi, const int latency)
 Return current session authentication state of the tls_multi structure This will return TLS_AUTHENTICATION_SUCCEEDED only if the session is fully authenicated, i.e. More...
 
bool tls_authenticate_key (struct tls_multi *multi, const unsigned int mda_key_id, const bool auth, const char *client_reason)
 
static int verify_user_pass_script (struct tls_session *session, struct tls_multi *multi, const struct user_pass *up)
 
static int verify_user_pass_plugin (struct tls_session *session, struct tls_multi *multi, const struct user_pass *up)
 
static int verify_user_pass_management (struct tls_session *session, struct tls_multi *multi, const struct user_pass *up)
 
static bool set_verify_user_pass_env (struct user_pass *up, struct tls_multi *multi, struct tls_session *session)
 
void verify_user_pass (struct user_pass *up, struct tls_multi *multi, struct tls_session *session)
 Main username/password verification entry point. More...
 
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, and whether a client config entry exists in the client config directory. More...
 
void tls_x509_clear_env (struct env_set *es)
 Remove any X509_ env variables from env_set es. More...
 

Macro Definition Documentation

◆ ACF_DISABLED

#define ACF_DISABLED   2

◆ ACF_FAILED

#define ACF_FAILED   3

◆ ACF_SUCCEEDED

#define ACF_SUCCEEDED   1

Definition at line 851 of file ssl_verify.c.

Referenced by key_state_test_auth_control_file(), and tls_authenticate_key().

◆ ACF_UNDEFINED

#define ACF_UNDEFINED   0

Definition at line 850 of file ssl_verify.c.

Referenced by key_state_test_auth_control_file(), and tls_authentication_status().

◆ KMDA_DEF

#define KMDA_DEF   3

Definition at line 1367 of file ssl_verify.c.

Referenced by verify_user_pass().

◆ KMDA_ERROR

#define KMDA_ERROR   0

Definition at line 1364 of file ssl_verify.c.

Referenced by verify_user_pass(), and verify_user_pass_management().

◆ KMDA_SUCCESS

#define KMDA_SUCCESS   1

Definition at line 1365 of file ssl_verify.c.

Referenced by verify_user_pass_management().

◆ KMDA_UNDEF

#define KMDA_UNDEF   2

Definition at line 1366 of file ssl_verify.c.

Referenced by verify_user_pass().

◆ TLS_USERNAME_LEN

#define TLS_USERNAME_LEN   64

Maximum length of common name.

Definition at line 52 of file ssl_verify.c.

Referenced by verify_cert(), and verify_user_pass().

Function Documentation

◆ auth_set_client_reason()

void auth_set_client_reason ( struct tls_multi multi,
const char *  client_reason 
)

Sets the reason why authentication of a client failed.

This be will send to the client when the AUTH_FAILED message is sent An example would be "SESSION: Token expired"

Parameters
multiThe multi tls struct
client_reasonThe string to send to the client as part of AUTH_FAILED

Definition at line 856 of file ssl_verify.c.

Referenced by key_state_check_auth_pending_file(), multi_client_set_protocol_options(), tls_authenticate_key(), tls_multi_free(), and verify_auth_token().

◆ cert_hash_compare()

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.

Parameters
chs1cert 1 hash set
chs2cert 2 hash set

Definition at line 249 of file ssl_verify.c.

References cert_hash_set::ch, MAX_CERT_DEPTH, and cert_hash::sha256_hash.

Referenced by multi_process_float(), and verify_final_auth_checks().

◆ cert_hash_copy()

static struct cert_hash_set* cert_hash_copy ( const struct cert_hash_set chs)
static

◆ cert_hash_free()

void cert_hash_free ( struct cert_hash_set chs)

Frees the given set of certificate hashes.

Parameters
chsThe certificate hash set to free.

Definition at line 235 of file ssl_verify.c.

References cert_hash_set::ch, free, and MAX_CERT_DEPTH.

Referenced by tls_multi_free(), and tls_session_free().

◆ cert_hash_remember()

void cert_hash_remember ( struct tls_session session,
const int  error_depth,
const struct buffer cert_hash 
)

◆ check_auth_pending_method()

static bool check_auth_pending_method ( const char *  peer_info,
const char *  method 
)
static

Check peer_info if the client supports the requested pending auth method.

Definition at line 902 of file ssl_verify.c.

References extract_var_peer_info(), gc_free(), and gc_new().

Referenced by key_state_check_auth_pending_file().

◆ key_state_check_auth_pending_file()

static bool key_state_check_auth_pending_file ( struct auth_deferred_status ads,
struct tls_multi multi 
)
static

Checks if the deferred state should also send auth pending request to the client.

Also removes the auth_pending control file

Returns
true if file was either processed sucessfully or did not exist at all
false The file had an invlaid format or another error occured

Definition at line 939 of file ssl_verify.c.

References auth_deferred_status::auth_pending_file, auth_set_client_reason(), BSTR, buffer_entry::buf, buf_chomp(), buffer_list_file(), buffer_list_free(), check_auth_pending_method(), buffer_list::head, key_state_rm_auth_pending_file(), M_INFO, M_WARN, msg, buffer_entry::next, openvpn_snprintf(), tls_multi::peer_info, and send_auth_pending_messages().

Referenced by verify_user_pass_plugin(), and verify_user_pass_script().

◆ key_state_gen_auth_control_files()

static bool key_state_gen_auth_control_files ( struct auth_deferred_status ads,
const struct tls_options opt 
)
static

Generates and creates the control files used for deferred authentification in the temporary directory.

Returns
true if file creation was successful

Definition at line 1023 of file ssl_verify.c.

References auth_deferred_status::auth_control_file, auth_deferred_status::auth_pending_file, tls_options::es, gc_free(), gc_new(), key_state_rm_auth_control_files(), platform_create_temp_file(), setenv_str(), string_alloc(), and tls_options::tmp_dir.

Referenced by verify_user_pass_plugin(), and verify_user_pass_script().

◆ key_state_rm_auth_control_files()

void key_state_rm_auth_control_files ( struct auth_deferred_status ads)

Removes auth_pending and auth_control files from file system and key_state structure.

Remove the given key state's auth deferred status auth control file, if it exists.

Definition at line 1005 of file ssl_verify.c.

References auth_deferred_status::auth_control_file, free, key_state_rm_auth_pending_file(), and platform_unlink().

Referenced by key_state_free(), key_state_gen_auth_control_files(), verify_user_pass_plugin(), and verify_user_pass_script().

◆ key_state_rm_auth_pending_file()

static void key_state_rm_auth_pending_file ( struct auth_deferred_status ads)
static

Removes auth_pending file from the file system and key_state structure.

Definition at line 888 of file ssl_verify.c.

References auth_deferred_status::auth_pending_file, free, and platform_unlink().

Referenced by key_state_check_auth_pending_file(), and key_state_rm_auth_control_files().

◆ key_state_test_auth_control_file()

static unsigned int key_state_test_auth_control_file ( struct auth_deferred_status ads)
static

◆ man_def_auth_test()

static unsigned int man_def_auth_test ( const struct key_state ks)
inlinestatic

◆ print_nsCertType()

static const char* print_nsCertType ( int  type)
static

Definition at line 320 of file ssl_verify.c.

References NS_CERT_CHECK_CLIENT, and NS_CERT_CHECK_SERVER.

Referenced by verify_peer_cert().

◆ set_common_name()

static void set_common_name ( struct tls_session session,
const char *  common_name 
)
static

◆ set_verify_user_pass_env()

static bool set_verify_user_pass_env ( struct user_pass up,
struct tls_multi multi,
struct tls_session session 
)
static

◆ setenv_untrusted()

static void setenv_untrusted ( struct tls_session session)
static

◆ string_mod_remap_name()

static void string_mod_remap_name ( char *  str)
static

Definition at line 55 of file ssl_verify.c.

References CC_CRLF, CC_PRINT, and string_mod().

Referenced by verify_cert(), and verify_user_pass().

◆ tls_authenticate_key()

bool tls_authenticate_key ( struct tls_multi multi,
const unsigned int  mda_key_id,
const bool  auth,
const char *  client_reason 
)

◆ tls_authentication_status()

enum tls_auth_status tls_authentication_status ( struct tls_multi multi,
const int  latency 
)

Return current session authentication state of the tls_multi structure This will return TLS_AUTHENTICATION_SUCCEEDED only if the session is fully authenicated, i.e.

VPN traffic is allowed over it.

Checks the status of all active keys and checks if the deferred authentication has succeeded.

As a side effect this function will also transition ks->authenticated from KS_AUTH_DEFERRED to KS_AUTH_FALSE/KS_AUTH_TRUE if the deferred authentication has succeeded after last call.

Parameters
latencyif not null, return TLS_AUTHENTICATION_UNDEFINED if the last call for this multi struct has been less than latency seconds ago
multithe tls_multi struct to operate on
Returns
Current authentication status of the tls_multi

Definition at line 1074 of file ssl_verify.c.

References ACF_DISABLED, ACF_FAILED, ACF_UNDEFINED, ASSERT, key_state::auth_deferred_expire, key_state::authenticated, D_TLS_ERRORS, dmsg, get_key_scan(), KEY_SCAN_SIZE, key_state_test_auth_control_file(), KS_AUTH_FALSE, KS_AUTH_TRUE, man_def_auth_test(), now, key_state::plugin_auth, key_state::script_auth, tls_multi::tas_last, TLS_AUTHENTICATED, TLS_AUTHENTICATION_DEFERRED, TLS_AUTHENTICATION_FAILED, TLS_AUTHENTICATION_SUCCEEDED, and TLS_AUTHENTICATION_UNDEFINED.

Referenced by multi_connection_established(), process_incoming_push_request(), and tls_multi_process().

◆ tls_common_name()

const char* tls_common_name ( const struct tls_multi multi,
const bool  null 
)

Returns the common name field for the given tunnel.

Parameters
multiThe tunnel to return the common name for
nullWhether null may be returned. If not, "UNDEF" will be returned.

Definition at line 128 of file ssl_verify.c.

References tls_session::common_name, tls_multi::session, and TM_ACTIVE.

Referenced by format_common_name(), learn_address_script(), management_callback_kill_by_cn(), multi_client_connect_setenv(), multi_client_connect_source_ccd(), multi_delete_dup(), multi_instance_string(), multi_print_status(), multi_process_float(), multi_select_virtual_addr(), and send_control_channel_string_dowork().

◆ tls_deauthenticate()

static void tls_deauthenticate ( struct tls_multi multi)
static

◆ tls_lock_cert_hash_set()

void tls_lock_cert_hash_set ( struct tls_multi multi)

Locks the certificate hash set used in the given tunnel.

Parameters
multiThe tunnel to lock

Definition at line 307 of file ssl_verify.c.

References cert_hash_copy(), tls_session::cert_hash_set, tls_multi::locked_cert_hash_set, tls_multi::session, and TM_ACTIVE.

Referenced by multi_client_connect_early_setup().

◆ tls_lock_common_name()

void tls_lock_common_name ( struct tls_multi multi)

Locks the common name field for the given tunnel.

Parameters
multiThe tunnel to lock

Definition at line 153 of file ssl_verify.c.

References tls_session::common_name, tls_multi::locked_cn, tls_multi::session, string_alloc(), and TM_ACTIVE.

Referenced by multi_client_connect_early_setup().

◆ tls_lock_username()

static bool tls_lock_username ( struct tls_multi multi,
const char *  username 
)
static

◆ tls_username()

const char* tls_username ( const struct tls_multi multi,
const bool  null 
)

Returns the username field for the given tunnel.

Parameters
multiThe tunnel to return the username for
nullWhether null may be returned. If not, "UNDEF" will be returned.

Definition at line 192 of file ssl_verify.c.

References tls_multi::locked_username.

Referenced by multi_print_status().

◆ tls_x509_clear_env()

void tls_x509_clear_env ( struct env_set es)

Remove any X509_ env variables from env_set es.

Definition at line 1677 of file ssl_verify.c.

References env_set_del(), env_set::list, env_item::next, and env_item::string.

Referenced by tls_client_reason(), and tls_process().

◆ verify_cert()

result_t verify_cert ( struct tls_session session,
openvpn_x509_cert_t cert,
int  cert_depth 
)

◆ verify_cert_call_command()

static result_t verify_cert_call_command ( const char *  verify_command,
struct env_set es,
int  cert_depth,
openvpn_x509_cert_t cert,
char *  subject,
const char *  verify_export_cert 
)
static

◆ verify_cert_call_plugin()

static result_t verify_cert_call_plugin ( const struct plugin_list plugins,
struct env_set es,
int  cert_depth,
openvpn_x509_cert_t cert,
char *  subject 
)
static

◆ verify_cert_export_cert()

static const char* verify_cert_export_cert ( openvpn_x509_cert_t peercert,
const char *  tmp_dir,
struct gc_arena gc 
)
static

◆ verify_cert_set_env()

static void verify_cert_set_env ( struct env_set es,
openvpn_x509_cert_t peer_cert,
int  cert_depth,
const char *  subject,
const char *  common_name,
const struct x509_track x509_track 
)
static

◆ verify_check_crl_dir()

static result_t verify_check_crl_dir ( const char *  crl_dir,
openvpn_x509_cert_t cert,
const char *  subject,
int  cert_depth 
)
static

◆ verify_final_auth_checks()

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, and whether a client config entry exists in the client config directory.

Parameters
multiThe TLS multi structure to verify locked structures.
sessionThe current TLS session

Definition at line 1615 of file ssl_verify.c.

References key_state::authenticated, CCD_DEFAULT, cert_hash_compare(), tls_session::cert_hash_set, tls_options::client_config_dir_exclusive, tls_session::common_name, D_TLS_ERRORS, gc_free(), gc_new(), tls_session::key, KS_AUTH_FALSE, KS_PRIMARY, tls_multi::locked_cert_hash_set, tls_multi::locked_cn, msg, tls_session::opt, platform_gen_path(), platform_test_file(), set_common_name(), tls_deauthenticate(), and wipe_auth_token().

Referenced by key_method_2_read().

◆ verify_peer_cert()

static result_t verify_peer_cert ( const struct tls_options opt,
openvpn_x509_cert_t peer_cert,
const char *  subject,
const char *  common_name 
)
static

◆ verify_user_pass()

void verify_user_pass ( struct user_pass up,
struct tls_multi multi,
struct tls_session session 
)

◆ verify_user_pass_management()

static int verify_user_pass_management ( struct tls_session session,
struct tls_multi multi,
const struct user_pass up 
)
static

◆ verify_user_pass_plugin()

static int verify_user_pass_plugin ( struct tls_session session,
struct tls_multi multi,
const struct user_pass up 
)
static

◆ verify_user_pass_script()

static int verify_user_pass_script ( struct tls_session session,
struct tls_multi multi,
const struct user_pass up 
)
static