tls-test: Add option to specify a specific remote identity
This commit is contained in:
+13
-3
@@ -48,6 +48,7 @@ static void usage(FILE *out, char *cmd)
|
|||||||
fprintf(out, " --cert <file> certificate to authenticate itself\n");
|
fprintf(out, " --cert <file> certificate to authenticate itself\n");
|
||||||
fprintf(out, " --key <file> private key to authenticate itself\n");
|
fprintf(out, " --key <file> private key to authenticate itself\n");
|
||||||
fprintf(out, " --cacert <file> certificate to verify other peer\n");
|
fprintf(out, " --cacert <file> certificate to verify other peer\n");
|
||||||
|
fprintf(out, " --identity <id> optional remote identity to enforce\n");
|
||||||
fprintf(out, " --auth-optional don't enforce client authentication\n");
|
fprintf(out, " --auth-optional don't enforce client authentication\n");
|
||||||
fprintf(out, " --times <n> specify the amount of repeated connection establishments\n");
|
fprintf(out, " --times <n> specify the amount of repeated connection establishments\n");
|
||||||
fprintf(out, " --ipv4 use IPv4\n");
|
fprintf(out, " --ipv4 use IPv4\n");
|
||||||
@@ -301,7 +302,7 @@ int main(int argc, char *argv[])
|
|||||||
char *address = NULL;
|
char *address = NULL;
|
||||||
bool listen = FALSE;
|
bool listen = FALSE;
|
||||||
int port = 0, times = -1, res, family = AF_UNSPEC;
|
int port = 0, times = -1, res, family = AF_UNSPEC;
|
||||||
identification_t *server, *client = NULL;
|
identification_t *server, *client = NULL, *identity = NULL;
|
||||||
tls_version_t min_version = TLS_SUPPORTED_MIN, max_version = TLS_SUPPORTED_MAX;
|
tls_version_t min_version = TLS_SUPPORTED_MIN, max_version = TLS_SUPPORTED_MAX;
|
||||||
tls_flag_t flags = TLS_FLAG_ENCRYPTION_OPTIONAL;
|
tls_flag_t flags = TLS_FLAG_ENCRYPTION_OPTIONAL;
|
||||||
tls_cache_t *cache;
|
tls_cache_t *cache;
|
||||||
@@ -326,6 +327,7 @@ int main(int argc, char *argv[])
|
|||||||
{"max-version", required_argument, NULL, 'M' },
|
{"max-version", required_argument, NULL, 'M' },
|
||||||
{"version", required_argument, NULL, 'v' },
|
{"version", required_argument, NULL, 'v' },
|
||||||
{"auth-optional", no_argument, NULL, 'n' },
|
{"auth-optional", no_argument, NULL, 'n' },
|
||||||
|
{"identity", required_argument, NULL, 'i' },
|
||||||
{"debug", required_argument, NULL, 'd' },
|
{"debug", required_argument, NULL, 'd' },
|
||||||
{0,0,0,0 }
|
{0,0,0,0 }
|
||||||
};
|
};
|
||||||
@@ -355,6 +357,13 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
client = identification_create_from_encoding(ID_ANY, chunk_empty);
|
client = identification_create_from_encoding(ID_ANY, chunk_empty);
|
||||||
continue;
|
continue;
|
||||||
|
case 'i':
|
||||||
|
identity = identification_create_from_string(optarg);
|
||||||
|
if (!identity)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
case 'l':
|
case 'l':
|
||||||
listen = TRUE;
|
listen = TRUE;
|
||||||
/* fall */
|
/* fall */
|
||||||
@@ -430,19 +439,20 @@ int main(int argc, char *argv[])
|
|||||||
cache = tls_cache_create(100, 30);
|
cache = tls_cache_create(100, 30);
|
||||||
if (listen)
|
if (listen)
|
||||||
{
|
{
|
||||||
res = serve(host, server, client, times, cache, min_version,
|
res = serve(host, server, identity ?: client, times, cache, min_version,
|
||||||
max_version, flags);
|
max_version, flags);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DESTROY_IF(client);
|
DESTROY_IF(client);
|
||||||
client = find_client_id();
|
client = find_client_id();
|
||||||
res = run_client(host, server, client, times, cache, min_version,
|
res = run_client(host, identity ?: server, client, times, cache, min_version,
|
||||||
max_version, flags);
|
max_version, flags);
|
||||||
DESTROY_IF(client);
|
DESTROY_IF(client);
|
||||||
}
|
}
|
||||||
cache->destroy(cache);
|
cache->destroy(cache);
|
||||||
host->destroy(host);
|
host->destroy(host);
|
||||||
server->destroy(server);
|
server->destroy(server);
|
||||||
|
DESTROY_IF(identity);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user