prepare for next release
[oweals/openssl.git] / crypto / x509v3 / v3_utl.c
index 9770b516770a6a37126b9abc3428197887ccffc7..7a45216c007f5721a342f49332afd59afcc58cc2 100644 (file)
@@ -1,5 +1,5 @@
 /* v3_utl.c */
-/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project.
  */
 /* ====================================================================
@@ -63,6 +63,7 @@
 #include "cryptlib.h"
 #include <openssl/conf.h>
 #include <openssl/x509v3.h>
+#include <openssl/bn.h>
 
 static char *strip_spaces(char *name);
 static int sk_strcmp(const char * const *a, const char * const *b);
@@ -70,7 +71,6 @@ static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens);
 static void str_free(void *str);
 static int append_ia5(STACK **sk, ASN1_IA5STRING *email);
 
-static int a2i_ipadd(unsigned char *ipout, const char *ipasc);
 static int ipv4_from_asc(unsigned char *v4, const char *in);
 static int ipv6_from_asc(unsigned char *v6, const char *in);
 static int ipv6_cb(const char *elem, int len, void *usr);
@@ -84,7 +84,7 @@ int X509V3_add_value(const char *name, const char *value,
        CONF_VALUE *vtmp = NULL;
        char *tname = NULL, *tvalue = NULL;
        if(name && !(tname = BUF_strdup(name))) goto err;
-       if(value && !(tvalue = BUF_strdup(value))) goto err;;
+       if(value && !(tvalue = BUF_strdup(value))) goto err;
        if(!(vtmp = (CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE)))) goto err;
        if(!*extlist && !(*extlist = sk_CONF_VALUE_new_null())) goto err;
        vtmp->section = NULL;
@@ -365,7 +365,7 @@ char *hex_to_string(unsigned char *buffer, long len)
        char *tmp, *q;
        unsigned char *p;
        int i;
-       static char hexdig[] = "0123456789ABCDEF";
+       const static char hexdig[] = "0123456789ABCDEF";
        if(!buffer || !len) return NULL;
        if(!(tmp = OPENSSL_malloc(len * 3 + 1))) {
                X509V3err(X509V3_F_HEX_TO_STRING,ERR_R_MALLOC_FAILURE);
@@ -473,6 +473,30 @@ STACK *X509_get1_email(X509 *x)
        return ret;
 }
 
+STACK *X509_get1_ocsp(X509 *x)
+{
+       AUTHORITY_INFO_ACCESS *info;
+       STACK *ret = NULL;
+       int i;
+       info = X509_get_ext_d2i(x, NID_info_access, NULL, NULL);
+       if (!info)
+               return NULL;
+       for (i = 0; i < sk_ACCESS_DESCRIPTION_num(info); i++)
+               {
+               ACCESS_DESCRIPTION *ad = sk_ACCESS_DESCRIPTION_value(info, i);
+               if (OBJ_obj2nid(ad->method) == NID_ad_OCSP)
+                       {
+                       if (ad->location->type == GEN_URI)
+                               {
+                               if (!append_ia5(&ret, ad->location->d.uniformResourceIdentifier))
+                                       break;
+                               }
+                       }
+               }
+       AUTHORITY_INFO_ACCESS_free(info);
+       return ret;
+}
+
 STACK *X509_REQ_get1_email(X509_REQ *x)
 {
        GENERAL_NAMES *gens;
@@ -614,7 +638,7 @@ ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc)
        }
        
 
-static int a2i_ipadd(unsigned char *ipout, const char *ipasc)
+int a2i_ipadd(unsigned char *ipout, const char *ipasc)
        {
        /* If string contains a ':' assume IPv6 */
 
@@ -712,17 +736,20 @@ static int ipv6_from_asc(unsigned char *v6, const char *in)
 
        /* Format result */
 
-       /* Copy initial part */
-       if (v6stat.zero_pos > 0)
+       if (v6stat.zero_pos >= 0)
+               {
+               /* Copy initial part */
                memcpy(v6, v6stat.tmp, v6stat.zero_pos);
-       /* Zero middle */
-       if (v6stat.total != 16)
+               /* Zero middle */
                memset(v6 + v6stat.zero_pos, 0, 16 - v6stat.total);
-       /* Copy final part */
-       if (v6stat.total != v6stat.zero_pos)
-               memcpy(v6 + v6stat.zero_pos + 16 - v6stat.total,
-                       v6stat.tmp + v6stat.zero_pos,
-                       v6stat.total - v6stat.zero_pos);
+               /* Copy final part */
+               if (v6stat.total != v6stat.zero_pos)
+                       memcpy(v6 + v6stat.zero_pos + 16 - v6stat.total,
+                               v6stat.tmp + v6stat.zero_pos,
+                               v6stat.total - v6stat.zero_pos);
+               }
+       else
+               memcpy(v6, v6stat.tmp, 16);
 
        return 1;
        }
@@ -801,7 +828,7 @@ int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE)*dn_sk,
                                                unsigned long chtype)
        {
        CONF_VALUE *v;
-       int i;
+       int i, mval;
        char *p, *type;
        if (!nm)
                return 0;
@@ -824,8 +851,19 @@ int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE)*dn_sk,
                                if(*p) type = p;
                                break;
                                }
+#ifndef CHARSET_EBCDIC
+               if (*type == '+')
+#else
+               if (*type == os_toascii['+'])
+#endif
+                       {
+                       mval = -1;
+                       type++;
+                       }
+               else
+                       mval = 0;
                if (!X509_NAME_add_entry_by_txt(nm,type, chtype,
-                               (unsigned char *) v->value,-1,-1,0))
+                               (unsigned char *) v->value,-1,-1,mval))
                                        return 0;
 
                }