| @@ -91,7 +91,11 @@ typedef struct RTMPContext { · 90 unmodified lines |
| 91 | 91 | int nb_invokes; ///< keeps track of invoke messages |
| 92 | 92 | char* tcurl; ///< url of the target stream |
| 93 | 93 | char* flashver; ///< version of the flash plugin |
| 94 | + char* swfhash; ///< SHA256 hash of the decompressed SWF file (32 bytes) |
| 95 | + int swfhash_len; ///< length of the SHA256 hash |
| 96 | + int swfsize; ///< size of the decompressed SWF file |
| 94 | 97 | char* swfurl; ///< url of the swf player |
| 98 | + char swfverification[42]; ///< hash of the SWF verification |
| 95 | 99 | char* pageurl; ///< url of the web page |
| 96 | 100 | char* subscribe; ///< name of live stream to subscribe |
| 97 | 101 | int server_bw; ///< server bandwidth |
| @@ -592,6 +596,27 @@ static int gen_pong(URLContext *s, RTMPContext *rt, RTMPPacket *ppkt) · 494 unmodified lines |
| 592 | 596 | return rtmp_send_packet(rt, &pkt, 0); |
| 593 | 597 | } |
| 594 | 598 | |
| 599 | +/** |
| 600 | + * Generate SWF verification message and send it to the server. |
| 601 | + */ |
| 602 | +static int gen_swf_verification(URLContext *s, RTMPContext *rt) |
| 603 | +{ |
| 604 | + RTMPPacket pkt; |
| 605 | + uint8_t *p; |
| 606 | + int ret; |
| 607 | + |
| 608 | + av_log(s, AV_LOG_DEBUG, "Sending SWF verification...\n"); |
| 609 | + if ((ret = ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_PING, |
| 610 | + 0, 44)) < 0) |
| 611 | + return ret; |
| 612 | + |
| 613 | + p = pkt.data; |
| 614 | + bytestream_put_be16(&p, 27); |
| 615 | + memcpy(p, rt->swfverification, 42); |
| 616 | + |
| 617 | + return rtmp_send_packet(rt, &pkt, 0); |
| 618 | +} |
| 619 | + |
| 595 | 620 | /** |
| 596 | 621 | * Generate server bandwidth message and send it to the server. |
| 597 | 622 | */ |
| @@ -776,6 +801,30 @@ static int rtmp_validate_digest(uint8_t *buf, int off) · 178 unmodified lines |
| 776 | 801 | return 0; |
| 777 | 802 | } |
| 778 | 803 | |
| 804 | +static int rtmp_calc_swf_verification(URLContext *s, RTMPContext *rt, |
| 805 | + uint8_t *buf) |
| 806 | +{ |
| 807 | + uint8_t *p; |
| 808 | + int ret; |
| 809 | + |
| 810 | + if (rt->swfhash_len != 32) { |
| 811 | + av_log(s, AV_LOG_ERROR, |
| 812 | + "Hash of the decompressed SWF file is not 32 bytes long.\n"); |
| 813 | + return AVERROR(EINVAL); |
| 814 | + } |
| 815 | + |
| 816 | + p = &rt->swfverification[0]; |
| 817 | + bytestream_put_byte(&p, 1); |
| 818 | + bytestream_put_byte(&p, 1); |
| 819 | + bytestream_put_be32(&p, rt->swfsize); |
| 820 | + bytestream_put_be32(&p, rt->swfsize); |
| 821 | + |
| 822 | + if ((ret = ff_rtmp_calc_digest(rt->swfhash, 32, 0, buf, 32, p)) < 0) |
| 823 | + return ret; |
| 824 | + |
| 825 | + return 0; |
| 826 | +} |
| 827 | + |
| 779 | 828 | /** |
| 780 | 829 | * Perform handshake with the server by means of exchanging pseudorandom data |
| 781 | 830 | * signed with HMAC-SHA2 digest. |
| @@ -866,6 +915,14 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) · 84 unmodified lines |
| 866 | 915 | } |
| 867 | 916 | } |
| 868 | 917 | |
| 918 | + /* Generate SWFVerification token (SHA256 HMAC hash of decompressed SWF, |
| 919 | + * key are the last 32 bytes of the server handshake. */ |
| 920 | + if (rt->swfsize) { |
| 921 | + if ((ret = rtmp_calc_swf_verification(s, rt, serverdata + 1 + |
| 922 | + RTMP_HANDSHAKE_PACKET_SIZE - 32)) < 0) |
| 923 | + return ret; |
| 924 | + } |
| 925 | + |
| 869 | 926 | ret = ff_rtmp_calc_digest(tosend + 1 + client_pos, 32, 0, |
| 870 | 927 | rtmp_server_key, sizeof(rtmp_server_key), |
| 871 | 928 | digest); |
| @@ -1001,6 +1058,13 @@ static int handle_ping(URLContext *s, RTMPPacket *pkt) · 129 unmodified lines |
| 1001 | 1058 | if (t == 6) { |
| 1002 | 1059 | if ((ret = gen_pong(s, rt, pkt)) < 0) |
| 1003 | 1060 | return ret; |
| 1061 | + } else if (t == 26) { |
| 1062 | + if (rt->swfsize) { |
| 1063 | + if ((ret = gen_swf_verification(s, rt)) < 0) |
| 1064 | + return ret; |
| 1065 | + } else { |
| 1066 | + av_log(s, AV_LOG_WARNING, "Ignoring SWFVerification request.\n"); |
| 1067 | + } |
| 1004 | 1068 | } |
| 1005 | 1069 | |
| 1006 | 1070 | return 0; |
| @@ -1717,6 +1781,8 @@ static const AVOption rtmp_options[] = { · 710 unmodified lines |
| 1717 | 1781 | {"rtmp_pageurl", "URL of the web page in which the media was embedded. By default no value will be sent.", OFFSET(pageurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC}, |
| 1718 | 1782 | {"rtmp_playpath", "Stream identifier to play or to publish", OFFSET(playpath), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, |
| 1719 | 1783 | {"rtmp_subscribe", "Name of live stream to subscribe to. Defaults to rtmp_playpath.", OFFSET(subscribe), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC}, |
| 1784 | + {"rtmp_swfhash", "SHA256 hash of the decompressed SWF file (32 bytes).", OFFSET(swfhash), AV_OPT_TYPE_BINARY, .flags = DEC}, |
| 1785 | + {"rtmp_swfsize", "Size of the decompressed SWF file, required for SWFVerification.", OFFSET(swfsize), AV_OPT_TYPE_INT, {0}, 0, INT_MAX, DEC}, |
| 1720 | 1786 | {"rtmp_swfurl", "URL of the SWF player. By default no value will be sent", OFFSET(swfurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, |
| 1721 | 1787 | {"rtmp_tcurl", "URL of the target stream. Defaults to proto://host[:port]/app.", OFFSET(tcurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, |
| 1722 | 1788 | { NULL }, |