mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-07 21:53:41 +08:00
Fix ASN.1 Time
This commit is contained in:
@@ -457,7 +457,6 @@ int asn1_integer_to_der_ex(int tag, const uint8_t *a, size_t alen, uint8_t **out
|
|||||||
|
|
||||||
int asn1_int_to_der_ex(int tag, int a, uint8_t **out, size_t *outlen)
|
int asn1_int_to_der_ex(int tag, int a, uint8_t **out, size_t *outlen)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
uint8_t buf[4] = {0};
|
uint8_t buf[4] = {0};
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
@@ -915,7 +914,7 @@ int asn1_time_to_str(int utc_time, time_t timestamp, char *str)
|
|||||||
p[1] += year % 10;
|
p[1] += year % 10;
|
||||||
p[2] += month / 10;
|
p[2] += month / 10;
|
||||||
p[3] += month % 10;
|
p[3] += month % 10;
|
||||||
p[4] += day / 10;
|
p[4] += (int)day / 10;
|
||||||
p[5] += day % 10;
|
p[5] += day % 10;
|
||||||
p[6] += hour / 10;
|
p[6] += hour / 10;
|
||||||
p[7] += hour % 10;
|
p[7] += hour % 10;
|
||||||
@@ -960,7 +959,6 @@ int asn1_utc_time_to_der_ex(int tag, time_t a, uint8_t **out, size_t *outlen)
|
|||||||
|
|
||||||
int asn1_generalized_time_to_der_ex(int tag, time_t a, uint8_t **out, size_t *outlen)
|
int asn1_generalized_time_to_der_ex(int tag, time_t a, uint8_t **out, size_t *outlen)
|
||||||
{
|
{
|
||||||
struct tm tm_val;
|
|
||||||
char buf[ASN1_GENERALIZED_TIME_LEN + 1] = {0};
|
char buf[ASN1_GENERALIZED_TIME_LEN + 1] = {0};
|
||||||
int utc_time = 0;
|
int utc_time = 0;
|
||||||
|
|
||||||
@@ -1280,10 +1278,8 @@ int asn1_utc_time_from_der_ex(int tag, time_t *t, const uint8_t **pin, size_t *p
|
|||||||
{
|
{
|
||||||
const uint8_t *in = *pin;
|
const uint8_t *in = *pin;
|
||||||
size_t inlen = *pinlen;
|
size_t inlen = *pinlen;
|
||||||
struct tm tm_val;
|
|
||||||
char buf[sizeof("YYYYMMDDHHMMSSZ")] = {0};
|
char buf[sizeof("YYYYMMDDHHMMSSZ")] = {0};
|
||||||
size_t len;
|
size_t len;
|
||||||
int year;
|
|
||||||
|
|
||||||
|
|
||||||
if (!t || !pin || !(*pin) || !pinlen) {
|
if (!t || !pin || !(*pin) || !pinlen) {
|
||||||
@@ -1318,7 +1314,6 @@ int asn1_generalized_time_from_der_ex(int tag, time_t *t, const uint8_t **pin, s
|
|||||||
int ret;
|
int ret;
|
||||||
const uint8_t *in = *pin;
|
const uint8_t *in = *pin;
|
||||||
size_t inlen = *pinlen;
|
size_t inlen = *pinlen;
|
||||||
struct tm tm_val;
|
|
||||||
char buf[sizeof("YYYYMMDDHHMMSS+HHMM")] = {0};
|
char buf[sizeof("YYYYMMDDHHMMSS+HHMM")] = {0};
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
|
|||||||
@@ -25,10 +25,6 @@
|
|||||||
#include <gmssl/x509.h>
|
#include <gmssl/x509.h>
|
||||||
#include <gmssl/error.h>
|
#include <gmssl/error.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include "u_time.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
const char *x509_version_name(int version)
|
const char *x509_version_name(int version)
|
||||||
{
|
{
|
||||||
@@ -100,13 +96,16 @@ int x509_time_to_der(time_t tv, uint8_t **out, size_t *outlen)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct tm tm_val;
|
struct tm tm_val;
|
||||||
|
static time_t utc_time_max = 0;
|
||||||
|
|
||||||
#ifdef WIN32
|
if (!utc_time_max) {
|
||||||
GMSSL_gmtime(&tv, &tm_val);
|
if (asn1_time_from_str(0, &utc_time_max, "20500101000000Z") != 1) {
|
||||||
#else
|
error_print();
|
||||||
gmtime_r(&tv, &tm_val);
|
return -1;
|
||||||
#endif
|
}
|
||||||
if (tm_val.tm_year < 2050 - 1900) {
|
}
|
||||||
|
|
||||||
|
if (tv < utc_time_max) {
|
||||||
if ((ret = asn1_utc_time_to_der(tv, out, outlen)) != 1) {
|
if ((ret = asn1_utc_time_to_der(tv, out, outlen)) != 1) {
|
||||||
if (ret < 0) error_print();
|
if (ret < 0) error_print();
|
||||||
}
|
}
|
||||||
@@ -144,13 +143,7 @@ int x509_validity_add_days(time_t *not_after, time_t not_before, int days)
|
|||||||
error_print();
|
error_print();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#ifdef WIN32
|
*not_after = not_before + (time_t)days * 24 * 60 * 60;
|
||||||
GMSSL_gmtime(¬_before, &tm_val);
|
|
||||||
#else
|
|
||||||
gmtime_r(¬_before, &tm_val);
|
|
||||||
#endif
|
|
||||||
tm_val.tm_mday += days;
|
|
||||||
*not_after = mktime(&tm_val);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user