diff options
| author | bcook <> | 2014-12-03 22:16:02 +0000 |
|---|---|---|
| committer | bcook <> | 2014-12-03 22:16:02 +0000 |
| commit | 56ba4dfacce3236710ca61edbd40744a424ca728 (patch) | |
| tree | e603f3b2b9b847e1ad959cceefe86bfb3d1513d9 | |
| parent | dce88910ead3a43bc663d7d9e46e2689189ac19d (diff) | |
| download | openbsd-56ba4dfacce3236710ca61edbd40744a424ca728.tar.gz openbsd-56ba4dfacce3236710ca61edbd40744a424ca728.tar.bz2 openbsd-56ba4dfacce3236710ca61edbd40744a424ca728.zip | |
Move Windows OS-specific functions to make porting easier.
Several functions that need to be redefined for a Windows port are right
in the middle of other code that is relatively portable. This patch
isolates the functions that need Windows-specific implementations so
they can be built conditionally in the portable tree.
Add calls to BIO_sock_init() as-needed to openssl(1) so that socket IO works on
Windows. Sorry, these are no-op on other platforms.
ok jsing@ deraadt@
Diffstat (limited to '')
| -rw-r--r-- | src/usr.bin/openssl/Makefile | 15 | ||||
| -rw-r--r-- | src/usr.bin/openssl/apps.c | 25 | ||||
| -rw-r--r-- | src/usr.bin/openssl/apps_posix.c | 144 | ||||
| -rw-r--r-- | src/usr.bin/openssl/s_socket.c | 12 |
4 files changed, 165 insertions, 31 deletions
diff --git a/src/usr.bin/openssl/Makefile b/src/usr.bin/openssl/Makefile index 015d9abeb6..1619163a13 100644 --- a/src/usr.bin/openssl/Makefile +++ b/src/usr.bin/openssl/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/09/10 16:51:42 jsing Exp $ | 1 | # $OpenBSD: Makefile,v 1.4 2014/12/03 22:16:02 bcook Exp $ |
| 2 | 2 | ||
| 3 | PROG= openssl | 3 | PROG= openssl |
| 4 | LDADD= -lssl -lcrypto | 4 | LDADD= -lssl -lcrypto |
| @@ -17,11 +17,12 @@ CFLAGS+= -Wunused | |||
| 17 | 17 | ||
| 18 | CFLAGS+= -DLIBRESSL_INTERNAL | 18 | CFLAGS+= -DLIBRESSL_INTERNAL |
| 19 | 19 | ||
| 20 | SRCS= apps.c asn1pars.c ca.c ciphers.c cms.c crl.c crl2p7.c dgst.c dh.c \ | 20 | SRCS= apps.c apps_posix.c asn1pars.c ca.c ciphers.c cms.c crl.c crl2p7.c \ |
| 21 | dhparam.c dsa.c dsaparam.c ec.c ecparam.c enc.c engine.c errstr.c \ | 21 | dgst.c dh.c dhparam.c dsa.c dsaparam.c ec.c ecparam.c enc.c engine.c \ |
| 22 | gendh.c gendsa.c genpkey.c genrsa.c nseq.c ocsp.c openssl.c passwd.c \ | 22 | errstr.c gendh.c gendsa.c genpkey.c genrsa.c nseq.c ocsp.c openssl.c \ |
| 23 | pkcs12.c pkcs7.c pkcs8.c pkey.c pkeyparam.c pkeyutl.c prime.c rand.c \ | 23 | passwd.c pkcs12.c pkcs7.c pkcs8.c pkey.c pkeyparam.c pkeyutl.c prime.c \ |
| 24 | req.c rsa.c rsautl.c s_cb.c s_client.c s_server.c s_socket.c s_time.c \ | 24 | rand.c req.c rsa.c rsautl.c s_cb.c s_client.c s_server.c s_socket.c \ |
| 25 | sess_id.c smime.c speed.c spkac.c ts.c verify.c version.c x509.c | 25 | s_time.c sess_id.c smime.c speed.c spkac.c ts.c verify.c version.c \ |
| 26 | x509.c | ||
| 26 | 27 | ||
| 27 | .include <bsd.prog.mk> | 28 | .include <bsd.prog.mk> |
diff --git a/src/usr.bin/openssl/apps.c b/src/usr.bin/openssl/apps.c index 78555528b6..a042f074f9 100644 --- a/src/usr.bin/openssl/apps.c +++ b/src/usr.bin/openssl/apps.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: apps.c,v 1.12 2014/11/07 14:16:48 jsing Exp $ */ | 1 | /* $OpenBSD: apps.c,v 1.13 2014/12/03 22:16:02 bcook Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -2205,27 +2205,6 @@ next_protos_parse(unsigned short *outlen, const char *in) | |||
| 2205 | #endif | 2205 | #endif |
| 2206 | /* !OPENSSL_NO_NEXTPROTONEG */ | 2206 | /* !OPENSSL_NO_NEXTPROTONEG */ |
| 2207 | 2207 | ||
| 2208 | double | ||
| 2209 | app_tminterval(int stop, int usertime) | ||
| 2210 | { | ||
| 2211 | double ret = 0; | ||
| 2212 | struct tms rus; | ||
| 2213 | clock_t now = times(&rus); | ||
| 2214 | static clock_t tmstart; | ||
| 2215 | |||
| 2216 | if (usertime) | ||
| 2217 | now = rus.tms_utime; | ||
| 2218 | |||
| 2219 | if (stop == TM_START) | ||
| 2220 | tmstart = now; | ||
| 2221 | else { | ||
| 2222 | long int tck = sysconf(_SC_CLK_TCK); | ||
| 2223 | ret = (now - tmstart) / (double) tck; | ||
| 2224 | } | ||
| 2225 | |||
| 2226 | return (ret); | ||
| 2227 | } | ||
| 2228 | |||
| 2229 | int | 2208 | int |
| 2230 | app_isdir(const char *name) | 2209 | app_isdir(const char *name) |
| 2231 | { | 2210 | { |
| @@ -2341,7 +2320,7 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) | |||
| 2341 | if (opt->func(opt, NULL) != 0) | 2320 | if (opt->func(opt, NULL) != 0) |
| 2342 | return (1); | 2321 | return (1); |
| 2343 | break; | 2322 | break; |
| 2344 | 2323 | ||
| 2345 | case OPTION_FLAG: | 2324 | case OPTION_FLAG: |
| 2346 | *opt->opt.flag = 1; | 2325 | *opt->opt.flag = 1; |
| 2347 | break; | 2326 | break; |
diff --git a/src/usr.bin/openssl/apps_posix.c b/src/usr.bin/openssl/apps_posix.c new file mode 100644 index 0000000000..c49a23a653 --- /dev/null +++ b/src/usr.bin/openssl/apps_posix.c | |||
| @@ -0,0 +1,144 @@ | |||
| 1 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 2 | * All rights reserved. | ||
| 3 | * | ||
| 4 | * This package is an SSL implementation written | ||
| 5 | * by Eric Young (eay@cryptsoft.com). | ||
| 6 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 7 | * | ||
| 8 | * This library is free for commercial and non-commercial use as long as | ||
| 9 | * the following conditions are aheared to. The following conditions | ||
| 10 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 11 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 12 | * included with this distribution is covered by the same copyright terms | ||
| 13 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 14 | * | ||
| 15 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 16 | * the code are not to be removed. | ||
| 17 | * If this package is used in a product, Eric Young should be given attribution | ||
| 18 | * as the author of the parts of the library used. | ||
| 19 | * This can be in the form of a textual message at program startup or | ||
| 20 | * in documentation (online or textual) provided with the package. | ||
| 21 | * | ||
| 22 | * Redistribution and use in source and binary forms, with or without | ||
| 23 | * modification, are permitted provided that the following conditions | ||
| 24 | * are met: | ||
| 25 | * 1. Redistributions of source code must retain the copyright | ||
| 26 | * notice, this list of conditions and the following disclaimer. | ||
| 27 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 28 | * notice, this list of conditions and the following disclaimer in the | ||
| 29 | * documentation and/or other materials provided with the distribution. | ||
| 30 | * 3. All advertising materials mentioning features or use of this software | ||
| 31 | * must display the following acknowledgement: | ||
| 32 | * "This product includes cryptographic software written by | ||
| 33 | * Eric Young (eay@cryptsoft.com)" | ||
| 34 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 35 | * being used are not cryptographic related :-). | ||
| 36 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 37 | * the apps directory (application code) you must include an acknowledgement: | ||
| 38 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 43 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 46 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 50 | * SUCH DAMAGE. | ||
| 51 | * | ||
| 52 | * The licence and distribution terms for any publically available version or | ||
| 53 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 54 | * copied and put under another distribution licence | ||
| 55 | * [including the GNU Public Licence.] | ||
| 56 | */ | ||
| 57 | /* ==================================================================== | ||
| 58 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | ||
| 59 | * | ||
| 60 | * Redistribution and use in source and binary forms, with or without | ||
| 61 | * modification, are permitted provided that the following conditions | ||
| 62 | * are met: | ||
| 63 | * | ||
| 64 | * 1. Redistributions of source code must retain the above copyright | ||
| 65 | * notice, this list of conditions and the following disclaimer. | ||
| 66 | * | ||
| 67 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 68 | * notice, this list of conditions and the following disclaimer in | ||
| 69 | * the documentation and/or other materials provided with the | ||
| 70 | * distribution. | ||
| 71 | * | ||
| 72 | * 3. All advertising materials mentioning features or use of this | ||
| 73 | * software must display the following acknowledgment: | ||
| 74 | * "This product includes software developed by the OpenSSL Project | ||
| 75 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 76 | * | ||
| 77 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 78 | * endorse or promote products derived from this software without | ||
| 79 | * prior written permission. For written permission, please contact | ||
| 80 | * openssl-core@openssl.org. | ||
| 81 | * | ||
| 82 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 83 | * nor may "OpenSSL" appear in their names without prior written | ||
| 84 | * permission of the OpenSSL Project. | ||
| 85 | * | ||
| 86 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 87 | * nor may "OpenSSL" appear in their names without prior written | ||
| 88 | * permission of the OpenSSL Project. | ||
| 89 | * | ||
| 90 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 91 | * acknowledgment: | ||
| 92 | * "This product includes software developed by the OpenSSL Project | ||
| 93 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 94 | * | ||
| 95 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 96 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 97 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 98 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 99 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 100 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 101 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 102 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 103 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 104 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 105 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 106 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 107 | * ==================================================================== | ||
| 108 | * | ||
| 109 | * This product includes cryptographic software written by Eric Young | ||
| 110 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 111 | * Hudson (tjh@cryptsoft.com). | ||
| 112 | * | ||
| 113 | */ | ||
| 114 | |||
| 115 | /* | ||
| 116 | * Functions that need to be overridden by non-POSIX operating systems. | ||
| 117 | */ | ||
| 118 | |||
| 119 | #include <sys/times.h> | ||
| 120 | |||
| 121 | #include <unistd.h> | ||
| 122 | |||
| 123 | #include "apps.h" | ||
| 124 | |||
| 125 | double | ||
| 126 | app_tminterval(int stop, int usertime) | ||
| 127 | { | ||
| 128 | double ret = 0; | ||
| 129 | struct tms rus; | ||
| 130 | clock_t now = times(&rus); | ||
| 131 | static clock_t tmstart; | ||
| 132 | |||
| 133 | if (usertime) | ||
| 134 | now = rus.tms_utime; | ||
| 135 | |||
| 136 | if (stop == TM_START) | ||
| 137 | tmstart = now; | ||
| 138 | else { | ||
| 139 | long int tck = sysconf(_SC_CLK_TCK); | ||
| 140 | ret = (now - tmstart) / (double) tck; | ||
| 141 | } | ||
| 142 | |||
| 143 | return (ret); | ||
| 144 | } | ||
diff --git a/src/usr.bin/openssl/s_socket.c b/src/usr.bin/openssl/s_socket.c index 2ce31eb5ef..7c416d69be 100644 --- a/src/usr.bin/openssl/s_socket.c +++ b/src/usr.bin/openssl/s_socket.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: s_socket.c,v 1.2 2014/11/06 13:46:09 jsing Exp $ */ | 1 | /* $OpenBSD: s_socket.c,v 1.3 2014/12/03 22:16:02 bcook Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -85,6 +85,11 @@ init_client(int *sock, char *host, char *port, int type, int af) | |||
| 85 | struct addrinfo hints, *ai_top, *ai; | 85 | struct addrinfo hints, *ai_top, *ai; |
| 86 | int i, s; | 86 | int i, s; |
| 87 | 87 | ||
| 88 | if (BIO_sock_init() != 1) { | ||
| 89 | BIO_printf(bio_err, "BIO_sock_init failed\n"); | ||
| 90 | return (0); | ||
| 91 | } | ||
| 92 | |||
| 88 | memset(&hints, '\0', sizeof(hints)); | 93 | memset(&hints, '\0', sizeof(hints)); |
| 89 | hints.ai_family = af; | 94 | hints.ai_family = af; |
| 90 | hints.ai_socktype = type; | 95 | hints.ai_socktype = type; |
| @@ -176,6 +181,11 @@ init_server_long(int *sock, int port, char *ip, int type) | |||
| 176 | struct sockaddr_in server; | 181 | struct sockaddr_in server; |
| 177 | int s = -1; | 182 | int s = -1; |
| 178 | 183 | ||
| 184 | if (BIO_sock_init() != 1) { | ||
| 185 | BIO_printf(bio_err, "BIO_sock_init failed\n"); | ||
| 186 | return (0); | ||
| 187 | } | ||
| 188 | |||
| 179 | memset((char *) &server, 0, sizeof(server)); | 189 | memset((char *) &server, 0, sizeof(server)); |
| 180 | server.sin_family = AF_INET; | 190 | server.sin_family = AF_INET; |
| 181 | server.sin_port = htons((unsigned short) port); | 191 | server.sin_port = htons((unsigned short) port); |
