Add object detection, tracking, mobile notifications, and search to any security camera.
remove 200kb stuff
roryclear486b36e55c2f
diff --git a/clearcam/DeviceStreamViewController.m b/clearcam/DeviceStreamViewController.mindex 452bac8..9034170 100644--- a/clearcam/DeviceStreamViewController.m+++ b/clearcam/DeviceStreamViewController.m@@ -167,7 +167,7 @@- (void)decryptAndQueueSegment:(NSData *)encryptedData withCompletion:(void (^)(NSData *))completion {if (self.decryptionKey) {- NSData *decryptedData = [[SecretManager sharedManager] decryptLiveSegment:encryptedData withKey:self.decryptionKey];+ NSData *decryptedData = [[SecretManager sharedManager] decryptData:encryptedData withKey:self.decryptionKey];if (decryptedData) {completion(decryptedData);self.decryptionFailedOnce = NO; // Reset on success@@ -201,7 +201,7 @@dispatch_async(dispatch_get_main_queue(), ^{[self promptUserForKeyWithCompletion:^(NSString *userProvidedKey) {if (userProvidedKey) {- NSData *decryptedData = [[SecretManager sharedManager] decryptLiveSegment:encryptedData withKey:userProvidedKey];+ NSData *decryptedData = [[SecretManager sharedManager] decryptData:encryptedData withKey:userProvidedKey];if (decryptedData) {// Save the valid key to keychainNSString *keyIdentifier = [NSString stringWithFormat:@"decryption_key_%@", self.deviceName];diff --git a/clearcam/SecretManager.h b/clearcam/SecretManager.hindex ebb37a5..61ebc1f 100644--- a/clearcam/SecretManager.h+++ b/clearcam/SecretManager.h@@ -23,9 +23,6 @@- (NSData *)decryptData:(NSData *)encryptedData withKey:(NSString *)key;- (NSData *)encryptData:(NSData *)data withKey:(NSString *)key;-//TODO remove these once they work-- (NSData *)decryptLiveSegment:(NSData *)encryptedDataWithIv withKey:(NSString *)key;-- (NSData *)encryptLiveSegment:(NSData *)data withKey:(NSString *)key;@enddiff --git a/clearcam/SecretManager.m b/clearcam/SecretManager.mindex 07b36dd..e66d5dd 100644--- a/clearcam/SecretManager.m+++ b/clearcam/SecretManager.m@@ -364,103 +364,4 @@ static NSString *const kServiceIdentifier = @"com.yourapp.aeskeys"; // Replace wreturn result;}-- (NSData *)decryptLiveSegment:(NSData *)encryptedDataWithIv withKey:(NSString *)key {- if (!encryptedDataWithIv || !key) return nil;- if (encryptedDataWithIv.length <= AES_BLOCK_SIZE) return nil;-- NSData *ivData = [encryptedDataWithIv subdataWithRange:NSMakeRange(0, AES_BLOCK_SIZE)];- NSData *cipherData = [encryptedDataWithIv subdataWithRange:NSMakeRange(AES_BLOCK_SIZE, encryptedDataWithIv.length - AES_BLOCK_SIZE)];-- char keyPtr[AES_KEY_SIZE + 1];- bzero(keyPtr, sizeof(keyPtr));- if (![key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]) return nil;-- size_t bufferSize = cipherData.length + AES_BLOCK_SIZE;- void *buffer = malloc(bufferSize);- if (!buffer) return nil;-- size_t numBytesDecrypted = 0;- CCCryptorStatus status = CCCrypt(kCCDecrypt,- kCCAlgorithmAES,- kCCOptionPKCS7Padding,- keyPtr,- AES_KEY_SIZE,- ivData.bytes,- cipherData.bytes,- cipherData.length,- buffer,- bufferSize,- &numBytesDecrypted);-- if (status != kCCSuccess) {- free(buffer);- return nil;- }-- if (numBytesDecrypted < sizeof(uint64_t) * 2) {- free(buffer);- return nil;- }-- uint64_t magic;- uint64_t originalLength;- memcpy(&magic, buffer, sizeof(uint64_t));- memcpy(&originalLength, buffer + sizeof(uint64_t), sizeof(uint64_t));-- if (magic != MAGIC_NUMBER || originalLength > (numBytesDecrypted - sizeof(uint64_t) * 2)) {- free(buffer);- return nil;- }-- NSData *result = [NSData dataWithBytes:(buffer + sizeof(uint64_t) * 2) length:originalLength];- free(buffer);- return result;-}--- (NSData *)encryptLiveSegment:(NSData *)data withKey:(NSString *)key {- if (!data || !key) return nil;-- uint64_t magic = MAGIC_NUMBER;- uint64_t originalLength = data.length;-- NSMutableData *plaintext = [NSMutableData data];- [plaintext appendBytes:&magic length:sizeof(magic)];- [plaintext appendBytes:&originalLength length:sizeof(originalLength)];- [plaintext appendData:data];-- char keyPtr[AES_KEY_SIZE];- bzero(keyPtr, sizeof(keyPtr));- if (![key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]) return nil;-- uint8_t iv[AES_BLOCK_SIZE];- if (SecRandomCopyBytes(kSecRandomDefault, sizeof(iv), iv) != errSecSuccess) return nil;-- size_t bufferSize = plaintext.length + AES_BLOCK_SIZE;- void *buffer = malloc(bufferSize);- if (!buffer) return nil;-- size_t numBytesEncrypted = 0;- CCCryptorStatus status = CCCrypt(kCCEncrypt,- kCCAlgorithmAES,- kCCOptionPKCS7Padding,- keyPtr,- AES_KEY_SIZE,- iv,- plaintext.bytes,- plaintext.length,- buffer,- bufferSize,- &numBytesEncrypted);-- if (status != kCCSuccess) {- free(buffer);- return nil;- }-- NSMutableData *final = [NSMutableData dataWithBytes:iv length:sizeof(iv)];- [final appendBytes:buffer length:numBytesEncrypted];- free(buffer);- return final;-}-@enddiff --git a/clearcam/ViewController.m b/clearcam/ViewController.mindex 67a1f69..cb767a5 100644--- a/clearcam/ViewController.m+++ b/clearcam/ViewController.m@@ -987,81 +987,23 @@ NSMutableDictionary *classColorMap;[request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)fileData.length] forHTTPHeaderField:@"Content-Length"];NSString *encryptionKey = [[SecretManager sharedManager] getEncryptionKey];if (!encryptionKey) return;- fileData = [self encryptData:fileData withKey:encryptionKey];-- NSInteger targetSize = 200*1024;- NSMutableData *mutableFileData = [fileData mutableCopy];- if (mutableFileData.length < targetSize) {- NSUInteger paddingNeeded = targetSize - mutableFileData.length;- NSMutableData *padding = [NSMutableData dataWithLength:paddingNeeded];- [mutableFileData appendData:padding];- }-+ fileData = [[SecretManager sharedManager] encryptData:fileData withKey:encryptionKey];+[[[NSURLSession sharedSession] uploadTaskWithRequest:request- fromData:mutableFileData+ fromData:fileDatacompletionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;- NSLog(@"size of segment.mp4.aes: %.2f KB", (float)mutableFileData.length / 1024.0);+ NSLog(@"size of segment.mp4.aes: %.2f KB", (float)fileData.length / 1024.0);if (error) {NSLog(@"❌ Upload failed: %@", error);} else if (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300) {- NSLog(@"✅ Uploaded segment.mp4.aes: %.2f KB", (float)mutableFileData.length / 1024.0);+ NSLog(@"✅ Uploaded segment.mp4.aes: %.2f KB", (float)fileData.length / 1024.0);} else {NSLog(@"❌ Upload failed with status %ld", (long)httpResponse.statusCode);}}] resume];}-#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)-#define AES_BLOCK_SIZE kCCBlockSizeAES128-#define AES_KEY_SIZE kCCKeySizeAES256-- (NSData *)encryptData:(NSData *)data withKey:(NSString *)key {- if (!data || !key) return nil;-- uint64_t magic = MAGIC_NUMBER;- uint64_t originalLength = data.length;-- NSMutableData *plaintext = [NSMutableData data];- [plaintext appendBytes:&magic length:sizeof(magic)];- [plaintext appendBytes:&originalLength length:sizeof(originalLength)];- [plaintext appendData:data];-- char keyPtr[AES_KEY_SIZE];- bzero(keyPtr, sizeof(keyPtr));- if (![key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]) return nil;-- uint8_t iv[AES_BLOCK_SIZE];- if (SecRandomCopyBytes(kSecRandomDefault, sizeof(iv), iv) != errSecSuccess) return nil;-- size_t bufferSize = plaintext.length + AES_BLOCK_SIZE;- void *buffer = malloc(bufferSize);- if (!buffer) return nil;-- size_t numBytesEncrypted = 0;- CCCryptorStatus status = CCCrypt(kCCEncrypt,- kCCAlgorithmAES,- kCCOptionPKCS7Padding,- keyPtr,- AES_KEY_SIZE,- iv,- plaintext.bytes,- plaintext.length,- buffer,- bufferSize,- &numBytesEncrypted);-- if (status != kCCSuccess) {- free(buffer);- return nil;- }-- NSMutableData *final = [NSMutableData dataWithBytes:iv length:sizeof(iv)];- [final appendBytes:buffer length:numBytesEncrypted];- free(buffer);- return final;-}-- (NSString *)jsonStringFromDictionary:(NSDictionary *)dictionary {NSError *error;NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:&error];