Implemented encryption for embedded profile.

This commit is contained in:
Jakob Friedl
2025-08-19 20:03:34 +02:00
parent 72fcb0d610
commit b023fca124
17 changed files with 79 additions and 49 deletions

View File

@@ -6,9 +6,24 @@ const CONFIGURATION {.strdefine.}: string = ""
proc deserializeConfiguration(config: string): AgentCtx =
var unpacker = Unpacker.init(config)
var aesKey = unpacker.getByteArray(Key)
let
iv = unpacker.getByteArray(Iv)
authTag = unpacker.getByteArray(AuthenticationTag)
length = int(unpacker.getUint32())
# Decrypt profile configuration
let (decData, gmac) = decrypt(aesKey, iv, unpacker.getBytes(length))
wipeKey(aesKey)
if gmac != authTag:
raise newException(CatchableError, "Invalid authentication tag.")
# Parse decrypted profile configuration
unpacker = Unpacker.init(Bytes.toString(decData))
var agentKeyPair = generateKeyPair()
var ctx = AgentCtx(
agentId: generateUUID(),
listenerId: Uuid.toString(unpacker.getUint32()),
@@ -19,9 +34,9 @@ proc deserializeConfiguration(config: string): AgentCtx =
agentPublicKey: agentKeyPair.publicKey,
profile: parseString(unpacker.getDataWithLengthPrefix())
)
wipeKey(agentKeyPair.privateKey)
wipeKey(agentKeyPair.privateKey)
echo "[+] Profile configuration deserialized."
return ctx