1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

support vn/an to disable video/audio, for radio streaming

This commit is contained in:
winlin 2014-03-19 22:45:58 +08:00
parent 747bbd988e
commit b7d40b5aba
6 changed files with 1044 additions and 935 deletions

21
trunk/conf/full.conf Normal file → Executable file
View file

@ -291,6 +291,25 @@ vhost audio.transcode.vhost.com {
}
}
}
# disable video, transcode/copy audio.
# for example, publish pure audio stream.
vhost vn.transcode.vhost.com {
transcode {
enabled on;
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
engine vn {
enabled on;
vcodec vn;
acodec libaacplus;
abitrate 45;
asample_rate 44100;
achannels 2;
aparams {
}
output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
}
}
}
# ffmpeg-copy(forward implements by ffmpeg).
# copy the video and audio to a new stream.
vhost copy.transcode.vhost.com {
@ -333,6 +352,7 @@ vhost all.transcode.vhost.com {
# video encoder name. can be:
# libx264: use h.264(libx264) video encoder.
# copy: donot encoder the video stream, copy it.
# vn: disable video output.
vcodec libx264;
# video bitrate, in kbps
vbitrate 1500;
@ -364,6 +384,7 @@ vhost all.transcode.vhost.com {
# audio encoder name. can be:
# libaacplus: use aac(libaacplus) audio encoder.
# copy: donot encoder the audio stream, copy it.
# an: disable audio output.
acodec libaacplus;
# audio bitrate, in kbps. [16, 72] for libaacplus.
abitrate 70;

15
trunk/conf/srs.conf Normal file → Executable file
View file

@ -3,4 +3,19 @@
listen 1935;
vhost __defaultVhost__ {
transcode {
enabled on;
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
engine vn {
enabled on;
vcodec vn;
acodec libaacplus;
abitrate 45;
asample_rate 44100;
achannels 2;
aparams {
}
output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
}
}
}

View file

@ -42,6 +42,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifdef SRS_FFMPEG
#define SRS_ENCODER_COPY "copy"
#define SRS_ENCODER_NO_VIDEO "vn"
#define SRS_ENCODER_NO_AUDIO "an"
#define SRS_ENCODER_VCODEC "libx264"
#define SRS_ENCODER_ACODEC "libaacplus"
@ -138,7 +140,13 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine)
}
_transcoded_url.push_back(output);
if (vcodec != SRS_ENCODER_COPY) {
if (vcodec == SRS_ENCODER_NO_VIDEO && acodec == SRS_ENCODER_NO_AUDIO) {
ret = ERROR_ENCODER_VCODEC;
srs_warn("video and audio disabled. ret=%d", ret);
return ret;
}
if (vcodec != SRS_ENCODER_COPY && vcodec != SRS_ENCODER_NO_VIDEO) {
if (vcodec != SRS_ENCODER_VCODEC) {
ret = ERROR_ENCODER_VCODEC;
srs_error("invalid vcodec, must be %s, actual %s, ret=%d",
@ -182,7 +190,7 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine)
}
}
if (acodec != SRS_ENCODER_COPY) {
if (acodec != SRS_ENCODER_COPY && acodec != SRS_ENCODER_NO_AUDIO) {
if (acodec != SRS_ENCODER_ACODEC) {
ret = ERROR_ENCODER_ACODEC;
srs_error("invalid acodec, must be %s, actual %s, ret=%d",
@ -254,11 +262,15 @@ int SrsFFMPEG::start()
}
// video specified.
if (vcodec != SRS_ENCODER_NO_VIDEO) {
params.push_back("-vcodec");
params.push_back(vcodec);
} else {
params.push_back("-vn");
}
// the codec params is disabled when copy
if (vcodec != SRS_ENCODER_COPY) {
if (vcodec != SRS_ENCODER_COPY && vcodec != SRS_ENCODER_NO_VIDEO) {
params.push_back("-b:v");
snprintf(tmp, sizeof(tmp), "%d", vbitrate * 1000);
params.push_back(tmp);
@ -299,11 +311,15 @@ int SrsFFMPEG::start()
}
// audio specified.
if (acodec != SRS_ENCODER_NO_AUDIO) {
params.push_back("-acodec");
params.push_back(acodec);
} else {
params.push_back("-an");
}
// the codec params is disabled when copy
if (acodec != SRS_ENCODER_COPY) {
if (acodec != SRS_ENCODER_COPY && acodec != SRS_ENCODER_NO_AUDIO) {
params.push_back("-b:a");
snprintf(tmp, sizeof(tmp), "%d", abitrate * 1000);
params.push_back(tmp);

View file

@ -32,12 +32,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_protocol_utility.hpp>
#include <srs_protocol_rtmp.hpp>
using namespace srs;
#ifdef SRS_SSL
// 68bytes FMS key which is used to sign the sever packet.
u_int8_t srs::SrsGenuineFMSKey[] = {
using namespace srs;
// for openssl_HMACsha256
#include <openssl/evp.h>
#include <openssl/hmac.h>
// for __openssl_generate_key
#include <openssl/dh.h>
namespace srs
{
// 68bytes FMS key which is used to sign the sever packet.
u_int8_t SrsGenuineFMSKey[] = {
0x47, 0x65, 0x6e, 0x75, 0x69, 0x6e, 0x65, 0x20,
0x41, 0x64, 0x6f, 0x62, 0x65, 0x20, 0x46, 0x6c,
0x61, 0x73, 0x68, 0x20, 0x4d, 0x65, 0x64, 0x69,
@ -47,10 +55,10 @@ u_int8_t srs::SrsGenuineFMSKey[] = {
0x2e, 0x00, 0xd0, 0xd1, 0x02, 0x9e, 0x7e, 0x57,
0x6e, 0xec, 0x5d, 0x2d, 0x29, 0x80, 0x6f, 0xab,
0x93, 0xb8, 0xe6, 0x36, 0xcf, 0xeb, 0x31, 0xae
}; // 68
}; // 68
// 62bytes FP key which is used to sign the client packet.
u_int8_t srs::SrsGenuineFPKey[] = {
// 62bytes FP key which is used to sign the client packet.
u_int8_t SrsGenuineFPKey[] = {
0x47, 0x65, 0x6E, 0x75, 0x69, 0x6E, 0x65, 0x20,
0x41, 0x64, 0x6F, 0x62, 0x65, 0x20, 0x46, 0x6C,
0x61, 0x73, 0x68, 0x20, 0x50, 0x6C, 0x61, 0x79,
@ -59,12 +67,10 @@ u_int8_t srs::SrsGenuineFPKey[] = {
0x2E, 0x00, 0xD0, 0xD1, 0x02, 0x9E, 0x7E, 0x57,
0x6E, 0xEC, 0x5D, 0x2D, 0x29, 0x80, 0x6F, 0xAB,
0x93, 0xB8, 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE
}; // 62
}; // 62
#include <openssl/evp.h>
#include <openssl/hmac.h>
int srs::openssl_HMACsha256(const void* data, int data_size, const void* key, int key_size, void* digest)
{
int openssl_HMACsha256(const void* data, int data_size, const void* key, int key_size, void* digest)
{
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
@ -81,20 +87,19 @@ int srs::openssl_HMACsha256(const void* data, int data_size, const void* key, in
}
return ERROR_SUCCESS;
}
}
#include <openssl/dh.h>
#define RFC2409_PRIME_1024 \
#define RFC2409_PRIME_1024 \
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381" \
"FFFFFFFFFFFFFFFF"
int __openssl_generate_key(
int __openssl_generate_key(
u_int8_t*& _private_key, u_int8_t*& _public_key, int32_t& size,
DH*& pdh, int32_t& bits_count, u_int8_t*& shared_key, int32_t& shared_key_length, BIGNUM*& peer_public_key
){
){
int ret = ERROR_SUCCESS;
//1. Create the DH
@ -182,9 +187,9 @@ int __openssl_generate_key(
}
return ret;
}
int openssl_generate_key(char* _private_key, char* _public_key, int32_t size)
{
}
int openssl_generate_key(char* _private_key, char* _public_key, int32_t size)
{
int ret = ERROR_SUCCESS;
// Initialize
@ -223,12 +228,12 @@ int openssl_generate_key(char* _private_key, char* _public_key, int32_t size)
}
return ret;
}
}
// calc the offset of key,
// the key->offset cannot be used as the offset of key.
int srs_key_block_get_offset(key_block* key)
{
// calc the offset of key,
// the key->offset cannot be used as the offset of key.
int srs_key_block_get_offset(key_block* key)
{
int max_offset_size = 764 - 128 - 4;
int offset = 0;
@ -239,11 +244,12 @@ int srs_key_block_get_offset(key_block* key)
offset += *pp++;
return offset % max_offset_size;
}
// create new key block data.
// if created, user must free it by srs_key_block_free
void srs_key_block_init(key_block* key)
{
}
// create new key block data.
// if created, user must free it by srs_key_block_free
void srs_key_block_init(key_block* key)
{
key->offset = (int32_t)rand();
key->random0 = NULL;
key->random1 = NULL;
@ -264,12 +270,13 @@ void srs_key_block_init(key_block* key)
key->random1 = new char[key->random1_size];
srs_random_generate(key->random1, key->random1_size);
}
}
// parse key block from c1s1.
// if created, user must free it by srs_key_block_free
// @c1s1_key_bytes the key start bytes, maybe c1s1 or c1s1+764
int srs_key_block_parse(key_block* key, char* c1s1_key_bytes)
{
}
// parse key block from c1s1.
// if created, user must free it by srs_key_block_free
// @c1s1_key_bytes the key start bytes, maybe c1s1 or c1s1+764
int srs_key_block_parse(key_block* key, char* c1s1_key_bytes)
{
int ret = ERROR_SUCCESS;
char* pp = c1s1_key_bytes + 764;
@ -301,23 +308,24 @@ int srs_key_block_parse(key_block* key, char* c1s1_key_bytes)
}
return ret;
}
// free the block data create by
// srs_key_block_init or srs_key_block_parse
void srs_key_block_free(key_block* key)
{
}
// free the block data create by
// srs_key_block_init or srs_key_block_parse
void srs_key_block_free(key_block* key)
{
if (key->random0) {
srs_freepa(key->random0);
}
if (key->random1) {
srs_freepa(key->random1);
}
}
}
// calc the offset of digest,
// the key->offset cannot be used as the offset of digest.
int srs_digest_block_get_offset(digest_block* digest)
{
// calc the offset of digest,
// the key->offset cannot be used as the offset of digest.
int srs_digest_block_get_offset(digest_block* digest)
{
int max_offset_size = 764 - 32 - 4;
int offset = 0;
@ -328,11 +336,12 @@ int srs_digest_block_get_offset(digest_block* digest)
offset += *pp++;
return offset % max_offset_size;
}
// create new digest block data.
// if created, user must free it by srs_digest_block_free
void srs_digest_block_init(digest_block* digest)
{
}
// create new digest block data.
// if created, user must free it by srs_digest_block_free
void srs_digest_block_init(digest_block* digest)
{
digest->offset = (int32_t)rand();
digest->random0 = NULL;
digest->random1 = NULL;
@ -353,12 +362,13 @@ void srs_digest_block_init(digest_block* digest)
digest->random1 = new char[digest->random1_size];
srs_random_generate(digest->random1, digest->random1_size);
}
}
// parse digest block from c1s1.
// if created, user must free it by srs_digest_block_free
// @c1s1_digest_bytes the digest start bytes, maybe c1s1 or c1s1+764
int srs_digest_block_parse(digest_block* digest, char* c1s1_digest_bytes)
{
}
// parse digest block from c1s1.
// if created, user must free it by srs_digest_block_free
// @c1s1_digest_bytes the digest start bytes, maybe c1s1 or c1s1+764
int srs_digest_block_parse(digest_block* digest, char* c1s1_digest_bytes)
{
int ret = ERROR_SUCCESS;
char* pp = c1s1_digest_bytes;
@ -389,33 +399,34 @@ int srs_digest_block_parse(digest_block* digest, char* c1s1_digest_bytes)
}
return ret;
}
// free the block data create by
// srs_digest_block_init or srs_digest_block_parse
void srs_digest_block_free(digest_block* digest)
{
}
// free the block data create by
// srs_digest_block_init or srs_digest_block_parse
void srs_digest_block_free(digest_block* digest)
{
if (digest->random0) {
srs_freepa(digest->random0);
}
if (digest->random1) {
srs_freepa(digest->random1);
}
}
}
void __srs_time_copy_to(char*& pp, int32_t time)
{
void __srs_time_copy_to(char*& pp, int32_t time)
{
// 4bytes time
*(int32_t*)pp = time;
pp += 4;
}
void __srs_version_copy_to(char*& pp, int32_t version)
{
}
void __srs_version_copy_to(char*& pp, int32_t version)
{
// 4bytes version
*(int32_t*)pp = version;
pp += 4;
}
void __srs_key_copy_to(char*& pp, key_block* key)
{
}
void __srs_key_copy_to(char*& pp, key_block* key)
{
// 764bytes key block
if (key->random0_size > 0) {
memcpy(pp, key->random0, key->random0_size);
@ -432,9 +443,9 @@ void __srs_key_copy_to(char*& pp, key_block* key)
*(int32_t*)pp = key->offset;
pp += 4;
}
void __srs_digest_copy_to(char*& pp, digest_block* digest, bool with_digest)
{
}
void __srs_digest_copy_to(char*& pp, digest_block* digest, bool with_digest)
{
// 732bytes digest block without the 32bytes digest-data
// nbytes digest block part1
*(int32_t*)pp = digest->offset;
@ -456,14 +467,14 @@ void __srs_digest_copy_to(char*& pp, digest_block* digest, bool with_digest)
memcpy(pp, digest->random1, digest->random1_size);
}
pp += digest->random1_size;
}
}
/**
* copy whole c1s1 to bytes.
*/
void srs_schema0_copy_to(char* bytes, bool with_digest,
/**
* copy whole c1s1 to bytes.
*/
void srs_schema0_copy_to(char* bytes, bool with_digest,
int32_t time, int32_t version, key_block* key, digest_block* digest)
{
{
char* pp = bytes;
__srs_time_copy_to(pp, time);
@ -476,10 +487,10 @@ void srs_schema0_copy_to(char* bytes, bool with_digest,
} else {
srs_assert(pp - bytes == 1536 - 32);
}
}
void srs_schema1_copy_to(char* bytes, bool with_digest,
}
void srs_schema1_copy_to(char* bytes, bool with_digest,
int32_t time, int32_t version, digest_block* digest, key_block* key)
{
{
char* pp = bytes;
__srs_time_copy_to(pp, time);
@ -492,43 +503,43 @@ void srs_schema1_copy_to(char* bytes, bool with_digest,
} else {
srs_assert(pp - bytes == 1536 - 32);
}
}
}
/**
* c1s1 is splited by digest:
* c1s1-part1: n bytes (time, version, key and digest-part1).
* digest-data: 32bytes
* c1s1-part2: (1536-n-32)bytes (digest-part2)
*/
char* srs::srs_bytes_join_schema0(int32_t time, int32_t version, key_block* key, digest_block* digest)
{
/**
* c1s1 is splited by digest:
* c1s1-part1: n bytes (time, version, key and digest-part1).
* digest-data: 32bytes
* c1s1-part2: (1536-n-32)bytes (digest-part2)
*/
char* srs_bytes_join_schema0(int32_t time, int32_t version, key_block* key, digest_block* digest)
{
char* bytes = new char[1536 -32];
srs_schema0_copy_to(bytes, false, time, version, key, digest);
return bytes;
}
}
/**
* c1s1 is splited by digest:
* c1s1-part1: n bytes (time, version and digest-part1).
* digest-data: 32bytes
* c1s1-part2: (1536-n-32)bytes (digest-part2 and key)
*/
char* srs::srs_bytes_join_schema1(int32_t time, int32_t version, digest_block* digest, key_block* key)
{
/**
* c1s1 is splited by digest:
* c1s1-part1: n bytes (time, version and digest-part1).
* digest-data: 32bytes
* c1s1-part2: (1536-n-32)bytes (digest-part2 and key)
*/
char* srs_bytes_join_schema1(int32_t time, int32_t version, digest_block* digest, key_block* key)
{
char* bytes = new char[1536 -32];
srs_schema1_copy_to(bytes, false, time, version, digest, key);
return bytes;
}
}
/**
* compare the memory in bytes.
*/
bool srs::srs_bytes_equals(void* pa, void* pb, int size)
{
/**
* compare the memory in bytes.
*/
bool srs_bytes_equals(void* pa, void* pb, int size)
{
u_int8_t* a = (u_int8_t*)pa;
u_int8_t* b = (u_int8_t*)pb;
@ -539,32 +550,32 @@ bool srs::srs_bytes_equals(void* pa, void* pb, int size)
}
return true;
}
}
c2s2::c2s2()
{
c2s2::c2s2()
{
srs_random_generate(random, 1504);
srs_random_generate(digest, 32);
}
}
c2s2::~c2s2()
{
}
c2s2::~c2s2()
{
}
void c2s2::dump(char* _c2s2)
{
void c2s2::dump(char* _c2s2)
{
memcpy(_c2s2, random, 1504);
memcpy(_c2s2 + 1504, digest, 32);
}
}
void c2s2::parse(char* _c2s2)
{
void c2s2::parse(char* _c2s2)
{
memcpy(random, _c2s2, 1504);
memcpy(digest, _c2s2 + 1504, 32);
}
}
int c2s2::c2_create(c1s1* s1)
{
int c2s2::c2_create(c1s1* s1)
{
int ret = ERROR_SUCCESS;
char temp_key[OpensslHashSize];
@ -584,10 +595,10 @@ int c2s2::c2_create(c1s1* s1)
memcpy(digest, _digest, 32);
return ret;
}
}
int c2s2::c2_validate(c1s1* s1, bool& is_valid)
{
int c2s2::c2_validate(c1s1* s1, bool& is_valid)
{
is_valid = false;
int ret = ERROR_SUCCESS;
@ -608,10 +619,10 @@ int c2s2::c2_validate(c1s1* s1, bool& is_valid)
is_valid = srs_bytes_equals(digest, _digest, 32);
return ret;
}
}
int c2s2::s2_create(c1s1* c1)
{
int c2s2::s2_create(c1s1* c1)
{
int ret = ERROR_SUCCESS;
char temp_key[OpensslHashSize];
@ -631,10 +642,10 @@ int c2s2::s2_create(c1s1* c1)
memcpy(digest, _digest, 32);
return ret;
}
}
int c2s2::s2_validate(c1s1* c1, bool& is_valid)
{
int c2s2::s2_validate(c1s1* c1, bool& is_valid)
{
is_valid = false;
int ret = ERROR_SUCCESS;
@ -655,20 +666,20 @@ int c2s2::s2_validate(c1s1* c1, bool& is_valid)
is_valid = srs_bytes_equals(digest, _digest, 32);
return ret;
}
}
// TODO: FIXME: move to the right position.
c1s1::c1s1()
{
// TODO: FIXME: move to the right position.
c1s1::c1s1()
{
schema = srs_schema_invalid;
}
c1s1::~c1s1()
{
}
c1s1::~c1s1()
{
destroy_blocks();
}
}
char* c1s1::get_digest()
{
char* c1s1::get_digest()
{
srs_assert(schema != srs_schema_invalid);
if (schema == srs_schema0) {
@ -676,10 +687,10 @@ char* c1s1::get_digest()
} else {
return block0.digest.digest;
}
}
}
void c1s1::dump(char* _c1s1)
{
void c1s1::dump(char* _c1s1)
{
srs_assert(schema != srs_schema_invalid);
if (schema == srs_schema0) {
@ -687,10 +698,10 @@ void c1s1::dump(char* _c1s1)
} else {
srs_schema1_copy_to(_c1s1, true, time, version, &block0.digest, &block1.key);
}
}
}
int c1s1::parse(char* _c1s1, srs_schema_type _schema)
{
int c1s1::parse(char* _c1s1, srs_schema_type _schema)
{
int ret = ERROR_SUCCESS;
if (_schema == srs_schema_invalid) {
@ -733,10 +744,10 @@ int c1s1::parse(char* _c1s1, srs_schema_type _schema)
schema = _schema;
return ret;
}
}
int c1s1::c1_create(srs_schema_type _schema)
{
int c1s1::c1_create(srs_schema_type _schema)
{
int ret = ERROR_SUCCESS;
if (_schema == srs_schema_invalid) {
@ -777,10 +788,10 @@ int c1s1::c1_create(srs_schema_type _schema)
}
return ret;
}
}
int c1s1::c1_validate_digest(bool& is_valid)
{
int c1s1::c1_validate_digest(bool& is_valid)
{
is_valid = false;
int ret = ERROR_SUCCESS;
@ -801,10 +812,10 @@ int c1s1::c1_validate_digest(bool& is_valid)
}
return ret;
}
}
int c1s1::s1_validate_digest(bool& is_valid)
{
int c1s1::s1_validate_digest(bool& is_valid)
{
is_valid = false;
int ret = ERROR_SUCCESS;
@ -825,10 +836,10 @@ int c1s1::s1_validate_digest(bool& is_valid)
}
return ret;
}
}
int c1s1::s1_create(c1s1* c1)
{
int c1s1::s1_create(c1s1* c1)
{
int ret = ERROR_SUCCESS;
if (c1->schema == srs_schema_invalid) {
@ -882,10 +893,10 @@ int c1s1::s1_create(c1s1* c1)
srs_verbose("copy s1 key success.");
return ret;
}
}
int c1s1::calc_s1_digest(char*& digest)
{
int c1s1::calc_s1_digest(char*& digest)
{
int ret = ERROR_SUCCESS;
srs_assert(schema == srs_schema0 || schema == srs_schema1);
@ -909,10 +920,10 @@ int c1s1::calc_s1_digest(char*& digest)
srs_verbose("digest calculated for s1");
return ret;
}
}
int c1s1::calc_c1_digest(char*& digest)
{
int c1s1::calc_c1_digest(char*& digest)
{
int ret = ERROR_SUCCESS;
srs_assert(schema == srs_schema0 || schema == srs_schema1);
@ -936,10 +947,10 @@ int c1s1::calc_c1_digest(char*& digest)
srs_verbose("digest calculated for c1");
return ret;
}
}
void c1s1::destroy_blocks()
{
void c1s1::destroy_blocks()
{
if (schema == srs_schema_invalid) {
return;
}
@ -951,6 +962,7 @@ void c1s1::destroy_blocks()
srs_digest_block_free(&block0.digest);
srs_key_block_free(&block1.key);
}
}
}
#endif
@ -1144,13 +1156,10 @@ int SrsComplexHandshake::handshake_with_client(SrsHandshakeBytes* hs_bytes, ISrs
c2s2 c2;
c2.parse(hs_bytes->c2);
srs_verbose("complex handshake read c2 success.");
// verify c2
if ((ret = c2.c2_validate(&s1, is_valid)) != ERROR_SUCCESS || !is_valid) {
ret = ERROR_RTMP_HANDSHAKE;
srs_trace("verify c2 failed. ret=%d", ret);
return ret;
}
srs_verbose("verify c2 success.");
// never verify c2, for ffmpeg will failed.
// it's ok for flash.
srs_trace("comple handshake with client success");

View file

@ -97,6 +97,78 @@ namespace srs
int random1_size;
};
// the digest key generate size.
#define OpensslHashSize 512
extern u_int8_t SrsGenuineFMSKey[];
extern u_int8_t SrsGenuineFPKey[];
int openssl_HMACsha256(const void* data, int data_size, const void* key, int key_size, void* digest);
int openssl_generate_key(char* _private_key, char* _public_key, int32_t size);
// calc the offset of key,
// the key->offset cannot be used as the offset of key.
int srs_key_block_get_offset(key_block* key);
// create new key block data.
// if created, user must free it by srs_key_block_free
void srs_key_block_init(key_block* key);
// parse key block from c1s1.
// if created, user must free it by srs_key_block_free
// @c1s1_key_bytes the key start bytes, maybe c1s1 or c1s1+764
int srs_key_block_parse(key_block* key, char* c1s1_key_bytes);
// free the block data create by
// srs_key_block_init or srs_key_block_parse
void srs_key_block_free(key_block* key);
// calc the offset of digest,
// the key->offset cannot be used as the offset of digest.
int srs_digest_block_get_offset(digest_block* digest);
// create new digest block data.
// if created, user must free it by srs_digest_block_free
void srs_digest_block_init(digest_block* digest);
// parse digest block from c1s1.
// if created, user must free it by srs_digest_block_free
// @c1s1_digest_bytes the digest start bytes, maybe c1s1 or c1s1+764
int srs_digest_block_parse(digest_block* digest, char* c1s1_digest_bytes);
// free the block data create by
// srs_digest_block_init or srs_digest_block_parse
void srs_digest_block_free(digest_block* digest);
/**
* copy whole c1s1 to bytes.
*/
void srs_schema0_copy_to(char* bytes, bool with_digest,
int32_t time, int32_t version, key_block* key, digest_block* digest);
void srs_schema1_copy_to(char* bytes, bool with_digest,
int32_t time, int32_t version, digest_block* digest, key_block* key);
/**
* c1s1 is splited by digest:
* c1s1-part1: n bytes (time, version, key and digest-part1).
* digest-data: 32bytes
* c1s1-part2: (1536-n-32)bytes (digest-part2)
* @return a new allocated bytes, user must free it.
*/
char* srs_bytes_join_schema0(int32_t time, int32_t version, key_block* key, digest_block* digest);
/**
* c1s1 is splited by digest:
* c1s1-part1: n bytes (time, version and digest-part1).
* digest-data: 32bytes
* c1s1-part2: (1536-n-32)bytes (digest-part2 and key)
* @return a new allocated bytes, user must free it.
*/
char* srs_bytes_join_schema1(int32_t time, int32_t version, digest_block* digest, key_block* key);
/**
* compare the memory in bytes.
*/
bool srs_bytes_equals(void* pa, void* pb, int size);
/**
* c1s1 schema0
* time: 4bytes
@ -236,35 +308,6 @@ namespace srs
*/
virtual int s2_validate(c1s1* c1, bool& is_valid);
};
/**
* compare the memory in bytes.
*/
bool srs_bytes_equals(void* pa, void* pb, int size);
/**
* c1s1 is splited by digest:
* c1s1-part1: n bytes (time, version, key and digest-part1).
* digest-data: 32bytes
* c1s1-part2: (1536-n-32)bytes (digest-part2)
* @return a new allocated bytes, user must free it.
*/
char* srs_bytes_join_schema0(int32_t time, int32_t version, key_block* key, digest_block* digest);
/**
* c1s1 is splited by digest:
* c1s1-part1: n bytes (time, version and digest-part1).
* digest-data: 32bytes
* c1s1-part2: (1536-n-32)bytes (digest-part2 and key)
* @return a new allocated bytes, user must free it.
*/
char* srs_bytes_join_schema1(int32_t time, int32_t version, digest_block* digest, key_block* key);
// the digest key generate size.
#define OpensslHashSize 512
extern u_int8_t SrsGenuineFMSKey[];
extern u_int8_t SrsGenuineFPKey[];
int openssl_HMACsha256(const void* data, int data_size, const void* key, int key_size, void* digest);
}
#endif

View file

@ -260,3 +260,8 @@ VOID TEST(HandshakeTest, ComplexHandshake)
ASSERT_TRUE(is_valid);
}
}
VOID TEST(HandshakeTest, BytesEqual)
{
//srs_bytes_equals
}