diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-01-04 13:17:28 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-01-04 13:17:28 +0200 |
commit | 4aaf21a1b7cd6b08ec2650d5c7d95b0adfadf17b (patch) | |
tree | 080185ba1abf76b28922daa88fefd9a08ecc48b5 | |
parent | ac0e8b024707ac16b1960bc167961170e956cb0f (diff) |
GmCerts: Importing an existing certificate
-rw-r--r-- | src/gmcerts.c | 37 | ||||
-rw-r--r-- | src/gmcerts.h | 1 |
2 files changed, 24 insertions, 14 deletions
diff --git a/src/gmcerts.c b/src/gmcerts.c index a1df1d20..0a5638fa 100644 --- a/src/gmcerts.c +++ b/src/gmcerts.c | |||
@@ -473,21 +473,9 @@ done: | |||
473 | return found; | 473 | return found; |
474 | } | 474 | } |
475 | 475 | ||
476 | iGmIdentity *newIdentity_GmCerts(iGmCerts *d, int flags, iDate validUntil, const iString *commonName, | 476 | static iGmIdentity *add_GmCerts_(iGmCerts *d, iTlsCertificate *cert, int flags) { |
477 | const iString *email, const iString *userId, const iString *domain, | ||
478 | const iString *org, const iString *country) { | ||
479 | const iTlsCertificateName names[] = { | ||
480 | { issuerCommonName_TlsCertificateNameType, commonName }, | ||
481 | { subjectCommonName_TlsCertificateNameType, commonName }, | ||
482 | { subjectEmailAddress_TlsCertificateNameType, !isEmpty_String(email) ? email : NULL }, | ||
483 | { subjectUserId_TlsCertificateNameType, !isEmpty_String(userId) ? userId : NULL }, | ||
484 | { subjectDomain_TlsCertificateNameType, !isEmpty_String(domain) ? domain : NULL }, | ||
485 | { subjectOrganization_TlsCertificateNameType, !isEmpty_String(org) ? org : NULL }, | ||
486 | { subjectCountry_TlsCertificateNameType, !isEmpty_String(country) ? country : NULL }, | ||
487 | { 0, NULL } | ||
488 | }; | ||
489 | iGmIdentity *id = new_GmIdentity(); | 477 | iGmIdentity *id = new_GmIdentity(); |
490 | setCertificate_GmIdentity_(id, newSelfSignedRSA_TlsCertificate(2048, validUntil, names)); | 478 | setCertificate_GmIdentity_(id, cert); |
491 | /* Save the certificate and private key as PEM files. */ | 479 | /* Save the certificate and private key as PEM files. */ |
492 | if (~flags & temporary_GmIdentityFlag) { | 480 | if (~flags & temporary_GmIdentityFlag) { |
493 | const char *finger = cstrCollect_String(hexEncode_Block(&id->fingerprint)); | 481 | const char *finger = cstrCollect_String(hexEncode_Block(&id->fingerprint)); |
@@ -508,6 +496,27 @@ iGmIdentity *newIdentity_GmCerts(iGmCerts *d, int flags, iDate validUntil, const | |||
508 | return id; | 496 | return id; |
509 | } | 497 | } |
510 | 498 | ||
499 | iGmIdentity *newIdentity_GmCerts(iGmCerts *d, int flags, iDate validUntil, const iString *commonName, | ||
500 | const iString *email, const iString *userId, const iString *domain, | ||
501 | const iString *org, const iString *country) { | ||
502 | const iTlsCertificateName names[] = { | ||
503 | { issuerCommonName_TlsCertificateNameType, commonName }, | ||
504 | { subjectCommonName_TlsCertificateNameType, commonName }, | ||
505 | { subjectEmailAddress_TlsCertificateNameType, !isEmpty_String(email) ? email : NULL }, | ||
506 | { subjectUserId_TlsCertificateNameType, !isEmpty_String(userId) ? userId : NULL }, | ||
507 | { subjectDomain_TlsCertificateNameType, !isEmpty_String(domain) ? domain : NULL }, | ||
508 | { subjectOrganization_TlsCertificateNameType, !isEmpty_String(org) ? org : NULL }, | ||
509 | { subjectCountry_TlsCertificateNameType, !isEmpty_String(country) ? country : NULL }, | ||
510 | { 0, NULL } | ||
511 | }; | ||
512 | return add_GmCerts_(d, newSelfSignedRSA_TlsCertificate(2048, validUntil, names), flags); | ||
513 | } | ||
514 | |||
515 | void importIdentity_GmCerts(iGmCerts *d, iTlsCertificate *cert, const iString *notes) { | ||
516 | iGmIdentity *id = add_GmCerts_(d, cert, 0); | ||
517 | set_String(&id->notes, notes); | ||
518 | } | ||
519 | |||
511 | static const char *certPath_GmCerts_(const iGmCerts *d, const iGmIdentity *identity) { | 520 | static const char *certPath_GmCerts_(const iGmCerts *d, const iGmIdentity *identity) { |
512 | if (!(identity->flags & (temporary_GmIdentityFlag | imported_GmIdentityFlag))) { | 521 | if (!(identity->flags & (temporary_GmIdentityFlag | imported_GmIdentityFlag))) { |
513 | const char *finger = cstrCollect_String(hexEncode_Block(&identity->fingerprint)); | 522 | const char *finger = cstrCollect_String(hexEncode_Block(&identity->fingerprint)); |
diff --git a/src/gmcerts.h b/src/gmcerts.h index a28c44b4..af116433 100644 --- a/src/gmcerts.h +++ b/src/gmcerts.h | |||
@@ -80,6 +80,7 @@ iGmIdentity * newIdentity_GmCerts (iGmCerts *, int flags, iDate validU | |||
80 | const iString *userId, const iString *domain, | 80 | const iString *userId, const iString *domain, |
81 | const iString *org, const iString *country); | 81 | const iString *org, const iString *country); |
82 | 82 | ||
83 | void importIdentity_GmCerts (iGmCerts *, iTlsCertificate *cert, const iString *notes); /* takes ownership */ | ||
83 | void deleteIdentity_GmCerts (iGmCerts *, iGmIdentity *identity); | 84 | void deleteIdentity_GmCerts (iGmCerts *, iGmIdentity *identity); |
84 | 85 | ||
85 | const iString * certificatePath_GmCerts (const iGmCerts *, const iGmIdentity *identity); | 86 | const iString * certificatePath_GmCerts (const iGmCerts *, const iGmIdentity *identity); |