Browse Source

fixed incorrect MAC calculation

pull/163/head
orignal 10 years ago
parent
commit
64a4799c8c
  1. 8
      Reseed.cpp
  2. 2
      Reseed.h

8
Reseed.cpp

@ -648,7 +648,7 @@ namespace data @@ -648,7 +648,7 @@ namespace data
finishedHash.Final (finishedHashDigest);
PRF (masterSecret, "client finished", finishedHashDigest, 32, 12, finishedPayload + 4);
uint8_t mac[32];
CalculateMACKey (0x16, 0, finishedPayload, 16, mac);
CalculateMAC (0x16, 0, finishedPayload, 16, mac);
Encrypt (finishedPayload, 16, mac, encryptedPayload);
site.write ((char *)finished, sizeof (finished));
site.write ((char *)encryptedPayload, 80);
@ -719,12 +719,12 @@ namespace data @@ -719,12 +719,12 @@ namespace data
return len - 48 - in[len -1] - 1;
}
void TlsSession::CalculateMACKey (uint8_t type, uint64_t seqn, const uint8_t * buf, size_t len, uint8_t * mac)
void TlsSession::CalculateMAC (uint8_t type, uint64_t seqn, const uint8_t * buf, size_t len, uint8_t * mac)
{
uint8_t header[13]; // seqn (8) + type (1) + version (2) + length (2)
htobuf64 (header, seqn);
htobe64buf (header, seqn);
header[8] = type; header[9] = 3; header[10] = 3; // 3,3 means TLS 1.2
htobuf16 (header + 11, len);
htobe16buf (header + 11, len);
CryptoPP::HMAC<CryptoPP::SHA256> hmac (m_MacKey, 32);
hmac.Update (header, 13);
hmac.Update (buf, len);

2
Reseed.h

@ -58,7 +58,7 @@ namespace data @@ -58,7 +58,7 @@ namespace data
CryptoPP::RSA::PublicKey ExtractPublicKey (const uint8_t * certificate, size_t len);
void PRF (const uint8_t * secret, const char * label, const uint8_t * random, size_t randomLen,
size_t len, uint8_t * buf);
void CalculateMACKey (uint8_t type, uint64_t seqn, const uint8_t * buf, size_t len, uint8_t * mac);
void CalculateMAC (uint8_t type, uint64_t seqn, const uint8_t * buf, size_t len, uint8_t * mac);
size_t Encrypt (const uint8_t * in, size_t len, const uint8_t * mac, uint8_t * out);
size_t Decrypt (uint8_t * in, size_t len, uint8_t * out);

Loading…
Cancel
Save