|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
Layer: L5 Session ยท Build flags: PC_ENABLE_IKEV2
IKEv2 (RFC 7296) is the key-exchange protocol that negotiates IPsec security associations - the standards-track way to build a secure tunnel to a machine over an untrusted network, over UDP 500 / 4500. services/ikev2 is tier 1 of that stack: the pure wire codec. It builds and parses the 28-octet IKE header and the payload chain (SA, KE, Nonce, IDi/IDr, AUTH, Notify, Delete, Traffic Selectors, and the SK encrypted envelope) into fixed caller buffers, with no heap.
Scope. This tier does the framing only. The Diffie-Hellman math, the SKEYSEED / SK_* key derivation, the SK AEAD, and the IKE_SA_INIT -> IKE_AUTH state machine are later tiers (they reuse the curve25519 / AES-GCM / HMAC the library already ships). So the KE public value and nonce in this sketch are placeholders - it emits a structurally valid IKE_SA_INIT and can walk any IKEv2 message, but it does not complete a handshake.
An IKEv2 message is a fixed header then a forward-linked chain of payloads, each with a 4-byte generic header (next-payload + critical bit + length):
The sketch builds an IKE_SA_INIT, hexdumps it, and walks its own payload chain. If you set GATEWAY_IP it also fires the message at that gateway on UDP 500 and parses whatever comes back - a real gateway usually answers a well-formed but crypto-incomplete IKE_SA_INIT with an INVALID_KE_PAYLOAD or COOKIE Notify, which the codec parses and prints (proof the parser handles a real peer's framing).
Nothing is required for the build + self-parse output. To see a real reply, point GATEWAY_IP at an IKEv2 responder (e.g. a strongSwan / libreswan host, or a router's IPsec endpoint) reachable on UDP 500.
Flash and watch Serial @ 115200:
The complete sketch is IKEv2.ino. The codec itself is in src/services/security/ikev2/ikev2.h; the header, payload chain, and the SA -> proposal -> transform tree (including the key-length attribute) are verified against RFC 7296 + the IANA registry and cross-checked byte-for-byte against scapy's IKEv2 codec.