Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

check key

roryclear9bbd64ed4fd1
diff --git a/clearcam/SceneDelegate.m b/clearcam/SceneDelegate.m
index 82a7a2d..86ad6ec 100644
--- a/clearcam/SceneDelegate.m
+++ b/clearcam/SceneDelegate.m
@@ -57,11 +57,15 @@
}
}
+#define MAGIC_NUMBER 0x4D41474943ULL // "MAGIC" in ASCII as a 64-bit value
+#define HEADER_SIZE (sizeof(uint64_t)) // Size of the magic number (8 bytes)
+
- (NSData *)decryptData:(NSData *)encryptedData withKey:(NSString *)key {
+ // Step 1: Decrypt the entire data first (we need at least the header)
char keyPtr[kCCKeySizeAES256 + 1]; // Buffer for key
bzero(keyPtr, sizeof(keyPtr)); // Zero out buffer
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
-
+
size_t bufferSize = encryptedData.length + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
@@ -78,12 +82,34 @@
bufferSize,
&numBytesDecrypted);
- if (status == kCCSuccess) {
- return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
+ if (status != kCCSuccess) {
+ free(buffer);
+ return nil;
}
-
- free(buffer);
- return nil;
+
+ // Step 2: Check if the decrypted data is long enough to contain the header
+ if (numBytesDecrypted < HEADER_SIZE) {
+ free(buffer);
+ return nil; // Data is too short to contain a valid header
+ }
+
+ // Step 3: Extract and verify the magic number from the header
+ uint64_t decryptedMagicNumber;
+ memcpy(&decryptedMagicNumber, buffer, HEADER_SIZE);
+ if (decryptedMagicNumber != MAGIC_NUMBER) {
+ free(buffer);
+ return nil; // Wrong key or corrupted data
+ }
+
+ // Step 4: Extract the original data (skip the header)
+ size_t originalDataLength = numBytesDecrypted - HEADER_SIZE;
+ void *originalDataBuffer = malloc(originalDataLength);
+ memcpy(originalDataBuffer, buffer + HEADER_SIZE, originalDataLength);
+
+ // Step 5: Return the original data
+ NSData *result = [NSData dataWithBytesNoCopy:originalDataBuffer length:originalDataLength];
+ free(buffer); // Free the full decrypted buffer
+ return result;
}
- (void)handleAESFile:(NSURL *)aesFileURL {
diff --git a/clearcam/SceneState.m b/clearcam/SceneState.m
index 745d6b5..ce3dc3e 100644
--- a/clearcam/SceneState.m
+++ b/clearcam/SceneState.m
@@ -4,6 +4,9 @@
#import <MobileCoreServices/MobileCoreServices.h> // Add this import
#import <CommonCrypto/CommonCryptor.h>
+#define MAGIC_NUMBER 0x4D41474943ULL // "MAGIC" in ASCII as a 64-bit value
+#define HEADER_SIZE (sizeof(uint64_t)) // Size of the magic number (8 bytes)
+
@implementation SceneState
- (instancetype)init {
@@ -127,11 +130,21 @@
}
- (NSData *)encryptData:(NSData *)data withKey:(NSString *)key {
+ // Step 1: Prepare the header (magic number)
+ uint64_t magicNumber = MAGIC_NUMBER;
+ NSMutableData *headerData = [NSMutableData dataWithBytes:&magicNumber length:HEADER_SIZE];
+
+ // Step 2: Combine header and original data
+ NSMutableData *dataToEncrypt = [NSMutableData data];
+ [dataToEncrypt appendData:headerData];
+ [dataToEncrypt appendData:data];
+
+ // Step 3: Encrypt the combined data
char keyPtr[kCCKeySizeAES256 + 1]; // Buffer for key
bzero(keyPtr, sizeof(keyPtr)); // Zero out buffer
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
-
- size_t bufferSize = data.length + kCCBlockSizeAES128;
+
+ size_t bufferSize = dataToEncrypt.length + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
size_t numBytesEncrypted = 0;
@@ -140,9 +153,9 @@
kCCOptionPKCS7Padding,
keyPtr,
kCCKeySizeAES256,
- NULL,
- data.bytes,
- data.length,
+ NULL, // IV (NULL for no IV)
+ dataToEncrypt.bytes,
+ dataToEncrypt.length,
buffer,
bufferSize,
&numBytesEncrypted);
@@ -150,36 +163,7 @@
if (status == kCCSuccess) {
return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
}
-
- free(buffer);
- return nil;
-}
-
-- (NSData *)decryptData:(NSData *)encryptedData withKey:(NSString *)key {
- char keyPtr[kCCKeySizeAES256 + 1]; // Buffer for key
- bzero(keyPtr, sizeof(keyPtr)); // Zero out buffer
- [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
-
- size_t bufferSize = encryptedData.length + kCCBlockSizeAES128;
- void *buffer = malloc(bufferSize);
-
- size_t numBytesDecrypted = 0;
- CCCryptorStatus status = CCCrypt(kCCDecrypt,
- kCCAlgorithmAES,
- kCCOptionPKCS7Padding,
- keyPtr,
- kCCKeySizeAES256,
- NULL,
- encryptedData.bytes,
- encryptedData.length,
- buffer,
- bufferSize,
- &numBytesDecrypted);
- if (status == kCCSuccess) {
- return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
- }
-
free(buffer);
return nil;
}