近來公司有 HTTPS 傳輸影音的需求,於是就基於Simple TLS Server寫了一個用 https 傳輸FLV檔案的最小實現當作proof of concept 這樣。
Source code 源碼
github download
Makefile need openssl ,要是buildroot 沒有就只能自備了
-lev -lssl -lz -lcrypto
Usage
[root@:]# ./https_flv_file_test -h
Usage
-p port number
-s flv format src file
-c cert.pem file
-k private key file
-h help
Concepts description
概念上一個 HTTPS in c需要的步驟
HTTPs in C needs the fallowing steps
- create ssl
SSL_CTX *ctx;
init_openssl();
ctx = create_context();
As normal tcpsocket link
- SSL_write(…) == send(…)
- SSL_read(…) == recv(…)
- end ssl
SSL_shutdown(ssl);
SSL_free(ssl);
close(client);
- close tcp socket
- release ssl
SSL_CTX_free(ctx);
cleanup_openssl();
In fact, HTTPS streaming is essentially HTTP-FLV with an additional layer of SSL/TLS encryption for the handshake process. The HTTP messages and FLV format inside are exactly the same as in HTTP-FLV.
Points to note:
- VLC requires a valid security certificate to play HTTPS streams.
- A media player that supports HTTPS must be used in the web browser to receive HTTPS streaming.
- When running the browser, it is necessary to add the flag --ignore-certificate-errors.
其實https streaming 就是在 http-flv 的基礎加一層 SSL/TLS 加密的握手過程,裡面的http報文與flv 格式與http-flv 完全一樣。
需要特別注意的是:
- vlc 必須通過安全憑證才能撥放 https
- 在 web browser 需要使用 https 的播放器才能收https streamming
- 並且運行瀏覽器的時候需要加上 --ignore-certificate-errors
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --ignore-certificate-errors