Skip to content

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

unify password prompt

rorycleara09fe458d2f1
diff --git a/clearcam/DeviceStreamViewController.m b/clearcam/DeviceStreamViewController.m
index 1f4c179..f5a9d9d 100644
--- a/clearcam/DeviceStreamViewController.m
+++ b/clearcam/DeviceStreamViewController.m
@@ -222,7 +222,7 @@
- (void)promptForKeyOnSecondFailure:(NSData *)encryptedData withCompletion:(void (^)(NSData *))completion {
dispatch_async(dispatch_get_main_queue(), ^{
- [self promptUserForKeyWithCompletion:^(NSString *userProvidedKey) {
+ [[SecretManager sharedManager] promptUserForKeyFromViewController:self completion:^(NSString *userProvidedKey) {
if (userProvidedKey) {
NSData *decryptedData = [[SecretManager sharedManager] decryptData:encryptedData withKey:userProvidedKey];
if (decryptedData) {
@@ -248,34 +248,6 @@
});
}
-- (void)promptUserForKeyWithCompletion:(void (^)(NSString *))completion {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enter Decryption Key"
- message:@"Please enter the password used by your device to encrypt this data."
- preferredStyle:UIAlertControllerStyleAlert];
-
- [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- textField.placeholder = @"Decryption Key";
- textField.secureTextEntry = YES;
- }];
-
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
- style:UIAlertActionStyleDefault
- handler:^(UIAlertAction * _Nonnull action) {
- NSString *key = alert.textFields.firstObject.text;
- completion(key);
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
- style:UIAlertActionStyleCancel
- handler:^(UIAlertAction * _Nonnull action) {
- completion(nil);
- }];
-
- [alert addAction:okAction];
- [alert addAction:cancelAction];
- [self presentViewController:alert animated:YES completion:nil];
-}
-
- (void)showErrorAlertWithMessage:(NSString *)message completion:(void (^)(void))completion {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error"
message:message
diff --git a/clearcam/GalleryViewController.m b/clearcam/GalleryViewController.m
index 036356b..1ca99d1 100644
--- a/clearcam/GalleryViewController.m
+++ b/clearcam/GalleryViewController.m
@@ -471,7 +471,7 @@
}
- (void)promptUserForKeyWithAESFileURL:(NSURL *)aesFileURL encryptedData:(NSData *)encryptedData {
- [self promptUserForKeyWithCompletion:^(NSString *userProvidedKey) {
+ [[SecretManager sharedManager] promptUserForKeyFromViewController:self completion:^(NSString *userProvidedKey) {
if (userProvidedKey) {
NSData *decryptedData = [[SecretManager sharedManager] decryptData:encryptedData withKey:userProvidedKey];
if (decryptedData) {
@@ -502,34 +502,6 @@
}];
}
-- (void)promptUserForKeyWithCompletion:(void (^)(NSString *))completion {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enter Decryption Key"
- message:@"Please enter the password used by your device to encrypt this data."
- preferredStyle:UIAlertControllerStyleAlert];
-
- [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- textField.placeholder = @"Decryption Key";
- textField.secureTextEntry = YES;
- }];
-
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
- style:UIAlertActionStyleDefault
- handler:^(UIAlertAction * _Nonnull action) {
- NSString *key = alert.textFields.firstObject.text;
- completion(key);
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
- style:UIAlertActionStyleCancel
- handler:^(UIAlertAction * _Nonnull action) {
- completion(nil);
- }];
-
- [alert addAction:okAction];
- [alert addAction:cancelAction];
- [self presentViewController:alert animated:YES completion:nil];
-}
-
- (void)showErrorAlertWithMessage:(NSString *)message {
[self showErrorAlertWithMessage:message completion:nil];
}
diff --git a/clearcam/SecretManager.h b/clearcam/SecretManager.h
index 61ebc1f..9156a13 100644
--- a/clearcam/SecretManager.h
+++ b/clearcam/SecretManager.h
@@ -2,6 +2,7 @@
#define SecretManager_h
#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
@interface SecretManager : NSObject
@@ -23,6 +24,8 @@
- (NSData *)decryptData:(NSData *)encryptedData withKey:(NSString *)key;
- (NSData *)encryptData:(NSData *)data withKey:(NSString *)key;
+- (void)promptUserForKeyFromViewController:(UIViewController *)presentingViewController
+ completion:(void (^)(NSString *key))completion;
@end
diff --git a/clearcam/SecretManager.m b/clearcam/SecretManager.m
index e66d5dd..b4c4c08 100644
--- a/clearcam/SecretManager.m
+++ b/clearcam/SecretManager.m
@@ -1,6 +1,7 @@
#import "SecretManager.h"
#import <Security/Security.h>
#import <CommonCrypto/CommonCryptor.h>
+#import <UIKit/UIKit.h>
static NSString *const kServiceIdentifier = @"com.yourapp.aeskeys"; // Replace with your app's unique identifier
@@ -110,6 +111,36 @@ static NSString *const kServiceIdentifier = @"com.yourapp.aeskeys"; // Replace w
return YES;
}
+- (void)promptUserForKeyFromViewController:(UIViewController *)presentingViewController completion:(void (^)(NSString *key))completion {
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enter Decryption Key"
+ message:@"Please enter the password used by your device to encrypt this data."
+ preferredStyle:UIAlertControllerStyleAlert];
+
+ [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
+ textField.placeholder = @"Decryption Key";
+ textField.secureTextEntry = YES;
+ }];
+
+ UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction * _Nonnull action) {
+ NSString *key = alert.textFields.firstObject.text;
+ completion(key);
+ }];
+
+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
+ style:UIAlertActionStyleCancel
+ handler:^(UIAlertAction * _Nonnull action) {
+ completion(nil);
+ }];
+
+ [alert addAction:okAction];
+ [alert addAction:cancelAction];
+
+ [presentingViewController presentViewController:alert animated:YES completion:nil];
+}
+
+
- (NSArray<NSString *> *)getAllDecryptionKeys {
NSMutableArray<NSString *> *keys = [NSMutableArray array];