diff options
author | beck <> | 2002-05-15 02:29:21 +0000 |
---|---|---|
committer | beck <> | 2002-05-15 02:29:21 +0000 |
commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/ocsp/ocsp_ht.c | |
parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
download | openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2 openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip |
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/ocsp/ocsp_ht.c')
-rw-r--r-- | src/lib/libcrypto/ocsp/ocsp_ht.c | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/src/lib/libcrypto/ocsp/ocsp_ht.c b/src/lib/libcrypto/ocsp/ocsp_ht.c new file mode 100644 index 0000000000..b78cd37092 --- /dev/null +++ b/src/lib/libcrypto/ocsp/ocsp_ht.c | |||
@@ -0,0 +1,164 @@ | |||
1 | /* ocsp_ht.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
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 | ||
18 | * distribution. | ||
19 | * | ||
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/)" | ||
24 | * | ||
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. | ||
29 | * | ||
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. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
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 | * ==================================================================== | ||
52 | * | ||
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). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <openssl/asn1.h> | ||
60 | #include <stdio.h> | ||
61 | #include <stdlib.h> | ||
62 | #include <ctype.h> | ||
63 | #include <string.h> | ||
64 | #include <openssl/ocsp.h> | ||
65 | #include <openssl/err.h> | ||
66 | #include <openssl/buffer.h> | ||
67 | |||
68 | /* Quick and dirty HTTP OCSP request handler. | ||
69 | * Could make this a bit cleverer by adding | ||
70 | * support for non blocking BIOs and a few | ||
71 | * other refinements. | ||
72 | */ | ||
73 | |||
74 | OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req) | ||
75 | { | ||
76 | BIO *mem = NULL; | ||
77 | char tmpbuf[1024]; | ||
78 | OCSP_RESPONSE *resp = NULL; | ||
79 | char *p, *q, *r; | ||
80 | int len, retcode; | ||
81 | static char req_txt[] = | ||
82 | "POST %s HTTP/1.0\r\n\ | ||
83 | Content-Type: application/ocsp-request\r\n\ | ||
84 | Content-Length: %d\r\n\r\n"; | ||
85 | |||
86 | len = i2d_OCSP_REQUEST(req, NULL); | ||
87 | if(BIO_printf(b, req_txt, path, len) < 0) { | ||
88 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_WRITE_ERROR); | ||
89 | goto err; | ||
90 | } | ||
91 | if(i2d_OCSP_REQUEST_bio(b, req) <= 0) { | ||
92 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_WRITE_ERROR); | ||
93 | goto err; | ||
94 | } | ||
95 | if(!(mem = BIO_new(BIO_s_mem()))) goto err; | ||
96 | /* Copy response to a memory BIO: socket bios can't do gets! */ | ||
97 | while ((len = BIO_read(b, tmpbuf, 1024))) { | ||
98 | if(len < 0) { | ||
99 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_READ_ERROR); | ||
100 | goto err; | ||
101 | } | ||
102 | BIO_write(mem, tmpbuf, len); | ||
103 | } | ||
104 | if(BIO_gets(mem, tmpbuf, 512) <= 0) { | ||
105 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR); | ||
106 | goto err; | ||
107 | } | ||
108 | /* Parse the HTTP response. This will look like this: | ||
109 | * "HTTP/1.0 200 OK". We need to obtain the numeric code and | ||
110 | * informational message. | ||
111 | */ | ||
112 | |||
113 | /* Skip to first white space (passed protocol info) */ | ||
114 | for(p = tmpbuf; *p && !isspace((unsigned char)*p); p++) continue; | ||
115 | if(!*p) { | ||
116 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR); | ||
117 | goto err; | ||
118 | } | ||
119 | /* Skip past white space to start of response code */ | ||
120 | while(*p && isspace((unsigned char)*p)) p++; | ||
121 | if(!*p) { | ||
122 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR); | ||
123 | goto err; | ||
124 | } | ||
125 | /* Find end of response code: first whitespace after start of code */ | ||
126 | for(q = p; *q && !isspace((unsigned char)*q); q++) continue; | ||
127 | if(!*q) { | ||
128 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR); | ||
129 | goto err; | ||
130 | } | ||
131 | /* Set end of response code and start of message */ | ||
132 | *q++ = 0; | ||
133 | /* Attempt to parse numeric code */ | ||
134 | retcode = strtoul(p, &r, 10); | ||
135 | if(*r) goto err; | ||
136 | /* Skip over any leading white space in message */ | ||
137 | while(*q && isspace((unsigned char)*q)) q++; | ||
138 | if(!*q) goto err; | ||
139 | /* Finally zap any trailing white space in message (include CRLF) */ | ||
140 | /* We know q has a non white space character so this is OK */ | ||
141 | for(r = q + strlen(q) - 1; isspace((unsigned char)*r); r--) *r = 0; | ||
142 | if(retcode != 200) { | ||
143 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_ERROR); | ||
144 | ERR_add_error_data(4, "Code=", p, ",Reason=", q); | ||
145 | goto err; | ||
146 | } | ||
147 | /* Find blank line marking beginning of content */ | ||
148 | while(BIO_gets(mem, tmpbuf, 512) > 0) | ||
149 | { | ||
150 | for(p = tmpbuf; *p && isspace((unsigned char)*p); p++) continue; | ||
151 | if(!*p) break; | ||
152 | } | ||
153 | if(*p) { | ||
154 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_NO_CONTENT); | ||
155 | goto err; | ||
156 | } | ||
157 | if(!(resp = d2i_OCSP_RESPONSE_bio(mem, NULL))) { | ||
158 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,ERR_R_NESTED_ASN1_ERROR); | ||
159 | goto err; | ||
160 | } | ||
161 | err: | ||
162 | BIO_free(mem); | ||
163 | return resp; | ||
164 | } | ||