Ejemplo n.º 1
0
int c1s1::c1_create(srs_schema_type _schema)
{
    int ret = ERROR_SUCCESS;

    if (_schema == srs_schema_invalid) {
        ret = ERROR_RTMP_CH_SCHEMA;
        log_error("create c1 failed. invalid schema=%d, ret=%d", _schema, ret);
        return ret;
    }

    destroy_blocks();

    time = ::time(NULL);
    // client c1 version
    char *_version = (char *)&version;
    _version[0] = 10;
    _version[1] = 0;
    _version[2] = 45;
    _version[3] = 2;

    if (_schema == srs_schema0) {
        srs_key_block_init(&block0.key);
        srs_digest_block_init(&block1.digest);
    } else {
        srs_digest_block_init(&block0.digest);
        srs_key_block_init(&block1.key);
    }

    schema = _schema;

    char *digest = NULL;

    if ((ret = calc_c1_digest(digest)) != ERROR_SUCCESS) {
        log_error("sign c1 error, failed to calc digest. ret=%d", ret);
        return ret;
    }

    mAssert(digest != NULL);
    mAutoFreeArray(char, digest);

    if (schema == srs_schema0) {
        memcpy(block1.digest.digest, digest, 32);
    } else {
        memcpy(block0.digest.digest, digest, 32);
    }

    return ret;
}
 int c1s1::c1_create(srs_schema_type _schema)
 {
     int ret = ERROR_SUCCESS;
     
     if (_schema == srs_schema_invalid) {
         ret = ERROR_RTMP_CH_SCHEMA;
         srs_error("create c1 failed. invalid schema=%d, ret=%d", _schema, ret);
         return ret;
     }
     
     destroy_blocks();
     
     // client c1 time and version
     time = ::time(NULL);
     version = 0x80000702; // client c1 version
     
     // generate signature by schema
     if (_schema == srs_schema0) {
         srs_key_block_init(&block0.key);
         srs_digest_block_init(&block1.digest);
     } else {
         srs_digest_block_init(&block0.digest);
         srs_key_block_init(&block1.key);
     }
     
     schema = _schema;
     
     // generate digest
     char* digest = NULL;
     
     if ((ret = calc_c1_digest(digest)) != ERROR_SUCCESS) {
         srs_error("sign c1 error, failed to calc digest. ret=%d", ret);
         return ret;
     }
     
     srs_assert(digest != NULL);
     SrsAutoFree(char, digest);
     
     if (schema == srs_schema0) {
         memcpy(block1.digest.digest, digest, 32);
     } else {
         memcpy(block0.digest.digest, digest, 32);
     }
     
     return ret;
 }
Ejemplo n.º 3
0
int c1s1::c1_validate_digest(bool &is_valid)
{
    int ret = ERROR_SUCCESS;

    char *c1_digest = NULL;

    if ((ret = calc_c1_digest(c1_digest)) != ERROR_SUCCESS) {
        log_error("validate c1 error, failed to calc digest. ret=%d", ret);
        return ret;
    }

    mAssert(c1_digest != NULL);
    mAutoFreeArray(char, c1_digest);

    if (schema == srs_schema0) {
        is_valid = srs_bytes_equals(block1.digest.digest, c1_digest, 32);
    } else {
        is_valid = srs_bytes_equals(block0.digest.digest, c1_digest, 32);
    }

    return ret;
}