From 42511d666fe9cf979e59e590b2510c436a70460a Mon Sep 17 00:00:00 2001 From: smizrahi Date: Mon, 12 Feb 2024 13:47:41 +0100 Subject: [PATCH] feat(core): Add URL encryption for GDPR compliancy. Check for null termination when decrypting. Disable url encryption for anonymous user. --- SoObjects/SOGo/NSString+Crypto.m | 15 ++++++++++++--- SoObjects/SOGo/SOGoUser.m | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/SoObjects/SOGo/NSString+Crypto.m b/SoObjects/SOGo/NSString+Crypto.m index 1bd339d10..c5777db24 100644 --- a/SoObjects/SOGo/NSString+Crypto.m +++ b/SoObjects/SOGo/NSString+Crypto.m @@ -500,8 +500,17 @@ static const NSString *kAES256GCMError = @"kAES256GCMError"; if (p_len > 0) { // Convert to NSString outputData = [NSData dataWithBytes: plaintext length: p_len]; - if (outputData) { - value = [NSString stringWithUTF8String: [outputData bytes]]; + if (outputData && [outputData length] > 0) { + char lastByte; + [outputData getBytes:&lastByte range:NSMakeRange([outputData length]-1, 1)]; + if (lastByte == 0x0) { + // string is null terminated + value = [NSString stringWithUTF8String: [outputData bytes]]; + } else { + // string is not null terminated + value = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding]; + [value autorelease]; + } } else { *ex = [NSException exceptionWithName: kAES128ECError reason:@"Empty data" userInfo: nil]; } @@ -659,7 +668,7 @@ static const NSString *kAES256GCMError = @"kAES256GCMError"; EVP_CIPHER_CTX_free(ctx); if (rv > 0) { - if (outputData) { + if (outputData && [outputData length] > 0) { char lastByte; [outputData getBytes:&lastByte range:NSMakeRange([outputData length]-1, 1)]; if (lastByte == 0x0) { diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index 7d217b28f..1c2a3142d 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -1302,7 +1302,7 @@ static const NSString *kEncryptedUserNamePrefix = @"uenc"; NSString *tmp, *cacheKey; SOGoCache *cache; - if (![[SOGoSystemDefaults sharedSystemDefaults] isURLEncryptionEnabled]) + if (![[SOGoSystemDefaults sharedSystemDefaults] isURLEncryptionEnabled] || [username isEqualToString: @"anonymous"]) return username; cache = [SOGoCache sharedCache]; @@ -1337,7 +1337,7 @@ static const NSString *kEncryptedUserNamePrefix = @"uenc"; NSString *tmp, *cacheKey; SOGoCache *cache; - if (![[SOGoSystemDefaults sharedSystemDefaults] isURLEncryptionEnabled]) + if (![[SOGoSystemDefaults sharedSystemDefaults] isURLEncryptionEnabled] || [username isEqualToString: @"anonymous"]) return username; cache = [SOGoCache sharedCache];