|
|
@ -198,9 +198,9 @@ namespace _srs_internal
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// copy public key to bytes.
|
|
|
|
// copy public key to bytes.
|
|
|
|
// TODO: FIXME: please finger it out.
|
|
|
|
// sometimes, the key_size is 127, seems ok.
|
|
|
|
int32_t key_size = BN_num_bytes(pdh->pub_key);
|
|
|
|
int32_t key_size = BN_num_bytes(pdh->pub_key);
|
|
|
|
srs_assert(key_size == size);
|
|
|
|
srs_assert(key_size > 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (BN_bn2bin(pdh->pub_key, (unsigned char*)public_key) != size) {
|
|
|
|
if (BN_bn2bin(pdh->pub_key, (unsigned char*)public_key) != size) {
|
|
|
|
//("Unable to copy key"); return ret;
|
|
|
|
//("Unable to copy key"); return ret;
|
|
|
@ -211,18 +211,13 @@ namespace _srs_internal
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* create DH and copy the 128bytes public key,
|
|
|
|
* use exists DH to create and copy the 128bytes shared key.
|
|
|
|
* generate and copy the shared key.
|
|
|
|
* the peer public key used to generate the shared key.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int __openssl_compute_key(DH* pdh, const char* peer_pub_key, int ppk_size, char* public_key, char* shared_key)
|
|
|
|
int __openssl_copy_shared_key(DH* pdh, const char* peer_pub_key, int ppk_size, char* shared_key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
|
|
// create DH and copy the 128bytes public key
|
|
|
|
|
|
|
|
if ((ret = __openssl_copy_key(pdh, public_key, ppk_size)) != ERROR_SUCCESS) {
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BIGNUM* ppk = NULL;
|
|
|
|
BIGNUM* ppk = NULL;
|
|
|
|
if ((ppk = BN_bin2bn((const unsigned char*)peer_pub_key, ppk_size, 0)) == NULL) {
|
|
|
|
if ((ppk = BN_bin2bn((const unsigned char*)peer_pub_key, ppk_size, 0)) == NULL) {
|
|
|
|
ret = ERROR_OpenSslGetPeerPublicKey;
|
|
|
|
ret = ERROR_OpenSslGetPeerPublicKey;
|
|
|
@ -240,6 +235,26 @@ namespace _srs_internal
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* create DH and copy the 128bytes public key,
|
|
|
|
|
|
|
|
* generate and copy the shared key.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int __openssl_compute_key(DH* pdh, const char* peer_pub_key, int ppk_size, char* public_key, char* shared_key)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create DH and copy the 128bytes public key
|
|
|
|
|
|
|
|
if ((ret = __openssl_copy_key(pdh, public_key, ppk_size)) != ERROR_SUCCESS) {
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// generate and copy the shared key
|
|
|
|
|
|
|
|
if ((ret = __openssl_copy_shared_key(pdh, peer_pub_key, ppk_size, shared_key)) != ERROR_SUCCESS) {
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
void __openssl_free(DH* pdh)
|
|
|
|
void __openssl_free(DH* pdh)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (pdh != NULL) {
|
|
|
|
if (pdh != NULL) {
|
|
|
|