[rtmpdump] [PATCH] Simplify initializing the TLS server context

Martin Storsjo martin at martin.st
Tue Oct 30 18:22:16 CET 2012


This does the same thing, but I wasn't aware of these functions
when I initially wrote this.
---
 librtmp/rtmp.c |   22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)

diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
index 5ea1c76..3994d42 100644
--- a/librtmp/rtmp.c
+++ b/librtmp/rtmp.c
@@ -280,32 +280,14 @@ RTMP_TLS_AllocServerContext(const char* cert, const char* key)
   }
 #elif !defined(NO_SSL) /* USE_OPENSSL */
   ctx = SSL_CTX_new(SSLv23_server_method());
-  FILE *f = fopen(key, "r");
-  if (!f) {
+  if (!SSL_CTX_use_certificate_chain_file(ctx, cert)) {
       SSL_CTX_free(ctx);
       return NULL;
   }
-  EVP_PKEY *k = PEM_read_PrivateKey(f, NULL, NULL, NULL);
-  fclose(f);
-  if (!k) {
+  if (!SSL_CTX_use_PrivateKey_file(ctx, key, SSL_FILETYPE_PEM)) {
       SSL_CTX_free(ctx);
       return NULL;
   }
-  SSL_CTX_use_PrivateKey(ctx, k);
-  EVP_PKEY_free(k);
-  f = fopen(cert, "r");
-  if (!f) {
-      SSL_CTX_free(ctx);
-      return NULL;
-  }
-  X509 *c = PEM_read_X509(f, NULL, NULL, NULL);
-  fclose(f);
-  if (!c) {
-      SSL_CTX_free(ctx);
-      return NULL;
-  }
-  SSL_CTX_use_certificate(ctx, c);
-  X509_free(c);
 #endif
 #endif
   return ctx;
-- 
1.7.9.4



More information about the rtmpdump mailing list