summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlan Antonuk <alan.antonuk@gmail.com>2016-03-07 22:55:40 -0800
committerAlan Antonuk <alan.antonuk@gmail.com>2016-03-07 23:07:31 -0800
commit1ec9ee9be974b5e853a173baba1476a75e7daffd (patch)
tree417217cf880e429ae861146e2febc1a7127f652e /examples
parent315e08b000a3644bb34f52b395ce73b39896e270 (diff)
downloadrabbitmq-c-1ec9ee9be974b5e853a173baba1476a75e7daffd.tar.gz
Examples: add verify opts to SSL connect_timeout
Add verifypeer, verifyhostname options to amqps_connect_timeout example.
Diffstat (limited to 'examples')
-rw-r--r--examples/amqps_connect_timeout.c52
1 files changed, 28 insertions, 24 deletions
diff --git a/examples/amqps_connect_timeout.c b/examples/amqps_connect_timeout.c
index 89c00ac..81e1e91 100644
--- a/examples/amqps_connect_timeout.c
+++ b/examples/amqps_connect_timeout.c
@@ -63,33 +63,33 @@
int main(int argc, char const *const *argv)
{
- char const nofile[2] = "-";
char const *hostname;
- int port, status;
+ int port;
+ int timeout;
amqp_socket_t *socket;
amqp_connection_state_t conn;
struct timeval *tv;
if (argc < 3) {
- fprintf(stderr, "Usage: amqps_connect_timeout host port "
- "[cacert.pem [key.pem cert.pem [timeout_sec [timeout_usec=0]]]]\n");
+ fprintf(
+ stderr,
+ "Usage: amqps_connect_timeout host port timeout_sec "
+ "[cacert.pem [verifypeer] [verifyhostname] [key.pem cert.pem]]\n");
return 1;
}
hostname = argv[1];
port = atoi(argv[2]);
- if (argc > 6) {
+ timeout = atoi(argv[3]);
+ if (timeout > 0) {
tv = malloc(sizeof(struct timeval));
-
- tv->tv_sec = atoi(argv[6]);
-
- if (argc > 7 ) {
- tv->tv_usec = atoi(argv[7]);
- } else {
- tv->tv_usec = 0;
+ if (tv == NULL) {
+ die("failed to malloc struct timeval");
}
+ tv->tv_sec = timeout;
+ tv->tv_usec = 0;
} else {
tv = NULL;
}
@@ -101,21 +101,25 @@ int main(int argc, char const *const *argv)
die("creating SSL/TLS socket");
}
- if (argc > 3 && strcmp(nofile, argv[3])) {
- die_on_error(amqp_ssl_socket_set_cacert(socket, argv[3]), "setting CA certificate");
- }
+ amqp_ssl_socket_set_verify_peer(socket, 0);
+ amqp_ssl_socket_set_verify_hostname(socket, 0);
if (argc > 5) {
- if (!strcmp(nofile, argv[5]) && !strcmp(nofile, argv[4])) {
- status = 0;
- } else if (!strcmp(nofile, argv[5]) || !strcmp(nofile, argv[4])) {
- status = -1;
- } else {
- status = amqp_ssl_socket_set_key(socket, argv[5], argv[4]);
+ int nextarg = 6;
+ die_on_error(amqp_ssl_socket_set_cacert(socket, argv[5]),
+ "setting CA certificate");
+ if (argc > nextarg && !strcmp("verifypeer", argv[nextarg])) {
+ amqp_ssl_socket_set_verify_peer(socket, 1);
+ nextarg++;
}
-
- if (status) {
- die("setting client key");
+ if (argc > nextarg && !strcmp("verifyhostname", argv[nextarg])) {
+ amqp_ssl_socket_set_verify_hostname(socket, 1);
+ nextarg++;
+ }
+ if (argc > nextarg + 1) {
+ die_on_error(
+ amqp_ssl_socket_set_key(socket, argv[nextarg + 1], argv[nextarg]),
+ "setting client key");
}
}