summaryrefslogtreecommitdiff
path: root/src/gmcerts.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-08-28 19:16:20 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-08-28 19:16:20 +0300
commit48deb41856d599e78ddbfd4e9d5f3ad6ac5bb55b (patch)
tree2cbc70bdf4199bcb926ed1f9b2da0d6bd4a6765b /src/gmcerts.c
parent425b2c5468269133107b8c27d0c205162748ff82 (diff)
Deleting identities
Diffstat (limited to 'src/gmcerts.c')
-rw-r--r--src/gmcerts.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/gmcerts.c b/src/gmcerts.c
index 923987b1..3c10fff2 100644
--- a/src/gmcerts.c
+++ b/src/gmcerts.c
@@ -271,7 +271,9 @@ static void loadIdentityFromCertificate_GmCerts_(iGmCerts *d, const iString *crt
271 iBlock *finger = fingerprint_TlsCertificate(cert); 271 iBlock *finger = fingerprint_TlsCertificate(cert);
272 iGmIdentity *ident = findIdentity_GmCerts_(d, finger); 272 iGmIdentity *ident = findIdentity_GmCerts_(d, finger);
273 if (!ident) { 273 if (!ident) {
274 /* User-provided certificate. */
274 ident = new_GmIdentity(); 275 ident = new_GmIdentity();
276 ident->flags |= imported_GmIdentityFlag;
275 iDate today; 277 iDate today;
276 initCurrent_Date(&today); 278 initCurrent_Date(&today);
277 set_String(&ident->notes, collect_String(format_Date(&today, "Imported on %b %d, %Y"))); 279 set_String(&ident->notes, collect_String(format_Date(&today, "Imported on %b %d, %Y")));
@@ -390,6 +392,14 @@ iBool checkTrust_GmCerts(iGmCerts *d, iRangecc domain, const iTlsCertificate *ce
390 return iTrue; 392 return iTrue;
391} 393}
392 394
395iGmIdentity *identity_GmCerts(iGmCerts *d, unsigned int id) {
396 return at_PtrArray(&d->idents, id);
397}
398
399const iGmIdentity *constIdentity_GmCerts(const iGmCerts *d, unsigned int id) {
400 return constAt_PtrArray(&d->idents, id);
401}
402
393const iGmIdentity *identityForUrl_GmCerts(const iGmCerts *d, const iString *url) { 403const iGmIdentity *identityForUrl_GmCerts(const iGmCerts *d, const iString *url) {
394 iConstForEach(PtrArray, i, &d->idents) { 404 iConstForEach(PtrArray, i, &d->idents) {
395 const iGmIdentity *ident = i.ptr; 405 const iGmIdentity *ident = i.ptr;
@@ -438,6 +448,18 @@ iGmIdentity *newIdentity_GmCerts(iGmCerts *d, int flags, iDate validUntil, const
438 return id; 448 return id;
439} 449}
440 450
451void deleteIdentity_GmCerts(iGmCerts *d, iGmIdentity *identity) {
452 /* Only delete the files if we created them. */
453 if (!(identity->flags & (temporary_GmIdentityFlag | imported_GmIdentityFlag))) {
454 const char *finger = cstrCollect_String(hexEncode_Block(&identity->fingerprint));
455 const char *filename = concatPath_CStr(cstr_String(&d->saveDir), format_CStr("idents/%s", finger));
456 remove(format_CStr("%s.crt", filename));
457 remove(format_CStr("%s.key", filename));
458 }
459 removeOne_PtrArray(&d->idents, identity);
460 collect_GmIdentity(identity);
461}
462
441const iPtrArray *identities_GmCerts(const iGmCerts *d) { 463const iPtrArray *identities_GmCerts(const iGmCerts *d) {
442 return &d->idents; 464 return &d->idents;
443} 465}