From: Nikos Mavrogiannopoulos Date: Tue, 16 Jun 2015 15:15:04 +0000 (+0200) Subject: pkcs7: write the DER encoded time X-Git-Tag: gnutls_3_4_2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=afa0e506834afd848ca5461f6450b528dde49fb2;p=thirdparty%2Fgnutls.git pkcs7: write the DER encoded time --- diff --git a/lib/x509/common.c b/lib/x509/common.c index d140566066..650fa95a7e 100644 --- a/lib/x509/common.c +++ b/lib/x509/common.c @@ -872,6 +872,34 @@ _gnutls_x509_set_time(ASN1_TYPE c2, const char *where, time_t tim, return 0; } +int +_gnutls_x509_set_raw_time(ASN1_TYPE c2, const char *where, time_t tim) +{ + char str_time[MAX_TIME]; + uint8_t buf[128]; + int result, len, der_len; + + result = + gtime2generalTime(tim, str_time, sizeof(str_time)); + if (result < 0) + return gnutls_assert_val(result); + len = strlen(str_time); + + buf[0] = ASN1_TAG_GENERALIZEDTime; + asn1_length_der(len, buf+1, &der_len); + + if ((unsigned)len > sizeof(buf)-der_len-1) { + return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR); + } + + memcpy(buf+1+der_len, str_time, len); + + result = asn1_write_value(c2, where, buf, len+1+der_len); + if (result != ASN1_SUCCESS) + return gnutls_assert_val(_gnutls_asn2err(result)); + return 0; +} + gnutls_x509_subject_alt_name_t _gnutls_x509_san_find_type(char *str_type) { diff --git a/lib/x509/common.h b/lib/x509/common.h index 3250276f3d..f387eaa9ca 100644 --- a/lib/x509/common.h +++ b/lib/x509/common.h @@ -75,7 +75,9 @@ #define ASN1_NULL_SIZE 2 int _gnutls_x509_set_time(ASN1_TYPE c2, const char *where, time_t tim, - int general); + int nochoice); +int +_gnutls_x509_set_raw_time(ASN1_TYPE c2, const char *where, time_t tim); int _gnutls_x509_decode_string(unsigned int etype, const uint8_t * der, size_t der_size, diff --git a/lib/x509/pkcs7.c b/lib/x509/pkcs7.c index 9001a61edd..5ab06b1b05 100644 --- a/lib/x509/pkcs7.c +++ b/lib/x509/pkcs7.c @@ -1756,7 +1756,7 @@ static int add_attrs(ASN1_TYPE c2, const char *root, gnutls_pkcs7_attrs_t attrs, return _gnutls_asn2err(result); } - snprintf(name, sizeof(name), "%s.?LAST.values.?LAST", root); + snprintf(name, sizeof(name), "%s.?LAST.values.?1", root); result = asn1_write_value(c2, name, p->data.data, p->data.size); if (result != ASN1_SUCCESS) { gnutls_assert(); @@ -1811,8 +1811,8 @@ static int write_attributes(ASN1_TYPE c2, const char *root, const gnutls_datum_t return ret; } - snprintf(name, sizeof(name), "%s.?LAST.values.?LAST", root); - ret = _gnutls_x509_set_time(c2, name, gnutls_time(0), 1); + snprintf(name, sizeof(name), "%s.?LAST.values.?1", root); + ret = _gnutls_x509_set_raw_time(c2, name, gnutls_time(0)); if (result != ASN1_SUCCESS) { gnutls_assert(); ret = _gnutls_asn2err(result);