Commit 6912debb authored by Mingtao Yang's avatar Mingtao Yang Committed by Richard Levitte
Browse files

Add APIs for custom X509_LOOKUP_METHOD creation



OpenSSL 1.1.0 made the X509_LOOKUP_METHOD structure opaque, so
applications that were previously able to define a custom lookup method
are not able to be ported.

This commit adds getters and setters for each of the current fields of
X509_LOOKUP_METHOD, along with getters and setters on several associated
opaque types (such as X509_LOOKUP and X509_OBJECT).

Reviewed-by: default avatarMatt Caswell <matt@openssl.org>
Reviewed-by: default avatarRichard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6152)

(cherry picked from commit 0124f32a)
parent ac35f285
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ SOURCE[../../libcrypto]=\
        x509_obj.c x509_req.c x509spki.c x509_vfy.c \
        x509_set.c x509cset.c x509rset.c x509_err.c \
        x509name.c x509_v3.c x509_ext.c x509_att.c \
        x509type.c x509_lu.c x_all.c x509_txt.c \
        x509type.c x509_meth.c x509_lu.c x_all.c x509_txt.c \
        x509_trs.c by_file.c by_dir.c x509_vpm.c \
        x_crl.c t_crl.c x_req.c t_req.c x_x509.c t_x509.c \
        x_pubkey.c x_x509a.c x_attrib.c x_exten.c x_name.c
+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ static int new_dir(X509_LOOKUP *lu)
        OPENSSL_free(a);
        return 0;
    }
    lu->method_data = (char *)a;
    lu->method_data = a;
    return 1;
}

+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ static ERR_STRING_DATA X509_str_functs[] = {
    {ERR_FUNC(X509_F_X509_LOAD_CERT_CRL_FILE), "X509_load_cert_crl_file"},
    {ERR_FUNC(X509_F_X509_LOAD_CERT_FILE), "X509_load_cert_file"},
    {ERR_FUNC(X509_F_X509_LOAD_CRL_FILE), "X509_load_crl_file"},
    {ERR_FUNC(X509_F_X509_LOOKUP_METH_NEW), "X509_LOOKUP_meth_new"},
    {ERR_FUNC(X509_F_X509_NAME_ADD_ENTRY), "X509_NAME_add_entry"},
    {ERR_FUNC(X509_F_X509_NAME_ENTRY_CREATE_BY_NID),
     "X509_NAME_ENTRY_create_by_NID"},
+2 −2
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ struct x509_crl_method_st {
};

struct x509_lookup_method_st {
    const char *name;
    char *name;
    int (*new_item) (X509_LOOKUP *ctx);
    void (*free) (X509_LOOKUP *ctx);
    int (*init) (X509_LOOKUP *ctx);
@@ -91,7 +91,7 @@ struct x509_lookup_st {
    int init;                   /* have we been started */
    int skip;                   /* don't use us. */
    X509_LOOKUP_METHOD *method; /* the functions */
    char *method_data;          /* method data */
    void *method_data;          /* method data */
    X509_STORE *store_ctx;      /* who owns us */
};

+45 −2
Original line number Diff line number Diff line
@@ -117,6 +117,23 @@ int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
    return ctx->method->get_by_alias(ctx, type, str, len, ret);
}

int X509_LOOKUP_set_method_data(X509_LOOKUP *ctx, void *data)
{
    ctx->method_data = data;
    return 1;
}

void *X509_LOOKUP_get_method_data(const X509_LOOKUP *ctx)
{
    return ctx->method_data;
}

X509_STORE *X509_LOOKUP_get_store(const X509_LOOKUP *ctx)
{
    return ctx->store_ctx;
}


static int x509_object_cmp(const X509_OBJECT *const *a,
                           const X509_OBJECT *const *b)
{
@@ -406,8 +423,7 @@ X509_OBJECT *X509_OBJECT_new()
    return ret;
}


void X509_OBJECT_free(X509_OBJECT *a)
static void x509_object_free_internal(X509_OBJECT *a)
{
    if (a == NULL)
        return;
@@ -421,6 +437,33 @@ void X509_OBJECT_free(X509_OBJECT *a)
        X509_CRL_free(a->data.crl);
        break;
    }
}

int X509_OBJECT_set1_X509(X509_OBJECT *a, X509 *obj)
{
    if (a == NULL || !X509_up_ref(obj))
        return 0;

    x509_object_free_internal(a);
    a->type = X509_LU_X509;
    a->data.x509 = obj;
    return 1;
}

int X509_OBJECT_set1_X509_CRL(X509_OBJECT *a, X509_CRL *obj)
{
    if (a == NULL || !X509_CRL_up_ref(obj))
        return 0;

    x509_object_free_internal(a);
    a->type = X509_LU_CRL;
    a->data.crl = obj;
    return 1;
}

void X509_OBJECT_free(X509_OBJECT *a)
{
    x509_object_free_internal(a);
    OPENSSL_free(a);
}

Loading