Merge pull request #10236 from akallabeth/winpr-makecert

[winpr,makecert] fix winpr-makecert month calculations
This commit is contained in:
akallabeth 2024-06-03 11:24:31 +02:00 committed by GitHub
commit eebea5ae0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 8 deletions

View File

@ -72,10 +72,10 @@ can be thought as "dummy" mode.
.IP "-n common_name"
The common name to use in the certificate.
.IP "-m months"
Validity period in months.
Validity period in months (multiple of 31 days, not clanendar months).
.IP "-y years"
Validity period in years. If months and years are specified the specified
month parameter will take precedence.
Validity period in years (365 days, leap years not accounted). If months and years are specified the specified
the values are accumulated.
.IP "-len length"
Key length in bits to use.
.IP "-a { \fImd5\fP | \fIsha1\fP | \fIsha256\fP | \fIs384\fP | \fIsha512\fP }"

View File

@ -405,7 +405,7 @@ static int makecert_context_parse_arguments(MAKECERT_CONTEXT* context,
val = strtol(arg->Value, NULL, 0);
if ((errno != 0) || (val < 1) || (val > 12))
if ((errno != 0) || (val < 0))
return -1;
context->duration_months = (int)val;
@ -999,10 +999,9 @@ int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
#endif
X509_gmtime_adj(before, 0);
if (context->duration_months)
X509_gmtime_adj(after, (long)(60 * 60 * 24 * 31 * context->duration_months));
else if (context->duration_years)
X509_gmtime_adj(after, (long)(60 * 60 * 24 * 365 * context->duration_years));
long duration = context->duration_months * 31l + context->duration_years * 365l;
duration *= 60l * 60l * 24l;
X509_gmtime_adj(after, duration);
}
X509_set_pubkey(context->x509, context->pkey);
name = X509_get_subject_name(context->x509);