Update contrib.
2 /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
5 /* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
59 © Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
63 #include <openssl/asn1.h>
68 #include <openssl/ocsp.h>
69 #include <openssl/err.h>
70 #include <openssl/buffer.h>
71 #if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
72 #include "libcrypto_wsd_macros.h"
73 #include "libcrypto_wsd.h"
75 #ifdef OPENSSL_SYS_SUNOS
76 #define strtoul (unsigned long)strtol
77 #endif /* OPENSSL_SYS_SUNOS */
79 /* Quick and dirty HTTP OCSP request handler.
80 * Could make this a bit cleverer by adding
81 * support for non blocking BIOs and a few
85 static const char req_txt[] =
86 "POST %s HTTP/1.0\r\n\
87 Content-Type: application/ocsp-request\r\n\
88 Content-Length: %d\r\n\r\n";
92 EXPORT_C OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req)
96 OCSP_RESPONSE *resp = NULL;
100 static char req_txt[] =
101 "POST %s HTTP/1.0\r\n\
102 Content-Type: application/ocsp-request\r\n\
103 Content-Length: %d\r\n\r\n";
106 len = i2d_OCSP_REQUEST(req, NULL);
107 if(BIO_printf(b, req_txt, path, len) < 0) {
108 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_WRITE_ERROR);
111 if(i2d_OCSP_REQUEST_bio(b, req) <= 0) {
112 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_WRITE_ERROR);
115 if(!(mem = BIO_new(BIO_s_mem()))) goto err;
116 /* Copy response to a memory BIO: socket bios can't do gets! */
117 while ((len = BIO_read(b, tmpbuf, sizeof tmpbuf))) {
119 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_READ_ERROR);
122 BIO_write(mem, tmpbuf, len);
124 if(BIO_gets(mem, tmpbuf, 512) <= 0) {
125 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
128 /* Parse the HTTP response. This will look like this:
129 * "HTTP/1.0 200 OK". We need to obtain the numeric code and
130 * (optional) informational message.
133 /* Skip to first white space (passed protocol info) */
134 for(p = tmpbuf; *p && !isspace((unsigned char)*p); p++) continue;
136 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
139 /* Skip past white space to start of response code */
140 while(*p && isspace((unsigned char)*p)) p++;
142 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
145 /* Find end of response code: first whitespace after start of code */
146 for(q = p; *q && !isspace((unsigned char)*q); q++) continue;
148 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
151 /* Set end of response code and start of message */
153 /* Attempt to parse numeric code */
154 retcode = strtoul(p, &r, 10);
156 /* Skip over any leading white space in message */
157 while(*q && isspace((unsigned char)*q)) q++;
159 /* Finally zap any trailing white space in message (include CRLF) */
160 /* We know q has a non white space character so this is OK */
161 for(r = q + strlen(q) - 1; isspace((unsigned char)*r); r--) *r = 0;
164 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_ERROR);
166 ERR_add_error_data(2, "Code=", p);
169 ERR_add_error_data(4, "Code=", p, ",Reason=", q);
173 /* Find blank line marking beginning of content */
174 while(BIO_gets(mem, tmpbuf, 512) > 0)
176 for(p = tmpbuf; *p && isspace((unsigned char)*p); p++) continue;
180 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_NO_CONTENT);
183 if(!(resp = d2i_OCSP_RESPONSE_bio(mem, NULL))) {
184 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,ERR_R_NESTED_ASN1_ERROR);