[rtmpdump] r77 - in trunk: Makefile dh.c dh.h rtmp.c rtmp.h
hyc
subversion at mplayerhq.hu
Thu Dec 17 00:38:52 CET 2009
Author: hyc
Date: Thu Dec 17 00:38:51 2009
New Revision: 77
Log:
Hide DH helpers
Replaced:
trunk/dh.h
- copied, changed from r73, trunk/dh.c
Deleted:
trunk/dh.c
Modified:
trunk/Makefile
trunk/rtmp.c
trunk/rtmp.h
Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile Wed Dec 16 22:16:10 2009 (r76)
+++ trunk/Makefile Thu Dec 17 00:38:51 2009 (r77)
@@ -40,13 +40,12 @@ clean:
streams: bytes.o log.o rtmp.o AMFObject.o rtmppacket.o streams.o parseurl.o dh.o handshake.o
$(CXX) $(LDFLAGS) $^ -o $@$(EXT) $(SLIBS)
-rtmpdump: log.o rtmp.o dh.o amf.o rtmpdump.o parseurl.o
+rtmpdump: log.o rtmp.o amf.o rtmpdump.o parseurl.o
$(CC) $(LDFLAGS) $^ -o $@$(EXT) $(LIBS)
log.o: log.c log.h Makefile
parseurl.o: parseurl.c parseurl.h log.h Makefile
streams.o: streams.cpp rtmp.h log.h Makefile
-dh.o: dh.c dh.h log.h Makefile
-rtmp.o: rtmp.c rtmp.h handshake.h log.h amf.h Makefile
+rtmp.o: rtmp.c rtmp.h handshake.h dh.h log.h amf.h Makefile
amf.o: amf.c amf.h bytes.h Makefile
rtmpdump.o: rtmpdump.c rtmp.h log.h amf.h Makefile
Copied and modified: trunk/dh.h (from r73, trunk/dh.c)
==============================================================================
--- trunk/dh.c Wed Dec 16 21:26:39 2009 (r73, copy source)
+++ trunk/dh.h Thu Dec 17 00:38:51 2009 (r77)
@@ -25,8 +25,14 @@
#include <assert.h>
#include <limits.h>
+#include <openssl/bn.h>
+#include <openssl/dh.h>
+
+#include <openssl/sha.h>
+#include <openssl/hmac.h>
+#include <openssl/rc4.h>
+
#include "log.h"
-#include "dh.h"
#include "dhgroups.h"
/*
@@ -51,8 +57,9 @@ void dh_pg_init()
*/
// RFC 2631, Section 2.1.5, http://www.ietf.org/rfc/rfc2631.txt
-int isValidPublicKey(BIGNUM *y, BIGNUM *p , BIGNUM *q)
+static bool isValidPublicKey(BIGNUM *y, BIGNUM *p , BIGNUM *q)
{
+ int ret = true;
assert(y);
BIGNUM *bn = BN_new();
@@ -62,6 +69,7 @@ int isValidPublicKey(BIGNUM *y, BIGNUM *
BN_set_word(bn,1);
if(BN_cmp(y,bn) < 0) {
Log(LOGWARNING, "DH public key must be at least 2");
+ ret = false;
goto failed;
}
@@ -70,6 +78,7 @@ int isValidPublicKey(BIGNUM *y, BIGNUM *
BN_sub_word(bn, 1);
if(BN_cmp(y,bn) > 0) {
Log(LOGWARNING, "DH public key must be at most p-2");
+ ret = false;
goto failed;
}
@@ -95,16 +104,12 @@ int isValidPublicKey(BIGNUM *y, BIGNUM *
//BN_CTX_free(ctx);
} //*/
- BN_free(bn);
-
- return 1;
failed:
- //Log(LOGDEBUG, "Insecure DH public key: %s", BN_bn2hex(y));
BN_free(bn);
- return 0;
+ return ret;
}
-DH* DHInit(int nKeyBits)
+static DH* DHInit(int nKeyBits)
{
int res;
DH* dh = DH_new();
@@ -134,7 +139,7 @@ failed:
return 0;
}
-int DHGenerateKey(DH *dh)
+static int DHGenerateKey(DH *dh)
{
if(!dh)
return 0;
@@ -163,7 +168,7 @@ int DHGenerateKey(DH *dh)
// fill pubkey with the public key in BIG ENDIAN order
// 00 00 00 00 00 x1 x2 x3 .....
-int DHGetPublicKey(DH *dh, uint8_t *pubkey, size_t nPubkeyLen)
+static int DHGetPublicKey(DH *dh, uint8_t *pubkey, size_t nPubkeyLen)
{
if(!dh || !dh->pub_key)
return 0;
@@ -177,7 +182,7 @@ int DHGetPublicKey(DH *dh, uint8_t *pubk
return 1;
}
-int DHGetPrivateKey(DH *dh, uint8_t *privkey, size_t nPrivkeyLen)
+static int DHGetPrivateKey(DH *dh, uint8_t *privkey, size_t nPrivkeyLen)
{
if(!dh || !dh->priv_key)
return 0;
@@ -192,7 +197,7 @@ int DHGetPrivateKey(DH *dh, uint8_t *pri
}
// computes the shared secret key from the private DH value and the othe parties public key (pubkey)
-int DHComputeSharedSecretKey(DH *dh, uint8_t *pubkey, size_t nPubkeyLen, uint8_t *secret)
+static int DHComputeSharedSecretKey(DH *dh, uint8_t *pubkey, size_t nPubkeyLen, uint8_t *secret)
{
if(!dh || !secret || nPubkeyLen >= INT_MAX)
return -1;
@@ -218,7 +223,7 @@ int DHComputeSharedSecretKey(DH *dh, uin
return len;
}
-void DHFree(DH *dh)
+static void DHFree(DH *dh)
{
if(dh)
DH_free(dh);
Modified: trunk/rtmp.c
==============================================================================
--- trunk/rtmp.c Wed Dec 16 22:16:10 2009 (r76)
+++ trunk/rtmp.c Thu Dec 17 00:38:51 2009 (r77)
@@ -42,6 +42,10 @@
#include "rtmp.h"
#include "log.h"
+#ifdef CRYPTO
+#include <openssl/rc4.h>
+#endif
+
#define RTMP_SIG_SIZE 1536
#define RTMP_LARGE_HEADER_SIZE 12
@@ -2145,6 +2149,20 @@ RTMP_Close(RTMP * r)
r->m_bPlaying = false;
r->m_nBufferSize = 0;
+
+#ifdef CRYPTO
+ DHFree(r->Link.dh);
+ if(r->Link.rc4keyIn)
+ {
+ free(r->Link.rc4keyIn);
+ r->Link.rc4keyIn = NULL;
+ }
+ if(r->Link.rc4keyOut)
+ {
+ free(r->Link.rc4keyOut);
+ r->Link.rc4keyOut = NULL;
+ }
+#endif
}
static bool
Modified: trunk/rtmp.h
==============================================================================
--- trunk/rtmp.h Wed Dec 16 22:16:10 2009 (r76)
+++ trunk/rtmp.h Thu Dec 17 00:38:51 2009 (r77)
@@ -40,11 +40,6 @@
#include <stdint.h>
#include "log.h"
-
-#ifdef CRYPTO
-#include "dh.h"
-#endif
-
#include "amf.h"
#define RTMP_PROTOCOL_UNDEFINED -1
@@ -119,9 +114,9 @@ typedef struct RTMP_LNK
unsigned short socksport;
#ifdef CRYPTO
- DH *dh; // for encryption
- RC4_KEY *rc4keyIn;
- RC4_KEY *rc4keyOut;
+ void *dh; // for encryption
+ void *rc4keyIn;
+ void *rc4keyOut;
AVal SWFHash;
uint32_t SWFSize;
More information about the rtmpdump
mailing list