diff options
author | beck <> | 2017-01-24 08:50:57 +0000 |
---|---|---|
committer | beck <> | 2017-01-24 08:50:57 +0000 |
commit | f748422c1c8c084effc6cacbef92cb4ee75c13d6 (patch) | |
tree | a8f074f9e36fc17e90b2be5b61a6676a5a58757c /src/usr.sbin/ocspcheck/http.h | |
parent | 461ec96400c0a98b56a42533ecf86de58bc3c16f (diff) | |
download | openbsd-f748422c1c8c084effc6cacbef92cb4ee75c13d6.tar.gz openbsd-f748422c1c8c084effc6cacbef92cb4ee75c13d6.tar.bz2 openbsd-f748422c1c8c084effc6cacbef92cb4ee75c13d6.zip |
New ocspcheck utility to validate a certificate against its ocsp responder
and save the reply for stapling
ok deraadt@ jsing@
Diffstat (limited to 'src/usr.sbin/ocspcheck/http.h')
-rw-r--r-- | src/usr.sbin/ocspcheck/http.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/usr.sbin/ocspcheck/http.h b/src/usr.sbin/ocspcheck/http.h new file mode 100644 index 0000000000..b4e66f21d3 --- /dev/null +++ b/src/usr.sbin/ocspcheck/http.h | |||
@@ -0,0 +1,96 @@ | |||
1 | /* $Id: http.h,v 1.1 2017/01/24 08:50:57 beck Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2016 Kristaps Dzonsons <kristaps@bsd.lv> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | #ifndef HTTP_H | ||
18 | #define HTTP_H | ||
19 | |||
20 | struct source { | ||
21 | int family; /* 4 (PF_INET) or 6 (PF_INET6) */ | ||
22 | char *ip; /* IPV4 or IPV6 address */ | ||
23 | }; | ||
24 | |||
25 | struct http; | ||
26 | |||
27 | /* | ||
28 | * Write and read callbacks to allow HTTP and HTTPS. | ||
29 | * Both of these return the number of bytes read (or written) or -1 on | ||
30 | * failure. | ||
31 | * 0 bytes read means that the connection has closed. | ||
32 | */ | ||
33 | typedef ssize_t (*writefp)(const void *, size_t, const struct http *); | ||
34 | typedef ssize_t (*readfp)(char *, size_t, const struct http *); | ||
35 | |||
36 | /* | ||
37 | * HTTP/S header pair. | ||
38 | * There's also a cooked-up pair, "Status", with the status code. | ||
39 | * Both strings are nil-terminated. | ||
40 | */ | ||
41 | struct httphead { | ||
42 | const char *key; | ||
43 | const char *val; | ||
44 | }; | ||
45 | |||
46 | /* | ||
47 | * Grab all information from a transfer. | ||
48 | * DO NOT free any parts of this, and editing the parts (e.g., changing | ||
49 | * the underlying strings) will persist; so in short, don't. | ||
50 | * All of these values will be set upon http_get() success. | ||
51 | */ | ||
52 | struct httpget { | ||
53 | struct httpxfer *xfer; /* underlying transfer */ | ||
54 | struct http *http; /* underlying connection */ | ||
55 | int code; /* return code */ | ||
56 | struct httphead *head; /* headers */ | ||
57 | size_t headsz; /* number of headers */ | ||
58 | char *headpart; /* header buffer */ | ||
59 | size_t headpartsz; /* size of headpart */ | ||
60 | char *bodypart; /* body buffer */ | ||
61 | size_t bodypartsz; /* size of bodypart */ | ||
62 | }; | ||
63 | |||
64 | __BEGIN_DECLS | ||
65 | |||
66 | int http_init(void); | ||
67 | |||
68 | /* Convenience functions. */ | ||
69 | struct httpget *http_get(const struct source *, size_t, | ||
70 | const char *, short, const char *, | ||
71 | const void *, size_t); | ||
72 | void http_get_free(struct httpget *); | ||
73 | |||
74 | /* Allocation and release. */ | ||
75 | struct http *http_alloc(const struct source *, size_t, | ||
76 | const char *, short, const char *); | ||
77 | void http_free(struct http *); | ||
78 | struct httpxfer *http_open(const struct http *, const void *, size_t); | ||
79 | void http_close(struct httpxfer *); | ||
80 | void http_disconnect(struct http *); | ||
81 | |||
82 | /* Access. */ | ||
83 | char *http_head_read(const struct http *, | ||
84 | struct httpxfer *, size_t *); | ||
85 | struct httphead *http_head_parse(const struct http *, | ||
86 | struct httpxfer *, size_t *); | ||
87 | char *http_body_read(const struct http *, | ||
88 | struct httpxfer *, size_t *); | ||
89 | int http_head_status(const struct http *, | ||
90 | struct httphead *, size_t); | ||
91 | struct httphead *http_head_get(const char *, | ||
92 | struct httphead *, size_t); | ||
93 | |||
94 | __END_DECLS | ||
95 | |||
96 | #endif /* HTTP_H */ | ||