コード例 #1
0
/**
Convert data from the API's form (as we're given it by RemCon) the
bearer-specific form.
*/
TInt CCoreSerialConverter::InterfaceToBearer(TUid aInterfaceUid,
		TUint aOperationId,
		const TDesC8& aData,
		TRemConMessageType aMsgType,
		TDes8& aBearerData) const
	{
	TInt ret = KErrCorrupt;

	if ( aData.Length() <= 10 )
		{
		if ( aMsgType == ERemConCommand )
			{
			aBearerData.Format(_L8("0x%08x 0x%02x %S %S"), aInterfaceUid, aOperationId, &KCmdText(), &aData);
			// Pad it up in case aData was less than 4 characters.
			while ( aBearerData.Length() < KRemConSerialBearerMessageLength )
				{
				aBearerData.Append(_L8(" "));
				}
			ret = KErrNone;
			}
		else if ( aMsgType == ERemConResponse )
			{
			aBearerData.Format(_L8("0x%08x 0x%02x %S %S"), aInterfaceUid, aOperationId, &KRspText(), &aData);
			// Pad it up in case aData was less than 4 characters.
			while ( aBearerData.Length() < KRemConSerialBearerMessageLength )
				{
				aBearerData.Append(_L8(" "));
				}
			ret = KErrNone;
			}
		}

	return ret;
	}
コード例 #2
0
ファイル: bluetooth.cpp プロジェクト: Felard/MoSync
static void ParseUUID(TDes8& aBuf, TUUID aUuid) {
	TPtrC8 uuid(aUuid.ShortestForm());
	const TUint8* ptr = uuid.Ptr();

	switch(uuid.Length()) {
	case 2:
		aBuf.Format(_L8("0x%04X"), BigEndian::Get16(ptr));
		break;
	case 4:
		aBuf.Format(_L8("0x%08X"), BigEndian::Get32(ptr));
		break;
	case 16:
		aBuf.Format(_L8("%08X-%08X-%08X-%08X"), BigEndian::Get32(ptr),
			BigEndian::Get32(ptr + 4), BigEndian::Get32(ptr + 8),
			BigEndian::Get32(ptr + 12));
		break;
	default:
		DEBIG_PHAT_ERROR;
	}
}
コード例 #3
0
ファイル: mschap2.cpp プロジェクト: kuailexs/symbiandump-os2
inline void CPppMsChap2::GenerateAuthenticatorResponseL(
    const TDesC16& aPassword,
    const TDesC8& aNTResponse,
    const TDesC8& aPeerChallenge,
    const TDesC8& aAuthenticatorChallenge,
    const TDesC8& aUserName,
    TDes8& aAuthenticatorResponse)
/**
   Generates the expected MS-CHAP-V2 Authenticator Response Value.
   @param aPassword [in] The Microsoft Windows NT password (0 to 256
   Unicode char).
   @param aNTResponse [in] The MS-CHAP-V2 NT-Response (24 octets).
   @param aPeerChallenge [in] The Peer Challenge (16 octets).
   @param aAuthenticatorChallenge [in] The Authenticator Challenge (16
   octets).
   @param aUserName [in] The Microsoft Windows NT username (0 to 256
   char).
   @param aAuthenticatorResponse [out] The expected MS-CHAP-V2
   Authenticator Response Value encoded in the format
   "S=<auth_string>" as specified in RFC 2759 (42 octets).
   @note This function implements the GenerateAuthenticatorResponse
   routine specified in RFC 2759.
   @internalComponent
*/
{
    ASSERT(aPassword.Length()<=KPppMsChapMaxNTPasswordLength);
    ASSERT(aNTResponse.Length() == KPppMsChap2NTResponseSize);
    ASSERT(aPeerChallenge.Length() ==
           KPppMsChap2PeerChallengeSize);
    ASSERT(aAuthenticatorChallenge.Length() ==
           KPppMsChap2AuthenticatorChallengeSize);
    ASSERT(aUserName.Length()<=KPppMsChapMaxNTUserNameLength);
    ASSERT(aAuthenticatorResponse.Length() ==
           KPppMsChap2AuthenticatorResponseSize);

    HBufC8* passwordHashBuf=HBufC8::NewMaxLC(KPppMsChap2HashSize);
    TPtr8 passwordHash(passwordHashBuf->Des());

    NtPasswordHashL(aPassword, passwordHash);

    HashNtPasswordHashL(passwordHash, passwordHash);

    CSHA1* sha1 = CSHA1::NewL();
    CleanupStack::PushL(sha1);

// A magic string literal specified in RFC 2759 used in reponse
// generation by the GenerateAuthenticatorResponse routine for SHA-1
// encryption.
    _LIT8(KMagic1, "Magic server to client signing constant");


    sha1->Update(passwordHash);
    sha1->Update(aNTResponse);
    TPtrC8 hash(sha1->Final(KMagic1));


    HBufC8* challengeHashBuf =
        HBufC8::NewMaxLC(KPppMsChap2ChallengeHashSize);
    TPtr8 challengeHash(challengeHashBuf->Des());
    ChallengeHashL(aPeerChallenge,
                   aAuthenticatorChallenge,
                   aUserName,
                   challengeHash);

// Another magic string literal specified in RFC 2759 used in reponse
// generation by the GenerateAuthenticatorResponse routine for SHA-1
// encryption.
    _LIT8(KMagic2, "Pad to make it do more than one iteration");


    sha1->Update(hash);
    sha1->Update(challengeHash);
    const TUint8* pHash = sha1->Final(KMagic2).Ptr();


    _LIT8(KFormat,
          "S=%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X"
          "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X");
    aAuthenticatorResponse.Format(KFormat,
                                  *pHash,
                                  *(pHash + 1),
                                  *(pHash + 2),
                                  *(pHash + 3),
                                  *(pHash + 4),
                                  *(pHash + 5),
                                  *(pHash + 6),
                                  *(pHash + 7),
                                  *(pHash + 8),
                                  *(pHash + 9),
                                  *(pHash + 10),
                                  *(pHash + 11),
                                  *(pHash + 12),
                                  *(pHash + 13),
                                  *(pHash + 14),
                                  *(pHash + 15),
                                  *(pHash + 16),
                                  *(pHash + 17),
                                  *(pHash + 18),
                                  *(pHash + 19));

    CleanupStack::PopAndDestroy(challengeHashBuf);

    CleanupStack::PopAndDestroy(sha1);
    CleanupStack::PopAndDestroy(passwordHashBuf);

    ASSERT(aAuthenticatorResponse.Length() ==
           KPppMsChap2AuthenticatorResponseSize);
}