]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
pkcs7: write the DER encoded time
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Tue, 16 Jun 2015 15:15:04 +0000 (17:15 +0200)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Tue, 16 Jun 2015 15:15:04 +0000 (17:15 +0200)
lib/x509/common.c
lib/x509/common.h
lib/x509/pkcs7.c

index d14056606629783e8f66d138b7e121859935a17e..650fa95a7e4ac2d27ff4ec858b413eedf158173e 100644 (file)
@@ -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)
 {
index 3250276f3d79e8d5323b6e28427a4efa4becf6a9..f387eaa9caaef8692c70c55a7ed98c11752cc095 100644 (file)
@@ -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,
index 9001a61edd9b6c42ffa8f67d5c5da76b4a5d35e2..5ab06b1b054b5216efeae5c5c1c3c7a8e255d043 100644 (file)
@@ -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);