Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

efikeygen: handle tokens that do not support trust #122

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/efikeygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,28 @@ add_trust(cms_context *cms, CERTIssuerAndSN *ias,
cmsreterr(-1, cms, "Could not find certificate");

status = CERT_ChangeCertTrust(CERT_GetDefaultCertDB(), cert, &trust);
if (status != SECSuccess)
cmsreterr(-1, cms, "could not set trust for certificate");
if (status != SECSuccess) {
// Some tokens doesn't supprot trust so CERT_ChangeCertTrust writes
// it to the internal token. Authenticate internal token and retry.
PK11SlotInfo *internal_slot = PK11_GetInternalKeySlot();
if (PK11_NeedLogin(internal_slot) && !PK11_IsLoggedIn(internal_slot, cms)) {
secuPWData pwdata;
memset(&pwdata, 0, sizeof(pwdata));
pwdata.source = pwdata.orig_source = PW_PROMPT;
cms_set_pw_data(cms, &pwdata);
status = PK11_Authenticate(internal_slot, PR_TRUE, cms);
if (status != SECSuccess) {
CERT_DestroyCertificate(cert);
cmsreterr(-1, cms, "authentication failed for internal token");
}
status = CERT_ChangeCertTrust(CERT_GetDefaultCertDB(), cert, &trust);
}
}

CERT_DestroyCertificate(cert);
if (status != SECSuccess) {
cmsreterr(-1, cms, "could not set trust for certificate");
}

return 0;
}
Expand Down
Loading