bsef11a055 / mp-onlinevideos2

Automatically exported from code.google.com/p/mp-onlinevideos2
0 stars 1 forks source link

Handshake error: Server not genuine adobe #103

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

I try to connect to a media server with rtmpe using RTMP_LIB library, but I get 
handshake error like this:
Size of decompressed SWF: 705980, Hash:
4F A3 14 83 7C 3D C7 16 C8 3E B5 D0 7D E3 C5 E3 AB C2 02 EB 37 75 EF 24 22 21 
85 5F 4A DF 18 17 
Client type: 6
DH pubkey position: 570
Client digest offset: 1448
Initial client digest: 
44 F4 9F F9 BA 4E 30 2A 96 77 DA 1E D0 A1 F3 CC 66 30 F5 F3 24 FF A6 26 FA FA 
9A 55 6E 9C 41 95 
Type Answer   : 6
Server Uptime : 258569045
FMS Version   : 3.5.1.1
Trying different position for server digest!
Server DH public key offset: 784
DH SecretKey:
00 F8 10 7B CA 51 6C CF 21 42 F2 90 83 0F 50 16 63 A5 47 66 B9 91 B7 81 51 39 
44 55 76 AF 5E D6 0D E1 AC F2 70 05 71 60 11 B5 D0 B1 B9 6D 59 2B FC 51 71 EE 
AD 3D 29 8E 48 26 3C DC 86 3F 2D 91 5A 90 59 B7 B0 80 9E 46 5B 08 C4 93 6F E3 
09 BC 35 20 25 61 96 65 67 CF 24 BD 3A 25 56 BA C6 AE FE 01 B2 01 45 79 C6 99 
4A 6C 33 2E 59 EA BD 60 ED E2 57 F2 BC 9B 8A DF CE BE C7 91 16 99 E0 F4 
RC4 Out Key: 
62 4E 4F 22 EE 22 9D 6A 1F A8 DB 30 88 B2 33 92 
RC4 In Key: 
56 34 66 45 EC 44 AB 6F 07 B9 27 CD 88 C7 96 10 
Calculated digest key from secure key and server digest: 
52 24 8A 5E C6 C1 97 D4 C9 D7 18 D7 4F 1B A1 6E 13 54 9A A9 8D C6 A7 9E 93 6A 
BA 94 6E 12 D0 EE 
Client signature calculated:
25 EE C0 4E 07 23 69 78 D0 25 24 7B 24 0A B4 4A 5A C9 09 4C 49 72 7A 6A C6 6E 
A7 15 8D 63 AC F2 
Client signature digest position: 505
Digest key: 
75 8D 12 E8 D5 BD FF 95 03 E1 D0 A7 FD F5 90 3F 73 4B 35 EF A0 0D 45 27 05 8F 
B6 15 0C BC 7D 03 
Signature calculated:
1C 3E 0E 6D C5 4E 2B 47 06 5C 06 95 E9 AB 4E EE 6B 6D 12 5A 45 89 12 D4 84 41 
59 0F 64 B4 7A CB 
Server sent signature:
3D 34 EA 9B 48 D6 F6 01 82 54 9A 84 4B 5D 61 60 44 92 06 BF A0 F9 47 0B A8 F0 
49 66 B3 66 FA 3C 
Server not genuine Adobe!

Is this something known issue?

Original issue reported on code.google.com by fvarko...@hotmail.com on 10 Jul 2011 at 7:20

GoogleCodeExporter commented 9 years ago
Does it work with rtmpdump?

Original comment by bborgsd...@gmail.com on 10 Jul 2011 at 9:49

GoogleCodeExporter commented 9 years ago
Hi bborgsdorf,

I don't know :o)
What's happining here, that I was wondering a few weeks ago, how great 
implementation is this for develope RTMP clients in C#, but unfortunatelly it 
is restrected to download viedos only. So I decided to modify RTMP_LIB code to 
be able to connect to media servers for general puposes, just like connecting 
to chat servers, sharedobjects, and live streams. It is working perfectly for 
rtmp but I realized serious problems at rtmpe includeing handshake, and invokes 
as well.

Concerning the problem descibed above:

I've just realized, that if I change offalg to message format2 it is working!
It seems, some of the rtmpe servers using message format2 in seconde part of 
handshake. If I use something like this, it seems both cases I find server 
signature:

            // 2nd part of handshake
            byte[] resp = new byte[RTMP.RTMP_SIG_SIZE];
            if (ReadN(resp, 0, RTMP.RTMP_SIG_SIZE) != RTMP.RTMP_SIG_SIZE) return false;

            if (FP9HandShake)
            {
                bool bSignatureFound=true;
                int digestPosClient=0;
                byte[] signature=null;
                byte[] digest=null;
                if (resp[4] == 0 && resp[5] == 0 && resp[6] == 0 && resp[7] == 0)
                {
                    logger.Log("Wait, did the server just refuse signed authentication?");
                }

                // verify server response
                //offalg ^= 1;
                digestPosClient = (int)GetDigestOffset(offalg, clientsig, 1, RTMP.RTMP_SIG_SIZE);

                signature = new byte[RTMP.SHA256_DIGEST_LENGTH];
                digest = new byte[RTMP.SHA256_DIGEST_LENGTH];

                logger.Log(string.Format("Client signature digest position: {0}", digestPosClient));
                HMACsha256(clientsig, 1 + digestPosClient, RTMP.SHA256_DIGEST_LENGTH, RTMP.GenuineFMSKey, RTMP.GenuineFMSKey.Length, digest, 0);
                HMACsha256(resp, 0, RTMP.RTMP_SIG_SIZE - RTMP.SHA256_DIGEST_LENGTH, digest, RTMP.SHA256_DIGEST_LENGTH, signature, 0);

                // show some information
                logger.Log("Digest key: ");
                logger.LogHex(digest, 0, RTMP.SHA256_DIGEST_LENGTH);

                // FP10 stuff
                if (type == 8)
                {
                    /* encrypt signatureResp */
                    for (int i = 0; i < RTMP.SHA256_DIGEST_LENGTH; i += 8)
                        rtmpe8_sig(signature, i, digest[i] % 15);
                }

                logger.Log("Signature calculated:");
                logger.LogHex(signature, 0, RTMP.SHA256_DIGEST_LENGTH);

                logger.Log("Server sent signature:");
                logger.LogHex(resp, RTMP.RTMP_SIG_SIZE - RTMP.SHA256_DIGEST_LENGTH, RTMP.SHA256_DIGEST_LENGTH);

               for (int i = 0; i < RTMP.SHA256_DIGEST_LENGTH; i++)
                {
                    if (signature[i] != resp[RTMP.RTMP_SIG_SIZE - RTMP.SHA256_DIGEST_LENGTH + i])
                    {
                        logger.Log("Signature not found, let's try changing the alg(message format2)!");
                        bSignatureFound=false;
                        break;
                    }
                }

               if(!bSignatureFound)
               {
                    offalg ^= 1;
                    digestPosClient = (int)GetDigestOffset(offalg, clientsig, 1, RTMP.RTMP_SIG_SIZE);

                    signature = new byte[RTMP.SHA256_DIGEST_LENGTH];
                    digest = new byte[RTMP.SHA256_DIGEST_LENGTH];

                    logger.Log(string.Format("Client signature digest position: {0}", digestPosClient));
                    HMACsha256(clientsig, 1 + digestPosClient, RTMP.SHA256_DIGEST_LENGTH, RTMP.GenuineFMSKey, RTMP.GenuineFMSKey.Length, digest, 0);
                    HMACsha256(resp, 0, RTMP.RTMP_SIG_SIZE - RTMP.SHA256_DIGEST_LENGTH, digest, RTMP.SHA256_DIGEST_LENGTH, signature, 0);

                    // show some information
                    logger.Log("Digest key: ");
                    logger.LogHex(digest, 0, RTMP.SHA256_DIGEST_LENGTH);

                    // FP10 stuff
                    if (type == 8)
                    {
                        /* encrypt signatureResp */
                        for (int i = 0; i < RTMP.SHA256_DIGEST_LENGTH; i += 8)
                            rtmpe8_sig(signature, i, digest[i] % 15);
                    }

                    logger.Log("Signature calculated:");
                    logger.LogHex(signature, 0, RTMP.SHA256_DIGEST_LENGTH);

                    logger.Log("Server sent signature:");
                    logger.LogHex(resp, RTMP.RTMP_SIG_SIZE - RTMP.SHA256_DIGEST_LENGTH, RTMP.SHA256_DIGEST_LENGTH);

                   for (int i = 0; i < RTMP.SHA256_DIGEST_LENGTH; i++)
                    {
                        byte b=resp[RTMP.RTMP_SIG_SIZE - RTMP.SHA256_DIGEST_LENGTH + i];
                        if (signature[i] != resp[RTMP.RTMP_SIG_SIZE - RTMP.SHA256_DIGEST_LENGTH + i])
                        {
                            logger.Log("Server not genuine Adobe!");
                            return false;
                        }
                    }
               }

                logger.Log("Genuine Adobe Flash Media Server");

I know it's very trivial solution but seems to be working...

After successful connection, server sends packages, what RTMP_LIB can't 
recognize, I don't know why, I just start investigate.

If I ask you to help me in this issue would you be so kind to do it?

Of course I'm happy to share the code here if you think it can be useful.
(I implement NetConnection,SharedObject and NetStream classes for general 
purpose usage of RTMP_LIB)

Thanks again,
Ferike

Original comment by fvarko...@hotmail.com on 10 Jul 2011 at 10:26

GoogleCodeExporter commented 9 years ago
Sure we can work together to make this lib much more complete!
But I have to say, I have no real knowledge about all this. The c# you find 
here is roughly a clone of the rtmpdump c++ lib, that I brought into the .net 
world :)

Original comment by bborgsd...@gmail.com on 10 Jul 2011 at 11:25

GoogleCodeExporter commented 9 years ago
Yeah, ok!
My real problem that I have no knowladge in cryptography used by RTMPE!
Maybe the best solution if I upload the best code I can attchieve here asking 
experts to improve it. I had to modify TCP connect to detach the connection 
from the GUI(this is needed for desktop applications) so I implemented async 
socket connection and some other manior modifacation I did. This reason,I 
renamed the library to RTMP_CLIENT.
I also had to update bouncycastle to the newiest version, because the one it is 
used in RTMP_LIB caused arithmetic exception at RTMPE. If you aggree I upload 
all what I have next to RTMP_LIB. If later when problems fixed and it is 
thought useful RTMP_LIB can be changed to RTMP_CLIENT with few effords. At the 
moment, the whole project needs to be tested, and of course all prealpha :o))

Original comment by fvarko...@hotmail.com on 10 Jul 2011 at 11:52

GoogleCodeExporter commented 9 years ago
You could also start a new project here on google code for your improved lib. 
And when it's stable enough we can integrate it here here well. This way 
there's a common rtmp client lib in c# available that can be used in many apps 
- should get more attraction.
I can then integrate that lib into the onlinevideos project.

Original comment by bborgsd...@gmail.com on 10 Jul 2011 at 12:04

GoogleCodeExporter commented 9 years ago
Ok! I will upload the code in a separated google code project in the next few 
days(I wanna make the scripts more clear, and commented till then) and I will 
inform you about it on this site.

Thanks for your help.

Original comment by fvarko...@hotmail.com on 10 Jul 2011 at 12:14

GoogleCodeExporter commented 9 years ago
Hi again,
I uploaded the project here:
http://code.google.com/p/rtmpconnector/

I tested NetConnection, SharedObject functionalities on some public chat 
applications and on Red5, and adobe FMS servers installed localy and they looks 
ok :O) (I mean RTMP connection. RTMPE handshake still problematic in some 
cases, other cases it's working)
I also tried NetStream functionalities and generaly its working, but I think 
there is still much work with it (Actually I did not modified the origin code, 
only commented out some parts I thought not important in this project. Those 
parts might must be reused later).
I did not implemented getLocal funcionality on SharedObject, cause I don't find 
it important in C# environment.
I also try to convert AMF typed-objects to Dictionary type because it's 
regularly used.
At the moment I'm still testing features of NetConnection and SharedObject 
types.

I would be happy if you or anybody else, participating your project, could test 
and/or help improve this project as well.

Ferike

Original comment by fvarko...@hotmail.com on 20 Jul 2011 at 11:53

GoogleCodeExporter commented 9 years ago
The repository on your url doesn't seem contain any source code yet?

Original comment by bborgsd...@gmail.com on 25 Jul 2011 at 4:57

GoogleCodeExporter commented 9 years ago
Hi again!

Realy I just uploaded a zip file to download section. I'm not familiar with 
googlecode yet, so I have to find out yet how to upload the source section :o)

I'm still modifying the code by the way, there is a lots of bug and I realized 
some missunderstanding I had while reading your code.
I'm in a big Sh***t concerining playing the live stream real time at the 
moment, I realized its not easy at all. Do you have any Idea how could I 
implement a player, can play flv from memorystream? I have found some advice in 
forums, but looks every solutions quite difficult, like implementing COM 
interface for directshow and so on... I would like to implement a very simple 
player what can attach the straem to ( like video class attachNetStream in AS3).

I think I mixed the timestamping you did in RTMP class, must be fixt in the 
near future.

Thanks for keeping the contact,
Ferike

Original comment by fvarko...@hotmail.com on 27 Jul 2011 at 3:16

GoogleCodeExporter commented 9 years ago
Playback is not easy for sure, because rtmp delivered streams can have many 
formats. The way it's done in the MediaPortal plugin is the easiest: Hand the 
stream to a directshow graph.

I didn't look in the downloads section of you project :) A code project should 
have the code checked in. As you started a git project you should make yourself 
familiar with the versioning system git.

Original comment by bborgsd...@gmail.com on 27 Jul 2011 at 3:27

GoogleCodeExporter commented 9 years ago
Thanks!

Do you play the stream directly from memory on mediaportal? From memorystraem 
for exapmle? Or you give the url to the player? Thats the big question.
In my understanding I can't forward the url to the player in case livestream, 
cause its simply not exists.
I plan to investigate this part of your code more deeply from now, the best 
solutions would be if I can copy this part from you, could save a lot off 
effort for me, I can pay for other issues of rtmpconnector :o))

I will learn the versioning system in the near future, I promiss, but till then 
I just wanna upload the project in zip file, if I mad some debug on it.

Original comment by fvarko...@hotmail.com on 27 Jul 2011 at 3:42

GoogleCodeExporter commented 9 years ago
My code has a local http server that acts as proxy to the directshow graph. So 
the directshow filters think they play a http file. That's a protocol we have a 
filter for.

Original comment by bborgsd...@gmail.com on 27 Jul 2011 at 3:44

GoogleCodeExporter commented 9 years ago
hm, tricky, I will check this solution

Original comment by fvarko...@hotmail.com on 27 Jul 2011 at 3:48

GoogleCodeExporter commented 9 years ago
Hi again,

At the end I created a source filter to play video directly from stream, also 
some bugs fixed. The player is not too sophisticated yet and not working 
properly, I tried many things but I can't play video and audio streams 
together(separetedly works..). This can be problem with time stamping, memmory 
allocator issue, or something different. I also uploded the source section on 
git. Can you overview the player and recommend how to modify (or anybody here 
is expert at directshow and willing to help me?)
RTMPE still not working for me, I don't know how can work in onlinevideo 
project.
Might be depends on the server connected to...

Thank you

Original comment by fvarko...@hotmail.com on 17 Sep 2011 at 6:05

GoogleCodeExporter commented 9 years ago
We also created a source filter for rtmp now that uses rtmplib. So the C# 
implementation has become almost obsolete.

Original comment by bborgsd...@gmail.com on 9 Jan 2012 at 4:36