Created
March 18, 2015 19:48
-
-
Save pusateri/8219265df9b80dd30d18 to your computer and use it in GitHub Desktop.
libevent SSL client certificate initialization for Apple Push Notifications service connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void | |
init_feedback_service(struct event_base *ev_base, struct evdns_base *dns) | |
{ | |
int rc; | |
struct bufferevent *bev; | |
SSL_CTX *ssl_ctx; | |
SSL *ssl; | |
ssl_ctx = SSL_CTX_new(SSLv3_method()); | |
rc = SSL_CTX_use_certificate_file(ssl_ctx, "my_apple_cert_and_key.pem", SSL_FILETYPE_PEM); | |
if (rc != 1) { | |
errx(EXIT_FAILURE, "Could not load certificate file"); | |
} | |
rc = SSL_CTX_use_PrivateKey_file(ssl_ctx, "my_apple_cert_and_key.pem", SSL_FILETYPE_PEM); | |
if (rc != 1) { | |
errx(EXIT_FAILURE, "Could not load private key file"); | |
} | |
ssl = SSL_new(ssl_ctx); | |
bev = bufferevent_openssl_socket_new(ev_base, -1, ssl, BUFFEREVENT_SSL_CONNECTING, BEV_OPT_CLOSE_ON_FREE); | |
bufferevent_setcb(bev, feedback_read_cb, NULL, feedback_event_cb, NULL); | |
rc = bufferevent_socket_connect_hostname(bev, dns, AF_INET, "feedback.sandbox.push.apple.com", 2196); | |
if (rc < 0) { | |
warnx("could not connect to feedback service: %s", | |
evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR())); | |
bufferevent_free(bev); | |
return; | |
} | |
bufferevent_enable(bev, EV_READ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment