Initial host certificate and encryption

Feb 11, 2008 at 4:08 AM
I believe I have figured out what the inital host certificate is encrypted in. The OID of the certificate is 1.2.840.113549.1.1.5. Which is RSA encryption using SHA-1. I am still trying to figure out how to use this in .NET and c#. If anybody has any suggestions, I would greatly appreciate the help.
Feb 18, 2008 at 8:26 AM
Whilst this is for MCE2005 - Xbox 360 Extender protocols, I highly recommend you take a look at the Tufour project which I looked at reversing to emulate connectivity:
written in .net and c# so will give you something play with. This will give you all the code to get by the four digit code bit no problems. Also I really struggled in getting a decent UPNP stack for C#, not 100% sure it's required for the MCE Extender detection phase but there you go.

I'd be happy to lend a hand, just waiting for the extenders to hit the U.K, which is what stopped my project in the first place.

Feb 18, 2008 at 2:24 PM
Edited Feb 18, 2008 at 2:46 PM
Thanks. Yeah, I have looked at that project but the protocols have seemed to change quite a bit since then. What do you mean by the four digit code bit? I see the 16 bit and 72 bit are still there but they don't seem to be needed for the v2 stuff. Right now I am working on figuring out
the certificate that gets passed in the first communication from the host (Vista). I haven't done a lot with certificates and need to figure out how to deal with it. Thanks for letting me know about it though. Do you have a XBox 360? If so, could you do a network monitor of the traffic of setting up
one as an extender to see if there is any differences with my setup?
Feb 18, 2008 at 2:36 PM
Edited Feb 18, 2008 at 2:47 PM
For anybody that wants to check out the certificate. Here is the Base64 encoded cert. I haven't dealt with certs much so if anybody has a way of dealing with this in .NET that would be great.



Feb 18, 2008 at 7:35 PM
Specifically look at client.cs on the Tufour, yeah I know some of the protocols are out of date, but as well some of the information is the same (from what I remember of the dumps from my xbox 360 to my vista mce machine). When you setup an Xbox 360 there is a shared out of band key process (I thought it was 4 digits), same with the V1 extenders on MCE2005. That bit of the project is still valid.
I'll try and get the Xbox 360 dump done this weekend; snowed over most weekdays :-(.
CryptoBlob.cs may also be of help with the RSA encryption, its been along time since I've looked at this project and it'll be a while before I'm useful again :-)

Feb 21, 2008 at 5:05 PM
Ok, I was able to use openssl asn1parse to get at least something from it...

Here is what I got using openssl asn1parse...

c:\OpenSSL\bin>openssl asn1parse -in cert.cer -offset 6
0:d=0 hl=4 l= 862 cons: SEQUENCE
4:d=1 hl=4 l= 582 cons: SEQUENCE
8:d=2 hl=2 l= 3 cons: cont 0
10:d=3 hl=2 l= 1 prim: INTEGER :02
13:d=2 hl=2 l= 16 prim: INTEGER :-3E4DAB412AD5646FB202A197E81D90C6
31:d=2 hl=2 l= 13 cons: SEQUENCE
33:d=3 hl=2 l= 9 prim: OBJECT :sha1WithRSAEncryption
44:d=3 hl=2 l= 0 prim: NULL
46:d=2 hl=2 l= 55 cons: SEQUENCE
48:d=3 hl=2 l= 53 cons: SET
50:d=4 hl=2 l= 51 cons: SEQUENCE
52:d=5 hl=2 l= 3 prim: OBJECT :commonName
57:d=5 hl=2 l= 44 prim: PRINTABLESTRING :Microsoft Windows Media Center Extender Host
103:d=2 hl=2 l= 30 cons: SEQUENCE
105:d=3 hl=2 l= 13 prim: UTCTIME :080114025348Z
120:d=3 hl=2 l= 13 prim: UTCTIME :380113091650Z
135:d=2 hl=2 l= 55 cons: SEQUENCE
137:d=3 hl=2 l= 53 cons: SET
139:d=4 hl=2 l= 51 cons: SEQUENCE
141:d=5 hl=2 l= 3 prim: OBJECT :commonName
146:d=5 hl=2 l= 44 prim: PRINTABLESTRING :Microsoft Windows Media Center Extender Host
192:d=2 hl=4 l= 290 cons: SEQUENCE
196:d=3 hl=2 l= 13 cons: SEQUENCE
198:d=4 hl=2 l= 9 prim: OBJECT :rsaEncryption
209:d=4 hl=2 l= 0 prim: NULL
211:d=3 hl=4 l= 271 prim: BIT STRING
486:d=2 hl=2 l= 102 cons: cont 3
488:d=3 hl=2 l= 100 cons: SEQUENCE
490:d=4 hl=2 l= 52 cons: SEQUENCE
492:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Subject Alternative Name
497:d=5 hl=2 l= 45 prim: OCTET STRING HEX DUMP:302B8629757569643A65373336383165622D316336322D343038332D626439392D613163343038643330343537
544:d=4 hl=2 l= 11 cons: SEQUENCE
546:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Key Usage
551:d=5 hl=2 l= 4 prim: OCTET STRING HEX DUMP:030204F0
557:d=4 hl=2 l= 31 cons: SEQUENCE
559:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Extended Key Usage
564:d=5 hl=2 l= 24 prim: OCTET STRING HEX DUMP:301606082B06010505070301060A2B0601040182370A050C
590:d=1 hl=2 l= 13 cons: SEQUENCE
592:d=2 hl=2 l= 9 prim: OBJECT :sha1WithRSAEncryption
603:d=2 hl=2 l= 0 prim: NULL
605:d=1 hl=4 l= 257 prim: BIT STRING
Feb 21, 2008 at 5:29 PM
Ok, using the 6 byte offset, I was able to output the string into a windows cert manager readable format. Here was the openssl command I used to do it....

openssl asn1parse -in cert.cer -strparse 6 -out certoutput.cer
Feb 21, 2008 at 5:31 PM
Ok, so now I need to be able to do this in .NET code. Anybody got an example of how to do this? I figure I have to convert it off of base 64 then truncate the first 6 bytes and then use that to import into a x509 cert class. Boy I have a lot of learning to do on this stuff.

Mar 1, 2008 at 9:56 PM
Edited Mar 1, 2008 at 10:19 PM
I will try to help you with that. So, basically, the task is:
-Given base64 string
-Convert to bytes
-Remove first 6 bytes
-Treat the resulting raw as certificate
-Create a x509 cert from the raw?

How did you know it was a 6 byte offset?
Mar 1, 2008 at 10:07 PM
Edited Mar 2, 2008 at 2:08 AM
Here's some C# code I threw together and tested successfully. It does what you wanted

Add reference for System.Security

using System.Security.Cryptography.X509Certificates;

private void LoadCertificate()
const string Base64String = @"AAABAANiMIIDXjCCAkagAwIBAgIQwbJUvtUqm5BN/V5oFJvOjANBgkqhkiG9w0BAQUFADA3MTUwMwYDVQQDEyxNaWNyb3NvZnQgV2luZG93cyBNZWRpYSBDZW50ZXIgRXh0ZW5kZXIgSG9zdDAeFw0wODAxMTQwMjUzNDhaFw0zODAxMTMwOTE2NTBaMDcxNTAzBgNVBAMTLE1pY3Jvc29mdCBXaW5kb3dzIE1lZGlhIENlbnRlciBFeHRlbmRlciBIb3N0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtwJXbDjMejgVKMLCkghR9tbpnLX0nitKsJnucZV6s/kABszxCVDeAxNiiasG26OmqEsSs3ZnrHaleIGe0b/dEnGMR3jlKrWt61KMKuItNMcXQckUU7gAAfjdLxEicZGmorjN9ZmPYOpTZs9DL48XPM5fvASuQSXwGOe4ojdVyZ8i0zOFc1NgADGLKVqktfySYiE5yy0un7850tM2p9JuM6XZy8B4nw9liGv7bd/iExF6uT1xkaHxhcfdLZql03ARESGtsQ5jXezyFtqfaYCaajRCtMPOrPBuQ6qhM6vB7Cg8LjXpJBap9/AB88bz8bM4bJUkRHH5pxwU23QIDAQABo2YwZDA0BgNVHREELTArhil1dWlkOmU3MzY4MWViLTFjNjItNDA4My1iZDk5LWExYzQwOGQzMDQ1NzALBgNVHQ8EBAMCBPAwHwYDVR0lBBgwFgYIKwYBBQUHAwEGCisGAQQBgjcKBQwwDQYJKoZIhvcNAQEFBQADggEBAKZ9UbCic89BhSrfyuGo467v8mhD9yS/wJBTlnPScc5sEhhfsn0Va7UjkcRlEYh62sW0Kx8X/li/lBt0ldwgZZK7NASAG7oP7udOmHz/MGX82q4FCU0zAH9vZNie+QE9/w7oxUz5zEx8GljxRAc0WKTQQyVGS56/Nt8kxYhZEQssBG7jxNZKi/sBTDNJcgyYQM2/uu1zLFvIYVPgigia03RLtY35lR9Mu6v5mGc0ViOVYyvLEVTDCpoXVidBR2vYPnrZ3ZX82LJrwhay4HMZDHqv5cbVJnzAwugf6vVhp3BwXQCLkYFkvgjusYXFDHDH0QIKe0ZtGnDp4=";

byte[] RawSource = Convert.FromBase64String(Base64String);
int CopyLength = RawSource.Length - 6;
byte[] Raw = new byte CopyLength ;
Array.Copy(RawSource,6, Raw,0,CopyLength);

X509Certificate2 Certificate = new X509Certificate2(Raw);
Mar 4, 2008 at 9:01 PM
I found the 6 byte offset because I had read somewhere that said all certs start with a 0x30 byte and I saw that it was the 6th one so I put that into the openssl
utility and there it was. Basically just a lucky guess. So now that I have the cert I need to figure out how to decrypt stuff with it. I will probably also need to create
my own certificate for use in encrypting stuff to send to the host.
Mar 7, 2008 at 4:49 PM
Edited Mar 7, 2008 at 4:54 PM
Looking at the key exchange (MS Trust Agreement crap) it looks like the Iterations parameter (i forget with Action/Method it was) sounds like it's referring to
the number of iterations needed when generating an encryption key from a password

Just thought this might help. The iterations and nonce things were bugging me when I tried to understand this msta rubbish

Mar 11, 2008 at 2:15 AM
Thanks. I found this as well. It talks about nonce..

A nonce is a random value unique for each communication. Thus, no two communications share a nonce and replays are easy to detect.

Mar 11, 2008 at 2:19 AM
Also, I am trying to create a certificate that matches most of the values of the XBox 360. I am not able to set a couple of the though. Does anybody know a tool that
will generate certs with more control? Some of the properties I am trying to set are key usage and enhanced key usage. Then there is a custom one that I am not sure what it is.
Mar 11, 2008 at 3:44 AM
lol. looks like i'm a dollar short and a week late: you're way ahead of me on this stuff. Does makecert.exe give you any options to set key usage?
Mar 11, 2008 at 6:34 PM
How are you currently creating the certificates, using the built-in .NET Framework X509Certificate related classes? Can you use OpenSSL to create certificates?
Mar 12, 2008 at 1:35 AM
yeah, i was using the .net makecert utility. I will look at OpenSSL for doing it. By the way, I put the XBox 360 cert in the project if you guys want to look at.
Mar 18, 2008 at 9:01 PM
Effectively the mcx use 4 iteration for generated a encryption key base 64 for password because the las message send by the server during initialisation is to send the pass for the mcx1 username. to connect rdp on port 3390.
The rdp is one think ... another think is the RTSP streaming, the server try to access files by unique identifier. Presently the Wmplayer cannot neg adequatly the communication for streaming. and not get play stream.