diff --git a/SoObjects/SOGo/NSData+Crypto.m b/SoObjects/SOGo/NSData+Crypto.m index 0e89a8f329..70205b8306 100644 --- a/SoObjects/SOGo/NSData+Crypto.m +++ b/SoObjects/SOGo/NSData+Crypto.m @@ -607,7 +607,7 @@ - (NSData *) _asCryptedUsingSalt: (NSData *) theSalt } cryptString = [[NSString alloc] initWithData: self encoding: NSUTF8StringEncoding]; - saltData = [NSMutableData dataWithData: [[NSString stringWithFormat:@"$@$", magic] dataUsingEncoding: NSUTF8StringEncoding]]; + saltData = [NSMutableData dataWithData: [[NSString stringWithFormat:@"$%@$", magic] dataUsingEncoding: NSUTF8StringEncoding]]; [saltData appendData: theSalt]; // Terminate with "$" @@ -709,25 +709,35 @@ - (NSData *) extractSalt: (NSString *) theScheme // the crypt() function is able to extract it by itself r = NSMakeRange(0, len); } - else if ([theScheme caseInsensitiveCompare: @"md5-crypt"] == NSOrderedSame) + else if ([theScheme caseInsensitiveCompare: @"md5-crypt"] == NSOrderedSame || + [theScheme caseInsensitiveCompare: @"sha256-crypt"] == NSOrderedSame || + [theScheme caseInsensitiveCompare: @"sha512-crypt"] == NSOrderedSame) { - // md5 crypt is generated the following "$1$$" + // md5-crypt is generated the following "$1$$" + // sha256-crypt is generated the following "$5$$" + // sha512-crypt is generated the following "$6$$" NSString *cryptString; NSArray *cryptParts; - cryptString = [NSString stringWithUTF8String: [self bytes] ]; + + cryptString = [[NSString alloc] initWithData: self encoding: NSUTF8StringEncoding]; + AUTORELEASE(cryptString); + cryptParts = [cryptString componentsSeparatedByString: @"$"]; // correct number of elements (first one is an empty string) if ([cryptParts count] != 4) { return [NSData data]; } - // second is the identifier of md5-crypt - else if( [[cryptParts objectAtIndex: 1] caseInsensitiveCompare: @"1"] != NSOrderedSame ) + // second is the identifier of md5-crypt/sha256-crypt or sha512-crypt + else if ([[cryptParts objectAtIndex: 1] caseInsensitiveCompare: @"1"] == NSOrderedSame || + [[cryptParts objectAtIndex: 1] caseInsensitiveCompare: @"5"] == NSOrderedSame || + [[cryptParts objectAtIndex: 1] caseInsensitiveCompare: @"6"] == NSOrderedSame) { - return [NSData data]; - } - // third is the salt; convert it to NSData - return [[cryptParts objectAtIndex: 2] dataUsingEncoding: NSUTF8StringEncoding]; + // third is the salt; convert it to NSData + return [[cryptParts objectAtIndex: 2] dataUsingEncoding: NSUTF8StringEncoding]; + } + // nothing good + return [NSData data]; } else if ([theScheme caseInsensitiveCompare: @"ssha"] == NSOrderedSame) {