Explorar el Código

Fix cross-module errors.

Some files in crypto/x509 were moved from crypto/asn1, so they emit errors from
another module. Fix make_errors.go to account for this: cross module errors
must use the foreign module as the first argument to OPENSSL_PUT_ERROR. Both
the function code and the error code should be declared in the foreign module.

Update make_errors.go to ignore cross-module error lines when deciding which
function tokens to emit.

Change-Id: Ic38377ddd56e22d033ef91318c30510762f6445d
Reviewed-on: https://boringssl-review.googlesource.com/3383
Reviewed-by: Adam Langley <agl@google.com>
kris/onging/CECPQ3_patch15
David Benjamin hace 9 años
committed by Adam Langley
padre
commit
96396b3aaa
Se han modificado 7 ficheros con 720 adiciones y 657 borrados
  1. +38
    -0
      crypto/asn1/asn1_lib.c
  2. +7
    -0
      crypto/err/asn1.errordata
  3. +626
    -619
      crypto/err/err_data.h
  4. +33
    -30
      crypto/x509/asn1_gen.c
  5. +4
    -3
      crypto/x509/i2d_pr.c
  6. +7
    -0
      include/openssl/asn1.h
  7. +5
    -5
      util/make_errors.go

+ 38
- 0
crypto/asn1/asn1_lib.c Ver fichero

@@ -63,8 +63,46 @@
#include <openssl/err.h>
#include <openssl/mem.h>


/* Used in asn1_mac.h.
* TODO(davidben): Remove this once asn1_mac.h is gone or trimmed. */
OPENSSL_DECLARE_ERROR_REASON(ASN1, MALLOC_FAILURE);

/* Cross-module errors from crypto/x509/i2d_pr.c */
OPENSSL_DECLARE_ERROR_FUNCTION(ASN1, i2d_PrivateKey);
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNSUPPORTED_PUBLIC_KEY_TYPE);

/* Cross-module errors from crypto/x509/asn1_gen.c.
* TODO(davidben): Remove these once asn1_gen.c is gone. */
OPENSSL_DECLARE_ERROR_FUNCTION(ASN1, ASN1_generate_v3);
OPENSSL_DECLARE_ERROR_FUNCTION(ASN1, asn1_cb);
OPENSSL_DECLARE_ERROR_FUNCTION(ASN1, parse_tagging);
OPENSSL_DECLARE_ERROR_FUNCTION(ASN1, append_exp);
OPENSSL_DECLARE_ERROR_FUNCTION(ASN1, asn1_str2type);
OPENSSL_DECLARE_ERROR_FUNCTION(ASN1, bitstr_cb);
OPENSSL_DECLARE_ERROR_REASON(ASN1, DEPTH_EXCEEDED);
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_BITSTRING_FORMAT);
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_BOOLEAN);
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_FORMAT);
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_HEX);
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_IMPLICIT_TAG);
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_INTEGER);
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_NESTED_TAGGING);
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_NULL_VALUE);
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_OBJECT);
OPENSSL_DECLARE_ERROR_REASON(ASN1, ILLEGAL_TIME_VALUE);
OPENSSL_DECLARE_ERROR_REASON(ASN1, INTEGER_NOT_ASCII_FORMAT);
OPENSSL_DECLARE_ERROR_REASON(ASN1, INVALID_MODIFIER);
OPENSSL_DECLARE_ERROR_REASON(ASN1, INVALID_NUMBER);
OPENSSL_DECLARE_ERROR_REASON(ASN1, LIST_ERROR);
OPENSSL_DECLARE_ERROR_REASON(ASN1, MISSING_VALUE);
OPENSSL_DECLARE_ERROR_REASON(ASN1, NOT_ASCII_FORMAT);
OPENSSL_DECLARE_ERROR_REASON(ASN1, OBJECT_NOT_ASCII_FORMAT);
OPENSSL_DECLARE_ERROR_REASON(ASN1, SEQUENCE_OR_SET_NEEDS_CONFIG);
OPENSSL_DECLARE_ERROR_REASON(ASN1, TIME_NOT_ASCII_FORMAT);
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_FORMAT);
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_TAG);
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNSUPPORTED_TYPE);

static int asn1_get_length(const unsigned char **pp,int *inf,long *rl,int max);
static void asn1_put_length(unsigned char **pp, int length);


+ 7
- 0
crypto/err/asn1.errordata Ver fichero

@@ -13,6 +13,7 @@ ASN1,function,132,ASN1_TIME_adj
ASN1,function,137,ASN1_UTCTIME_adj
ASN1,function,103,ASN1_d2i_fp
ASN1,function,101,ASN1_dup
ASN1,function,161,ASN1_generate_v3
ASN1,function,158,ASN1_get_object
ASN1,function,145,ASN1_i2d_bio
ASN1,function,153,ASN1_i2d_fp
@@ -36,6 +37,8 @@ ASN1,function,123,a2d_ASN1_OBJECT
ASN1,function,160,a2i_ASN1_ENUMERATED
ASN1,function,114,a2i_ASN1_INTEGER
ASN1,function,102,a2i_ASN1_STRING
ASN1,function,162,append_exp
ASN1,function,163,asn1_cb
ASN1,function,152,asn1_check_tlen
ASN1,function,156,asn1_collate_primitive
ASN1,function,115,asn1_collect
@@ -45,8 +48,10 @@ ASN1,function,107,asn1_do_adb
ASN1,function,109,asn1_ex_c2i
ASN1,function,149,asn1_find_end
ASN1,function,105,asn1_item_ex_combine_new
ASN1,function,164,asn1_str2type
ASN1,function,100,asn1_template_ex_d2i
ASN1,function,141,asn1_template_noexp_d2i
ASN1,function,165,bitstr_cb
ASN1,function,142,c2i_ASN1_BIT_STRING
ASN1,function,110,c2i_ASN1_INTEGER
ASN1,function,118,c2i_ASN1_OBJECT
@@ -58,7 +63,9 @@ ASN1,function,147,d2i_ASN1_UTCTIME
ASN1,function,159,d2i_ASN1_bytes
ASN1,function,113,d2i_ASN1_type_bytes
ASN1,function,131,i2d_ASN1_TIME
ASN1,function,166,i2d_PrivateKey
ASN1,function,121,long_c2i
ASN1,function,167,parse_tagging
ASN1,reason,101,ADDING_OBJECT
ASN1,reason,158,ASN1_LENGTH_MISMATCH
ASN1,reason,123,ASN1_PARSE_ERROR


+ 626
- 619
crypto/err/err_data.h
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 33
- 30
crypto/x509/asn1_gen.c Ver fichero

@@ -65,6 +65,9 @@
#include <openssl/x509v3.h>


/* Although this file is in crypto/x509 for layering purposes, it emits errors
* from the ASN.1 module for OpenSSL compatibility. */

#define ASN1_GEN_FLAG 0x10000
#define ASN1_GEN_FLAG_IMP (ASN1_GEN_FLAG|1)
#define ASN1_GEN_FLAG_EXP (ASN1_GEN_FLAG|2)
@@ -165,7 +168,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
{
if (!cnf)
{
OPENSSL_PUT_ERROR(X509, ASN1_generate_v3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG);
OPENSSL_PUT_ERROR(ASN1, ASN1_generate_v3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG);
return NULL;
}
ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf);
@@ -308,7 +311,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr)

if (utype == -1)
{
OPENSSL_PUT_ERROR(X509, asn1_cb, ASN1_R_UNKNOWN_TAG);
OPENSSL_PUT_ERROR(ASN1, asn1_cb, ASN1_R_UNKNOWN_TAG);
ERR_add_error_data(2, "tag=", elem);
return -1;
}
@@ -321,7 +324,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr)
/* If no value and not end of string, error */
if (!vstart && elem[len])
{
OPENSSL_PUT_ERROR(X509, asn1_cb, ASN1_R_MISSING_VALUE);
OPENSSL_PUT_ERROR(ASN1, asn1_cb, ASN1_R_MISSING_VALUE);
return -1;
}
return 0;
@@ -334,7 +337,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr)
/* Check for illegal multiple IMPLICIT tagging */
if (arg->imp_tag != -1)
{
OPENSSL_PUT_ERROR(X509, asn1_cb, ASN1_R_ILLEGAL_NESTED_TAGGING);
OPENSSL_PUT_ERROR(ASN1, asn1_cb, ASN1_R_ILLEGAL_NESTED_TAGGING);
return -1;
}
if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class))
@@ -380,7 +383,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr)
arg->format = ASN1_GEN_FORMAT_BITLIST;
else
{
OPENSSL_PUT_ERROR(X509, asn1_cb, ASN1_R_UNKNOWN_FORMAT);
OPENSSL_PUT_ERROR(ASN1, asn1_cb, ASN1_R_UNKNOWN_FORMAT);
return -1;
}
break;
@@ -404,7 +407,7 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
return 0;
if (tag_num < 0)
{
OPENSSL_PUT_ERROR(X509, parse_tagging, ASN1_R_INVALID_NUMBER);
OPENSSL_PUT_ERROR(ASN1, parse_tagging, ASN1_R_INVALID_NUMBER);
return 0;
}
*ptag = tag_num;
@@ -437,7 +440,7 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
default:
erch[0] = *eptr;
erch[1] = 0;
OPENSSL_PUT_ERROR(X509, parse_tagging, ASN1_R_INVALID_MODIFIER);
OPENSSL_PUT_ERROR(ASN1, parse_tagging, ASN1_R_INVALID_MODIFIER);
ERR_add_error_data(2, "Char=", erch);
return 0;
break;
@@ -523,13 +526,13 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons
/* Can only have IMPLICIT if permitted */
if ((arg->imp_tag != -1) && !imp_ok)
{
OPENSSL_PUT_ERROR(X509, append_exp, ASN1_R_ILLEGAL_IMPLICIT_TAG);
OPENSSL_PUT_ERROR(ASN1, append_exp, ASN1_R_ILLEGAL_IMPLICIT_TAG);
return 0;
}

if (arg->exp_count == ASN1_FLAG_EXP_MAX)
{
OPENSSL_PUT_ERROR(X509, append_exp, ASN1_R_DEPTH_EXCEEDED);
OPENSSL_PUT_ERROR(ASN1, append_exp, ASN1_R_DEPTH_EXCEEDED);
return 0;
}

@@ -647,7 +650,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)

if (!(atmp = ASN1_TYPE_new()))
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ERR_R_MALLOC_FAILURE);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ERR_R_MALLOC_FAILURE);
return NULL;
}

@@ -660,7 +663,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
case V_ASN1_NULL:
if (str && *str)
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_ILLEGAL_NULL_VALUE);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_ILLEGAL_NULL_VALUE);
goto bad_form;
}
break;
@@ -668,7 +671,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
case V_ASN1_BOOLEAN:
if (format != ASN1_GEN_FORMAT_ASCII)
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_NOT_ASCII_FORMAT);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_NOT_ASCII_FORMAT);
goto bad_form;
}
vtmp.name = NULL;
@@ -676,7 +679,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
vtmp.value = (char *)str;
if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean))
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_ILLEGAL_BOOLEAN);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_ILLEGAL_BOOLEAN);
goto bad_str;
}
break;
@@ -685,12 +688,12 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
case V_ASN1_ENUMERATED:
if (format != ASN1_GEN_FORMAT_ASCII)
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_INTEGER_NOT_ASCII_FORMAT);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_INTEGER_NOT_ASCII_FORMAT);
goto bad_form;
}
if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str)))
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_ILLEGAL_INTEGER);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_ILLEGAL_INTEGER);
goto bad_str;
}
break;
@@ -698,12 +701,12 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
case V_ASN1_OBJECT:
if (format != ASN1_GEN_FORMAT_ASCII)
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_OBJECT_NOT_ASCII_FORMAT);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_OBJECT_NOT_ASCII_FORMAT);
goto bad_form;
}
if (!(atmp->value.object = OBJ_txt2obj(str, 0)))
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_ILLEGAL_OBJECT);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_ILLEGAL_OBJECT);
goto bad_str;
}
break;
@@ -712,23 +715,23 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
case V_ASN1_GENERALIZEDTIME:
if (format != ASN1_GEN_FORMAT_ASCII)
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_TIME_NOT_ASCII_FORMAT);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_TIME_NOT_ASCII_FORMAT);
goto bad_form;
}
if (!(atmp->value.asn1_string = ASN1_STRING_new()))
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ERR_R_MALLOC_FAILURE);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ERR_R_MALLOC_FAILURE);
goto bad_str;
}
if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1))
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ERR_R_MALLOC_FAILURE);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ERR_R_MALLOC_FAILURE);
goto bad_str;
}
atmp->value.asn1_string->type = utype;
if (!ASN1_TIME_check(atmp->value.asn1_string))
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_ILLEGAL_TIME_VALUE);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_ILLEGAL_TIME_VALUE);
goto bad_str;
}

@@ -750,7 +753,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
format = MBSTRING_UTF8;
else
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_ILLEGAL_FORMAT);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_ILLEGAL_FORMAT);
goto bad_form;
}

@@ -758,7 +761,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str,
-1, format, ASN1_tag2bit(utype)) <= 0)
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ERR_R_MALLOC_FAILURE);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ERR_R_MALLOC_FAILURE);
goto bad_str;
}
@@ -771,7 +774,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)

if (!(atmp->value.asn1_string = ASN1_STRING_new()))
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ERR_R_MALLOC_FAILURE);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ERR_R_MALLOC_FAILURE);
goto bad_form;
}

@@ -780,7 +783,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)

if (!(rdata = string_to_hex((char *)str, &rdlen)))
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_ILLEGAL_HEX);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_ILLEGAL_HEX);
goto bad_str;
}

@@ -795,7 +798,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
{
if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string))
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_LIST_ERROR);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_LIST_ERROR);
goto bad_str;
}
no_unused = 0;
@@ -803,7 +806,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
}
else
{
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_ILLEGAL_BITSTRING_FORMAT);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_ILLEGAL_BITSTRING_FORMAT);
goto bad_form;
}

@@ -819,7 +822,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
break;

default:
OPENSSL_PUT_ERROR(X509, asn1_str2type, ASN1_R_UNSUPPORTED_TYPE);
OPENSSL_PUT_ERROR(ASN1, asn1_str2type, ASN1_R_UNSUPPORTED_TYPE);
goto bad_str;
break;
}
@@ -849,12 +852,12 @@ static int bitstr_cb(const char *elem, int len, void *bitstr)
return 0;
if (bitnum < 0)
{
OPENSSL_PUT_ERROR(X509, bitstr_cb, ASN1_R_INVALID_NUMBER);
OPENSSL_PUT_ERROR(ASN1, bitstr_cb, ASN1_R_INVALID_NUMBER);
return 0;
}
if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1))
{
OPENSSL_PUT_ERROR(X509, bitstr_cb, ERR_R_MALLOC_FAILURE);
OPENSSL_PUT_ERROR(ASN1, bitstr_cb, ERR_R_MALLOC_FAILURE);
return 0;
}
return 1;


+ 4
- 3
crypto/x509/i2d_pr.c Ver fichero

@@ -57,8 +57,7 @@

#include <openssl/x509.h>

#include <stdio.h>

#include <openssl/asn1.h>
#include <openssl/err.h>
#include <openssl/evp.h>

@@ -77,7 +76,9 @@ int i2d_PrivateKey(const EVP_PKEY *a, unsigned char **pp)
PKCS8_PRIV_KEY_INFO_free(p8);
return ret;
}
OPENSSL_PUT_ERROR(X509, i2d_PrivateKey, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
/* Although this file is in crypto/x509 for layering reasons, it emits
* an error code from ASN1 for OpenSSL compatibility. */
OPENSSL_PUT_ERROR(ASN1, i2d_PrivateKey, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
return -1;
}


+ 7
- 0
include/openssl/asn1.h Ver fichero

@@ -1139,6 +1139,13 @@ OPENSSL_EXPORT int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_f
#define ASN1_F_ASN1_get_object 158
#define ASN1_F_d2i_ASN1_bytes 159
#define ASN1_F_a2i_ASN1_ENUMERATED 160
#define ASN1_F_ASN1_generate_v3 161
#define ASN1_F_append_exp 162
#define ASN1_F_asn1_cb 163
#define ASN1_F_asn1_str2type 164
#define ASN1_F_bitstr_cb 165
#define ASN1_F_i2d_PrivateKey 166
#define ASN1_F_parse_tagging 167
#define ASN1_R_ASN1_SIG_PARSE_ERROR 100
#define ASN1_R_ADDING_OBJECT 101
#define ASN1_R_MIME_NO_CONTENT_TYPE 102


+ 5
- 5
util/make_errors.go Ver fichero

@@ -366,8 +366,7 @@ func addFunctionsAndReasons(functions, reasons map[string]int, filename, prefix
}
defer file.Close()

prefix += "_"
reasonPrefix := prefix + "R_"
reasonPrefix := prefix + "_R_"
var currentFunction string

scanner := bufio.NewScanner(file)
@@ -394,8 +393,9 @@ func addFunctionsAndReasons(functions, reasons map[string]int, filename, prefix
}
}

if strings.Contains(line, "OPENSSL_PUT_ERROR(") {
functionToken := prefix + "F_" + currentFunction
// Do not include cross-module error lines.
if strings.Contains(line, "OPENSSL_PUT_ERROR(" + prefix + ",") {
functionToken := prefix + "_F_" + currentFunction
if _, ok := functions[functionToken]; !ok {
functions[functionToken] = -1
}
@@ -405,7 +405,7 @@ func addFunctionsAndReasons(functions, reasons map[string]int, filename, prefix
handleDeclareMacro(line, "_F_", "OPENSSL_DECLARE_ERROR_FUNCTION(", functions)

for len(line) > 0 {
i := strings.Index(line, prefix)
i := strings.Index(line, prefix + "_")
if i == -1 {
break
}


Cargando…
Cancelar
Guardar