1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-17 15:44:34 +02:00

* main.h, keygen.c (parse_expire_string, ask_expire_interval), sign.c

(sign_file, clearsign_file, sign_symencrypt_file), g10.c (main), keyedit.c
(sign_uids): Use seconds rather than days internally to calculate
expiration.  We no longer need the day-based code as we don't generate v3
keys.
This commit is contained in:
David Shaw 2005-05-06 19:25:19 +00:00
parent 10f51e0714
commit 89c844bd3a
6 changed files with 65 additions and 62 deletions

View File

@ -1,5 +1,11 @@
2005-05-06 David Shaw <dshaw@jabberwocky.com> 2005-05-06 David Shaw <dshaw@jabberwocky.com>
* main.h, keygen.c (parse_expire_string, ask_expire_interval),
sign.c (sign_file, clearsign_file, sign_symencrypt_file), g10.c
(main), keyedit.c (sign_uids): Use seconds rather than days
internally to calculate expiration. We no longer need the
day-based code as we don't generate v3 keys.
* sign.c (sign_file, clearsign_file, sign_symencrypt_file): Use * sign.c (sign_file, clearsign_file, sign_symencrypt_file): Use
the default sig expire value when signing in batchmode. the default sig expire value when signing in batchmode.

View File

@ -2234,7 +2234,7 @@ main( int argc, char **argv )
case oDefSigExpire: case oDefSigExpire:
if(*pargs.r.ret_str!='\0') if(*pargs.r.ret_str!='\0')
{ {
if(parse_expire_string(pargs.r.ret_str)==-1) if(parse_expire_string(pargs.r.ret_str)==(u32)-1)
log_error(_("`%s' is not a valid signature expiration\n"), log_error(_("`%s' is not a valid signature expiration\n"),
pargs.r.ret_str); pargs.r.ret_str);
else else
@ -2246,7 +2246,7 @@ main( int argc, char **argv )
case oDefCertExpire: case oDefCertExpire:
if(*pargs.r.ret_str!='\0') if(*pargs.r.ret_str!='\0')
{ {
if(parse_expire_string(pargs.r.ret_str)==-1) if(parse_expire_string(pargs.r.ret_str)==(u32)-1)
log_error(_("`%s' is not a valid signature expiration\n"), log_error(_("`%s' is not a valid signature expiration\n"),
pargs.r.ret_str); pargs.r.ret_str);
else else

View File

@ -865,7 +865,7 @@ sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified,
if(opt.ask_cert_expire) if(opt.ask_cert_expire)
duration=ask_expire_interval(1,opt.def_cert_expire); duration=ask_expire_interval(1,opt.def_cert_expire);
else else
duration=parse_expire_string(opt.def_cert_expire)*86400L; duration=parse_expire_string(opt.def_cert_expire);
} }
if(duration) if(duration)

View File

@ -1503,46 +1503,39 @@ ask_keysize( int algo )
/**************** /****************
* Parse an expire string and return it's value in days. * Parse an expire string and return its value in seconds.
* Returns -1 on error. * Returns (u32)-1 on error.
* This isn't perfect since scan_isodatestr returns unix time, and
* OpenPGP actually allows a 32-bit time *plus* a 32-bit offset.
* Because of this, we only permit setting expirations up to 2106, but
* OpenPGP could theoretically allow up to 2242. I think we'll all
* just cope for the next few years until we get a 64-bit time_t or
* similar.
*/ */
int u32
parse_expire_string( const char *string ) parse_expire_string( const char *string )
{ {
int mult; int mult;
u32 abs_date=0; u32 seconds,abs_date=0,curtime = make_timestamp();
u32 curtime = make_timestamp();
int valid_days;
if( !*string ) if( !*string )
valid_days = 0; seconds = 0;
else if( (abs_date = scan_isodatestr(string)) && abs_date > curtime ) { else if( (abs_date = scan_isodatestr(string)) && abs_date > curtime )
/* This calculation is not perfectly okay because we seconds = abs_date - curtime;
* are later going to simply multiply by 86400 and don't else if( (mult=check_valid_days(string)) )
* correct for leapseconds. A solution would be to change seconds = atoi(string) * 86400L * mult;
* the whole implemenation to work with dates and not intervals else
* which are required for v3 keys. seconds=(u32)-1;
*/
valid_days = abs_date/86400-curtime/86400+1; return seconds;
}
else if( (mult=check_valid_days(string)) ) {
valid_days = atoi(string) * mult;
if( valid_days < 0 || valid_days > 39447 )
valid_days = 0;
}
else {
valid_days = -1;
}
return valid_days;
} }
/* object == 0 for a key, and 1 for a sig */ /* object == 0 for a key, and 1 for a sig */
u32 u32
ask_expire_interval(int object,const char *def_expire) ask_expire_interval(int object,const char *def_expire)
{ {
u32 interval;
char *answer; char *answer;
int valid_days=0;
u32 interval = 0;
switch(object) switch(object)
{ {
@ -1603,22 +1596,21 @@ ask_expire_interval(int object,const char *def_expire)
} }
cpr_kill_prompt(); cpr_kill_prompt();
trim_spaces(answer); trim_spaces(answer);
valid_days = parse_expire_string( answer ); interval = parse_expire_string( answer );
if( valid_days < 0 ) { if( interval == (u32)-1 )
{
tty_printf(_("invalid value\n")); tty_printf(_("invalid value\n"));
continue; continue;
} }
if( !valid_days ) if( !interval )
{ {
tty_printf((object==0) tty_printf((object==0)
? _("Key does not expire at all\n") ? _("Key does not expire at all\n")
: _("Signature does not expire at all\n")); : _("Signature does not expire at all\n"));
interval = 0;
} }
else { else
interval = valid_days * 86400L; {
tty_printf(object==0 tty_printf(object==0
? _("Key expires at %s\n") ? _("Key expires at %s\n")
: _("Signature expires at %s\n"), : _("Signature expires at %s\n"),
@ -1635,6 +1627,7 @@ ask_expire_interval(int object,const char *def_expire)
_("Is this correct? (y/N) ")) ) _("Is this correct? (y/N) ")) )
break; break;
} }
m_free(answer); m_free(answer);
return interval; return interval;
} }
@ -2206,18 +2199,22 @@ proc_parameter_file( struct para_data_s *para, const char *fname,
/* make KEYEXPIRE from Expire-Date */ /* make KEYEXPIRE from Expire-Date */
r = get_parameter( para, pEXPIREDATE ); r = get_parameter( para, pEXPIREDATE );
if( r && *r->u.value ) { if( r && *r->u.value )
i = parse_expire_string( r->u.value ); {
if( i < 0 ) { u32 seconds;
seconds = parse_expire_string( r->u.value );
if( seconds == (u32)-1 )
{
log_error("%s:%d: invalid expire date\n", fname, r->lnr ); log_error("%s:%d: invalid expire date\n", fname, r->lnr );
return -1; return -1;
} }
r->u.expire = i * 86400L; r->u.expire = seconds;
r->key = pKEYEXPIRE; /* change hat entry */ r->key = pKEYEXPIRE; /* change hat entry */
/* also set it for the subkey */ /* also set it for the subkey */
r = m_alloc_clear( sizeof *r + 20 ); r = m_alloc_clear( sizeof *r + 20 );
r->key = pSUBKEYEXPIRE; r->key = pSUBKEYEXPIRE;
r->u.expire = i * 86400L; r->u.expire = seconds;
r->next = para; r->next = para;
para = r; para = r;
} }

View File

@ -165,7 +165,7 @@ void keyedit_menu( const char *username, STRLIST locusr,
void show_basic_key_info (KBNODE keyblock); void show_basic_key_info (KBNODE keyblock);
/*-- keygen.c --*/ /*-- keygen.c --*/
int parse_expire_string(const char *string); u32 parse_expire_string(const char *string);
u32 ask_expire_interval(int object,const char *def_expire); u32 ask_expire_interval(int object,const char *def_expire);
u32 ask_expiredate(void); u32 ask_expiredate(void);
void generate_keypair( const char *fname, const char *card_serialno, void generate_keypair( const char *fname, const char *card_serialno,

View File

@ -749,7 +749,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
if(opt.ask_sig_expire && !opt.batch) if(opt.ask_sig_expire && !opt.batch)
duration=ask_expire_interval(1,opt.def_sig_expire); duration=ask_expire_interval(1,opt.def_sig_expire);
else else
duration=parse_expire_string(opt.def_sig_expire)*86400L; duration=parse_expire_string(opt.def_sig_expire);
} }
if( (rc=build_sk_list( locusr, &sk_list, 1, PUBKEY_USAGE_SIG )) ) if( (rc=build_sk_list( locusr, &sk_list, 1, PUBKEY_USAGE_SIG )) )
@ -1019,7 +1019,7 @@ clearsign_file( const char *fname, STRLIST locusr, const char *outfile )
if(opt.ask_sig_expire && !opt.batch) if(opt.ask_sig_expire && !opt.batch)
duration=ask_expire_interval(1,opt.def_sig_expire); duration=ask_expire_interval(1,opt.def_sig_expire);
else else
duration=parse_expire_string(opt.def_sig_expire)*86400L; duration=parse_expire_string(opt.def_sig_expire);
} }
if( (rc=build_sk_list( locusr, &sk_list, 1, PUBKEY_USAGE_SIG )) ) if( (rc=build_sk_list( locusr, &sk_list, 1, PUBKEY_USAGE_SIG )) )
@ -1178,7 +1178,7 @@ sign_symencrypt_file (const char *fname, STRLIST locusr)
if(opt.ask_sig_expire && !opt.batch) if(opt.ask_sig_expire && !opt.batch)
duration=ask_expire_interval(1,opt.def_sig_expire); duration=ask_expire_interval(1,opt.def_sig_expire);
else else
duration=parse_expire_string(opt.def_sig_expire)*86400L; duration=parse_expire_string(opt.def_sig_expire);
} }
rc = build_sk_list (locusr, &sk_list, 1, PUBKEY_USAGE_SIG); rc = build_sk_list (locusr, &sk_list, 1, PUBKEY_USAGE_SIG);