return "UNKNOWN";
}
+typedef struct {
+ char *key;
+ char *value;
+} kv_s;
+
#if defined(IPSEC_TEST)
typedef enum {
IPSEC_HYBRID_RSA,
}
}
-typedef struct {
- char *key;
- char *value;
-} kv_s;
-
-
typedef enum {
IPSEC_VERSION,
IPSEC_LEFT_ADDRS,
typedef void (*gen_ipsec_settings_f)(void);
#endif
+/**
+ * Note: Below template is to set Wireguard VPN Settings
+ *
+ * Type = wireguard
+ * Name = <Anything you like>
+ * Host = <Public IP of the WireGuard server>
+ * WireGuard.Address = <The internal IP of the client node, e.g. a /24 address>
+ * WireGuard.PrivateKey = <The client private key>
+ * WireGuard.PublicKey = <The server public key>
+ * WireGuard.AllowedIPs = <Subnets accessed via the tunnel, 0.0.0.0/0 is "route all traffic">
+ * WireGuard.EndpointPort = <The server listen port, default: 51820> (Optional)
+ * WireGuard.ListenPort = <The client/own device listen port> (Optional)
+ * WireGuard.DNS = <comma separated DNS> (Optional)
+ * WireGuard.PresharedKey = <The preshared key> (Optional)
+ * WireGuard.PersistentKeepalive = <The time in seconds to emit periodic keep alive message> (Optional)
+ */
+
+typedef enum {
+ WIREGUARD_ADDRESS,
+ WIREGUARD_PRIVATE_KEY,
+ WIREGUARD_PUBLIC_KEY,
+ WIREGUARD_ALLOWED_IPS,
+ WIREGUARD_ENDPOINT_PORT,
+ WIREGUARD_PERSISTENT_KEEPALIVE,
+ WIREGUARD_KVS_MAX
+} wireguard_kv_e;
+
+kv_s wg_setting_kvs[] = {
+ {"WireGuard.Address", NULL},
+ {"WireGuard.PrivateKey", NULL},
+ {"WireGuard.PublicKey", NULL},
+ {"WireGuard.AllowedIPs", NULL},
+ {"WireGuard.EndpointPort", "51820"},
+ {"WireGuard.PersistentKeepalive", "10"},
+ {NULL, NULL},
+};
+
static void __test_created_callback(vpn_error_e result,
void *user_data)
{
printf(" Name[%p] - %s\n", iter->data, name);
printf(" Type[%p] - %s\n", iter->data, type);
printf(" Host[%p] - %s\n", iter->data, host);
- printf(" Domain[%p] - %s\n", iter->data, domain);
+ printf(" Domain[%p] - %s\n", iter->data, domain ? domain : "NULL");
}
printf("==================================\n");
return 1;
}
-int test_vpn_settings_add(void)
+int test_vpn_settings_add(const char *type, const char *name, const char *host, const char *domain)
{
int rv = 0;
char buf[MAX_USER_INPUT_LEN + 1];
- _test_get_user_input(&buf[0], "Type");
- rv = vpn_settings_set_type(&buf[0]);
+ if (type == NULL) {
+ _test_get_user_input(&buf[0], "Type");
+ rv = vpn_settings_set_type(&buf[0]);
+ } else {
+ rv = vpn_settings_set_type(type);
+ }
if (rv != VPN_ERROR_NONE) {
printf("Fail to VPN Settings Type[%s]\n",
__test_convert_error_to_string(rv));
return -1;
}
- _test_get_user_input(&buf[0], "Name");
- rv = vpn_settings_set_name(&buf[0]);
+ if (name == NULL) {
+ _test_get_user_input(&buf[0], "Name");
+ rv = vpn_settings_set_name(&buf[0]);
+ } else {
+ rv = vpn_settings_set_name(name);
+ }
if (rv != VPN_ERROR_NONE) {
printf("Fail to VPN Settings Name[%s]\n",
__test_convert_error_to_string(rv));
return -1;
}
- _test_get_user_input(&buf[0], "Host");
- rv = vpn_settings_set_host(&buf[0]);
+ if (host == NULL) {
+ _test_get_user_input(&buf[0], "Host");
+ rv = vpn_settings_set_host(&buf[0]);
+ } else {
+ rv = vpn_settings_set_host(host);
+ }
if (rv != VPN_ERROR_NONE) {
printf("Fail to VPN Settings Host[%s]\n",
__test_convert_error_to_string(rv));
return -1;
}
- _test_get_user_input(&buf[0], "Domain");
- rv = vpn_settings_set_domain(&buf[0]);
+ if (!g_strcmp0(type, "wireguard"))
+ return 1;
+
+ if (domain == NULL) {
+ _test_get_user_input(&buf[0], "Domain");
+ rv = vpn_settings_set_domain(&buf[0]);
+ } else {
+ rv = vpn_settings_set_domain(domain);
+ }
if (rv != VPN_ERROR_NONE) {
printf("Fail to VPN Settings Domain[%s]\n",
__test_convert_error_to_string(rv));
return 1;
}
+int _test_vpn_settings_set_specific(const char *key, const char *value)
+{
+ int rv = 0;
+ if (key == NULL || value == NULL) {
+ printf("Invalid parameters\n");
+ return -1;
+ }
+
+ rv = vpn_settings_set_specific(key, value);
+ if (rv != VPN_ERROR_NONE) {
+ printf("Fail to Set Specific VPN Settings %s[%s]\n",
+ key, __test_convert_error_to_string(rv));
+ return -1;
+ }
+
+ printf("Success in VPN Settings Add %s=%s\n", key, value);
+
+ return 1;
+}
+
int test_vpn_create(void)
{
int rv = 0;
return 1;
}
-#if defined(IPSEC_TEST)
static int __test_init()
{
int rv = 0;
return rv;
}
-static int __test_add(ipsec_type_e type)
-{
- int rv = 0;
-
- rv = vpn_settings_set_type("ipsec");
- if (rv != VPN_ERROR_NONE) {
- printf("Fail to VPN Settings Type[%s]\n",
- __test_convert_error_to_string(rv));
- return -1;
- }
-
- rv = vpn_settings_set_name(__get_ipsec_name(type));
- if (rv != VPN_ERROR_NONE) {
- printf("Fail to VPN Settings Name[%s]\n",
- __test_convert_error_to_string(rv));
- return -1;
- }
-
- rv = vpn_settings_set_host("1.1.1.1");
- if (rv != VPN_ERROR_NONE) {
- printf("Fail to VPN Settings Host[%s]\n",
- __test_convert_error_to_string(rv));
- return -1;
- }
-
- rv = vpn_settings_set_domain("default_domain@strongswan.org");
- if (rv != VPN_ERROR_NONE) {
- printf("Fail to VPN Settings Domain[%s]\n",
- __test_convert_error_to_string(rv));
- return -1;
- }
- return rv;
-}
-
+#if defined(IPSEC_TEST)
static void __init_ipsec_setting_kvs()
{
int i = 0;
if (rv != VPN_ERROR_NONE)
return -1;
- rv = __test_add(type);
- if (rv != VPN_ERROR_NONE)
+ rv = test_vpn_settings_add("ipsec", __get_ipsec_name(type),
+ "1.1.1.1", "default_domain@strongswan.org");
+ if (rv < 0)
return -1;
gen_ipsec_settings[type]();
}
#endif
+int test_create_wireguard(void)
+{
+ int rv = 0;
+ int i;
+
+ printf("Creating Wireguard VPN Profile\n");
+
+ rv = test_vpn_settings_add("wireguard", "wireguard_test_client",
+ NULL, NULL);
+ if (rv < 0) {
+ printf("Fail to add wireguard vpn settings\n");
+ return -1;
+ }
+
+ for (i = 0; i < WIREGUARD_KVS_MAX; i++) {
+ char value[MAX_USER_INPUT_LEN + 1];
+ if (wg_setting_kvs[i].value == NULL)
+ _test_get_user_input(&value[0], wg_setting_kvs[i].key);
+ else
+ g_strlcpy(value, wg_setting_kvs[i].value, sizeof(value));
+
+ rv = _test_vpn_settings_set_specific(wg_setting_kvs[i].key, value);
+ if (rv < 0) {
+ printf("Fail to set wireguard vpn settings");
+ __test_deinit();
+ return -1;
+ }
+ }
+
+ rv = vpn_create(__test_created_callback, NULL);
+ if (rv != VPN_ERROR_NONE) {
+ printf("Fail to Create VPN Profile [%s]\n",
+ __test_convert_error_to_string(rv));
+ __init_ipsec_setting_kvs();
+ __test_deinit();
+ return -1;
+ }
+
+ printf("Success to Create Wireguard VPN profile\n");
+
+ return 1;
+}
+
+int test_destroy_wireguard(void)
+{
+ return test_vpn_remove();
+}
+
int main(int argc, char **argv)
{
GMainLoop *mainloop;
#endif
printf("g\t- VPN Set state callback - Set the VPN state callback\n");
printf("h\t- VPN Unset state callback - Unset the VPN state callback\n");
+ printf("i\t- Create Wireguard VPN tunnel\n");
+ printf("j\t- Destroy Wireguard VPN tunnel\n");
printf("0\t- Exit\n");
printf("ENTER - Show options menu.......\n");
rv = test_vpn_settings_set_specific();
break;
case '6':
- rv = test_vpn_settings_add();
+ rv = test_vpn_settings_add(NULL, NULL, NULL, NULL);
break;
case '7':
rv = test_vpn_create();
case 'h':
rv = test_vpn_unset_state_callback();
break;
+ case 'i':
+ rv = test_create_wireguard();
+ break;
+ case 'j':
+ rv = test_destroy_wireguard();
+ break;
default:
break;
}