Commit e12c0beb authored by Matt Caswell's avatar Matt Caswell
Browse files

Add the ability to set OCSP_RESPID fields



OCSP_RESPID was made opaque in 1.1.0, but no accessors were provided for
setting the name/key value for the OCSP_RESPID.

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
parent e408c09b
Loading
Loading
Loading
Loading
+37 −10
Original line number Diff line number Diff line
@@ -193,17 +193,10 @@ int OCSP_basic_sign(OCSP_BASICRESP *brsp,

    rid = &brsp->tbsResponseData.responderId;
    if (flags & OCSP_RESPID_KEY) {
        unsigned char md[SHA_DIGEST_LENGTH];
        X509_pubkey_digest(signer, EVP_sha1(), md, NULL);
        if ((rid->value.byKey = ASN1_OCTET_STRING_new()) == NULL)
            goto err;
        if (!(ASN1_OCTET_STRING_set(rid->value.byKey, md, SHA_DIGEST_LENGTH)))
        if (!OCSP_RESPID_set_by_key(rid, signer))
            goto err;
        rid->type = V_OCSP_RESPID_KEY;
    } else {
        if (!X509_NAME_set(&rid->value.byName, X509_get_subject_name(signer)))
    } else if (!OCSP_RESPID_set_by_name(rid, signer)) {
        goto err;
        rid->type = V_OCSP_RESPID_NAME;
    }

    if (!(flags & OCSP_NOTIME) &&
@@ -222,3 +215,37 @@ int OCSP_basic_sign(OCSP_BASICRESP *brsp,
 err:
    return 0;
}

int OCSP_RESPID_set_by_name(OCSP_RESPID *respid, X509 *cert)
{
    if (!X509_NAME_set(&respid->value.byName, X509_get_subject_name(cert)))
        return 0;

    respid->type = V_OCSP_RESPID_NAME;

    return 1;
}

int OCSP_RESPID_set_by_key(OCSP_RESPID *respid, X509 *cert)
{
    ASN1_OCTET_STRING *byKey = NULL;
    unsigned char md[SHA_DIGEST_LENGTH];

    /* RFC2560 requires SHA1 */
    if (!X509_pubkey_digest(cert, EVP_sha1(), md, NULL))
        return 0;

    byKey = ASN1_OCTET_STRING_new();
    if (byKey == NULL)
        return 0;

    if (!(ASN1_OCTET_STRING_set(respid->value.byKey, md, SHA_DIGEST_LENGTH))) {
        ASN1_OCTET_STRING_free(byKey);
        return 0;
    }

    respid->type = V_OCSP_RESPID_KEY;
    respid->value.byKey = byKey;

    return 1;
}
+26 −1
Original line number Diff line number Diff line
@@ -3,7 +3,8 @@
=head1 NAME

OCSP_response_status, OCSP_response_get1_basic, OCSP_response_create,
OCSP_RESPONSE_free - OCSP response functions
OCSP_RESPONSE_free, OCSP_RESPID_set_by_name,
OCSP_RESPID_set_by_key - OCSP response functions

=head1 SYNOPSIS

@@ -14,6 +15,9 @@ OCSP_RESPONSE_free - OCSP response functions
 OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs);
 void OCSP_RESPONSE_free(OCSP_RESPONSE *resp);

 int OCSP_RESPID_set_by_name(OCSP_RESPID *respid, X509 *cert);
 int OCSP_RESPID_set_by_key(OCSP_RESPID *respid, X509 *cert);

=head1 DESCRIPTION

OCSP_response_status() returns the OCSP response status of B<resp>. It returns
@@ -30,6 +34,17 @@ B<status> and optionally including basic response B<bs>.

OCSP_RESPONSE_free() frees up OCSP response B<resp>.

OCSP_RESPID_set_by_name() sets the name of the OCSP_RESPID to be the same as the
subject name in the supplied X509 certificate B<cert> for the OCSP responder.

OCSP_RESPID_set_by_key() sets the key of the OCSP_RESPID to be the same as the
key in the supplied X509 certificate B<cert> for the OCSP responder. The key is
stored as a SHA1 hash.

Note that an OCSP_RESPID can only have one of the name, or the key set. Calling
OCSP_RESPID_set_by_name() or OCSP_RESPID_set_by_key() will clear any existing
setting.

=head1 RETURN VALUES

OCSP_RESPONSE_status() returns a status value.
@@ -42,6 +57,9 @@ if an error occurred.

OCSP_RESPONSE_free() does not return a value.

OCSP_RESPID_set_by_name() and OCSP_RESPID_set_by_key() return 1 on success or 0
on failure.

=head1 NOTES

OCSP_response_get1_basic() is only called if the status of a response is
@@ -55,6 +73,13 @@ L<OCSP_request_add1_nonce(3)>
L<OCSP_REQUEST_new(3)>
L<OCSP_response_find_status(3)>
L<OCSP_sendreq_new(3)>
L<OCSP_RESPID_new(3)>
L<OCSP_RESPID_free(3)>

=head1 HISTORY

The OCSP_RESPID_set_by_name() and OCSP_RESPID_set_by_key() functions were added
in OpenSSL version 1.1.0a.

=head1 COPYRIGHT

+2 −0
Original line number Diff line number Diff line
@@ -259,6 +259,8 @@ int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert);
int OCSP_basic_sign(OCSP_BASICRESP *brsp,
                    X509 *signer, EVP_PKEY *key, const EVP_MD *dgst,
                    STACK_OF(X509) *certs, unsigned long flags);
int OCSP_RESPID_set_by_name(OCSP_RESPID *respid, X509 *cert);
int OCSP_RESPID_set_by_key(OCSP_RESPID *respid, X509 *cert);

X509_EXTENSION *OCSP_crlID_new(const char *url, long *n, char *tim);

+2 −0
Original line number Diff line number Diff line
@@ -4203,3 +4203,5 @@ ECPKPARAMETERS_free 4153 1_1_0 EXIST::FUNCTION:EC
ECPARAMETERS_free                       4154	1_1_0	EXIST::FUNCTION:EC
ECPKPARAMETERS_new                      4155	1_1_0	EXIST::FUNCTION:EC
ECPARAMETERS_new                        4156	1_1_0	EXIST::FUNCTION:EC
OCSP_RESPID_set_by_name                 4157	1_1_0a	EXIST::FUNCTION:OCSP
OCSP_RESPID_set_by_key                  4158	1_1_0a	EXIST::FUNCTION:OCSP