From 9fbc84158a75e0ed00d5eafe810f175e037a63de Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 6 Jan 2017 15:52:19 -0500 Subject: [PATCH] (fix) handle sha512-crypt with rounds --- SoObjects/SOGo/NSData+Crypto.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/SoObjects/SOGo/NSData+Crypto.m b/SoObjects/SOGo/NSData+Crypto.m index 797e1aa29..5bf3c515e 100644 --- a/SoObjects/SOGo/NSData+Crypto.m +++ b/SoObjects/SOGo/NSData+Crypto.m @@ -721,7 +721,7 @@ static void _nettle_md5_compress(uint32_t *digest, const uint8_t *input); cryptParts = [cryptString componentsSeparatedByString: @"$"]; // correct number of elements (first one is an empty string) - if ([cryptParts count] != 4) + if ([cryptParts count] < 4) { return [NSData data]; } @@ -731,7 +731,16 @@ static void _nettle_md5_compress(uint32_t *digest, const uint8_t *input); [[cryptParts objectAtIndex: 1] caseInsensitiveCompare: @"6"] == NSOrderedSame) { // third is the salt; convert it to NSData - return [[cryptParts objectAtIndex: 2] dataUsingEncoding: NSUTF8StringEncoding]; + if ([cryptParts count] == 4) + return [[cryptParts objectAtIndex: 2] dataUsingEncoding: NSUTF8StringEncoding]; + else + { + NSString *saltWithRounds; + + saltWithRounds = [NSString stringWithFormat: @"%@$%@", [cryptParts objectAtIndex: 2], [cryptParts objectAtIndex: 3]]; + + return [saltWithRounds dataUsingEncoding: NSUTF8StringEncoding]; + } } // nothing good return [NSData data];