示例#1
0
        internal bool AddDomainX509Rec( DomainX509Record Rec )
        {
            if( Rec == null )
              return false;

            DomainX509RecArray[DomainX509RecArrayLast] = Rec;
            DomainX509RecArrayLast++;

            if( DomainX509RecArrayLast >= DomainX509RecArray.Length )
              {
              try
              {
              Array.Resize( ref DomainX509RecArray, DomainX509RecArray.Length + (1024 * 4));
              }
              catch( Exception Except )
            {
            MForm.ShowStatus( "Error: Couldn't resize the arrays for X.509 data." );
            MForm.ShowStatus( Except.Message );
            return false;
            }
              }

            return true;
        }
示例#2
0
        internal void Copy( DomainX509Record ToCopy )
        {
            if( ToCopy.DomainName.Length > 2 )
              DomainName = ToCopy.DomainName;

            ModifyTime.Copy( ToCopy.ModifyTime );
            PublicKeyExponent = ToCopy.PublicKeyExponent;
            PublicKeyModulus = ToCopy.PublicKeyModulus;
        }
        private void GetX509BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker Worker = (BackgroundWorker)sender;
            BackWorkerInfo WInfo = (BackWorkerInfo)(e.Argument);

            try // catch
            {
            if( Worker.CancellationPending )
              {
              e.Cancel = true;
              return;
              }

            SendCustomerTLSHandshake SendMessage = new SendCustomerTLSHandshake( Worker, WInfo );
            try // finally
            {

            if( !SendMessage.Connect())
              return;

            if( Worker.CancellationPending )
              {
              e.Cancel = true;
              return;
              }

            Worker.ReportProgress( 0, "Before SendMessage.ExchangeMessages()." );
            if( SendMessage.ExchangeMessages())
              {
              X509Record = SendMessage.GetX509Record();
              }
            }
            finally
              {
              Worker.ReportProgress( 0, "Closing the connection." );
              SendMessage.FreeEverything();
              }
            }
            catch( Exception Except )
              {
              Worker.ReportProgress( 0, "Error in DoWork process:" );
              Worker.ReportProgress( 0, Except.Message );
              e.Cancel = true;
              return;
              }
        }
示例#4
0
        internal int ProcessX509Certificates( int Index, byte[] TLSOuterRecordBuffer, int TLSOuterRecordBufferLast )
        {
            StatusString += "Top of Certificate.\r\n";

            // This is a chain of certificates.
            int OriginalIndex = Index;
            StatusString += "\r\n";
            StatusString += "Processing Certificate message.\r\n";
            StatusString += "Index is: " + Index.ToString() + "\r\n";

            int MessageType = TLSOuterRecordBuffer[Index];
            Index++;
            if( MessageType != 11 )
              {
              StatusString += "This is a bug. MessageType != 11.\r\n";
              ShowBytesInBuffer( TLSOuterRecordBuffer, TLSOuterRecordBufferLast );
              return -1;
              }

            StatusString += "MessageType: " + MessageType.ToString() + "\r\n";

            int Length = TLSOuterRecordBuffer[Index];
            Length <<= 8;
            Index++;
            Length |= TLSOuterRecordBuffer[Index];
            Length <<= 8;
            Index++;
            Length |= TLSOuterRecordBuffer[Index];
            Index++;

            StatusString += "Length is: " + Length.ToString() + "\r\n";
            if( TLSOuterRecordBufferLast < (Index + Length) )
              {
              StatusString += "TLSOuterRecordBufferLast < (Index + Length). Length is: " + Length.ToString() + "\r\n";
              ShowBytesInBuffer( TLSOuterRecordBuffer, TLSOuterRecordBufferLast );
              return -1;
              }

            // "Implementations MUST NOT send zero-length fragments of Handshake,
            // Alert, or ChangeCipherSpec content types."
            if( Length < 1 )
              {
              StatusString += "The length of this message was less than one. Length is: " + Length.ToString() + "\r\n";
              ShowBytesInBuffer( TLSOuterRecordBuffer, TLSOuterRecordBufferLast );
              throw( new Exception( "Length less than one." ));
              // return -1;
              }

            // This MoveTo gets returned as the index for the start of the
            // next inner message.
            // The message type plus 3 bytes for the length is 4 bytes for the
            // header.  So add the 4 bytes here.
            int MoveTo = OriginalIndex + Length + 4;
            StatusString += "MoveTo is: " + MoveTo.ToString() + "\r\n";

            byte[] X509Buffer = new byte[Length];
            for( int Count = 0; Count < Length; Count++ )
              {
              X509Buffer[Count] = TLSOuterRecordBuffer[Index];
              Index++;
              }

            X509Record = new DomainX509Record( DomainName );
            X509Record.ParseAndAddOneCertificateList( X509Buffer );
            StatusString += X509Record.GetStatusString();

            StatusString += "Index after loop is: " + Index.ToString() + "\r\n";
            return -1;
        }
示例#5
0
        internal bool UpdateDomainX509Rec( DomainX509Record Rec )
        {
            if( Rec == null )
              return false;

             if( Rec.DomainName.Length < 2 )
               {
               MForm.ShowStatus( "Trying to update a DomainX509 record with no domain name." );
               return false;
               }

            // ToDo: Use a dictionary to index this and find it quickly.
            for( int Count = 0; Count < DomainX509RecArrayLast; Count++ )
              {
              if( Rec.DomainName == DomainX509RecArray[Count].DomainName )
            {
            Rec.SetModifyTimeToNow();
            DomainX509RecArray[Count].Copy( Rec );
            return true;
            }
              }

            // Didn't find a match so add it.
            return AddDomainX509Rec( Rec );
        }
示例#6
0
        internal bool ReadFromTextFile()
        {
            try
            {
            string Line;
            using( StreamReader SReader = new StreamReader( FileName  ))
              {
              int HowMany = 0;
              for( int Count = 0; Count < 1000000; Count++ )
            {
            /*
            if( (Count & 0xFF) == 1 )
              {
              MForm.ShowStatus( "Count is: " + Count.ToString( "N0" ));
              if( !MForm.CheckEvents())
            return false;

              }
              */

            if( SReader.Peek() < 0 )
              break;

            Line = SReader.ReadLine();
            if( Line == null )
              break;

            if( !Line.Contains( "\t" ))
              continue;

            DomainX509Record Rec = new DomainX509Record();
            if( !Rec.StringToObject( Line ))
              {
              // MForm.ShowStatus( "Got false for: " + Line );
              continue;
              }

            if( !AddDomainX509Rec( Rec ))
              break; // Out of RAM.

            HowMany++;
            }

              MForm.ShowStatus( " " );
              MForm.ShowStatus( "Records: " + HowMany.ToString( "N0" ));
              }

            return true;

            }
            catch( Exception Except )
              {
              MForm.ShowStatus( "Could not read the X.509 data file." );
              MForm.ShowStatus( Except.Message );
              return false;
              }
        }
示例#7
0
        internal bool ImportFromOriginalListFile()
        {
            // string FileName = MForm.GetDataDirectory() + "Top1MillionDomains.txt";
            string FileName = MForm.GetDataDirectory() + "Top10KDomains.txt";
            // ECTime RecTime = new ECTime();

            try
            {
            string Line;
            using( StreamReader SReader = new StreamReader( FileName  ))
              {
              int HowMany = 0;
              for( int Count = 0; Count < 1000000; Count++ )
            {
            /*
            if( (Count & 0xFF) == 1 )
              {
              MForm.ShowStatus( "Count is: " + Count.ToString( "N0" ));
              if( !MForm.CheckEvents())
            return false;

              }
              */

            if( SReader.Peek() < 0 )
              break;

            Line = SReader.ReadLine();
            if( Line == null )
              break;

            Line = Line.Trim();
            if( Line.Length < 3 )
              break;

            if( !Line.Contains( "," ))
              continue;

            DomainX509Record Rec = new DomainX509Record();
            if( !Rec.ImportOriginalStringToObject( Line ))
              {
              MForm.ShowStatus( "Got false for: " + Line );
              continue;
              }

            if( !Rec.DomainName.EndsWith( ".com" ))
              continue;

            if( !AddDomainX509Rec( Rec ))
              break; // Out of RAM.

            HowMany++;
            }

              MForm.ShowStatus( " " );
              MForm.ShowStatus( "Records: " + HowMany.ToString( "N0" ));
              }

            return true;

            }
            catch( Exception Except )
              {
              MForm.ShowStatus( "Could not import the X.509 data file." );
              MForm.ShowStatus( Except.Message );
              return false;
              }
        }