internal SendCustomerTLSHandshake( BackgroundWorker UseWorker, BackWorkerInfo UseWInfo )
 {
     Worker = UseWorker;
     WInfo = UseWInfo;
     StartTime = new ECTime();
     StartTime.SetToNow();
     MsgClient = new CustomerTLSClient( WInfo.ServerIPOrDomainName );
 }
Exemplo n.º 2
0
        internal bool SendCrudeClientHello( RNGCryptoServiceProvider CryptoRand, CustomerTLSClient CustomerTLS )
        {
            try
            {
            int LengthOfOuterMessage = 52 - 5;
            byte[] ToSendBuf = new byte[LengthOfOuterMessage + 5];

            // The first five bytes are the outer TLS record.
            ToSendBuf[0] = 22; // Content type is Handshake
            ToSendBuf[1] = 3;  // Version Major   TLS version 1.2 is version 3.3 (of SSL).
            ToSendBuf[2] = 3;  // Version Minor
            ToSendBuf[3] = (byte)(LengthOfOuterMessage >> 8);
            ToSendBuf[4] = (byte)(LengthOfOuterMessage);

            // Start of the inner ClientHello message.
            ToSendBuf[5] = 1; // Message type 1 is a  ClientHello message.

            int LengthOfClientHelloMessage = LengthOfOuterMessage - 4;
            ToSendBuf[6] = (byte)(LengthOfClientHelloMessage >> 16);
            ToSendBuf[7] = (byte)(LengthOfClientHelloMessage >> 8);
            ToSendBuf[8] = (byte)(LengthOfClientHelloMessage);
            ToSendBuf[9] = 3;   // Version Major
            ToSendBuf[10] = 3;  // Version Minor

            // This part for Unix time is not in TLS 1.3 because there's no point in having it.
            // But it is here in TLS 1.2.
            ECTime RightNow = new ECTime();
            RightNow.SetToNow();
            ulong UnixTime = RightNow.ToUnixTime();
            ToSendBuf[11] = (byte)(UnixTime >> 24);
            ToSendBuf[12] = (byte)(UnixTime >> 16);
            ToSendBuf[13] = (byte)(UnixTime >> 8);
            ToSendBuf[14] = (byte)(UnixTime);

            // These bytes have to be cryptographically random.
            // These are used later in generating the master secret and keys, etc.
            byte[] RandomBytes = new byte[28];
            CryptoRand.GetBytes( RandomBytes );

            int Index = 15;
            for( int Count = 0; Count < 28; Count++ )
              {
              ToSendBuf[Index] = RandomBytes[Count];
              Index++;
              }

            // Index is 15 + 28 = 43.
            // StatusString += "Index at the end of Random bytes is: " + Index.ToString() + "\r\n";
            // Index at the end of Random bytes is: 43

            ToSendBuf[43] = 0; // Session ID Length is zero. It's not resuming a session here.

            // A browser sends a lot more cipher suites than this so this is
            // usually a lot longer.  The algorithm you prefer to use should
            // be listed first.  So they are listed in order of preference.
            ToSendBuf[44] = 0; // Cipher Suites Length high byte
            ToSendBuf[45] = 4; // Cipher Suites Length
            ToSendBuf[46] = 0;
            ToSendBuf[47] = 0x35; // TLS_RSA_WITH_AES_256_CBC_SHA    = { 0x00,0x35 };
            ToSendBuf[48] = 0;
            ToSendBuf[49] = 0x3D; // TLS_RSA_WITH_AES_256_CBC_SHA256 = { 0x00,0x3D };
            ToSendBuf[50] = 1; // Compression Methods Length
            ToSendBuf[51] = 0; // Compression Method is null.

            // This message has no extensions, so that's all there is to send.
            return CustomerTLS.SendBuffer( ToSendBuf );

            }
            catch( Exception Except )
              {
              StatusString += "Exception in SendCrudeClientHello()\r\n";
              StatusString += Except.Message + "\r\n";
              return false;
              }
        }