diff --git a/enzevalos_iphone/Certificate.swift b/enzevalos_iphone/Certificate.swift index 730425415db8f814811263559d739e03873dbaa5..fdaf83a1097e98f63a1052488a26530e40e746aa 100644 --- a/enzevalos_iphone/Certificate.swift +++ b/enzevalos_iphone/Certificate.swift @@ -8,8 +8,10 @@ import Foundation +/** + Contains information about a certificate + */ class Certificate { - // TODO: make all attributes private with getters let pem: String // raw PEM string let fingerPrint: String let eMails: [String]? diff --git a/enzevalos_iphone/SMIMEHelpers.swift b/enzevalos_iphone/SMIMEHelpers.swift index 8f3ba675073f71cf7a1f68f331d8e58a4b56e096..50aeccef3b3faa9b33edba3567712ab8b073587c 100644 --- a/enzevalos_iphone/SMIMEHelpers.swift +++ b/enzevalos_iphone/SMIMEHelpers.swift @@ -62,19 +62,14 @@ func getFingerprintFromPem (pem: String) -> (String?, [String]?, [UInt]?) { return (fpStr, nil, errArr) } -/** - - - errors: - - Wrong password: - error code: 101077092 - error string: EVP_DecryptFinal_ex - error code: 587690100 - error string: PKCS12_pbe_crypt - error code: 587636853 - error string: PKCS12_item_decrypt_d2i - error code: 151498765 - error string: PEM_read_bio_PrivateKey - */ + /** + Exrtracts a private key from an ecnrypted PEM + + - parameters: + - pem: key's PEM as a string + - passwd: password to decrypt the PEM + - returns:(<decrypted PEM>, <array of errors>) + */ func getPKeyFromEncryptedPem(pem: String, passwd: String) -> (String?, [UInt]?) { let res = get_pkey_from_enc_pem(pem, passwd) defer { @@ -89,6 +84,14 @@ func getFingerprintFromPem (pem: String) -> (String?, [String]?, [UInt]?) { return (pKey, errArr) } +/** + Encrypts a private key's PEM with a password (encryption key) + + - parameters: + - pem: key's PEM as a string + - passwd: password for the encryption + - returns:(<encrypted PEM>, <array of errors>) + */ func getEncryptedPemFromPKey(pem: String, passwd: String) -> (String?, [UInt]?) { let res = get_enc_pem_from_pkey(pem, passwd) defer { @@ -103,6 +106,12 @@ func getFingerprintFromPem (pem: String) -> (String?, [String]?, [UInt]?) { return (pKey, errArr) } +/** + Returns the complete string of an OpenSSL error. Includes things such as reason, function that caused it and so on + + - parameters; + - errCode: the error code + */ func getErrorString(errCode: UInt) -> String { let cStr = get_err_string(errCode); defer { @@ -116,6 +125,12 @@ func getErrorString(errCode: UInt) -> String { return "Invalid error code!" } +/** + Returns the reason part of the string of an OpenSSL error. + + - parameters; + - errCode: the error code + */ func getErrorReasonString(errCode: UInt) -> String { let cStr = get_err_reason_string(errCode); defer { @@ -129,6 +144,14 @@ func getErrorReasonString(errCode: UInt) -> String { return "Invalid error code!" } +/** + Returns the list of all e-mails from an array of certificates. Each email has only one instance in the array. + + - parameters: + - certs: an array of PEMs + + - returns:an array of emails + */ func getAllEmailsFromPEMs(certs: [String]) -> [String] { let certObjects = certs.map( { (arg) -> Certificate in return Certificate(pem: arg) @@ -161,8 +184,6 @@ enum ResultAttribute { case fingerprints } -// TODO: Bring all C struct extensions to the same file - /** A structure returned by the C crypto functions diff --git a/enzevalos_iphone/c/general-helpers.c b/enzevalos_iphone/c/general-helpers.c index e537ba48d064af03aa2430eb138c075aad5944a9..bc3c21dff6803b3f0f62d7654fa7e86b0b8d63ff 100644 --- a/enzevalos_iphone/c/general-helpers.c +++ b/enzevalos_iphone/c/general-helpers.c @@ -25,10 +25,6 @@ int get_array_size(array_with_length *arr) { char *get_err_string(unsigned long err) { char * error_permanent = malloc(256); ERR_error_string_n(err, error_permanent, 256); - // printf("\nError: %s", error_permanent); - /*char * error_permanent = (char *) malloc(strlen(error)+1); - error_permanent[strlen(error)]=0; // To Nullterminate the string - memcpy(error_permanent,error,strlen(error));*/ return error_permanent; } @@ -38,7 +34,6 @@ char *get_err_reason_string(unsigned long err) { char * error_permanent = (char *) malloc(strlen(reason_str)+1); error_permanent[strlen(reason_str)]=0; // To Nullterminate the string memcpy(error_permanent,reason_str,strlen(reason_str)); - // printf("\nError: %s", error_permanent); return error_permanent; } diff --git a/enzevalos_iphone/c/smime-helpers.c b/enzevalos_iphone/c/smime-helpers.c index 62e528307be0a781713b74ac88838ff323e0f78d..0d5569e2a5df5b05e4b65e5de66977520d36bd36 100644 --- a/enzevalos_iphone/c/smime-helpers.c +++ b/enzevalos_iphone/c/smime-helpers.c @@ -39,7 +39,6 @@ void OpenSSL_print_ver(void) { printf("%s", OPENSSL_VERSION_TEXT); } -// TODO: move this to general-helpers.c array_with_length *create_list_of_errors() { unsigned long err = 0; linked_list *head = NULL; @@ -50,8 +49,6 @@ array_with_length *create_list_of_errors() { unsigned long * arr = NULL; while ((err = ERR_get_error()) != 0) { - char error[256]; - printf("Error code from collection: %lu\nError string returned: %s\nError string from buf: %s\n", err, ERR_error_string(err, error), error); linked_list * newerr = malloc(sizeof(linked_list)); newerr->content = malloc(sizeof(unsigned long)); memcpy(newerr->content, &err, sizeof(unsigned long));