2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2016-05-17 18:52:22 +00:00
|
|
|
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2000-10-27 11:05:35 +00:00
|
|
|
*
|
2016-05-17 18:52:22 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2000-10-27 11:05:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
2000-10-27 11:05:35 +00:00
|
|
|
#include <openssl/objects.h>
|
|
|
|
#include <openssl/x509.h>
|
|
|
|
#include <openssl/ocsp.h>
|
2015-03-05 13:41:11 +00:00
|
|
|
#include "ocsp_lcl.h"
|
2001-01-08 01:21:55 +00:00
|
|
|
#include <openssl/rand.h>
|
2000-10-27 11:05:35 +00:00
|
|
|
#include <openssl/x509v3.h>
|
|
|
|
|
2000-12-28 01:05:05 +00:00
|
|
|
/* Standard wrapper functions for extensions */
|
|
|
|
|
|
|
|
/* OCSP request extensions */
|
|
|
|
|
|
|
|
int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext_count(x->tbsRequest.requestExtensions);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return (X509v3_get_ext_by_NID
|
2015-10-06 22:04:08 +00:00
|
|
|
(x->tbsRequest.requestExtensions, nid, lastpos));
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2016-07-31 17:38:09 +00:00
|
|
|
int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, const ASN1_OBJECT *obj,
|
2015-01-22 03:40:55 +00:00
|
|
|
int lastpos)
|
|
|
|
{
|
|
|
|
return (X509v3_get_ext_by_OBJ
|
2015-10-06 22:04:08 +00:00
|
|
|
(x->tbsRequest.requestExtensions, obj, lastpos));
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return (X509v3_get_ext_by_critical
|
2015-10-06 22:04:08 +00:00
|
|
|
(x->tbsRequest.requestExtensions, crit, lastpos));
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext(x->tbsRequest.requestExtensions, loc);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_delete_ext(x->tbsRequest.requestExtensions, loc);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-10-06 22:04:08 +00:00
|
|
|
return X509V3_get_d2i(x->tbsRequest.requestExtensions, nid, crit, idx);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit,
|
2015-01-22 03:40:55 +00:00
|
|
|
unsigned long flags)
|
|
|
|
{
|
2015-10-06 22:04:08 +00:00
|
|
|
return X509V3_add1_i2d(&x->tbsRequest.requestExtensions, nid, value,
|
2015-01-22 03:40:55 +00:00
|
|
|
crit, flags);
|
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-10-06 22:04:08 +00:00
|
|
|
return (X509v3_add_ext(&(x->tbsRequest.requestExtensions), ex, loc) !=
|
2015-01-22 03:40:55 +00:00
|
|
|
NULL);
|
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
/* Single extensions */
|
|
|
|
|
|
|
|
int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext_count(x->singleRequestExtensions);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext_by_NID(x->singleRequestExtensions, nid, lastpos);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
2016-07-31 17:38:09 +00:00
|
|
|
int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, const ASN1_OBJECT *obj,
|
|
|
|
int lastpos)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext_by_OBJ(x->singleRequestExtensions, obj, lastpos);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return (X509v3_get_ext_by_critical
|
|
|
|
(x->singleRequestExtensions, crit, lastpos));
|
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext(x->singleRequestExtensions, loc);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_delete_ext(x->singleRequestExtensions, loc);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return X509V3_get_d2i(x->singleRequestExtensions, nid, crit, idx);
|
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit,
|
2015-01-22 03:40:55 +00:00
|
|
|
unsigned long flags)
|
|
|
|
{
|
|
|
|
return X509V3_add1_i2d(&x->singleRequestExtensions, nid, value, crit,
|
|
|
|
flags);
|
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return (X509v3_add_ext(&(x->singleRequestExtensions), ex, loc) != NULL);
|
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
/* OCSP Basic response */
|
|
|
|
|
|
|
|
int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext_count(x->tbsResponseData.responseExtensions);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return (X509v3_get_ext_by_NID
|
2015-10-06 22:04:08 +00:00
|
|
|
(x->tbsResponseData.responseExtensions, nid, lastpos));
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2016-07-31 17:38:09 +00:00
|
|
|
int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, const ASN1_OBJECT *obj,
|
2015-01-22 03:40:55 +00:00
|
|
|
int lastpos)
|
|
|
|
{
|
|
|
|
return (X509v3_get_ext_by_OBJ
|
2015-10-06 22:04:08 +00:00
|
|
|
(x->tbsResponseData.responseExtensions, obj, lastpos));
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit,
|
|
|
|
int lastpos)
|
|
|
|
{
|
|
|
|
return (X509v3_get_ext_by_critical
|
2015-10-06 22:04:08 +00:00
|
|
|
(x->tbsResponseData.responseExtensions, crit, lastpos));
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext(x->tbsResponseData.responseExtensions, loc);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_delete_ext(x->tbsResponseData.responseExtensions, loc);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit,
|
|
|
|
int *idx)
|
|
|
|
{
|
2015-10-06 22:04:08 +00:00
|
|
|
return X509V3_get_d2i(x->tbsResponseData.responseExtensions, nid, crit,
|
2015-01-22 03:40:55 +00:00
|
|
|
idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value,
|
|
|
|
int crit, unsigned long flags)
|
|
|
|
{
|
2015-10-06 22:04:08 +00:00
|
|
|
return X509V3_add1_i2d(&x->tbsResponseData.responseExtensions, nid,
|
2015-01-22 03:40:55 +00:00
|
|
|
value, crit, flags);
|
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-10-06 22:04:08 +00:00
|
|
|
return (X509v3_add_ext(&(x->tbsResponseData.responseExtensions), ex, loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
!= NULL);
|
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
/* OCSP single response extensions */
|
|
|
|
|
|
|
|
int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext_count(x->singleExtensions);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext_by_NID(x->singleExtensions, nid, lastpos);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2016-07-31 17:38:09 +00:00
|
|
|
int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, const ASN1_OBJECT *obj,
|
2015-01-22 03:40:55 +00:00
|
|
|
int lastpos)
|
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext_by_OBJ(x->singleExtensions, obj, lastpos);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit,
|
|
|
|
int lastpos)
|
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext_by_critical(x->singleExtensions, crit, lastpos);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_get_ext(x->singleExtensions, loc);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return X509v3_delete_ext(x->singleExtensions, loc);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit,
|
|
|
|
int *idx)
|
|
|
|
{
|
|
|
|
return X509V3_get_d2i(x->singleExtensions, nid, crit, idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value,
|
|
|
|
int crit, unsigned long flags)
|
|
|
|
{
|
|
|
|
return X509V3_add1_i2d(&x->singleExtensions, nid, value, crit, flags);
|
|
|
|
}
|
2000-12-28 01:05:05 +00:00
|
|
|
|
|
|
|
int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return (X509v3_add_ext(&(x->singleExtensions), ex, loc) != NULL);
|
|
|
|
}
|
2000-10-27 11:05:35 +00:00
|
|
|
|
|
|
|
/* also CRL Entry Extensions */
|
|
|
|
|
2001-01-08 01:21:55 +00:00
|
|
|
/* Nonce handling functions */
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2016-02-05 20:23:54 +00:00
|
|
|
* Add a nonce to an extension stack. A nonce can be specified or if NULL a
|
2015-01-22 03:40:55 +00:00
|
|
|
* random nonce will be generated. Note: OpenSSL 0.9.7d and later create an
|
|
|
|
* OCTET STRING containing the nonce, previous versions used the raw nonce.
|
2001-01-08 01:21:55 +00:00
|
|
|
*/
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts,
|
|
|
|
unsigned char *val, int len)
|
|
|
|
{
|
|
|
|
unsigned char *tmpval;
|
|
|
|
ASN1_OCTET_STRING os;
|
|
|
|
int ret = 0;
|
|
|
|
if (len <= 0)
|
|
|
|
len = OCSP_DEFAULT_NONCE_LENGTH;
|
|
|
|
/*
|
|
|
|
* Create the OCTET STRING manually by writing out the header and
|
|
|
|
* appending the content octets. This avoids an extra memory allocation
|
|
|
|
* operation in some cases. Applications should *NOT* do this because it
|
|
|
|
* relies on library internals.
|
|
|
|
*/
|
|
|
|
os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING);
|
2016-08-22 22:39:28 +00:00
|
|
|
if (os.length < 0)
|
2016-08-25 08:40:17 +00:00
|
|
|
return 0;
|
2016-08-22 22:39:28 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
os.data = OPENSSL_malloc(os.length);
|
|
|
|
if (os.data == NULL)
|
|
|
|
goto err;
|
|
|
|
tmpval = os.data;
|
|
|
|
ASN1_put_object(&tmpval, 0, len, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL);
|
|
|
|
if (val)
|
|
|
|
memcpy(tmpval, val, len);
|
2015-02-26 11:57:37 +00:00
|
|
|
else if (RAND_bytes(tmpval, len) <= 0)
|
|
|
|
goto err;
|
2015-01-22 03:40:55 +00:00
|
|
|
if (!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce,
|
|
|
|
&os, 0, X509V3_ADD_REPLACE))
|
|
|
|
goto err;
|
|
|
|
ret = 1;
|
|
|
|
err:
|
2015-05-01 14:02:07 +00:00
|
|
|
OPENSSL_free(os.data);
|
2015-01-22 03:40:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2001-02-12 23:28:45 +00:00
|
|
|
|
|
|
|
/* Add nonce to an OCSP request */
|
|
|
|
|
|
|
|
int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-10-06 22:04:08 +00:00
|
|
|
return ocsp_add1_nonce(&req->tbsRequest.requestExtensions, val, len);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2001-02-12 23:28:45 +00:00
|
|
|
|
|
|
|
/* Same as above but for a response */
|
|
|
|
|
|
|
|
int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2015-10-06 22:04:08 +00:00
|
|
|
return ocsp_add1_nonce(&resp->tbsResponseData.responseExtensions, val,
|
2015-01-22 03:40:55 +00:00
|
|
|
len);
|
|
|
|
}
|
2001-02-12 23:28:45 +00:00
|
|
|
|
2015-01-05 00:34:00 +00:00
|
|
|
/*-
|
|
|
|
* Check nonce validity in a request and response.
|
2001-02-12 23:28:45 +00:00
|
|
|
* Return value reflects result:
|
|
|
|
* 1: nonces present and equal.
|
|
|
|
* 2: nonces both absent.
|
|
|
|
* 3: nonce present in response only.
|
|
|
|
* 0: nonces both present and not equal.
|
|
|
|
* -1: nonce in request only.
|
|
|
|
*
|
|
|
|
* For most responders clients can check return > 0.
|
|
|
|
* If responder doesn't handle nonces return != 0 may be
|
|
|
|
* necessary. return == 0 is always an error.
|
2001-01-08 01:21:55 +00:00
|
|
|
*/
|
2001-02-12 23:28:45 +00:00
|
|
|
|
2001-01-08 01:21:55 +00:00
|
|
|
int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Since we are only interested in the presence or absence of
|
|
|
|
* the nonce and comparing its value there is no need to use
|
|
|
|
* the X509V3 routines: this way we can avoid them allocating an
|
|
|
|
* ASN1_OCTET_STRING structure for the value which would be
|
|
|
|
* freed immediately anyway.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int req_idx, resp_idx;
|
|
|
|
X509_EXTENSION *req_ext, *resp_ext;
|
|
|
|
req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
|
|
|
|
resp_idx = OCSP_BASICRESP_get_ext_by_NID(bs, NID_id_pkix_OCSP_Nonce, -1);
|
|
|
|
/* Check both absent */
|
|
|
|
if ((req_idx < 0) && (resp_idx < 0))
|
|
|
|
return 2;
|
|
|
|
/* Check in request only */
|
|
|
|
if ((req_idx >= 0) && (resp_idx < 0))
|
|
|
|
return -1;
|
|
|
|
/* Check in response but not request */
|
|
|
|
if ((req_idx < 0) && (resp_idx >= 0))
|
|
|
|
return 3;
|
|
|
|
/*
|
|
|
|
* Otherwise nonce in request and response so retrieve the extensions
|
|
|
|
*/
|
|
|
|
req_ext = OCSP_REQUEST_get_ext(req, req_idx);
|
|
|
|
resp_ext = OCSP_BASICRESP_get_ext(bs, resp_idx);
|
2015-03-15 13:43:56 +00:00
|
|
|
if (ASN1_OCTET_STRING_cmp(X509_EXTENSION_get_data(req_ext),
|
|
|
|
X509_EXTENSION_get_data(resp_ext)))
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the nonce value (if any) from an OCSP request to a response.
|
2001-02-05 00:35:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
X509_EXTENSION *req_ext;
|
|
|
|
int req_idx;
|
|
|
|
/* Check for nonce in request */
|
|
|
|
req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
|
|
|
|
/* If no nonce that's OK */
|
|
|
|
if (req_idx < 0)
|
|
|
|
return 2;
|
|
|
|
req_ext = OCSP_REQUEST_get_ext(req, req_idx);
|
|
|
|
return OCSP_BASICRESP_add_ext(resp, req_ext, -1);
|
|
|
|
}
|
2000-10-27 11:05:35 +00:00
|
|
|
|
2016-08-06 15:54:32 +00:00
|
|
|
X509_EXTENSION *OCSP_crlID_new(const char *url, long *n, char *tim)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
X509_EXTENSION *x = NULL;
|
|
|
|
OCSP_CRLID *cid = NULL;
|
|
|
|
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((cid = OCSP_CRLID_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
|
|
|
if (url) {
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((cid->crlUrl = ASN1_IA5STRING_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
|
|
|
if (!(ASN1_STRING_set(cid->crlUrl, url, -1)))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (n) {
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((cid->crlNum = ASN1_INTEGER_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
|
|
|
if (!(ASN1_INTEGER_set(cid->crlNum, *n)))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (tim) {
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((cid->crlTime = ASN1_GENERALIZEDTIME_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
|
|
|
if (!(ASN1_GENERALIZEDTIME_set_string(cid->crlTime, tim)))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
x = X509V3_EXT_i2d(NID_id_pkix_OCSP_CrlID, 0, cid);
|
|
|
|
err:
|
2015-05-01 18:37:16 +00:00
|
|
|
OCSP_CRLID_free(cid);
|
2015-01-22 03:40:55 +00:00
|
|
|
return x;
|
|
|
|
}
|
2000-10-27 11:05:35 +00:00
|
|
|
|
|
|
|
/* AcceptableResponses ::= SEQUENCE OF OBJECT IDENTIFIER */
|
|
|
|
X509_EXTENSION *OCSP_accept_responses_new(char **oids)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
int nid;
|
|
|
|
STACK_OF(ASN1_OBJECT) *sk = NULL;
|
|
|
|
ASN1_OBJECT *o = NULL;
|
|
|
|
X509_EXTENSION *x = NULL;
|
|
|
|
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((sk = sk_ASN1_OBJECT_new_null()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
|
|
|
while (oids && *oids) {
|
|
|
|
if ((nid = OBJ_txt2nid(*oids)) != NID_undef && (o = OBJ_nid2obj(nid)))
|
|
|
|
sk_ASN1_OBJECT_push(sk, o);
|
|
|
|
oids++;
|
|
|
|
}
|
|
|
|
x = X509V3_EXT_i2d(NID_id_pkix_OCSP_acceptableResponses, 0, sk);
|
|
|
|
err:
|
2015-04-30 15:30:03 +00:00
|
|
|
sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
|
2015-01-22 03:40:55 +00:00
|
|
|
return x;
|
|
|
|
}
|
2000-10-27 11:05:35 +00:00
|
|
|
|
|
|
|
/* ArchiveCutoff ::= GeneralizedTime */
|
2015-01-22 03:40:55 +00:00
|
|
|
X509_EXTENSION *OCSP_archive_cutoff_new(char *tim)
|
|
|
|
{
|
|
|
|
X509_EXTENSION *x = NULL;
|
|
|
|
ASN1_GENERALIZEDTIME *gt = NULL;
|
|
|
|
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((gt = ASN1_GENERALIZEDTIME_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
|
|
|
if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim)))
|
|
|
|
goto err;
|
|
|
|
x = X509V3_EXT_i2d(NID_id_pkix_OCSP_archiveCutoff, 0, gt);
|
|
|
|
err:
|
2015-04-30 15:30:03 +00:00
|
|
|
ASN1_GENERALIZEDTIME_free(gt);
|
2015-01-22 03:40:55 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* per ACCESS_DESCRIPTION parameter are oids, of which there are currently
|
|
|
|
* two--NID_ad_ocsp, NID_id_ad_caIssuers--and GeneralName value. This method
|
|
|
|
* forces NID_ad_ocsp and uniformResourceLocator [6] IA5String.
|
2000-10-27 11:05:35 +00:00
|
|
|
*/
|
2016-08-06 15:54:32 +00:00
|
|
|
X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME *issuer, const char **urls)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
X509_EXTENSION *x = NULL;
|
|
|
|
ASN1_IA5STRING *ia5 = NULL;
|
|
|
|
OCSP_SERVICELOC *sloc = NULL;
|
|
|
|
ACCESS_DESCRIPTION *ad = NULL;
|
|
|
|
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((sloc = OCSP_SERVICELOC_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
2019-05-19 22:33:58 +00:00
|
|
|
X509_NAME_free(sloc->issuer);
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((sloc->issuer = X509_NAME_dup(issuer)) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
2015-05-06 17:43:59 +00:00
|
|
|
if (urls && *urls
|
|
|
|
&& (sloc->locator = sk_ACCESS_DESCRIPTION_new_null()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
|
|
|
while (urls && *urls) {
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((ad = ACCESS_DESCRIPTION_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((ad->method = OBJ_nid2obj(NID_ad_OCSP)) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((ia5 = ASN1_IA5STRING_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
|
|
|
if (!ASN1_STRING_set((ASN1_STRING *)ia5, *urls, -1))
|
|
|
|
goto err;
|
2019-05-19 22:33:58 +00:00
|
|
|
/* ad->location is allocated inside ACCESS_DESCRIPTION_new */
|
2015-01-22 03:40:55 +00:00
|
|
|
ad->location->type = GEN_URI;
|
|
|
|
ad->location->d.ia5 = ia5;
|
2016-04-27 12:40:52 +00:00
|
|
|
ia5 = NULL;
|
2015-01-22 03:40:55 +00:00
|
|
|
if (!sk_ACCESS_DESCRIPTION_push(sloc->locator, ad))
|
|
|
|
goto err;
|
2016-04-27 12:40:52 +00:00
|
|
|
ad = NULL;
|
2015-01-22 03:40:55 +00:00
|
|
|
urls++;
|
|
|
|
}
|
|
|
|
x = X509V3_EXT_i2d(NID_id_pkix_OCSP_serviceLocator, 0, sloc);
|
|
|
|
err:
|
2016-04-27 12:40:52 +00:00
|
|
|
ASN1_IA5STRING_free(ia5);
|
|
|
|
ACCESS_DESCRIPTION_free(ad);
|
2015-05-01 18:37:16 +00:00
|
|
|
OCSP_SERVICELOC_free(sloc);
|
2015-01-22 03:40:55 +00:00
|
|
|
return x;
|
|
|
|
}
|