Modified from code in SRS2 (src/protocol/srs_rtmp_handshake.cpp:94)
| 146 | |
| 147 | // Modified from code in SRS2 (src/protocol/srs_rtmp_handshake.cpp:94) |
| 148 | int openssl_HMACsha256(const void* key, int key_size, |
| 149 | const void* data, int data_size, void* digest) { |
| 150 | if (NULL == EVP_sha256) { |
| 151 | LOG_ONCE(ERROR) << "Fail to find EVP_sha256, fall back to simple handshaking"; |
| 152 | return -1; |
| 153 | } |
| 154 | unsigned int digest_size = 0; |
| 155 | unsigned char* temp_digest = (unsigned char*)digest; |
| 156 | if (key == NULL) { |
| 157 | // NOTE: first parameter of EVP_Digest in older openssl is void*. |
| 158 | if (EVP_Digest(const_cast<void*>(data), data_size, temp_digest, |
| 159 | &digest_size, EVP_sha256(), NULL) < 0) { |
| 160 | LOG(ERROR) << "Fail to EVP_Digest"; |
| 161 | return -1; |
| 162 | } |
| 163 | } else { |
| 164 | // Note: following code uses HMAC_CTX previously which is ABI |
| 165 | // inconsistent in different version of openssl. |
| 166 | if (HMAC(EVP_sha256(), key, key_size, |
| 167 | (const unsigned char*) data, data_size, |
| 168 | temp_digest, &digest_size) == NULL) { |
| 169 | LOG(ERROR) << "Fail to HMAC"; |
| 170 | return -1; |
| 171 | } |
| 172 | } |
| 173 | if (digest_size != 32) { |
| 174 | LOG(ERROR) << "digest_size=" << digest_size << " of sha256 is not 32"; |
| 175 | return -1; |
| 176 | } |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | // 68bytes FMS key for signing the sever packets. |
| 181 | static const uint8_t GenuineFMSKey[] = { |
no outgoing calls
no test coverage detected