Skip to content

Commit

Permalink
efikeygen: move knowledge of key size and exponents up a level
Browse files Browse the repository at this point in the history
We need to be able to generate keys other than just RSA2048 now.  As a
result, we need to have the key generation data determined outside of
generate_keys() itself.

This makes those parameters part of the generate_keys() call, and moves
the default values into efikeygen itself.

Signed-off-by: Peter Jones <[email protected]>
  • Loading branch information
vathpela committed Nov 14, 2023
1 parent 1fb3c85 commit e02a97e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/cms_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1779,11 +1779,12 @@ generate_auth_info(cms_context *cms, SECItem *der, char *url)

int
generate_keys(cms_context *cms, PK11SlotInfo *slot,
SECKEYPrivateKey **privkey, SECKEYPublicKey **pubkey)
SECKEYPrivateKey **privkey, SECKEYPublicKey **pubkey,
int key_bits, unsigned long exponent)
{
PK11RSAGenParams rsaparams = {
.keySizeInBits = 2048,
.pe = 0x010001,
.keySizeInBits = key_bits,
.pe = exponent,
};

SECStatus rv;
Expand Down
3 changes: 2 additions & 1 deletion src/cms_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ extern int generate_signature(cms_context *ctx);
extern int unlock_nss_token(cms_context *ctx);
extern int find_certificate(cms_context *ctx, int needs_private_key);
extern int generate_keys(cms_context *cms, PK11SlotInfo *slot,
SECKEYPrivateKey **privkey, SECKEYPublicKey **pubkey);
SECKEYPrivateKey **privkey, SECKEYPublicKey **pubkey,
int key_bits, unsigned long exponent);
extern int is_issuer_of(CERTCertificate *c0, CERTCertificate *c1);

typedef int (find_cert_match_t)(CERTCertificate *cert, void *cbdata);
Expand Down
5 changes: 4 additions & 1 deletion src/efikeygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ int main(int argc, char *argv[])
PRStatus prstatus;
void *frees[50] = { NULL, };
int nfrees = 0;
int key_bits = 2048;
unsigned long exponent = 0x010001ul;

cms_context *cms = NULL;

Expand Down Expand Up @@ -1017,7 +1019,8 @@ int main(int argc, char *argv[])
nsserr(1, "could not find NSS slot for token \"%s\"",
cms->tokenname);

rc = generate_keys(cms, slot, &privkey, &pubkey);
rc = generate_keys(cms, slot, &privkey, &pubkey, key_bits,
exponent);
}
if (rc < 0)
exit(1);
Expand Down

0 comments on commit e02a97e

Please sign in to comment.