Logo Search packages:      
Sourcecode: kmess version File versions  Download package

const QString MSNChallengeHandler::computeHash ( const QString &  challengeString  ) 

Computes the response hash string for the specified challenge string.

Definition at line 57 of file msnchallengehandler.cpp.

References createHashKey(), and hexSwap().

Referenced by OfflineImService::parseSecureFault().

{
  // Step One: THe MD5 Hash.

  // Combine the received challenge string with the product key.
  const QByteArray digest( QCryptographicHash::hash( ( challengeString + productKey_ ).toUtf8(),
                                                       QCryptographicHash::Md5 ).toHex() );

#ifdef KMESSDEBUG_CHALLENGEHANDLER
  kDebug() << "md5: " << digest;
#endif

  QVector<qint32> md5Integers(4);
  for( int i = 0; i < md5Integers.count(); i++ )
  {
    md5Integers[i] = hexSwap( digest.mid( i * 8, 8 ) ).toUInt( 0, 16 ) & 0x7FFFFFFF;

#ifdef KMESSDEBUG_CHALLENGEHANDLER
    kDebug() << "hex " << i << " 0x" + hexSwap( digest.mid( i * 8, 8 ) ) << " = " << md5Integers[i];
#endif
  }

  // Step Two: Create the challenge string key

  QString challengeKey( challengeString + productId_ );
  // Pad to multiple of 8.
  challengeKey = challengeKey.leftJustified(challengeKey.length() + ( 8 - challengeKey.length() % 8 ), '0');

#ifdef KMESSDEBUG_CHALLENGEHANDLER
  kDebug() << "challenge key: " << challengeKey;
#endif

  QVector<qint32> challengeIntegers( challengeKey.length() / 4 );
  for( int i = 0; i < challengeIntegers.count(); i++ )
  {
    QString sNumHex;
    const QString& sNum( challengeKey.mid( i * 4, 4 ) );

    // Go through the number string, determining the hex equivalent of each value
    // and add that to our new hex string for this number.
    for( int j = 0; j < sNum.length(); j++ )
    {
      sNumHex += QString::number( ( int ) sNum[j].toLatin1(), 16);
    }

    // swap because of the byte ordering issue.
    sNumHex = hexSwap( sNumHex );
    // Assign the converted number.
    challengeIntegers[i] = sNumHex.toInt(0, 16);

#ifdef KMESSDEBUG_CHALLENGEHANDLER
    kDebug() << "challenge int " << sNum << (": 0x" + sNumHex) << " = " << challengeIntegers[i];
#endif
  }

  // Step Three: Create the 64-bit hash key.

  // Get the hash key using the specified arrays.
  qint64 key = createHashKey( md5Integers, challengeIntegers );

  // Step Four: Create the final hash key.

  QString upper( QString::number( QString( digest.mid( 0,  16 ) ).toULongLong( 0, 16 ) ^ key, 16 ) );
  if( upper.length() % 16 != 0 )
  {
    upper = upper.rightJustified( upper.length() + (16 - upper.length() % 16), '0' );
  }

  QString lower( QString::number( QString( digest.mid( 16, 16 ) ).toULongLong( 0, 16 ) ^ key, 16 ) );
  if( lower.length() % 16 != 0 )
  {
    lower = lower.rightJustified( lower.length() + (16 - lower.length() % 16), '0' );
  }

  return ( upper + lower );
}


Generated by  Doxygen 1.6.0   Back to index