libtasn1-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU libtasn1 branch, master, updated. libtasn1_4_2-14-g5ad06db


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU libtasn1 branch, master, updated. libtasn1_4_2-14-g5ad06db
Date: Fri, 06 Mar 2015 09:33:43 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU libtasn1".

http://git.savannah.gnu.org/cgit/libtasn1.git/commit/?id=5ad06db9ebdf2139d12331f83d48d77853ad55ef

The branch, master has been updated
       via  5ad06db9ebdf2139d12331f83d48d77853ad55ef (commit)
       via  7fa2798449b8f0cf673fd7206b65982acdde8439 (commit)
       via  0ce4c07330905cf77108dd7a4685d56bc6d5f72d (commit)
      from  b7e5386d669d72fcec154d571d28e128ffc5db1b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5ad06db9ebdf2139d12331f83d48d77853ad55ef
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Fri Mar 6 10:33:35 2015 +0100

    updated error text in Test_choice_ocsp

commit 7fa2798449b8f0cf673fd7206b65982acdde8439
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Fri Mar 6 10:30:10 2015 +0100

    simplified string test for BER

commit 0ce4c07330905cf77108dd7a4685d56bc6d5f72d
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Fri Mar 6 09:32:44 2015 +0100

    asn1_decode_simple_ber() will decode unsupported types as DER

-----------------------------------------------------------------------

Summary of changes:
 lib/decoding.c           |   68 +++++++++++++++++++++++++---------------------
 lib/libtasn1.h           |    2 +-
 tests/Test_choice_ocsp.c |    2 +-
 tests/Test_strings.c     |   16 +++++++----
 4 files changed, 49 insertions(+), 39 deletions(-)

diff --git a/lib/decoding.c b/lib/decoding.c
index 2ccd1a3..e858f0a 100644
--- a/lib/decoding.c
+++ b/lib/decoding.c
@@ -2145,7 +2145,7 @@ asn1_decode_simple_der (unsigned int etype, const 
unsigned char *der,
   return ASN1_SUCCESS;
 }
 
-static int append(uint8_t **dst, unsigned *dst_size, const uint8_t *src, 
unsigned src_size)
+static int append(uint8_t **dst, unsigned *dst_size, const unsigned char *src, 
unsigned src_size)
 {
   *dst = realloc(*dst, *dst_size+src_size);
   if (*dst == NULL)
@@ -2165,7 +2165,8 @@ static int append(uint8_t **dst, unsigned *dst_size, 
const uint8_t *src, unsigne
  * @ber_len: the total length occupied by BER (may be %NULL)
  *
  * Decodes a BER encoded type. The output is an allocated value 
- * of the data. This function works for OCTET STRINGS only.
+ * of the data. This decodes BER STRINGS only. Other types are
+ * decoded as DER.
  *
  * Returns: %ASN1_SUCCESS if successful or an error value.
  **/
@@ -2181,6 +2182,8 @@ asn1_decode_simple_ber (unsigned int etype, const 
unsigned char *der,
   unsigned total_size = 0;
   unsigned char class;
   unsigned long tag;
+  unsigned char *out = NULL;
+  unsigned out_len;
   long ret;
 
   if (ber_len) *ber_len = 0;
@@ -2220,15 +2223,21 @@ asn1_decode_simple_ber (unsigned int etype, const 
unsigned char *der,
       return ASN1_DER_ERROR;
     }
 
-  if (class == ASN1_CLASS_STRUCTURED)
+  p += tag_len;
+  der_len -= tag_len;
+  if (der_len <= 0)
+    return ASN1_DER_ERROR;
+
+  if (class == ASN1_CLASS_STRUCTURED && (etype == ASN1_ETYPE_GENERALSTRING ||
+      etype == ASN1_ETYPE_NUMERIC_STRING || etype == ASN1_ETYPE_IA5_STRING ||
+      etype == ASN1_ETYPE_TELETEX_STRING || etype == 
ASN1_ETYPE_PRINTABLE_STRING ||
+      etype == ASN1_ETYPE_UNIVERSAL_STRING || etype == ASN1_ETYPE_BMP_STRING ||
+      etype == ASN1_ETYPE_UTF8_STRING || etype == ASN1_ETYPE_VISIBLE_STRING ||
+      etype == ASN1_ETYPE_OCTET_STRING))
     {
-      p += tag_len;
-      der_len -= tag_len;
-      if (der_len <= 0)
-        return ASN1_DER_ERROR;
 
-      ret = asn1_get_length_ber (p, der_len, &len_len);
-      if (ret < 0)
+      len_len = 1;
+      if (p[0] != 0x80)
         {
           warn();
           return ASN1_DER_ERROR;
@@ -2239,13 +2248,11 @@ asn1_decode_simple_ber (unsigned int etype, const 
unsigned char *der,
       if (der_len <= 0)
         return ASN1_DER_ERROR;
 
-      if (ber_len) *ber_len += ret + len_len;
+      if (ber_len) *ber_len += len_len;
 
       /* decode the available octet strings */
       do
         {
-          uint8_t *out = NULL;
-          unsigned out_len;
           unsigned tmp_len;
 
           ret = asn1_decode_simple_ber(etype, p, der_len, &out, &out_len, 
&tmp_len);
@@ -2254,9 +2261,9 @@ asn1_decode_simple_ber (unsigned int etype, const 
unsigned char *der,
               free(total);
               return ret;
             }
-
           p += tmp_len;
           der_len -= tmp_len;
+          if (ber_len) *ber_len += tmp_len;
 
           if (der_len < 2) /* we need the EOC */
             {
@@ -2276,33 +2283,32 @@ asn1_decode_simple_ber (unsigned int etype, const 
unsigned char *der,
            }
 
          if (p[0] == 0 && p[1] == 0) /* EOC */
-           break;
+           {
+              if (ber_len) *ber_len += 2;
+             break;
+           }
         }
       while(1);
     }
   else if (class == ETYPE_CLASS(etype))
     {
-      p += tag_len;
-      der_len -= tag_len;
-      if (der_len <= 0)
-        return ASN1_DER_ERROR;
-
-      ret = asn1_get_length_der (p, der_len, &len_len);
-      if (ret < 0)
+      if (ber_len)
         {
-          warn();
-          return ASN1_DER_ERROR;
+          ret = asn1_get_length_der (p, der_len, &len_len);
+          if (ret < 0)
+            {
+              warn();
+              return ASN1_DER_ERROR;
+            }
+          *ber_len += ret + len_len;
         }
 
-      p += len_len;
-      der_len -= len_len;
-      if (der_len <= 0)
-        return ASN1_DER_ERROR;
-
-      if (ber_len)
-        *ber_len += len_len + ret;
+      /* non-string values are decoded as DER */
+      ret = asn1_decode_simple_der(etype, der, _der_len, (const unsigned 
char**)&out, &out_len);
+      if (ret != ASN1_SUCCESS)
+        return ret;
 
-      ret = append(&total, &total_size, p, ret);
+      ret = append(&total, &total_size, out, out_len);
       if (ret != ASN1_SUCCESS)
         return ret;
     }
diff --git a/lib/libtasn1.h b/lib/libtasn1.h
index 1e9a61e..c0632c3 100644
--- a/lib/libtasn1.h
+++ b/lib/libtasn1.h
@@ -44,7 +44,7 @@ extern "C"
 {
 #endif
 
-#define ASN1_VERSION "4.2"
+#define ASN1_VERSION "4.3"
 
 #if defined(__GNUC__) && !defined(ASN1_INTERNAL_BUILD)
 # define _ASN1_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + 
__GNUC_PATCHLEVEL__)
diff --git a/tests/Test_choice_ocsp.c b/tests/Test_choice_ocsp.c
index 253a2e2..2deff39 100644
--- a/tests/Test_choice_ocsp.c
+++ b/tests/Test_choice_ocsp.c
@@ -63,7 +63,7 @@ main (int argc, char** argv)
 
   if (len != data_size)
     {
-      printf ("length doesn't match: known issue\n");
+      printf ("length doesn't match (got: %d, should be: %d): known issue\n", 
len, data_size);
       exit (77);
     }
 
diff --git a/tests/Test_strings.c b/tests/Test_strings.c
index c68e617..83a73cc 100644
--- a/tests/Test_strings.c
+++ b/tests/Test_strings.c
@@ -54,16 +54,20 @@ static const struct tv tv[] = {
    
"\x04\x24\x30\x22\x80\x0F\x32\x30\x31\x31\x30\x38\x32\x31\x30\x38\x30\x30\x30\x36\x5A\x81\x0F\x32\x30\x31\x31\x30\x38\x32\x33\x32\x30\x35\x39\x35\x39\x5A"}
 };
 
+#define SSTR(x) sizeof(x)-1,x
 static const struct tv ber[] = {
   {ASN1_ETYPE_OCTET_STRING, 
-   2, "\xa0\xa0",
-   10,"\x24\x80\x04\x82\x00\x02\xa0\xa0\x00\x00"},
+   SSTR("\xa0\xa0"),
+   SSTR("\x24\x80\x04\x82\x00\x02\xa0\xa0\x00\x00")},
   {ASN1_ETYPE_OCTET_STRING,
-   5, "\xa0\xa0\xb0\xb0\xb0",
-   17, "\x24\x80\x04\x82\x00\x02\xa0\xa0\x04\x82\x00\x03\xb0\xb0\xb0\x00\x00"},
+   SSTR("\xa0\xa0\xb0\xb0\xb0"),
+   
SSTR("\x24\x80\x04\x82\x00\x02\xa0\xa0\x04\x82\x00\x03\xb0\xb0\xb0\x00\x00")},
   {ASN1_ETYPE_OCTET_STRING,
-   7, "\xa0\xa0\xb0\xb0\xb0\xa1\xa1",
-   27, 
"\x24\x80\x04\x82\x00\x02\xa0\xa0\x04\x82\x00\x03\xb0\xb0\xb0\x24\x80\x04\x82\x00\x02\xa1\xa1\x00\x00\x00\x00"},
+   SSTR("\xa0\xa0\xb0\xb0\xb0\xa1\xa1"),
+   
SSTR("\x24\x80\x04\x82\x00\x02\xa0\xa0\x04\x82\x00\x03\xb0\xb0\xb0\x24\x80\x04\x82\x00\x02\xa1\xa1\x00\x00\x00\x00")},
+  {ASN1_ETYPE_OCTET_STRING,
+   SSTR("\xa0\xa0\xb0\xb0\xb0\xa1\xa1\xc1"),
+   
SSTR("\x24\x80\x04\x82\x00\x02\xa0\xa0\x04\x82\x00\x03\xb0\xb0\xb0\x24\x80\x04\x82\x00\x02\xa1\xa1\x04\x82\x00\x01\xc1\x00\x00\x00\x00")},
 };
 
 int


hooks/post-receive
-- 
GNU libtasn1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]