Skip to content

Commit

Permalink
Added additional logs to debug cellbox issue (#258)
Browse files Browse the repository at this point in the history
* Added additional logs to debug cellbox issue

Signed-off-by: HimajaDhanyamraju2 <dhanyamraju.himaja2@mindtree.com>

* Resolved compilation issue

Signed-off-by: HimajaDhanyamraju2 <dhanyamraju.himaja2@mindtree.com>

---------

Signed-off-by: HimajaDhanyamraju2 <dhanyamraju.himaja2@mindtree.com>
Co-authored-by: HimajaDhanyamraju2 <dhanyamraju.himaja2@mindtree.com>
  • Loading branch information
HimajaDhanyamraju2 and HimajaDhanyamraju2 authored May 10, 2024
1 parent 9e148db commit 940a4a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hub/hub_service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ service object {
if (message.hubSecret is string) {
string hubSecret = <string> 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] = <byte>(check random:createIntInRange(0, 255));
Expand Down
3 changes: 3 additions & 0 deletions hub/start_hub.bal
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,15 @@ function startMissingSubscribers(websubhub:VerifiedSubscription[] persistedSubsc
kafka:Consumer consumerEp = check conn:createMessageConsumer(topicName, consumerGroup);
if (subscriber.hubSecret is string && (<string>subscriber.hubSecret).startsWith(config:ENCRYPTED_SECRET_PREFIX) && (<string>subscriber.hubSecret).endsWith(config:ENCRYPTED_SECRET_SUFFIX)) {
string hubSecretWithPattern = <string> 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);
Expand Down

0 comments on commit 940a4a1

Please sign in to comment.