Skip to content

Commit 874908d

Browse files
fix create privateKey
Signed-off-by: Marino Faggiana <[email protected]>
1 parent b3c4fe3 commit 874908d

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

Nextcloud.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5907,7 +5907,7 @@
59075907
CLANG_WARN_UNREACHABLE_CODE = YES;
59085908
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
59095909
COPY_PHASE_STRIP = NO;
5910-
CURRENT_PROJECT_VERSION = 0;
5910+
CURRENT_PROJECT_VERSION = 1;
59115911
DEBUG_INFORMATION_FORMAT = dwarf;
59125912
DEVELOPMENT_TEAM = NKUJUXUJ3B;
59135913
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -5973,7 +5973,7 @@
59735973
CLANG_WARN_UNREACHABLE_CODE = YES;
59745974
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
59755975
COPY_PHASE_STRIP = NO;
5976-
CURRENT_PROJECT_VERSION = 0;
5976+
CURRENT_PROJECT_VERSION = 1;
59775977
DEVELOPMENT_TEAM = NKUJUXUJ3B;
59785978
ENABLE_STRICT_OBJC_MSGSEND = YES;
59795979
ENABLE_TESTABILITY = YES;

iOSClient/Networking/E2EE/NCEndToEndEncryption.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
- (NSString *)createCSR:(NSString *)userId directory:(NSString *)directory;
2020
- (NSString *)encryptPrivateKey:(NSString *)userId directory: (NSString *)directory passphrase:(NSString *)passphrase privateKey:(NSString **)privateKey;
2121
- (NSData *)decryptPrivateKey:(NSString *)privateKey passphrase:(NSString *)passphrase;
22-
- (BOOL)isValidPrivateKeyPEM:(NSString *)privateKeyPEM;
2322

2423
// Encrypt / Decrypt file material
2524

iOSClient/Networking/E2EE/NCEndToEndEncryption.m

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,6 @@ void nk_openssl_load_legacy_provider_if_needed(void) {
7070
}
7171
}
7272

73-
- (BOOL)isValidPrivateKeyPEM:(NSString *)privateKeyPEM {
74-
const char *pemCString = [privateKeyPEM UTF8String];
75-
BIO *bio = BIO_new_mem_buf((void *)pemCString, -1);
76-
if (!bio) return NO;
77-
78-
EVP_PKEY *pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);
79-
BIO_free(bio);
80-
81-
if (pkey) {
82-
EVP_PKEY_free(pkey);
83-
return YES;
84-
} else {
85-
ERR_print_errors_fp(stderr); // ti stampa l’errore dettagliato
86-
return NO;
87-
}
88-
}
89-
9073
#
9174
#pragma mark - Generate Certificate X509 - CSR - Private Key
9275
#
@@ -360,8 +343,10 @@ - (NSString *)encryptPrivateKey:(NSString *)userId directory:(NSString *)directo
360343
NSMutableData *key = [NSMutableData dataWithLength:PBKDF2_KEY_LENGTH / 8];
361344
NSData *salt = [self generateSalt:AES_SALT_LENGTH];
362345

346+
// Clean passphrase
363347
passphrase = [passphrase stringByReplacingOccurrencesOfString:@" " withString:@""];
364348

349+
// PBKDF2-HMAC-SHA256
365350
CCKeyDerivationPBKDF(kCCPBKDF2,
366351
passphrase.UTF8String,
367352
(int)passphrase.length,
@@ -375,14 +360,18 @@ - (NSString *)encryptPrivateKey:(NSString *)userId directory:(NSString *)directo
375360
NSData *initializationVector = [self generateIV:AES_IVEC_LENGTH];
376361
NSMutableData *authenticationTag = [NSMutableData dataWithLength:AES_TAG_LENGTH];
377362

363+
// Base64 encode private key
378364
NSString *pkEncoded = [_privateKeyData base64EncodedStringWithOptions:0];
379365
NSData *pkEncodedData = [pkEncoded dataUsingEncoding:NSUTF8StringEncoding];
380366

381-
BOOL result = [self encryptData:pkEncodedData cipher:&cipher key:key keyLen:AES_KEY_256_LENGTH initializationVector:initializationVector authenticationTag:&authenticationTag];
367+
BOOL result = [self encryptData:pkEncodedData
368+
cipher:&cipher
369+
key:key
370+
keyLen:AES_KEY_256_LENGTH
371+
initializationVector:initializationVector
372+
authenticationTag:&authenticationTag];
382373

383374
if (result && cipher) {
384-
[cipher appendData:authenticationTag]; // Append tag at the end
385-
386375
NSString *cipherString = [cipher base64EncodedStringWithOptions:0];
387376
NSString *ivString = [initializationVector base64EncodedStringWithOptions:0];
388377
NSString *saltString = [salt base64EncodedStringWithOptions:0];
@@ -392,6 +381,7 @@ - (NSString *)encryptPrivateKey:(NSString *)userId directory:(NSString *)directo
392381
ivString, IV_DELIMITER_ENCODED,
393382
saltString];
394383

384+
// Output: decoded private key (for UI, debug, etc.)
395385
NSString *decodedPrivateKey = [[NSString alloc] initWithData:_privateKeyData encoding:NSUTF8StringEncoding];
396386
if (!decodedPrivateKey) {
397387
decodedPrivateKey = [_privateKeyData base64EncodedStringWithOptions:0];

0 commit comments

Comments
 (0)