/* * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved. * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* * ocspdServer.cpp - Server class for OCSP helper * * Created 6 July 2004 by dmitch */ #include "ocspdServer.h" #include #include #include "ocspdNetwork.h" #include "ocspdDb.h" #include "crlDb.h" #include #include #include #include #include #include #include /* created by MIG */ #pragma mark ----- OCSP utilities ----- /* * Once we've gotten a response from a server, cook up a SecAsn1OCSPDReply. */ static SecAsn1OCSPDReply *ocspdGenReply( SecAsn1CoderRef coder, const CSSM_DATA &resp, const CSSM_DATA &certID) { SecAsn1OCSPDReply *ocspdRep = (SecAsn1OCSPDReply *)SecAsn1Malloc(coder, sizeof(*ocspdRep)); SecAsn1AllocCopyItem(coder, &resp, &ocspdRep->ocspResp); SecAsn1AllocCopyItem(coder, &certID, &ocspdRep->certID); return ocspdRep; } static SecAsn1OCSPDReply *ocspdHandleReq( SecAsn1CoderRef coder, SecAsn1OCSPDRequest &request) { CSSM_DATA derResp = {0, NULL}; CSSM_RETURN crtn; bool cacheReadDisable = false; bool cacheWriteDisable = false; if((request.cacheReadDisable != NULL) && (request.cacheReadDisable->Length != 0) && (request.cacheReadDisable->Data[0] != 0)) { cacheReadDisable = true; } if((request.cacheWriteDisable != NULL) && (request.cacheWriteDisable->Length != 0) && (request.cacheWriteDisable->Data[0] != 0)) { cacheWriteDisable = true; } if(!cacheReadDisable) { /* do a cache lookup */ bool found = ocspdDbCacheLookup(coder, request.certID, request.localRespURI, derResp); if(found) { return ocspdGenReply(coder, derResp, request.certID); } } if(request.localRespURI) { if(request.ocspReq == NULL) { ocspdErrorLog("ocspdHandleReq: localRespURI but no request to send\n"); return NULL; } crtn = ocspdHttpPost(coder, *request.localRespURI, *request.ocspReq, derResp); if(crtn == CSSM_OK) { SecAsn1OCSPDReply *reply = ocspdGenReply(coder, derResp, request.certID); if(!cacheWriteDisable) { ocspdDbCacheAdd(derResp, *request.localRespURI); } return reply; } } /* now try everything in requests.urls, the normal case */ unsigned numUris = ocspdArraySize((const void **)request.urls); for(unsigned dex=0; dexmsgh_id); return ocspd_server(in, out); }