29 static_assert(
sizeof(
wg_common_header) == 4,
"wg_common_header size is not 4 bytes");
69 return (portSrc == 51820 || portDst == 51820);
131 static std::vector<FieldDescriptor>
all()
135 std::copy(extra.begin(), extra.end(), std::back_inserter(result));
159 #pragma pack(push, 1)
165 uint32_t senderIndex;
167 uint8_t initiatorEphemeral[32];
169 uint8_t encryptedInitiatorStatic[48];
171 uint8_t encryptedTimestamp[28];
176 } wg_handshake_initiation;
178 wg_handshake_initiation* getHandshakeInitiationHeader()
const
180 return reinterpret_cast<wg_handshake_initiation*
>(getBasicHeader());
200 return data !=
nullptr && dataLen >=
sizeof(wg_handshake_initiation);
211 const uint8_t encryptedInitiatorStatic[48],
212 const uint8_t encryptedTimestamp[28],
const uint8_t mac1[16],
213 const uint8_t mac2[16]);
246 void setMac1(
const std::array<uint8_t, 16>& mac1);
249 void setMac2(
const std::array<uint8_t, 16>& mac2);
265 static std::vector<FieldDescriptor>
all()
268 std::initializer_list<FieldDescriptor> extra{
271 std::copy(extra.begin(), extra.end(), std::back_inserter(result));
305 #pragma pack(push, 1)
311 uint32_t senderIndex;
313 uint32_t receiverIndex;
315 uint8_t responderEphemeral[32];
317 uint8_t encryptedEmpty[16];
322 } wg_handshake_response;
325 wg_handshake_response* getHandshakeResponseHeader()
const
327 return reinterpret_cast<wg_handshake_response*
>(getBasicHeader());
347 return data !=
nullptr && dataLen >=
sizeof(wg_handshake_response);
358 const uint8_t responderEphemeral[32],
const uint8_t encryptedEmpty[16],
359 const uint8_t mac1[16],
const uint8_t mac2[16]);
392 void setMac1(
const std::array<uint8_t, 16>& mac1);
395 void setMac2(
const std::array<uint8_t, 16>& mac2);
411 static std::vector<FieldDescriptor>
all()
416 std::copy(extra.begin(), extra.end(), std::back_inserter(result));
450 #pragma pack(push, 1)
456 uint32_t receiverIndex;
460 uint8_t encryptedCookie[32];
464 wg_cookie_reply* getCookieReplyHeader()
const
466 return reinterpret_cast<wg_cookie_reply*
>(getBasicHeader());
485 return data !=
nullptr && dataLen >=
sizeof(wg_cookie_reply);
507 void setNonce(
const std::array<uint8_t, 24>& nonce);
526 static std::vector<FieldDescriptor>
all()
530 std::copy(extra.begin(), extra.end(), std::back_inserter(result));
553 #pragma pack(push, 1)
559 uint32_t receiverIndex;
563 uint8_t encryptedData[0];
567 wg_transport_data* getTransportHeader()
const
569 return reinterpret_cast<wg_transport_data*
>(getBasicHeader());
588 return data !=
nullptr && dataLen >=
sizeof(wg_transport_data);
597 size_t encryptedDataLen);
633 static std::vector<FieldDescriptor>
all()
637 std::copy(extra.begin(), extra.end(), std::back_inserter(result));
Definition: Serializers.h:230
Definition: WireGuardLayer.h:448
std::array< uint8_t, 32 > getEncryptedCookie() const
std::array< uint8_t, 24 > getNonce() const
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: WireGuardLayer.h:483
WireGuardMessageType getWireGuardMessageType() const override
Definition: WireGuardLayer.h:515
WireGuardCookieReplyLayer(uint32_t receiverIndex, const uint8_t nonce[24], const uint8_t encryptedCookie[32])
void setReceiverIndex(uint32_t receiverIndex)
void setNonce(const std::array< uint8_t, 24 > &nonce)
WireGuardCookieReplyLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: WireGuardLayer.h:475
void serializeLayer(ObjectScope &serializer) const override
uint32_t getReceiverIndex() const
void setEncryptedCookie(const std::array< uint8_t, 32 > &encryptedCookie)
Definition: WireGuardLayer.h:157
void serializeLayer(ObjectScope &serializer) const override
void setMac2(const std::array< uint8_t, 16 > &mac2)
WireGuardMessageType getWireGuardMessageType() const override
Definition: WireGuardLayer.h:254
void setMac1(const std::array< uint8_t, 16 > &mac1)
std::array< uint8_t, 48 > getEncryptedInitiatorStatic() const
std::array< uint8_t, 16 > getMac1() const
WireGuardHandshakeInitiationLayer(uint32_t senderIndex, const uint8_t initiatorEphemeral[32], const uint8_t encryptedInitiatorStatic[48], const uint8_t encryptedTimestamp[28], const uint8_t mac1[16], const uint8_t mac2[16])
uint32_t getSenderIndex() const
std::array< uint8_t, 16 > getMac2() const
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: WireGuardLayer.h:198
std::array< uint8_t, 28 > getEncryptedTimestamp() const
void setEncryptedInitiatorStatic(const std::array< uint8_t, 48 > &encryptedInitiatorStatic)
WireGuardHandshakeInitiationLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: WireGuardLayer.h:189
void setEncryptedTimestamp(const std::array< uint8_t, 28 > &encryptedTimestamp)
std::array< uint8_t, 32 > getInitiatorEphemeral() const
void setInitiatorEphemeral(const std::array< uint8_t, 32 > &initiatorEphemeral)
void setSenderIndex(uint32_t senderIndex)
Definition: WireGuardLayer.h:303
void serializeLayer(ObjectScope &serializer) const override
uint32_t getSenderIndex() const
std::array< uint8_t, 16 > getMac1() const
WireGuardHandshakeResponseLayer(uint32_t senderIndex, uint32_t receiverIndex, const uint8_t responderEphemeral[32], const uint8_t encryptedEmpty[16], const uint8_t mac1[16], const uint8_t mac2[16])
void setResponderEphemeral(const std::array< uint8_t, 32 > &responderEphemeral)
uint32_t getReceiverIndex() const
void setMac2(const std::array< uint8_t, 16 > &mac2)
void setReceiverIndex(uint32_t receiverIndex)
WireGuardMessageType getWireGuardMessageType() const override
Definition: WireGuardLayer.h:400
void setEncryptedEmpty(const std::array< uint8_t, 16 > &encryptedEmpty)
WireGuardHandshakeResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: WireGuardLayer.h:336
void setMac1(const std::array< uint8_t, 16 > &mac1)
std::array< uint8_t, 16 > getMac2() const
void setSenderIndex(uint32_t senderIndex)
std::array< uint8_t, 32 > getResponderEphemeral() const
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: WireGuardLayer.h:345
std::array< uint8_t, 16 > getEncryptedEmpty() const
Definition: WireGuardLayer.h:16
void setReserved(const std::array< uint8_t, 3 > &reserved)
OsiModelLayer getOsiModelLayer() const override
Definition: WireGuardLayer.h:114
size_t getHeaderLen() const override
static bool isWireGuardPorts(uint16_t portSrc, uint16_t portDst)
Definition: WireGuardLayer.h:67
virtual WireGuardMessageType getWireGuardMessageType() const
Definition: WireGuardLayer.h:120
WireGuardMessageType
WireGuard message types.
Definition: WireGuardLayer.h:41
@ HandshakeInitiation
Handshake Initiation message.
@ HandshakeResponse
Handshake Response message.
@ CookieReply
Cookie Reply message.
@ TransportData
Transport Data message.
@ Unknown
Unknown Initiation message.
static bool isDataValid(const uint8_t *data, size_t dataLen)
std::string toString() const override
uint32_t getReserved() const
std::string getMessageTypeAsString() const
static WireGuardLayer * parseWireGuardLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
void parseNextLayer() override
Does nothing for this layer (WireGuard layer is always last)
Definition: WireGuardLayer.h:99
void computeCalculateFields() override
No fields to compute or update, so this method is left empty.
Definition: WireGuardLayer.h:106
WireGuardLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: WireGuardLayer.h:59
uint8_t getMessageType() const
void serializeLayer(ObjectScope &serializer) const override
Definition: WireGuardLayer.h:551
void setEncryptedData(const uint8_t *encryptedData, size_t encryptedDataLen)
void setCounter(uint64_t counter)
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: WireGuardLayer.h:586
void serializeLayer(ObjectScope &serializer) const override
uint32_t getReceiverIndex() const
uint64_t getCounter() const
WireGuardTransportDataLayer(uint32_t receiverIndex, uint64_t counter, const uint8_t *encryptedData, size_t encryptedDataLen)
WireGuardTransportDataLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: WireGuardLayer.h:578
const uint8_t * getEncryptedData() const
void setReceiverIndex(uint32_t receiverIndex)
WireGuardMessageType getWireGuardMessageType() const override
Definition: WireGuardLayer.h:622
const ProtocolType WireGuard
WireGuard protocol.
Definition: ProtocolType.h:240
The main namespace for the PcapPlusPlus lib.
Definition: AssertionUtils.h:19
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:425
@ OsiModelNetworkLayer
Network layer (layer 3)
Definition: ProtocolType.h:431
Definition: Serializers.h:18
static std::vector< FieldDescriptor > all()
Definition: Layer.h:214
static constexpr uint16_t MaxID
Maximum field ID used by the layer.
Definition: Layer.h:229
Definition: WireGuardLayer.h:524
static const FieldDescriptor ReceiverIndex
Field descriptor for the receiver index, written as a hex value.
Definition: WireGuardLayer.h:535
static const FieldDescriptor EncryptedCookie
Field descriptor for the 32-byte encrypted cookie, written as a hex string with no separators.
Definition: WireGuardLayer.h:541
static std::vector< FieldDescriptor > all()
Definition: WireGuardLayer.h:526
static const FieldDescriptor Nonce
Field descriptor for the 24-byte nonce, written as a hex string with no separators.
Definition: WireGuardLayer.h:538
Definition: WireGuardLayer.h:263
static std::vector< FieldDescriptor > all()
Definition: WireGuardLayer.h:265
static const FieldDescriptor Mac2
Field descriptor for the 16-byte MAC2, written as a hex string with no separators.
Definition: WireGuardLayer.h:293
static const FieldDescriptor EncryptedTimestamp
Field descriptor for the 28-byte encrypted timestamp, written as a hex string with no separators.
Definition: WireGuardLayer.h:287
static const FieldDescriptor SenderIndex
Field descriptor for the sender index, written as a hex value.
Definition: WireGuardLayer.h:276
static const FieldDescriptor InitiatorEphemeral
Field descriptor for the 32-byte initiator ephemeral public key, written as a hex string with no sepa...
Definition: WireGuardLayer.h:280
static const FieldDescriptor Mac1
Field descriptor for the 16-byte MAC1, written as a hex string with no separators.
Definition: WireGuardLayer.h:290
static const FieldDescriptor EncryptedInitiatorStatic
Field descriptor for the 48-byte encrypted initiator static key, written as a hex string with no sepa...
Definition: WireGuardLayer.h:284
Definition: WireGuardLayer.h:409
static const FieldDescriptor SenderIndex
Field descriptor for the sender index, written as a hex value.
Definition: WireGuardLayer.h:421
static const FieldDescriptor EncryptedEmpty
Field descriptor for the 16-byte encrypted empty field, written as a hex string with no separators.
Definition: WireGuardLayer.h:432
static const FieldDescriptor Mac1
Field descriptor for the 16-byte MAC1, written as a hex string with no separators.
Definition: WireGuardLayer.h:435
static std::vector< FieldDescriptor > all()
Definition: WireGuardLayer.h:411
static const FieldDescriptor ResponderEphemeral
Field descriptor for the 32-byte responder ephemeral public key, written as a hex string with no sepa...
Definition: WireGuardLayer.h:428
static const FieldDescriptor Mac2
Field descriptor for the 16-byte MAC2, written as a hex string with no separators.
Definition: WireGuardLayer.h:438
static const FieldDescriptor ReceiverIndex
Field descriptor for the receiver index, written as a hex value.
Definition: WireGuardLayer.h:424
Definition: WireGuardLayer.h:129
static constexpr uint16_t MaxID
Maximum field ID used by WireGuardLayer.
Definition: WireGuardLayer.h:147
static const FieldDescriptor MessageTypeName
Field descriptor for the message type name, written as a string.
Definition: WireGuardLayer.h:143
static const FieldDescriptor MessageType
Field descriptor for the raw message type value, written as a number.
Definition: WireGuardLayer.h:140
static std::vector< FieldDescriptor > all()
Definition: WireGuardLayer.h:131
Definition: WireGuardLayer.h:631
static const FieldDescriptor ReceiverIndex
Field descriptor for the receiver index, written as a hex value.
Definition: WireGuardLayer.h:642
static std::vector< FieldDescriptor > all()
Definition: WireGuardLayer.h:633
static const FieldDescriptor Counter
Field descriptor for the counter (nonce), written as a number.
Definition: WireGuardLayer.h:645