Browse Source

Test v1 backward compatibility

Rob Napier 11 years ago
parent
commit
57299743b0

+ 3 - 0
RNCryptor OS X/RNCryptor OS X-Prefix.pch

@@ -2,6 +2,9 @@
 // Prefix header for all source files of the 'RNCryptor OS X' target in the 'RNCryptor OS X' project
 //
 
+// For testing
+// #define RNCRYPTOR_ALLOW_V1_BAD_HMAC
+
 #ifdef __OBJC__
 #endif
 

+ 10 - 4
RNCryptor.xcodeproj/project.pbxproj

@@ -40,6 +40,7 @@
 		FB7565241512D9BE007B808D /* RNOpenSSLEncryptor.h in Headers */ = {isa = PBXBuildFile; fileRef = FB7565241512D9BE007B808C /* RNOpenSSLEncryptor.h */; };
 		FB7565241512D9BE007B808F /* RNOpenSSLDecryptor.h in Headers */ = {isa = PBXBuildFile; fileRef = FB7565241512D9BE007B808E /* RNOpenSSLDecryptor.h */; };
 		FB7565241512D9BE007B8091 /* RNOpenSSLDecryptor.m in Sources */ = {isa = PBXBuildFile; fileRef = FB7565241512D9BE007B8090 /* RNOpenSSLDecryptor.m */; };
+		FBE1F73B16A899E400C90463 /* RNCryptorV1.enc in CopyFiles */ = {isa = PBXBuildFile; fileRef = FBE1F73A16A899D800C90463 /* RNCryptorV1.enc */; };
 		FBF7D58E167E5031004B6F0F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FB7564F31512D3C4007B806B /* Foundation.framework */; };
 		FBF7D591167E5032004B6F0F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = FBF7D590167E5032004B6F0F /* main.m */; };
 		FBF7D5A9167E515D004B6F0F /* RNCryptor.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB13427A15E0FC2300456914 /* RNCryptor.framework */; };
@@ -58,12 +59,13 @@
 /* Begin PBXCopyFilesBuildPhase section */
 		FBF7D58A167E5031004B6F0F /* CopyFiles */ = {
 			isa = PBXCopyFilesBuildPhase;
-			buildActionMask = 2147483647;
-			dstPath = /usr/share/man/man1/;
-			dstSubfolderSpec = 0;
+			buildActionMask = 12;
+			dstPath = "";
+			dstSubfolderSpec = 16;
 			files = (
+				FBE1F73B16A899E400C90463 /* RNCryptorV1.enc in CopyFiles */,
 			);
-			runOnlyForDeploymentPostprocessing = 1;
+			runOnlyForDeploymentPostprocessing = 0;
 		};
 /* End PBXCopyFilesBuildPhase section */
 
@@ -104,6 +106,7 @@
 		FB7565241512D9BE007B808E /* RNOpenSSLDecryptor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNOpenSSLDecryptor.h; sourceTree = "<group>"; };
 		FB7565241512D9BE007B8090 /* RNOpenSSLDecryptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNOpenSSLDecryptor.m; sourceTree = "<group>"; };
 		FB7565241512D9BE007B8092 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = file.md; path = README.md; sourceTree = "<group>"; };
+		FBE1F73A16A899D800C90463 /* RNCryptorV1.enc */ = {isa = PBXFileReference; lastKnownFileType = file; path = RNCryptorV1.enc; sourceTree = SOURCE_ROOT; };
 		FBF7D58C167E5031004B6F0F /* RNCryptorVectors */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = RNCryptorVectors; sourceTree = BUILT_PRODUCTS_DIR; };
 		FBF7D590167E5032004B6F0F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
 		FBF7D593167E5032004B6F0F /* RNCryptorVectors-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNCryptorVectors-Prefix.pch"; sourceTree = "<group>"; };
@@ -270,6 +273,7 @@
 			isa = PBXGroup;
 			children = (
 				FBF7D590167E5032004B6F0F /* main.m */,
+				FBE1F73A16A899D800C90463 /* RNCryptorV1.enc */,
 				FBF7D592167E5032004B6F0F /* Supporting Files */,
 			);
 			path = RNCryptorVectors;
@@ -690,6 +694,7 @@
 				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = "RNCryptorVectors/RNCryptorVectors-Prefix.pch";
+				GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
 				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
 				MACOSX_DEPLOYMENT_TARGET = 10.8;
 				ONLY_ACTIVE_ARCH = YES;
@@ -710,6 +715,7 @@
 				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = "RNCryptorVectors/RNCryptorVectors-Prefix.pch";
+				GCC_PREPROCESSOR_DEFINITIONS = "";
 				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
 				MACOSX_DEPLOYMENT_TARGET = 10.8;
 				PRODUCT_NAME = "$(TARGET_NAME)";

+ 1 - 1
RNCryptor/RNDecryptor.m

@@ -36,7 +36,7 @@ static const NSUInteger kPreambleSize = 2;
 @property (nonatomic, readwrite, copy) NSData *encryptionKey;
 @property (nonatomic, readwrite, copy) NSData *HMACKey;
 @property (nonatomic, readwrite, copy) NSString *password;
-@property (nonatomic, readwrite, assign) BOOL *hasV1HMAC;
+@property (nonatomic, readwrite, assign) BOOL hasV1HMAC;
 
 @end
 

+ 2 - 0
RNCryptorV1.enc

@@ -0,0 +1,2 @@
+ױי°מן£3muxֱש÷¾K]ילשY�Jבא€לqאֺ÷ׂ"״׀�[קrת~FF]	lװ¡”×�+U“ױש*¡;'�zתֺ|¡T�j’)�ט„ְµ´¥U¾(…+¡¢u‎_A|¹iֳ™b;s¦W�M�ץn�חb^…%±5�ּן”`5
+ֽn=י%

+ 8 - 0
RNCryptorVectors/main.m

@@ -8,6 +8,7 @@
 
 #import <Foundation/Foundation.h>
 #import "RNEncryptor.h"
+#import "RNDecryptor.h"
 #import "RNCryptorEngine.h"
 
 void Encrypt(NSString *string, NSString *password, NSData *encryptionSalt, NSData *HMACSalt, NSData *IV)
@@ -71,6 +72,13 @@ int main(int argc, const char * argv[])
                                                error:&error];
 
     [encryptedData writeToFile:@"/tmp/RNCryptor.enc" atomically:NO];
+
+    NSData *v1Data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"RNCryptorV1.enc" ofType:nil]];
+
+    NSData *decryptedData = [RNDecryptor decryptData:v1Data withPassword:password error:&error];
+    NSLog(@"decryptedData:%@", [[NSString alloc] initWithData:decryptedData encoding:NSUTF8StringEncoding]);
+    NSLog(@"error:%@", error);
+
   }
   return 0;
 }