Skip to content

Commit

Permalink
(fix) fixed broken string initializations (fixes #3899)
Browse files Browse the repository at this point in the history
  • Loading branch information
extrafu committed Nov 15, 2016
1 parent d992ab9 commit 53b1cc5
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions SoObjects/SOGo/NSData+Crypto.m
Expand Up @@ -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 "$"
Expand Down Expand Up @@ -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$<salt>$<encrypted pass>"
// md5-crypt is generated the following "$1$<salt>$<encrypted pass>"
// sha256-crypt is generated the following "$5$<salt>$<encrypted pass>"
// sha512-crypt is generated the following "$6$<salt>$<encrypted pass>"
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)
{
Expand Down

0 comments on commit 53b1cc5

Please sign in to comment.