diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/ocspcheck/CMakeLists.txt | 14 | ||||
-rw-r--r-- | apps/ocspcheck/Makefile.am | 8 | ||||
-rw-r--r-- | apps/ocspcheck/compat/inet_ntop.c | 204 | ||||
-rw-r--r-- | apps/ocspcheck/compat/memmem.c | 63 |
4 files changed, 289 insertions, 0 deletions
diff --git a/apps/ocspcheck/CMakeLists.txt b/apps/ocspcheck/CMakeLists.txt index 87a22d2..5e4639f 100644 --- a/apps/ocspcheck/CMakeLists.txt +++ b/apps/ocspcheck/CMakeLists.txt | |||
@@ -11,6 +11,20 @@ set( | |||
11 | ocspcheck.c | 11 | ocspcheck.c |
12 | ) | 12 | ) |
13 | 13 | ||
14 | check_function_exists(inet_ntop HAVE_INET_NTOP) | ||
15 | if(HAVE_INET_NTOP) | ||
16 | add_definitions(-DHAVE_INET_NTOP) | ||
17 | else() | ||
18 | set(OCSPCHECK_SRC ${OCSPCHECK_SRC} compat/inet_ntop.c) | ||
19 | endif() | ||
20 | |||
21 | check_function_exists(inet_ntop HAVE_MEMMEM) | ||
22 | if(HAVE_MEMMEM) | ||
23 | add_definitions(-DHAVE_MEMMEM) | ||
24 | else() | ||
25 | set(OCSPCHECK_SRC ${OCSPCHECK_SRC} compat/memmem.c) | ||
26 | endif() | ||
27 | |||
14 | if(NOT "${OPENSSLDIR}" STREQUAL "") | 28 | if(NOT "${OPENSSLDIR}" STREQUAL "") |
15 | add_definitions(-DDEFAULT_CA_FILE=\"${OPENSSLDIR}/cert.pem\") | 29 | add_definitions(-DDEFAULT_CA_FILE=\"${OPENSSLDIR}/cert.pem\") |
16 | else() | 30 | else() |
diff --git a/apps/ocspcheck/Makefile.am b/apps/ocspcheck/Makefile.am index 2f6540d..f7eb131 100644 --- a/apps/ocspcheck/Makefile.am +++ b/apps/ocspcheck/Makefile.am | |||
@@ -13,3 +13,11 @@ ocspcheck_LDADD += $(PLATFORM_LDADD) $(PROG_LDADD) | |||
13 | ocspcheck_SOURCES = http.c | 13 | ocspcheck_SOURCES = http.c |
14 | ocspcheck_SOURCES += ocspcheck.c | 14 | ocspcheck_SOURCES += ocspcheck.c |
15 | noinst_HEADERS = http.h | 15 | noinst_HEADERS = http.h |
16 | |||
17 | if !HAVE_INET_NTOP | ||
18 | ocspcheck_SOURCES += compat/inet_ntop.c | ||
19 | endif | ||
20 | |||
21 | if !HAVE_MEMMEM | ||
22 | ocspcheck_SOURCES += compat/memmem.c | ||
23 | endif | ||
diff --git a/apps/ocspcheck/compat/inet_ntop.c b/apps/ocspcheck/compat/inet_ntop.c new file mode 100644 index 0000000..016d3d7 --- /dev/null +++ b/apps/ocspcheck/compat/inet_ntop.c | |||
@@ -0,0 +1,204 @@ | |||
1 | /* $OpenBSD: inet_ntop.c,v 1.12 2015/09/13 21:36:08 guenther Exp $ */ | ||
2 | |||
3 | /* Copyright (c) 1996 by Internet Software Consortium. | ||
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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
10 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
11 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
12 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
13 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
14 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
15 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
16 | * SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <sys/types.h> | ||
20 | #include <sys/socket.h> | ||
21 | #include <netinet/in.h> | ||
22 | #include <arpa/inet.h> | ||
23 | #include <arpa/nameser.h> | ||
24 | #include <string.h> | ||
25 | #include <errno.h> | ||
26 | #include <stdio.h> | ||
27 | |||
28 | /* | ||
29 | * WARNING: Don't even consider trying to compile this on a system where | ||
30 | * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. | ||
31 | */ | ||
32 | |||
33 | static const char *inet_ntop4(const u_char *src, char *dst, size_t size); | ||
34 | static const char *inet_ntop6(const u_char *src, char *dst, size_t size); | ||
35 | |||
36 | /* const char * | ||
37 | * inet_ntop(af, src, dst, size) | ||
38 | * convert a network format address to presentation format. | ||
39 | * return: | ||
40 | * pointer to presentation format address (`dst'), or NULL (see errno). | ||
41 | * author: | ||
42 | * Paul Vixie, 1996. | ||
43 | */ | ||
44 | const char * | ||
45 | inet_ntop(int af, const void *src, char *dst, socklen_t size) | ||
46 | { | ||
47 | switch (af) { | ||
48 | case AF_INET: | ||
49 | return (inet_ntop4(src, dst, size)); | ||
50 | case AF_INET6: | ||
51 | return (inet_ntop6(src, dst, size)); | ||
52 | default: | ||
53 | errno = EAFNOSUPPORT; | ||
54 | return (NULL); | ||
55 | } | ||
56 | /* NOTREACHED */ | ||
57 | } | ||
58 | |||
59 | /* const char * | ||
60 | * inet_ntop4(src, dst, size) | ||
61 | * format an IPv4 address, more or less like inet_ntoa() | ||
62 | * return: | ||
63 | * `dst' (as a const) | ||
64 | * notes: | ||
65 | * (1) uses no statics | ||
66 | * (2) takes a u_char* not an in_addr as input | ||
67 | * author: | ||
68 | * Paul Vixie, 1996. | ||
69 | */ | ||
70 | static const char * | ||
71 | inet_ntop4(const u_char *src, char *dst, size_t size) | ||
72 | { | ||
73 | char tmp[sizeof "255.255.255.255"]; | ||
74 | int l; | ||
75 | |||
76 | l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u", | ||
77 | src[0], src[1], src[2], src[3]); | ||
78 | if (l <= 0 || l >= size) { | ||
79 | errno = ENOSPC; | ||
80 | return (NULL); | ||
81 | } | ||
82 | strlcpy(dst, tmp, size); | ||
83 | return (dst); | ||
84 | } | ||
85 | |||
86 | /* const char * | ||
87 | * inet_ntop6(src, dst, size) | ||
88 | * convert IPv6 binary address into presentation (printable) format | ||
89 | * author: | ||
90 | * Paul Vixie, 1996. | ||
91 | */ | ||
92 | static const char * | ||
93 | inet_ntop6(const u_char *src, char *dst, size_t size) | ||
94 | { | ||
95 | /* | ||
96 | * Note that int32_t and int16_t need only be "at least" large enough | ||
97 | * to contain a value of the specified size. On some systems, like | ||
98 | * Crays, there is no such thing as an integer variable with 16 bits. | ||
99 | * Keep this in mind if you think this function should have been coded | ||
100 | * to use pointer overlays. All the world's not a VAX. | ||
101 | */ | ||
102 | char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; | ||
103 | char *tp, *ep; | ||
104 | struct { int base, len; } best, cur; | ||
105 | u_int words[IN6ADDRSZ / INT16SZ]; | ||
106 | int i; | ||
107 | int advance; | ||
108 | |||
109 | /* | ||
110 | * Preprocess: | ||
111 | * Copy the input (bytewise) array into a wordwise array. | ||
112 | * Find the longest run of 0x00's in src[] for :: shorthanding. | ||
113 | */ | ||
114 | memset(words, '\0', sizeof words); | ||
115 | for (i = 0; i < IN6ADDRSZ; i++) | ||
116 | words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); | ||
117 | best.base = -1; | ||
118 | cur.base = -1; | ||
119 | for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { | ||
120 | if (words[i] == 0) { | ||
121 | if (cur.base == -1) | ||
122 | cur.base = i, cur.len = 1; | ||
123 | else | ||
124 | cur.len++; | ||
125 | } else { | ||
126 | if (cur.base != -1) { | ||
127 | if (best.base == -1 || cur.len > best.len) | ||
128 | best = cur; | ||
129 | cur.base = -1; | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | if (cur.base != -1) { | ||
134 | if (best.base == -1 || cur.len > best.len) | ||
135 | best = cur; | ||
136 | } | ||
137 | if (best.base != -1 && best.len < 2) | ||
138 | best.base = -1; | ||
139 | |||
140 | /* | ||
141 | * Format the result. | ||
142 | */ | ||
143 | tp = tmp; | ||
144 | ep = tmp + sizeof(tmp); | ||
145 | for (i = 0; i < (IN6ADDRSZ / INT16SZ) && tp < ep; i++) { | ||
146 | /* Are we inside the best run of 0x00's? */ | ||
147 | if (best.base != -1 && i >= best.base && | ||
148 | i < (best.base + best.len)) { | ||
149 | if (i == best.base) { | ||
150 | if (tp + 1 >= ep) { | ||
151 | errno = ENOSPC; | ||
152 | return (NULL); | ||
153 | } | ||
154 | *tp++ = ':'; | ||
155 | } | ||
156 | continue; | ||
157 | } | ||
158 | /* Are we following an initial run of 0x00s or any real hex? */ | ||
159 | if (i != 0) { | ||
160 | if (tp + 1 >= ep) { | ||
161 | errno = ENOSPC; | ||
162 | return (NULL); | ||
163 | } | ||
164 | *tp++ = ':'; | ||
165 | } | ||
166 | /* Is this address an encapsulated IPv4? */ | ||
167 | if (i == 6 && best.base == 0 && | ||
168 | (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { | ||
169 | if (!inet_ntop4(src+12, tp, ep - tp)) | ||
170 | return (NULL); | ||
171 | tp += strlen(tp); | ||
172 | break; | ||
173 | } | ||
174 | advance = snprintf(tp, ep - tp, "%x", words[i]); | ||
175 | if (advance <= 0 || advance >= ep - tp) { | ||
176 | errno = ENOSPC; | ||
177 | return (NULL); | ||
178 | } | ||
179 | tp += advance; | ||
180 | } | ||
181 | /* Was it a trailing run of 0x00's? */ | ||
182 | if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) { | ||
183 | if (tp + 1 >= ep) { | ||
184 | errno = ENOSPC; | ||
185 | return (NULL); | ||
186 | } | ||
187 | *tp++ = ':'; | ||
188 | } | ||
189 | if (tp + 1 >= ep) { | ||
190 | errno = ENOSPC; | ||
191 | return (NULL); | ||
192 | } | ||
193 | *tp++ = '\0'; | ||
194 | |||
195 | /* | ||
196 | * Check for overflow, copy, and we're done. | ||
197 | */ | ||
198 | if ((size_t)(tp - tmp) > size) { | ||
199 | errno = ENOSPC; | ||
200 | return (NULL); | ||
201 | } | ||
202 | strlcpy(dst, tmp, size); | ||
203 | return (dst); | ||
204 | } | ||
diff --git a/apps/ocspcheck/compat/memmem.c b/apps/ocspcheck/compat/memmem.c new file mode 100644 index 0000000..5793a7d --- /dev/null +++ b/apps/ocspcheck/compat/memmem.c | |||
@@ -0,0 +1,63 @@ | |||
1 | /* $OpenBSD: memmem.c,v 1.3 2013/05/30 01:10:45 ajacoutot Exp $ */ | ||
2 | /*- | ||
3 | * Copyright (c) 2005 Pascal Gloor <pascal.gloor@spale.com> | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * 1. Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * 2. Redistributions in binary form must reproduce the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer in the | ||
12 | * documentation and/or other materials provided with the distribution. | ||
13 | * 3. The name of the author may not be used to endorse or promote | ||
14 | * products derived from this software without specific prior written | ||
15 | * permission. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
27 | * SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #include <string.h> | ||
31 | |||
32 | /* | ||
33 | * Find the first occurrence of the byte string s in byte string l. | ||
34 | */ | ||
35 | |||
36 | void * | ||
37 | memmem(const void *l, size_t l_len, const void *s, size_t s_len) | ||
38 | { | ||
39 | const char *cur, *last; | ||
40 | const char *cl = l; | ||
41 | const char *cs = s; | ||
42 | |||
43 | /* a zero length needle should just return the haystack */ | ||
44 | if (s_len == 0) | ||
45 | return (void *)cl; | ||
46 | |||
47 | /* "s" must be smaller or equal to "l" */ | ||
48 | if (l_len < s_len) | ||
49 | return NULL; | ||
50 | |||
51 | /* special case where s_len == 1 */ | ||
52 | if (s_len == 1) | ||
53 | return memchr(l, *cs, l_len); | ||
54 | |||
55 | /* the last position where its possible to find "s" in "l" */ | ||
56 | last = cl + l_len - s_len; | ||
57 | |||
58 | for (cur = cl; cur <= last; cur++) | ||
59 | if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0) | ||
60 | return (void *)cur; | ||
61 | |||
62 | return NULL; | ||
63 | } | ||