Skip to content
Snippets Groups Projects

Resolve "SMIME Support"

Merged lazarog98 requested to merge 232-smime-support into dev
Compare and Show latest version
4 files
+ 24
5
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -70,9 +70,10 @@ array_with_length *create_list_of_errors() {
linked_list *cur = head;
int i = 0;
while (cur != NULL) {
arr[i] = (unsigned long) cur->content;
arr[i] = *((unsigned long*) cur->content);
linked_list *old = cur;
cur = cur->next;
free(old->content);
free(old);
i++;
}
@@ -93,6 +94,8 @@ result * OpenSSL_encrypt(const char *text, const char *pem) {
CMS_ContentInfo *cms = NULL;
array_with_length *temp = NULL;
result *res = malloc(sizeof(result));
res->certs = NULL;
res->num_certs = 0;
rec_cert_bio = BIO_new_mem_buf(pem, (int) strlen(pem));
@@ -145,6 +148,7 @@ deinit:
BIO_free(in);
BIO_free(out); // also frees tmp
BIO_free(rec_cert_bio);
sk_X509_pop_free(cert_stack, X509_free);
X509_free(rec_cert);
return res;
}
@@ -159,6 +163,8 @@ result * OpenSSL_decrypt(const char *str, const char *pem_cert, const char *pem_
EVP_PKEY *rkey = NULL;
result *res = malloc(sizeof(result));
array_with_length *temp = NULL;
res->certs = NULL;
res->num_certs = 0;
// this trick allows to hardcode a certificate as a string
rec_cert_bio = BIO_new_mem_buf(pem_cert, (int) strlen(pem_cert));
@@ -228,6 +234,8 @@ result * OpenSSL_sign(const char *text, const char *pem_cert, const char *pem_ke
int flags = CMS_STREAM | CMS_PARTIAL;
result *res = malloc(sizeof(result));
res->certs = NULL;
res->num_certs = 0;
array_with_length *temp = NULL;
if (detached) flags |= CMS_DETACHED;
@@ -296,6 +304,7 @@ deinit:
BIO_free(sig_key_bio);
EVP_PKEY_free(skey);
X509_free(sig_cert);
sk_X509_pop_free(cert_stack, X509_free);
return res;
}
@@ -306,6 +315,7 @@ result * OpenSSL_verify(const char *text, char **pem_cert, const int num_certs)
ver->certs = NULL;
ver->errors = NULL;
ver->res = NULL;
ver->num_certs = 0;
BIO *in = NULL, *out = NULL;
// recipient certificate
@@ -323,6 +333,7 @@ result * OpenSSL_verify(const char *text, char **pem_cert, const int num_certs)
// this trick allows to hardcode a certificate as a string
for (int i = 0; i<num_certs; i++) {
BIO *sig_cert_bio = BIO_new_mem_buf(pem_cert[i], (int) strlen(pem_cert[i]));
sig_certs[i] = NULL;
if (!sig_cert_bio) {
printf("VERT Failed reading mykey.pem!\n");
@@ -372,10 +383,13 @@ deinit:
ver->num_errors = temp->size;
free(temp);
CMS_ContentInfo_free(cms);
if (detached != NULL) BIO_free(detached);
BIO_free(in);
BIO_free(out); // also frees tmp
X509_STORE_free(cert_store);
for (int i =0;i>num_certs;i++) X509_free(sig_certs[i]); //We need to free all certs
for (int i =0;i<num_certs;i++) X509_free(sig_certs[i]); //We need to free all certs
free(sig_certs);
sk_X509_pop_free(cert_stack, X509_free);
// OpenSSL ver 1.0.2.f has a bug (seemingly) that causes a crash when freeing cms content info pointers
return ver;
}
Loading