Guest User

openssl patch for unique identifier

a guest
Dec 10th, 2015
1,076
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.46 KB | None | 0 0
  1. diff -Naur openssl-1.0.1q-clean/crypto/asn1/a_strnid.c openssl-1.0.1q-modified/crypto/asn1/a_strnid.c
  2. --- openssl-1.0.1q-clean/crypto/asn1/a_strnid.c 2015-12-03 14:04:23.000000000 +0000
  3. +++ openssl-1.0.1q-modified/crypto/asn1/a_strnid.c  2015-12-10 10:34:02.436653664 +0000
  4. @@ -133,7 +133,7 @@
  5.      ASN1_STRING_TABLE *tbl;
  6.      ASN1_STRING *str = NULL;
  7.      unsigned long mask;
  8. -    int ret;
  9. +    int ret = 0;
  10.      if (!out)
  11.          out = &str;
  12.      tbl = ASN1_STRING_TABLE_get(nid);
  13. @@ -141,8 +141,64 @@
  14.          mask = tbl->mask;
  15.          if (!(tbl->flags & STABLE_NO_MASK))
  16.              mask &= global_mask;
  17. -        ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask,
  18. -                                  tbl->minsize, tbl->maxsize);
  19. +        if (mask & B_ASN1_BIT_STRING) {
  20. +          int len = (inlen < 0 ? strlen((const char*)in) : inlen);
  21. +          unsigned char *dest = NULL;
  22. +          unsigned char *source = (unsigned char*)in;
  23. +          int i = 0;
  24. +          if (len > 2 && source[0]=='0' && source[1]=='x') {
  25. +            for (i = 2; i < len; i++) {
  26. +              if (!isxdigit(source[i])) {
  27. +                ret = -1;
  28. +                break;
  29. +              }
  30. +            }
  31. +            if (ret >= 0) {
  32. +              /* we have a hex string */
  33. +              int newlen = ((len - 2) / 2) + (len % 2);
  34. +              source = (unsigned char *)OPENSSL_malloc(newlen);
  35. +              for (i = len - 2; i > 0 && ret >= 0; i = i - 2) {
  36. +                unsigned char buf[3];
  37. +                char *endptr = NULL;
  38. +                buf[0] = i == 1 ? '0' : in[i];
  39. +                buf[1] = in[i+1];
  40. +                buf[2] = '\0';
  41. +                source[(i - 2 + (i % 2)) / 2] = (unsigned int)strtoul((const char*)buf,&endptr,16);
  42. +                if (*endptr != '\0') {
  43. +                  ret = -1;
  44. +                }
  45. +              }
  46. +              len = newlen;
  47. +            }
  48. +          }
  49. +
  50. +          if (ret >= 0) {
  51. +            dest = (unsigned char *)OPENSSL_malloc(len);
  52. +            if (dest == NULL) {
  53. +              ret = ERR_R_MALLOC_FAILURE;
  54. +            } else {
  55. +              memcpy(dest, source, len);
  56. +
  57. +              if (source != (unsigned char*)in) {
  58. +                OPENSSL_free(source);
  59. +                source = NULL;
  60. +              }
  61. +              
  62. +              (*out)->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear */
  63. +              (*out)->flags |= ASN1_STRING_FLAG_BITS_LEFT;           /* set */
  64. +              
  65. +              (*out)->length = len;
  66. +              if ((*out)->data != NULL)
  67. +                OPENSSL_free((*out)->data);
  68. +              (*out)->data = dest;
  69. +              (*out)->type = V_ASN1_BIT_STRING;
  70. +              ret = 1;
  71. +            }
  72. +          }
  73. +        } else {
  74. +          ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask,
  75. +                                    tbl->minsize, tbl->maxsize);
  76. +        }
  77.      } else
  78.          ret =
  79.              ASN1_mbstring_copy(out, in, inlen, inform,
  80. @@ -192,7 +248,8 @@
  81.      {NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
  82.      {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
  83.      {NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK},
  84. -    {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}
  85. +    {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK},
  86. +    {NID_x500UniqueIdentifier, 0, 0, B_ASN1_BIT_STRING, STABLE_NO_MASK}
  87.  };
  88.  
  89.  static int sk_table_cmp(const ASN1_STRING_TABLE *const *a,
Advertisement
Add Comment
Please, Sign In to add comment