├── .gitignore
├── LICENSE
├── README.md
├── blake2-impl.h
├── blake2.h
├── blake2b-ref.c
├── librtmp
├── amf.c
├── amf.h
├── bytes.h
├── cencode.c
├── cencode.h
├── dh.h
├── dhgroups.h
├── handshake.h
├── hashswf.c
├── http.h
├── log.c
├── log.h
├── md5.c
├── md5.h
├── parseurl.c
├── rtmp.c
├── rtmp.h
├── rtmp_sys.h
└── stdint.h
├── main.cpp
├── resource.h
├── small.ico
├── twichtest.rc
├── twitchbwtest.vcxproj
└── twitchtest.ico
/.gitignore:
--------------------------------------------------------------------------------
1 | # Object files
2 | *.o
3 | *.ko
4 | *.obj
5 | *.elf
6 |
7 | # Precompiled Headers
8 | *.gch
9 | *.pch
10 |
11 | # Libraries
12 | *.lib
13 | *.a
14 | *.la
15 | *.lo
16 |
17 | # Shared objects (inc. Windows DLLs)
18 | *.dll
19 | *.so
20 | *.so.*
21 | *.dylib
22 |
23 | # Executables
24 | *.exe
25 | *.out
26 | *.app
27 | *.i*86
28 | *.x86_64
29 | *.hex
30 |
31 | # Debug files
32 | *.dSYM/
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TwitchTest
2 | Bandwidth tester for [Twitch](https://twitch.tv/)
3 |
4 | 
5 |
6 | TwitchTest creates a test stream to Twitch, using the "?bandwidthtest" option so your channel doesn't actually go live. It will attempt to stream at up to 10 mbps and show the achieved bitrate for each server. An estimation of the connection quality is presented, which is based on the number of retransmissions required and how consistent the delay between consecutive sends are. A connection quality of 80+ is recommended for a reliable stream. The TCP window size (SO_SNDBUF) can be adjusted to see what effects it has, the default setting matches what is used in [OBS](https://obsproject.com/).
7 |
8 | Requires Administrator privileges to run, as the Windows TCP connection metrics API is only available to applications running as administrator.
9 |
10 | A pre-compiled binary for Windows can be downloaded at https://r1ch.net/projects/twitchtest.
11 |
--------------------------------------------------------------------------------
/blake2-impl.h:
--------------------------------------------------------------------------------
1 | /*
2 | BLAKE2 reference source code package - reference C implementations
3 |
4 | Copyright 2012, Samuel Neves . You may use this under the
5 | terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
6 | your option. The terms of these licenses can be found at:
7 |
8 | - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
9 | - OpenSSL license : https://www.openssl.org/source/license.html
10 | - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | More information about the BLAKE2 hash function can be found at
13 | https://blake2.net.
14 | */
15 | #ifndef BLAKE2_IMPL_H
16 | #define BLAKE2_IMPL_H
17 |
18 | #include
19 | #include
20 |
21 | #if !defined(__cplusplus) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
22 | #if defined(_MSC_VER)
23 | #define BLAKE2_INLINE __inline
24 | #elif defined(__GNUC__)
25 | #define BLAKE2_INLINE __inline__
26 | #else
27 | #define BLAKE2_INLINE
28 | #endif
29 | #else
30 | #define BLAKE2_INLINE inline
31 | #endif
32 |
33 | static BLAKE2_INLINE uint32_t load32( const void *src )
34 | {
35 | #if defined(NATIVE_LITTLE_ENDIAN)
36 | uint32_t w;
37 | memcpy(&w, src, sizeof w);
38 | return w;
39 | #else
40 | const uint8_t *p = ( const uint8_t * )src;
41 | return (( uint32_t )( p[0] ) << 0) |
42 | (( uint32_t )( p[1] ) << 8) |
43 | (( uint32_t )( p[2] ) << 16) |
44 | (( uint32_t )( p[3] ) << 24) ;
45 | #endif
46 | }
47 |
48 | static BLAKE2_INLINE uint64_t load64( const void *src )
49 | {
50 | #if defined(NATIVE_LITTLE_ENDIAN)
51 | uint64_t w;
52 | memcpy(&w, src, sizeof w);
53 | return w;
54 | #else
55 | const uint8_t *p = ( const uint8_t * )src;
56 | return (( uint64_t )( p[0] ) << 0) |
57 | (( uint64_t )( p[1] ) << 8) |
58 | (( uint64_t )( p[2] ) << 16) |
59 | (( uint64_t )( p[3] ) << 24) |
60 | (( uint64_t )( p[4] ) << 32) |
61 | (( uint64_t )( p[5] ) << 40) |
62 | (( uint64_t )( p[6] ) << 48) |
63 | (( uint64_t )( p[7] ) << 56) ;
64 | #endif
65 | }
66 |
67 | static BLAKE2_INLINE uint16_t load16( const void *src )
68 | {
69 | #if defined(NATIVE_LITTLE_ENDIAN)
70 | uint16_t w;
71 | memcpy(&w, src, sizeof w);
72 | return w;
73 | #else
74 | const uint8_t *p = ( const uint8_t * )src;
75 | return (( uint16_t )( p[0] ) << 0) |
76 | (( uint16_t )( p[1] ) << 8) ;
77 | #endif
78 | }
79 |
80 | static BLAKE2_INLINE void store16( void *dst, uint16_t w )
81 | {
82 | #if defined(NATIVE_LITTLE_ENDIAN)
83 | memcpy(dst, &w, sizeof w);
84 | #else
85 | uint8_t *p = ( uint8_t * )dst;
86 | *p++ = ( uint8_t )w; w >>= 8;
87 | *p++ = ( uint8_t )w;
88 | #endif
89 | }
90 |
91 | static BLAKE2_INLINE void store32( void *dst, uint32_t w )
92 | {
93 | #if defined(NATIVE_LITTLE_ENDIAN)
94 | memcpy(dst, &w, sizeof w);
95 | #else
96 | uint8_t *p = ( uint8_t * )dst;
97 | p[0] = (uint8_t)(w >> 0);
98 | p[1] = (uint8_t)(w >> 8);
99 | p[2] = (uint8_t)(w >> 16);
100 | p[3] = (uint8_t)(w >> 24);
101 | #endif
102 | }
103 |
104 | static BLAKE2_INLINE void store64( void *dst, uint64_t w )
105 | {
106 | #if defined(NATIVE_LITTLE_ENDIAN)
107 | memcpy(dst, &w, sizeof w);
108 | #else
109 | uint8_t *p = ( uint8_t * )dst;
110 | p[0] = (uint8_t)(w >> 0);
111 | p[1] = (uint8_t)(w >> 8);
112 | p[2] = (uint8_t)(w >> 16);
113 | p[3] = (uint8_t)(w >> 24);
114 | p[4] = (uint8_t)(w >> 32);
115 | p[5] = (uint8_t)(w >> 40);
116 | p[6] = (uint8_t)(w >> 48);
117 | p[7] = (uint8_t)(w >> 56);
118 | #endif
119 | }
120 |
121 | static BLAKE2_INLINE uint64_t load48( const void *src )
122 | {
123 | const uint8_t *p = ( const uint8_t * )src;
124 | return (( uint64_t )( p[0] ) << 0) |
125 | (( uint64_t )( p[1] ) << 8) |
126 | (( uint64_t )( p[2] ) << 16) |
127 | (( uint64_t )( p[3] ) << 24) |
128 | (( uint64_t )( p[4] ) << 32) |
129 | (( uint64_t )( p[5] ) << 40) ;
130 | }
131 |
132 | static BLAKE2_INLINE void store48( void *dst, uint64_t w )
133 | {
134 | uint8_t *p = ( uint8_t * )dst;
135 | p[0] = (uint8_t)(w >> 0);
136 | p[1] = (uint8_t)(w >> 8);
137 | p[2] = (uint8_t)(w >> 16);
138 | p[3] = (uint8_t)(w >> 24);
139 | p[4] = (uint8_t)(w >> 32);
140 | p[5] = (uint8_t)(w >> 40);
141 | }
142 |
143 | static BLAKE2_INLINE uint32_t rotr32( const uint32_t w, const unsigned c )
144 | {
145 | return ( w >> c ) | ( w << ( 32 - c ) );
146 | }
147 |
148 | static BLAKE2_INLINE uint64_t rotr64( const uint64_t w, const unsigned c )
149 | {
150 | return ( w >> c ) | ( w << ( 64 - c ) );
151 | }
152 |
153 | /* prevents compiler optimizing out memset() */
154 | static BLAKE2_INLINE void secure_zero_memory(void *v, size_t n)
155 | {
156 | static void *(*const volatile memset_v)(void *, int, size_t) = &memset;
157 | memset_v(v, 0, n);
158 | }
159 |
160 | #endif
161 |
--------------------------------------------------------------------------------
/blake2.h:
--------------------------------------------------------------------------------
1 | /*
2 | BLAKE2 reference source code package - reference C implementations
3 |
4 | Copyright 2012, Samuel Neves . You may use this under the
5 | terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
6 | your option. The terms of these licenses can be found at:
7 |
8 | - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
9 | - OpenSSL license : https://www.openssl.org/source/license.html
10 | - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | More information about the BLAKE2 hash function can be found at
13 | https://blake2.net.
14 | */
15 | #ifndef BLAKE2_H
16 | #define BLAKE2_H
17 |
18 | #include
19 | #include
20 |
21 | #if defined(_MSC_VER)
22 | #define BLAKE2_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
23 | #else
24 | #define BLAKE2_PACKED(x) x __attribute__((packed))
25 | #endif
26 |
27 | #if defined(__cplusplus)
28 | extern "C" {
29 | #endif
30 |
31 | enum blake2s_constant
32 | {
33 | BLAKE2S_BLOCKBYTES = 64,
34 | BLAKE2S_OUTBYTES = 32,
35 | BLAKE2S_KEYBYTES = 32,
36 | BLAKE2S_SALTBYTES = 8,
37 | BLAKE2S_PERSONALBYTES = 8
38 | };
39 |
40 | enum blake2b_constant
41 | {
42 | BLAKE2B_BLOCKBYTES = 128,
43 | BLAKE2B_OUTBYTES = 64,
44 | BLAKE2B_KEYBYTES = 64,
45 | BLAKE2B_SALTBYTES = 16,
46 | BLAKE2B_PERSONALBYTES = 16
47 | };
48 |
49 | typedef struct blake2s_state__
50 | {
51 | uint32_t h[8];
52 | uint32_t t[2];
53 | uint32_t f[2];
54 | uint8_t buf[BLAKE2S_BLOCKBYTES];
55 | size_t buflen;
56 | size_t outlen;
57 | uint8_t last_node;
58 | } blake2s_state;
59 |
60 | typedef struct blake2b_state__
61 | {
62 | uint64_t h[8];
63 | uint64_t t[2];
64 | uint64_t f[2];
65 | uint8_t buf[BLAKE2B_BLOCKBYTES];
66 | size_t buflen;
67 | size_t outlen;
68 | uint8_t last_node;
69 | } blake2b_state;
70 |
71 | typedef struct blake2sp_state__
72 | {
73 | blake2s_state S[8][1];
74 | blake2s_state R[1];
75 | uint8_t buf[8 * BLAKE2S_BLOCKBYTES];
76 | size_t buflen;
77 | size_t outlen;
78 | } blake2sp_state;
79 |
80 | typedef struct blake2bp_state__
81 | {
82 | blake2b_state S[4][1];
83 | blake2b_state R[1];
84 | uint8_t buf[4 * BLAKE2B_BLOCKBYTES];
85 | size_t buflen;
86 | size_t outlen;
87 | } blake2bp_state;
88 |
89 |
90 | BLAKE2_PACKED(struct blake2s_param__
91 | {
92 | uint8_t digest_length; /* 1 */
93 | uint8_t key_length; /* 2 */
94 | uint8_t fanout; /* 3 */
95 | uint8_t depth; /* 4 */
96 | uint32_t leaf_length; /* 8 */
97 | uint32_t node_offset; /* 12 */
98 | uint16_t xof_length; /* 14 */
99 | uint8_t node_depth; /* 15 */
100 | uint8_t inner_length; /* 16 */
101 | /* uint8_t reserved[0]; */
102 | uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
103 | uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
104 | });
105 |
106 | typedef struct blake2s_param__ blake2s_param;
107 |
108 | BLAKE2_PACKED(struct blake2b_param__
109 | {
110 | uint8_t digest_length; /* 1 */
111 | uint8_t key_length; /* 2 */
112 | uint8_t fanout; /* 3 */
113 | uint8_t depth; /* 4 */
114 | uint32_t leaf_length; /* 8 */
115 | uint32_t node_offset; /* 12 */
116 | uint32_t xof_length; /* 16 */
117 | uint8_t node_depth; /* 17 */
118 | uint8_t inner_length; /* 18 */
119 | uint8_t reserved[14]; /* 32 */
120 | uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
121 | uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
122 | });
123 |
124 | typedef struct blake2b_param__ blake2b_param;
125 |
126 | typedef struct blake2xs_state__
127 | {
128 | blake2s_state S[1];
129 | blake2s_param P[1];
130 | } blake2xs_state;
131 |
132 | typedef struct blake2xb_state__
133 | {
134 | blake2b_state S[1];
135 | blake2b_param P[1];
136 | } blake2xb_state;
137 |
138 | /* Padded structs result in a compile-time error */
139 | enum {
140 | BLAKE2_DUMMY_1 = 1/(int)(sizeof(blake2s_param) == BLAKE2S_OUTBYTES),
141 | BLAKE2_DUMMY_2 = 1/(int)(sizeof(blake2b_param) == BLAKE2B_OUTBYTES)
142 | };
143 |
144 | /* Streaming API */
145 | int blake2s_init( blake2s_state *S, size_t outlen );
146 | int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen );
147 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
148 | int blake2s_update( blake2s_state *S, const void *in, size_t inlen );
149 | int blake2s_final( blake2s_state *S, void *out, size_t outlen );
150 |
151 | int blake2b_init( blake2b_state *S, size_t outlen );
152 | int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen );
153 | int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
154 | int blake2b_update( blake2b_state *S, const void *in, size_t inlen );
155 | int blake2b_final( blake2b_state *S, void *out, size_t outlen );
156 |
157 | int blake2sp_init( blake2sp_state *S, size_t outlen );
158 | int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen );
159 | int blake2sp_update( blake2sp_state *S, const void *in, size_t inlen );
160 | int blake2sp_final( blake2sp_state *S, void *out, size_t outlen );
161 |
162 | int blake2bp_init( blake2bp_state *S, size_t outlen );
163 | int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen );
164 | int blake2bp_update( blake2bp_state *S, const void *in, size_t inlen );
165 | int blake2bp_final( blake2bp_state *S, void *out, size_t outlen );
166 |
167 | /* Variable output length API */
168 | int blake2xs_init( blake2xs_state *S, const size_t outlen );
169 | int blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen );
170 | int blake2xs_update( blake2xs_state *S, const void *in, size_t inlen );
171 | int blake2xs_final(blake2xs_state *S, void *out, size_t outlen);
172 |
173 | int blake2xb_init( blake2xb_state *S, const size_t outlen );
174 | int blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, size_t keylen );
175 | int blake2xb_update( blake2xb_state *S, const void *in, size_t inlen );
176 | int blake2xb_final(blake2xb_state *S, void *out, size_t outlen);
177 |
178 | /* Simple API */
179 | int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
180 | int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
181 |
182 | int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
183 | int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
184 |
185 | int blake2xs( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
186 | int blake2xb( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
187 |
188 | /* This is simply an alias for blake2b */
189 | int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
190 |
191 | #if defined(__cplusplus)
192 | }
193 | #endif
194 |
195 | #endif
196 |
--------------------------------------------------------------------------------
/blake2b-ref.c:
--------------------------------------------------------------------------------
1 | /*
2 | BLAKE2 reference source code package - reference C implementations
3 |
4 | Copyright 2012, Samuel Neves . You may use this under the
5 | terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
6 | your option. The terms of these licenses can be found at:
7 |
8 | - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
9 | - OpenSSL license : https://www.openssl.org/source/license.html
10 | - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | More information about the BLAKE2 hash function can be found at
13 | https://blake2.net.
14 | */
15 |
16 | #include
17 | #include
18 | #include
19 |
20 | #include "blake2.h"
21 | #include "blake2-impl.h"
22 |
23 | static const uint64_t blake2b_IV[8] =
24 | {
25 | 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
26 | 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
27 | 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
28 | 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
29 | };
30 |
31 | static const uint8_t blake2b_sigma[12][16] =
32 | {
33 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
34 | { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
35 | { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
36 | { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
37 | { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
38 | { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
39 | { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
40 | { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
41 | { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
42 | { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
43 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
44 | { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
45 | };
46 |
47 |
48 | static void blake2b_set_lastnode( blake2b_state *S )
49 | {
50 | S->f[1] = (uint64_t)-1;
51 | }
52 |
53 | /* Some helper functions, not necessarily useful */
54 | static int blake2b_is_lastblock( const blake2b_state *S )
55 | {
56 | return S->f[0] != 0;
57 | }
58 |
59 | static void blake2b_set_lastblock( blake2b_state *S )
60 | {
61 | if( S->last_node ) blake2b_set_lastnode( S );
62 |
63 | S->f[0] = (uint64_t)-1;
64 | }
65 |
66 | static void blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
67 | {
68 | S->t[0] += inc;
69 | S->t[1] += ( S->t[0] < inc );
70 | }
71 |
72 | static void blake2b_init0( blake2b_state *S )
73 | {
74 | size_t i;
75 | memset( S, 0, sizeof( blake2b_state ) );
76 |
77 | for( i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
78 | }
79 |
80 | /* init xors IV with input parameter block */
81 | int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
82 | {
83 | const uint8_t *p = ( const uint8_t * )( P );
84 | size_t i;
85 |
86 | blake2b_init0( S );
87 |
88 | /* IV XOR ParamBlock */
89 | for( i = 0; i < 8; ++i )
90 | S->h[i] ^= load64( p + sizeof( S->h[i] ) * i );
91 |
92 | S->outlen = P->digest_length;
93 | return 0;
94 | }
95 |
96 |
97 |
98 | int blake2b_init( blake2b_state *S, size_t outlen )
99 | {
100 | blake2b_param P[1];
101 |
102 | if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
103 |
104 | P->digest_length = (uint8_t)outlen;
105 | P->key_length = 0;
106 | P->fanout = 1;
107 | P->depth = 1;
108 | store32( &P->leaf_length, 0 );
109 | store32( &P->node_offset, 0 );
110 | store32( &P->xof_length, 0 );
111 | P->node_depth = 0;
112 | P->inner_length = 0;
113 | memset( P->reserved, 0, sizeof( P->reserved ) );
114 | memset( P->salt, 0, sizeof( P->salt ) );
115 | memset( P->personal, 0, sizeof( P->personal ) );
116 | return blake2b_init_param( S, P );
117 | }
118 |
119 |
120 | int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen )
121 | {
122 | blake2b_param P[1];
123 |
124 | if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
125 |
126 | if ( !key || !keylen || keylen > BLAKE2B_KEYBYTES ) return -1;
127 |
128 | P->digest_length = (uint8_t)outlen;
129 | P->key_length = (uint8_t)keylen;
130 | P->fanout = 1;
131 | P->depth = 1;
132 | store32( &P->leaf_length, 0 );
133 | store32( &P->node_offset, 0 );
134 | store32( &P->xof_length, 0 );
135 | P->node_depth = 0;
136 | P->inner_length = 0;
137 | memset( P->reserved, 0, sizeof( P->reserved ) );
138 | memset( P->salt, 0, sizeof( P->salt ) );
139 | memset( P->personal, 0, sizeof( P->personal ) );
140 |
141 | if( blake2b_init_param( S, P ) < 0 ) return -1;
142 |
143 | {
144 | uint8_t block[BLAKE2B_BLOCKBYTES];
145 | memset( block, 0, BLAKE2B_BLOCKBYTES );
146 | memcpy( block, key, keylen );
147 | blake2b_update( S, block, BLAKE2B_BLOCKBYTES );
148 | secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */
149 | }
150 | return 0;
151 | }
152 |
153 | #define G(r,i,a,b,c,d) \
154 | do { \
155 | a = a + b + m[blake2b_sigma[r][2*i+0]]; \
156 | d = rotr64(d ^ a, 32); \
157 | c = c + d; \
158 | b = rotr64(b ^ c, 24); \
159 | a = a + b + m[blake2b_sigma[r][2*i+1]]; \
160 | d = rotr64(d ^ a, 16); \
161 | c = c + d; \
162 | b = rotr64(b ^ c, 63); \
163 | } while(0)
164 |
165 | #define ROUND(r) \
166 | do { \
167 | G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
168 | G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
169 | G(r,2,v[ 2],v[ 6],v[10],v[14]); \
170 | G(r,3,v[ 3],v[ 7],v[11],v[15]); \
171 | G(r,4,v[ 0],v[ 5],v[10],v[15]); \
172 | G(r,5,v[ 1],v[ 6],v[11],v[12]); \
173 | G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
174 | G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
175 | } while(0)
176 |
177 | static void blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] )
178 | {
179 | uint64_t m[16];
180 | uint64_t v[16];
181 | size_t i;
182 |
183 | for( i = 0; i < 16; ++i ) {
184 | m[i] = load64( block + i * sizeof( m[i] ) );
185 | }
186 |
187 | for( i = 0; i < 8; ++i ) {
188 | v[i] = S->h[i];
189 | }
190 |
191 | v[ 8] = blake2b_IV[0];
192 | v[ 9] = blake2b_IV[1];
193 | v[10] = blake2b_IV[2];
194 | v[11] = blake2b_IV[3];
195 | v[12] = blake2b_IV[4] ^ S->t[0];
196 | v[13] = blake2b_IV[5] ^ S->t[1];
197 | v[14] = blake2b_IV[6] ^ S->f[0];
198 | v[15] = blake2b_IV[7] ^ S->f[1];
199 |
200 | ROUND( 0 );
201 | ROUND( 1 );
202 | ROUND( 2 );
203 | ROUND( 3 );
204 | ROUND( 4 );
205 | ROUND( 5 );
206 | ROUND( 6 );
207 | ROUND( 7 );
208 | ROUND( 8 );
209 | ROUND( 9 );
210 | ROUND( 10 );
211 | ROUND( 11 );
212 |
213 | for( i = 0; i < 8; ++i ) {
214 | S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
215 | }
216 | }
217 |
218 | #undef G
219 | #undef ROUND
220 |
221 | int blake2b_update( blake2b_state *S, const void *pin, size_t inlen )
222 | {
223 | const unsigned char * in = (const unsigned char *)pin;
224 | if( inlen > 0 )
225 | {
226 | size_t left = S->buflen;
227 | size_t fill = BLAKE2B_BLOCKBYTES - left;
228 | if( inlen > fill )
229 | {
230 | S->buflen = 0;
231 | memcpy( S->buf + left, in, fill ); /* Fill buffer */
232 | blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
233 | blake2b_compress( S, S->buf ); /* Compress */
234 | in += fill; inlen -= fill;
235 | while(inlen > BLAKE2B_BLOCKBYTES) {
236 | blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES);
237 | blake2b_compress( S, in );
238 | in += BLAKE2B_BLOCKBYTES;
239 | inlen -= BLAKE2B_BLOCKBYTES;
240 | }
241 | }
242 | memcpy( S->buf + S->buflen, in, inlen );
243 | S->buflen += inlen;
244 | }
245 | return 0;
246 | }
247 |
248 | int blake2b_final( blake2b_state *S, void *out, size_t outlen )
249 | {
250 | uint8_t buffer[BLAKE2B_OUTBYTES] = {0};
251 | size_t i;
252 |
253 | if( out == NULL || outlen < S->outlen )
254 | return -1;
255 |
256 | if( blake2b_is_lastblock( S ) )
257 | return -1;
258 |
259 | blake2b_increment_counter( S, S->buflen );
260 | blake2b_set_lastblock( S );
261 | memset( S->buf + S->buflen, 0, BLAKE2B_BLOCKBYTES - S->buflen ); /* Padding */
262 | blake2b_compress( S, S->buf );
263 |
264 | for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */
265 | store64( buffer + sizeof( S->h[i] ) * i, S->h[i] );
266 |
267 | memcpy( out, buffer, S->outlen );
268 | secure_zero_memory(buffer, sizeof(buffer));
269 | return 0;
270 | }
271 |
272 | /* inlen, at least, should be uint64_t. Others can be size_t. */
273 | int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen )
274 | {
275 | blake2b_state S[1];
276 |
277 | /* Verify parameters */
278 | if ( NULL == in && inlen > 0 ) return -1;
279 |
280 | if ( NULL == out ) return -1;
281 |
282 | if( NULL == key && keylen > 0 ) return -1;
283 |
284 | if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1;
285 |
286 | if( keylen > BLAKE2B_KEYBYTES ) return -1;
287 |
288 | if( keylen > 0 )
289 | {
290 | if( blake2b_init_key( S, outlen, key, keylen ) < 0 ) return -1;
291 | }
292 | else
293 | {
294 | if( blake2b_init( S, outlen ) < 0 ) return -1;
295 | }
296 |
297 | blake2b_update( S, ( const uint8_t * )in, inlen );
298 | blake2b_final( S, out, outlen );
299 | return 0;
300 | }
301 |
302 | int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) {
303 | return blake2b(out, outlen, in, inlen, key, keylen);
304 | }
305 |
306 | #if defined(SUPERCOP)
307 | int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen )
308 | {
309 | return blake2b( out, BLAKE2B_OUTBYTES, in, inlen, NULL, 0 );
310 | }
311 | #endif
312 |
313 | #if defined(BLAKE2B_SELFTEST)
314 | #include
315 | #include "blake2-kat.h"
316 | int main( void )
317 | {
318 | uint8_t key[BLAKE2B_KEYBYTES];
319 | uint8_t buf[BLAKE2_KAT_LENGTH];
320 | size_t i, step;
321 |
322 | for( i = 0; i < BLAKE2B_KEYBYTES; ++i )
323 | key[i] = ( uint8_t )i;
324 |
325 | for( i = 0; i < BLAKE2_KAT_LENGTH; ++i )
326 | buf[i] = ( uint8_t )i;
327 |
328 | /* Test simple API */
329 | for( i = 0; i < BLAKE2_KAT_LENGTH; ++i )
330 | {
331 | uint8_t hash[BLAKE2B_OUTBYTES];
332 | blake2b( hash, BLAKE2B_OUTBYTES, buf, i, key, BLAKE2B_KEYBYTES );
333 |
334 | if( 0 != memcmp( hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES ) )
335 | {
336 | goto fail;
337 | }
338 | }
339 |
340 | /* Test streaming API */
341 | for(step = 1; step < BLAKE2B_BLOCKBYTES; ++step) {
342 | for (i = 0; i < BLAKE2_KAT_LENGTH; ++i) {
343 | uint8_t hash[BLAKE2B_OUTBYTES];
344 | blake2b_state S;
345 | uint8_t * p = buf;
346 | size_t mlen = i;
347 | int err = 0;
348 |
349 | if( (err = blake2b_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) {
350 | goto fail;
351 | }
352 |
353 | while (mlen >= step) {
354 | if ( (err = blake2b_update(&S, p, step)) < 0 ) {
355 | goto fail;
356 | }
357 | mlen -= step;
358 | p += step;
359 | }
360 | if ( (err = blake2b_update(&S, p, mlen)) < 0) {
361 | goto fail;
362 | }
363 | if ( (err = blake2b_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) {
364 | goto fail;
365 | }
366 |
367 | if (0 != memcmp(hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES)) {
368 | goto fail;
369 | }
370 | }
371 | }
372 |
373 | puts( "ok" );
374 | return 0;
375 | fail:
376 | puts("error");
377 | return -1;
378 | }
379 | #endif
380 |
--------------------------------------------------------------------------------
/librtmp/amf.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2005-2008 Team XBMC
3 | * http://www.xbmc.org
4 | * Copyright (C) 2008-2009 Andrej Stepanchuk
5 | * Copyright (C) 2009-2010 Howard Chu
6 | *
7 | * This file is part of librtmp.
8 | *
9 | * librtmp is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU Lesser General Public License as
11 | * published by the Free Software Foundation; either version 2.1,
12 | * or (at your option) any later version.
13 | *
14 | * librtmp is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with librtmp see the file COPYING. If not, write to
21 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 | * Boston, MA 02110-1301, USA.
23 | * http://www.gnu.org/copyleft/lgpl.html
24 | */
25 |
26 | #include "rtmp_sys.h"
27 | #include "amf.h"
28 | #include "log.h"
29 | #include "bytes.h"
30 |
31 | static const AMFObjectProperty AMFProp_Invalid = { {0, 0}, AMF_INVALID };
32 | static const AVal AV_empty = { 0, 0 };
33 |
34 | /* Data is Big-Endian */
35 | unsigned short
36 | AMF_DecodeInt16(const char *data)
37 | {
38 | unsigned char *c = (unsigned char *) data;
39 | unsigned short val;
40 | val = (c[0] << 8) | c[1];
41 | return val;
42 | }
43 |
44 | unsigned int
45 | AMF_DecodeInt24(const char *data)
46 | {
47 | unsigned char *c = (unsigned char *) data;
48 | unsigned int val;
49 | val = (c[0] << 16) | (c[1] << 8) | c[2];
50 | return val;
51 | }
52 |
53 | unsigned int
54 | AMF_DecodeInt32(const char *data)
55 | {
56 | unsigned char *c = (unsigned char *)data;
57 | unsigned int val;
58 | val = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3];
59 | return val;
60 | }
61 |
62 | void
63 | AMF_DecodeString(const char *data, AVal *bv)
64 | {
65 | bv->av_len = AMF_DecodeInt16(data);
66 | bv->av_val = (bv->av_len > 0) ? (char *)data + 2 : NULL;
67 | }
68 |
69 | void
70 | AMF_DecodeLongString(const char *data, AVal *bv)
71 | {
72 | bv->av_len = AMF_DecodeInt32(data);
73 | bv->av_val = (bv->av_len > 0) ? (char *)data + 4 : NULL;
74 | }
75 |
76 | double
77 | AMF_DecodeNumber(const char *data)
78 | {
79 | double dVal;
80 | #if __FLOAT_WORD_ORDER == __BYTE_ORDER
81 | #if __BYTE_ORDER == __BIG_ENDIAN
82 | memcpy(&dVal, data, 8);
83 | #elif __BYTE_ORDER == __LITTLE_ENDIAN
84 | unsigned char *ci, *co;
85 | ci = (unsigned char *)data;
86 | co = (unsigned char *)&dVal;
87 | co[0] = ci[7];
88 | co[1] = ci[6];
89 | co[2] = ci[5];
90 | co[3] = ci[4];
91 | co[4] = ci[3];
92 | co[5] = ci[2];
93 | co[6] = ci[1];
94 | co[7] = ci[0];
95 | #endif
96 | #else
97 | #if __BYTE_ORDER == __LITTLE_ENDIAN /* __FLOAT_WORD_ORER == __BIG_ENDIAN */
98 | unsigned char *ci, *co;
99 | ci = (unsigned char *)data;
100 | co = (unsigned char *)&dVal;
101 | co[0] = ci[3];
102 | co[1] = ci[2];
103 | co[2] = ci[1];
104 | co[3] = ci[0];
105 | co[4] = ci[7];
106 | co[5] = ci[6];
107 | co[6] = ci[5];
108 | co[7] = ci[4];
109 | #else /* __BYTE_ORDER == __BIG_ENDIAN && __FLOAT_WORD_ORER == __LITTLE_ENDIAN */
110 | unsigned char *ci, *co;
111 | ci = (unsigned char *)data;
112 | co = (unsigned char *)&dVal;
113 | co[0] = ci[4];
114 | co[1] = ci[5];
115 | co[2] = ci[6];
116 | co[3] = ci[7];
117 | co[4] = ci[0];
118 | co[5] = ci[1];
119 | co[6] = ci[2];
120 | co[7] = ci[3];
121 | #endif
122 | #endif
123 | return dVal;
124 | }
125 |
126 | int
127 | AMF_DecodeBoolean(const char *data)
128 | {
129 | return *data != 0;
130 | }
131 |
132 | char *
133 | AMF_EncodeInt16(char *output, char *outend, short nVal)
134 | {
135 | if (output+2 > outend)
136 | return NULL;
137 |
138 | output[1] = nVal & 0xff;
139 | output[0] = nVal >> 8;
140 | return output+2;
141 | }
142 |
143 | char *
144 | AMF_EncodeInt24(char *output, char *outend, int nVal)
145 | {
146 | if (output+3 > outend)
147 | return NULL;
148 |
149 | output[2] = nVal & 0xff;
150 | output[1] = nVal >> 8;
151 | output[0] = nVal >> 16;
152 | return output+3;
153 | }
154 |
155 | char *
156 | AMF_EncodeInt32(char *output, char *outend, int nVal)
157 | {
158 | if (output+4 > outend)
159 | return NULL;
160 |
161 | output[3] = nVal & 0xff;
162 | output[2] = nVal >> 8;
163 | output[1] = nVal >> 16;
164 | output[0] = nVal >> 24;
165 | return output+4;
166 | }
167 |
168 | char *
169 | AMF_EncodeString(char *output, char *outend, const AVal *bv)
170 | {
171 | if ((bv->av_len < 65536 && output + 1 + 2 + bv->av_len > outend) ||
172 | output + 1 + 4 + bv->av_len > outend)
173 | return NULL;
174 |
175 | if (bv->av_len < 65536)
176 | {
177 | *output++ = AMF_STRING;
178 |
179 | output = AMF_EncodeInt16(output, outend, bv->av_len);
180 | }
181 | else
182 | {
183 | *output++ = AMF_LONG_STRING;
184 |
185 | output = AMF_EncodeInt32(output, outend, bv->av_len);
186 | }
187 | memcpy(output, bv->av_val, bv->av_len);
188 | output += bv->av_len;
189 |
190 | return output;
191 | }
192 |
193 | char *
194 | AMF_EncodeNumber(char *output, char *outend, double dVal)
195 | {
196 | if (output+1+8 > outend)
197 | return NULL;
198 |
199 | *output++ = AMF_NUMBER; /* type: Number */
200 |
201 | #if __FLOAT_WORD_ORDER == __BYTE_ORDER
202 | #if __BYTE_ORDER == __BIG_ENDIAN
203 | memcpy(output, &dVal, 8);
204 | #elif __BYTE_ORDER == __LITTLE_ENDIAN
205 | {
206 | unsigned char *ci, *co;
207 | ci = (unsigned char *)&dVal;
208 | co = (unsigned char *)output;
209 | co[0] = ci[7];
210 | co[1] = ci[6];
211 | co[2] = ci[5];
212 | co[3] = ci[4];
213 | co[4] = ci[3];
214 | co[5] = ci[2];
215 | co[6] = ci[1];
216 | co[7] = ci[0];
217 | }
218 | #endif
219 | #else
220 | #if __BYTE_ORDER == __LITTLE_ENDIAN /* __FLOAT_WORD_ORER == __BIG_ENDIAN */
221 | {
222 | unsigned char *ci, *co;
223 | ci = (unsigned char *)&dVal;
224 | co = (unsigned char *)output;
225 | co[0] = ci[3];
226 | co[1] = ci[2];
227 | co[2] = ci[1];
228 | co[3] = ci[0];
229 | co[4] = ci[7];
230 | co[5] = ci[6];
231 | co[6] = ci[5];
232 | co[7] = ci[4];
233 | }
234 | #else /* __BYTE_ORDER == __BIG_ENDIAN && __FLOAT_WORD_ORER == __LITTLE_ENDIAN */
235 | {
236 | unsigned char *ci, *co;
237 | ci = (unsigned char *)&dVal;
238 | co = (unsigned char *)output;
239 | co[0] = ci[4];
240 | co[1] = ci[5];
241 | co[2] = ci[6];
242 | co[3] = ci[7];
243 | co[4] = ci[0];
244 | co[5] = ci[1];
245 | co[6] = ci[2];
246 | co[7] = ci[3];
247 | }
248 | #endif
249 | #endif
250 |
251 | return output+8;
252 | }
253 |
254 | char *
255 | AMF_EncodeBoolean(char *output, char *outend, int bVal)
256 | {
257 | if (output+2 > outend)
258 | return NULL;
259 |
260 | *output++ = AMF_BOOLEAN;
261 |
262 | *output++ = bVal ? 0x01 : 0x00;
263 |
264 | return output;
265 | }
266 |
267 | char *
268 | AMF_EncodeNamedString(char *output, char *outend, const AVal *strName, const AVal *strValue)
269 | {
270 | if (output+2+strName->av_len > outend)
271 | return NULL;
272 | output = AMF_EncodeInt16(output, outend, strName->av_len);
273 |
274 | memcpy(output, strName->av_val, strName->av_len);
275 | output += strName->av_len;
276 |
277 | return AMF_EncodeString(output, outend, strValue);
278 | }
279 |
280 | char *
281 | AMF_EncodeNamedNumber(char *output, char *outend, const AVal *strName, double dVal)
282 | {
283 | if (output+2+strName->av_len > outend)
284 | return NULL;
285 | output = AMF_EncodeInt16(output, outend, strName->av_len);
286 |
287 | memcpy(output, strName->av_val, strName->av_len);
288 | output += strName->av_len;
289 |
290 | return AMF_EncodeNumber(output, outend, dVal);
291 | }
292 |
293 | char *
294 | AMF_EncodeNamedBoolean(char *output, char *outend, const AVal *strName, int bVal)
295 | {
296 | if (output+2+strName->av_len > outend)
297 | return NULL;
298 | output = AMF_EncodeInt16(output, outend, strName->av_len);
299 |
300 | memcpy(output, strName->av_val, strName->av_len);
301 | output += strName->av_len;
302 |
303 | return AMF_EncodeBoolean(output, outend, bVal);
304 | }
305 |
306 | void
307 | AMFProp_GetName(AMFObjectProperty *prop, AVal *name)
308 | {
309 | *name = prop->p_name;
310 | }
311 |
312 | void
313 | AMFProp_SetName(AMFObjectProperty *prop, AVal *name)
314 | {
315 | prop->p_name = *name;
316 | }
317 |
318 | AMFDataType
319 | AMFProp_GetType(AMFObjectProperty *prop)
320 | {
321 | return prop->p_type;
322 | }
323 |
324 | double
325 | AMFProp_GetNumber(AMFObjectProperty *prop)
326 | {
327 | return prop->p_vu.p_number;
328 | }
329 |
330 | int
331 | AMFProp_GetBoolean(AMFObjectProperty *prop)
332 | {
333 | return prop->p_vu.p_number != 0;
334 | }
335 |
336 | void
337 | AMFProp_GetString(AMFObjectProperty *prop, AVal *str)
338 | {
339 | *str = prop->p_vu.p_aval;
340 | }
341 |
342 | void
343 | AMFProp_GetObject(AMFObjectProperty *prop, AMFObject *obj)
344 | {
345 | *obj = prop->p_vu.p_object;
346 | }
347 |
348 | int
349 | AMFProp_IsValid(AMFObjectProperty *prop)
350 | {
351 | return prop->p_type != AMF_INVALID;
352 | }
353 |
354 | char *
355 | AMFProp_Encode(AMFObjectProperty *prop, char *pBuffer, char *pBufEnd)
356 | {
357 | if (prop->p_type == AMF_INVALID)
358 | return NULL;
359 |
360 | if (prop->p_type != AMF_NULL && pBuffer + prop->p_name.av_len + 2 + 1 >= pBufEnd)
361 | return NULL;
362 |
363 | if (prop->p_type != AMF_NULL && prop->p_name.av_len)
364 | {
365 | *pBuffer++ = prop->p_name.av_len >> 8;
366 | *pBuffer++ = prop->p_name.av_len & 0xff;
367 | memcpy(pBuffer, prop->p_name.av_val, prop->p_name.av_len);
368 | pBuffer += prop->p_name.av_len;
369 | }
370 |
371 | switch (prop->p_type)
372 | {
373 | case AMF_NUMBER:
374 | pBuffer = AMF_EncodeNumber(pBuffer, pBufEnd, prop->p_vu.p_number);
375 | break;
376 |
377 | case AMF_BOOLEAN:
378 | pBuffer = AMF_EncodeBoolean(pBuffer, pBufEnd, prop->p_vu.p_number != 0);
379 | break;
380 |
381 | case AMF_STRING:
382 | pBuffer = AMF_EncodeString(pBuffer, pBufEnd, &prop->p_vu.p_aval);
383 | break;
384 |
385 | case AMF_NULL:
386 | if (pBuffer+1 >= pBufEnd)
387 | return NULL;
388 | *pBuffer++ = AMF_NULL;
389 | break;
390 |
391 | case AMF_OBJECT:
392 | pBuffer = AMF_Encode(&prop->p_vu.p_object, pBuffer, pBufEnd);
393 | break;
394 |
395 | case AMF_ECMA_ARRAY:
396 | pBuffer = AMF_EncodeEcmaArray(&prop->p_vu.p_object, pBuffer, pBufEnd);
397 | break;
398 |
399 | case AMF_STRICT_ARRAY:
400 | pBuffer = AMF_EncodeArray(&prop->p_vu.p_object, pBuffer, pBufEnd);
401 | break;
402 |
403 | default:
404 | RTMP_Log(RTMP_LOGERROR, "%s, invalid type. %d", __FUNCTION__, prop->p_type);
405 | pBuffer = NULL;
406 | };
407 |
408 | return pBuffer;
409 | }
410 |
411 | #define AMF3_INTEGER_MAX 268435455
412 | #define AMF3_INTEGER_MIN -268435456
413 |
414 | int
415 | AMF3ReadInteger(const char *data, int32_t *valp)
416 | {
417 | int i = 0;
418 | int32_t val = 0;
419 |
420 | while (i <= 2)
421 | {
422 | /* handle first 3 bytes */
423 | if (data[i] & 0x80)
424 | {
425 | /* byte used */
426 | val <<= 7; /* shift up */
427 | val |= (data[i] & 0x7f); /* add bits */
428 | i++;
429 | }
430 | else
431 | {
432 | break;
433 | }
434 | }
435 |
436 | if (i > 2)
437 | {
438 | /* use 4th byte, all 8bits */
439 | val <<= 8;
440 | val |= data[3];
441 |
442 | /* range check */
443 | if (val > AMF3_INTEGER_MAX)
444 | val -= (1 << 29);
445 | }
446 | else
447 | {
448 | /* use 7bits of last unparsed byte (0xxxxxxx) */
449 | val <<= 7;
450 | val |= data[i];
451 | }
452 |
453 | *valp = val;
454 |
455 | return i > 2 ? 4 : i + 1;
456 | }
457 |
458 | int
459 | AMF3ReadString(const char *data, AVal *str)
460 | {
461 | int32_t ref = 0;
462 | int len;
463 | assert(str != 0);
464 |
465 | len = AMF3ReadInteger(data, &ref);
466 | data += len;
467 |
468 | if ((ref & 0x1) == 0)
469 | {
470 | /* reference: 0xxx */
471 | uint32_t refIndex = (ref >> 1);
472 | RTMP_Log(RTMP_LOGDEBUG,
473 | "%s, string reference, index: %d, not supported, ignoring!",
474 | __FUNCTION__, refIndex);
475 | return len;
476 | }
477 | else
478 | {
479 | uint32_t nSize = (ref >> 1);
480 |
481 | str->av_val = (char *)data;
482 | str->av_len = nSize;
483 |
484 | return len + nSize;
485 | }
486 | return len;
487 | }
488 |
489 | int
490 | AMF3Prop_Decode(AMFObjectProperty *prop, const char *pBuffer, int nSize,
491 | int bDecodeName)
492 | {
493 | int nOriginalSize = nSize;
494 | AMF3DataType type;
495 |
496 | prop->p_name.av_len = 0;
497 | prop->p_name.av_val = NULL;
498 |
499 | if (nSize == 0 || !pBuffer)
500 | {
501 | RTMP_Log(RTMP_LOGDEBUG, "empty buffer/no buffer pointer!");
502 | return -1;
503 | }
504 |
505 | /* decode name */
506 | if (bDecodeName)
507 | {
508 | AVal name = AV_empty;
509 | int nRes = AMF3ReadString(pBuffer, &name);
510 |
511 | if (name.av_len <= 0)
512 | return nRes;
513 |
514 | prop->p_name = name;
515 | pBuffer += nRes;
516 | nSize -= nRes;
517 | }
518 |
519 | /* decode */
520 | type = *pBuffer++;
521 | nSize--;
522 |
523 | switch (type)
524 | {
525 | case AMF3_UNDEFINED:
526 | case AMF3_NULL:
527 | prop->p_type = AMF_NULL;
528 | break;
529 | case AMF3_FALSE:
530 | prop->p_type = AMF_BOOLEAN;
531 | prop->p_vu.p_number = 0.0;
532 | break;
533 | case AMF3_TRUE:
534 | prop->p_type = AMF_BOOLEAN;
535 | prop->p_vu.p_number = 1.0;
536 | break;
537 | case AMF3_INTEGER:
538 | {
539 | int32_t res = 0;
540 | int len = AMF3ReadInteger(pBuffer, &res);
541 | prop->p_vu.p_number = (double)res;
542 | prop->p_type = AMF_NUMBER;
543 | nSize -= len;
544 | break;
545 | }
546 | case AMF3_DOUBLE:
547 | if (nSize < 8)
548 | return -1;
549 | prop->p_vu.p_number = AMF_DecodeNumber(pBuffer);
550 | prop->p_type = AMF_NUMBER;
551 | nSize -= 8;
552 | break;
553 | case AMF3_STRING:
554 | case AMF3_XML_DOC:
555 | case AMF3_XML:
556 | {
557 | int len = AMF3ReadString(pBuffer, &prop->p_vu.p_aval);
558 | prop->p_type = AMF_STRING;
559 | nSize -= len;
560 | break;
561 | }
562 | case AMF3_DATE:
563 | {
564 | int32_t res = 0;
565 | int len = AMF3ReadInteger(pBuffer, &res);
566 |
567 | nSize -= len;
568 | pBuffer += len;
569 |
570 | if ((res & 0x1) == 0)
571 | {
572 | /* reference */
573 | uint32_t nIndex = (res >> 1);
574 | RTMP_Log(RTMP_LOGDEBUG, "AMF3_DATE reference: %d, not supported!", nIndex);
575 | }
576 | else
577 | {
578 | if (nSize < 8)
579 | return -1;
580 |
581 | prop->p_vu.p_number = AMF_DecodeNumber(pBuffer);
582 | nSize -= 8;
583 | prop->p_type = AMF_NUMBER;
584 | }
585 | break;
586 | }
587 | case AMF3_OBJECT:
588 | {
589 | int nRes = AMF3_Decode(&prop->p_vu.p_object, pBuffer, nSize, TRUE);
590 | if (nRes == -1)
591 | return -1;
592 | nSize -= nRes;
593 | prop->p_type = AMF_OBJECT;
594 | break;
595 | }
596 | case AMF3_ARRAY:
597 | case AMF3_BYTE_ARRAY:
598 | default:
599 | RTMP_Log(RTMP_LOGDEBUG, "%s - AMF3 unknown/unsupported datatype 0x%02x, @%p",
600 | __FUNCTION__, (unsigned char)(*pBuffer), pBuffer);
601 | return -1;
602 | }
603 |
604 | return nOriginalSize - nSize;
605 | }
606 |
607 | int
608 | AMFProp_Decode(AMFObjectProperty *prop, const char *pBuffer, int nSize,
609 | int bDecodeName)
610 | {
611 | int nOriginalSize = nSize;
612 | int nRes;
613 |
614 | prop->p_name.av_len = 0;
615 | prop->p_name.av_val = NULL;
616 |
617 | if (nSize == 0 || !pBuffer)
618 | {
619 | RTMP_Log(RTMP_LOGDEBUG, "%s: Empty buffer/no buffer pointer!", __FUNCTION__);
620 | return -1;
621 | }
622 |
623 | if (bDecodeName && nSize < 4)
624 | {
625 | /* at least name (length + at least 1 byte) and 1 byte of data */
626 | RTMP_Log(RTMP_LOGDEBUG,
627 | "%s: Not enough data for decoding with name, less than 4 bytes!",
628 | __FUNCTION__);
629 | return -1;
630 | }
631 |
632 | if (bDecodeName)
633 | {
634 | unsigned short nNameSize = AMF_DecodeInt16(pBuffer);
635 | if (nNameSize > nSize - 2)
636 | {
637 | RTMP_Log(RTMP_LOGDEBUG,
638 | "%s: Name size out of range: namesize (%d) > len (%d) - 2",
639 | __FUNCTION__, nNameSize, nSize);
640 | return -1;
641 | }
642 |
643 | AMF_DecodeString(pBuffer, &prop->p_name);
644 | nSize -= 2 + nNameSize;
645 | pBuffer += 2 + nNameSize;
646 | }
647 |
648 | if (nSize == 0)
649 | {
650 | return -1;
651 | }
652 |
653 | nSize--;
654 |
655 | prop->p_type = *pBuffer++;
656 | switch (prop->p_type)
657 | {
658 | case AMF_NUMBER:
659 | if (nSize < 8)
660 | return -1;
661 | prop->p_vu.p_number = AMF_DecodeNumber(pBuffer);
662 | nSize -= 8;
663 | break;
664 | case AMF_BOOLEAN:
665 | if (nSize < 1)
666 | return -1;
667 | prop->p_vu.p_number = (double)AMF_DecodeBoolean(pBuffer);
668 | nSize--;
669 | break;
670 | case AMF_STRING:
671 | {
672 | unsigned short nStringSize = AMF_DecodeInt16(pBuffer);
673 |
674 | if (nSize < (long)nStringSize + 2)
675 | return -1;
676 | AMF_DecodeString(pBuffer, &prop->p_vu.p_aval);
677 | nSize -= (2 + nStringSize);
678 | break;
679 | }
680 | case AMF_OBJECT:
681 | {
682 | int nRes = AMF_Decode(&prop->p_vu.p_object, pBuffer, nSize, TRUE);
683 | if (nRes == -1)
684 | return -1;
685 | nSize -= nRes;
686 | break;
687 | }
688 | case AMF_MOVIECLIP:
689 | {
690 | RTMP_Log(RTMP_LOGERROR, "AMF_MOVIECLIP reserved!");
691 | return -1;
692 | break;
693 | }
694 | case AMF_NULL:
695 | case AMF_UNDEFINED:
696 | case AMF_UNSUPPORTED:
697 | prop->p_type = AMF_NULL;
698 | break;
699 | case AMF_REFERENCE:
700 | {
701 | RTMP_Log(RTMP_LOGERROR, "AMF_REFERENCE not supported!");
702 | return -1;
703 | break;
704 | }
705 | case AMF_ECMA_ARRAY:
706 | {
707 | nSize -= 4;
708 |
709 | /* next comes the rest, mixed array has a final 0x000009 mark and names, so its an object */
710 | nRes = AMF_Decode(&prop->p_vu.p_object, pBuffer + 4, nSize, TRUE);
711 | if (nRes == -1)
712 | return -1;
713 | nSize -= nRes;
714 | break;
715 | }
716 | case AMF_OBJECT_END:
717 | {
718 | return -1;
719 | break;
720 | }
721 | case AMF_STRICT_ARRAY:
722 | {
723 | unsigned int nArrayLen = AMF_DecodeInt32(pBuffer);
724 | nSize -= 4;
725 |
726 | nRes = AMF_DecodeArray(&prop->p_vu.p_object, pBuffer + 4, nSize,
727 | nArrayLen, FALSE);
728 | if (nRes == -1)
729 | return -1;
730 | nSize -= nRes;
731 | break;
732 | }
733 | case AMF_DATE:
734 | {
735 | RTMP_Log(RTMP_LOGDEBUG, "AMF_DATE");
736 |
737 | if (nSize < 10)
738 | return -1;
739 |
740 | prop->p_vu.p_number = AMF_DecodeNumber(pBuffer);
741 | prop->p_UTCoffset = AMF_DecodeInt16(pBuffer + 8);
742 |
743 | nSize -= 10;
744 | break;
745 | }
746 | case AMF_LONG_STRING:
747 | case AMF_XML_DOC:
748 | {
749 | unsigned int nStringSize = AMF_DecodeInt32(pBuffer);
750 | if (nSize < (long)nStringSize + 4)
751 | return -1;
752 | AMF_DecodeLongString(pBuffer, &prop->p_vu.p_aval);
753 | nSize -= (4 + nStringSize);
754 | if (prop->p_type == AMF_LONG_STRING)
755 | prop->p_type = AMF_STRING;
756 | break;
757 | }
758 | case AMF_RECORDSET:
759 | {
760 | RTMP_Log(RTMP_LOGERROR, "AMF_RECORDSET reserved!");
761 | return -1;
762 | break;
763 | }
764 | case AMF_TYPED_OBJECT:
765 | {
766 | RTMP_Log(RTMP_LOGERROR, "AMF_TYPED_OBJECT not supported!");
767 | return -1;
768 | break;
769 | }
770 | case AMF_AVMPLUS:
771 | {
772 | int nRes = AMF3_Decode(&prop->p_vu.p_object, pBuffer, nSize, TRUE);
773 | if (nRes == -1)
774 | return -1;
775 | nSize -= nRes;
776 | prop->p_type = AMF_OBJECT;
777 | break;
778 | }
779 | default:
780 | RTMP_Log(RTMP_LOGDEBUG, "%s - unknown datatype 0x%02x, @%p", __FUNCTION__,
781 | prop->p_type, pBuffer - 1);
782 | return -1;
783 | }
784 |
785 | return nOriginalSize - nSize;
786 | }
787 |
788 | void
789 | AMFProp_Dump(AMFObjectProperty *prop)
790 | {
791 | char strRes[256];
792 | char str[256];
793 | AVal name;
794 |
795 | if (prop->p_type == AMF_INVALID)
796 | {
797 | RTMP_Log(RTMP_LOGDEBUG, "Property: INVALID");
798 | return;
799 | }
800 |
801 | if (prop->p_type == AMF_NULL)
802 | {
803 | RTMP_Log(RTMP_LOGDEBUG, "Property: NULL");
804 | return;
805 | }
806 |
807 | if (prop->p_name.av_len)
808 | {
809 | name = prop->p_name;
810 | }
811 | else
812 | {
813 | name.av_val = "no-name.";
814 | name.av_len = sizeof("no-name.") - 1;
815 | }
816 | if (name.av_len > 18)
817 | name.av_len = 18;
818 |
819 | snprintf(strRes, 255, "Name: %18.*s, ", name.av_len, name.av_val);
820 |
821 | if (prop->p_type == AMF_OBJECT)
822 | {
823 | RTMP_Log(RTMP_LOGDEBUG, "Property: <%sOBJECT>", strRes);
824 | AMF_Dump(&prop->p_vu.p_object);
825 | return;
826 | }
827 | else if (prop->p_type == AMF_ECMA_ARRAY)
828 | {
829 | RTMP_Log(RTMP_LOGDEBUG, "Property: <%sECMA_ARRAY>", strRes);
830 | AMF_Dump(&prop->p_vu.p_object);
831 | return;
832 | }
833 | else if (prop->p_type == AMF_STRICT_ARRAY)
834 | {
835 | RTMP_Log(RTMP_LOGDEBUG, "Property: <%sSTRICT_ARRAY>", strRes);
836 | AMF_Dump(&prop->p_vu.p_object);
837 | return;
838 | }
839 |
840 | switch (prop->p_type)
841 | {
842 | case AMF_NUMBER:
843 | snprintf(str, 255, "NUMBER:\t%.2f", prop->p_vu.p_number);
844 | break;
845 | case AMF_BOOLEAN:
846 | snprintf(str, 255, "BOOLEAN:\t%s",
847 | prop->p_vu.p_number != 0.0 ? "TRUE" : "FALSE");
848 | break;
849 | case AMF_STRING:
850 | snprintf(str, 255, "STRING:\t%.*s", prop->p_vu.p_aval.av_len,
851 | prop->p_vu.p_aval.av_val);
852 | break;
853 | case AMF_DATE:
854 | snprintf(str, 255, "DATE:\ttimestamp: %.2f, UTC offset: %d",
855 | prop->p_vu.p_number, prop->p_UTCoffset);
856 | break;
857 | default:
858 | snprintf(str, 255, "INVALID TYPE 0x%02x", (unsigned char)prop->p_type);
859 | }
860 |
861 | RTMP_Log(RTMP_LOGDEBUG, "Property: <%s%s>", strRes, str);
862 | }
863 |
864 | void
865 | AMFProp_Reset(AMFObjectProperty *prop)
866 | {
867 | if (prop->p_type == AMF_OBJECT || prop->p_type == AMF_ECMA_ARRAY || prop->p_type == AMF_STRICT_ARRAY)
868 | AMF_Reset(&prop->p_vu.p_object);
869 | else
870 | {
871 | prop->p_vu.p_aval.av_len = 0;
872 | prop->p_vu.p_aval.av_val = NULL;
873 | }
874 | prop->p_type = AMF_INVALID;
875 | }
876 |
877 | /* AMFObject */
878 |
879 | char *
880 | AMF_Encode(AMFObject *obj, char *pBuffer, char *pBufEnd)
881 | {
882 | int i;
883 |
884 | if (pBuffer+4 >= pBufEnd)
885 | return NULL;
886 |
887 | *pBuffer++ = AMF_OBJECT;
888 |
889 | for (i = 0; i < obj->o_num; i++)
890 | {
891 | char *res = AMFProp_Encode(&obj->o_props[i], pBuffer, pBufEnd);
892 | if (res == NULL)
893 | {
894 | RTMP_Log(RTMP_LOGERROR, "AMF_Encode - failed to encode property in index %d",
895 | i);
896 | break;
897 | }
898 | else
899 | {
900 | pBuffer = res;
901 | }
902 | }
903 |
904 | if (pBuffer + 3 >= pBufEnd)
905 | return NULL; /* no room for the end marker */
906 |
907 | pBuffer = AMF_EncodeInt24(pBuffer, pBufEnd, AMF_OBJECT_END);
908 |
909 | return pBuffer;
910 | }
911 |
912 | char *
913 | AMF_EncodeEcmaArray(AMFObject *obj, char *pBuffer, char *pBufEnd)
914 | {
915 | int i;
916 |
917 | if (pBuffer+4 >= pBufEnd)
918 | return NULL;
919 |
920 | *pBuffer++ = AMF_ECMA_ARRAY;
921 |
922 | pBuffer = AMF_EncodeInt32(pBuffer, pBufEnd, obj->o_num);
923 |
924 | for (i = 0; i < obj->o_num; i++)
925 | {
926 | char *res = AMFProp_Encode(&obj->o_props[i], pBuffer, pBufEnd);
927 | if (res == NULL)
928 | {
929 | RTMP_Log(RTMP_LOGERROR, "AMF_Encode - failed to encode property in index %d",
930 | i);
931 | break;
932 | }
933 | else
934 | {
935 | pBuffer = res;
936 | }
937 | }
938 |
939 | if (pBuffer + 3 >= pBufEnd)
940 | return NULL; /* no room for the end marker */
941 |
942 | pBuffer = AMF_EncodeInt24(pBuffer, pBufEnd, AMF_OBJECT_END);
943 |
944 | return pBuffer;
945 | }
946 |
947 | char *
948 | AMF_EncodeArray(AMFObject *obj, char *pBuffer, char *pBufEnd)
949 | {
950 | int i;
951 |
952 | if (pBuffer+4 >= pBufEnd)
953 | return NULL;
954 |
955 | *pBuffer++ = AMF_STRICT_ARRAY;
956 |
957 | pBuffer = AMF_EncodeInt32(pBuffer, pBufEnd, obj->o_num);
958 |
959 | for (i = 0; i < obj->o_num; i++)
960 | {
961 | char *res = AMFProp_Encode(&obj->o_props[i], pBuffer, pBufEnd);
962 | if (res == NULL)
963 | {
964 | RTMP_Log(RTMP_LOGERROR, "AMF_Encode - failed to encode property in index %d",
965 | i);
966 | break;
967 | }
968 | else
969 | {
970 | pBuffer = res;
971 | }
972 | }
973 |
974 | //if (pBuffer + 3 >= pBufEnd)
975 | // return NULL; /* no room for the end marker */
976 |
977 | //pBuffer = AMF_EncodeInt24(pBuffer, pBufEnd, AMF_OBJECT_END);
978 |
979 | return pBuffer;
980 | }
981 |
982 | int
983 | AMF_DecodeArray(AMFObject *obj, const char *pBuffer, int nSize,
984 | int nArrayLen, int bDecodeName)
985 | {
986 | int nOriginalSize = nSize;
987 | int bError = FALSE;
988 |
989 | obj->o_num = 0;
990 | obj->o_props = NULL;
991 | while (nArrayLen > 0)
992 | {
993 | AMFObjectProperty prop;
994 | int nRes;
995 | nArrayLen--;
996 |
997 | nRes = AMFProp_Decode(&prop, pBuffer, nSize, bDecodeName);
998 | if (nRes == -1)
999 | bError = TRUE;
1000 | else
1001 | {
1002 | nSize -= nRes;
1003 | pBuffer += nRes;
1004 | AMF_AddProp(obj, &prop);
1005 | }
1006 | }
1007 | if (bError)
1008 | return -1;
1009 |
1010 | return nOriginalSize - nSize;
1011 | }
1012 |
1013 | int
1014 | AMF3_Decode(AMFObject *obj, const char *pBuffer, int nSize, int bAMFData)
1015 | {
1016 | int nOriginalSize = nSize;
1017 | int32_t ref;
1018 | int len;
1019 |
1020 | obj->o_num = 0;
1021 | obj->o_props = NULL;
1022 | if (bAMFData)
1023 | {
1024 | if (*pBuffer != AMF3_OBJECT)
1025 | RTMP_Log(RTMP_LOGERROR,
1026 | "AMF3 Object encapsulated in AMF stream does not start with AMF3_OBJECT!");
1027 | pBuffer++;
1028 | nSize--;
1029 | }
1030 |
1031 | ref = 0;
1032 | len = AMF3ReadInteger(pBuffer, &ref);
1033 | pBuffer += len;
1034 | nSize -= len;
1035 |
1036 | if ((ref & 1) == 0)
1037 | {
1038 | /* object reference, 0xxx */
1039 | uint32_t objectIndex = (ref >> 1);
1040 |
1041 | RTMP_Log(RTMP_LOGDEBUG, "Object reference, index: %d", objectIndex);
1042 | }
1043 | else /* object instance */
1044 | {
1045 | int32_t classRef = (ref >> 1);
1046 |
1047 | AMF3ClassDef cd = { {0, 0}
1048 | };
1049 | AMFObjectProperty prop;
1050 |
1051 | if ((classRef & 0x1) == 0)
1052 | {
1053 | /* class reference */
1054 | uint32_t classIndex = (classRef >> 1);
1055 | RTMP_Log(RTMP_LOGDEBUG, "Class reference: %d", classIndex);
1056 | }
1057 | else
1058 | {
1059 | int32_t classExtRef = (classRef >> 1);
1060 | int i;
1061 |
1062 | cd.cd_externalizable = (classExtRef & 0x1) == 1;
1063 | cd.cd_dynamic = ((classExtRef >> 1) & 0x1) == 1;
1064 |
1065 | cd.cd_num = classExtRef >> 2;
1066 |
1067 | /* class name */
1068 |
1069 | len = AMF3ReadString(pBuffer, &cd.cd_name);
1070 | nSize -= len;
1071 | pBuffer += len;
1072 |
1073 | /*std::string str = className; */
1074 |
1075 | RTMP_Log(RTMP_LOGDEBUG,
1076 | "Class name: %s, externalizable: %d, dynamic: %d, classMembers: %d",
1077 | cd.cd_name.av_val, cd.cd_externalizable, cd.cd_dynamic,
1078 | cd.cd_num);
1079 |
1080 | for (i = 0; i < cd.cd_num; i++)
1081 | {
1082 | AVal memberName = AV_empty;
1083 | len = AMF3ReadString(pBuffer, &memberName);
1084 | RTMP_Log(RTMP_LOGDEBUG, "Member: %s", memberName.av_val);
1085 | AMF3CD_AddProp(&cd, &memberName);
1086 | nSize -= len;
1087 | pBuffer += len;
1088 | }
1089 | }
1090 |
1091 | /* add as referencable object */
1092 |
1093 | if (cd.cd_externalizable)
1094 | {
1095 | int nRes;
1096 | AVal name = AVC("DEFAULT_ATTRIBUTE");
1097 |
1098 | RTMP_Log(RTMP_LOGDEBUG, "Externalizable, TODO check");
1099 |
1100 | nRes = AMF3Prop_Decode(&prop, pBuffer, nSize, FALSE);
1101 | if (nRes == -1)
1102 | RTMP_Log(RTMP_LOGDEBUG, "%s, failed to decode AMF3 property!",
1103 | __FUNCTION__);
1104 | else
1105 | {
1106 | nSize -= nRes;
1107 | pBuffer += nRes;
1108 | }
1109 |
1110 | AMFProp_SetName(&prop, &name);
1111 | AMF_AddProp(obj, &prop);
1112 | }
1113 | else
1114 | {
1115 | int nRes, i;
1116 | for (i = 0; i < cd.cd_num; i++) /* non-dynamic */
1117 | {
1118 | nRes = AMF3Prop_Decode(&prop, pBuffer, nSize, FALSE);
1119 | if (nRes == -1)
1120 | RTMP_Log(RTMP_LOGDEBUG, "%s, failed to decode AMF3 property!",
1121 | __FUNCTION__);
1122 |
1123 | AMFProp_SetName(&prop, AMF3CD_GetProp(&cd, i));
1124 | AMF_AddProp(obj, &prop);
1125 |
1126 | pBuffer += nRes;
1127 | nSize -= nRes;
1128 | }
1129 | if (cd.cd_dynamic)
1130 | {
1131 | int len = 0;
1132 |
1133 | do
1134 | {
1135 | nRes = AMF3Prop_Decode(&prop, pBuffer, nSize, TRUE);
1136 | AMF_AddProp(obj, &prop);
1137 |
1138 | pBuffer += nRes;
1139 | nSize -= nRes;
1140 |
1141 | len = prop.p_name.av_len;
1142 | }
1143 | while (len > 0);
1144 | }
1145 | }
1146 | RTMP_Log(RTMP_LOGDEBUG, "class object!");
1147 | }
1148 | return nOriginalSize - nSize;
1149 | }
1150 |
1151 | int
1152 | AMF_Decode(AMFObject *obj, const char *pBuffer, int nSize, int bDecodeName)
1153 | {
1154 | int nOriginalSize = nSize;
1155 | int bError = FALSE; /* if there is an error while decoding - try to at least find the end mark AMF_OBJECT_END */
1156 |
1157 | obj->o_num = 0;
1158 | obj->o_props = NULL;
1159 | while (nSize > 0)
1160 | {
1161 | AMFObjectProperty prop;
1162 | int nRes;
1163 |
1164 | if (nSize >=3 && AMF_DecodeInt24(pBuffer) == AMF_OBJECT_END)
1165 | {
1166 | nSize -= 3;
1167 | bError = FALSE;
1168 | break;
1169 | }
1170 |
1171 | if (bError)
1172 | {
1173 | RTMP_Log(RTMP_LOGERROR,
1174 | "DECODING ERROR, IGNORING BYTES UNTIL NEXT KNOWN PATTERN!");
1175 | nSize--;
1176 | pBuffer++;
1177 | continue;
1178 | }
1179 |
1180 | nRes = AMFProp_Decode(&prop, pBuffer, nSize, bDecodeName);
1181 | if (nRes == -1)
1182 | bError = TRUE;
1183 | else
1184 | {
1185 | nSize -= nRes;
1186 | pBuffer += nRes;
1187 | AMF_AddProp(obj, &prop);
1188 | }
1189 | }
1190 |
1191 | if (bError)
1192 | return -1;
1193 |
1194 | return nOriginalSize - nSize;
1195 | }
1196 |
1197 | void
1198 | AMF_AddProp(AMFObject *obj, const AMFObjectProperty *prop)
1199 | {
1200 | if (!(obj->o_num & 0x0f))
1201 | obj->o_props =
1202 | realloc(obj->o_props, (obj->o_num + 16) * sizeof(AMFObjectProperty));
1203 | memcpy(&obj->o_props[obj->o_num++], prop, sizeof(AMFObjectProperty));
1204 | }
1205 |
1206 | int
1207 | AMF_CountProp(AMFObject *obj)
1208 | {
1209 | return obj->o_num;
1210 | }
1211 |
1212 | AMFObjectProperty *
1213 | AMF_GetProp(AMFObject *obj, const AVal *name, int nIndex)
1214 | {
1215 | if (nIndex >= 0)
1216 | {
1217 | if (nIndex < obj->o_num)
1218 | return &obj->o_props[nIndex];
1219 | }
1220 | else
1221 | {
1222 | int n;
1223 | for (n = 0; n < obj->o_num; n++)
1224 | {
1225 | if (AVMATCH(&obj->o_props[n].p_name, name))
1226 | return &obj->o_props[n];
1227 | }
1228 | }
1229 |
1230 | return (AMFObjectProperty *)&AMFProp_Invalid;
1231 | }
1232 |
1233 | void
1234 | AMF_Dump(AMFObject *obj)
1235 | {
1236 | int n;
1237 | RTMP_Log(RTMP_LOGDEBUG, "(object begin)");
1238 | for (n = 0; n < obj->o_num; n++)
1239 | {
1240 | AMFProp_Dump(&obj->o_props[n]);
1241 | }
1242 | RTMP_Log(RTMP_LOGDEBUG, "(object end)");
1243 | }
1244 |
1245 | void
1246 | AMF_Reset(AMFObject *obj)
1247 | {
1248 | int n;
1249 | for (n = 0; n < obj->o_num; n++)
1250 | {
1251 | AMFProp_Reset(&obj->o_props[n]);
1252 | }
1253 | free(obj->o_props);
1254 | obj->o_props = NULL;
1255 | obj->o_num = 0;
1256 | }
1257 |
1258 |
1259 | /* AMF3ClassDefinition */
1260 |
1261 | void
1262 | AMF3CD_AddProp(AMF3ClassDef *cd, AVal *prop)
1263 | {
1264 | if (!(cd->cd_num & 0x0f))
1265 | cd->cd_props = realloc(cd->cd_props, (cd->cd_num + 16) * sizeof(AVal));
1266 | cd->cd_props[cd->cd_num++] = *prop;
1267 | }
1268 |
1269 | AVal *
1270 | AMF3CD_GetProp(AMF3ClassDef *cd, int nIndex)
1271 | {
1272 | if (nIndex >= cd->cd_num)
1273 | return (AVal *)&AV_empty;
1274 | return &cd->cd_props[nIndex];
1275 | }
1276 |
--------------------------------------------------------------------------------
/librtmp/amf.h:
--------------------------------------------------------------------------------
1 | #ifndef __AMF_H__
2 | #define __AMF_H__
3 | /*
4 | * Copyright (C) 2005-2008 Team XBMC
5 | * http://www.xbmc.org
6 | * Copyright (C) 2008-2009 Andrej Stepanchuk
7 | * Copyright (C) 2009-2010 Howard Chu
8 | *
9 | * This file is part of librtmp.
10 | *
11 | * librtmp is free software; you can redistribute it and/or modify
12 | * it under the terms of the GNU Lesser General Public License as
13 | * published by the Free Software Foundation; either version 2.1,
14 | * or (at your option) any later version.
15 | *
16 | * librtmp is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU Lesser General Public License
22 | * along with librtmp see the file COPYING. If not, write to
23 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 | * Boston, MA 02110-1301, USA.
25 | * http://www.gnu.org/copyleft/lgpl.html
26 | */
27 |
28 | #ifndef TRUE
29 | #define TRUE 1
30 | #define FALSE 0
31 | #endif
32 |
33 | #ifdef __cplusplus
34 | extern "C"
35 | {
36 | #endif
37 |
38 | typedef enum
39 | {
40 | AMF_NUMBER = 0, AMF_BOOLEAN, AMF_STRING, AMF_OBJECT,
41 | AMF_MOVIECLIP, /* reserved, not used */
42 | AMF_NULL, AMF_UNDEFINED, AMF_REFERENCE, AMF_ECMA_ARRAY, AMF_OBJECT_END,
43 | AMF_STRICT_ARRAY, AMF_DATE, AMF_LONG_STRING, AMF_UNSUPPORTED,
44 | AMF_RECORDSET, /* reserved, not used */
45 | AMF_XML_DOC, AMF_TYPED_OBJECT,
46 | AMF_AVMPLUS, /* switch to AMF3 */
47 | AMF_INVALID = 0xff
48 | }
49 | AMFDataType;
50 |
51 | typedef enum
52 | {
53 | AMF3_UNDEFINED = 0, AMF3_NULL, AMF3_FALSE, AMF3_TRUE,
54 | AMF3_INTEGER, AMF3_DOUBLE, AMF3_STRING, AMF3_XML_DOC, AMF3_DATE,
55 | AMF3_ARRAY, AMF3_OBJECT, AMF3_XML, AMF3_BYTE_ARRAY
56 | } AMF3DataType;
57 |
58 | typedef struct AVal
59 | {
60 | char *av_val;
61 | int av_len;
62 | } AVal;
63 | #define AVC(str) {str,sizeof(str)-1}
64 | #define AVMATCH(a1,a2) ((a1)->av_len == (a2)->av_len && !memcmp((a1)->av_val,(a2)->av_val,(a1)->av_len))
65 |
66 | struct AMFObjectProperty;
67 |
68 | typedef struct AMFObject
69 | {
70 | int o_num;
71 | struct AMFObjectProperty *o_props;
72 | } AMFObject;
73 |
74 | typedef struct AMFObjectProperty
75 | {
76 | AVal p_name;
77 | AMFDataType p_type;
78 | union
79 | {
80 | double p_number;
81 | AVal p_aval;
82 | AMFObject p_object;
83 | } p_vu;
84 | int16_t p_UTCoffset;
85 | } AMFObjectProperty;
86 |
87 | char *AMF_EncodeString(char *output, char *outend, const AVal * str);
88 | char *AMF_EncodeNumber(char *output, char *outend, double dVal);
89 | char *AMF_EncodeInt16(char *output, char *outend, short nVal);
90 | char *AMF_EncodeInt24(char *output, char *outend, int nVal);
91 | char *AMF_EncodeInt32(char *output, char *outend, int nVal);
92 | char *AMF_EncodeBoolean(char *output, char *outend, int bVal);
93 |
94 | /* Shortcuts for AMFProp_Encode */
95 | char *AMF_EncodeNamedString(char *output, char *outend, const AVal * name, const AVal * value);
96 | char *AMF_EncodeNamedNumber(char *output, char *outend, const AVal * name, double dVal);
97 | char *AMF_EncodeNamedBoolean(char *output, char *outend, const AVal * name, int bVal);
98 |
99 | unsigned short AMF_DecodeInt16(const char *data);
100 | unsigned int AMF_DecodeInt24(const char *data);
101 | unsigned int AMF_DecodeInt32(const char *data);
102 | void AMF_DecodeString(const char *data, AVal * str);
103 | void AMF_DecodeLongString(const char *data, AVal * str);
104 | int AMF_DecodeBoolean(const char *data);
105 | double AMF_DecodeNumber(const char *data);
106 |
107 | char *AMF_Encode(AMFObject * obj, char *pBuffer, char *pBufEnd);
108 | char *AMF_EncodeEcmaArray(AMFObject *obj, char *pBuffer, char *pBufEnd);
109 | char *AMF_EncodeArray(AMFObject *obj, char *pBuffer, char *pBufEnd);
110 |
111 | int AMF_Decode(AMFObject * obj, const char *pBuffer, int nSize,
112 | int bDecodeName);
113 | int AMF_DecodeArray(AMFObject * obj, const char *pBuffer, int nSize,
114 | int nArrayLen, int bDecodeName);
115 | int AMF3_Decode(AMFObject * obj, const char *pBuffer, int nSize,
116 | int bDecodeName);
117 | void AMF_Dump(AMFObject * obj);
118 | void AMF_Reset(AMFObject * obj);
119 |
120 | void AMF_AddProp(AMFObject * obj, const AMFObjectProperty * prop);
121 | int AMF_CountProp(AMFObject * obj);
122 | AMFObjectProperty *AMF_GetProp(AMFObject * obj, const AVal * name,
123 | int nIndex);
124 |
125 | AMFDataType AMFProp_GetType(AMFObjectProperty * prop);
126 | void AMFProp_SetNumber(AMFObjectProperty * prop, double dval);
127 | void AMFProp_SetBoolean(AMFObjectProperty * prop, int bflag);
128 | void AMFProp_SetString(AMFObjectProperty * prop, AVal * str);
129 | void AMFProp_SetObject(AMFObjectProperty * prop, AMFObject * obj);
130 |
131 | void AMFProp_GetName(AMFObjectProperty * prop, AVal * name);
132 | void AMFProp_SetName(AMFObjectProperty * prop, AVal * name);
133 | double AMFProp_GetNumber(AMFObjectProperty * prop);
134 | int AMFProp_GetBoolean(AMFObjectProperty * prop);
135 | void AMFProp_GetString(AMFObjectProperty * prop, AVal * str);
136 | void AMFProp_GetObject(AMFObjectProperty * prop, AMFObject * obj);
137 |
138 | int AMFProp_IsValid(AMFObjectProperty * prop);
139 |
140 | char *AMFProp_Encode(AMFObjectProperty * prop, char *pBuffer, char *pBufEnd);
141 | int AMF3Prop_Decode(AMFObjectProperty * prop, const char *pBuffer,
142 | int nSize, int bDecodeName);
143 | int AMFProp_Decode(AMFObjectProperty * prop, const char *pBuffer,
144 | int nSize, int bDecodeName);
145 |
146 | void AMFProp_Dump(AMFObjectProperty * prop);
147 | void AMFProp_Reset(AMFObjectProperty * prop);
148 |
149 | typedef struct AMF3ClassDef
150 | {
151 | AVal cd_name;
152 | char cd_externalizable;
153 | char cd_dynamic;
154 | int cd_num;
155 | AVal *cd_props;
156 | } AMF3ClassDef;
157 |
158 | void AMF3CD_AddProp(AMF3ClassDef * cd, AVal * prop);
159 | AVal *AMF3CD_GetProp(AMF3ClassDef * cd, int idx);
160 |
161 | #ifdef __cplusplus
162 | }
163 | #endif
164 |
165 | #endif /* __AMF_H__ */
166 |
--------------------------------------------------------------------------------
/librtmp/bytes.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2005-2008 Team XBMC
3 | * http://www.xbmc.org
4 | * Copyright (C) 2008-2009 Andrej Stepanchuk
5 | * Copyright (C) 2009-2010 Howard Chu
6 | *
7 | * This file is part of librtmp.
8 | *
9 | * librtmp is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU Lesser General Public License as
11 | * published by the Free Software Foundation; either version 2.1,
12 | * or (at your option) any later version.
13 | *
14 | * librtmp is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with librtmp see the file COPYING. If not, write to
21 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 | * Boston, MA 02110-1301, USA.
23 | * http://www.gnu.org/copyleft/lgpl.html
24 | */
25 |
26 | #ifndef __BYTES_H__
27 | #define __BYTES_H__
28 |
29 | #ifdef _WIN32
30 | /* Windows is little endian only */
31 | #define __LITTLE_ENDIAN 1234
32 | #define __BIG_ENDIAN 4321
33 | #define __BYTE_ORDER __LITTLE_ENDIAN
34 | #define __FLOAT_WORD_ORDER __BYTE_ORDER
35 |
36 | typedef unsigned char uint8_t;
37 |
38 | #else /* !_WIN32 */
39 |
40 | #include
41 |
42 | #if defined(BYTE_ORDER) && !defined(__BYTE_ORDER)
43 | #define __BYTE_ORDER BYTE_ORDER
44 | #endif
45 |
46 | #if defined(BIG_ENDIAN) && !defined(__BIG_ENDIAN)
47 | #define __BIG_ENDIAN BIG_ENDIAN
48 | #endif
49 |
50 | #if defined(LITTLE_ENDIAN) && !defined(__LITTLE_ENDIAN)
51 | #define __LITTLE_ENDIAN LITTLE_ENDIAN
52 | #endif
53 |
54 | #endif /* !_WIN32 */
55 |
56 | /* define default endianness */
57 | #ifndef __LITTLE_ENDIAN
58 | #define __LITTLE_ENDIAN 1234
59 | #endif
60 |
61 | #ifndef __BIG_ENDIAN
62 | #define __BIG_ENDIAN 4321
63 | #endif
64 |
65 | #ifndef __BYTE_ORDER
66 | #warning "Byte order not defined on your system, assuming little endian!"
67 | #define __BYTE_ORDER __LITTLE_ENDIAN
68 | #endif
69 |
70 | /* ok, we assume to have the same float word order and byte order if float word order is not defined */
71 | #ifndef __FLOAT_WORD_ORDER
72 | #warning "Float word order not defined, assuming the same as byte order!"
73 | #define __FLOAT_WORD_ORDER __BYTE_ORDER
74 | #endif
75 |
76 | #if !defined(__BYTE_ORDER) || !defined(__FLOAT_WORD_ORDER)
77 | #error "Undefined byte or float word order!"
78 | #endif
79 |
80 | #if __FLOAT_WORD_ORDER != __BIG_ENDIAN && __FLOAT_WORD_ORDER != __LITTLE_ENDIAN
81 | #error "Unknown/unsupported float word order!"
82 | #endif
83 |
84 | #if __BYTE_ORDER != __BIG_ENDIAN && __BYTE_ORDER != __LITTLE_ENDIAN
85 | #error "Unknown/unsupported byte order!"
86 | #endif
87 |
88 | #endif
89 |
90 |
--------------------------------------------------------------------------------
/librtmp/cencode.c:
--------------------------------------------------------------------------------
1 | /*
2 | cencoder.c - c source to a base64 encoding algorithm implementation
3 |
4 | This is part of the libb64 project, and has been placed in the public domain.
5 | For details, see http://sourceforge.net/projects/libb64
6 | */
7 |
8 | #include "cencode.h"
9 |
10 | const int CHARS_PER_LINE = 72;
11 |
12 | void base64_init_encodestate(base64_encodestate* state_in)
13 | {
14 | state_in->step = step_A;
15 | state_in->result = 0;
16 | state_in->stepcount = 0;
17 | }
18 |
19 | char base64_encode_value(char value_in)
20 | {
21 | static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
22 | if (value_in > 63) return '=';
23 | return encoding[(int)value_in];
24 | }
25 |
26 | int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in)
27 | {
28 | const char* plainchar = plaintext_in;
29 | const char* const plaintextend = plaintext_in + length_in;
30 | char* codechar = code_out;
31 | char result;
32 | char fragment;
33 |
34 | result = state_in->result;
35 |
36 | switch (state_in->step)
37 | {
38 | while (1)
39 | {
40 | case step_A:
41 | if (plainchar == plaintextend)
42 | {
43 | state_in->result = result;
44 | state_in->step = step_A;
45 | return codechar - code_out;
46 | }
47 | fragment = *plainchar++;
48 | result = (fragment & 0x0fc) >> 2;
49 | *codechar++ = base64_encode_value(result);
50 | result = (fragment & 0x003) << 4;
51 | case step_B:
52 | if (plainchar == plaintextend)
53 | {
54 | state_in->result = result;
55 | state_in->step = step_B;
56 | return codechar - code_out;
57 | }
58 | fragment = *plainchar++;
59 | result |= (fragment & 0x0f0) >> 4;
60 | *codechar++ = base64_encode_value(result);
61 | result = (fragment & 0x00f) << 2;
62 | case step_C:
63 | if (plainchar == plaintextend)
64 | {
65 | state_in->result = result;
66 | state_in->step = step_C;
67 | return codechar - code_out;
68 | }
69 | fragment = *plainchar++;
70 | result |= (fragment & 0x0c0) >> 6;
71 | *codechar++ = base64_encode_value(result);
72 | result = (fragment & 0x03f) >> 0;
73 | *codechar++ = base64_encode_value(result);
74 |
75 | ++(state_in->stepcount);
76 | /*if (state_in->stepcount == CHARS_PER_LINE/4)
77 | {
78 | *codechar++ = '\n';
79 | state_in->stepcount = 0;
80 | }*/
81 | }
82 | }
83 | /* control should not reach here */
84 | return codechar - code_out;
85 | }
86 |
87 | int base64_encode_blockend(char* code_out, base64_encodestate* state_in)
88 | {
89 | char* codechar = code_out;
90 |
91 | switch (state_in->step)
92 | {
93 | case step_B:
94 | *codechar++ = base64_encode_value(state_in->result);
95 | *codechar++ = '=';
96 | *codechar++ = '=';
97 | break;
98 | case step_C:
99 | *codechar++ = base64_encode_value(state_in->result);
100 | *codechar++ = '=';
101 | break;
102 | case step_A:
103 | break;
104 | }
105 | *codechar++ = '\0';
106 |
107 | return codechar - code_out;
108 | }
109 |
110 |
--------------------------------------------------------------------------------
/librtmp/cencode.h:
--------------------------------------------------------------------------------
1 | /*
2 | cencode.h - c header for a base64 encoding algorithm
3 |
4 | This is part of the libb64 project, and has been placed in the public domain.
5 | For details, see http://sourceforge.net/projects/libb64
6 | */
7 |
8 | #ifndef BASE64_CENCODE_H
9 | #define BASE64_CENCODE_H
10 |
11 | typedef enum
12 | {
13 | step_A, step_B, step_C
14 | } base64_encodestep;
15 |
16 | typedef struct
17 | {
18 | base64_encodestep step;
19 | char result;
20 | int stepcount;
21 | } base64_encodestate;
22 |
23 | void base64_init_encodestate(base64_encodestate* state_in);
24 |
25 | char base64_encode_value(char value_in);
26 |
27 | int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in);
28 |
29 | int base64_encode_blockend(char* code_out, base64_encodestate* state_in);
30 |
31 | #endif /* BASE64_CENCODE_H */
32 |
--------------------------------------------------------------------------------
/librtmp/dh.h:
--------------------------------------------------------------------------------
1 | /* RTMPDump - Diffie-Hellmann Key Exchange
2 | * Copyright (C) 2009 Andrej Stepanchuk
3 | * Copyright (C) 2009-2010 Howard Chu
4 | *
5 | * This file is part of librtmp.
6 | *
7 | * librtmp is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1,
10 | * or (at your option) any later version.
11 | *
12 | * librtmp is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public License
18 | * along with librtmp see the file COPYING. If not, write to
19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 | * Boston, MA 02110-1301, USA.
21 | * http://www.gnu.org/copyleft/lgpl.html
22 | */
23 |
24 | #ifdef USE_POLARSSL
25 | #include
26 | typedef mpi * MP_t;
27 | #define MP_new(m) m = malloc(sizeof(mpi)); mpi_init(m)
28 | #define MP_set_w(mpi, w) mpi_lset(mpi, w)
29 | #define MP_cmp(u, v) mpi_cmp_mpi(u, v)
30 | #define MP_set(u, v) mpi_copy(u, v)
31 | #define MP_sub_w(mpi, w) mpi_sub_int(mpi, mpi, w)
32 | #define MP_cmp_1(mpi) mpi_cmp_int(mpi, 1)
33 | #define MP_modexp(r, y, q, p) mpi_exp_mod(r, y, q, p, NULL)
34 | #define MP_free(mpi) mpi_free(mpi); free(mpi)
35 | #define MP_gethex(u, hex, res) MP_new(u); res = mpi_read_string(u, 16, hex) == 0
36 | #define MP_bytes(u) mpi_size(u)
37 | #define MP_setbin(u,buf,len) mpi_write_binary(u,buf,len)
38 | #define MP_getbin(u,buf,len) MP_new(u); mpi_read_binary(u,buf,len)
39 |
40 | typedef struct MDH
41 | {
42 | MP_t p;
43 | MP_t g;
44 | MP_t pub_key;
45 | MP_t priv_key;
46 | long length;
47 | dhm_context ctx;
48 | } MDH;
49 |
50 | #define MDH_new() calloc(1,sizeof(MDH))
51 | #define MDH_free(vp) {MDH *_dh = vp; dhm_free(&_dh->ctx); MP_free(_dh->p); MP_free(_dh->g); MP_free(_dh->pub_key); MP_free(_dh->priv_key); free(_dh);}
52 |
53 | static int MDH_generate_key(MDH *dh)
54 | {
55 | unsigned char out[2];
56 | MP_set(&dh->ctx.P, dh->p);
57 | MP_set(&dh->ctx.G, dh->g);
58 | dh->ctx.len = 128;
59 | dhm_make_public(&dh->ctx, 1024, out, 1, havege_random, &RTMP_TLS_ctx->hs);
60 | MP_new(dh->pub_key);
61 | MP_new(dh->priv_key);
62 | MP_set(dh->pub_key, &dh->ctx.GX);
63 | MP_set(dh->priv_key, &dh->ctx.X);
64 | return 1;
65 | }
66 |
67 | static int MDH_compute_key(uint8_t *secret, size_t len, MP_t pub, MDH *dh)
68 | {
69 | MP_set(&dh->ctx.GY, pub);
70 | dhm_calc_secret(&dh->ctx, secret, &len);
71 | return 0;
72 | }
73 |
74 | #elif defined(USE_GNUTLS)
75 | #include
76 | #include
77 | typedef mpz_ptr MP_t;
78 | #define MP_new(m) m = malloc(sizeof(*m)); mpz_init2(m, 1)
79 | #define MP_set_w(mpi, w) mpz_set_ui(mpi, w)
80 | #define MP_cmp(u, v) mpz_cmp(u, v)
81 | #define MP_set(u, v) mpz_set(u, v)
82 | #define MP_sub_w(mpi, w) mpz_sub_ui(mpi, mpi, w)
83 | #define MP_cmp_1(mpi) mpz_cmp_ui(mpi, 1)
84 | #define MP_modexp(r, y, q, p) mpz_powm(r, y, q, p)
85 | #define MP_free(mpi) mpz_clear(mpi); free(mpi)
86 | #define MP_gethex(u, hex, res) u = malloc(sizeof(*u)); mpz_init2(u, 1); res = (mpz_set_str(u, hex, 16) == 0)
87 | #define MP_bytes(u) (mpz_sizeinbase(u, 2) + 7) / 8
88 | #define MP_setbin(u,buf,len) nettle_mpz_get_str_256(len,buf,u)
89 | #define MP_getbin(u,buf,len) u = malloc(sizeof(*u)); mpz_init2(u, 1); nettle_mpz_set_str_256_u(u,len,buf)
90 |
91 | typedef struct MDH
92 | {
93 | MP_t p;
94 | MP_t g;
95 | MP_t pub_key;
96 | MP_t priv_key;
97 | long length;
98 | } MDH;
99 |
100 | #define MDH_new() calloc(1,sizeof(MDH))
101 | #define MDH_free(dh) do {MP_free(((MDH*)(dh))->p); MP_free(((MDH*)(dh))->g); MP_free(((MDH*)(dh))->pub_key); MP_free(((MDH*)(dh))->priv_key); free(dh);} while(0)
102 |
103 | extern MP_t gnutls_calc_dh_secret(MP_t *priv, MP_t g, MP_t p);
104 | extern MP_t gnutls_calc_dh_key(MP_t y, MP_t x, MP_t p);
105 |
106 | #define MDH_generate_key(dh) (dh->pub_key = gnutls_calc_dh_secret(&dh->priv_key, dh->g, dh->p))
107 | static int MDH_compute_key(uint8_t *secret, size_t len, MP_t pub, MDH *dh)
108 | {
109 | MP_t sec = gnutls_calc_dh_key(pub, dh->priv_key, dh->p);
110 | if (sec)
111 | {
112 | MP_setbin(sec, secret, len);
113 | MP_free(sec);
114 | return 0;
115 | }
116 | else
117 | return -1;
118 | }
119 |
120 | #else /* USE_OPENSSL */
121 | #include
122 | #include
123 |
124 | typedef BIGNUM * MP_t;
125 | #define MP_new(m) m = BN_new()
126 | #define MP_set_w(mpi, w) BN_set_word(mpi, w)
127 | #define MP_cmp(u, v) BN_cmp(u, v)
128 | #define MP_set(u, v) BN_copy(u, v)
129 | #define MP_sub_w(mpi, w) BN_sub_word(mpi, w)
130 | #define MP_cmp_1(mpi) BN_cmp(mpi, BN_value_one())
131 | #define MP_modexp(r, y, q, p) do {BN_CTX *ctx = BN_CTX_new(); BN_mod_exp(r, y, q, p, ctx); BN_CTX_free(ctx);} while(0)
132 | #define MP_free(mpi) BN_free(mpi)
133 | #define MP_gethex(u, hex, res) res = BN_hex2bn(&u, hex)
134 | #define MP_bytes(u) BN_num_bytes(u)
135 | #define MP_setbin(u,buf,len) BN_bn2bin(u,buf)
136 | #define MP_getbin(u,buf,len) u = BN_bin2bn(buf,len,0)
137 |
138 | #define MDH DH
139 | #define MDH_new() DH_new()
140 | #define MDH_free(dh) DH_free(dh)
141 | #define MDH_generate_key(dh) DH_generate_key(dh)
142 | #define MDH_compute_key(secret, seclen, pub, dh) DH_compute_key(secret, pub, dh)
143 |
144 | #endif
145 |
146 | #include "log.h"
147 | #include "dhgroups.h"
148 |
149 | /* RFC 2631, Section 2.1.5, http://www.ietf.org/rfc/rfc2631.txt */
150 | static int
151 | isValidPublicKey(MP_t y, MP_t p, MP_t q)
152 | {
153 | int ret = TRUE;
154 | MP_t bn;
155 | assert(y);
156 |
157 | MP_new(bn);
158 | assert(bn);
159 |
160 | /* y must lie in [2,p-1] */
161 | MP_set_w(bn, 1);
162 | if (MP_cmp(y, bn) < 0)
163 | {
164 | RTMP_Log(RTMP_LOGERROR, "DH public key must be at least 2");
165 | ret = FALSE;
166 | goto failed;
167 | }
168 |
169 | /* bn = p-2 */
170 | MP_set(bn, p);
171 | MP_sub_w(bn, 1);
172 | if (MP_cmp(y, bn) > 0)
173 | {
174 | RTMP_Log(RTMP_LOGERROR, "DH public key must be at most p-2");
175 | ret = FALSE;
176 | goto failed;
177 | }
178 |
179 | /* Verify with Sophie-Germain prime
180 | *
181 | * This is a nice test to make sure the public key position is calculated
182 | * correctly. This test will fail in about 50% of the cases if applied to
183 | * random data.
184 | */
185 | if (q)
186 | {
187 | /* y must fulfill y^q mod p = 1 */
188 | MP_modexp(bn, y, q, p);
189 |
190 | if (MP_cmp_1(bn) != 0)
191 | {
192 | RTMP_Log(RTMP_LOGWARNING, "DH public key does not fulfill y^q mod p = 1");
193 | }
194 | }
195 |
196 | failed:
197 | MP_free(bn);
198 | return ret;
199 | }
200 |
201 | static MDH *
202 | DHInit(int nKeyBits)
203 | {
204 | size_t res;
205 | MDH *dh = MDH_new();
206 |
207 | if (!dh)
208 | goto failed;
209 |
210 | MP_new(dh->g);
211 |
212 | if (!dh->g)
213 | goto failed;
214 |
215 | MP_gethex(dh->p, P1024, res); /* prime P1024, see dhgroups.h */
216 | if (!res)
217 | {
218 | goto failed;
219 | }
220 |
221 | MP_set_w(dh->g, 2); /* base 2 */
222 |
223 | dh->length = nKeyBits;
224 | return dh;
225 |
226 | failed:
227 | if (dh)
228 | MDH_free(dh);
229 |
230 | return 0;
231 | }
232 |
233 | static int
234 | DHGenerateKey(MDH *dh)
235 | {
236 | size_t res = 0;
237 | if (!dh)
238 | return 0;
239 |
240 | while (!res)
241 | {
242 | MP_t q1 = NULL;
243 |
244 | if (!MDH_generate_key(dh))
245 | return 0;
246 |
247 | MP_gethex(q1, Q1024, res);
248 | assert(res);
249 |
250 | res = isValidPublicKey(dh->pub_key, dh->p, q1);
251 | if (!res)
252 | {
253 | MP_free(dh->pub_key);
254 | MP_free(dh->priv_key);
255 | dh->pub_key = dh->priv_key = 0;
256 | }
257 |
258 | MP_free(q1);
259 | }
260 | return 1;
261 | }
262 |
263 | /* fill pubkey with the public key in BIG ENDIAN order
264 | * 00 00 00 00 00 x1 x2 x3 .....
265 | */
266 |
267 | static int
268 | DHGetPublicKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen)
269 | {
270 | int len;
271 | if (!dh || !dh->pub_key)
272 | return 0;
273 |
274 | len = MP_bytes(dh->pub_key);
275 | if (len <= 0 || len > (int) nPubkeyLen)
276 | return 0;
277 |
278 | memset(pubkey, 0, nPubkeyLen);
279 | MP_setbin(dh->pub_key, pubkey + (nPubkeyLen - len), len);
280 | return 1;
281 | }
282 |
283 | #if 0 /* unused */
284 | static int
285 | DHGetPrivateKey(MDH *dh, uint8_t *privkey, size_t nPrivkeyLen)
286 | {
287 | if (!dh || !dh->priv_key)
288 | return 0;
289 |
290 | int len = MP_bytes(dh->priv_key);
291 | if (len <= 0 || len > (int) nPrivkeyLen)
292 | return 0;
293 |
294 | memset(privkey, 0, nPrivkeyLen);
295 | MP_setbin(dh->priv_key, privkey + (nPrivkeyLen - len), len);
296 | return 1;
297 | }
298 | #endif
299 |
300 | /* computes the shared secret key from the private MDH value and the
301 | * other party's public key (pubkey)
302 | */
303 | static int
304 | DHComputeSharedSecretKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen,
305 | uint8_t *secret)
306 | {
307 | MP_t q1 = NULL, pubkeyBn = NULL;
308 | size_t len;
309 | int res;
310 |
311 | if (!dh || !secret || nPubkeyLen >= INT_MAX)
312 | return -1;
313 |
314 | MP_getbin(pubkeyBn, pubkey, nPubkeyLen);
315 | if (!pubkeyBn)
316 | return -1;
317 |
318 | MP_gethex(q1, Q1024, len);
319 | assert(len);
320 |
321 | if (isValidPublicKey(pubkeyBn, dh->p, q1))
322 | res = MDH_compute_key(secret, nPubkeyLen, pubkeyBn, dh);
323 | else
324 | res = -1;
325 |
326 | MP_free(q1);
327 | MP_free(pubkeyBn);
328 |
329 | return res;
330 | }
331 |
--------------------------------------------------------------------------------
/librtmp/dhgroups.h:
--------------------------------------------------------------------------------
1 | /* librtmp - Diffie-Hellmann Key Exchange
2 | * Copyright (C) 2009 Andrej Stepanchuk
3 | *
4 | * This file is part of librtmp.
5 | *
6 | * librtmp is free software; you can redistribute it and/or modify
7 | * it under the terms of the GNU Lesser General Public License as
8 | * published by the Free Software Foundation; either version 2.1,
9 | * or (at your option) any later version.
10 | *
11 | * librtmp is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with librtmp see the file COPYING. If not, write to
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 | * Boston, MA 02110-1301, USA.
20 | * http://www.gnu.org/copyleft/lgpl.html
21 | */
22 |
23 | /* from RFC 3526, see http://www.ietf.org/rfc/rfc3526.txt */
24 |
25 | /* 2^768 - 2 ^704 - 1 + 2^64 * { [2^638 pi] + 149686 } */
26 | #define P768 \
27 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
28 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
29 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
30 | "E485B576625E7EC6F44C42E9A63A3620FFFFFFFFFFFFFFFF"
31 |
32 | /* 2^1024 - 2^960 - 1 + 2^64 * { [2^894 pi] + 129093 } */
33 | #define P1024 \
34 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
35 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
36 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
37 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
38 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381" \
39 | "FFFFFFFFFFFFFFFF"
40 |
41 | /* Group morder largest prime factor: */
42 | #define Q1024 \
43 | "7FFFFFFFFFFFFFFFE487ED5110B4611A62633145C06E0E68" \
44 | "948127044533E63A0105DF531D89CD9128A5043CC71A026E" \
45 | "F7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E122" \
46 | "F242DABB312F3F637A262174D31BF6B585FFAE5B7A035BF6" \
47 | "F71C35FDAD44CFD2D74F9208BE258FF324943328F67329C0" \
48 | "FFFFFFFFFFFFFFFF"
49 |
50 | /* 2^1536 - 2^1472 - 1 + 2^64 * { [2^1406 pi] + 741804 } */
51 | #define P1536 \
52 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
53 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
54 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
55 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
56 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
57 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
58 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
59 | "670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF"
60 |
61 | /* 2^2048 - 2^1984 - 1 + 2^64 * { [2^1918 pi] + 124476 } */
62 | #define P2048 \
63 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
64 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
65 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
66 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
67 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
68 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
69 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
70 | "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
71 | "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
72 | "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
73 | "15728E5A8AACAA68FFFFFFFFFFFFFFFF"
74 |
75 | /* 2^3072 - 2^3008 - 1 + 2^64 * { [2^2942 pi] + 1690314 } */
76 | #define P3072 \
77 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
78 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
79 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
80 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
81 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
82 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
83 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
84 | "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
85 | "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
86 | "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
87 | "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
88 | "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
89 | "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
90 | "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
91 | "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
92 | "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF"
93 |
94 | /* 2^4096 - 2^4032 - 1 + 2^64 * { [2^3966 pi] + 240904 } */
95 | #define P4096 \
96 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
97 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
98 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
99 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
100 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
101 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
102 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
103 | "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
104 | "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
105 | "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
106 | "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
107 | "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
108 | "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
109 | "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
110 | "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
111 | "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" \
112 | "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" \
113 | "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" \
114 | "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" \
115 | "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" \
116 | "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199" \
117 | "FFFFFFFFFFFFFFFF"
118 |
119 | /* 2^6144 - 2^6080 - 1 + 2^64 * { [2^6014 pi] + 929484 } */
120 | #define P6144 \
121 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
122 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
123 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
124 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
125 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
126 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
127 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
128 | "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
129 | "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
130 | "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
131 | "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
132 | "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
133 | "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
134 | "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
135 | "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
136 | "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" \
137 | "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" \
138 | "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" \
139 | "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" \
140 | "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" \
141 | "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934028492" \
142 | "36C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BD" \
143 | "F8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831" \
144 | "179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1B" \
145 | "DB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF" \
146 | "5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6" \
147 | "D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F3" \
148 | "23A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA" \
149 | "CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE328" \
150 | "06A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55C" \
151 | "DA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE" \
152 | "12BF2D5B0B7474D6E694F91E6DCC4024FFFFFFFFFFFFFFFF"
153 |
154 | /* 2^8192 - 2^8128 - 1 + 2^64 * { [2^8062 pi] + 4743158 } */
155 | #define P8192 \
156 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
157 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
158 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
159 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
160 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
161 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
162 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
163 | "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
164 | "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
165 | "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
166 | "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
167 | "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
168 | "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
169 | "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
170 | "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
171 | "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" \
172 | "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" \
173 | "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" \
174 | "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" \
175 | "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" \
176 | "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934028492" \
177 | "36C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BD" \
178 | "F8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831" \
179 | "179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1B" \
180 | "DB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF" \
181 | "5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6" \
182 | "D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F3" \
183 | "23A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA" \
184 | "CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE328" \
185 | "06A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55C" \
186 | "DA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE" \
187 | "12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E4" \
188 | "38777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300" \
189 | "741FA7BF8AFC47ED2576F6936BA424663AAB639C5AE4F568" \
190 | "3423B4742BF1C978238F16CBE39D652DE3FDB8BEFC848AD9" \
191 | "22222E04A4037C0713EB57A81A23F0C73473FC646CEA306B" \
192 | "4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A" \
193 | "062B3CF5B3A278A66D2A13F83F44F82DDF310EE074AB6A36" \
194 | "4597E899A0255DC164F31CC50846851DF9AB48195DED7EA1" \
195 | "B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F92" \
196 | "4009438B481C6CD7889A002ED5EE382BC9190DA6FC026E47" \
197 | "9558E4475677E9AA9E3050E2765694DFC81F56E880B96E71" \
198 | "60C980DD98EDD3DFFFFFFFFFFFFFFFFF"
199 |
200 |
--------------------------------------------------------------------------------
/librtmp/hashswf.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Howard Chu
3 | *
4 | * This file is part of librtmp.
5 | *
6 | * librtmp is free software; you can redistribute it and/or modify
7 | * it under the terms of the GNU Lesser General Public License as
8 | * published by the Free Software Foundation; either version 2.1,
9 | * or (at your option) any later version.
10 | *
11 | * librtmp is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with librtmp see the file COPYING. If not, write to
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 | * Boston, MA 02110-1301, USA.
20 | * http://www.gnu.org/copyleft/lgpl.html
21 | */
22 |
23 | #include "rtmp_sys.h"
24 | #include "log.h"
25 | #include "http.h"
26 |
27 | #ifdef CRYPTO
28 | #ifdef USE_POLARSSL
29 | #include
30 | #ifndef SHA256_DIGEST_LENGTH
31 | #define SHA256_DIGEST_LENGTH 32
32 | #endif
33 | #define HMAC_CTX sha2_context
34 | #define HMAC_setup(ctx, key, len) sha2_hmac_starts(&ctx, (unsigned char *)key, len, 0)
35 | #define HMAC_crunch(ctx, buf, len) sha2_hmac_update(&ctx, buf, len)
36 | #define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; sha2_hmac_finish(&ctx, dig)
37 | #define HMAC_close(ctx)
38 | #elif defined(USE_GNUTLS)
39 | #include
40 | #ifndef SHA256_DIGEST_LENGTH
41 | #define SHA256_DIGEST_LENGTH 32
42 | #endif
43 | #undef HMAC_CTX
44 | #define HMAC_CTX struct hmac_sha256_ctx
45 | #define HMAC_setup(ctx, key, len) hmac_sha256_set_key(&ctx, len, key)
46 | #define HMAC_crunch(ctx, buf, len) hmac_sha256_update(&ctx, len, buf)
47 | #define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; hmac_sha256_digest(&ctx, SHA256_DIGEST_LENGTH, dig)
48 | #define HMAC_close(ctx)
49 | #else /* USE_OPENSSL */
50 | #include
51 | #include
52 | #include
53 | #include
54 | #define HMAC_setup(ctx, key, len) HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, (unsigned char *)key, len, EVP_sha256(), 0)
55 | #define HMAC_crunch(ctx, buf, len) HMAC_Update(&ctx, (unsigned char *)buf, len)
56 | #define HMAC_finish(ctx, dig, dlen) HMAC_Final(&ctx, (unsigned char *)dig, &dlen);
57 | #define HMAC_close(ctx) HMAC_CTX_cleanup(&ctx)
58 | #endif
59 |
60 | extern void RTMP_TLS_Init();
61 | extern TLS_CTX RTMP_TLS_ctx;
62 |
63 | #include
64 |
65 | #endif /* CRYPTO */
66 |
67 | #define AGENT "Mozilla/5.0"
68 |
69 | HTTPResult
70 | HTTP_get(struct HTTP_ctx *http, const char *url, HTTP_read_callback *cb)
71 | {
72 | char *host, *path;
73 | char *p1, *p2;
74 | char hbuf[256];
75 | int port = 80;
76 | #ifdef CRYPTO
77 | int ssl = 0;
78 | #endif
79 | int hlen, flen = 0;
80 | int rc, i;
81 | int len_known;
82 | HTTPResult ret = HTTPRES_OK;
83 | struct sockaddr_in sa;
84 | RTMPSockBuf sb = {0};
85 |
86 | http->status = -1;
87 |
88 | memset(&sa, 0, sizeof(struct sockaddr_in));
89 | sa.sin_family = AF_INET;
90 |
91 | /* we only handle http here */
92 | if (strncasecmp(url, "http", 4))
93 | return HTTPRES_BAD_REQUEST;
94 |
95 | if (url[4] == 's')
96 | {
97 | #ifdef CRYPTO
98 | ssl = 1;
99 | port = 443;
100 | if (!RTMP_TLS_ctx)
101 | RTMP_TLS_Init();
102 | #else
103 | return HTTPRES_BAD_REQUEST;
104 | #endif
105 | }
106 |
107 | p1 = strchr(url + 4, ':');
108 | if (!p1 || strncmp(p1, "://", 3))
109 | return HTTPRES_BAD_REQUEST;
110 |
111 | host = p1 + 3;
112 | path = strchr(host, '/');
113 | hlen = path - host;
114 | strncpy(hbuf, host, hlen);
115 | hbuf[hlen] = '\0';
116 | host = hbuf;
117 | p1 = strrchr(host, ':');
118 | if (p1)
119 | {
120 | *p1++ = '\0';
121 | port = atoi(p1);
122 | }
123 |
124 | sa.sin_addr.s_addr = inet_addr(host);
125 | if (sa.sin_addr.s_addr == INADDR_NONE)
126 | {
127 | struct hostent *hp = gethostbyname(host);
128 | if (!hp || !hp->h_addr)
129 | return HTTPRES_LOST_CONNECTION;
130 | sa.sin_addr = *(struct in_addr *)hp->h_addr;
131 | }
132 | sa.sin_port = htons(port);
133 | sb.sb_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
134 | if (sb.sb_socket == -1)
135 | return HTTPRES_LOST_CONNECTION;
136 | i =
137 | sprintf(sb.sb_buf,
138 | "GET %s HTTP/1.0\r\nUser-Agent: %s\r\nHost: %s\r\nReferer: %.*s\r\n",
139 | path, AGENT, host, (int)(path - url + 1), url);
140 | if (http->date[0])
141 | i += sprintf(sb.sb_buf + i, "If-Modified-Since: %s\r\n", http->date);
142 | i += sprintf(sb.sb_buf + i, "\r\n");
143 |
144 | if (connect
145 | (sb.sb_socket, (struct sockaddr *)&sa, sizeof(struct sockaddr)) < 0)
146 | {
147 | ret = HTTPRES_LOST_CONNECTION;
148 | goto leave;
149 | }
150 | #ifdef CRYPTO
151 | if (ssl)
152 | {
153 | #ifdef NO_SSL
154 | RTMP_Log(RTMP_LOGERROR, "%s, No SSL/TLS support", __FUNCTION__);
155 | ret = HTTPRES_BAD_REQUEST;
156 | goto leave;
157 | #else
158 | TLS_client(RTMP_TLS_ctx, sb.sb_ssl);
159 | TLS_setfd(sb.sb_ssl, sb.sb_socket);
160 | if (TLS_connect(sb.sb_ssl) < 0)
161 | {
162 | RTMP_Log(RTMP_LOGERROR, "%s, TLS_Connect failed", __FUNCTION__);
163 | ret = HTTPRES_LOST_CONNECTION;
164 | goto leave;
165 | }
166 | #endif
167 | }
168 | #endif
169 | RTMPSockBuf_Send(&sb, sb.sb_buf, i);
170 |
171 | /* set timeout */
172 | #define HTTP_TIMEOUT 5
173 | {
174 | SET_RCVTIMEO(tv, HTTP_TIMEOUT);
175 | if (setsockopt
176 | (sb.sb_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)))
177 | {
178 | RTMP_Log(RTMP_LOGERROR, "%s, Setting socket timeout to %ds failed!",
179 | __FUNCTION__, HTTP_TIMEOUT);
180 | }
181 | }
182 |
183 | sb.sb_size = 0;
184 | sb.sb_timedout = FALSE;
185 | if (RTMPSockBuf_Fill(&sb) < 1)
186 | {
187 | ret = HTTPRES_LOST_CONNECTION;
188 | goto leave;
189 | }
190 | if (strncmp(sb.sb_buf, "HTTP/1", 6))
191 | {
192 | ret = HTTPRES_BAD_REQUEST;
193 | goto leave;
194 | }
195 |
196 | p1 = strchr(sb.sb_buf, ' ');
197 | rc = atoi(p1 + 1);
198 | http->status = rc;
199 |
200 | if (rc >= 300)
201 | {
202 | if (rc == 304)
203 | {
204 | ret = HTTPRES_OK_NOT_MODIFIED;
205 | goto leave;
206 | }
207 | else if (rc == 404)
208 | ret = HTTPRES_NOT_FOUND;
209 | else if (rc >= 500)
210 | ret = HTTPRES_SERVER_ERROR;
211 | else if (rc >= 400)
212 | ret = HTTPRES_BAD_REQUEST;
213 | else
214 | ret = HTTPRES_REDIRECTED;
215 | }
216 |
217 | p1 = memchr(sb.sb_buf, '\n', sb.sb_size);
218 | if (!p1)
219 | {
220 | ret = HTTPRES_BAD_REQUEST;
221 | goto leave;
222 | }
223 | sb.sb_start = p1 + 1;
224 | sb.sb_size -= sb.sb_start - sb.sb_buf;
225 |
226 | while ((p2 = memchr(sb.sb_start, '\r', sb.sb_size)))
227 | {
228 | if (*sb.sb_start == '\r')
229 | {
230 | sb.sb_start += 2;
231 | sb.sb_size -= 2;
232 | break;
233 | }
234 | else if (!strncasecmp
235 | (sb.sb_start, "Content-Length: ", sizeof("Content-Length: ") - 1))
236 | {
237 | flen = atoi(sb.sb_start + sizeof("Content-Length: ") - 1);
238 | }
239 | else if (!strncasecmp
240 | (sb.sb_start, "Last-Modified: ", sizeof("Last-Modified: ") - 1))
241 | {
242 | *p2 = '\0';
243 | strcpy(http->date, sb.sb_start + sizeof("Last-Modified: ") - 1);
244 | }
245 | p2 += 2;
246 | sb.sb_size -= p2 - sb.sb_start;
247 | sb.sb_start = p2;
248 | if (sb.sb_size < 1)
249 | {
250 | if (RTMPSockBuf_Fill(&sb) < 1)
251 | {
252 | ret = HTTPRES_LOST_CONNECTION;
253 | goto leave;
254 | }
255 | }
256 | }
257 |
258 | len_known = flen > 0;
259 | while ((!len_known || flen > 0) &&
260 | (sb.sb_size > 0 || RTMPSockBuf_Fill(&sb) > 0))
261 | {
262 | cb(sb.sb_start, 1, sb.sb_size, http->data);
263 | if (len_known)
264 | flen -= sb.sb_size;
265 | http->size += sb.sb_size;
266 | sb.sb_size = 0;
267 | }
268 |
269 | if (flen > 0)
270 | ret = HTTPRES_LOST_CONNECTION;
271 |
272 | leave:
273 | RTMPSockBuf_Close(&sb);
274 | return ret;
275 | }
276 |
277 | #ifdef CRYPTO
278 |
279 | #define CHUNK 16384
280 |
281 | struct info
282 | {
283 | z_stream *zs;
284 | HMAC_CTX ctx;
285 | int first;
286 | int zlib;
287 | int size;
288 | };
289 |
290 | static size_t
291 | swfcrunch(void *ptr, size_t size, size_t nmemb, void *stream)
292 | {
293 | struct info *i = stream;
294 | char *p = ptr;
295 | size_t len = size * nmemb;
296 |
297 | if (i->first)
298 | {
299 | i->first = 0;
300 | /* compressed? */
301 | if (!strncmp(p, "CWS", 3))
302 | {
303 | *p = 'F';
304 | i->zlib = 1;
305 | }
306 | HMAC_crunch(i->ctx, (unsigned char *)p, 8);
307 | p += 8;
308 | len -= 8;
309 | i->size = 8;
310 | }
311 |
312 | if (i->zlib)
313 | {
314 | unsigned char out[CHUNK];
315 | i->zs->next_in = (unsigned char *)p;
316 | i->zs->avail_in = len;
317 | do
318 | {
319 | i->zs->avail_out = CHUNK;
320 | i->zs->next_out = out;
321 | inflate(i->zs, Z_NO_FLUSH);
322 | len = CHUNK - i->zs->avail_out;
323 | i->size += len;
324 | HMAC_crunch(i->ctx, out, len);
325 | }
326 | while (i->zs->avail_out == 0);
327 | }
328 | else
329 | {
330 | i->size += len;
331 | HMAC_crunch(i->ctx, (unsigned char *)p, len);
332 | }
333 | return size * nmemb;
334 | }
335 |
336 | static int tzoff;
337 | static int tzchecked;
338 |
339 | #define JAN02_1980 318340800
340 |
341 | static const char *monthtab[12] = { "Jan", "Feb", "Mar",
342 | "Apr", "May", "Jun",
343 | "Jul", "Aug", "Sep",
344 | "Oct", "Nov", "Dec"
345 | };
346 | static const char *days[] =
347 | { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
348 |
349 | /* Parse an HTTP datestamp into Unix time */
350 | static time_t
351 | make_unix_time(char *s)
352 | {
353 | struct tm time;
354 | int i, ysub = 1900, fmt = 0;
355 | char *month;
356 | char *n;
357 | time_t res;
358 |
359 | if (s[3] != ' ')
360 | {
361 | fmt = 1;
362 | if (s[3] != ',')
363 | ysub = 0;
364 | }
365 | for (n = s; *n; ++n)
366 | if (*n == '-' || *n == ':')
367 | *n = ' ';
368 |
369 | time.tm_mon = 0;
370 | n = strchr(s, ' ');
371 | if (fmt)
372 | {
373 | /* Day, DD-MMM-YYYY HH:MM:SS GMT */
374 | time.tm_mday = strtol(n + 1, &n, 0);
375 | month = n + 1;
376 | n = strchr(month, ' ');
377 | time.tm_year = strtol(n + 1, &n, 0);
378 | time.tm_hour = strtol(n + 1, &n, 0);
379 | time.tm_min = strtol(n + 1, &n, 0);
380 | time.tm_sec = strtol(n + 1, NULL, 0);
381 | }
382 | else
383 | {
384 | /* Unix ctime() format. Does not conform to HTTP spec. */
385 | /* Day MMM DD HH:MM:SS YYYY */
386 | month = n + 1;
387 | n = strchr(month, ' ');
388 | while (isspace(*n))
389 | n++;
390 | time.tm_mday = strtol(n, &n, 0);
391 | time.tm_hour = strtol(n + 1, &n, 0);
392 | time.tm_min = strtol(n + 1, &n, 0);
393 | time.tm_sec = strtol(n + 1, &n, 0);
394 | time.tm_year = strtol(n + 1, NULL, 0);
395 | }
396 | if (time.tm_year > 100)
397 | time.tm_year -= ysub;
398 |
399 | for (i = 0; i < 12; i++)
400 | if (!strncasecmp(month, monthtab[i], 3))
401 | {
402 | time.tm_mon = i;
403 | break;
404 | }
405 | time.tm_isdst = 0; /* daylight saving is never in effect in GMT */
406 |
407 | /* this is normally the value of extern int timezone, but some
408 | * braindead C libraries don't provide it.
409 | */
410 | if (!tzchecked)
411 | {
412 | struct tm *tc;
413 | time_t then = JAN02_1980;
414 | tc = localtime(&then);
415 | tzoff = (12 - tc->tm_hour) * 3600 + tc->tm_min * 60 + tc->tm_sec;
416 | tzchecked = 1;
417 | }
418 | res = mktime(&time);
419 | /* Unfortunately, mktime() assumes the input is in local time,
420 | * not GMT, so we have to correct it here.
421 | */
422 | if (res != -1)
423 | res += tzoff;
424 | return res;
425 | }
426 |
427 | /* Convert a Unix time to a network time string
428 | * Weekday, DD-MMM-YYYY HH:MM:SS GMT
429 | */
430 | static void
431 | strtime(time_t * t, char *s)
432 | {
433 | struct tm *tm;
434 |
435 | tm = gmtime((time_t *) t);
436 | sprintf(s, "%s, %02d %s %d %02d:%02d:%02d GMT",
437 | days[tm->tm_wday], tm->tm_mday, monthtab[tm->tm_mon],
438 | tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec);
439 | }
440 |
441 | #define HEX2BIN(a) (((a)&0x40)?((a)&0xf)+9:((a)&0xf))
442 |
443 | int
444 | RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash,
445 | int age)
446 | {
447 | FILE *f = NULL;
448 | char *path, date[64], cctim[64];
449 | long pos = 0;
450 | time_t ctim = -1, cnow;
451 | int i, got = 0, ret = 0;
452 | unsigned int hlen;
453 | struct info in = { 0 };
454 | struct HTTP_ctx http = { 0 };
455 | HTTPResult httpres;
456 | z_stream zs = { 0 };
457 | AVal home, hpre;
458 |
459 | date[0] = '\0';
460 | #ifdef _WIN32
461 | #ifdef XBMC4XBOX
462 | hpre.av_val = "Q:";
463 | hpre.av_len = 2;
464 | home.av_val = "\\UserData";
465 | #else
466 | hpre.av_val = getenv("HOMEDRIVE");
467 | hpre.av_len = strlen(hpre.av_val);
468 | home.av_val = getenv("HOMEPATH");
469 | #endif
470 | #define DIRSEP "\\"
471 |
472 | #else /* !_WIN32 */
473 | hpre.av_val = "";
474 | hpre.av_len = 0;
475 | home.av_val = getenv("HOME");
476 | #define DIRSEP "/"
477 | #endif
478 | if (!home.av_val)
479 | home.av_val = ".";
480 | home.av_len = strlen(home.av_val);
481 |
482 | /* SWF hash info is cached in a fixed-format file.
483 | * url:
484 | * ctim: HTTP datestamp of when we last checked it.
485 | * date: HTTP datestamp of the SWF's last modification.
486 | * size: SWF size in hex
487 | * hash: SWF hash in hex
488 | *
489 | * These fields must be present in this order. All fields
490 | * besides URL are fixed size.
491 | */
492 | path = malloc(hpre.av_len + home.av_len + sizeof(DIRSEP ".swfinfo"));
493 | sprintf(path, "%s%s" DIRSEP ".swfinfo", hpre.av_val, home.av_val);
494 |
495 | f = fopen(path, "r+");
496 | while (f)
497 | {
498 | char buf[4096], *file, *p;
499 |
500 | file = strchr(url, '/');
501 | if (!file)
502 | break;
503 | file += 2;
504 | file = strchr(file, '/');
505 | if (!file)
506 | break;
507 | file++;
508 | hlen = file - url;
509 | p = strrchr(file, '/');
510 | if (p)
511 | file = p;
512 | else
513 | file--;
514 |
515 | while (fgets(buf, sizeof(buf), f))
516 | {
517 | char *r1;
518 |
519 | got = 0;
520 |
521 | if (strncmp(buf, "url: ", 5))
522 | continue;
523 | if (strncmp(buf + 5, url, hlen))
524 | continue;
525 | r1 = strrchr(buf, '/');
526 | i = strlen(r1);
527 | r1[--i] = '\0';
528 | if (strncmp(r1, file, i))
529 | continue;
530 | pos = ftell(f);
531 | while (got < 4 && fgets(buf, sizeof(buf), f))
532 | {
533 | if (!strncmp(buf, "size: ", 6))
534 | {
535 | *size = strtol(buf + 6, NULL, 16);
536 | got++;
537 | }
538 | else if (!strncmp(buf, "hash: ", 6))
539 | {
540 | unsigned char *ptr = hash, *in = (unsigned char *)buf + 6;
541 | int l = strlen((char *)in) - 1;
542 | for (i = 0; i < l; i += 2)
543 | *ptr++ = (HEX2BIN(in[i]) << 4) | HEX2BIN(in[i + 1]);
544 | got++;
545 | }
546 | else if (!strncmp(buf, "date: ", 6))
547 | {
548 | buf[strlen(buf) - 1] = '\0';
549 | strncpy(date, buf + 6, sizeof(date));
550 | got++;
551 | }
552 | else if (!strncmp(buf, "ctim: ", 6))
553 | {
554 | buf[strlen(buf) - 1] = '\0';
555 | ctim = make_unix_time(buf + 6);
556 | got++;
557 | }
558 | else if (!strncmp(buf, "url: ", 5))
559 | break;
560 | }
561 | break;
562 | }
563 | break;
564 | }
565 |
566 | cnow = time(NULL);
567 | /* If we got a cache time, see if it's young enough to use directly */
568 | if (age && ctim > 0)
569 | {
570 | ctim = cnow - ctim;
571 | ctim /= 3600 * 24; /* seconds to days */
572 | if (ctim < age) /* ok, it's new enough */
573 | goto out;
574 | }
575 |
576 | in.first = 1;
577 | HMAC_setup(in.ctx, "Genuine Adobe Flash Player 001", 30);
578 | inflateInit(&zs);
579 | in.zs = &zs;
580 |
581 | http.date = date;
582 | http.data = ∈
583 |
584 | httpres = HTTP_get(&http, url, swfcrunch);
585 |
586 | inflateEnd(&zs);
587 |
588 | if (httpres != HTTPRES_OK && httpres != HTTPRES_OK_NOT_MODIFIED)
589 | {
590 | ret = -1;
591 | if (httpres == HTTPRES_LOST_CONNECTION)
592 | RTMP_Log(RTMP_LOGERROR, "%s: connection lost while downloading swfurl %s",
593 | __FUNCTION__, url);
594 | else if (httpres == HTTPRES_NOT_FOUND)
595 | RTMP_Log(RTMP_LOGERROR, "%s: swfurl %s not found", __FUNCTION__, url);
596 | else
597 | RTMP_Log(RTMP_LOGERROR, "%s: couldn't contact swfurl %s (HTTP error %d)",
598 | __FUNCTION__, url, http.status);
599 | }
600 | else
601 | {
602 | if (got && pos)
603 | fseek(f, pos, SEEK_SET);
604 | else
605 | {
606 | char *q;
607 | if (!f)
608 | f = fopen(path, "w");
609 | if (!f)
610 | {
611 | int err = errno;
612 | RTMP_Log(RTMP_LOGERROR,
613 | "%s: couldn't open %s for writing, errno %d (%s)",
614 | __FUNCTION__, path, err, strerror(err));
615 | ret = -1;
616 | goto out;
617 | }
618 | fseek(f, 0, SEEK_END);
619 | q = strchr(url, '?');
620 | if (q)
621 | i = q - url;
622 | else
623 | i = strlen(url);
624 |
625 | fprintf(f, "url: %.*s\n", i, url);
626 | }
627 | strtime(&cnow, cctim);
628 | fprintf(f, "ctim: %s\n", cctim);
629 |
630 | if (!in.first)
631 | {
632 | HMAC_finish(in.ctx, hash, hlen);
633 | *size = in.size;
634 |
635 | fprintf(f, "date: %s\n", date);
636 | fprintf(f, "size: %08x\n", in.size);
637 | fprintf(f, "hash: ");
638 | for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
639 | fprintf(f, "%02x", hash[i]);
640 | fprintf(f, "\n");
641 | }
642 | }
643 | HMAC_close(in.ctx);
644 | out:
645 | free(path);
646 | if (f)
647 | fclose(f);
648 | return ret;
649 | }
650 | #else
651 | int
652 | RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash,
653 | int age)
654 | {
655 | return -1;
656 | }
657 | #endif
658 |
--------------------------------------------------------------------------------
/librtmp/http.h:
--------------------------------------------------------------------------------
1 | #ifndef __RTMP_HTTP_H__
2 | #define __RTMP_HTTP_H__
3 | /*
4 | * Copyright (C) 2010 Howard Chu
5 | * Copyright (C) 2010 Antti Ajanki
6 | *
7 | * This file is part of librtmp.
8 | *
9 | * librtmp is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU Lesser General Public License as
11 | * published by the Free Software Foundation; either version 2.1,
12 | * or (at your option) any later version.
13 | *
14 | * librtmp is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with librtmp see the file COPYING. If not, write to
21 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 | * Boston, MA 02110-1301, USA.
23 | * http://www.gnu.org/copyleft/lgpl.html
24 | */
25 |
26 | typedef enum
27 | {
28 | HTTPRES_OK, /* result OK */
29 | HTTPRES_OK_NOT_MODIFIED, /* not modified since last request */
30 | HTTPRES_NOT_FOUND, /* not found */
31 | HTTPRES_BAD_REQUEST, /* client error */
32 | HTTPRES_SERVER_ERROR, /* server reported an error */
33 | HTTPRES_REDIRECTED, /* resource has been moved */
34 | HTTPRES_LOST_CONNECTION /* connection lost while waiting for data */
35 | } HTTPResult;
36 |
37 | struct HTTP_ctx
38 | {
39 | char *date;
40 | int size;
41 | int status;
42 | void *data;
43 | };
44 |
45 | typedef size_t (HTTP_read_callback)(void *ptr, size_t size, size_t nmemb, void *stream);
46 |
47 | HTTPResult HTTP_get(struct HTTP_ctx *http, const char *url, HTTP_read_callback *cb);
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/librtmp/log.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008-2009 Andrej Stepanchuk
3 | * Copyright (C) 2009-2010 Howard Chu
4 | *
5 | * This file is part of librtmp.
6 | *
7 | * librtmp is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1,
10 | * or (at your option) any later version.
11 | *
12 | * librtmp is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public License
18 | * along with librtmp see the file COPYING. If not, write to
19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 | * Boston, MA 02110-1301, USA.
21 | * http://www.gnu.org/copyleft/lgpl.html
22 | */
23 |
24 | #include "rtmp_sys.h"
25 | #include "log.h"
26 |
27 | #define MAX_PRINT_LEN 2048
28 |
29 | RTMP_LogLevel RTMP_debuglevel = RTMP_LOGERROR;
30 |
31 | static int neednl;
32 |
33 | static FILE *fmsg;
34 |
35 | static RTMP_LogCallback rtmp_log_default, *cb = rtmp_log_default;
36 |
37 | static const char *levels[] =
38 | {
39 | "CRIT", "ERROR", "WARNING", "INFO",
40 | "DEBUG", "DEBUG2"
41 | };
42 |
43 | static void rtmp_log_default(int level, const char *format, va_list vl)
44 | {
45 | char str[MAX_PRINT_LEN]="";
46 |
47 | vsnprintf(str, MAX_PRINT_LEN-1, format, vl);
48 |
49 | /* Filter out 'no-name' */
50 | if ( RTMP_debuglevel RTMP_debuglevel )
105 | return;
106 |
107 | ptr = line;
108 |
109 | for(i=0; i> 4)];
112 | *ptr++ = hexdig[0x0f & data[i]];
113 | if ((i & 0x0f) == 0x0f)
114 | {
115 | *ptr = '\0';
116 | ptr = line;
117 | RTMP_Log(level, "%s", line);
118 | }
119 | else
120 | {
121 | *ptr++ = ' ';
122 | }
123 | }
124 | if (i & 0x0f)
125 | {
126 | *ptr = '\0';
127 | RTMP_Log(level, "%s", line);
128 | }
129 | }
130 |
131 | void RTMP_LogHexString(int level, const uint8_t *data, unsigned long len)
132 | {
133 | #define BP_OFFSET 9
134 | #define BP_GRAPH 60
135 | #define BP_LEN 80
136 | char line[BP_LEN];
137 | unsigned long i;
138 |
139 | if ( !data || level > RTMP_debuglevel )
140 | return;
141 |
142 | /* in case len is zero */
143 | line[0] = '\0';
144 |
145 | for ( i = 0 ; i < len ; i++ )
146 | {
147 | int n = i % 16;
148 | unsigned off;
149 |
150 | if( !n )
151 | {
152 | if( i ) RTMP_Log( level, "%s", line );
153 | memset( line, ' ', sizeof(line)-2 );
154 | line[sizeof(line)-2] = '\0';
155 |
156 | off = i % 0x0ffffU;
157 |
158 | line[2] = hexdig[0x0f & (off >> 12)];
159 | line[3] = hexdig[0x0f & (off >> 8)];
160 | line[4] = hexdig[0x0f & (off >> 4)];
161 | line[5] = hexdig[0x0f & off];
162 | line[6] = ':';
163 | }
164 |
165 | off = BP_OFFSET + n*3 + ((n >= 8)?1:0);
166 | line[off] = hexdig[0x0f & ( data[i] >> 4 )];
167 | line[off+1] = hexdig[0x0f & data[i]];
168 |
169 | off = BP_GRAPH + n + ((n >= 8)?1:0);
170 |
171 | if ( isprint( data[i] ))
172 | {
173 | line[BP_GRAPH + n] = data[i];
174 | }
175 | else
176 | {
177 | line[BP_GRAPH + n] = '.';
178 | }
179 | }
180 |
181 | RTMP_Log( level, "%s", line );
182 | }
183 |
184 | /* These should only be used by apps, never by the library itself */
185 | void RTMP_LogPrintf(const char *format, ...)
186 | {
187 | char str[MAX_PRINT_LEN]="";
188 | int len;
189 | va_list args;
190 | va_start(args, format);
191 | len = vsnprintf(str, MAX_PRINT_LEN-1, format, args);
192 | va_end(args);
193 |
194 | if ( RTMP_debuglevel==RTMP_LOGCRIT )
195 | return;
196 |
197 | if ( !fmsg ) fmsg = stderr;
198 |
199 | if (neednl)
200 | {
201 | putc('\n', fmsg);
202 | neednl = 0;
203 | }
204 |
205 | if (len > MAX_PRINT_LEN-1)
206 | len = MAX_PRINT_LEN-1;
207 | fprintf(fmsg, "%s", str);
208 | if (str[len-1] == '\n')
209 | fflush(fmsg);
210 | }
211 |
212 | void RTMP_LogStatus(const char *format, ...)
213 | {
214 | char str[MAX_PRINT_LEN]="";
215 | va_list args;
216 | va_start(args, format);
217 | vsnprintf(str, MAX_PRINT_LEN-1, format, args);
218 | va_end(args);
219 |
220 | if ( RTMP_debuglevel==RTMP_LOGCRIT )
221 | return;
222 |
223 | if ( !fmsg ) fmsg = stderr;
224 |
225 | fprintf(fmsg, "%s", str);
226 | fflush(fmsg);
227 | neednl = 1;
228 | }
229 |
--------------------------------------------------------------------------------
/librtmp/log.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008-2009 Andrej Stepanchuk
3 | * Copyright (C) 2009-2010 Howard Chu
4 | *
5 | * This file is part of librtmp.
6 | *
7 | * librtmp is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1,
10 | * or (at your option) any later version.
11 | *
12 | * librtmp is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public License
18 | * along with librtmp see the file COPYING. If not, write to
19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 | * Boston, MA 02110-1301, USA.
21 | * http://www.gnu.org/copyleft/lgpl.html
22 | */
23 |
24 | #ifndef __RTMP_LOG_H__
25 | #define __RTMP_LOG_H__
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 | /* Enable this to get full debugging output */
31 | /* #define _DEBUG */
32 |
33 | #ifdef _DEBUG
34 | #undef NODEBUG
35 | #endif
36 |
37 | typedef enum
38 | {
39 | RTMP_LOGCRIT=0, RTMP_LOGERROR, RTMP_LOGWARNING, RTMP_LOGINFO,
40 | RTMP_LOGDEBUG, RTMP_LOGDEBUG2, RTMP_LOGALL
41 | }
42 | RTMP_LogLevel;
43 |
44 | extern RTMP_LogLevel RTMP_debuglevel;
45 |
46 | typedef void (RTMP_LogCallback)(int level, const char *fmt, va_list);
47 | void RTMP_LogSetCallback(RTMP_LogCallback *cb);
48 | void RTMP_LogSetOutput(FILE *file);
49 | #ifdef __GNUC__
50 | void RTMP_LogPrintf(const char *format, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
51 | void RTMP_LogStatus(const char *format, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
52 | void RTMP_Log(int level, const char *format, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
53 | #else
54 | void RTMP_LogPrintf(const char *format, ...);
55 | void RTMP_LogStatus(const char *format, ...);
56 | void RTMP_Log(int level, const char *format, ...);
57 | #endif
58 | void RTMP_LogHex(int level, const uint8_t *data, unsigned long len);
59 | void RTMP_LogHexString(int level, const uint8_t *data, unsigned long len);
60 | void RTMP_LogSetLevel(RTMP_LogLevel lvl);
61 | RTMP_LogLevel RTMP_LogGetLevel(void);
62 |
63 | #ifdef __cplusplus
64 | }
65 | #endif
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/librtmp/md5.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
3 | * MD5 Message-Digest Algorithm (RFC 1321).
4 | *
5 | * Homepage:
6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
7 | *
8 | * Author:
9 | * Alexander Peslyak, better known as Solar Designer
10 | *
11 | * This software was written by Alexander Peslyak in 2001. No copyright is
12 | * claimed, and the software is hereby placed in the public domain.
13 | * In case this attempt to disclaim copyright and place the software in the
14 | * public domain is deemed null and void, then the software is
15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
16 | * general public under the following terms:
17 | *
18 | * Redistribution and use in source and binary forms, with or without
19 | * modification, are permitted.
20 | *
21 | * There's ABSOLUTELY NO WARRANTY, express or implied.
22 | *
23 | * (This is a heavily cut-down "BSD license".)
24 | *
25 | * This differs from Colin Plumb's older public domain implementation in that
26 | * no exactly 32-bit integer data type is required (any 32-bit or wider
27 | * unsigned integer data type will do), there's no compile-time endianness
28 | * configuration, and the function prototypes match OpenSSL's. No code from
29 | * Colin Plumb's implementation has been reused; this comment merely compares
30 | * the properties of the two independent implementations.
31 | *
32 | * The primary goals of this implementation are portability and ease of use.
33 | * It is meant to be fast, but not as fast as possible. Some known
34 | * optimizations are not included to reduce source code size and avoid
35 | * compile-time configuration.
36 | */
37 |
38 | #ifndef HAVE_OPENSSL
39 |
40 | #include
41 |
42 | #include "md5.h"
43 |
44 | /*
45 | * The basic MD5 functions.
46 | *
47 | * F and G are optimized compared to their RFC 1321 definitions for
48 | * architectures that lack an AND-NOT instruction, just like in Colin Plumb's
49 | * implementation.
50 | */
51 | #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
52 | #define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
53 | #define H(x, y, z) ((x) ^ (y) ^ (z))
54 | #define I(x, y, z) ((y) ^ ((x) | ~(z)))
55 |
56 | /*
57 | * The MD5 transformation for all four rounds.
58 | */
59 | #define STEP(f, a, b, c, d, x, t, s) \
60 | (a) += f((b), (c), (d)) + (x) + (t); \
61 | (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
62 | (a) += (b);
63 |
64 | /*
65 | * SET reads 4 input bytes in little-endian byte order and stores them
66 | * in a properly aligned word in host byte order.
67 | *
68 | * The check for little-endian architectures that tolerate unaligned
69 | * memory accesses is just an optimization. Nothing will break if it
70 | * doesn't work.
71 | */
72 | #if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
73 | #define SET(n) \
74 | (*(MD5_u32plus *)&ptr[(n) * 4])
75 | #define GET(n) \
76 | SET(n)
77 | #else
78 | #define SET(n) \
79 | (ctx->block[(n)] = \
80 | (MD5_u32plus)ptr[(n) * 4] | \
81 | ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
82 | ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
83 | ((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
84 | #define GET(n) \
85 | (ctx->block[(n)])
86 | #endif
87 |
88 | /*
89 | * This processes one or more 64-byte data blocks, but does NOT update
90 | * the bit counters. There are no alignment requirements.
91 | */
92 | static void *body(MD5_CTX *ctx, void *data, unsigned long size)
93 | {
94 | unsigned char *ptr;
95 | MD5_u32plus a, b, c, d;
96 | MD5_u32plus saved_a, saved_b, saved_c, saved_d;
97 |
98 | ptr = data;
99 |
100 | a = ctx->a;
101 | b = ctx->b;
102 | c = ctx->c;
103 | d = ctx->d;
104 |
105 | do {
106 | saved_a = a;
107 | saved_b = b;
108 | saved_c = c;
109 | saved_d = d;
110 |
111 | /* Round 1 */
112 | STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
113 | STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
114 | STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
115 | STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
116 | STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
117 | STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
118 | STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
119 | STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
120 | STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
121 | STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
122 | STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
123 | STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
124 | STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
125 | STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
126 | STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
127 | STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
128 |
129 | /* Round 2 */
130 | STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
131 | STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
132 | STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
133 | STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
134 | STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
135 | STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
136 | STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
137 | STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
138 | STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
139 | STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
140 | STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
141 | STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
142 | STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
143 | STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
144 | STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
145 | STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
146 |
147 | /* Round 3 */
148 | STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
149 | STEP(H, d, a, b, c, GET(8), 0x8771f681, 11)
150 | STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
151 | STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23)
152 | STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
153 | STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11)
154 | STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
155 | STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23)
156 | STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
157 | STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11)
158 | STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
159 | STEP(H, b, c, d, a, GET(6), 0x04881d05, 23)
160 | STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
161 | STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11)
162 | STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
163 | STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23)
164 |
165 | /* Round 4 */
166 | STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
167 | STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
168 | STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
169 | STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
170 | STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
171 | STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
172 | STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
173 | STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
174 | STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
175 | STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
176 | STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
177 | STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
178 | STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
179 | STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
180 | STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
181 | STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
182 |
183 | a += saved_a;
184 | b += saved_b;
185 | c += saved_c;
186 | d += saved_d;
187 |
188 | ptr += 64;
189 | } while (size -= 64);
190 |
191 | ctx->a = a;
192 | ctx->b = b;
193 | ctx->c = c;
194 | ctx->d = d;
195 |
196 | return ptr;
197 | }
198 |
199 | void MD5_Init(MD5_CTX *ctx)
200 | {
201 | ctx->a = 0x67452301;
202 | ctx->b = 0xefcdab89;
203 | ctx->c = 0x98badcfe;
204 | ctx->d = 0x10325476;
205 |
206 | ctx->lo = 0;
207 | ctx->hi = 0;
208 | }
209 |
210 | void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size)
211 | {
212 | MD5_u32plus saved_lo;
213 | unsigned long used, free;
214 |
215 | saved_lo = ctx->lo;
216 | if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
217 | ctx->hi++;
218 | ctx->hi += size >> 29;
219 |
220 | used = saved_lo & 0x3f;
221 |
222 | if (used) {
223 | free = 64 - used;
224 |
225 | if (size < free) {
226 | memcpy(&ctx->buffer[used], data, size);
227 | return;
228 | }
229 |
230 | memcpy(&ctx->buffer[used], data, free);
231 | data = (unsigned char *)data + free;
232 | size -= free;
233 | body(ctx, ctx->buffer, 64);
234 | }
235 |
236 | if (size >= 64) {
237 | data = body(ctx, data, size & ~(unsigned long)0x3f);
238 | size &= 0x3f;
239 | }
240 |
241 | memcpy(ctx->buffer, data, size);
242 | }
243 |
244 | void MD5_Final(unsigned char *result, MD5_CTX *ctx)
245 | {
246 | unsigned long used, free;
247 |
248 | used = ctx->lo & 0x3f;
249 |
250 | ctx->buffer[used++] = 0x80;
251 |
252 | free = 64 - used;
253 |
254 | if (free < 8) {
255 | memset(&ctx->buffer[used], 0, free);
256 | body(ctx, ctx->buffer, 64);
257 | used = 0;
258 | free = 64;
259 | }
260 |
261 | memset(&ctx->buffer[used], 0, free - 8);
262 |
263 | ctx->lo <<= 3;
264 | ctx->buffer[56] = ctx->lo;
265 | ctx->buffer[57] = ctx->lo >> 8;
266 | ctx->buffer[58] = ctx->lo >> 16;
267 | ctx->buffer[59] = ctx->lo >> 24;
268 | ctx->buffer[60] = ctx->hi;
269 | ctx->buffer[61] = ctx->hi >> 8;
270 | ctx->buffer[62] = ctx->hi >> 16;
271 | ctx->buffer[63] = ctx->hi >> 24;
272 |
273 | body(ctx, ctx->buffer, 64);
274 |
275 | result[0] = ctx->a;
276 | result[1] = ctx->a >> 8;
277 | result[2] = ctx->a >> 16;
278 | result[3] = ctx->a >> 24;
279 | result[4] = ctx->b;
280 | result[5] = ctx->b >> 8;
281 | result[6] = ctx->b >> 16;
282 | result[7] = ctx->b >> 24;
283 | result[8] = ctx->c;
284 | result[9] = ctx->c >> 8;
285 | result[10] = ctx->c >> 16;
286 | result[11] = ctx->c >> 24;
287 | result[12] = ctx->d;
288 | result[13] = ctx->d >> 8;
289 | result[14] = ctx->d >> 16;
290 | result[15] = ctx->d >> 24;
291 |
292 | memset(ctx, 0, sizeof(*ctx));
293 | }
294 |
295 | #endif
296 |
--------------------------------------------------------------------------------
/librtmp/md5.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
3 | * MD5 Message-Digest Algorithm (RFC 1321).
4 | *
5 | * Homepage:
6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
7 | *
8 | * Author:
9 | * Alexander Peslyak, better known as Solar Designer
10 | *
11 | * This software was written by Alexander Peslyak in 2001. No copyright is
12 | * claimed, and the software is hereby placed in the public domain.
13 | * In case this attempt to disclaim copyright and place the software in the
14 | * public domain is deemed null and void, then the software is
15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
16 | * general public under the following terms:
17 | *
18 | * Redistribution and use in source and binary forms, with or without
19 | * modification, are permitted.
20 | *
21 | * There's ABSOLUTELY NO WARRANTY, express or implied.
22 | *
23 | * See md5.c for more information.
24 | */
25 |
26 | #ifdef HAVE_OPENSSL
27 | #include
28 | #elif !defined(_MD5_H)
29 | #define _MD5_H
30 |
31 | /* Any 32-bit or wider unsigned integer data type will do */
32 | typedef unsigned int MD5_u32plus;
33 |
34 | typedef struct {
35 | MD5_u32plus lo, hi;
36 | MD5_u32plus a, b, c, d;
37 | unsigned char buffer[64];
38 | MD5_u32plus block[16];
39 | } MD5_CTX;
40 |
41 | extern void MD5_Init(MD5_CTX *ctx);
42 | extern void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size);
43 | extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/librtmp/parseurl.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 Andrej Stepanchuk
3 | * Copyright (C) 2009-2010 Howard Chu
4 | *
5 | * This file is part of librtmp.
6 | *
7 | * librtmp is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1,
10 | * or (at your option) any later version.
11 | *
12 | * librtmp is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public License
18 | * along with librtmp see the file COPYING. If not, write to
19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 | * Boston, MA 02110-1301, USA.
21 | * http://www.gnu.org/copyleft/lgpl.html
22 | */
23 |
24 | #include "rtmp_sys.h"
25 | #include "log.h"
26 |
27 | int RTMP_ParseURL(const char *url, int *protocol, AVal *host, unsigned int *port,
28 | AVal *playpath, AVal *app)
29 | {
30 | char *p, *end, *col, *ques, *slash;
31 |
32 | RTMP_Log(RTMP_LOGDEBUG, "Parsing...");
33 |
34 | *protocol = RTMP_PROTOCOL_RTMP;
35 | *port = 0;
36 | playpath->av_len = 0;
37 | playpath->av_val = NULL;
38 | app->av_len = 0;
39 | app->av_val = NULL;
40 |
41 | /* Old School Parsing */
42 |
43 | /* look for usual :// pattern */
44 | p = strstr(url, "://");
45 | if(!p)
46 | {
47 | RTMP_Log(RTMP_LOGERROR, "RTMP URL: No :// in url!");
48 | return FALSE;
49 | }
50 | {
51 | int len = (int)(p-url);
52 |
53 | if(len == 4 && strncasecmp(url, "rtmp", 4)==0)
54 | *protocol = RTMP_PROTOCOL_RTMP;
55 | else if(len == 5 && strncasecmp(url, "rtmpt", 5)==0)
56 | *protocol = RTMP_PROTOCOL_RTMPT;
57 | else if(len == 5 && strncasecmp(url, "rtmps", 5)==0)
58 | *protocol = RTMP_PROTOCOL_RTMPS;
59 | else if(len == 5 && strncasecmp(url, "rtmpe", 5)==0)
60 | *protocol = RTMP_PROTOCOL_RTMPE;
61 | else if(len == 5 && strncasecmp(url, "rtmfp", 5)==0)
62 | *protocol = RTMP_PROTOCOL_RTMFP;
63 | else if(len == 6 && strncasecmp(url, "rtmpte", 6)==0)
64 | *protocol = RTMP_PROTOCOL_RTMPTE;
65 | else if(len == 6 && strncasecmp(url, "rtmpts", 6)==0)
66 | *protocol = RTMP_PROTOCOL_RTMPTS;
67 | else
68 | {
69 | RTMP_Log(RTMP_LOGWARNING, "Unknown protocol!\n");
70 | goto parsehost;
71 | }
72 | }
73 |
74 | RTMP_Log(RTMP_LOGDEBUG, "Parsed protocol: %d", *protocol);
75 |
76 | parsehost:
77 | /* let's get the hostname */
78 | p+=3;
79 |
80 | /* check for sudden death */
81 | if(*p==0)
82 | {
83 | RTMP_Log(RTMP_LOGWARNING, "No hostname in URL!");
84 | return FALSE;
85 | }
86 |
87 | end = p + strlen(p);
88 | col = strchr(p, ':');
89 | ques = strchr(p, '?');
90 | slash = strchr(p, '/');
91 |
92 | {
93 | int hostlen;
94 | if(slash)
95 | hostlen = slash - p;
96 | else
97 | hostlen = end - p;
98 | if(col && col -p < hostlen)
99 | hostlen = col - p;
100 |
101 | if(hostlen < 256)
102 | {
103 | host->av_val = p;
104 | host->av_len = hostlen;
105 | RTMP_Log(RTMP_LOGDEBUG, "Parsed host : %.*s", hostlen, host->av_val);
106 | }
107 | else
108 | {
109 | RTMP_Log(RTMP_LOGWARNING, "Hostname exceeds 255 characters!");
110 | }
111 |
112 | p+=hostlen;
113 | }
114 |
115 | /* get the port number if available */
116 | if(*p == ':')
117 | {
118 | unsigned int p2;
119 | p++;
120 | p2 = atoi(p);
121 | if(p2 > 65535)
122 | {
123 | RTMP_Log(RTMP_LOGWARNING, "Invalid port number!");
124 | }
125 | else
126 | {
127 | *port = p2;
128 | }
129 | }
130 |
131 | if(!slash)
132 | {
133 | RTMP_Log(RTMP_LOGWARNING, "No application or playpath in URL!");
134 | return TRUE;
135 | }
136 | p = slash+1;
137 |
138 | {
139 | /* parse application
140 | *
141 | * rtmp://host[:port]/app[/appinstance][/...]
142 | * application = app[/appinstance]
143 | */
144 |
145 | char *slash2, *slash3 = NULL, *slash4 = NULL;
146 | int applen, appnamelen;
147 |
148 | slash2 = strchr(p, '/');
149 | if(slash2)
150 | slash3 = strchr(slash2+1, '/');
151 | if(slash3)
152 | slash4 = strchr(slash3+1, '/');
153 |
154 | applen = end-p; /* ondemand, pass all parameters as app */
155 | appnamelen = applen; /* ondemand length */
156 |
157 | if(ques && strstr(p, "slist=")) /* whatever it is, the '?' and slist= means we need to use everything as app and parse plapath from slist= */
158 | {
159 | appnamelen = ques-p;
160 | }
161 | else if(strncmp(p, "ondemand/", 9)==0)
162 | {
163 | /* app = ondemand/foobar, only pass app=ondemand */
164 | applen = 8;
165 | appnamelen = 8;
166 | }
167 | else /* app!=ondemand, so app is app[/appinstance] */
168 | {
169 | if(slash4)
170 | appnamelen = slash4-p;
171 | else if(slash3)
172 | appnamelen = slash3-p;
173 | else if(slash2)
174 | appnamelen = slash2-p;
175 |
176 | applen = appnamelen;
177 | }
178 |
179 | app->av_val = p;
180 | app->av_len = applen;
181 | RTMP_Log(RTMP_LOGDEBUG, "Parsed app : %.*s", applen, p);
182 |
183 | p += appnamelen;
184 | }
185 |
186 | if (*p == '/')
187 | p++;
188 |
189 | if (end-p)
190 | {
191 | AVal av = {p, end-p};
192 | RTMP_ParsePlaypath(&av, playpath);
193 | }
194 |
195 | return TRUE;
196 | }
197 |
198 | int RTMP_ParseURL2(const char *url, int *protocol, AVal *host, unsigned int *port,
199 | AVal *app)
200 | {
201 | char *p, *end, *col, *ques, *slash;
202 |
203 | RTMP_Log(RTMP_LOGDEBUG, "Parsing...");
204 |
205 | *protocol = RTMP_PROTOCOL_RTMP;
206 | *port = 0;
207 | app->av_len = 0;
208 | app->av_val = NULL;
209 |
210 | /* Old School Parsing */
211 |
212 | /* look for usual :// pattern */
213 | p = strstr(url, "://");
214 | if(!p)
215 | {
216 | RTMP_Log(RTMP_LOGERROR, "RTMP URL: No :// in url!");
217 | return FALSE;
218 | }
219 | {
220 | int len = (int)(p-url);
221 |
222 | if(len == 4 && strncasecmp(url, "rtmp", 4)==0)
223 | *protocol = RTMP_PROTOCOL_RTMP;
224 | else if(len == 5 && strncasecmp(url, "rtmpt", 5)==0)
225 | *protocol = RTMP_PROTOCOL_RTMPT;
226 | else if(len == 5 && strncasecmp(url, "rtmps", 5)==0)
227 | *protocol = RTMP_PROTOCOL_RTMPS;
228 | else if(len == 5 && strncasecmp(url, "rtmpe", 5)==0)
229 | *protocol = RTMP_PROTOCOL_RTMPE;
230 | else if(len == 5 && strncasecmp(url, "rtmfp", 5)==0)
231 | *protocol = RTMP_PROTOCOL_RTMFP;
232 | else if(len == 6 && strncasecmp(url, "rtmpte", 6)==0)
233 | *protocol = RTMP_PROTOCOL_RTMPTE;
234 | else if(len == 6 && strncasecmp(url, "rtmpts", 6)==0)
235 | *protocol = RTMP_PROTOCOL_RTMPTS;
236 | else
237 | {
238 | RTMP_Log(RTMP_LOGWARNING, "Unknown protocol!\n");
239 | goto parsehost;
240 | }
241 | }
242 |
243 | RTMP_Log(RTMP_LOGDEBUG, "Parsed protocol: %d", *protocol);
244 |
245 | parsehost:
246 | /* let's get the hostname */
247 | p+=3;
248 |
249 | /* check for sudden death */
250 | if(*p==0)
251 | {
252 | RTMP_Log(RTMP_LOGWARNING, "No hostname in URL!");
253 | return FALSE;
254 | }
255 |
256 | end = p + strlen(p);
257 | col = strchr(p, ':');
258 | ques = strchr(p, '?');
259 | slash = strchr(p, '/');
260 |
261 | {
262 | int hostlen;
263 | if(slash)
264 | hostlen = slash - p;
265 | else
266 | hostlen = end - p;
267 | if(col && col -p < hostlen)
268 | hostlen = col - p;
269 |
270 | if(hostlen < 256)
271 | {
272 | host->av_val = p;
273 | host->av_len = hostlen;
274 | RTMP_Log(RTMP_LOGDEBUG, "Parsed host : %.*s", hostlen, host->av_val);
275 | }
276 | else
277 | {
278 | RTMP_Log(RTMP_LOGWARNING, "Hostname exceeds 255 characters!");
279 | }
280 |
281 | p+=hostlen;
282 | }
283 |
284 | /* get the port number if available */
285 | if(*p == ':')
286 | {
287 | unsigned int p2;
288 | p++;
289 | p2 = atoi(p);
290 | if(p2 > 65535)
291 | {
292 | RTMP_Log(RTMP_LOGWARNING, "Invalid port number!");
293 | }
294 | else
295 | {
296 | *port = p2;
297 | }
298 | }
299 |
300 | if(!slash)
301 | {
302 | RTMP_Log(RTMP_LOGWARNING, "No application or playpath in URL!");
303 | return TRUE;
304 | }
305 | p = slash+1;
306 |
307 | //just.. whatever.
308 | app->av_val = p;
309 | app->av_len = (int)strlen(p);
310 |
311 | if(app->av_len && p[app->av_len-1] == '/')
312 | app->av_len--;
313 |
314 | RTMP_Log(RTMP_LOGDEBUG, "Parsed app : %.*s", app->av_len, p);
315 | p += app->av_len;
316 |
317 | if (*p == '/')
318 | p++;
319 |
320 | return TRUE;
321 | }
322 |
323 | /*
324 | * Extracts playpath from RTMP URL. playpath is the file part of the
325 | * URL, i.e. the part that comes after rtmp://host:port/app/
326 | *
327 | * Returns the stream name in a format understood by FMS. The name is
328 | * the playpath part of the URL with formatting depending on the stream
329 | * type:
330 | *
331 | * mp4 streams: prepend "mp4:", remove extension
332 | * mp3 streams: prepend "mp3:", remove extension
333 | * flv streams: remove extension
334 | */
335 | void RTMP_ParsePlaypath(AVal *in, AVal *out)
336 | {
337 | int addMP4 = 0;
338 | int addMP3 = 0;
339 | int subExt = 0;
340 | const char *playpath = in->av_val;
341 | const char *temp, *q, *ext = NULL;
342 | const char *ppstart = playpath;
343 | char *streamname, *destptr, *p;
344 |
345 | int pplen = in->av_len;
346 |
347 | out->av_val = NULL;
348 | out->av_len = 0;
349 |
350 | if ((*ppstart == '?') &&
351 | (temp=strstr(ppstart, "slist=")) != 0)
352 | {
353 | ppstart = temp+6;
354 | pplen = (int)strlen(ppstart);
355 |
356 | temp = strchr(ppstart, '&');
357 | if (temp)
358 | {
359 | pplen = temp-ppstart;
360 | }
361 | }
362 |
363 | q = strchr(ppstart, '?');
364 | if (pplen >= 4)
365 | {
366 | if (q)
367 | ext = q-4;
368 | else
369 | ext = &ppstart[pplen-4];
370 | if ((strncmp(ext, ".f4v", 4) == 0) ||
371 | (strncmp(ext, ".mp4", 4) == 0))
372 | {
373 | addMP4 = 1;
374 | subExt = 1;
375 | /* Only remove .flv from rtmp URL, not slist params */
376 | }
377 | else if ((ppstart == playpath) &&
378 | (strncmp(ext, ".flv", 4) == 0))
379 | {
380 | subExt = 1;
381 | }
382 | else if (strncmp(ext, ".mp3", 4) == 0)
383 | {
384 | addMP3 = 1;
385 | subExt = 1;
386 | }
387 | }
388 |
389 | streamname = (char *)malloc((pplen+4+1)*sizeof(char));
390 | if (!streamname)
391 | return;
392 |
393 | destptr = streamname;
394 | if (addMP4)
395 | {
396 | if (strncmp(ppstart, "mp4:", 4))
397 | {
398 | strcpy(destptr, "mp4:");
399 | destptr += 4;
400 | }
401 | else
402 | {
403 | subExt = 0;
404 | }
405 | }
406 | else if (addMP3)
407 | {
408 | if (strncmp(ppstart, "mp3:", 4))
409 | {
410 | strcpy(destptr, "mp3:");
411 | destptr += 4;
412 | }
413 | else
414 | {
415 | subExt = 0;
416 | }
417 | }
418 |
419 | for (p=(char *)ppstart; pplen >0;)
420 | {
421 | /* skip extension */
422 | if (subExt && p == ext)
423 | {
424 | p += 4;
425 | pplen -= 4;
426 | continue;
427 | }
428 | if (*p == '%')
429 | {
430 | unsigned int c;
431 | sscanf(p+1, "%02x", &c);
432 | *destptr++ = c;
433 | pplen -= 3;
434 | p += 3;
435 | }
436 | else
437 | {
438 | *destptr++ = *p++;
439 | pplen--;
440 | }
441 | }
442 | *destptr = '\0';
443 |
444 | out->av_val = streamname;
445 | out->av_len = destptr - streamname;
446 | }
447 |
--------------------------------------------------------------------------------
/librtmp/rtmp.h:
--------------------------------------------------------------------------------
1 | #ifndef __RTMP_H__
2 | #define __RTMP_H__
3 | /*
4 | * Copyright (C) 2005-2008 Team XBMC
5 | * http://www.xbmc.org
6 | * Copyright (C) 2008-2009 Andrej Stepanchuk
7 | * Copyright (C) 2009-2010 Howard Chu
8 | *
9 | * This file is part of librtmp.
10 | *
11 | * librtmp is free software; you can redistribute it and/or modify
12 | * it under the terms of the GNU Lesser General Public License as
13 | * published by the Free Software Foundation; either version 2.1,
14 | * or (at your option) any later version.
15 | *
16 | * librtmp is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU Lesser General Public License
22 | * along with librtmp see the file COPYING. If not, write to
23 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 | * Boston, MA 02110-1301, USA.
25 | * http://www.gnu.org/copyleft/lgpl.html
26 | */
27 |
28 | #define NO_CRYPTO 1
29 |
30 | #if !defined(NO_CRYPTO) && !defined(CRYPTO)
31 | #define CRYPTO
32 | #else
33 | #include //for off_t
34 | #endif
35 |
36 | #pragma warning(disable:4996) //depricated warnings
37 | #pragma warning(disable:4244) //64bit defensive mechanism, fixed the ones that mattered
38 |
39 | #include "amf.h"
40 |
41 | #ifdef __cplusplus
42 | extern "C"
43 | {
44 | #endif
45 |
46 | #define RTMP_LIB_VERSION 0x020300 /* 2.3 */
47 |
48 | #define RTMP_FEATURE_HTTP 0x01
49 | #define RTMP_FEATURE_ENC 0x02
50 | #define RTMP_FEATURE_SSL 0x04
51 | #define RTMP_FEATURE_MFP 0x08 /* not yet supported */
52 | #define RTMP_FEATURE_WRITE 0x10 /* publish, not play */
53 | #define RTMP_FEATURE_HTTP2 0x20 /* server-side rtmpt */
54 |
55 | #define RTMP_PROTOCOL_UNDEFINED -1
56 | #define RTMP_PROTOCOL_RTMP 0
57 | #define RTMP_PROTOCOL_RTMPE RTMP_FEATURE_ENC
58 | #define RTMP_PROTOCOL_RTMPT RTMP_FEATURE_HTTP
59 | #define RTMP_PROTOCOL_RTMPS RTMP_FEATURE_SSL
60 | #define RTMP_PROTOCOL_RTMPTE (RTMP_FEATURE_HTTP|RTMP_FEATURE_ENC)
61 | #define RTMP_PROTOCOL_RTMPTS (RTMP_FEATURE_HTTP|RTMP_FEATURE_SSL)
62 | #define RTMP_PROTOCOL_RTMFP RTMP_FEATURE_MFP
63 |
64 | #define RTMP_DEFAULT_CHUNKSIZE 128
65 |
66 | /* needs to fit largest number of bytes recv() may return */
67 | #define RTMP_BUFFER_CACHE_SIZE (16*1024)
68 |
69 | #define RTMP_CHANNELS 65600
70 |
71 | extern const char RTMPProtocolStringsLower[][7];
72 | extern const AVal RTMP_DefaultFlashVer;
73 | extern int RTMP_ctrlC;
74 |
75 | uint32_t RTMP_GetTime(void);
76 |
77 | /* RTMP_PACKET_TYPE_... 0x00 */
78 | #define RTMP_PACKET_TYPE_CHUNK_SIZE 0x01
79 | /* RTMP_PACKET_TYPE_... 0x02 */
80 | #define RTMP_PACKET_TYPE_BYTES_READ_REPORT 0x03
81 | #define RTMP_PACKET_TYPE_CONTROL 0x04
82 | #define RTMP_PACKET_TYPE_SERVER_BW 0x05
83 | #define RTMP_PACKET_TYPE_CLIENT_BW 0x06
84 | /* RTMP_PACKET_TYPE_... 0x07 */
85 | #define RTMP_PACKET_TYPE_AUDIO 0x08
86 | #define RTMP_PACKET_TYPE_VIDEO 0x09
87 | /* RTMP_PACKET_TYPE_... 0x0A */
88 | /* RTMP_PACKET_TYPE_... 0x0B */
89 | /* RTMP_PACKET_TYPE_... 0x0C */
90 | /* RTMP_PACKET_TYPE_... 0x0D */
91 | /* RTMP_PACKET_TYPE_... 0x0E */
92 | #define RTMP_PACKET_TYPE_FLEX_STREAM_SEND 0x0F
93 | #define RTMP_PACKET_TYPE_FLEX_SHARED_OBJECT 0x10
94 | #define RTMP_PACKET_TYPE_FLEX_MESSAGE 0x11
95 | #define RTMP_PACKET_TYPE_INFO 0x12
96 | #define RTMP_PACKET_TYPE_SHARED_OBJECT 0x13
97 | #define RTMP_PACKET_TYPE_INVOKE 0x14
98 | /* RTMP_PACKET_TYPE_... 0x15 */
99 | #define RTMP_PACKET_TYPE_FLASH_VIDEO 0x16
100 |
101 | #define RTMP_MAX_HEADER_SIZE 18
102 |
103 | #define RTMP_PACKET_SIZE_LARGE 0
104 | #define RTMP_PACKET_SIZE_MEDIUM 1
105 | #define RTMP_PACKET_SIZE_SMALL 2
106 | #define RTMP_PACKET_SIZE_MINIMUM 3
107 |
108 | typedef struct RTMPChunk
109 | {
110 | int c_headerSize;
111 | int c_chunkSize;
112 | char *c_chunk;
113 | char c_header[RTMP_MAX_HEADER_SIZE];
114 | } RTMPChunk;
115 |
116 | typedef struct RTMPPacket
117 | {
118 | uint8_t m_headerType;
119 | uint8_t m_packetType;
120 | uint8_t m_hasAbsTimestamp; /* timestamp absolute or relative? */
121 | int m_nChannel;
122 | uint32_t m_nTimeStamp; /* timestamp */
123 | int32_t m_nInfoField2; /* last 4 bytes in a long header */
124 | uint32_t m_nBodySize;
125 | uint32_t m_nBytesRead;
126 | RTMPChunk *m_chunk;
127 | char *m_body;
128 | } RTMPPacket;
129 |
130 | typedef struct RTMPSockBuf
131 | {
132 | SOCKET sb_socket;
133 | int sb_size; /* number of unprocessed bytes in buffer */
134 | char *sb_start; /* pointer into sb_pBuffer of next byte to process */
135 | char sb_buf[RTMP_BUFFER_CACHE_SIZE]; /* data read from socket */
136 | int sb_timedout;
137 | void *sb_ssl;
138 | } RTMPSockBuf;
139 |
140 | void RTMPPacket_Reset(RTMPPacket *p);
141 | void RTMPPacket_Dump(RTMPPacket *p);
142 | int RTMPPacket_Alloc(RTMPPacket *p, int nSize);
143 | void RTMPPacket_Free(RTMPPacket *p);
144 |
145 | #define RTMPPacket_IsReady(a) ((a)->m_nBytesRead == (a)->m_nBodySize)
146 |
147 | typedef struct RTMP_LNK
148 | {
149 | AVal hostname;
150 | AVal sockshost;
151 |
152 | AVal playpath0; /* parsed from URL */
153 | AVal playpath; /* passed in explicitly */
154 | AVal tcUrl;
155 | AVal swfUrl;
156 | AVal pageUrl;
157 | AVal app;
158 | AVal auth;
159 | AVal flashVer;
160 | AVal subscribepath;
161 | AVal usherToken;
162 | AVal token;
163 | AVal pubUser;
164 | AVal pubPasswd;
165 | AMFObject extras;
166 | int edepth;
167 |
168 | int seekTime;
169 | int stopTime;
170 |
171 | #define RTMP_LF_AUTH 0x0001 /* using auth param */
172 | #define RTMP_LF_LIVE 0x0002 /* stream is live */
173 | #define RTMP_LF_SWFV 0x0004 /* do SWF verification */
174 | #define RTMP_LF_PLST 0x0008 /* send playlist before play */
175 | #define RTMP_LF_BUFX 0x0010 /* toggle stream on BufferEmpty msg */
176 | #define RTMP_LF_FTCU 0x0020 /* free tcUrl on close */
177 | int lFlags;
178 |
179 | int swfAge;
180 |
181 | int protocol;
182 | int timeout; /* connection timeout in seconds */
183 |
184 | #define RTMP_PUB_NAME 0x0001 /* send login to server */
185 | #define RTMP_PUB_RESP 0x0002 /* send salted password hash */
186 | #define RTMP_PUB_ALLOC 0x0004 /* allocated data for new tcUrl & app */
187 | #define RTMP_PUB_CLEAN 0x0008 /* need to free allocated data for newer tcUrl & app at exit */
188 | #define RTMP_PUB_CLATE 0x0010 /* late clean tcUrl & app at exit */
189 | int pFlags;
190 |
191 | unsigned short socksport;
192 | unsigned short port;
193 |
194 | #ifdef CRYPTO
195 | #define RTMP_SWF_HASHLEN 32
196 | void *dh; /* for encryption */
197 | void *rc4keyIn;
198 | void *rc4keyOut;
199 |
200 | uint32_t SWFSize;
201 | uint8_t SWFHash[RTMP_SWF_HASHLEN];
202 | char SWFVerificationResponse[RTMP_SWF_HASHLEN+10];
203 | #endif
204 | } RTMP_LNK;
205 |
206 | /* state for read() wrapper */
207 | typedef struct RTMP_READ
208 | {
209 | char *buf;
210 | char *bufpos;
211 | unsigned int buflen;
212 | uint32_t timestamp;
213 | uint8_t dataType;
214 | uint8_t flags;
215 | #define RTMP_READ_HEADER 0x01
216 | #define RTMP_READ_RESUME 0x02
217 | #define RTMP_READ_NO_IGNORE 0x04
218 | #define RTMP_READ_GOTKF 0x08
219 | #define RTMP_READ_GOTFLVK 0x10
220 | #define RTMP_READ_SEEKING 0x20
221 | int8_t status;
222 | #define RTMP_READ_COMPLETE -3
223 | #define RTMP_READ_ERROR -2
224 | #define RTMP_READ_EOF -1
225 | #define RTMP_READ_IGNORE 0
226 |
227 | /* if bResume == TRUE */
228 | uint8_t initialFrameType;
229 | uint32_t nResumeTS;
230 | char *metaHeader;
231 | char *initialFrame;
232 | uint32_t nMetaHeaderSize;
233 | uint32_t nInitialFrameSize;
234 | uint32_t nIgnoredFrameCounter;
235 | uint32_t nIgnoredFlvFrameCounter;
236 | } RTMP_READ;
237 |
238 | typedef struct RTMP_METHOD
239 | {
240 | AVal name;
241 | int num;
242 | } RTMP_METHOD;
243 |
244 | typedef struct RTMP_BINDINFO
245 | {
246 | struct sockaddr_storage addr;
247 | int addrLen;
248 | } RTMP_BINDINFO;
249 |
250 | typedef int (*CUSTOMSEND)(RTMPSockBuf*, const char *, int, void*);
251 |
252 | typedef struct RTMP
253 | {
254 | int m_inChunkSize;
255 | int m_outChunkSize;
256 | int m_nBWCheckCounter;
257 | int m_nBytesIn;
258 | int m_nBytesInSent;
259 | int m_nBufferMS;
260 | int m_stream_id; /* returned in _result from createStream */
261 | int m_mediaChannel;
262 | uint32_t m_mediaStamp;
263 | uint32_t m_pauseStamp;
264 | int m_pausing;
265 | int m_nServerBW;
266 | int m_nClientBW;
267 | uint8_t m_nClientBW2;
268 | uint8_t m_bPlaying;
269 | uint8_t m_bSendEncoding;
270 | uint8_t m_bSendCounter;
271 |
272 | uint8_t m_bUseNagle;
273 | uint8_t m_bCustomSend;
274 | void* m_customSendParam;
275 | CUSTOMSEND m_customSendFunc;
276 |
277 | RTMP_BINDINFO m_bindIP;
278 |
279 | uint8_t m_bSendChunkSizeInfo;
280 |
281 | int m_numInvokes;
282 | int m_numCalls;
283 | RTMP_METHOD *m_methodCalls; /* remote method calls queue */
284 |
285 | int m_channelsAllocatedIn;
286 | int m_channelsAllocatedOut;
287 | RTMPPacket **m_vecChannelsIn;
288 | RTMPPacket **m_vecChannelsOut;
289 | int *m_channelTimestamp; /* abs timestamp of last packet */
290 |
291 | double m_fAudioCodecs; /* audioCodecs for the connect packet */
292 | double m_fVideoCodecs; /* videoCodecs for the connect packet */
293 | double m_fEncoding; /* AMF0 or AMF3 */
294 |
295 | double m_fDuration; /* duration of stream in seconds */
296 |
297 | int m_msgCounter; /* RTMPT stuff */
298 | int m_polling;
299 | int m_resplen;
300 | int m_unackd;
301 | AVal m_clientID;
302 |
303 | RTMP_READ m_read;
304 | RTMPPacket m_write;
305 | RTMPSockBuf m_sb;
306 | RTMP_LNK Link;
307 |
308 | int m_nBytesOut;
309 | } RTMP;
310 |
311 | int RTMP_ParseURL(const char *url, int *protocol, AVal *host,
312 | unsigned int *port, AVal *playpath, AVal *app);
313 |
314 | int RTMP_ParseURL2(const char *url, int *protocol, AVal *host,
315 | unsigned int *port, AVal *app);
316 |
317 | void RTMP_ParsePlaypath(AVal *in, AVal *out);
318 | void RTMP_SetBufferMS(RTMP *r, int size);
319 | void RTMP_UpdateBufferMS(RTMP *r);
320 |
321 | int RTMP_SetOpt(RTMP *r, const AVal *opt, AVal *arg);
322 | int RTMP_SetupURL(RTMP *r, char *url);
323 | int RTMP_SetupURL2(RTMP *r, char *url, char *playpath);
324 | void RTMP_SetupStream(RTMP *r, int protocol,
325 | AVal *hostname,
326 | unsigned int port,
327 | AVal *sockshost,
328 | AVal *playpath,
329 | AVal *tcUrl,
330 | AVal *swfUrl,
331 | AVal *pageUrl,
332 | AVal *app,
333 | AVal *auth,
334 | AVal *swfSHA256Hash,
335 | uint32_t swfSize,
336 | AVal *flashVer,
337 | AVal *subscribepath,
338 | AVal *usherToken,
339 | int dStart,
340 | int dStop, int bLiveStream, long int timeout);
341 |
342 | int RTMP_Connect(RTMP *r, RTMPPacket *cp);
343 | struct sockaddr;
344 | int RTMP_Connect0(RTMP *r, struct sockaddr *svc);
345 | int RTMP_Connect1(RTMP *r, RTMPPacket *cp);
346 | int RTMP_Serve(RTMP *r);
347 | int RTMP_TLS_Accept(RTMP *r, void *ctx);
348 |
349 | int RTMP_ReadPacket(RTMP *r, RTMPPacket *packet);
350 | int RTMP_SendPacket(RTMP *r, RTMPPacket *packet, int queue);
351 | int RTMP_SendChunk(RTMP *r, RTMPChunk *chunk);
352 | int RTMP_IsConnected(RTMP *r);
353 | SOCKET RTMP_Socket(RTMP *r);
354 | int RTMP_IsTimedout(RTMP *r);
355 | double RTMP_GetDuration(RTMP *r);
356 | int RTMP_ToggleStream(RTMP *r);
357 |
358 | int RTMP_ConnectStream(RTMP *r, int seekTime);
359 | int RTMP_ReconnectStream(RTMP *r, int seekTime);
360 | void RTMP_DeleteStream(RTMP *r);
361 | int RTMP_GetNextMediaPacket(RTMP *r, RTMPPacket *packet);
362 | int RTMP_ClientPacket(RTMP *r, RTMPPacket *packet);
363 |
364 | void RTMP_Init(RTMP *r);
365 | void RTMP_Close(RTMP *r);
366 | RTMP *RTMP_Alloc(void);
367 | void RTMP_Free(RTMP *r);
368 | void RTMP_EnableWrite(RTMP *r);
369 |
370 | void *RTMP_TLS_AllocServerContext(const char* cert, const char* key);
371 | void RTMP_TLS_FreeServerContext(void *ctx);
372 |
373 | int RTMP_LibVersion(void);
374 | void RTMP_UserInterrupt(void); /* user typed Ctrl-C */
375 |
376 | int RTMP_SendCtrl(RTMP *r, short nType, unsigned int nObject,
377 | unsigned int nTime);
378 |
379 | /* caller probably doesn't know current timestamp, should
380 | * just use RTMP_Pause instead
381 | */
382 | int RTMP_SendPause(RTMP *r, int DoPause, int dTime);
383 | int RTMP_Pause(RTMP *r, int DoPause);
384 |
385 | int RTMP_FindFirstMatchingProperty(AMFObject *obj, const AVal *name,
386 | AMFObjectProperty * p);
387 |
388 | int RTMPSockBuf_Fill(RTMPSockBuf *sb);
389 | int RTMPSockBuf_Send(RTMPSockBuf *sb, const char *buf, int len);
390 | int RTMPSockBuf_Close(RTMPSockBuf *sb);
391 |
392 | int RTMP_SendCreateStream(RTMP *r);
393 | int RTMP_SendSeek(RTMP *r, int dTime);
394 | int RTMP_SendServerBW(RTMP *r);
395 | int RTMP_SendClientBW(RTMP *r);
396 | void RTMP_DropRequest(RTMP *r, int i, int freeit);
397 | int RTMP_Read(RTMP *r, char *buf, int size);
398 | int RTMP_Write(RTMP *r, const char *buf, int size);
399 |
400 | /* hashswf.c */
401 | int RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash,
402 | int age);
403 |
404 | #ifdef __cplusplus
405 | };
406 | #endif
407 |
408 | #endif
409 |
--------------------------------------------------------------------------------
/librtmp/rtmp_sys.h:
--------------------------------------------------------------------------------
1 | #ifndef __RTMP_SYS_H__
2 | #define __RTMP_SYS_H__
3 | /*
4 | * Copyright (C) 2010 Howard Chu
5 | *
6 | * This file is part of librtmp.
7 | *
8 | * librtmp is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU Lesser General Public License as
10 | * published by the Free Software Foundation; either version 2.1,
11 | * or (at your option) any later version.
12 | *
13 | * librtmp is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public License
19 | * along with librtmp see the file COPYING. If not, write to
20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 | * Boston, MA 02110-1301, USA.
22 | * http://www.gnu.org/copyleft/lgpl.html
23 | */
24 |
25 | #ifdef _WIN32
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 |
38 | #include
39 | #include
40 | #include
41 |
42 | #include "stdint.h"
43 |
44 | #ifdef _MSC_VER /* MSVC */
45 | #define snprintf _snprintf
46 | #define strcasecmp stricmp
47 | #define strncasecmp strnicmp
48 | #define vsnprintf _vsnprintf
49 | #endif
50 |
51 | #define GetSockError() WSAGetLastError()
52 | #define SetSockError(e) WSASetLastError(e)
53 | #define setsockopt(a,b,c,d,e) (setsockopt)(a,b,c,(const char *)d,(int)e)
54 | #ifdef EWOULDBLOCK
55 | #undef EWOULDBLOCK
56 | #endif
57 | #define EWOULDBLOCK WSAETIMEDOUT /* we don't use nonblocking, but we do use timeouts */
58 | #define sleep(n) Sleep(n*1000)
59 | #define msleep(n) Sleep(n)
60 | #define SET_RCVTIMEO(tv,s) int tv = s*1000
61 | #else /* !_WIN32 */
62 | #include
63 | #include
64 | #include
65 | #include
66 | #include
67 | #include
68 | #include
69 | #include
70 | #define GetSockError() errno
71 | #define SetSockError(e) errno = e
72 | #undef closesocket
73 | #define closesocket(s) close(s)
74 | #define msleep(n) usleep(n*1000)
75 | #define SET_RCVTIMEO(tv,s) struct timeval tv = {s,0}
76 | #endif
77 |
78 | #include "rtmp.h"
79 |
80 | #ifdef USE_POLARSSL
81 | #include
82 | #include
83 | #include
84 | #include
85 | #if POLARSSL_VERSION_NUMBER < 0x01010000
86 | #define havege_random havege_rand
87 | #endif
88 | #if POLARSSL_VERSION_NUMBER >= 0x01020000
89 | #define SSL_SET_SESSION(S,resume,timeout,ctx) ssl_set_session(S,ctx)
90 | #else
91 | #define SSL_SET_SESSION(S,resume,timeout,ctx) ssl_set_session(S,resume,timeout,ctx)
92 | #endif
93 | typedef struct tls_ctx
94 | {
95 | havege_state hs;
96 | ssl_session ssn;
97 | } tls_ctx;
98 | typedef struct tls_server_ctx
99 | {
100 | havege_state *hs;
101 | x509_cert cert;
102 | rsa_context key;
103 | ssl_session ssn;
104 | const char *dhm_P, *dhm_G;
105 | } tls_server_ctx;
106 |
107 | #define TLS_CTX tls_ctx *
108 | #define TLS_client(ctx,s) s = malloc(sizeof(ssl_context)); ssl_init(s);\
109 | ssl_set_endpoint(s, SSL_IS_CLIENT); ssl_set_authmode(s, SSL_VERIFY_NONE);\
110 | ssl_set_rng(s, havege_random, &ctx->hs);\
111 | ssl_set_ciphersuites(s, ssl_default_ciphersuites);\
112 | SSL_SET_SESSION(s, 1, 600, &ctx->ssn)
113 | #define TLS_server(ctx,s) s = malloc(sizeof(ssl_context)); ssl_init(s);\
114 | ssl_set_endpoint(s, SSL_IS_SERVER); ssl_set_authmode(s, SSL_VERIFY_NONE);\
115 | ssl_set_rng(s, havege_random, ((tls_server_ctx*)ctx)->hs);\
116 | ssl_set_ciphersuites(s, ssl_default_ciphersuites);\
117 | SSL_SET_SESSION(s, 1, 600, &((tls_server_ctx*)ctx)->ssn);\
118 | ssl_set_own_cert(s, &((tls_server_ctx*)ctx)->cert, &((tls_server_ctx*)ctx)->key);\
119 | ssl_set_dh_param(s, ((tls_server_ctx*)ctx)->dhm_P, ((tls_server_ctx*)ctx)->dhm_G)
120 | #define TLS_setfd(s,fd) ssl_set_bio(s, net_recv, &fd, net_send, &fd)
121 | #define TLS_connect(s) ssl_handshake(s)
122 | #define TLS_accept(s) ssl_handshake(s)
123 | #define TLS_read(s,b,l) ssl_read(s,(unsigned char *)b,l)
124 | #define TLS_write(s,b,l) ssl_write(s,(unsigned char *)b,l)
125 | #define TLS_shutdown(s) ssl_close_notify(s)
126 | #define TLS_close(s) ssl_free(s); free(s)
127 |
128 | #elif defined(USE_GNUTLS)
129 | #include
130 | typedef struct tls_ctx
131 | {
132 | gnutls_certificate_credentials_t cred;
133 | gnutls_priority_t prios;
134 | } tls_ctx;
135 | #define TLS_CTX tls_ctx *
136 | #define TLS_client(ctx,s) gnutls_init((gnutls_session_t *)(&s), GNUTLS_CLIENT); gnutls_priority_set(s, ctx->prios); gnutls_credentials_set(s, GNUTLS_CRD_CERTIFICATE, ctx->cred)
137 | #define TLS_server(ctx,s) gnutls_init((gnutls_session_t *)(&s), GNUTLS_SERVER); gnutls_priority_set_direct(s, "NORMAL", NULL); gnutls_credentials_set(s, GNUTLS_CRD_CERTIFICATE, ctx)
138 | #define TLS_setfd(s,fd) gnutls_transport_set_ptr(s, (gnutls_transport_ptr_t)(long)fd)
139 | #define TLS_connect(s) gnutls_handshake(s)
140 | #define TLS_accept(s) gnutls_handshake(s)
141 | #define TLS_read(s,b,l) gnutls_record_recv(s,b,l)
142 | #define TLS_write(s,b,l) gnutls_record_send(s,b,l)
143 | #define TLS_shutdown(s) gnutls_bye(s, GNUTLS_SHUT_RDWR)
144 | #define TLS_close(s) gnutls_deinit(s)
145 |
146 | #elif defined(USE_ONLY_MD5)
147 | #include "md5.h"
148 | #include "cencode.h"
149 | #define MD5_DIGEST_LENGTH 16
150 |
151 | #else /* USE_OPENSSL */
152 | #define TLS_CTX SSL_CTX *
153 | #define TLS_client(ctx,s) s = SSL_new(ctx)
154 | #define TLS_server(ctx,s) s = SSL_new(ctx)
155 | #define TLS_setfd(s,fd) SSL_set_fd(s,fd)
156 | #define TLS_connect(s) SSL_connect(s)
157 | #define TLS_accept(s) SSL_accept(s)
158 | #define TLS_read(s,b,l) SSL_read(s,b,l)
159 | #define TLS_write(s,b,l) SSL_write(s,b,l)
160 | #define TLS_shutdown(s) SSL_shutdown(s)
161 | #define TLS_close(s) SSL_free(s)
162 |
163 | #endif
164 | #endif
165 |
--------------------------------------------------------------------------------
/librtmp/stdint.h:
--------------------------------------------------------------------------------
1 | /* ISO C9x 7.18 Integer types
2 | * Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
3 | *
4 | * THIS SOFTWARE IS NOT COPYRIGHTED
5 | *
6 | * Contributor: Danny Smith
7 | *
8 | * This source code is offered for use in the public domain. You may
9 | * use, modify or distribute it freely.
10 | *
11 | * This code is distributed in the hope that it will be useful but
12 | * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
13 | * DISCLAIMED. This includes but is not limited to warranties of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 | *
16 | * Date: 2000-12-02
17 | */
18 |
19 |
20 | #ifndef _STDINT_H
21 | #define _STDINT_H
22 | #define __need_wint_t
23 | #define __need_wchar_t
24 |
25 | /* 7.18.1.1 Exact-width integer types */
26 | typedef signed char int8_t;
27 | typedef unsigned char uint8_t;
28 | typedef short int16_t;
29 | typedef unsigned short uint16_t;
30 | typedef int int32_t;
31 | typedef unsigned uint32_t;
32 | typedef __int64 int64_t;
33 | typedef unsigned __int64 uint64_t;
34 |
35 | /* 7.18.1.2 Minimum-width integer types */
36 | typedef signed char int_least8_t;
37 | typedef unsigned char uint_least8_t;
38 | typedef short int_least16_t;
39 | typedef unsigned short uint_least16_t;
40 | typedef int int_least32_t;
41 | typedef unsigned uint_least32_t;
42 | typedef __int64 int_least64_t;
43 | typedef unsigned __int64 uint_least64_t;
44 |
45 | /* 7.18.1.3 Fastest minimum-width integer types
46 | * Not actually guaranteed to be fastest for all purposes
47 | * Here we use the exact-width types for 8 and 16-bit ints.
48 | */
49 | typedef char int_fast8_t;
50 | typedef unsigned char uint_fast8_t;
51 | typedef short int_fast16_t;
52 | typedef unsigned short uint_fast16_t;
53 | typedef int int_fast32_t;
54 | typedef unsigned int uint_fast32_t;
55 | typedef __int64 int_fast64_t;
56 | typedef unsigned __int64 uint_fast64_t;
57 |
58 | /* 7.18.1.4 Integer types capable of holding object pointers */
59 | /*typedef int intptr_t;
60 | typedef unsigned uintptr_t;*/
61 |
62 | /* 7.18.1.5 Greatest-width integer types */
63 | typedef __int64 intmax_t;
64 | typedef unsigned __int64 uintmax_t;
65 |
66 | /* 7.18.2 Limits of specified-width integer types */
67 | #if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS)
68 |
69 | /* 7.18.2.1 Limits of exact-width integer types */
70 | #define INT8_MIN (-128)
71 | #define INT16_MIN (-32768)
72 | #define INT32_MIN (-2147483647 - 1)
73 | #define INT64_MIN (-9223372036854775807LL - 1)
74 |
75 | #define INT8_MAX 127
76 | #define INT16_MAX 32767
77 | #define INT32_MAX 2147483647
78 | #define INT64_MAX 9223372036854775807LL
79 |
80 | #define UINT8_MAX 0xff /* 255U */
81 | #define UINT16_MAX 0xffff /* 65535U */
82 | #define UINT32_MAX 0xffffffff /* 4294967295U */
83 | #define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
84 |
85 | /* 7.18.2.2 Limits of minimum-width integer types */
86 | #define INT_LEAST8_MIN INT8_MIN
87 | #define INT_LEAST16_MIN INT16_MIN
88 | #define INT_LEAST32_MIN INT32_MIN
89 | #define INT_LEAST64_MIN INT64_MIN
90 |
91 | #define INT_LEAST8_MAX INT8_MAX
92 | #define INT_LEAST16_MAX INT16_MAX
93 | #define INT_LEAST32_MAX INT32_MAX
94 | #define INT_LEAST64_MAX INT64_MAX
95 |
96 | #define UINT_LEAST8_MAX UINT8_MAX
97 | #define UINT_LEAST16_MAX UINT16_MAX
98 | #define UINT_LEAST32_MAX UINT32_MAX
99 | #define UINT_LEAST64_MAX UINT64_MAX
100 |
101 | /* 7.18.2.3 Limits of fastest minimum-width integer types */
102 | #define INT_FAST8_MIN INT8_MIN
103 | #define INT_FAST16_MIN INT16_MIN
104 | #define INT_FAST32_MIN INT32_MIN
105 | #define INT_FAST64_MIN INT64_MIN
106 |
107 | #define INT_FAST8_MAX INT8_MAX
108 | #define INT_FAST16_MAX INT16_MAX
109 | #define INT_FAST32_MAX INT32_MAX
110 | #define INT_FAST64_MAX INT64_MAX
111 |
112 | #define UINT_FAST8_MAX UINT8_MAX
113 | #define UINT_FAST16_MAX UINT16_MAX
114 | #define UINT_FAST32_MAX UINT32_MAX
115 | #define UINT_FAST64_MAX UINT64_MAX
116 |
117 | /* 7.18.2.4 Limits of integer types capable of holding
118 | object pointers */
119 | #if defined(_WIN64) || defined(__LP64__)
120 | #define INTPTR_MIN INT64_MIN
121 | #define INTPTR_MAX INT64_MAX
122 | #define UINTPTR_MAX UINT64_MAX
123 | #else
124 | #define INTPTR_MIN INT32_MIN
125 | #define INTPTR_MAX INT32_MAX
126 | #define UINTPTR_MAX UINT32_MAX
127 | #endif
128 |
129 | /* 7.18.2.5 Limits of greatest-width integer types */
130 | #define INTMAX_MIN INT64_MIN
131 | #define INTMAX_MAX INT64_MAX
132 | #define UINTMAX_MAX UINT64_MAX
133 |
134 | /* 7.18.3 Limits of other integer types */
135 | #if defined(_WIN64) || defined(__LP64__)
136 | #define PTRDIFF_MIN INT64_MIN
137 | #define PTRDIFF_MAX INT64_MAX
138 | #else
139 | #define PTRDIFF_MIN INT32_MIN
140 | #define PTRDIFF_MAX INT32_MAX
141 | #endif
142 |
143 | #define SIG_ATOMIC_MIN INT32_MIN
144 | #define SIG_ATOMIC_MAX INT32_MAX
145 |
146 | #ifndef SIZE_MAX
147 | #if defined(_WIN64) || defined(__LP64__)
148 | #define SIZE_MAX UINT64_MAX
149 | #else
150 | #define SIZE_MAX UINT32_MAX
151 | #endif
152 | #endif
153 |
154 | #ifndef WCHAR_MIN /* also in wchar.h */
155 | #define WCHAR_MIN 0
156 | #define WCHAR_MAX ((wchar_t)-1) /* UINT16_MAX */
157 | #endif
158 |
159 | /*
160 | * wint_t is unsigned short for compatibility with MS runtime
161 | */
162 | #define WINT_MIN 0
163 | #define WINT_MAX ((wint_t)-1) /* UINT16_MAX */
164 |
165 | #endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */
166 |
167 |
168 | /* 7.18.4 Macros for integer constants */
169 | #if !defined ( __cplusplus) || defined (__STDC_CONSTANT_MACROS)
170 |
171 | /* 7.18.4.1 Macros for minimum-width integer constants
172 |
173 | Accoding to Douglas Gwyn :
174 | "This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
175 | 9899:1999 as initially published, the expansion was required
176 | to be an integer constant of precisely matching type, which
177 | is impossible to accomplish for the shorter types on most
178 | platforms, because C99 provides no standard way to designate
179 | an integer constant with width less than that of type int.
180 | TC1 changed this to require just an integer constant
181 | *expression* with *promoted* type."
182 |
183 | The trick used here is from Clive D W Feather.
184 | */
185 |
186 | #define INT8_C(val) (INT_LEAST8_MAX-INT_LEAST8_MAX+(val))
187 | #define INT16_C(val) (INT_LEAST16_MAX-INT_LEAST16_MAX+(val))
188 | #define INT32_C(val) (INT_LEAST32_MAX-INT_LEAST32_MAX+(val))
189 | #define INT64_C(val) (INT_LEAST64_MAX-INT_LEAST64_MAX+(val))
190 |
191 | #define UINT8_C(val) (UINT_LEAST8_MAX-UINT_LEAST8_MAX+(val))
192 | #define UINT16_C(val) (UINT_LEAST16_MAX-UINT_LEAST16_MAX+(val))
193 | #define UINT32_C(val) (UINT_LEAST32_MAX-UINT_LEAST32_MAX+(val))
194 | #define UINT64_C(val) (UINT_LEAST64_MAX-UINT_LEAST64_MAX+(val))
195 |
196 | /* 7.18.4.2 Macros for greatest-width integer constants */
197 | #define INTMAX_C(val) (INTMAX_MAX-INTMAX_MAX+(val))
198 | #define UINTMAX_C(val) (UINTMAX_MAX-UINTMAX_MAX+(val))
199 |
200 | #endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */
201 |
202 | #endif
203 |
--------------------------------------------------------------------------------
/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by twichtest.rc
4 | //
5 | #define IDD_DIALOG1 101
6 | #define IDI_ICON1 103
7 | #define IDI_ICON2 104
8 | #define IDC_FILENAME 1001
9 | #define IDC_EXIT 1003
10 | #define IDC_BROWSE 1004
11 | #define IDC_RADIO1 1006
12 | #define IDC_RADIO2 1007
13 | #define IDC_PROGRESS1 1008
14 | #define IDC_PROGRESS 1008
15 | #define IDC_EDIT1 1009
16 | #define IDC_COMBO1 1010
17 | #define IDC_GETKEY 1011
18 | #define IDC_COMBO2 1012
19 | #define IDC_DURATION 1012
20 | #define IDC_EU 1017
21 | #define IDC_US 1018
22 | #define IDC_ASIA 1019
23 | #define IDC_OTHER 1020
24 | #define IDC_LIST 1021
25 | #define IDC_BUTTON1 1022
26 | #define IDC_SHARE 1022
27 | #define IDC_INTERFACE 1023
28 | #define IDC_INTERFACE2 1024
29 | #define IDC_US2 1024
30 | #define IDC_SA 1024
31 |
32 | // Next default values for new objects
33 | //
34 | #ifdef APSTUDIO_INVOKED
35 | #ifndef APSTUDIO_READONLY_SYMBOLS
36 | #define _APS_NEXT_RESOURCE_VALUE 105
37 | #define _APS_NEXT_COMMAND_VALUE 40001
38 | #define _APS_NEXT_CONTROL_VALUE 1024
39 | #define _APS_NEXT_SYMED_VALUE 101
40 | #endif
41 | #endif
42 |
--------------------------------------------------------------------------------
/small.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/notr1ch/TwitchTest/c34fe317f2b7968ab45e585051d1e66273e26049/small.ico
--------------------------------------------------------------------------------
/twichtest.rc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/notr1ch/TwitchTest/c34fe317f2b7968ab45e585051d1e66273e26049/twichtest.rc
--------------------------------------------------------------------------------
/twitchbwtest.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | TwitchTest
15 | {50AF660B-5BB1-43E9-A716-5D131B1F9358}
16 | Win32Proj
17 | 10.0
18 |
19 |
20 |
21 | Application
22 | v142
23 | Unicode
24 | true
25 |
26 |
27 | Application
28 | v142
29 | Unicode
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | <_ProjectFileVersion>12.0.30501.0
43 |
44 |
45 | Debug\
46 | Debug\
47 | true
48 |
49 |
50 | Release\
51 | Release\
52 | false
53 |
54 |
55 |
56 | Disabled
57 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)
58 | true
59 | EnableFastChecks
60 | MultiThreadedDLL
61 |
62 | Level3
63 | EditAndContinue
64 |
65 |
66 | setupapi.lib;psapi.lib;crypt32.lib;gdiplus.lib;winmm.lib;comctl32.lib;Iphlpapi.lib;jansson.lib;wininet.lib;ws2_32.lib;%(AdditionalDependencies)
67 | true
68 | $(OutDir)$(TargetName).pdb
69 | Windows
70 | MachineX86
71 | HighestAvailable
72 |
73 |
74 |
75 |
76 | MinSpace
77 | true
78 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)
79 | true
80 | MultiThreadedDLL
81 | true
82 | true
83 |
84 | Level3
85 |
86 | true
87 | false
88 | true
89 | Guard
90 |
91 |
92 | setupapi.lib;psapi.lib;crypt32.lib;gdiplus.lib;;winmm.lib;comctl32.lib;Iphlpapi.lib;jansson.lib;wininet.lib;ws2_32.lib;%(AdditionalDependencies)
93 | %(IgnoreSpecificDefaultLibraries)
94 | false
95 | Windows
96 | true
97 | true
98 | MachineX86
99 | HighestAvailable
100 |
101 |
102 | true
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------
/twitchtest.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/notr1ch/TwitchTest/c34fe317f2b7968ab45e585051d1e66273e26049/twitchtest.ico
--------------------------------------------------------------------------------