MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / SendTokenRequest

Method SendTokenRequest

libi2pd/SSU2Session.cpp:1454–1496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1452 }
1453
1454 void SSU2Session::SendTokenRequest ()
1455 {
1456 // we are Alice
1457#if OPENSSL_PQ
1458 if (m_Server.GetVersion () > 2) // we support post quantum in config
1459 SetVersion (m_Address->v);
1460#endif
1461 Header header;
1462 uint8_t h[32], payload[41];
1463 // fill packet
1464 header.h.connID = m_DestConnID; // dest id
1465 RAND_bytes (header.buf + 8, 4); // random packet num
1466 header.h.type = eSSU2TokenRequest;
1467 header.h.flags[0] = GetVersion (); // ver
1468 header.h.flags[1] = (uint8_t)i2p::context.GetNetID (); // netID
1469 header.h.flags[2] = 0; // flag
1470 memcpy (h, header.buf, 16);
1471 memcpy (h + 16, &m_SourceConnID, 8); // source id
1472 memset (h + 24, 0, 8); // zero token
1473 // payload
1474 payload[0] = eSSU2BlkDateTime;
1475 htobe16buf (payload + 1, 4);
1476 htobe32buf (payload + 3, (i2p::util::GetMillisecondsSinceEpoch () + 500)/1000);
1477 size_t payloadSize = 7;
1478 payloadSize += CreatePaddingBlock (payload + payloadSize, 25 - payloadSize, 1);
1479 // encrypt
1480 uint8_t nonce[12];
1481 CreateNonce (be32toh (header.h.packetNum), nonce);
1482 i2p::crypto::AEADChaCha20Poly1305 (payload, payloadSize, h, 32, m_Address->i, nonce, payload, payloadSize + 16, true);
1483 payloadSize += 16;
1484 header.ll[0] ^= CreateHeaderMask (m_Address->i, payload + (payloadSize - 24));
1485 header.ll[1] ^= CreateHeaderMask (m_Address->i, payload + (payloadSize - 12));
1486 memset (nonce, 0, 12);
1487 m_Server.ChaCha20 (h + 16, 16, m_Address->i, nonce, h + 16);
1488 // send
1489 if (m_Server.AddPendingOutgoingSession (shared_from_this ()))
1490 m_Server.Send (header.buf, 16, h + 16, 16, payload, payloadSize, m_RemoteEndpoint);
1491 else
1492 {
1493 LogPrint (eLogWarning, "SSU2: TokenRequest request to ", m_RemoteEndpoint, " already pending");
1494 Terminate ();
1495 }
1496 }
1497
1498 bool SSU2Session::ProcessTokenRequest (Header& header, uint8_t * buf, size_t len)
1499 {

Callers

nothing calls this directly

Calls 13

htobe16bufFunction · 0.85
htobe32bufFunction · 0.85
CreateNonceFunction · 0.85
be32tohFunction · 0.85
AEADChaCha20Poly1305Function · 0.85
CreateHeaderMaskFunction · 0.85
LogPrintFunction · 0.85
GetNetIDMethod · 0.80
ChaCha20Method · 0.80
GetVersionMethod · 0.45

Tested by

no test coverage detected