28#include "openvpn-plugin.h"
30#define PLUGIN_NAME "base64.c"
57get_env(
const char *name,
const char *envp[])
61 const size_t namelen = strlen(name);
62 for (
int i = 0; envp[
i]; ++
i)
64 if (!strncmp(envp[
i], name, namelen))
66 const char *cp = envp[
i] + namelen;
102 struct openvpn_plugin_args_open_return *ret)
105 if (v3structver != OPENVPN_PLUGINv3_STRUCTVER)
107 printf(
"base64.c: ** ERROR ** Incompatible plug-in interface between this plug-in and OpenVPN\n");
108 return OPENVPN_PLUGIN_FUNC_ERROR;
112 ret->type_mask = OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY)
113 | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V2);
116 ret->handle = calloc(1, 1);
119 ovpn_log = args->callbacks->plugin_log;
120 ovpn_vlog = args->callbacks->plugin_vlog;
126 args->ovpn_version, args->ovpn_version_major, args->ovpn_version_minor,
127 args->ovpn_version_patch);
129 return OPENVPN_PLUGIN_FUNC_SUCCESS;
158 if (type != OPENVPN_PLUGIN_TLS_VERIFY && type != OPENVPN_PLUGIN_CLIENT_CONNECT_V2)
161 return OPENVPN_PLUGIN_FUNC_ERROR;
165 const char *clcert_cn =
get_env(
"X509_0_CN", envp);
169 return OPENVPN_PLUGIN_FUNC_SUCCESS;
175 ovpn_log(PLOG_NOTE,
PLUGIN_NAME,
"BASE64 encoded '%s' (return value %i): '%s'", clcert_cn, r,
179 char buf2[256] = { 0 };
181 ovpn_log(PLOG_NOTE,
PLUGIN_NAME,
"BASE64 decoded '%s' (return value %i): '%s'", buf, r, buf2);
184 r = strcmp(clcert_cn, buf2);
187 return (r == 0) ? OPENVPN_PLUGIN_FUNC_SUCCESS : OPENVPN_PLUGIN_FUNC_ERROR;
OPENVPN_EXPORT int openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, const char *argv[], const char *envp[])
This function is called by OpenVPN each time the OpenVPN reaches a point where plug-in calls should h...
OPENVPN_EXPORT void openvpn_plugin_close_v1(openvpn_plugin_handle_t handle)
This cleans up the last part of the plug-in, allows it to shut down cleanly and release the plug-in g...
plugin_log_t ovpn_log
Pointer to the OpenVPN log function.
plugin_base64_decode_t ovpn_base64_decode
Pointer to the openvpn_base64_decode () function.
plugin_base64_encode_t ovpn_base64_encode
Pointer to the openvpn_base64_encode () function.
plugin_vlog_t ovpn_vlog
Pointer to the OpenVPN vlog function.
static const char * get_env(const char *name, const char *envp[])
Search the environment pointer for a specific env var name.
OPENVPN_EXPORT int openvpn_plugin_open_v3(const int v3structver, struct openvpn_plugin_args_open_in const *args, struct openvpn_plugin_args_open_return *ret)
This function is called when OpenVPN loads the plug-in.
Contains all state information for one tunnel.