mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-05 16:35:10 +00:00
Improve display of S/MIME certificates
This commit is contained in:
@@ -208,60 +208,25 @@
|
||||
|
||||
if (pem)
|
||||
{
|
||||
BIO *pemBio;
|
||||
X509 *x;
|
||||
|
||||
OpenSSL_add_all_algorithms();
|
||||
ERR_load_crypto_strings();
|
||||
pemBio = BIO_new_mem_buf((void *) [pem bytes], [pem length]);
|
||||
x = PEM_read_bio_X509(pemBio, NULL, 0, NULL);
|
||||
if (x)
|
||||
data = [pem certificateDescription];
|
||||
if (data)
|
||||
{
|
||||
BIO *buf;
|
||||
char p[1024];
|
||||
NSString *subject, *issuer;
|
||||
|
||||
memset(p, 0, 1024);
|
||||
buf = BIO_new(BIO_s_mem());
|
||||
X509_NAME_print_ex(buf, X509_get_subject_name(x), 0,
|
||||
ASN1_STRFLGS_ESC_CTRL | XN_FLAG_SEP_MULTILINE | XN_FLAG_FN_LN);
|
||||
BIO_read(buf, p, 1024);
|
||||
subject = [NSString stringWithUTF8String: p];
|
||||
BIO_free(buf);
|
||||
|
||||
memset(p, 0, 1024);
|
||||
buf = BIO_new(BIO_s_mem());
|
||||
X509_NAME_print_ex(buf, X509_get_issuer_name(x), 0,
|
||||
ASN1_STRFLGS_ESC_CTRL | XN_FLAG_SEP_MULTILINE | XN_FLAG_FN_LN);
|
||||
BIO_read(buf, p, 1024);
|
||||
issuer = [NSString stringWithUTF8String: p];
|
||||
BIO_free(buf);
|
||||
|
||||
data = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[subject componentsFromMultilineDN], @"subject",
|
||||
[issuer componentsFromMultilineDN], @"issuer",
|
||||
nil];
|
||||
response = [self responseWithStatus: 200
|
||||
andJSONRepresentation: data];
|
||||
response = [self responseWithStatus: 200 andJSONRepresentation: data];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"FATAL: failed to read certificate.");
|
||||
data = [NSDictionary
|
||||
dictionaryWithObject: [self labelForKey: @"Error reading the certificate. Please install a new certificate."]
|
||||
forKey: @"message"];
|
||||
response = [self responseWithStatus: 500
|
||||
andJSONRepresentation: data];
|
||||
response = [self responseWithStatus: 500 andJSONRepresentation: data];
|
||||
}
|
||||
|
||||
BIO_free(pemBio);
|
||||
X509_free(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = [self responseWithStatus: 404
|
||||
andJSONRepresentation: [NSDictionary dictionaryWithObject: [self labelForKey: @"No certificate associated to account."]
|
||||
forKey: @"message"]];
|
||||
data = [NSDictionary
|
||||
dictionaryWithObject: [self labelForKey: @"No certificate associated to account."]
|
||||
forKey: @"message"];
|
||||
response = [self responseWithStatus: 404 andJSONRepresentation: data];
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
Reference in New Issue
Block a user