]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util-decode-der: decode GeneralizedTime
authorMats Klepsland <mats.klepsland@gmail.com>
Mon, 19 Oct 2015 08:19:20 +0000 (10:19 +0200)
committerVictor Julien <victor@inliniac.net>
Sun, 25 Sep 2016 20:35:34 +0000 (22:35 +0200)
Decode ASN.1 element type GeneralizedTime in DER-encoded
structures.

src/util-decode-der.c
src/util-decode-der.h

index 00c1bccaef07567df066caa67b4d3a95c1757bcc..d3fb3237f3640a3c91f9e94e841a1b793b0a58c7 100644 (file)
@@ -88,6 +88,9 @@ static Asn1Generic * DecodeAsn1DerT61String(const unsigned char *buffer,
 static Asn1Generic * DecodeAsn1DerUTCTime(const unsigned char *buffer,
                                           uint32_t size, uint8_t depth,
                                           uint32_t *errcode);
+static Asn1Generic * DecodeAsn1DerGeneralizedTime(const unsigned char *buffer,
+                                                  uint32_t size, uint8_t depth,
+                                                  uint32_t *errcode);
 
 static Asn1Generic * Asn1GenericNew(void)
 {
@@ -220,6 +223,9 @@ static Asn1Generic * DecodeAsn1DerGeneric(const unsigned char *buffer,
         case ASN1_UTCTIME:
             child = DecodeAsn1DerUTCTime(d_ptr, el_max_size, depth+1, errcode);
             break;
+        case ASN1_GENERALIZEDTIME:
+            child = DecodeAsn1DerGeneralizedTime(d_ptr, el_max_size, depth+1, errcode);
+            break;
         default:
             /* unknown ASN.1 type */
             child = NULL;
@@ -862,6 +868,20 @@ static Asn1Generic * DecodeAsn1DerUTCTime(const unsigned char *buffer,
     return a;
 }
 
+static Asn1Generic * DecodeAsn1DerGeneralizedTime(const unsigned char *buffer,
+                                                  uint32_t max_size,
+                                                  uint8_t depth,
+                                                  uint32_t *errcode)
+{
+    Asn1Generic *a;
+
+    a = DecodeAsn1DerIA5String(buffer, max_size, depth, errcode);
+    if (a != NULL)
+        a->type = ASN1_GENERALIZEDTIME;
+
+    return a;
+}
+
 Asn1Generic * DecodeDer(const unsigned char *buffer, uint32_t size,
                         uint32_t *errcode)
 {
index b923c12d40cd9ecca6f6bd00d5894f14dd7539d3..5383b4f1d1db2b006f60a823a4463d6023739d8c 100644 (file)
 #define ASN1_CLASS_CONTEXTSPEC 2
 #define ASN1_CLASS_PRIVATE     3
 
-#define ASN1_UNKNOWN        0
-#define ASN1_BOOLEAN     0x01
-#define ASN1_INTEGER     0x02
-#define ASN1_BITSTRING   0x03
-#define ASN1_OCTETSTRING 0x04
-#define ASN1_NULL        0x05
-#define ASN1_OID         0x06
-#define ASN1_UTF8STRING  0x0c
-#define ASN1_SEQUENCE    0x10
-#define ASN1_SET         0x11
-#define ASN1_PRINTSTRING 0x13
-#define ASN1_T61STRING   0x14
-#define ASN1_IA5STRING   0x16
-#define ASN1_UTCTIME     0x17
+#define ASN1_UNKNOWN            0
+#define ASN1_BOOLEAN         0x01
+#define ASN1_INTEGER         0x02
+#define ASN1_BITSTRING       0x03
+#define ASN1_OCTETSTRING     0x04
+#define ASN1_NULL            0x05
+#define ASN1_OID             0x06
+#define ASN1_UTF8STRING      0x0c
+#define ASN1_SEQUENCE        0x10
+#define ASN1_SET             0x11
+#define ASN1_PRINTSTRING     0x13
+#define ASN1_T61STRING       0x14
+#define ASN1_IA5STRING       0x16
+#define ASN1_UTCTIME         0x17
+#define ASN1_GENERALIZEDTIME 0x18
 
 typedef struct Asn1ElementType_ {
        uint8_t cls:2;