diff options
author | Brent Cook <bcook@cvs.openbsd.org> | 2014-12-03 22:16:03 +0000 |
---|---|---|
committer | Brent Cook <bcook@cvs.openbsd.org> | 2014-12-03 22:16:03 +0000 |
commit | d8252f2f357fba523067ddd8db8369329b2c1ef1 (patch) | |
tree | 12548eebff5fc81dd8a16d12bc637345e5758ba1 /usr.bin | |
parent | 245410b1179d4efd8904438860b37c3b3e47a5cb (diff) |
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 'usr.bin')
-rw-r--r-- | usr.bin/openssl/Makefile | 15 | ||||
-rw-r--r-- | usr.bin/openssl/apps.c | 25 | ||||
-rw-r--r-- | usr.bin/openssl/apps_posix.c | 144 | ||||
-rw-r--r-- | usr.bin/openssl/s_socket.c | 12 |
4 files changed, 165 insertions, 31 deletions
diff --git a/usr.bin/openssl/Makefile b/usr.bin/openssl/Makefile index 015d9abeb6b..1619163a136 100644 --- a/usr.bin/openssl/Makefile +++ b/usr.bin/openssl/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.3 2014/09/10 16:51:42 jsing Exp $ +# $OpenBSD: Makefile,v 1.4 2014/12/03 22:16:02 bcook Exp $ PROG= openssl LDADD= -lssl -lcrypto @@ -17,11 +17,12 @@ CFLAGS+= -Wunused CFLAGS+= -DLIBRESSL_INTERNAL -SRCS= apps.c asn1pars.c ca.c ciphers.c cms.c crl.c crl2p7.c dgst.c dh.c \ - dhparam.c dsa.c dsaparam.c ec.c ecparam.c enc.c engine.c errstr.c \ - gendh.c gendsa.c genpkey.c genrsa.c nseq.c ocsp.c openssl.c passwd.c \ - pkcs12.c pkcs7.c pkcs8.c pkey.c pkeyparam.c pkeyutl.c prime.c rand.c \ - req.c rsa.c rsautl.c s_cb.c s_client.c s_server.c s_socket.c s_time.c \ - sess_id.c smime.c speed.c spkac.c ts.c verify.c version.c x509.c +SRCS= apps.c apps_posix.c asn1pars.c ca.c ciphers.c cms.c crl.c crl2p7.c \ + dgst.c dh.c dhparam.c dsa.c dsaparam.c ec.c ecparam.c enc.c engine.c \ + errstr.c gendh.c gendsa.c genpkey.c genrsa.c nseq.c ocsp.c openssl.c \ + passwd.c pkcs12.c pkcs7.c pkcs8.c pkey.c pkeyparam.c pkeyutl.c prime.c \ + rand.c req.c rsa.c rsautl.c s_cb.c s_client.c s_server.c s_socket.c \ + s_time.c sess_id.c smime.c speed.c spkac.c ts.c verify.c version.c \ + x509.c .include <bsd.prog.mk> diff --git a/usr.bin/openssl/apps.c b/usr.bin/openssl/apps.c index 78555528b66..a042f074f90 100644 --- a/usr.bin/openssl/apps.c +++ b/usr.bin/openssl/apps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.c,v 1.12 2014/11/07 14:16:48 jsing Exp $ */ +/* $OpenBSD: apps.c,v 1.13 2014/12/03 22:16:02 bcook Exp $ */ /* * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> * @@ -2205,27 +2205,6 @@ next_protos_parse(unsigned short *outlen, const char *in) #endif /* !OPENSSL_NO_NEXTPROTONEG */ -double -app_tminterval(int stop, int usertime) -{ - double ret = 0; - struct tms rus; - clock_t now = times(&rus); - static clock_t tmstart; - - if (usertime) - now = rus.tms_utime; - - if (stop == TM_START) - tmstart = now; - else { - long int tck = sysconf(_SC_CLK_TCK); - ret = (now - tmstart) / (double) tck; - } - - return (ret); -} - int app_isdir(const char *name) { @@ -2341,7 +2320,7 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) if (opt->func(opt, NULL) != 0) return (1); break; - + case OPTION_FLAG: *opt->opt.flag = 1; break; diff --git a/usr.bin/openssl/apps_posix.c b/usr.bin/openssl/apps_posix.c new file mode 100644 index 00000000000..c49a23a653c --- /dev/null +++ b/usr.bin/openssl/apps_posix.c @@ -0,0 +1,144 @@ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +/* ==================================================================== + * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* + * Functions that need to be overridden by non-POSIX operating systems. + */ + +#include <sys/times.h> + +#include <unistd.h> + +#include "apps.h" + +double +app_tminterval(int stop, int usertime) +{ + double ret = 0; + struct tms rus; + clock_t now = times(&rus); + static clock_t tmstart; + + if (usertime) + now = rus.tms_utime; + + if (stop == TM_START) + tmstart = now; + else { + long int tck = sysconf(_SC_CLK_TCK); + ret = (now - tmstart) / (double) tck; + } + + return (ret); +} diff --git a/usr.bin/openssl/s_socket.c b/usr.bin/openssl/s_socket.c index 2ce31eb5ef2..7c416d69bec 100644 --- a/usr.bin/openssl/s_socket.c +++ b/usr.bin/openssl/s_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_socket.c,v 1.2 2014/11/06 13:46:09 jsing Exp $ */ +/* $OpenBSD: s_socket.c,v 1.3 2014/12/03 22:16:02 bcook Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -85,6 +85,11 @@ init_client(int *sock, char *host, char *port, int type, int af) struct addrinfo hints, *ai_top, *ai; int i, s; + if (BIO_sock_init() != 1) { + BIO_printf(bio_err, "BIO_sock_init failed\n"); + return (0); + } + memset(&hints, '\0', sizeof(hints)); hints.ai_family = af; hints.ai_socktype = type; @@ -176,6 +181,11 @@ init_server_long(int *sock, int port, char *ip, int type) struct sockaddr_in server; int s = -1; + if (BIO_sock_init() != 1) { + BIO_printf(bio_err, "BIO_sock_init failed\n"); + return (0); + } + memset((char *) &server, 0, sizeof(server)); server.sin_family = AF_INET; server.sin_port = htons((unsigned short) port); |