ocsp_cl.c revision 9dc0df1bac950d6e491f9a7c7e4888f2b301cb15
/* ocsp_cl.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 <time.h>
#include <cryptlib.h>
/* Utility functions related to sending OCSP requests and extracting
* relevant information from the response.
*/
/* Add an OCSP_CERTID to an OCSP request. Return new OCSP_ONEREQ
* pointer: useful if we want to add extensions.
*/
{
if (req &&
goto err;
return one;
err:
return NULL;
}
/* Set requestorName from an X509_NAME structure */
{
gen = GENERAL_NAME_new();
return 0;
{
return 0;
}
return 1;
}
/* Add a certificate to an OCSP request */
{
if (!req->optionalSignature)
if (!sig) return 0;
if (!cert) return 1;
return 0;
return 1;
}
/* Sign an OCSP request set the requestorName to the subjec
* name of an optional signers certificate and include one
* or more optional certificates in the request. Behaves
* like PKCS7_sign().
*/
unsigned long flags)
{
int i;
X509 *x;
goto err;
if (key)
{
{
goto err;
}
}
if (!(flags & OCSP_NOCERTS))
{
for (i = 0; i < sk_X509_num(certs); i++)
{
x = sk_X509_value(certs, i);
}
}
return 1;
err:
return 0;
}
/* Get response status */
{
}
/* Extract basic response from OCSP_RESPONSE or NULL if
* no basic response present.
*/
{
if (!rb)
{
return NULL;
}
{
return NULL;
}
}
/* Return number of OCSP_SINGLERESP reponses present in
* a basic response.
*/
{
if (!bs) return -1;
}
/* Extract an OCSP_SINGLERESP response with a given index */
{
}
/* Look single response matching a given certificate ID */
{
int i;
if (!bs) return -1;
else last++;
{
}
return -1;
}
/* Extract status information from an OCSP_SINGLERESP structure.
* Note: the revtime and reason values are only set if the
* certificate status is revoked. Returns numerical value of
* status.
*/
{
int ret;
if(!single) return -1;
if (ret == V_OCSP_CERTSTATUS_REVOKED)
{
if (reason)
{
if(rev->revocationReason)
else *reason = -1;
}
}
return ret;
}
/* This function combines the previous ones: look up a certificate ID and
* if found extract status information. Return 0 is successful.
*/
int *reason,
{
int i;
/* Maybe check for multiple responses and give an error? */
if(i < 0) return 0;
return 1;
}
/* Check validity of thisUpdate and nextUpdate fields. It is possible that the request will
* rejecting otherwise valid time we allow the times to be within 'nsec' of the current time.
* Also to avoid accepting very old responses without a nextUpdate field an optional maxage
* parameter specifies the maximum age the thisUpdate field can be.
*/
int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd, ASN1_GENERALIZEDTIME *nextupd, long nsec, long maxsec)
{
int ret = 1;
/* Check thisUpdate is valid and not more than nsec in the future */
{
ret = 0;
}
else
{
{
ret = 0;
}
/* If maxsec specified check thisUpdate is not more than maxsec in the past */
if (maxsec >= 0)
{
{
ret = 0;
}
}
}
/* Check nextUpdate is valid and not more than nsec in the past */
{
ret = 0;
}
else
{
{
ret = 0;
}
}
/* Also don't allow nextUpdate to precede thisUpdate */
{
ret = 0;
}
return ret;
}