"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/h235/h235support.cxx" between
h323plus-1_26_9.tar.gz and h323plus-1_27_0.tar.gz

About: H.323 Plus offers libraries for voice (VoIP) and videoconferencing using H.323.

h235support.cxx  (h323plus-1_26_9):h235support.cxx  (h323plus-1_27_0)
skipping to change at line 50 skipping to change at line 50
#include <ptlib.h> #include <ptlib.h>
#include "openh323buildopts.h" #include "openh323buildopts.h"
#ifdef H323_H235 #ifdef H323_H235
#include "h235/h235support.h" #include "h235/h235support.h"
#include <h235.h> #include <h235.h>
#include <ptclib/cypher.h> #include <ptclib/cypher.h>
extern "C" { extern "C" {
#include <openssl/opensslv.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/dh.h> #include <openssl/dh.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/bn.h> #include <openssl/bn.h>
}; };
#if OPENSSL_VERSION_NUMBER < 0x10100000L
inline void DH_get0_pqg(const DH *dh,
const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
{
if (p != NULL)
*p = dh->p;
if (q != NULL)
*q = dh->q;
if (g != NULL)
*g = dh->g;
}
inline int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
{
/* If the fields p and g in d are NULL, the corresponding input
* parameters MUST be non-NULL. q may remain NULL.
*/
if ((dh->p == NULL && p == NULL)
|| (dh->g == NULL && g == NULL))
return 0;
if (p != NULL) {
BN_free(dh->p);
dh->p = p;
}
if (q != NULL) {
BN_free(dh->q);
dh->q = q;
}
if (g != NULL) {
BN_free(dh->g);
dh->g = g;
}
if (q != NULL) {
dh->length = BN_num_bits(q);
}
return 1;
}
inline void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **pri
v_key)
{
if (pub_key != NULL)
*pub_key = dh->pub_key;
if (priv_key != NULL)
*priv_key = dh->priv_key;
}
inline int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key)
{
/* If the field pub_key in dh is NULL, the corresponding input
* parameters MUST be non-NULL. The priv_key field may
* be left NULL.
*/
if (dh->pub_key == NULL && pub_key == NULL)
return 0;
if (pub_key != NULL) {
BN_free(dh->pub_key);
dh->pub_key = pub_key;
}
if (priv_key != NULL) {
BN_free(dh->priv_key);
dh->priv_key = priv_key;
}
return 1;
}
#endif // OPENSSL_VERSION_NUMBER < 0x10100000L
//////////////////////////////////////////////////////////////////////////////// //// //////////////////////////////////////////////////////////////////////////////// ////
// Diffie Hellman // Diffie Hellman
H235_DiffieHellman::H235_DiffieHellman(const PConfig & dhFile, const PString & section) H235_DiffieHellman::H235_DiffieHellman(const PConfig & dhFile, const PString & section)
: dh(NULL), m_remKey(NULL), m_toSend(true), m_wasReceived(false), m_wasDHReceive d(false), m_keySize(0), m_loadFromFile(false) : dh(NULL), m_remKey(NULL), m_toSend(true), m_wasReceived(false), m_wasDHReceive d(false), m_keySize(0), m_loadFromFile(false)
{ {
if (Load(dhFile, section)) { if (Load(dhFile, section)) {
if (dh->pub_key == NULL) { const BIGNUM *pub_key = NULL;
DH_get0_key(dh, &pub_key, NULL);
if (pub_key == NULL) {
GenerateHalfKey(); GenerateHalfKey();
DH_get0_key(dh, &pub_key, NULL);
} }
m_keySize = BN_num_bytes(dh->pub_key); m_keySize = BN_num_bytes(pub_key);
} }
} }
H235_DiffieHellman::H235_DiffieHellman(const PFilePath & dhPKCS3) H235_DiffieHellman::H235_DiffieHellman(const PFilePath & dhPKCS3)
: dh(NULL), m_remKey(NULL), m_toSend(true), m_wasReceived(false), m_wasDHReceive d(false), m_keySize(0), m_loadFromFile(false) : dh(NULL), m_remKey(NULL), m_toSend(true), m_wasReceived(false), m_wasDHReceive d(false), m_keySize(0), m_loadFromFile(false)
{ {
FILE *paramfile; FILE *paramfile;
paramfile = fopen(dhPKCS3, "r"); paramfile = fopen(dhPKCS3, "r");
if (paramfile) { if (paramfile) {
dh = PEM_read_DHparams(paramfile, NULL, NULL, NULL); dh = PEM_read_DHparams(paramfile, NULL, NULL, NULL);
fclose(paramfile); fclose(paramfile);
if (dh) { if (dh) {
m_keySize = BN_num_bits(dh->p); const BIGNUM* dh_p = NULL;
DH_get0_pqg(dh, &dh_p, NULL, NULL);
m_keySize = BN_num_bits(dh_p);
m_loadFromFile = true; m_loadFromFile = true;
} }
} }
} }
H235_DiffieHellman::H235_DiffieHellman(const BYTE * pData, PINDEX pSize, H235_DiffieHellman::H235_DiffieHellman(const BYTE * pData, PINDEX pSize,
const BYTE * gData, PINDEX gSize, const BYTE * gData, PINDEX gSize,
PBoolean send) PBoolean send)
: m_remKey(NULL), m_toSend(send), m_wasReceived(false), m_wasDHReceived(false), m_keySize(pSize), m_loadFromFile(false) : m_remKey(NULL), m_toSend(send), m_wasReceived(false), m_wasDHReceived(false), m_keySize(pSize), m_loadFromFile(false)
{ {
dh = DH_new(); dh = DH_new();
if (dh == NULL) { if (dh == NULL) {
PTRACE(1, "H235_DH\tFailed to allocate DH"); PTRACE(1, "H235_DH\tFailed to allocate DH");
return; return;
}; };
dh->p = BN_bin2bn(pData, pSize, NULL); BIGNUM* p = BN_bin2bn(pData, pSize, NULL);
dh->g = BN_bin2bn(gData, gSize, NULL); BIGNUM* g = BN_bin2bn(gData, gSize, NULL);
if (dh->p != NULL && dh->g != NULL) { if (p != NULL && g != NULL) {
DH_set0_pqg(dh, p, NULL, g);
GenerateHalfKey(); GenerateHalfKey();
return; return;
} }
if (g)
BN_free(g);
if (p)
BN_free(p);
PTRACE(1, "H235_DH\tFailed to generate half key"); PTRACE(1, "H235_DH\tFailed to generate half key");
DH_free(dh); DH_free(dh);
dh = NULL; dh = NULL;
} }
static DH * DH_dup(const DH * dh) static DH * DH_dup(const DH * dh)
{ {
if (dh == NULL) if (dh == NULL)
return NULL; return NULL;
DH * ret = DH_new(); DH * ret = DH_new();
if (ret == NULL) if (ret == NULL)
return NULL; return NULL;
if (dh->p) const BIGNUM *p = NULL, *q = NULL, *g = NULL;
ret->p = BN_dup(dh->p); DH_get0_pqg(dh, &p, &q, &g);
if (dh->q)
ret->q = BN_dup(dh->q); if (p)
if (dh->g) p = BN_dup(p);
ret->g = BN_dup(dh->g); if (q)
if (dh->pub_key) q = BN_dup(q);
ret->pub_key = BN_dup(dh->pub_key); if (g)
if (dh->priv_key) g = BN_dup(g);
ret->priv_key = BN_dup(dh->priv_key); DH_set0_pqg(ret, const_cast< BIGNUM* >(p), const_cast< BIGNUM* >(q), const_cas
t< BIGNUM* >(g));
const BIGNUM *pub_key = NULL, *priv_key = NULL;
DH_get0_key(dh, &pub_key, &priv_key);
if (pub_key)
pub_key = BN_dup(pub_key);
if (priv_key)
priv_key = BN_dup(priv_key);
DH_set0_key(ret, const_cast< BIGNUM* >(pub_key), const_cast< BIGNUM* >(priv_ke
y));
return ret; return ret;
} }
H235_DiffieHellman::H235_DiffieHellman(const H235_DiffieHellman & diffie) H235_DiffieHellman::H235_DiffieHellman(const H235_DiffieHellman & diffie)
: m_remKey(NULL), m_toSend(diffie.GetToSend()), m_wasReceived(ReceivedFromRemote ()), m_wasDHReceived(diffie.DHReceived()), : m_remKey(NULL), m_toSend(diffie.GetToSend()), m_wasReceived(ReceivedFromRemote ()), m_wasDHReceived(diffie.DHReceived()),
m_keySize(diffie.GetKeySize()), m_loadFromFile(diffie.LoadFile()) m_keySize(diffie.GetKeySize()), m_loadFromFile(diffie.LoadFile())
{ {
dh = DH_dup(diffie); dh = DH_dup(diffie);
} }
skipping to change at line 158 skipping to change at line 250
m_keySize = other.GetKeySize(); m_keySize = other.GetKeySize();
m_loadFromFile = other.LoadFile(); m_loadFromFile = other.LoadFile();
} }
return *this; return *this;
} }
H235_DiffieHellman::~H235_DiffieHellman() H235_DiffieHellman::~H235_DiffieHellman()
{ {
if (dh) if (dh)
DH_free(dh); DH_free(dh);
if (m_remKey)
BN_free(m_remKey);
} }
PObject * H235_DiffieHellman::Clone() const PObject * H235_DiffieHellman::Clone() const
{ {
return new H235_DiffieHellman(*this); return new H235_DiffieHellman(*this);
} }
PBoolean H235_DiffieHellman::CheckParams() const PBoolean H235_DiffieHellman::CheckParams() const
{ {
// TODO: FIX so it actually checks the whole DH // TODO: FIX so it actually checks the whole DH
skipping to change at line 203 skipping to change at line 297
return TRUE; return TRUE;
} }
PBoolean H235_DiffieHellman::Encode_P(PASN_BitString & p) const PBoolean H235_DiffieHellman::Encode_P(PASN_BitString & p) const
{ {
PWaitAndSignal m(vbMutex); PWaitAndSignal m(vbMutex);
if (!m_toSend) if (!m_toSend)
return false; return false;
unsigned char * data = (unsigned char *)OPENSSL_malloc(BN_num_bytes(dh->p)); const BIGNUM *dh_p = NULL;
DH_get0_pqg(dh, &dh_p, NULL, NULL);
unsigned char * data = (unsigned char *)OPENSSL_malloc(BN_num_bytes(dh_p));
if (data != NULL) { if (data != NULL) {
memset(data, 0, BN_num_bytes(dh->p)); memset(data, 0, BN_num_bytes(dh_p));
if (BN_bn2bin(dh->p, data) > 0) { if (BN_bn2bin(dh_p, data) > 0) {
p.SetData(BN_num_bits(dh->p), data); p.SetData(BN_num_bits(dh_p), data);
} else { } else {
PTRACE(1, "H235_DH\tFailed to encode P"); PTRACE(1, "H235_DH\tFailed to encode P");
OPENSSL_free(data); OPENSSL_free(data);
return false; return false;
} }
} }
OPENSSL_free(data); OPENSSL_free(data);
return true; return true;
} }
void H235_DiffieHellman::Decode_P(const PASN_BitString & p) void H235_DiffieHellman::Decode_P(const PASN_BitString & p)
{ {
if (p.GetSize() == 0) if (p.GetSize() == 0)
return; return;
PWaitAndSignal m(vbMutex); PWaitAndSignal m(vbMutex);
const unsigned char * data = p.GetDataPointer(); DH_set0_pqg(dh, BN_bin2bn(p.GetDataPointer(), p.GetDataLength() - 1, NULL), NU
if (dh->p) LL, NULL);
BN_free(dh->p);
dh->p = BN_bin2bn(data, p.GetDataLength() - 1, NULL);
} }
PBoolean H235_DiffieHellman::Encode_G(PASN_BitString & g) const PBoolean H235_DiffieHellman::Encode_G(PASN_BitString & g) const
{ {
if (!m_toSend) if (!m_toSend)
return false; return false;
PWaitAndSignal m(vbMutex); PWaitAndSignal m(vbMutex);
int len_p = BN_num_bytes(dh->p);
int len_g = BN_num_bytes(dh->g); const BIGNUM *dh_p = NULL, *dh_g = NULL;
int bits_p = BN_num_bits(dh->p); DH_get0_pqg(dh, &dh_p, NULL, &dh_g);
//int bits_g = BN_num_bits(dh->g); // unused
int len_p = BN_num_bytes(dh_p);
int len_g = BN_num_bytes(dh_g);
int bits_p = BN_num_bits(dh_p);
//int bits_g = BN_num_bits(dh_g); // unused
if (len_p <= 128) { // Key lengths <= 1024 bits if (len_p <= 128) { // Key lengths <= 1024 bits
// Backwards compatibility G is padded out to the length of P // Backwards compatibility G is padded out to the length of P
unsigned char * data = (unsigned char *)OPENSSL_malloc(len_p); unsigned char * data = (unsigned char *)OPENSSL_malloc(len_p);
if (data != NULL) { if (data != NULL) {
memset(data, 0, len_p); memset(data, 0, len_p);
if (BN_bn2bin(dh->g, data + len_p - len_g) > 0) { if (BN_bn2bin(dh_g, data + len_p - len_g) > 0) {
g.SetData(bits_p, data); g.SetData(bits_p, data);
} }
else { else {
PTRACE(1, "H235_DH\tFailed to encode G"); PTRACE(1, "H235_DH\tFailed to encode G");
OPENSSL_free(data); OPENSSL_free(data);
return false; return false;
} }
} }
OPENSSL_free(data); OPENSSL_free(data);
} else { } else {
unsigned char * data = (unsigned char *)OPENSSL_malloc(len_g); unsigned char * data = (unsigned char *)OPENSSL_malloc(len_g);
if (data != NULL) { if (data != NULL) {
memset(data, 0, len_g); memset(data, 0, len_g);
if (BN_bn2bin(dh->g, data) > 0) { if (BN_bn2bin(dh_g, data) > 0) {
g.SetData(8, data); g.SetData(8, data);
} }
else { else {
PTRACE(1, "H235_DH\tFailed to encode P"); PTRACE(1, "H235_DH\tFailed to encode P");
OPENSSL_free(data); OPENSSL_free(data);
return false; return false;
} }
} }
OPENSSL_free(data); OPENSSL_free(data);
} }
return true; return true;
} }
void H235_DiffieHellman::Decode_G(const PASN_BitString & g) void H235_DiffieHellman::Decode_G(const PASN_BitString & g)
{ {
if (g.GetSize() == 0) if (g.GetSize() == 0)
return; return;
PWaitAndSignal m(vbMutex); PWaitAndSignal m(vbMutex);
if (dh->g) DH_set0_pqg(dh, NULL, NULL, BN_bin2bn(g.GetDataPointer(), g.GetDataLength() -
BN_free(dh->g); 1, NULL));
dh->g = BN_bin2bn(g.GetDataPointer(), g.GetDataLength() - 1, NULL);
} }
void H235_DiffieHellman::Encode_HalfKey(PASN_BitString & hk) const void H235_DiffieHellman::Encode_HalfKey(PASN_BitString & hk) const
{ {
PWaitAndSignal m(vbMutex); PWaitAndSignal m(vbMutex);
int len_p = BN_num_bytes(dh->p); const BIGNUM *dh_p = NULL;
int len_key = BN_num_bytes(dh->pub_key); DH_get0_pqg(dh, &dh_p, NULL, NULL);
int bits_p = BN_num_bits(dh->p); const BIGNUM *pub_key = NULL;
DH_get0_key(dh, &pub_key, NULL);
int len_p = BN_num_bytes(dh_p);
int len_key = BN_num_bytes(pub_key);
int bits_p = BN_num_bits(dh_p);
if (len_key > len_p) { if (len_key > len_p) {
PTRACE(1, "H235_DH\tFailed to encode halfkey: len key > len prime"); PTRACE(1, "H235_DH\tFailed to encode halfkey: len key > len prime");
return; return;
} }
// halfkey is padded out to the length of P // halfkey is padded out to the length of P
unsigned char * data = (unsigned char *)OPENSSL_malloc(len_p); unsigned char * data = (unsigned char *)OPENSSL_malloc(len_p);
if (data != NULL) { if (data != NULL) {
memset(data, 0, len_p); memset(data, 0, len_p);
if (BN_bn2bin(dh->pub_key, data + len_p - len_key) > 0) { if (BN_bn2bin(pub_key, data + len_p - len_key) > 0) {
hk.SetData(bits_p, data); hk.SetData(bits_p, data);
} else { } else {
PTRACE(1, "H235_DH\tFailed to encode halfkey"); PTRACE(1, "H235_DH\tFailed to encode halfkey");
} }
} }
OPENSSL_free(data); OPENSSL_free(data);
} }
void H235_DiffieHellman::Decode_HalfKey(const PASN_BitString & hk) void H235_DiffieHellman::Decode_HalfKey(const PASN_BitString & hk)
{ {
PWaitAndSignal m(vbMutex); PWaitAndSignal m(vbMutex);
const unsigned char *data = hk.GetDataPointer(); const unsigned char *data = hk.GetDataPointer();
if (dh->pub_key) DH_set0_key(dh, BN_bin2bn(data, hk.GetDataLength() - 1, NULL), NULL);
BN_free(dh->pub_key);
dh->pub_key = BN_bin2bn(data, hk.GetDataLength() - 1, NULL);
} }
void H235_DiffieHellman::SetRemoteKey(bignum_st * remKey) void H235_DiffieHellman::SetRemoteKey(bignum_st * remKey)
{ {
m_remKey = remKey; m_remKey = remKey;
} }
void H235_DiffieHellman::SetRemoteHalfKey(const PASN_BitString & hk) void H235_DiffieHellman::SetRemoteHalfKey(const PASN_BitString & hk)
{ {
const unsigned char *data = hk.GetDataPointer(); const unsigned char *data = hk.GetDataPointer();
if (m_remKey) if (m_remKey)
BN_free(m_remKey); BN_free(m_remKey);
m_remKey = BN_bin2bn(data, hk.GetDataLength() - 1, NULL); m_remKey = BN_bin2bn(data, hk.GetDataLength() - 1, NULL);
if (m_remKey) if (m_remKey)
m_wasReceived = true; m_wasReceived = true;
} }
PBoolean H235_DiffieHellman::GenerateHalfKey() PBoolean H235_DiffieHellman::GenerateHalfKey()
{ {
if (dh && dh->pub_key) if (dh) {
return true; const BIGNUM *pub_key = NULL;
DH_get0_key(dh, &pub_key, NULL);
if (pub_key)
return true;
}
PWaitAndSignal m(vbMutex); PWaitAndSignal m(vbMutex);
if (!DH_generate_key(dh)) { if (!DH_generate_key(dh)) {
char buf[256]; char buf[256];
ERR_error_string(ERR_get_error(), buf); ERR_error_string(ERR_get_error(), buf);
PTRACE(1, "H235_DH\tERROR generating DH halfkey " << buf); PTRACE(1, "H235_DH\tERROR generating DH halfkey " << buf);
return FALSE; return FALSE;
} }
skipping to change at line 376 skipping to change at line 479
DH_free(dh); DH_free(dh);
dh = NULL; dh = NULL;
} }
dh = DH_new(); dh = DH_new();
if (dh == NULL) if (dh == NULL)
return false; return false;
PString str; PString str;
PBYTEArray data; PBYTEArray data;
BIGNUM *dh_p = NULL, *dh_g = NULL, *pub_key = NULL, *priv_key = NULL;
PBoolean ok = true; PBoolean ok = true;
if (dhFile.HasKey(section, "PRIME")) { if (dhFile.HasKey(section, "PRIME")) {
str = dhFile.GetString(section, "PRIME", ""); str = dhFile.GetString(section, "PRIME", "");
PBase64::Decode(str, data); PBase64::Decode(str, data);
dh->p = BN_bin2bn(data.GetPointer(), data.GetSize(), NULL); dh_p = BN_bin2bn(data.GetPointer(), data.GetSize(), NULL);
ok = ok && (BN_num_bytes(dh->p) > 0); ok = ok && (BN_num_bytes(dh_p) > 0);
} else } else
ok = false; ok = false;
if (dhFile.HasKey(section, "GENERATOR")) { if (dhFile.HasKey(section, "GENERATOR")) {
str = dhFile.GetString(section, "GENERATOR", ""); str = dhFile.GetString(section, "GENERATOR", "");
PBase64::Decode(str, data); PBase64::Decode(str, data);
PBYTEArray temp(1); PBYTEArray temp(1);
memcpy(temp.GetPointer(), data.GetPointer(), 1); memcpy(temp.GetPointer(), data.GetPointer(), 1);
memset(data.GetPointer(), 0, data.GetSize()); memset(data.GetPointer(), 0, data.GetSize());
memcpy(data.GetPointer() + data.GetSize()-1, temp.GetPointer(), 1); memcpy(data.GetPointer() + data.GetSize()-1, temp.GetPointer(), 1);
dh->g = BN_bin2bn(data.GetPointer(), data.GetSize(), NULL); dh_g = BN_bin2bn(data.GetPointer(), data.GetSize(), NULL);
ok = ok && (BN_num_bytes(dh->g) > 0); ok = ok && (BN_num_bytes(dh_g) > 0);
} else } else
ok = false; ok = false;
if (dhFile.HasKey(section, "PUBLIC")) { if (dhFile.HasKey(section, "PUBLIC")) {
str = dhFile.GetString(section, "PUBLIC", ""); str = dhFile.GetString(section, "PUBLIC", "");
PBase64::Decode(str, data); PBase64::Decode(str, data);
dh->pub_key = BN_bin2bn(data.GetPointer(), data.GetSize(), NULL); pub_key = BN_bin2bn(data.GetPointer(), data.GetSize(), NULL);
ok = ok && (BN_num_bytes(dh->pub_key) > 0); ok = ok && (BN_num_bytes(pub_key) > 0);
} }
if (dhFile.HasKey(section, "PRIVATE")) { if (dhFile.HasKey(section, "PRIVATE")) {
str = dhFile.GetString(section, "PRIVATE", ""); str = dhFile.GetString(section, "PRIVATE", "");
PBase64::Decode(str, data); PBase64::Decode(str, data);
dh->priv_key = BN_bin2bn(data.GetPointer(), data.GetSize(), NULL); priv_key = BN_bin2bn(data.GetPointer(), data.GetSize(), NULL);
ok = ok && (BN_num_bytes(dh->priv_key) > 0); ok = ok && (BN_num_bytes(priv_key) > 0);
}
if (ok) {
if (DH_set0_pqg(dh, dh_p, NULL, dh_g)) {
dh_p = NULL;
dh_g = NULL;
} else {
ok = false;
}
}
if (ok) {
if (DH_set0_key(dh, pub_key, priv_key)) {
pub_key = NULL;
priv_key = NULL;
} else {
ok = false;
}
} }
if (ok /*&& CheckParams()*/) if (ok /*&& CheckParams()*/)
m_loadFromFile = true; m_loadFromFile = true;
else { else {
if (priv_key)
BN_free(priv_key);
if (pub_key)
BN_free(pub_key);
if (dh_g)
BN_free(dh_g);
if (dh_p)
BN_free(dh_p);
DH_free(dh); DH_free(dh);
dh = NULL; dh = NULL;
} }
return m_loadFromFile; return m_loadFromFile;
} }
PBoolean H235_DiffieHellman::LoadedFromFile() PBoolean H235_DiffieHellman::LoadedFromFile()
{ {
return m_loadFromFile; return m_loadFromFile;
} }
PBoolean H235_DiffieHellman::Save(const PFilePath & dhFile, const PString & oid) PBoolean H235_DiffieHellman::Save(const PFilePath & dhFile, const PString & oid)
{ {
if (!dh || !dh->pub_key) if (!dh)
return false;
const BIGNUM *pub_key = NULL, *priv_key = NULL;
DH_get0_key(dh, &pub_key, &priv_key);
if (!pub_key)
return false; return false;
const BIGNUM *dh_p = NULL, *dh_g = NULL;
DH_get0_pqg(dh, &dh_p, NULL, &dh_g);
PConfig config(dhFile, oid); PConfig config(dhFile, oid);
PString str = PString(); PString str = PString();
int len = BN_num_bytes(dh->pub_key); int len = BN_num_bytes(pub_key);
unsigned char * data = (unsigned char *)OPENSSL_malloc(len); unsigned char * data = (unsigned char *)OPENSSL_malloc(len);
if (data != NULL && BN_bn2bin(dh->p, data) > 0) { if (data != NULL && BN_bn2bin(dh_p, data) > 0) {
str = PBase64::Encode(data, len, ""); str = PBase64::Encode(data, len, "");
config.SetString("PRIME",str); config.SetString("PRIME",str);
} }
OPENSSL_free(data); OPENSSL_free(data);
data = (unsigned char *)OPENSSL_malloc(len); data = (unsigned char *)OPENSSL_malloc(len);
if (data != NULL && BN_bn2bin(dh->g, data) > 0) { if (data != NULL && BN_bn2bin(dh_g, data) > 0) {
str = PBase64::Encode(data, len, ""); str = PBase64::Encode(data, len, "");
config.SetString("GENERATOR",str); config.SetString("GENERATOR",str);
} }
OPENSSL_free(data); OPENSSL_free(data);
data = (unsigned char *)OPENSSL_malloc(len); data = (unsigned char *)OPENSSL_malloc(len);
if (data != NULL && BN_bn2bin(dh->pub_key, data) > 0) { if (data != NULL && BN_bn2bin(pub_key, data) > 0) {
str = PBase64::Encode(data, len, ""); str = PBase64::Encode(data, len, "");
config.SetString("PUBLIC",str); config.SetString("PUBLIC",str);
} }
OPENSSL_free(data); OPENSSL_free(data);
data = (unsigned char *)OPENSSL_malloc(len); data = (unsigned char *)OPENSSL_malloc(len);
if (data != NULL && BN_bn2bin(dh->priv_key, data) > 0) { if (data != NULL && BN_bn2bin(priv_key, data) > 0) {
PString str = PBase64::Encode(data, len, ""); PString str = PBase64::Encode(data, len, "");
config.SetString("PRIVATE",str); config.SetString("PRIVATE",str);
} }
OPENSSL_free(data); OPENSSL_free(data);
return true; return true;
} }
PBoolean H235_DiffieHellman::ComputeSessionKey(PBYTEArray & SessionKey) PBoolean H235_DiffieHellman::ComputeSessionKey(PBYTEArray & SessionKey)
{ {
SessionKey.SetSize(0); SessionKey.SetSize(0);
skipping to change at line 494 skipping to change at line 632
SessionKey.SetSize(out); SessionKey.SetSize(out);
memcpy(SessionKey.GetPointer(), (void *)buf, out); memcpy(SessionKey.GetPointer(), (void *)buf, out);
OPENSSL_free(buf); OPENSSL_free(buf);
return true; return true;
} }
bignum_st * H235_DiffieHellman::GetPublicKey() const bignum_st * H235_DiffieHellman::GetPublicKey() const
{ {
return dh->pub_key; const BIGNUM *pub_key = NULL;
DH_get0_key(dh, &pub_key, NULL);
return const_cast< BIGNUM* >(pub_key);
} }
int H235_DiffieHellman::GetKeyLength() const int H235_DiffieHellman::GetKeyLength() const
{ {
return m_keySize; return m_keySize;
} }
void H235_DiffieHellman::Generate(PINDEX keyLength, PINDEX keyGenerator, PString ToString & parameters) void H235_DiffieHellman::Generate(PINDEX keyLength, PINDEX keyGenerator, PString ToString & parameters)
{ {
PString lOID; PString lOID;
skipping to change at line 525 skipping to change at line 665
dh_st * vdh = DH_new(); dh_st * vdh = DH_new();
if (!DH_generate_parameters_ex(vdh, keyLength, keyGenerator, NULL)) { if (!DH_generate_parameters_ex(vdh, keyLength, keyGenerator, NULL)) {
cout << "Error generating Key Pair\n"; cout << "Error generating Key Pair\n";
DH_free(vdh); DH_free(vdh);
vdh = NULL; vdh = NULL;
return; return;
} }
parameters.SetAt("OID", lOID); parameters.SetAt("OID", lOID);
const BIGNUM *vdh_p = NULL, *vdh_g = NULL;
DH_get0_pqg(vdh, &vdh_p, NULL, &vdh_g);
PString str = PString(); PString str = PString();
int len = BN_num_bytes(vdh->p); int len = BN_num_bytes(vdh_p);
unsigned char * data = (unsigned char *)OPENSSL_malloc(len); unsigned char * data = (unsigned char *)OPENSSL_malloc(len);
if (data != NULL && BN_bn2bin(vdh->p, data) > 0) { if (data != NULL && BN_bn2bin(vdh_p, data) > 0) {
str = PBase64::Encode(data, len, ""); str = PBase64::Encode(data, len, "");
parameters.SetAt("PRIME", str); parameters.SetAt("PRIME", str);
} }
OPENSSL_free(data); OPENSSL_free(data);
len = BN_num_bytes(vdh->g); len = BN_num_bytes(vdh_g);
data = (unsigned char *)OPENSSL_malloc(len); data = (unsigned char *)OPENSSL_malloc(len);
if (data != NULL && BN_bn2bin(vdh->g, data) > 0) { if (data != NULL && BN_bn2bin(vdh_g, data) > 0) {
str = PBase64::Encode(data, len, ""); str = PBase64::Encode(data, len, "");
parameters.SetAt("GENERATOR", str); parameters.SetAt("GENERATOR", str);
} }
OPENSSL_free(data); OPENSSL_free(data);
DH_free(vdh); DH_free(vdh);
} }
#endif // H323_H235 #endif // H323_H235
 End of changes. 40 change blocks. 
61 lines changed or deleted 209 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)