Accept the two possible keys for v4 crypto 1.1.x
authorstefan
Thu, 25 Nov 2010 11:46:36 -0500
branch1.1.x
changeset 303 c0665eb29f6879a240e0e6efc94321ea1c8ab505
parent 302 4341252f0a1dd703b48f3bcb6eb66a93c0035aa8
child 304 8abc11c48ee039830080690a88206802f0e247e9
push id160
push userstefan@arentz.ca
push dateThu, 25 Nov 2010 16:46:41 +0000
Accept the two possible keys for v4 crypto
Sources/NetworkAndStorage/CryptoUtils.m
--- a/Sources/NetworkAndStorage/CryptoUtils.m
+++ b/Sources/NetworkAndStorage/CryptoUtils.m
@@ -472,22 +472,31 @@ static CryptoUtils* _cryptoManager = nil
 			}
 			
 			// Storage version 4 is a lot simpler. We simply generate the initial crypto and hmac keys from the
 			// sync key. Which is possibly derived from the passphrase. We then download the crypto/keys from
 			// the server and keep those around.
 			
 			case 4:
 			{
-				// If this key is a 26 character new style sync key then decode it
+				// We accept two types of passwords for v4. Hyphenated or plain.
 			
 				NSData* passphraseData = nil;
-			
+				
 				if ([passphrase length] == 26) {
 					passphraseData = [passphrase userfriendlyBase32Decoding];
+				} else if ([passphrase isMatchedByRegex: @"^(?i)[A-Z2-9]{1}-[A-Z2-9]{5}-[A-Z2-9]{5}-[A-Z2-9]{5}-[A-Z2-9]{5}-[A-Z2-9]{5}$"]) {
+					passphrase = [passphrase stringByReplacingOccurrencesOfString: @"-" withString: @""];
+					passphraseData = [passphrase userfriendlyBase32Decoding];
+				} else {
+					[self release];
+					NSException *e = [NSException exceptionWithName:PASSPHRASE_EXCEPTION_STRING
+						reason:NSLocalizedString(@"Incorrect Secret Phrase", @"incorrect secret phrase") userInfo:nil];
+					@throw e;
+					return nil;
 				}
 				
 				// Load the keys
 				
 				NSDictionary* keys = [[self downloadKeysWithUsername: accountName passphraseData: passphraseData] retain];
 				if (keys == nil) {
 					[self release];
 					NSException *e = [NSException exceptionWithName:PASSPHRASE_EXCEPTION_STRING