From 940a4a1a6efdc8a270e6903fc805829b19cde859 Mon Sep 17 00:00:00 2001 From: Himaja Dhanyamraju <43470317+HimajaDhanyamraju2@users.noreply.github.com> Date: Fri, 10 May 2024 14:24:39 +0530 Subject: [PATCH] Added additional logs to debug cellbox issue (#258) * Added additional logs to debug cellbox issue Signed-off-by: HimajaDhanyamraju2 * Resolved compilation issue Signed-off-by: HimajaDhanyamraju2 --------- Signed-off-by: HimajaDhanyamraju2 Co-authored-by: HimajaDhanyamraju2 --- hub/hub_service.bal | 2 ++ hub/start_hub.bal | 3 +++ 2 files changed, 5 insertions(+) diff --git a/hub/hub_service.bal b/hub/hub_service.bal index 8da7e1f..94d1084 100644 --- a/hub/hub_service.bal +++ b/hub/hub_service.bal @@ -221,7 +221,9 @@ service object { if (message.hubSecret is string) { string hubSecret = message.hubSecret; string encryptionKey = config:HUB_SECRET_ENCRYPTION_KEY; + log:printInfo("Encryption key", encryptionKey = encryptionKey); byte[] encryptionKeyInBytes = (config:HUB_SECRET_ENCRYPTION_KEY_FORMAT).equalsIgnoreCaseAscii("base64-encoded-bytes") ? (check array:fromBase64(encryptionKey)) : encryptionKey.toBytes(); + log:printInfo("Encryption key in bytes", encryptionKeyInBytes = encryptionKeyInBytes); byte[16] initialVector = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; foreach int i in 0...15 { initialVector[i] = (check random:createIntInRange(0, 255)); diff --git a/hub/start_hub.bal b/hub/start_hub.bal index 22d1e32..9ceb247 100644 --- a/hub/start_hub.bal +++ b/hub/start_hub.bal @@ -198,12 +198,15 @@ function startMissingSubscribers(websubhub:VerifiedSubscription[] persistedSubsc kafka:Consumer consumerEp = check conn:createMessageConsumer(topicName, consumerGroup); if (subscriber.hubSecret is string && (subscriber.hubSecret).startsWith(config:ENCRYPTED_SECRET_PREFIX) && (subscriber.hubSecret).endsWith(config:ENCRYPTED_SECRET_SUFFIX)) { string hubSecretWithPattern = subscriber.hubSecret; + log:printInfo("Hubsecret before decryption", hubSecret = hubSecretWithPattern); string hubSecret = hubSecretWithPattern.substring((config:ENCRYPTED_SECRET_PREFIX).length(), hubSecretWithPattern.length() - (config:ENCRYPTED_SECRET_SUFFIX).length()); byte[] ivAppendedCipherText = check array:fromBase64(hubSecret); int cipherLength = ivAppendedCipherText.length(); byte[] cipher = ivAppendedCipherText.slice(0, cipherLength-16); byte[] iv = ivAppendedCipherText.slice(cipherLength-16, cipherLength); string encryptionKey = config:HUB_SECRET_ENCRYPTION_KEY; + log:printInfo("Encryption key", encryptionKey = encryptionKey); + log:printInfo("Encryption key in bytes", encryptionKeyInBytes = encryptionKey.toBytes()); byte[] plainText = check crypto:decryptAesGcm(cipher, encryptionKey.toBytes(), iv); subscriber.hubSecret = check string:fromBytes(plainText); log:printInfo("Decrypted the hubSecret", topic = subscriber.hubTopic);