summaryrefslogtreecommitdiffstats
path: root/g10/keygen.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2023-07-12 06:34:19 +0200
committerNIIBE Yutaka <gniibe@fsij.org>2023-07-12 06:34:19 +0200
commitb07b5144ff6a9208ea27fe1e1518270bd22b382c (patch)
treecc30853c7ea48400bf87860ddd8c10329395d0df /g10/keygen.c
parentgpg: Move the check by is_secured_file earlier. (diff)
downloadgnupg2-b07b5144ff6a9208ea27fe1e1518270bd22b382c.tar.xz
gnupg2-b07b5144ff6a9208ea27fe1e1518270bd22b382c.zip
gpg: Fix expiration time when Creation-Date is specified.
* g10/keygen.c (parse_expire_string_with_ct): New function, optionally supply the creation time. (parse_expire_string): Use parse_expire_string_with_ct with no creation time. (proc_parameter_file): Use parse_expire_string_with_ct possibly with the creation time. -- GnuPG-bug-id: 5252 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to '')
-rw-r--r--g10/keygen.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/g10/keygen.c b/g10/keygen.c
index 3cafc476d..594a9ee82 100644
--- a/g10/keygen.c
+++ b/g10/keygen.c
@@ -2740,14 +2740,19 @@ ask_curve (int *algo, int *subkey_algo, const char *current)
* just cope for the next few years until we get a 64-bit time_t or
* similar.
*/
-u32
-parse_expire_string( const char *string )
+static u32
+parse_expire_string_with_ct (const char *string, u32 creation_time)
{
int mult;
u32 seconds;
u32 abs_date = 0;
- u32 curtime = make_timestamp ();
time_t tt;
+ u32 curtime;
+
+ if (creation_time == (u32)-1)
+ curtime = make_timestamp ();
+ else
+ curtime = creation_time;
if (!string || !*string || !strcmp (string, "none")
|| !strcmp (string, "never") || !strcmp (string, "-"))
@@ -2767,6 +2772,13 @@ parse_expire_string( const char *string )
return seconds;
}
+u32
+parse_expire_string ( const char *string )
+{
+ return parse_expire_string_with_ct (string, (u32)-1);
+}
+
+
/* Parse a Creation-Date string which is either "1986-04-26" or
"19860426T042640". Returns 0 on error. */
static u32
@@ -4157,6 +4169,7 @@ proc_parameter_file (ctrl_t ctrl, struct para_data_s *para, const char *fname,
int is_default = 0;
int have_user_id = 0;
int err, algo;
+ u32 creation_time = (u32)-1;
/* Check that we have all required parameters. */
r = get_parameter( para, pKEYTYPE );
@@ -4322,15 +4335,13 @@ proc_parameter_file (ctrl_t ctrl, struct para_data_s *para, const char *fname,
if (r && *r->u.value && !(get_parameter_bool (para, pCARDKEY)
&& get_parameter_u32 (para, pKEYCREATIONDATE)))
{
- u32 seconds;
-
- seconds = parse_creation_string (r->u.value);
- if (!seconds)
+ creation_time = parse_creation_string (r->u.value);
+ if (!creation_time)
{
log_error ("%s:%d: invalid creation date\n", fname, r->lnr );
return -1;
}
- r->u.creation = seconds;
+ r->u.creation = creation_time;
r->key = pKEYCREATIONDATE; /* Change that entry. */
}
@@ -4340,7 +4351,7 @@ proc_parameter_file (ctrl_t ctrl, struct para_data_s *para, const char *fname,
{
u32 seconds;
- seconds = parse_expire_string( r->u.value );
+ seconds = parse_expire_string_with_ct (r->u.value, creation_time);
if( seconds == (u32)-1 )
{
log_error("%s:%d: invalid expire date\n", fname, r->lnr );