summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2023-07-12 07:04:28 +0200
committerNIIBE Yutaka <gniibe@fsij.org>2023-07-25 04:15:22 +0200
commit96b69c1866dd960942c0c845ea3630f8884a8849 (patch)
tree2767c185d53e5838e901702e0bb1e3f875a52717
parentgpg: Fix expiration time when Creation-Date is specified. (diff)
downloadgnupg2-96b69c1866dd960942c0c845ea3630f8884a8849.tar.xz
gnupg2-96b69c1866dd960942c0c845ea3630f8884a8849.zip
gpg: Add support for Subkey-Expire-Date.
* g10/keygen.c (enum para_name): Add pSUBKEYEXPIREDATE. (proc_parameter_file): Add support for pSUBKEYEXPIREDATE. (read_parameter_file): Add "Subkey-Expire-Date". -- Cherry-pick from master commit of: 23bcb78d279ebc81ec9340356401d19cf89985f1 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
-rw-r--r--g10/keygen.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/g10/keygen.c b/g10/keygen.c
index 608867cfa..c252b0de4 100644
--- a/g10/keygen.c
+++ b/g10/keygen.c
@@ -87,6 +87,7 @@ enum para_name {
pEXPIREDATE,
pKEYEXPIRE, /* in n seconds */
pSUBKEYCREATIONDATE,
+ pSUBKEYEXPIREDATE,
pSUBKEYEXPIRE, /* in n seconds */
pAUTHKEYCREATIONDATE, /* Not yet used. */
pPASSPHRASE,
@@ -4331,12 +4332,29 @@ proc_parameter_file (ctrl_t ctrl, struct para_data_s *para, const char *fname,
return -1;
}
r->u.expire = seconds;
- r->key = pKEYEXPIRE; /* change hat entry */
- /* also set it for the subkey */
- r = xmalloc_clear( sizeof *r + 20 );
- r->key = pSUBKEYEXPIRE;
- r->u.expire = seconds;
- append_to_parameter (para, r);
+ r->key = pKEYEXPIRE; /* change that entry */
+
+ /* Make SUBKEYEXPIRE from Subkey-Expire-Date, if any. */
+ r = get_parameter( para, pSUBKEYEXPIREDATE );
+ if( r && *r->u.value )
+ {
+ seconds = parse_expire_string_with_ct (r->u.value, creation_time);
+ if( seconds == (u32)-1 )
+ {
+ log_error("%s:%d: invalid subkey expire date\n", fname, r->lnr );
+ return -1;
+ }
+ r->key = pSUBKEYEXPIRE; /* change that entry */
+ r->u.expire = seconds;
+ }
+ else
+ {
+ /* Or else, set Expire-Date for the subkey */
+ r = xmalloc_clear( sizeof *r + 20 );
+ r->key = pSUBKEYEXPIRE;
+ r->u.expire = seconds;
+ append_to_parameter (para, r);
+ }
}
do_generate_keypair (ctrl, para, outctrl, card );
@@ -4367,6 +4385,7 @@ read_parameter_file (ctrl_t ctrl, const char *fname )
{ "Name-Email", pNAMEEMAIL },
{ "Name-Comment", pNAMECOMMENT },
{ "Expire-Date", pEXPIREDATE },
+ { "Subkey-Expire-Date", pSUBKEYEXPIREDATE },
{ "Creation-Date", pCREATIONDATE },
{ "Passphrase", pPASSPHRASE },
{ "Preferences", pPREFERENCES },