ocsp_ext.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/* ocsp_ext.c */
/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
* project. */
/* History:
This file was transfered to Richard Levitte from CertCo by Kathy
Weinhold in mid-spring 2000 to be included in OpenSSL or released
as a patch kit. */
/* ====================================================================
* Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
#include <stdio.h>
#include <cryptlib.h>
/* Standard wrapper functions for extensions */
/* OCSP request extensions */
{
}
{
}
{
}
{
}
{
}
{
}
{
}
unsigned long flags)
{
}
{
}
/* Single extensions */
int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x)
{
return(X509v3_get_ext_count(x->singleRequestExtensions));
}
{
}
{
}
{
}
{
}
{
}
{
}
unsigned long flags)
{
}
{
}
/* OCSP Basic response */
{
}
{
}
{
}
{
}
{
}
{
}
{
}
unsigned long flags)
{
}
{
}
/* OCSP single response extensions */
{
return(X509v3_get_ext_count(x->singleExtensions));
}
{
}
{
}
{
}
{
}
{
}
{
}
unsigned long flags)
{
}
{
}
/* also CRL Entry Extensions */
{
int i;
unsigned char *p, *b = NULL;
if (data)
{
if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i)))
goto err;
}
else if (sk)
{
if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i)))
goto err;
}
else
{
goto err;
}
if (!s && !(s = ASN1_STRING_new())) goto err;
if (!(ASN1_STRING_set(s, b, i))) goto err;
OPENSSL_free(b);
return s;
err:
if (b) OPENSSL_free(b);
return NULL;
}
/* Nonce handling functions */
/* Add a nonce to an extension stack. A nonce can be specificed or if NULL
* a 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.
*/
{
unsigned char *tmpval;
int ret = 0;
/* 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.
*/
goto err;
if (val)
else
&os, 0, X509V3_ADD_REPLACE))
goto err;
ret = 1;
err:
return ret;
}
/* Add nonce to an OCSP request */
{
}
/* Same as above but for a response */
{
}
/* Check nonce validity in a request and response.
* 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.
*/
{
/*
* 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.
*/
/* Check both absent */
return 2;
/* Check in request only */
return -1;
/* Check in response but not request */
return 3;
/* Otherwise nonce in request and response so retrieve the extensions */
return 0;
return 1;
}
/* Copy the nonce value (if any) from an OCSP request to
* a response.
*/
{
int req_idx;
/* Check for nonce in request */
/* If no nonce that's OK */
if (req_idx < 0) return 2;
}
{
X509_EXTENSION *x = NULL;
if (url)
{
}
if (n)
{
}
if (tim)
{
goto err;
}
if (!(x = X509_EXTENSION_new())) goto err;
goto err;
return x;
err:
if (x) X509_EXTENSION_free(x);
return NULL;
}
/* AcceptableResponses ::= SEQUENCE OF OBJECT IDENTIFIER */
{
int nid;
ASN1_OBJECT *o = NULL;
X509_EXTENSION *x = NULL;
{
sk_ASN1_OBJECT_push(sk, o);
oids++;
}
if (!(x = X509_EXTENSION_new())) goto err;
goto err;
goto err;
return x;
err:
if (x) X509_EXTENSION_free(x);
return NULL;
}
/* ArchiveCutoff ::= GeneralizedTime */
{
X509_EXTENSION *x=NULL;
if (!(x = X509_EXTENSION_new())) goto err;
return x;
err:
if (x) X509_EXTENSION_free(x);
return NULL;
}
/* 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.
*/
{
X509_EXTENSION *x = NULL;
{
urls++;
}
if (!(x = X509_EXTENSION_new())) goto err;
goto err;
return x;
err:
if (x) X509_EXTENSION_free(x);
return NULL;
}