Skip to content

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

can email encrypted img

roryclear8d385507dab3
diff --git a/clearcam/SceneState.h b/clearcam/SceneState.h
index fe42f36..dd86e0d 100644
--- a/clearcam/SceneState.h
+++ b/clearcam/SceneState.h
@@ -1,6 +1,7 @@
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import <AVFoundation/AVFoundation.h>
+#import "pgp.h"
@interface SceneState : NSObject
@@ -10,6 +11,7 @@
@property (nonatomic, strong) NSDictionary *alerts;
@property (strong, nonatomic) NSManagedObjectContext *backgroundContext;
@property (strong, nonatomic) NSDate *last_email_time;
+@property (strong, nonatomic) PGP *pgp;
- (void)sendEmailWithImageAtPath:(NSString *)imagePath;
- (void)processOutput:(NSArray *)array withImage:(CIImage *)image;
- (void)writeToFileWithString:(NSString *)customString;
diff --git a/clearcam/SceneState.m b/clearcam/SceneState.m
index 0a71495..6cbff58 100644
--- a/clearcam/SceneState.m
+++ b/clearcam/SceneState.m
@@ -2,10 +2,12 @@
#import "SettingsManager.h"
#import "AppDelegate.h"
#import <MobileCoreServices/MobileCoreServices.h> // Add this import
+#import "pgp.h"
@implementation SceneState
- (instancetype)init {
+ self.pgp = [[PGP alloc] init];
self = [super init];
if (self) {
self.lastN = [NSMutableArray array];
@@ -90,7 +92,7 @@
if (self.last_email_time && [[NSDate date] timeIntervalSinceDate:self.last_email_time] > 300) { // only once per hour? enforce server side!
self.last_email_time = [NSDate date]; // Set to now
NSLog(@"sending email");
- //[self sendEmailWithImageAtPath:filePath];
+ [self sendEmailWithImageAtPath:filePath encryptImage:NO];
} else {
NSLog(@"NOT sending an email");
}
@@ -122,13 +124,13 @@
}
}
-- (void)sendEmailWithImageAtPath:(NSString *)imagePath {
+- (void)sendEmailWithImageAtPath:(NSString *)imagePath encryptImage:(BOOL)encryptImage {
// Server details
NSString *server = @"http://192.168.1.103:8080";
NSString *endpoint = @"/";
// Email recipient address (hardcoded)
- NSString *toEmail = @"[email protected]";
+ NSString *toEmail = @"[email protected]";
// Read image file
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
@@ -137,6 +139,29 @@
return;
}
+ // Encrypt the image if enabled
+ NSString *filePathToSend = imagePath;
+ NSString *fileExtension = @"jpg";
+ if (encryptImage) {
+ // Encrypt the image and get the path to the .pgp file
+ [self.pgp encryptImageWithPublicKey:imagePath];
+ filePathToSend = [[imagePath stringByDeletingPathExtension] stringByAppendingPathExtension:@"pgp"];
+ fileExtension = @"pgp";
+
+ // Verify the encrypted file exists
+ if (![[NSFileManager defaultManager] fileExistsAtPath:filePathToSend]) {
+ NSLog(@"Failed to encrypt image or create .pgp file.");
+ return;
+ }
+ }
+
+ // Read the file to send (either the original image or the encrypted .pgp file)
+ NSData *fileData = [NSData dataWithContentsOfFile:filePathToSend];
+ if (!fileData) {
+ NSLog(@"Failed to read file data from path: %@", filePathToSend);
+ return;
+ }
+
// Generate a unique boundary
NSString *boundary = [NSString stringWithFormat:@"Boundary-%@", [[NSUUID UUID] UUIDString]];
@@ -149,11 +174,11 @@
[bodyData appendData:[toEmail dataUsingEncoding:NSUTF8StringEncoding]];
[bodyData appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
- // Add image file
+ // Add file (either image or encrypted .pgp)
[bodyData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
- [bodyData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", [imagePath lastPathComponent]] dataUsingEncoding:NSUTF8StringEncoding]];
- [bodyData appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", [self mimeTypeForFileAtPath:imagePath]] dataUsingEncoding:NSUTF8StringEncoding]];
- [bodyData appendData:imageData];
+ [bodyData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", [filePathToSend lastPathComponent]] dataUsingEncoding:NSUTF8StringEncoding]];
+ [bodyData appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", [self mimeTypeForFileAtPath:filePathToSend]] dataUsingEncoding:NSUTF8StringEncoding]];
+ [bodyData appendData:fileData];
[bodyData appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// End boundary