diff options
Diffstat (limited to 'src/gmcerts.c')
-rw-r--r-- | src/gmcerts.c | 37 |
1 files changed, 23 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)); |