list-ciphers.c
text/plain
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
int main(int argc, char *argv[])
{
const SSL_METHOD *method = TLSv1_client_method();
SSL_CTX *ctx;
SSL *ssl = NULL;
char *ciphers;
int i;
if (argc < 2)
{
fprintf(stderr, "ciphers not specified\n");
exit(1);
}
ciphers = argv[1];
SSL_library_init();
ctx = SSL_CTX_new(method);
if (!ctx)
{
fprintf(stderr, "something went wrong\n");
exit(1);
}
if (!SSL_CTX_set_cipher_list(ctx, ciphers))
{
fprintf(stderr, "unable to set cipher list\n");
exit(1);
}
ssl = SSL_new(ctx);
if (!ssl)
{
fprintf(stderr, "unable to create the SSL object\n");
exit(1);
}
for (i = 0;; i++)
{
const char *cipher;
cipher = SSL_get_cipher_list(ssl, i);
if (cipher == NULL)
{
fprintf(stderr, "end of cipher list?\n");
break;
}
printf("cipher: %s\n", cipher);
}
SSL_CTX_free(ctx);
SSL_free(ssl);
return 0;
}