summaryrefslogtreecommitdiff
path: root/Cryptlib/OpenSSL/crypto/bio
diff options
context:
space:
mode:
authorMathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>2017-09-13 12:09:40 -0700
committerMathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>2017-09-13 12:09:40 -0700
commitb6f94dbeacfc6f0a507413096189304c58dbe66c (patch)
treebce8c7db22209078618294c51d95a0c033aec7d9 /Cryptlib/OpenSSL/crypto/bio
parent25f7fd1fb389a5f6356f353d16c5ead80dac6bbc (diff)
downloadefi-boot-shim-upstream/13_git1505328970.9c1c35c5.tar.gz
efi-boot-shim-upstream/13_git1505328970.9c1c35c5.zip
New upstream version 13~git1505328970.9c1c35c5upstream/13_git1505328970.9c1c35c5
Diffstat (limited to 'Cryptlib/OpenSSL/crypto/bio')
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/b_addr.c897
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/b_dump.c78
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/b_print.c297
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/b_sock.c921
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/b_sock2.c270
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bf_buff.c102
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bf_lbuf.c319
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bf_nbio.c87
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bf_null.c69
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bio_cb.c78
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bio_err.c144
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bio_lcl.h154
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bio_lib.c246
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bio_meth.c145
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bss_acpt.c490
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bss_bio.c126
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bss_conn.c399
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bss_dgram.c417
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bss_fd.c79
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bss_file.c251
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bss_log.c91
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bss_mem.c224
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bss_null.c69
-rw-r--r--Cryptlib/OpenSSL/crypto/bio/bss_sock.c90
24 files changed, 2743 insertions, 3300 deletions
diff --git a/Cryptlib/OpenSSL/crypto/bio/b_addr.c b/Cryptlib/OpenSSL/crypto/bio/b_addr.c
deleted file mode 100644
index 0f1900db..00000000
--- a/Cryptlib/OpenSSL/crypto/bio/b_addr.c
+++ /dev/null
@@ -1,897 +0,0 @@
-/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
- *
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
- */
-
-#include <string.h>
-
-#include "bio_lcl.h"
-#include <openssl/crypto.h>
-
-#ifndef OPENSSL_NO_SOCK
-#include <openssl/err.h>
-#include <openssl/buffer.h>
-#include <internal/thread_once.h>
-#include <ctype.h>
-
-#ifdef _HPUX_SOURCE
-static const char *ossl_hstrerror(int herr)
-{
- switch (herr) {
- case -1:
- return strerror(errno);
- case 0:
- return "No error";
- case HOST_NOT_FOUND:
- return "Host not found";
- case NO_DATA: /* NO_ADDRESS is a synonym */
- return "No data";
- case NO_RECOVERY:
- return "Non recoverable error";
- case TRY_AGAIN:
- return "Try again";
- default:
- break;
- }
- return "unknown error";
-}
-# define hstrerror(e) ossl_hstrerror(e)
-#endif
-
-CRYPTO_RWLOCK *bio_lookup_lock;
-static CRYPTO_ONCE bio_lookup_init = CRYPTO_ONCE_STATIC_INIT;
-
-/*
- * Throughout this file and bio_lcl.h, the existence of the macro
- * AI_PASSIVE is used to detect the availability of struct addrinfo,
- * getnameinfo() and getaddrinfo(). If that macro doesn't exist,
- * we use our own implementation instead, using gethostbyname,
- * getservbyname and a few other.
- */
-
-/**********************************************************************
- *
- * Address structure
- *
- */
-
-BIO_ADDR *BIO_ADDR_new(void)
-{
- BIO_ADDR *ret = OPENSSL_zalloc(sizeof(*ret));
-
- if (ret == NULL) {
- BIOerr(BIO_F_BIO_ADDR_NEW, ERR_R_MALLOC_FAILURE);
- return NULL;
- }
-
- ret->sa.sa_family = AF_UNSPEC;
- return ret;
-}
-
-void BIO_ADDR_free(BIO_ADDR *ap)
-{
- OPENSSL_free(ap);
-}
-
-void BIO_ADDR_clear(BIO_ADDR *ap)
-{
- memset(ap, 0, sizeof(*ap));
- ap->sa.sa_family = AF_UNSPEC;
-}
-
-/*
- * BIO_ADDR_make - non-public routine to fill a BIO_ADDR with the contents
- * of a struct sockaddr.
- */
-int BIO_ADDR_make(BIO_ADDR *ap, const struct sockaddr *sa)
-{
- if (sa->sa_family == AF_INET) {
- ap->s_in = *(const struct sockaddr_in *)sa;
- return 1;
- }
-#ifdef AF_INET6
- if (sa->sa_family == AF_INET6) {
- ap->s_in6 = *(const struct sockaddr_in6 *)sa;
- return 1;
- }
-#endif
-#ifdef AF_UNIX
- if (ap->sa.sa_family == AF_UNIX) {
- ap->s_un = *(const struct sockaddr_un *)sa;
- return 1;
- }
-#endif
-
- return 0;
-}
-
-int BIO_ADDR_rawmake(BIO_ADDR *ap, int family,
- const void *where, size_t wherelen,
- unsigned short port)
-{
-#ifdef AF_UNIX
- if (family == AF_UNIX) {
- if (wherelen + 1 > sizeof(ap->s_un.sun_path))
- return 0;
- memset(&ap->s_un, 0, sizeof(ap->s_un));
- ap->s_un.sun_family = family;
- strncpy(ap->s_un.sun_path, where, sizeof(ap->s_un.sun_path) - 1);
- return 1;
- }
-#endif
- if (family == AF_INET) {
- if (wherelen != sizeof(struct in_addr))
- return 0;
- memset(&ap->s_in, 0, sizeof(ap->s_in));
- ap->s_in.sin_family = family;
- ap->s_in.sin_port = port;
- ap->s_in.sin_addr = *(struct in_addr *)where;
- return 1;
- }
-#ifdef AF_INET6
- if (family == AF_INET6) {
- if (wherelen != sizeof(struct in6_addr))
- return 0;
- memset(&ap->s_in6, 0, sizeof(ap->s_in6));
- ap->s_in6.sin6_family = family;
- ap->s_in6.sin6_port = port;
- ap->s_in6.sin6_addr = *(struct in6_addr *)where;
- return 1;
- }
-#endif
-
- return 0;
-}
-
-int BIO_ADDR_family(const BIO_ADDR *ap)
-{
- return ap->sa.sa_family;
-}
-
-int BIO_ADDR_rawaddress(const BIO_ADDR *ap, void *p, size_t *l)
-{
- size_t len = 0;
- const void *addrptr = NULL;
-
- if (ap->sa.sa_family == AF_INET) {
- len = sizeof(ap->s_in.sin_addr);
- addrptr = &ap->s_in.sin_addr;
- }
-#ifdef AF_INET6
- else if (ap->sa.sa_family == AF_INET6) {
- len = sizeof(ap->s_in6.sin6_addr);
- addrptr = &ap->s_in6.sin6_addr;
- }
-#endif
-#ifdef AF_UNIX
- else if (ap->sa.sa_family == AF_UNIX) {
- len = strlen(ap->s_un.sun_path);
- addrptr = &ap->s_un.sun_path;
- }
-#endif
-
- if (addrptr == NULL)
- return 0;
-
- if (p != NULL) {
- memcpy(p, addrptr, len);
- }
- if (l != NULL)
- *l = len;
-
- return 1;
-}
-
-unsigned short BIO_ADDR_rawport(const BIO_ADDR *ap)
-{
- if (ap->sa.sa_family == AF_INET)
- return ap->s_in.sin_port;
-#ifdef AF_INET6
- if (ap->sa.sa_family == AF_INET6)
- return ap->s_in6.sin6_port;
-#endif
- return 0;
-}
-
-/*-
- * addr_strings - helper function to get host and service names
- * @ap: the BIO_ADDR that has the input info
- * @numeric: 0 if actual names should be returned, 1 if the numeric
- * representation should be returned.
- * @hostname: a pointer to a pointer to a memory area to store the
- * host name or numeric representation. Unused if NULL.
- * @service: a pointer to a pointer to a memory area to store the
- * service name or numeric representation. Unused if NULL.
- *
- * The return value is 0 on failure, with the error code in the error
- * stack, and 1 on success.
- */
-static int addr_strings(const BIO_ADDR *ap, int numeric,
- char **hostname, char **service)
-{
- if (BIO_sock_init() != 1)
- return 0;
-
- if (1) {
-#ifdef AI_PASSIVE
- int ret = 0;
- char host[NI_MAXHOST] = "", serv[NI_MAXSERV] = "";
- int flags = 0;
-
- if (numeric)
- flags |= NI_NUMERICHOST | NI_NUMERICSERV;
-
- if ((ret = getnameinfo(BIO_ADDR_sockaddr(ap),
- BIO_ADDR_sockaddr_size(ap),
- host, sizeof(host), serv, sizeof(serv),
- flags)) != 0) {
-# ifdef EAI_SYSTEM
- if (ret == EAI_SYSTEM) {
- SYSerr(SYS_F_GETNAMEINFO, get_last_socket_error());
- BIOerr(BIO_F_ADDR_STRINGS, ERR_R_SYS_LIB);
- } else
-# endif
- {
- BIOerr(BIO_F_ADDR_STRINGS, ERR_R_SYS_LIB);
- ERR_add_error_data(1, gai_strerror(ret));
- }
- return 0;
- }
-
- /* VMS getnameinfo() has a bug, it doesn't fill in serv, which
- * leaves it with whatever garbage that happens to be there.
- * However, we initialise serv with the empty string (serv[0]
- * is therefore NUL), so it gets real easy to detect when things
- * didn't go the way one might expect.
- */
- if (serv[0] == '\0') {
- BIO_snprintf(serv, sizeof(serv), "%d",
- ntohs(BIO_ADDR_rawport(ap)));
- }
-
- if (hostname != NULL)
- *hostname = OPENSSL_strdup(host);
- if (service != NULL)
- *service = OPENSSL_strdup(serv);
- } else {
-#endif
- if (hostname != NULL)
- *hostname = OPENSSL_strdup(inet_ntoa(ap->s_in.sin_addr));
- if (service != NULL) {
- char serv[6]; /* port is 16 bits => max 5 decimal digits */
- BIO_snprintf(serv, sizeof(serv), "%d", ntohs(ap->s_in.sin_port));
- *service = OPENSSL_strdup(serv);
- }
- }
-
- if ((hostname != NULL && *hostname == NULL)
- || (service != NULL && *service == NULL)) {
- if (hostname != NULL) {
- OPENSSL_free(*hostname);
- *hostname = NULL;
- }
- if (service != NULL) {
- OPENSSL_free(*service);
- *service = NULL;
- }
- BIOerr(BIO_F_ADDR_STRINGS, ERR_R_MALLOC_FAILURE);
- return 0;
- }
-
- return 1;
-}
-
-char *BIO_ADDR_hostname_string(const BIO_ADDR *ap, int numeric)
-{
- char *hostname = NULL;
-
- if (addr_strings(ap, numeric, &hostname, NULL))
- return hostname;
-
- return NULL;
-}
-
-char *BIO_ADDR_service_string(const BIO_ADDR *ap, int numeric)
-{
- char *service = NULL;
-
- if (addr_strings(ap, numeric, NULL, &service))
- return service;
-
- return NULL;
-}
-
-char *BIO_ADDR_path_string(const BIO_ADDR *ap)
-{
-#ifdef AF_UNIX
- if (ap->sa.sa_family == AF_UNIX)
- return OPENSSL_strdup(ap->s_un.sun_path);
-#endif
- return NULL;
-}
-
-/*
- * BIO_ADDR_sockaddr - non-public routine to return the struct sockaddr
- * for a given BIO_ADDR. In reality, this is simply a type safe cast.
- * The returned struct sockaddr is const, so it can't be tampered with.
- */
-const struct sockaddr *BIO_ADDR_sockaddr(const BIO_ADDR *ap)
-{
- return &(ap->sa);
-}
-
-/*
- * BIO_ADDR_sockaddr_noconst - non-public function that does the same
- * as BIO_ADDR_sockaddr, but returns a non-const. USE WITH CARE, as
- * it allows you to tamper with the data (and thereby the contents
- * of the input BIO_ADDR).
- */
-struct sockaddr *BIO_ADDR_sockaddr_noconst(BIO_ADDR *ap)
-{
- return &(ap->sa);
-}
-
-/*
- * BIO_ADDR_sockaddr_size - non-public function that returns the size
- * of the struct sockaddr the BIO_ADDR is using. If the protocol family
- * isn't set or is something other than AF_INET, AF_INET6 or AF_UNIX,
- * the size of the BIO_ADDR type is returned.
- */
-socklen_t BIO_ADDR_sockaddr_size(const BIO_ADDR *ap)
-{
- if (ap->sa.sa_family == AF_INET)
- return sizeof(ap->s_in);
-#ifdef AF_INET6
- if (ap->sa.sa_family == AF_INET6)
- return sizeof(ap->s_in6);
-#endif
-#ifdef AF_UNIX
- if (ap->sa.sa_family == AF_UNIX)
- return sizeof(ap->s_un);
-#endif
- return sizeof(*ap);
-}
-
-/**********************************************************************
- *
- * Address info database
- *
- */
-
-const BIO_ADDRINFO *BIO_ADDRINFO_next(const BIO_ADDRINFO *bai)
-{
- if (bai != NULL)
- return bai->bai_next;
- return NULL;
-}
-
-int BIO_ADDRINFO_family(const BIO_ADDRINFO *bai)
-{
- if (bai != NULL)
- return bai->bai_family;
- return 0;
-}
-
-int BIO_ADDRINFO_socktype(const BIO_ADDRINFO *bai)
-{
- if (bai != NULL)
- return bai->bai_socktype;
- return 0;
-}
-
-int BIO_ADDRINFO_protocol(const BIO_ADDRINFO *bai)
-{
- if (bai != NULL) {
- if (bai->bai_protocol != 0)
- return bai->bai_protocol;
-
-#ifdef AF_UNIX
- if (bai->bai_family == AF_UNIX)
- return 0;
-#endif
-
- switch (bai->bai_socktype) {
- case SOCK_STREAM:
- return IPPROTO_TCP;
- case SOCK_DGRAM:
- return IPPROTO_UDP;
- default:
- break;
- }
- }
- return 0;
-}
-
-/*
- * BIO_ADDRINFO_sockaddr_size - non-public function that returns the size
- * of the struct sockaddr inside the BIO_ADDRINFO.
- */
-socklen_t BIO_ADDRINFO_sockaddr_size(const BIO_ADDRINFO *bai)
-{
- if (bai != NULL)
- return bai->bai_addrlen;
- return 0;
-}
-
-/*
- * BIO_ADDRINFO_sockaddr - non-public function that returns bai_addr
- * as the struct sockaddr it is.
- */
-const struct sockaddr *BIO_ADDRINFO_sockaddr(const BIO_ADDRINFO *bai)
-{
- if (bai != NULL)
- return bai->bai_addr;
- return NULL;
-}
-
-const BIO_ADDR *BIO_ADDRINFO_address(const BIO_ADDRINFO *bai)
-{
- if (bai != NULL)
- return (BIO_ADDR *)bai->bai_addr;
- return NULL;
-}
-
-void BIO_ADDRINFO_free(BIO_ADDRINFO *bai)
-{
- if (bai == NULL)
- return;
-
-#ifdef AI_PASSIVE
-# ifdef AF_UNIX
-# define _cond bai->bai_family != AF_UNIX
-# else
-# define _cond 1
-# endif
- if (_cond) {
- freeaddrinfo(bai);
- return;
- }
-#endif
-
- /* Free manually when we know that addrinfo_wrap() was used.
- * See further comment above addrinfo_wrap()
- */
- while (bai != NULL) {
- BIO_ADDRINFO *next = bai->bai_next;
- OPENSSL_free(bai->bai_addr);
- OPENSSL_free(bai);
- bai = next;
- }
-}
-
-/**********************************************************************
- *
- * Service functions
- *
- */
-
-/*-
- * The specs in hostserv can take these forms:
- *
- * host:service => *host = "host", *service = "service"
- * host:* => *host = "host", *service = NULL
- * host: => *host = "host", *service = NULL
- * :service => *host = NULL, *service = "service"
- * *:service => *host = NULL, *service = "service"
- *
- * in case no : is present in the string, the result depends on
- * hostserv_prio, as follows:
- *
- * when hostserv_prio == BIO_PARSE_PRIO_HOST
- * host => *host = "host", *service untouched
- *
- * when hostserv_prio == BIO_PARSE_PRIO_SERV
- * service => *host untouched, *service = "service"
- *
- */
-int BIO_parse_hostserv(const char *hostserv, char **host, char **service,
- enum BIO_hostserv_priorities hostserv_prio)
-{
- const char *h = NULL; size_t hl = 0;
- const char *p = NULL; size_t pl = 0;
-
- if (*hostserv == '[') {
- if ((p = strchr(hostserv, ']')) == NULL)
- goto spec_err;
- h = hostserv + 1;
- hl = p - h;
- p++;
- if (*p == '\0')
- p = NULL;
- else if (*p != ':')
- goto spec_err;
- else {
- p++;
- pl = strlen(p);
- }
- } else {
- const char *p2 = strrchr(hostserv, ':');
- p = strchr(hostserv, ':');
-
- /*-
- * Check for more than one colon. There are three possible
- * interpretations:
- * 1. IPv6 address with port number, last colon being separator.
- * 2. IPv6 address only.
- * 3. IPv6 address only if hostserv_prio == BIO_PARSE_PRIO_HOST,
- * IPv6 address and port number if hostserv_prio == BIO_PARSE_PRIO_SERV
- * Because of this ambiguity, we currently choose to make it an
- * error.
- */
- if (p != p2)
- goto amb_err;
-
- if (p != NULL) {
- h = hostserv;
- hl = p - h;
- p++;
- pl = strlen(p);
- } else if (hostserv_prio == BIO_PARSE_PRIO_HOST) {
- h = hostserv;
- hl = strlen(h);
- } else {
- p = hostserv;
- pl = strlen(p);
- }
- }
-
- if (p != NULL && strchr(p, ':'))
- goto spec_err;
-
- if (h != NULL && host != NULL) {
- if (hl == 0
- || (hl == 1 && h[0] == '*')) {
- *host = NULL;
- } else {
- *host = OPENSSL_strndup(h, hl);
- if (*host == NULL)
- goto memerr;
- }
- }
- if (p != NULL && service != NULL) {
- if (pl == 0
- || (pl == 1 && p[0] == '*')) {
- *service = NULL;
- } else {
- *service = OPENSSL_strndup(p, pl);
- if (*service == NULL)
- goto memerr;
- }
- }
-
- return 1;
- amb_err:
- BIOerr(BIO_F_BIO_PARSE_HOSTSERV, BIO_R_AMBIGUOUS_HOST_OR_SERVICE);
- return 0;
- spec_err:
- BIOerr(BIO_F_BIO_PARSE_HOSTSERV, BIO_R_MALFORMED_HOST_OR_SERVICE);
- return 0;
- memerr:
- BIOerr(BIO_F_BIO_PARSE_HOSTSERV, ERR_R_MALLOC_FAILURE);
- return 0;
-}
-
-/* addrinfo_wrap is used to build our own addrinfo "chain".
- * (it has only one entry, so calling it a chain may be a stretch)
- * It should ONLY be called when getaddrinfo() and friends
- * aren't available, OR when dealing with a non IP protocol
- * family, such as AF_UNIX
- *
- * the return value is 1 on success, or 0 on failure, which
- * only happens if a memory allocation error occurred.
- */
-static int addrinfo_wrap(int family, int socktype,
- const void *where, size_t wherelen,
- unsigned short port,
- BIO_ADDRINFO **bai)
-{
- OPENSSL_assert(bai != NULL);
-
- *bai = OPENSSL_zalloc(sizeof(**bai));
- if (*bai == NULL)
- return 0;
-
- (*bai)->bai_family = family;
- (*bai)->bai_socktype = socktype;
- if (socktype == SOCK_STREAM)
- (*bai)->bai_protocol = IPPROTO_TCP;
- if (socktype == SOCK_DGRAM)
- (*bai)->bai_protocol = IPPROTO_UDP;
-#ifdef AF_UNIX
- if (family == AF_UNIX)
- (*bai)->bai_protocol = 0;
-#endif
- {
- /* Magic: We know that BIO_ADDR_sockaddr_noconst is really
- just an advanced cast of BIO_ADDR* to struct sockaddr *
- by the power of union, so while it may seem that we're
- creating a memory leak here, we are not. It will be
- all right. */
- BIO_ADDR *addr = BIO_ADDR_new();
- if (addr != NULL) {
- BIO_ADDR_rawmake(addr, family, where, wherelen, port);
- (*bai)->bai_addr = BIO_ADDR_sockaddr_noconst(addr);
- }
- }
- (*bai)->bai_next = NULL;
- if ((*bai)->bai_addr == NULL) {
- BIO_ADDRINFO_free(*bai);
- *bai = NULL;
- return 0;
- }
- return 1;
-}
-
-DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init)
-{
- OPENSSL_init_crypto(0, NULL);
- bio_lookup_lock = CRYPTO_THREAD_lock_new();
- return bio_lookup_lock != NULL;
-}
-
-/*-
- * BIO_lookup - look up the node and service you want to connect to.
- * @node: the node you want to connect to.
- * @service: the service you want to connect to.
- * @lookup_type: declare intent with the result, client or server.
- * @family: the address family you want to use. Use AF_UNSPEC for any, or
- * AF_INET, AF_INET6 or AF_UNIX.
- * @socktype: The socket type you want to use. Can be SOCK_STREAM, SOCK_DGRAM
- * or 0 for all.
- * @res: Storage place for the resulting list of returned addresses
- *
- * This will do a lookup of the node and service that you want to connect to.
- * It returns a linked list of different addresses you can try to connect to.
- *
- * When no longer needed you should call BIO_ADDRINFO_free() to free the result.
- *
- * The return value is 1 on success or 0 in case of error.
- */
-int BIO_lookup(const char *host, const char *service,
- enum BIO_lookup_type lookup_type,
- int family, int socktype, BIO_ADDRINFO **res)
-{
- int ret = 0; /* Assume failure */
-
- switch(family) {
- case AF_INET:
-#ifdef AF_INET6
- case AF_INET6:
-#endif
-#ifdef AF_UNIX
- case AF_UNIX:
-#endif
-#ifdef AF_UNSPEC
- case AF_UNSPEC:
-#endif
- break;
- default:
- BIOerr(BIO_F_BIO_LOOKUP, BIO_R_UNSUPPORTED_PROTOCOL_FAMILY);
- return 0;
- }
-
-#ifdef AF_UNIX
- if (family == AF_UNIX) {
- if (addrinfo_wrap(family, socktype, host, strlen(host), 0, res))
- return 1;
- else
- BIOerr(BIO_F_BIO_LOOKUP, ERR_R_MALLOC_FAILURE);
- return 0;
- }
-#endif
-
- if (BIO_sock_init() != 1)
- return 0;
-
- if (1) {
- int gai_ret = 0;
-#ifdef AI_PASSIVE
- struct addrinfo hints;
- memset(&hints, 0, sizeof hints);
-
- hints.ai_family = family;
- hints.ai_socktype = socktype;
-
- if (lookup_type == BIO_LOOKUP_SERVER)
- hints.ai_flags |= AI_PASSIVE;
-
- /* Note that |res| SHOULD be a 'struct addrinfo **' thanks to
- * macro magic in bio_lcl.h
- */
- switch ((gai_ret = getaddrinfo(host, service, &hints, res))) {
-# ifdef EAI_SYSTEM
- case EAI_SYSTEM:
- SYSerr(SYS_F_GETADDRINFO, get_last_socket_error());
- BIOerr(BIO_F_BIO_LOOKUP, ERR_R_SYS_LIB);
- break;
-# endif
- case 0:
- ret = 1; /* Success */
- break;
- default:
- BIOerr(BIO_F_BIO_LOOKUP, ERR_R_SYS_LIB);
- ERR_add_error_data(1, gai_strerror(gai_ret));
- break;
- }
- } else {
-#endif
- const struct hostent *he;
-/*
- * Because struct hostent is defined for 32-bit pointers only with
- * VMS C, we need to make sure that '&he_fallback_address' and
- * '&he_fallback_addresses' are 32-bit pointers
- */
-#if defined(OPENSSL_SYS_VMS) && defined(__DECC)
-# pragma pointer_size save
-# pragma pointer_size 32
-#endif
- /* Windows doesn't seem to have in_addr_t */
-#ifdef OPENSSL_SYS_WINDOWS
- static uint32_t he_fallback_address;
- static const char *he_fallback_addresses[] =
- { (char *)&he_fallback_address, NULL };
-#else
- static in_addr_t he_fallback_address;
- static const char *he_fallback_addresses[] =
- { (char *)&he_fallback_address, NULL };
-#endif
- static const struct hostent he_fallback =
- { NULL, NULL, AF_INET, sizeof(he_fallback_address),
- (char **)&he_fallback_addresses };
-#if defined(OPENSSL_SYS_VMS) && defined(__DECC)
-# pragma pointer_size restore
-#endif
-
- struct servent *se;
- /* Apparently, on WIN64, s_proto and s_port have traded places... */
-#ifdef _WIN64
- struct servent se_fallback = { NULL, NULL, NULL, 0 };
-#else
- struct servent se_fallback = { NULL, NULL, 0, NULL };
-#endif
-
- if (!RUN_ONCE(&bio_lookup_init, do_bio_lookup_init)) {
- BIOerr(BIO_F_BIO_LOOKUP, ERR_R_MALLOC_FAILURE);
- ret = 0;
- goto err;
- }
-
- CRYPTO_THREAD_write_lock(bio_lookup_lock);
- he_fallback_address = INADDR_ANY;
- if (host == NULL) {
- he = &he_fallback;
- switch(lookup_type) {
- case BIO_LOOKUP_CLIENT:
- he_fallback_address = INADDR_LOOPBACK;
- break;
- case BIO_LOOKUP_SERVER:
- he_fallback_address = INADDR_ANY;
- break;
- default:
- OPENSSL_assert(("We forgot to handle a lookup type!" == 0));
- break;
- }
- } else {
- he = gethostbyname(host);
-
- if (he == NULL) {
-#ifndef OPENSSL_SYS_WINDOWS
- BIOerr(BIO_F_BIO_LOOKUP, ERR_R_SYS_LIB);
- ERR_add_error_data(1, hstrerror(h_errno));
-#else
- SYSerr(SYS_F_GETHOSTBYNAME, WSAGetLastError());
-#endif
- ret = 0;
- goto err;
- }
- }
-
- if (service == NULL) {
- se_fallback.s_port = 0;
- se_fallback.s_proto = NULL;
- se = &se_fallback;
- } else {
- char *endp = NULL;
- long portnum = strtol(service, &endp, 10);
-
-/*
- * Because struct servent is defined for 32-bit pointers only with
- * VMS C, we need to make sure that 'proto' is a 32-bit pointer.
- */
-#if defined(OPENSSL_SYS_VMS) && defined(__DECC)
-# pragma pointer_size save
-# pragma pointer_size 32
-#endif
- char *proto = NULL;
-#if defined(OPENSSL_SYS_VMS) && defined(__DECC)
-# pragma pointer_size restore
-#endif
-
- switch (socktype) {
- case SOCK_STREAM:
- proto = "tcp";
- break;
- case SOCK_DGRAM:
- proto = "udp";
- break;
- }
-
- if (endp != service && *endp == '\0'
- && portnum > 0 && portnum < 65536) {
- se_fallback.s_port = htons(portnum);
- se_fallback.s_proto = proto;
- se = &se_fallback;
- } else if (endp == service) {
- se = getservbyname(service, proto);
-
- if (se == NULL) {
-#ifndef OPENSSL_SYS_WINDOWS
- BIOerr(BIO_F_BIO_LOOKUP, ERR_R_SYS_LIB);
- ERR_add_error_data(1, hstrerror(h_errno));
-#else
- SYSerr(SYS_F_GETSERVBYNAME, WSAGetLastError());
-#endif
- goto err;
- }
- } else {
- BIOerr(BIO_F_BIO_LOOKUP, BIO_R_MALFORMED_HOST_OR_SERVICE);
- goto err;
- }
- }
-
- *res = NULL;
-
- {
-/*
- * Because hostent::h_addr_list is an array of 32-bit pointers with VMS C,
- * we must make sure our iterator designates the same element type, hence
- * the pointer size dance.
- */
-#if defined(OPENSSL_SYS_VMS) && defined(__DECC)
-# pragma pointer_size save
-# pragma pointer_size 32
-#endif
- char **addrlistp;
-#if defined(OPENSSL_SYS_VMS) && defined(__DECC)
-# pragma pointer_size restore
-#endif
- size_t addresses;
- BIO_ADDRINFO *tmp_bai = NULL;
-
- /* The easiest way to create a linked list from an
- array is to start from the back */
- for(addrlistp = he->h_addr_list; *addrlistp != NULL;
- addrlistp++)
- ;
-
- for(addresses = addrlistp - he->h_addr_list;
- addrlistp--, addresses-- > 0; ) {
- if (!addrinfo_wrap(he->h_addrtype, socktype,
- *addrlistp, he->h_length,
- se->s_port, &tmp_bai))
- goto addrinfo_malloc_err;
- tmp_bai->bai_next = *res;
- *res = tmp_bai;
- continue;
- addrinfo_malloc_err:
- BIO_ADDRINFO_free(*res);
- *res = NULL;
- BIOerr(BIO_F_BIO_LOOKUP, ERR_R_MALLOC_FAILURE);
- ret = 0;
- goto err;
- }
-
- ret = 1;
- }
- err:
- CRYPTO_THREAD_unlock(bio_lookup_lock);
- }
-
- return ret;
-}
-
-#endif /* OPENSSL_NO_SOCK */
diff --git a/Cryptlib/OpenSSL/crypto/bio/b_dump.c b/Cryptlib/OpenSSL/crypto/bio/b_dump.c
index a27954fa..ccf0e287 100644
--- a/Cryptlib/OpenSSL/crypto/bio/b_dump.c
+++ b/Cryptlib/OpenSSL/crypto/bio/b_dump.c
@@ -1,10 +1,59 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/b_dump.c */
+/* 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.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
/*
@@ -12,6 +61,7 @@
*/
#include <stdio.h>
+#include "cryptlib.h"
#include "bio_lcl.h"
#define TRUNCATE
@@ -54,20 +104,20 @@ int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u),
if ((rows * dump_width) < len)
rows++;
for (i = 0; i < rows; i++) {
- OPENSSL_strlcpy(buf, str, sizeof buf);
+ BUF_strlcpy(buf, str, sizeof buf);
BIO_snprintf(tmp, sizeof tmp, "%04x - ", i * dump_width);
- OPENSSL_strlcat(buf, tmp, sizeof buf);
+ BUF_strlcat(buf, tmp, sizeof buf);
for (j = 0; j < dump_width; j++) {
if (((i * dump_width) + j) >= len) {
- OPENSSL_strlcat(buf, " ", sizeof buf);
+ BUF_strlcat(buf, " ", sizeof buf);
} else {
ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff;
BIO_snprintf(tmp, sizeof tmp, "%02x%c", ch,
j == 7 ? '-' : ' ');
- OPENSSL_strlcat(buf, tmp, sizeof buf);
+ BUF_strlcat(buf, tmp, sizeof buf);
}
}
- OPENSSL_strlcat(buf, " ", sizeof buf);
+ BUF_strlcat(buf, " ", sizeof buf);
for (j = 0; j < dump_width; j++) {
if (((i * dump_width) + j) >= len)
break;
@@ -81,9 +131,9 @@ int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u),
? os_toebcdic[ch]
: '.');
#endif
- OPENSSL_strlcat(buf, tmp, sizeof buf);
+ BUF_strlcat(buf, tmp, sizeof buf);
}
- OPENSSL_strlcat(buf, "\n", sizeof buf);
+ BUF_strlcat(buf, "\n", sizeof buf);
/*
* if this is the last call then update the ddt_dump thing so that we
* will move the selection point in the debug window
@@ -100,7 +150,7 @@ int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u),
return (ret);
}
-#ifndef OPENSSL_NO_STDIO
+#ifndef OPENSSL_NO_FP_API
static int write_fp(const void *data, size_t len, void *fp)
{
return UP_fwrite(data, len, 1, fp);
diff --git a/Cryptlib/OpenSSL/crypto/bio/b_print.c b/Cryptlib/OpenSSL/crypto/bio/b_print.c
index f33caa2c..fea73864 100644
--- a/Cryptlib/OpenSSL/crypto/bio/b_print.c
+++ b/Cryptlib/OpenSSL/crypto/bio/b_print.c
@@ -1,17 +1,78 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/b_print.c */
+/* 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)"
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
+ */
+
+/* disable assert() unless BIO_DEBUG has been defined */
+#ifndef BIO_DEBUG
+# ifndef NDEBUG
+# define NDEBUG
+# endif
+#endif
+
+/*
+ * Stolen from tjh's ssl/ssl_trc.c stuff.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
-#include "internal/numbers.h"
-#include "internal/cryptlib.h"
+#include <assert.h>
+#include <limits.h>
+#include "cryptlib.h"
#ifndef NO_SYS_TYPES_H
# include <sys/types.h>
#endif
@@ -24,6 +85,8 @@
# endif
#endif
+/***************************************************************************/
+
/*
* Copyright Patrick Powell 1995
* This code is based on code written by Patrick Powell <papowell@astart.com>
@@ -31,6 +94,21 @@
* on all source code distributions.
*/
+/*-
+ * This code contains numerious changes and enhancements which were
+ * made by lots of contributors over the last years to Patrick Powell's
+ * original code:
+ *
+ * o Patrick Powell <papowell@astart.com> (1995)
+ * o Brandon Long <blong@fiction.net> (1996, for Mutt)
+ * o Thomas Roessler <roessler@guug.de> (1998, for Mutt)
+ * o Michael Elkins <me@cs.hmc.edu> (1998, for Mutt)
+ * o Andrew Tridgell <tridge@samba.org> (1998, for Samba)
+ * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)
+ * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth)
+ * o ... (for OpenSSL)
+ */
+
#ifdef HAVE_LONG_DOUBLE
# define LDOUBLE long double
#else
@@ -53,7 +131,7 @@ static int fmtint(char **, char **, size_t *, size_t *,
LLONG, int, int, int, int);
#ifndef OPENSSL_SYS_UEFI
static int fmtfp(char **, char **, size_t *, size_t *,
- LDOUBLE, int, int, int, int);
+ LDOUBLE, int, int, int);
#endif
static int doapr_outch(char **, char **, size_t *, size_t *, int);
static int _dopr(char **sbuffer, char **buffer,
@@ -71,19 +149,12 @@ static int _dopr(char **sbuffer, char **buffer,
#define DP_S_DONE 7
/* format flags - Bits */
-/* left-aligned padding */
#define DP_F_MINUS (1 << 0)
-/* print an explicit '+' for a value with positive sign */
#define DP_F_PLUS (1 << 1)
-/* print an explicit ' ' for a value with positive sign */
#define DP_F_SPACE (1 << 2)
-/* print 0/0x prefix for octal/hex and decimal point for floating point */
#define DP_F_NUM (1 << 3)
-/* print leading zeroes */
#define DP_F_ZERO (1 << 4)
-/* print HEX in UPPPERcase */
#define DP_F_UP (1 << 5)
-/* treat value as unsigned */
#define DP_F_UNSIGNED (1 << 6)
/* conversion flags */
@@ -92,11 +163,6 @@ static int _dopr(char **sbuffer, char **buffer,
#define DP_C_LDOUBLE 3
#define DP_C_LLONG 4
-/* Floating point formats */
-#define F_FORMAT 0
-#define E_FORMAT 1
-#define G_FORMAT 2
-
/* some handy macros */
#define char_to_int(p) (p - '0')
#define OSSL_MAX(p,q) ((p >= q) ? p : q)
@@ -280,7 +346,7 @@ _dopr(char **sbuffer,
else
fvalue = va_arg(args, double);
if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,
- flags, F_FORMAT))
+ flags))
return 0;
break;
case 'E':
@@ -290,9 +356,6 @@ _dopr(char **sbuffer,
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
- if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,
- flags, E_FORMAT))
- return 0;
break;
case 'G':
flags |= DP_F_UP;
@@ -301,9 +364,6 @@ _dopr(char **sbuffer,
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
- if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,
- flags, G_FORMAT))
- return 0;
break;
#endif
case 'c':
@@ -324,7 +384,7 @@ _dopr(char **sbuffer,
return 0;
break;
case 'p':
- value = (size_t)va_arg(args, void *);
+ value = (long)va_arg(args, void *);
if (!fmtint(sbuffer, buffer, &currlen, maxlen,
value, 16, min, max, flags | DP_F_NUM))
return 0;
@@ -399,37 +459,28 @@ fmtstr(char **sbuffer,
if (value == 0)
value = "<NULL>";
- strln = OPENSSL_strnlen(value, max < 0 ? SIZE_MAX : (size_t)max);
+ strln = strlen(value);
+ if (strln > INT_MAX)
+ strln = INT_MAX;
padlen = min - strln;
if (min < 0 || padlen < 0)
padlen = 0;
- if (max >= 0) {
- /*
- * Calculate the maximum output including padding.
- * Make sure max doesn't overflow into negativity
- */
- if (max < INT_MAX - padlen)
- max += padlen;
- else
- max = INT_MAX;
- }
if (flags & DP_F_MINUS)
padlen = -padlen;
- while ((padlen > 0) && (max < 0 || cnt < max)) {
+ while ((padlen > 0) && (cnt < max)) {
if(!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
return 0;
--padlen;
++cnt;
}
- while (strln > 0 && (max < 0 || cnt < max)) {
+ while (*value && (cnt < max)) {
if(!doapr_outch(sbuffer, buffer, currlen, maxlen, *value++))
return 0;
- --strln;
++cnt;
}
- while ((padlen < 0) && (max < 0 || cnt < max)) {
+ while ((padlen < 0) && (cnt < max)) {
if(!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
return 0;
++padlen;
@@ -459,7 +510,7 @@ fmtint(char **sbuffer,
if (!(flags & DP_F_UNSIGNED)) {
if (value < 0) {
signvalue = '-';
- uvalue = 0 - (unsigned LLONG)value;
+ uvalue = -value;
} else if (flags & DP_F_PLUS)
signvalue = '+';
else if (flags & DP_F_SPACE)
@@ -571,28 +622,23 @@ static int
fmtfp(char **sbuffer,
char **buffer,
size_t *currlen,
- size_t *maxlen, LDOUBLE fvalue, int min, int max, int flags, int style)
+ size_t *maxlen, LDOUBLE fvalue, int min, int max, int flags)
{
int signvalue = 0;
LDOUBLE ufvalue;
- LDOUBLE tmpvalue;
char iconvert[20];
char fconvert[20];
- char econvert[20];
int iplace = 0;
int fplace = 0;
- int eplace = 0;
int padlen = 0;
int zpadlen = 0;
- long exp = 0;
- unsigned long intpart;
- unsigned long fracpart;
- unsigned long max10;
- int realstyle;
+ long intpart;
+ long fracpart;
+ long max10;
if (max < 0)
max = 6;
-
+ ufvalue = abs_val(fvalue);
if (fvalue < 0)
signvalue = '-';
else if (flags & DP_F_PLUS)
@@ -600,73 +646,7 @@ fmtfp(char **sbuffer,
else if (flags & DP_F_SPACE)
signvalue = ' ';
- /*
- * G_FORMAT sometimes prints like E_FORMAT and sometimes like F_FORMAT
- * depending on the number to be printed. Work out which one it is and use
- * that from here on.
- */
- if (style == G_FORMAT) {
- if (fvalue == 0.0) {
- realstyle = F_FORMAT;
- } else if (fvalue < 0.0001) {
- realstyle = E_FORMAT;
- } else if ((max == 0 && fvalue >= 10)
- || (max > 0 && fvalue >= pow_10(max))) {
- realstyle = E_FORMAT;
- } else {
- realstyle = F_FORMAT;
- }
- } else {
- realstyle = style;
- }
-
- if (style != F_FORMAT) {
- tmpvalue = fvalue;
- /* Calculate the exponent */
- if (fvalue != 0.0) {
- while (tmpvalue < 1) {
- tmpvalue *= 10;
- exp--;
- }
- while (tmpvalue > 10) {
- tmpvalue /= 10;
- exp++;
- }
- }
- if (style == G_FORMAT) {
- /*
- * In G_FORMAT the "precision" represents significant digits. We
- * always have at least 1 significant digit.
- */
- if (max == 0)
- max = 1;
- /* Now convert significant digits to decimal places */
- if (realstyle == F_FORMAT) {
- max -= (exp + 1);
- if (max < 0) {
- /*
- * Should not happen. If we're in F_FORMAT then exp < max?
- */
- return 0;
- }
- } else {
- /*
- * In E_FORMAT there is always one significant digit in front
- * of the decimal point, so:
- * significant digits == 1 + decimal places
- */
- max--;
- }
- }
- if (realstyle == E_FORMAT)
- fvalue = tmpvalue;
- }
- ufvalue = abs_val(fvalue);
- if (ufvalue > ULONG_MAX) {
- /* Number too big */
- return 0;
- }
- intpart = (unsigned long)ufvalue;
+ intpart = (long)ufvalue;
/*
* sorry, we only support 9 digits past the decimal because of our
@@ -697,51 +677,16 @@ fmtfp(char **sbuffer,
iconvert[iplace] = 0;
/* convert fractional part */
- while (fplace < max) {
- if (style == G_FORMAT && fplace == 0 && (fracpart % 10) == 0) {
- /* We strip trailing zeros in G_FORMAT */
- max--;
- fracpart = fracpart / 10;
- if (fplace < max)
- continue;
- break;
- }
+ do {
fconvert[fplace++] = "0123456789"[fracpart % 10];
fracpart = (fracpart / 10);
- }
-
+ } while (fplace < max);
if (fplace == sizeof fconvert)
fplace--;
fconvert[fplace] = 0;
- /* convert exponent part */
- if (realstyle == E_FORMAT) {
- int tmpexp;
- if (exp < 0)
- tmpexp = -exp;
- else
- tmpexp = exp;
-
- do {
- econvert[eplace++] = "0123456789"[tmpexp % 10];
- tmpexp = (tmpexp / 10);
- } while (tmpexp > 0 && eplace < (int)sizeof(econvert));
- /* Exponent is huge!! Too big to print */
- if (tmpexp > 0)
- return 0;
- /* Add a leading 0 for single digit exponents */
- if (eplace == 1)
- econvert[eplace++] = '0';
- }
-
- /*
- * -1 for decimal point (if we have one, i.e. max > 0),
- * another -1 if we are printing a sign
- */
- padlen = min - iplace - max - (max > 0 ? 1 : 0) - ((signvalue) ? 1 : 0);
- /* Take some off for exponent prefix "+e" and exponent */
- if (realstyle == E_FORMAT)
- padlen -= 2 + eplace;
+ /* -1 for decimal point, another -1 if we are printing a sign */
+ padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
zpadlen = max - fplace;
if (zpadlen < 0)
zpadlen = 0;
@@ -795,28 +740,6 @@ fmtfp(char **sbuffer,
return 0;
--zpadlen;
}
- if (realstyle == E_FORMAT) {
- char ech;
-
- if ((flags & DP_F_UP) == 0)
- ech = 'e';
- else
- ech = 'E';
- if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ech))
- return 0;
- if (exp < 0) {
- if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '-'))
- return 0;
- } else {
- if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '+'))
- return 0;
- }
- while (eplace > 0) {
- if (!doapr_outch(sbuffer, buffer, currlen, maxlen,
- econvert[--eplace]))
- return 0;
- }
- }
while (padlen < 0) {
if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
@@ -834,10 +757,10 @@ doapr_outch(char **sbuffer,
char **buffer, size_t *currlen, size_t *maxlen, int c)
{
/* If we haven't at least one buffer, someone has doe a big booboo */
- OPENSSL_assert(*sbuffer != NULL || buffer != NULL);
+ assert(*sbuffer != NULL || buffer != NULL);
/* |currlen| must always be <= |*maxlen| */
- OPENSSL_assert(*currlen <= *maxlen);
+ assert(*currlen <= *maxlen);
if (buffer && *currlen == *maxlen) {
if (*maxlen > INT_MAX - BUFFER_INC)
@@ -849,7 +772,7 @@ doapr_outch(char **sbuffer,
if (*buffer == NULL)
return 0;
if (*currlen > 0) {
- OPENSSL_assert(*sbuffer != NULL);
+ assert(*sbuffer != NULL);
memcpy(*buffer, *sbuffer, *currlen);
}
*sbuffer = NULL;
@@ -900,6 +823,7 @@ int BIO_vprintf(BIO *bio, const char *format, va_list args)
int ignored;
dynbuf = NULL;
+ CRYPTO_push_info("doapr()");
if (!_dopr(&hugebufp, &dynbuf, &hugebufsize, &retlen, &ignored, format,
args)) {
OPENSSL_free(dynbuf);
@@ -911,6 +835,7 @@ int BIO_vprintf(BIO *bio, const char *format, va_list args)
} else {
ret = BIO_write(bio, hugebuf, (int)retlen);
}
+ CRYPTO_pop_info();
return (ret);
}
diff --git a/Cryptlib/OpenSSL/crypto/bio/b_sock.c b/Cryptlib/OpenSSL/crypto/bio/b_sock.c
index ac2c2d16..5bad0a2b 100644
--- a/Cryptlib/OpenSSL/crypto/bio/b_sock.c
+++ b/Cryptlib/OpenSSL/crypto/bio/b_sock.c
@@ -1,21 +1,76 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/b_sock.c */
+/* 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.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
-#include "bio_lcl.h"
-#if defined(NETWARE_CLIB)
-# include <sys/ioctl.h>
+#define USE_SOCKETS
+#include "cryptlib.h"
+#include <openssl/bio.h>
+#if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_BSDSOCK)
+# include <netdb.h>
+# if defined(NETWARE_CLIB)
+# include <sys/ioctl.h>
NETDB_DEFINE_CONTEXT
+# endif
#endif
#ifndef OPENSSL_NO_SOCK
+# include <openssl/dso.h>
# define SOCKET_PROTOCOL IPPROTO_TCP
# ifdef SO_MAXCONN
# define MAX_LISTEN SO_MAXCONN
@@ -24,93 +79,294 @@ NETDB_DEFINE_CONTEXT
# else
# define MAX_LISTEN 32
# endif
-# if defined(OPENSSL_SYS_WINDOWS)
+# if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK))
static int wsa_init_done = 0;
# endif
-# if OPENSSL_API_COMPAT < 0x10100000L
+/*
+ * WSAAPI specifier is required to make indirect calls to run-time
+ * linked WinSock 2 functions used in this module, to be specific
+ * [get|free]addrinfo and getnameinfo. This is because WinSock uses
+ * uses non-C calling convention, __stdcall vs. __cdecl, on x86
+ * Windows. On non-WinSock platforms WSAAPI needs to be void.
+ */
+# ifndef WSAAPI
+# define WSAAPI
+# endif
+
+# if 0
+static unsigned long BIO_ghbn_hits = 0L;
+static unsigned long BIO_ghbn_miss = 0L;
+
+# define GHBN_NUM 4
+static struct ghbn_cache_st {
+ char name[129];
+ struct hostent *ent;
+ unsigned long order;
+} ghbn_cache[GHBN_NUM];
+# endif
+
+static int get_ip(const char *str, unsigned char *ip);
+# if 0
+static void ghbn_free(struct hostent *a);
+static struct hostent *ghbn_dup(struct hostent *a);
+# endif
int BIO_get_host_ip(const char *str, unsigned char *ip)
{
- BIO_ADDRINFO *res = NULL;
- int ret = 0;
+ int i;
+ int err = 1;
+ int locked = 0;
+ struct hostent *he;
+ i = get_ip(str, ip);
+ if (i < 0) {
+ BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_INVALID_IP_ADDRESS);
+ goto err;
+ }
+
+ /*
+ * At this point, we have something that is most probably correct in some
+ * way, so let's init the socket.
+ */
if (BIO_sock_init() != 1)
return 0; /* don't generate another error code here */
- if (BIO_lookup(str, NULL, BIO_LOOKUP_CLIENT, AF_INET, SOCK_STREAM, &res)) {
- size_t l;
-
- if (BIO_ADDRINFO_family(res) != AF_INET) {
- BIOerr(BIO_F_BIO_GET_HOST_IP,
- BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
- } else {
- BIO_ADDR_rawaddress(BIO_ADDRINFO_address(res), NULL, &l);
- /* Because only AF_INET addresses will reach this far,
- we can assert that l should be 4 */
- OPENSSL_assert(l == 4);
+ /*
+ * If the string actually contained an IP address, we need not do
+ * anything more
+ */
+ if (i > 0)
+ return (1);
+
+ /* do a gethostbyname */
+ CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
+ locked = 1;
+ he = BIO_gethostbyname(str);
+ if (he == NULL) {
+ BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_BAD_HOSTNAME_LOOKUP);
+ goto err;
+ }
- BIO_ADDR_rawaddress(BIO_ADDRINFO_address(res), ip, &l);
- ret = 1;
- }
- BIO_ADDRINFO_free(res);
- } else {
- ERR_add_error_data(2, "host=", str);
+ /* cast to short because of win16 winsock definition */
+ if ((short)he->h_addrtype != AF_INET) {
+ BIOerr(BIO_F_BIO_GET_HOST_IP,
+ BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
+ goto err;
}
+ for (i = 0; i < 4; i++)
+ ip[i] = he->h_addr_list[0][i];
+ err = 0;
- return ret;
+ err:
+ if (locked)
+ CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
+ if (err) {
+ ERR_add_error_data(2, "host=", str);
+ return 0;
+ } else
+ return 1;
}
int BIO_get_port(const char *str, unsigned short *port_ptr)
{
- BIO_ADDRINFO *res = NULL;
- int ret = 0;
+ int i;
+ struct servent *s;
if (str == NULL) {
BIOerr(BIO_F_BIO_GET_PORT, BIO_R_NO_PORT_DEFINED);
return (0);
}
-
- if (BIO_sock_init() != 1)
- return 0; /* don't generate another error code here */
-
- if (BIO_lookup(NULL, str, BIO_LOOKUP_CLIENT, AF_INET, SOCK_STREAM, &res)) {
- if (BIO_ADDRINFO_family(res) != AF_INET) {
- BIOerr(BIO_F_BIO_GET_PORT,
- BIO_R_ADDRINFO_ADDR_IS_NOT_AF_INET);
- } else {
- *port_ptr = ntohs(BIO_ADDR_rawport(BIO_ADDRINFO_address(res)));
- ret = 1;
+ i = atoi(str);
+ if (i != 0)
+ *port_ptr = (unsigned short)i;
+ else {
+ CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME);
+ /*
+ * Note: under VMS with SOCKETSHR, it seems like the first parameter
+ * is 'char *', instead of 'const char *'
+ */
+# ifndef CONST_STRICT
+ s = getservbyname((char *)str, "tcp");
+# else
+ s = getservbyname(str, "tcp");
+# endif
+ if (s != NULL)
+ *port_ptr = ntohs((unsigned short)s->s_port);
+ CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME);
+ if (s == NULL) {
+ if (strcmp(str, "http") == 0)
+ *port_ptr = 80;
+ else if (strcmp(str, "telnet") == 0)
+ *port_ptr = 23;
+ else if (strcmp(str, "socks") == 0)
+ *port_ptr = 1080;
+ else if (strcmp(str, "https") == 0)
+ *port_ptr = 443;
+ else if (strcmp(str, "ssl") == 0)
+ *port_ptr = 443;
+ else if (strcmp(str, "ftp") == 0)
+ *port_ptr = 21;
+ else if (strcmp(str, "gopher") == 0)
+ *port_ptr = 70;
+# if 0
+ else if (strcmp(str, "wais") == 0)
+ *port_ptr = 21;
+# endif
+ else {
+ SYSerr(SYS_F_GETSERVBYNAME, get_last_socket_error());
+ ERR_add_error_data(3, "service='", str, "'");
+ return (0);
+ }
}
- BIO_ADDRINFO_free(res);
- } else {
- ERR_add_error_data(2, "host=", str);
}
-
- return ret;
+ return (1);
}
-# endif
int BIO_sock_error(int sock)
{
- int j = 0, i;
- socklen_t size = sizeof(j);
+ int j, i;
+ union {
+ size_t s;
+ int i;
+ } size;
+
+# if defined(OPENSSL_SYS_BEOS_R5)
+ return 0;
+# endif
+ /* heuristic way to adapt for platforms that expect 64-bit optlen */
+ size.s = 0, size.i = sizeof(j);
/*
* Note: under Windows the third parameter is of type (char *) whereas
* under other systems it is (void *) if you don't have a cast it will
* choke the compiler: if you do have a cast then you can either go for
* (char *) or (void *).
*/
- i = getsockopt(sock, SOL_SOCKET, SO_ERROR, (void *)&j, &size);
+ i = getsockopt(sock, SOL_SOCKET, SO_ERROR, (void *)&j, (void *)&size);
if (i < 0)
- return (get_last_socket_error());
+ return (1);
else
return (j);
}
-# if OPENSSL_API_COMPAT < 0x10100000L
+# if 0
+long BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
+{
+ int i;
+ char **p;
+
+ switch (cmd) {
+ case BIO_GHBN_CTRL_HITS:
+ return (BIO_ghbn_hits);
+ /* break; */
+ case BIO_GHBN_CTRL_MISSES:
+ return (BIO_ghbn_miss);
+ /* break; */
+ case BIO_GHBN_CTRL_CACHE_SIZE:
+ return (GHBN_NUM);
+ /* break; */
+ case BIO_GHBN_CTRL_GET_ENTRY:
+ if ((iarg >= 0) && (iarg < GHBN_NUM) && (ghbn_cache[iarg].order > 0)) {
+ p = (char **)parg;
+ if (p == NULL)
+ return (0);
+ *p = ghbn_cache[iarg].name;
+ ghbn_cache[iarg].name[128] = '\0';
+ return (1);
+ }
+ return (0);
+ /* break; */
+ case BIO_GHBN_CTRL_FLUSH:
+ for (i = 0; i < GHBN_NUM; i++)
+ ghbn_cache[i].order = 0;
+ break;
+ default:
+ return (0);
+ }
+ return (1);
+}
+# endif
+
+# if 0
+static struct hostent *ghbn_dup(struct hostent *a)
+{
+ struct hostent *ret;
+ int i, j;
+
+ MemCheck_off();
+ ret = (struct hostent *)OPENSSL_malloc(sizeof(struct hostent));
+ if (ret == NULL)
+ return (NULL);
+ memset(ret, 0, sizeof(struct hostent));
+
+ for (i = 0; a->h_aliases[i] != NULL; i++) ;
+ i++;
+ ret->h_aliases = (char **)OPENSSL_malloc(i * sizeof(char *));
+ if (ret->h_aliases == NULL)
+ goto err;
+ memset(ret->h_aliases, 0, i * sizeof(char *));
+
+ for (i = 0; a->h_addr_list[i] != NULL; i++) ;
+ i++;
+ ret->h_addr_list = (char **)OPENSSL_malloc(i * sizeof(char *));
+ if (ret->h_addr_list == NULL)
+ goto err;
+ memset(ret->h_addr_list, 0, i * sizeof(char *));
+
+ j = strlen(a->h_name) + 1;
+ if ((ret->h_name = OPENSSL_malloc(j)) == NULL)
+ goto err;
+ memcpy((char *)ret->h_name, a->h_name, j);
+ for (i = 0; a->h_aliases[i] != NULL; i++) {
+ j = strlen(a->h_aliases[i]) + 1;
+ if ((ret->h_aliases[i] = OPENSSL_malloc(j)) == NULL)
+ goto err;
+ memcpy(ret->h_aliases[i], a->h_aliases[i], j);
+ }
+ ret->h_length = a->h_length;
+ ret->h_addrtype = a->h_addrtype;
+ for (i = 0; a->h_addr_list[i] != NULL; i++) {
+ if ((ret->h_addr_list[i] = OPENSSL_malloc(a->h_length)) == NULL)
+ goto err;
+ memcpy(ret->h_addr_list[i], a->h_addr_list[i], a->h_length);
+ }
+ if (0) {
+ err:
+ if (ret != NULL)
+ ghbn_free(ret);
+ ret = NULL;
+ }
+ MemCheck_on();
+ return (ret);
+}
+
+static void ghbn_free(struct hostent *a)
+{
+ int i;
+
+ if (a == NULL)
+ return;
+
+ if (a->h_aliases != NULL) {
+ for (i = 0; a->h_aliases[i] != NULL; i++)
+ OPENSSL_free(a->h_aliases[i]);
+ OPENSSL_free(a->h_aliases);
+ }
+ if (a->h_addr_list != NULL) {
+ for (i = 0; a->h_addr_list[i] != NULL; i++)
+ OPENSSL_free(a->h_addr_list[i]);
+ OPENSSL_free(a->h_addr_list);
+ }
+ if (a->h_name != NULL)
+ OPENSSL_free(a->h_name);
+ OPENSSL_free(a);
+}
+
+# endif
+
struct hostent *BIO_gethostbyname(const char *name)
{
+# if 1
/*
* Caching gethostbyname() results forever is wrong, so we have to let
* the true gethostbyname() worry about this
@@ -120,8 +376,83 @@ struct hostent *BIO_gethostbyname(const char *name)
# else
return gethostbyname(name);
# endif
-}
+# else
+ struct hostent *ret;
+ int i, lowi = 0, j;
+ unsigned long low = (unsigned long)-1;
+
+# if 0
+ /*
+ * It doesn't make sense to use locking here: The function interface is
+ * not thread-safe, because threads can never be sure when some other
+ * thread destroys the data they were given a pointer to.
+ */
+ CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
+# endif
+ j = strlen(name);
+ if (j < 128) {
+ for (i = 0; i < GHBN_NUM; i++) {
+ if (low > ghbn_cache[i].order) {
+ low = ghbn_cache[i].order;
+ lowi = i;
+ }
+ if (ghbn_cache[i].order > 0) {
+ if (strncmp(name, ghbn_cache[i].name, 128) == 0)
+ break;
+ }
+ }
+ } else
+ i = GHBN_NUM;
+
+ if (i == GHBN_NUM) { /* no hit */
+ BIO_ghbn_miss++;
+ /*
+ * Note: under VMS with SOCKETSHR, it seems like the first parameter
+ * is 'char *', instead of 'const char *'
+ */
+# ifndef CONST_STRICT
+ ret = gethostbyname((char *)name);
+# else
+ ret = gethostbyname(name);
+# endif
+
+ if (ret == NULL)
+ goto end;
+ if (j > 128) { /* too big to cache */
+# if 0
+ /*
+ * If we were trying to make this function thread-safe (which is
+ * bound to fail), we'd have to give up in this case (or allocate
+ * more memory).
+ */
+ ret = NULL;
+# endif
+ goto end;
+ }
+
+ /* else add to cache */
+ if (ghbn_cache[lowi].ent != NULL)
+ ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */
+ ghbn_cache[lowi].name[0] = '\0';
+
+ if ((ret = ghbn_cache[lowi].ent = ghbn_dup(ret)) == NULL) {
+ BIOerr(BIO_F_BIO_GETHOSTBYNAME, ERR_R_MALLOC_FAILURE);
+ goto end;
+ }
+ strncpy(ghbn_cache[lowi].name, name, 128);
+ ghbn_cache[lowi].order = BIO_ghbn_miss + BIO_ghbn_hits;
+ } else {
+ BIO_ghbn_hits++;
+ ret = ghbn_cache[i].ent;
+ ghbn_cache[i].order = BIO_ghbn_miss + BIO_ghbn_hits;
+ }
+ end:
+# if 0
+ CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
+# endif
+ return (ret);
# endif
+}
int BIO_sock_init(void)
{
@@ -135,7 +466,7 @@ int BIO_sock_init(void)
memset(&wsa_state, 0, sizeof(wsa_state));
/*
* Not making wsa_state available to the rest of the code is formally
- * wrong. But the structures we use are [believed to be] invariable
+ * wrong. But the structures we use are [beleived to be] invariable
* among Winsock DLLs, while API availability is [expected to be]
* probed at run-time with DSO_global_lookup.
*/
@@ -154,14 +485,40 @@ int BIO_sock_init(void)
return (-1);
# endif
+# if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
+ WORD wVerReq;
+ WSADATA wsaData;
+ int err;
+
+ if (!wsa_init_done) {
+ wsa_init_done = 1;
+ wVerReq = MAKEWORD(2, 0);
+ err = WSAStartup(wVerReq, &wsaData);
+ if (err != 0) {
+ SYSerr(SYS_F_WSASTARTUP, err);
+ BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP);
+ return (-1);
+ }
+ }
+# endif
+
return (1);
}
-void bio_sock_cleanup_int(void)
+void BIO_sock_cleanup(void)
{
# ifdef OPENSSL_SYS_WINDOWS
if (wsa_init_done) {
wsa_init_done = 0;
+# if 0 /* this call is claimed to be non-present in
+ * Winsock2 */
+ WSACancelBlockingCall();
+# endif
+ WSACleanup();
+ }
+# elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
+ if (wsa_init_done) {
+ wsa_init_done = 0;
WSACleanup();
}
# endif
@@ -208,83 +565,369 @@ int BIO_socket_ioctl(int fd, long type, void *arg)
}
# endif /* __VMS_VER */
-# if OPENSSL_API_COMPAT < 0x10100000L
-int BIO_get_accept_socket(char *host, int bind_mode)
+/*
+ * The reason I have implemented this instead of using sscanf is because
+ * Visual C 1.52c gives an unresolved external when linking a DLL :-(
+ */
+static int get_ip(const char *str, unsigned char ip[4])
{
- int s = INVALID_SOCKET;
- char *h = NULL, *p = NULL;
- BIO_ADDRINFO *res = NULL;
+ unsigned int tmp[4];
+ int num = 0, c, ok = 0;
+
+ tmp[0] = tmp[1] = tmp[2] = tmp[3] = 0;
+
+ for (;;) {
+ c = *(str++);
+ if ((c >= '0') && (c <= '9')) {
+ ok = 1;
+ tmp[num] = tmp[num] * 10 + c - '0';
+ if (tmp[num] > 255)
+ return (0);
+ } else if (c == '.') {
+ if (!ok)
+ return (-1);
+ if (num == 3)
+ return (0);
+ num++;
+ ok = 0;
+ } else if (c == '\0' && (num == 3) && ok)
+ break;
+ else
+ return (0);
+ }
+ ip[0] = tmp[0];
+ ip[1] = tmp[1];
+ ip[2] = tmp[2];
+ ip[3] = tmp[3];
+ return (1);
+}
- if (!BIO_parse_hostserv(host, &h, &p, BIO_PARSE_PRIO_SERV))
- return INVALID_SOCKET;
+int BIO_get_accept_socket(char *host, int bind_mode)
+{
+ int ret = 0;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sa_in;
+# if OPENSSL_USE_IPV6
+ struct sockaddr_in6 sa_in6;
+# endif
+ } server, client;
+ int s = INVALID_SOCKET, cs, addrlen;
+ unsigned char ip[4];
+ unsigned short port;
+ char *str = NULL, *e;
+ char *h, *p;
+ unsigned long l;
+ int err_num;
if (BIO_sock_init() != 1)
- return INVALID_SOCKET;
+ return (INVALID_SOCKET);
+
+ if ((str = BUF_strdup(host)) == NULL)
+ return (INVALID_SOCKET);
+
+ h = p = NULL;
+ h = str;
+ for (e = str; *e; e++) {
+ if (*e == ':') {
+ p = e;
+ } else if (*e == '/') {
+ *e = '\0';
+ break;
+ }
+ }
+ if (p)
+ *p++ = '\0'; /* points at last ':', '::port' is special
+ * [see below] */
+ else
+ p = h, h = NULL;
+
+# ifdef EAI_FAMILY
+ do {
+ static union {
+ void *p;
+ int (WSAAPI *f) (const char *, const char *,
+ const struct addrinfo *, struct addrinfo **);
+ } p_getaddrinfo = {
+ NULL
+ };
+ static union {
+ void *p;
+ void (WSAAPI *f) (struct addrinfo *);
+ } p_freeaddrinfo = {
+ NULL
+ };
+ struct addrinfo *res, hint;
+
+ if (p_getaddrinfo.p == NULL) {
+ if ((p_getaddrinfo.p = DSO_global_lookup("getaddrinfo")) == NULL
+ || (p_freeaddrinfo.p =
+ DSO_global_lookup("freeaddrinfo")) == NULL)
+ p_getaddrinfo.p = (void *)-1;
+ }
+ if (p_getaddrinfo.p == (void *)-1)
+ break;
- if (BIO_lookup(h, p, BIO_LOOKUP_SERVER, AF_UNSPEC, SOCK_STREAM, &res) != 0)
- goto err;
+ /*
+ * '::port' enforces IPv6 wildcard listener. Some OSes, e.g. Solaris,
+ * default to IPv6 without any hint. Also note that commonly IPv6
+ * wildchard socket can service IPv4 connections just as well...
+ */
+ memset(&hint, 0, sizeof(hint));
+ hint.ai_flags = AI_PASSIVE;
+ if (h) {
+ if (strchr(h, ':')) {
+ if (h[1] == '\0')
+ h = NULL;
+# if OPENSSL_USE_IPV6
+ hint.ai_family = AF_INET6;
+# else
+ h = NULL;
+# endif
+ } else if (h[0] == '*' && h[1] == '\0') {
+ hint.ai_family = AF_INET;
+ h = NULL;
+ }
+ }
- if ((s = BIO_socket(BIO_ADDRINFO_family(res), BIO_ADDRINFO_socktype(res),
- BIO_ADDRINFO_protocol(res), 0)) == INVALID_SOCKET) {
- s = INVALID_SOCKET;
+ if ((*p_getaddrinfo.f) (h, p, &hint, &res))
+ break;
+
+ addrlen = res->ai_addrlen <= sizeof(server) ?
+ res->ai_addrlen : sizeof(server);
+ memcpy(&server, res->ai_addr, addrlen);
+
+ (*p_freeaddrinfo.f) (res);
+ goto again;
+ } while (0);
+# endif
+
+ if (!BIO_get_port(p, &port))
goto err;
+
+ memset((char *)&server, 0, sizeof(server));
+ server.sa_in.sin_family = AF_INET;
+ server.sa_in.sin_port = htons(port);
+ addrlen = sizeof(server.sa_in);
+
+ if (h == NULL || strcmp(h, "*") == 0)
+ server.sa_in.sin_addr.s_addr = INADDR_ANY;
+ else {
+ if (!BIO_get_host_ip(h, &(ip[0])))
+ goto err;
+ l = (unsigned long)
+ ((unsigned long)ip[0] << 24L) |
+ ((unsigned long)ip[1] << 16L) |
+ ((unsigned long)ip[2] << 8L) | ((unsigned long)ip[3]);
+ server.sa_in.sin_addr.s_addr = htonl(l);
}
- if (!BIO_listen(s, BIO_ADDRINFO_address(res),
- bind_mode ? BIO_SOCK_REUSEADDR : 0)) {
- BIO_closesocket(s);
- s = INVALID_SOCKET;
+ again:
+ s = socket(server.sa.sa_family, SOCK_STREAM, SOCKET_PROTOCOL);
+ if (s == INVALID_SOCKET) {
+ SYSerr(SYS_F_SOCKET, get_last_socket_error());
+ ERR_add_error_data(3, "port='", host, "'");
+ BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_CREATE_SOCKET);
+ goto err;
}
+# ifdef SO_REUSEADDR
+ if (bind_mode == BIO_BIND_REUSEADDR) {
+ int i = 1;
+ ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&i, sizeof(i));
+ bind_mode = BIO_BIND_NORMAL;
+ }
+# endif
+ if (bind(s, &server.sa, addrlen) == -1) {
+# ifdef SO_REUSEADDR
+ err_num = get_last_socket_error();
+ if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
+# ifdef OPENSSL_SYS_WINDOWS
+ /*
+ * Some versions of Windows define EADDRINUSE to a dummy value.
+ */
+ (err_num == WSAEADDRINUSE))
+# else
+ (err_num == EADDRINUSE))
+# endif
+ {
+ client = server;
+ if (h == NULL || strcmp(h, "*") == 0) {
+# if OPENSSL_USE_IPV6
+ if (client.sa.sa_family == AF_INET6) {
+ memset(&client.sa_in6.sin6_addr, 0,
+ sizeof(client.sa_in6.sin6_addr));
+ client.sa_in6.sin6_addr.s6_addr[15] = 1;
+ } else
+# endif
+ if (client.sa.sa_family == AF_INET) {
+ client.sa_in.sin_addr.s_addr = htonl(0x7F000001);
+ } else
+ goto err;
+ }
+ cs = socket(client.sa.sa_family, SOCK_STREAM, SOCKET_PROTOCOL);
+ if (cs != INVALID_SOCKET) {
+ int ii;
+ ii = connect(cs, &client.sa, addrlen);
+ closesocket(cs);
+ if (ii == INVALID_SOCKET) {
+ bind_mode = BIO_BIND_REUSEADDR;
+ closesocket(s);
+ goto again;
+ }
+ /* else error */
+ }
+ /* else error */
+ }
+# endif
+ SYSerr(SYS_F_BIND, err_num);
+ ERR_add_error_data(3, "port='", host, "'");
+ BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_BIND_SOCKET);
+ goto err;
+ }
+ if (listen(s, MAX_LISTEN) == -1) {
+ SYSerr(SYS_F_BIND, get_last_socket_error());
+ ERR_add_error_data(3, "port='", host, "'");
+ BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_LISTEN_SOCKET);
+ goto err;
+ }
+ ret = 1;
err:
- BIO_ADDRINFO_free(res);
- OPENSSL_free(h);
- OPENSSL_free(p);
-
- return s;
+ if (str != NULL)
+ OPENSSL_free(str);
+ if ((ret == 0) && (s != INVALID_SOCKET)) {
+ closesocket(s);
+ s = INVALID_SOCKET;
+ }
+ return (s);
}
-int BIO_accept(int sock, char **ip_port)
+int BIO_accept(int sock, char **addr)
{
- BIO_ADDR res;
- int ret = -1;
+ int ret = INVALID_SOCKET;
+ unsigned long l;
+ unsigned short port;
+ char *p;
- ret = BIO_accept_ex(sock, &res, 0);
- if (ret == (int)INVALID_SOCKET) {
- if (BIO_sock_should_retry(ret)) {
- ret = -2;
- goto end;
- }
+ struct {
+ /*
+ * As for following union. Trouble is that there are platforms
+ * that have socklen_t and there are platforms that don't, on
+ * some platforms socklen_t is int and on some size_t. So what
+ * one can do? One can cook #ifdef spaghetti, which is nothing
+ * but masochistic. Or one can do union between int and size_t.
+ * One naturally does it primarily for 64-bit platforms where
+ * sizeof(int) != sizeof(size_t). But would it work? Note that
+ * if size_t member is initialized to 0, then later int member
+ * assignment naturally does the job on little-endian platforms
+ * regardless accept's expectations! What about big-endians?
+ * If accept expects int*, then it works, and if size_t*, then
+ * length value would appear as unreasonably large. But this
+ * won't prevent it from filling in the address structure. The
+ * trouble of course would be if accept returns more data than
+ * actual buffer can accomodate and overwrite stack... That's
+ * where early OPENSSL_assert comes into picture. Besides, the
+ * only 64-bit big-endian platform found so far that expects
+ * size_t* is HP-UX, where stack grows towards higher address.
+ * <appro>
+ */
+ union {
+ size_t s;
+ int i;
+ } len;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sa_in;
+# if OPENSSL_USE_IPV6
+ struct sockaddr_in6 sa_in6;
+# endif
+ } from;
+ } sa;
+
+ sa.len.s = 0;
+ sa.len.i = sizeof(sa.from);
+ memset(&sa.from, 0, sizeof(sa.from));
+ ret = accept(sock, &sa.from.sa, (void *)&sa.len);
+ if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) {
+ OPENSSL_assert(sa.len.s <= sizeof(sa.from));
+ sa.len.i = (int)sa.len.s;
+ /* use sa.len.i from this point */
+ }
+ if (ret == INVALID_SOCKET) {
+ if (BIO_sock_should_retry(ret))
+ return -2;
SYSerr(SYS_F_ACCEPT, get_last_socket_error());
BIOerr(BIO_F_BIO_ACCEPT, BIO_R_ACCEPT_ERROR);
goto end;
}
- if (ip_port != NULL) {
- char *host = BIO_ADDR_hostname_string(&res, 1);
- char *port = BIO_ADDR_service_string(&res, 1);
- if (host != NULL && port != NULL)
- *ip_port = OPENSSL_zalloc(strlen(host) + strlen(port) + 2);
- else
- *ip_port = NULL;
+ if (addr == NULL)
+ goto end;
- if (*ip_port == NULL) {
- BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE);
- BIO_closesocket(ret);
- ret = (int)INVALID_SOCKET;
+# ifdef EAI_FAMILY
+ do {
+ char h[NI_MAXHOST], s[NI_MAXSERV];
+ size_t nl;
+ static union {
+ void *p;
+ int (WSAAPI *f) (const struct sockaddr *, size_t /* socklen_t */ ,
+ char *, size_t, char *, size_t, int);
+ } p_getnameinfo = {
+ NULL
+ };
+ /*
+ * 2nd argument to getnameinfo is specified to be socklen_t.
+ * Unfortunately there is a number of environments where socklen_t is
+ * not defined. As it's passed by value, it's safe to pass it as
+ * size_t... <appro>
+ */
+
+ if (p_getnameinfo.p == NULL) {
+ if ((p_getnameinfo.p = DSO_global_lookup("getnameinfo")) == NULL)
+ p_getnameinfo.p = (void *)-1;
+ }
+ if (p_getnameinfo.p == (void *)-1)
+ break;
+
+ if ((*p_getnameinfo.f) (&sa.from.sa, sa.len.i, h, sizeof(h), s,
+ sizeof(s), NI_NUMERICHOST | NI_NUMERICSERV))
+ break;
+ nl = strlen(h) + strlen(s) + 2;
+ p = *addr;
+ if (p) {
+ *p = '\0';
+ p = OPENSSL_realloc(p, nl);
} else {
- strcpy(*ip_port, host);
- strcat(*ip_port, ":");
- strcat(*ip_port, port);
+ p = OPENSSL_malloc(nl);
+ }
+ if (p == NULL) {
+ BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE);
+ goto end;
+ }
+ *addr = p;
+ BIO_snprintf(*addr, nl, "%s:%s", h, s);
+ goto end;
+ } while (0);
+# endif
+ if (sa.from.sa.sa_family != AF_INET)
+ goto end;
+ l = ntohl(sa.from.sa_in.sin_addr.s_addr);
+ port = ntohs(sa.from.sa_in.sin_port);
+ if (*addr == NULL) {
+ if ((p = OPENSSL_malloc(24)) == NULL) {
+ BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE);
+ goto end;
}
- OPENSSL_free(host);
- OPENSSL_free(port);
+ *addr = p;
}
-
+ BIO_snprintf(*addr, 24, "%d.%d.%d.%d:%d",
+ (unsigned char)(l >> 24L) & 0xff,
+ (unsigned char)(l >> 16L) & 0xff,
+ (unsigned char)(l >> 8L) & 0xff,
+ (unsigned char)(l) & 0xff, port);
end:
- return ret;
+ return (ret);
}
-# endif
int BIO_set_tcp_ndelay(int s, int on)
{
@@ -312,70 +955,8 @@ int BIO_socket_nbio(int s, int mode)
l = mode;
# ifdef FIONBIO
- l = mode;
-
ret = BIO_socket_ioctl(s, FIONBIO, &l);
-# elif defined(F_GETFL) && defined(F_SETFL) && (defined(O_NONBLOCK) || defined(FNDELAY))
- /* make sure this call always pushes an error level; BIO_socket_ioctl() does so, so we do too. */
-
- l = fcntl(s, F_GETFL, 0);
- if (l == -1) {
- SYSerr(SYS_F_FCNTL, get_last_rtl_error());
- ret = -1;
- } else {
-# if defined(O_NONBLOCK)
- l &= ~O_NONBLOCK;
-# else
- l &= ~FNDELAY; /* BSD4.x */
-# endif
- if (mode) {
-# if defined(O_NONBLOCK)
- l |= O_NONBLOCK;
-# else
- l |= FNDELAY; /* BSD4.x */
-# endif
- }
- ret = fcntl(s, F_SETFL, l);
-
- if (ret < 0) {
- SYSerr(SYS_F_FCNTL, get_last_rtl_error());
- }
- }
-# else
- /* make sure this call always pushes an error level; BIO_socket_ioctl() does so, so we do too. */
- BIOerr(BIO_F_BIO_SOCKET_NBIO, ERR_R_PASSED_INVALID_ARGUMENT);
# endif
-
return (ret == 0);
}
-
-int BIO_sock_info(int sock,
- enum BIO_sock_info_type type, union BIO_sock_info_u *info)
-{
- switch (type) {
- case BIO_SOCK_INFO_ADDRESS:
- {
- socklen_t addr_len;
- int ret = 0;
- addr_len = sizeof(*info->addr);
- ret = getsockname(sock, BIO_ADDR_sockaddr_noconst(info->addr),
- &addr_len);
- if (ret == -1) {
- SYSerr(SYS_F_GETSOCKNAME, get_last_socket_error());
- BIOerr(BIO_F_BIO_SOCK_INFO, BIO_R_GETSOCKNAME_ERROR);
- return 0;
- }
- if ((size_t)addr_len > sizeof(*info->addr)) {
- BIOerr(BIO_F_BIO_SOCK_INFO, BIO_R_GETSOCKNAME_TRUNCATED_ADDRESS);
- return 0;
- }
- }
- break;
- default:
- BIOerr(BIO_F_BIO_SOCK_INFO, BIO_R_UNKNOWN_INFO_TYPE);
- return 0;
- }
- return 1;
-}
-
#endif
diff --git a/Cryptlib/OpenSSL/crypto/bio/b_sock2.c b/Cryptlib/OpenSSL/crypto/bio/b_sock2.c
deleted file mode 100644
index 7f4d89e5..00000000
--- a/Cryptlib/OpenSSL/crypto/bio/b_sock2.c
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
- *
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include "bio_lcl.h"
-
-#include <openssl/err.h>
-
-#ifndef OPENSSL_NO_SOCK
-# ifdef SO_MAXCONN
-# define MAX_LISTEN SO_MAXCONN
-# elif defined(SOMAXCONN)
-# define MAX_LISTEN SOMAXCONN
-# else
-# define MAX_LISTEN 32
-# endif
-
-/*-
- * BIO_socket - create a socket
- * @domain: the socket domain (AF_INET, AF_INET6, AF_UNIX, ...)
- * @socktype: the socket type (SOCK_STEAM, SOCK_DGRAM)
- * @protocol: the protocol to use (IPPROTO_TCP, IPPROTO_UDP)
- * @options: BIO socket options (currently unused)
- *
- * Creates a socket. This should be called before calling any
- * of BIO_connect and BIO_listen.
- *
- * Returns the file descriptor on success or INVALID_SOCKET on failure. On
- * failure errno is set, and a status is added to the OpenSSL error stack.
- */
-int BIO_socket(int domain, int socktype, int protocol, int options)
-{
- int sock = -1;
-
- if (BIO_sock_init() != 1)
- return INVALID_SOCKET;
-
- sock = socket(domain, socktype, protocol);
- if (sock == -1) {
- SYSerr(SYS_F_SOCKET, get_last_socket_error());
- BIOerr(BIO_F_BIO_SOCKET, BIO_R_UNABLE_TO_CREATE_SOCKET);
- return INVALID_SOCKET;
- }
-
- return sock;
-}
-
-/*-
- * BIO_connect - connect to an address
- * @sock: the socket to connect with
- * @addr: the address to connect to
- * @options: BIO socket options
- *
- * Connects to the address using the given socket and options.
- *
- * Options can be a combination of the following:
- * - BIO_SOCK_KEEPALIVE: enable regularly sending keep-alive messages.
- * - BIO_SOCK_NONBLOCK: Make the socket non-blocking.
- * - BIO_SOCK_NODELAY: don't delay small messages.
- *
- * options holds BIO socket options that can be used
- * You should call this for every address returned by BIO_lookup
- * until the connection is successful.
- *
- * Returns 1 on success or 0 on failure. On failure errno is set
- * and an error status is added to the OpenSSL error stack.
- */
-int BIO_connect(int sock, const BIO_ADDR *addr, int options)
-{
- int on = 1;
-
- if (sock == -1) {
- BIOerr(BIO_F_BIO_CONNECT, BIO_R_INVALID_SOCKET);
- return 0;
- }
-
- if (!BIO_socket_nbio(sock, (options & BIO_SOCK_NONBLOCK) != 0))
- return 0;
-
- if (options & BIO_SOCK_KEEPALIVE) {
- if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
- BIOerr(BIO_F_BIO_CONNECT, BIO_R_UNABLE_TO_KEEPALIVE);
- return 0;
- }
- }
-
- if (options & BIO_SOCK_NODELAY) {
- if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
- BIOerr(BIO_F_BIO_CONNECT, BIO_R_UNABLE_TO_NODELAY);
- return 0;
- }
- }
-
- if (connect(sock, BIO_ADDR_sockaddr(addr),
- BIO_ADDR_sockaddr_size(addr)) == -1) {
- if (!BIO_sock_should_retry(-1)) {
- SYSerr(SYS_F_CONNECT, get_last_socket_error());
- BIOerr(BIO_F_BIO_CONNECT, BIO_R_CONNECT_ERROR);
- }
- return 0;
- }
- return 1;
-}
-
-/*-
- * BIO_listen - Creates a listen socket
- * @sock: the socket to listen with
- * @addr: local address to bind to
- * @options: BIO socket options
- *
- * Binds to the address using the given socket and options, then
- * starts listening for incoming connections.
- *
- * Options can be a combination of the following:
- * - BIO_SOCK_KEEPALIVE: enable regularly sending keep-alive messages.
- * - BIO_SOCK_NONBLOCK: Make the socket non-blocking.
- * - BIO_SOCK_NODELAY: don't delay small messages.
- * - BIO_SOCK_REUSEADDR: Try to reuse the address and port combination
- * for a recently closed port.
- * - BIO_SOCK_V6_ONLY: When creating an IPv6 socket, make it listen only
- * for IPv6 addresses and not IPv4 addresses mapped to IPv6.
- *
- * It's recommended that you set up both an IPv6 and IPv4 listen socket, and
- * then check both for new clients that connect to it. You want to set up
- * the socket as non-blocking in that case since else it could hang.
- *
- * Not all operating systems support IPv4 addresses on an IPv6 socket, and for
- * others it's an option. If you pass the BIO_LISTEN_V6_ONLY it will try to
- * create the IPv6 sockets to only listen for IPv6 connection.
- *
- * It could be that the first BIO_listen() call will listen to all the IPv6
- * and IPv4 addresses and that then trying to bind to the IPv4 address will
- * fail. We can't tell the difference between already listening ourself to
- * it and someone else listening to it when failing and errno is EADDRINUSE, so
- * it's recommended to not give an error in that case if the first call was
- * successful.
- *
- * When restarting the program it could be that the port is still in use. If
- * you set to BIO_SOCK_REUSEADDR option it will try to reuse the port anyway.
- * It's recommended that you use this.
- */
-int BIO_listen(int sock, const BIO_ADDR *addr, int options)
-{
- int on = 1;
- int socktype;
- socklen_t socktype_len = sizeof(socktype);
-
- if (sock == -1) {
- BIOerr(BIO_F_BIO_LISTEN, BIO_R_INVALID_SOCKET);
- return 0;
- }
-
- if (getsockopt(sock, SOL_SOCKET, SO_TYPE, &socktype, &socktype_len) != 0
- || socktype_len != sizeof(socktype)) {
- SYSerr(SYS_F_GETSOCKOPT, get_last_socket_error());
- BIOerr(BIO_F_BIO_LISTEN, BIO_R_GETTING_SOCKTYPE);
- return 0;
- }
-
- if (!BIO_socket_nbio(sock, (options & BIO_SOCK_NONBLOCK) != 0))
- return 0;
-
-# ifndef OPENSSL_SYS_WINDOWS
- /* SO_REUSEADDR has different behavior on Windows than on
- * other operating systems, don't set it there. */
- if (options & BIO_SOCK_REUSEADDR) {
- if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
- BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_REUSEADDR);
- return 0;
- }
- }
-# endif
-
- if (options & BIO_SOCK_KEEPALIVE) {
- if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
- BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_KEEPALIVE);
- return 0;
- }
- }
-
- if (options & BIO_SOCK_NODELAY) {
- if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
- BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_NODELAY);
- return 0;
- }
- }
-
-# ifdef IPV6_V6ONLY
- if ((options & BIO_SOCK_V6_ONLY) && BIO_ADDR_family(addr) == AF_INET6) {
- if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) != 0) {
- SYSerr(SYS_F_SETSOCKOPT, get_last_socket_error());
- BIOerr(BIO_F_BIO_LISTEN, BIO_R_LISTEN_V6_ONLY);
- return 0;
- }
- }
-# endif
-
- if (bind(sock, BIO_ADDR_sockaddr(addr), BIO_ADDR_sockaddr_size(addr)) != 0) {
- SYSerr(SYS_F_BIND, get_last_socket_error());
- BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_BIND_SOCKET);
- return 0;
- }
-
- if (socktype != SOCK_DGRAM && listen(sock, MAX_LISTEN) == -1) {
- SYSerr(SYS_F_LISTEN, get_last_socket_error());
- BIOerr(BIO_F_BIO_LISTEN, BIO_R_UNABLE_TO_LISTEN_SOCKET);
- return 0;
- }
-
- return 1;
-}
-
-/*-
- * BIO_accept_ex - Accept new incoming connections
- * @sock: the listening socket
- * @addr: the BIO_ADDR to store the peer address in
- * @options: BIO socket options, applied on the accepted socket.
- *
- */
-int BIO_accept_ex(int accept_sock, BIO_ADDR *addr_, int options)
-{
- socklen_t len;
- int accepted_sock;
- BIO_ADDR locaddr;
- BIO_ADDR *addr = addr_ == NULL ? &locaddr : addr_;
-
- len = sizeof(*addr);
- accepted_sock = accept(accept_sock,
- BIO_ADDR_sockaddr_noconst(addr), &len);
- if (accepted_sock == -1) {
- if (!BIO_sock_should_retry(accepted_sock)) {
- SYSerr(SYS_F_ACCEPT, get_last_socket_error());
- BIOerr(BIO_F_BIO_ACCEPT_EX, BIO_R_ACCEPT_ERROR);
- }
- return INVALID_SOCKET;
- }
-
- if (!BIO_socket_nbio(accepted_sock, (options & BIO_SOCK_NONBLOCK) != 0)) {
- closesocket(accepted_sock);
- return INVALID_SOCKET;
- }
-
- return accepted_sock;
-}
-
-/*-
- * BIO_closesocket - Close a socket
- * @sock: the socket to close
- */
-int BIO_closesocket(int sock)
-{
- if (closesocket(sock) < 0)
- return 0;
- return 1;
-}
-#endif
diff --git a/Cryptlib/OpenSSL/crypto/bio/bf_buff.c b/Cryptlib/OpenSSL/crypto/bio/bf_buff.c
index b2a387b5..478fa16a 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bf_buff.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bf_buff.c
@@ -1,16 +1,65 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bf_buff.c */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
#include <stdio.h>
#include <errno.h>
-#include "bio_lcl.h"
-#include "internal/cryptlib.h"
+#include "cryptlib.h"
+#include <openssl/bio.h>
static int buffer_write(BIO *h, const char *buf, int num);
static int buffer_read(BIO *h, char *buf, int size);
@@ -22,7 +71,7 @@ static int buffer_free(BIO *data);
static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
#define DEFAULT_BUFFER_SIZE 4096
-static const BIO_METHOD methods_buffer = {
+static BIO_METHOD methods_buffer = {
BIO_TYPE_BUFFER,
"buffer",
buffer_write,
@@ -35,30 +84,35 @@ static const BIO_METHOD methods_buffer = {
buffer_callback_ctrl,
};
-const BIO_METHOD *BIO_f_buffer(void)
+BIO_METHOD *BIO_f_buffer(void)
{
return (&methods_buffer);
}
static int buffer_new(BIO *bi)
{
- BIO_F_BUFFER_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
+ BIO_F_BUFFER_CTX *ctx;
+ ctx = (BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX));
if (ctx == NULL)
return (0);
- ctx->ibuf_size = DEFAULT_BUFFER_SIZE;
- ctx->ibuf = OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
+ ctx->ibuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
if (ctx->ibuf == NULL) {
OPENSSL_free(ctx);
return (0);
}
- ctx->obuf_size = DEFAULT_BUFFER_SIZE;
- ctx->obuf = OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
+ ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
if (ctx->obuf == NULL) {
OPENSSL_free(ctx->ibuf);
OPENSSL_free(ctx);
return (0);
}
+ ctx->ibuf_size = DEFAULT_BUFFER_SIZE;
+ ctx->obuf_size = DEFAULT_BUFFER_SIZE;
+ ctx->ibuf_len = 0;
+ ctx->ibuf_off = 0;
+ ctx->obuf_len = 0;
+ ctx->obuf_off = 0;
bi->init = 1;
bi->ptr = (char *)ctx;
@@ -73,8 +127,10 @@ static int buffer_free(BIO *a)
if (a == NULL)
return (0);
b = (BIO_F_BUFFER_CTX *)a->ptr;
- OPENSSL_free(b->ibuf);
- OPENSSL_free(b->obuf);
+ if (b->ibuf != NULL)
+ OPENSSL_free(b->ibuf);
+ if (b->obuf != NULL)
+ OPENSSL_free(b->obuf);
OPENSSL_free(a->ptr);
a->ptr = NULL;
a->init = 0;
@@ -283,7 +339,8 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
p1 = OPENSSL_malloc((int)num);
if (p1 == NULL)
goto malloc_error;
- OPENSSL_free(ctx->ibuf);
+ if (ctx->ibuf != NULL)
+ OPENSSL_free(ctx->ibuf);
ctx->ibuf = p1;
}
ctx->ibuf_off = 0;
@@ -309,12 +366,12 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
p1 = ctx->ibuf;
p2 = ctx->obuf;
if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) {
- p1 = OPENSSL_malloc((int)num);
+ p1 = (char *)OPENSSL_malloc((int)num);
if (p1 == NULL)
goto malloc_error;
}
if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) {
- p2 = OPENSSL_malloc((int)num);
+ p2 = (char *)OPENSSL_malloc((int)num);
if (p2 == NULL) {
if (p1 != ctx->ibuf)
OPENSSL_free(p1);
@@ -357,6 +414,10 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
if (ctx->obuf_len > 0) {
r = BIO_write(b->next_bio,
&(ctx->obuf[ctx->obuf_off]), ctx->obuf_len);
+#if 0
+ fprintf(stderr, "FLUSH [%3d] %3d -> %3d\n", ctx->obuf_off,
+ ctx->obuf_len, r);
+#endif
BIO_copy_next_retry(b);
if (r <= 0)
return ((long)r);
@@ -365,6 +426,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
} else {
ctx->obuf_len = 0;
ctx->obuf_off = 0;
+ ret = 1;
break;
}
}
diff --git a/Cryptlib/OpenSSL/crypto/bio/bf_lbuf.c b/Cryptlib/OpenSSL/crypto/bio/bf_lbuf.c
deleted file mode 100644
index b3c2b5ee..00000000
--- a/Cryptlib/OpenSSL/crypto/bio/bf_lbuf.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
- *
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include "bio_lcl.h"
-#include "internal/cryptlib.h"
-#include <openssl/evp.h>
-
-static int linebuffer_write(BIO *h, const char *buf, int num);
-static int linebuffer_read(BIO *h, char *buf, int size);
-static int linebuffer_puts(BIO *h, const char *str);
-static int linebuffer_gets(BIO *h, char *str, int size);
-static long linebuffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
-static int linebuffer_new(BIO *h);
-static int linebuffer_free(BIO *data);
-static long linebuffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
-
-/* A 10k maximum should be enough for most purposes */
-#define DEFAULT_LINEBUFFER_SIZE 1024*10
-
-/* #define DEBUG */
-
-static const BIO_METHOD methods_linebuffer = {
- BIO_TYPE_LINEBUFFER,
- "linebuffer",
- linebuffer_write,
- linebuffer_read,
- linebuffer_puts,
- linebuffer_gets,
- linebuffer_ctrl,
- linebuffer_new,
- linebuffer_free,
- linebuffer_callback_ctrl,
-};
-
-const BIO_METHOD *BIO_f_linebuffer(void)
-{
- return (&methods_linebuffer);
-}
-
-typedef struct bio_linebuffer_ctx_struct {
- char *obuf; /* the output char array */
- int obuf_size; /* how big is the output buffer */
- int obuf_len; /* how many bytes are in it */
-} BIO_LINEBUFFER_CTX;
-
-static int linebuffer_new(BIO *bi)
-{
- BIO_LINEBUFFER_CTX *ctx;
-
- ctx = OPENSSL_malloc(sizeof(*ctx));
- if (ctx == NULL)
- return (0);
- ctx->obuf = OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE);
- if (ctx->obuf == NULL) {
- OPENSSL_free(ctx);
- return (0);
- }
- ctx->obuf_size = DEFAULT_LINEBUFFER_SIZE;
- ctx->obuf_len = 0;
-
- bi->init = 1;
- bi->ptr = (char *)ctx;
- bi->flags = 0;
- return (1);
-}
-
-static int linebuffer_free(BIO *a)
-{
- BIO_LINEBUFFER_CTX *b;
-
- if (a == NULL)
- return (0);
- b = (BIO_LINEBUFFER_CTX *)a->ptr;
- OPENSSL_free(b->obuf);
- OPENSSL_free(a->ptr);
- a->ptr = NULL;
- a->init = 0;
- a->flags = 0;
- return (1);
-}
-
-static int linebuffer_read(BIO *b, char *out, int outl)
-{
- int ret = 0;
-
- if (out == NULL)
- return (0);
- if (b->next_bio == NULL)
- return (0);
- ret = BIO_read(b->next_bio, out, outl);
- BIO_clear_retry_flags(b);
- BIO_copy_next_retry(b);
- return (ret);
-}
-
-static int linebuffer_write(BIO *b, const char *in, int inl)
-{
- int i, num = 0, foundnl;
- BIO_LINEBUFFER_CTX *ctx;
-
- if ((in == NULL) || (inl <= 0))
- return (0);
- ctx = (BIO_LINEBUFFER_CTX *)b->ptr;
- if ((ctx == NULL) || (b->next_bio == NULL))
- return (0);
-
- BIO_clear_retry_flags(b);
-
- do {
- const char *p;
-
- for (p = in; p < in + inl && *p != '\n'; p++) ;
- if (*p == '\n') {
- p++;
- foundnl = 1;
- } else
- foundnl = 0;
-
- /*
- * If a NL was found and we already have text in the save buffer,
- * concatenate them and write
- */
- while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len)
- && ctx->obuf_len > 0) {
- int orig_olen = ctx->obuf_len;
-
- i = ctx->obuf_size - ctx->obuf_len;
- if (p - in > 0) {
- if (i >= p - in) {
- memcpy(&(ctx->obuf[ctx->obuf_len]), in, p - in);
- ctx->obuf_len += p - in;
- inl -= p - in;
- num += p - in;
- in = p;
- } else {
- memcpy(&(ctx->obuf[ctx->obuf_len]), in, i);
- ctx->obuf_len += i;
- inl -= i;
- in += i;
- num += i;
- }
- }
- i = BIO_write(b->next_bio, ctx->obuf, ctx->obuf_len);
- if (i <= 0) {
- ctx->obuf_len = orig_olen;
- BIO_copy_next_retry(b);
-
- if (i < 0)
- return ((num > 0) ? num : i);
- if (i == 0)
- return (num);
- }
- if (i < ctx->obuf_len)
- memmove(ctx->obuf, ctx->obuf + i, ctx->obuf_len - i);
- ctx->obuf_len -= i;
- }
-
- /*
- * Now that the save buffer is emptied, let's write the input buffer
- * if a NL was found and there is anything to write.
- */
- if ((foundnl || p - in > ctx->obuf_size) && p - in > 0) {
- i = BIO_write(b->next_bio, in, p - in);
- if (i <= 0) {
- BIO_copy_next_retry(b);
- if (i < 0)
- return ((num > 0) ? num : i);
- if (i == 0)
- return (num);
- }
- num += i;
- in += i;
- inl -= i;
- }
- }
- while (foundnl && inl > 0);
- /*
- * We've written as much as we can. The rest of the input buffer, if
- * any, is text that doesn't and with a NL and therefore needs to be
- * saved for the next trip.
- */
- if (inl > 0) {
- memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl);
- ctx->obuf_len += inl;
- num += inl;
- }
- return num;
-}
-
-static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
-{
- BIO *dbio;
- BIO_LINEBUFFER_CTX *ctx;
- long ret = 1;
- char *p;
- int r;
- int obs;
-
- ctx = (BIO_LINEBUFFER_CTX *)b->ptr;
-
- switch (cmd) {
- case BIO_CTRL_RESET:
- ctx->obuf_len = 0;
- if (b->next_bio == NULL)
- return (0);
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
- break;
- case BIO_CTRL_INFO:
- ret = (long)ctx->obuf_len;
- break;
- case BIO_CTRL_WPENDING:
- ret = (long)ctx->obuf_len;
- if (ret == 0) {
- if (b->next_bio == NULL)
- return (0);
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
- }
- break;
- case BIO_C_SET_BUFF_SIZE:
- obs = (int)num;
- p = ctx->obuf;
- if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) {
- p = OPENSSL_malloc((int)num);
- if (p == NULL)
- goto malloc_error;
- }
- if (ctx->obuf != p) {
- if (ctx->obuf_len > obs) {
- ctx->obuf_len = obs;
- }
- memcpy(p, ctx->obuf, ctx->obuf_len);
- OPENSSL_free(ctx->obuf);
- ctx->obuf = p;
- ctx->obuf_size = obs;
- }
- break;
- case BIO_C_DO_STATE_MACHINE:
- if (b->next_bio == NULL)
- return (0);
- BIO_clear_retry_flags(b);
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
- BIO_copy_next_retry(b);
- break;
-
- case BIO_CTRL_FLUSH:
- if (b->next_bio == NULL)
- return (0);
- if (ctx->obuf_len <= 0) {
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
- break;
- }
-
- for (;;) {
- BIO_clear_retry_flags(b);
- if (ctx->obuf_len > 0) {
- r = BIO_write(b->next_bio, ctx->obuf, ctx->obuf_len);
- BIO_copy_next_retry(b);
- if (r <= 0)
- return ((long)r);
- if (r < ctx->obuf_len)
- memmove(ctx->obuf, ctx->obuf + r, ctx->obuf_len - r);
- ctx->obuf_len -= r;
- } else {
- ctx->obuf_len = 0;
- break;
- }
- }
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
- break;
- case BIO_CTRL_DUP:
- dbio = (BIO *)ptr;
- if (!BIO_set_write_buffer_size(dbio, ctx->obuf_size))
- ret = 0;
- break;
- default:
- if (b->next_bio == NULL)
- return (0);
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
- break;
- }
- return (ret);
- malloc_error:
- BIOerr(BIO_F_LINEBUFFER_CTRL, ERR_R_MALLOC_FAILURE);
- return (0);
-}
-
-static long linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
-{
- long ret = 1;
-
- if (b->next_bio == NULL)
- return (0);
- switch (cmd) {
- default:
- ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
- break;
- }
- return (ret);
-}
-
-static int linebuffer_gets(BIO *b, char *buf, int size)
-{
- if (b->next_bio == NULL)
- return (0);
- return (BIO_gets(b->next_bio, buf, size));
-}
-
-static int linebuffer_puts(BIO *b, const char *str)
-{
- return (linebuffer_write(b, str, strlen(str)));
-}
diff --git a/Cryptlib/OpenSSL/crypto/bio/bf_nbio.c b/Cryptlib/OpenSSL/crypto/bio/bf_nbio.c
index 364d9fb5..4842bb4c 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bf_nbio.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bf_nbio.c
@@ -1,17 +1,66 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bf_nbio.c */
+/* 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.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
#include <stdio.h>
#include <errno.h>
-#include "bio_lcl.h"
-#include "internal/cryptlib.h"
+#include "cryptlib.h"
#include <openssl/rand.h>
+#include <openssl/bio.h>
/*
* BIO_put and BIO_get both add to the digest, BIO_gets returns the digest
@@ -31,7 +80,7 @@ typedef struct nbio_test_st {
int lwn;
} NBIO_TEST;
-static const BIO_METHOD methods_nbiof = {
+static BIO_METHOD methods_nbiof = {
BIO_TYPE_NBIO_TEST,
"non-blocking IO test filter",
nbiof_write,
@@ -44,7 +93,7 @@ static const BIO_METHOD methods_nbiof = {
nbiof_callback_ctrl,
};
-const BIO_METHOD *BIO_f_nbio_test(void)
+BIO_METHOD *BIO_f_nbio_test(void)
{
return (&methods_nbiof);
}
@@ -53,12 +102,13 @@ static int nbiof_new(BIO *bi)
{
NBIO_TEST *nt;
- if ((nt = OPENSSL_zalloc(sizeof(*nt))) == NULL)
+ if (!(nt = (NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST))))
return (0);
nt->lrn = -1;
nt->lwn = -1;
bi->ptr = (char *)nt;
bi->init = 1;
+ bi->flags = 0;
return (1);
}
@@ -66,7 +116,8 @@ static int nbiof_free(BIO *a)
{
if (a == NULL)
return (0);
- OPENSSL_free(a->ptr);
+ if (a->ptr != NULL)
+ OPENSSL_free(a->ptr);
a->ptr = NULL;
a->init = 0;
a->flags = 0;
@@ -76,8 +127,10 @@ static int nbiof_free(BIO *a)
static int nbiof_read(BIO *b, char *out, int outl)
{
int ret = 0;
+#if 1
int num;
unsigned char n;
+#endif
if (out == NULL)
return (0);
@@ -85,6 +138,7 @@ static int nbiof_read(BIO *b, char *out, int outl)
return (0);
BIO_clear_retry_flags(b);
+#if 1
if (RAND_bytes(&n, 1) <= 0)
return -1;
num = (n & 0x07);
@@ -95,7 +149,9 @@ static int nbiof_read(BIO *b, char *out, int outl)
if (num == 0) {
ret = -1;
BIO_set_retry_read(b);
- } else {
+ } else
+#endif
+ {
ret = BIO_read(b->next_bio, out, outl);
if (ret < 0)
BIO_copy_next_retry(b);
@@ -118,6 +174,7 @@ static int nbiof_write(BIO *b, const char *in, int inl)
BIO_clear_retry_flags(b);
+#if 1
if (nt->lwn > 0) {
num = nt->lwn;
nt->lwn = 0;
@@ -133,7 +190,9 @@ static int nbiof_write(BIO *b, const char *in, int inl)
if (num == 0) {
ret = -1;
BIO_set_retry_write(b);
- } else {
+ } else
+#endif
+ {
ret = BIO_write(b->next_bio, in, inl);
if (ret < 0) {
BIO_copy_next_retry(b);
diff --git a/Cryptlib/OpenSSL/crypto/bio/bf_null.c b/Cryptlib/OpenSSL/crypto/bio/bf_null.c
index 0736b3f2..e0c79e82 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bf_null.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bf_null.c
@@ -1,16 +1,65 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bf_null.c */
+/* 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.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
#include <stdio.h>
#include <errno.h>
-#include "bio_lcl.h"
-#include "internal/cryptlib.h"
+#include "cryptlib.h"
+#include <openssl/bio.h>
/*
* BIO_put and BIO_get both add to the digest, BIO_gets returns the digest
@@ -24,7 +73,7 @@ static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int nullf_new(BIO *h);
static int nullf_free(BIO *data);
static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
-static const BIO_METHOD methods_nullf = {
+static BIO_METHOD methods_nullf = {
BIO_TYPE_NULL_FILTER,
"NULL filter",
nullf_write,
@@ -37,7 +86,7 @@ static const BIO_METHOD methods_nullf = {
nullf_callback_ctrl,
};
-const BIO_METHOD *BIO_f_null(void)
+BIO_METHOD *BIO_f_null(void)
{
return (&methods_nullf);
}
diff --git a/Cryptlib/OpenSSL/crypto/bio/bio_cb.c b/Cryptlib/OpenSSL/crypto/bio/bio_cb.c
index 69ea3d06..d3e86068 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bio_cb.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bio_cb.c
@@ -1,24 +1,73 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bio_cb.c */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include "bio_lcl.h"
-#include "internal/cryptlib.h"
+#include "cryptlib.h"
+#include <openssl/bio.h>
#include <openssl/err.h>
-long BIO_debug_callback(BIO *bio, int cmd, const char *argp,
- int argi, long argl, long ret)
+long MS_CALLBACK BIO_debug_callback(BIO *bio, int cmd, const char *argp,
+ int argi, long argl, long ret)
{
BIO *b;
- char buf[256];
+ MS_STATIC char buf[256];
char *p;
long r = 1;
int len;
@@ -27,11 +76,8 @@ long BIO_debug_callback(BIO *bio, int cmd, const char *argp,
if (BIO_CB_RETURN & cmd)
r = ret;
- len = BIO_snprintf(buf, sizeof buf, "BIO[%p]: ", (void *)bio);
+ len = BIO_snprintf(buf,sizeof buf,"BIO[%p]: ",(void *)bio);
- /* Ignore errors and continue printing the other information. */
- if (len < 0)
- len = 0;
p = buf + len;
p_maxlen = sizeof(buf) - len;
@@ -91,7 +137,7 @@ long BIO_debug_callback(BIO *bio, int cmd, const char *argp,
b = (BIO *)bio->cb_arg;
if (b != NULL)
BIO_write(b, buf, strlen(buf));
-#if !defined(OPENSSL_NO_STDIO)
+#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
else
fputs(buf, stderr);
#endif
diff --git a/Cryptlib/OpenSSL/crypto/bio/bio_err.c b/Cryptlib/OpenSSL/crypto/bio/bio_err.c
index 98c90d6e..d9007aa3 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bio_err.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bio_err.c
@@ -1,11 +1,62 @@
-/*
- * Generated by util/mkerr.pl DO NOT EDIT
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bio_err.c */
+/* ====================================================================
+ * Copyright (c) 1999-2015 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.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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).
+ *
+ */
+
+/*
+ * NOTE: this file was auto generated by the mkerr.pl script: any changes
+ * made to it will be overwritten when the script next updates this file,
+ * only reason strings will be preserved.
*/
#include <stdio.h>
@@ -19,21 +70,17 @@
# define ERR_REASON(reason) ERR_PACK(ERR_LIB_BIO,0,reason)
static ERR_STRING_DATA BIO_str_functs[] = {
- {ERR_FUNC(BIO_F_ACPT_STATE), "acpt_state"},
- {ERR_FUNC(BIO_F_ADDR_STRINGS), "addr_strings"},
+ {ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"},
{ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"},
- {ERR_FUNC(BIO_F_BIO_ACCEPT_EX), "BIO_accept_ex"},
- {ERR_FUNC(BIO_F_BIO_ADDR_NEW), "BIO_ADDR_new"},
+ {ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"},
{ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"},
- {ERR_FUNC(BIO_F_BIO_CONNECT), "BIO_connect"},
{ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"},
+ {ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"},
{ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"},
+ {ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"},
{ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"},
- {ERR_FUNC(BIO_F_BIO_GET_NEW_INDEX), "BIO_get_new_index"},
{ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"},
- {ERR_FUNC(BIO_F_BIO_LISTEN), "BIO_listen"},
- {ERR_FUNC(BIO_F_BIO_LOOKUP), "BIO_lookup"},
- {ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "bio_make_pair"},
+ {ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"},
{ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"},
{ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"},
{ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"},
@@ -41,70 +88,56 @@ static ERR_STRING_DATA BIO_str_functs[] = {
{ERR_FUNC(BIO_F_BIO_NREAD0), "BIO_nread0"},
{ERR_FUNC(BIO_F_BIO_NWRITE), "BIO_nwrite"},
{ERR_FUNC(BIO_F_BIO_NWRITE0), "BIO_nwrite0"},
- {ERR_FUNC(BIO_F_BIO_PARSE_HOSTSERV), "BIO_parse_hostserv"},
{ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"},
{ERR_FUNC(BIO_F_BIO_READ), "BIO_read"},
- {ERR_FUNC(BIO_F_BIO_SOCKET), "BIO_socket"},
- {ERR_FUNC(BIO_F_BIO_SOCKET_NBIO), "BIO_socket_nbio"},
- {ERR_FUNC(BIO_F_BIO_SOCK_INFO), "BIO_sock_info"},
{ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"},
{ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"},
- {ERR_FUNC(BIO_F_BUFFER_CTRL), "buffer_ctrl"},
- {ERR_FUNC(BIO_F_CONN_CTRL), "conn_ctrl"},
- {ERR_FUNC(BIO_F_CONN_STATE), "conn_state"},
- {ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "dgram_sctp_read"},
- {ERR_FUNC(BIO_F_DGRAM_SCTP_WRITE), "dgram_sctp_write"},
- {ERR_FUNC(BIO_F_FILE_CTRL), "file_ctrl"},
- {ERR_FUNC(BIO_F_FILE_READ), "file_read"},
- {ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "linebuffer_ctrl"},
- {ERR_FUNC(BIO_F_MEM_WRITE), "mem_write"},
+ {ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"},
+ {ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"},
+ {ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"},
+ {ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "DGRAM_SCTP_READ"},
+ {ERR_FUNC(BIO_F_DGRAM_SCTP_WRITE), "DGRAM_SCTP_WRITE"},
+ {ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"},
+ {ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"},
+ {ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"},
+ {ERR_FUNC(BIO_F_MEM_READ), "MEM_READ"},
+ {ERR_FUNC(BIO_F_MEM_WRITE), "MEM_WRITE"},
{ERR_FUNC(BIO_F_SSL_NEW), "SSL_new"},
+ {ERR_FUNC(BIO_F_WSASTARTUP), "WSASTARTUP"},
{0, NULL}
};
static ERR_STRING_DATA BIO_str_reasons[] = {
{ERR_REASON(BIO_R_ACCEPT_ERROR), "accept error"},
- {ERR_REASON(BIO_R_ADDRINFO_ADDR_IS_NOT_AF_INET),
- "addrinfo addr is not af inet"},
- {ERR_REASON(BIO_R_AMBIGUOUS_HOST_OR_SERVICE),
- "ambiguous host or service"},
{ERR_REASON(BIO_R_BAD_FOPEN_MODE), "bad fopen mode"},
+ {ERR_REASON(BIO_R_BAD_HOSTNAME_LOOKUP), "bad hostname lookup"},
{ERR_REASON(BIO_R_BROKEN_PIPE), "broken pipe"},
{ERR_REASON(BIO_R_CONNECT_ERROR), "connect error"},
+ {ERR_REASON(BIO_R_EOF_ON_MEMORY_BIO), "EOF on memory BIO"},
+ {ERR_REASON(BIO_R_ERROR_SETTING_NBIO), "error setting nbio"},
+ {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET),
+ "error setting nbio on accepted socket"},
+ {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET),
+ "error setting nbio on accept socket"},
{ERR_REASON(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET),
"gethostbyname addr is not af inet"},
- {ERR_REASON(BIO_R_GETSOCKNAME_ERROR), "getsockname error"},
- {ERR_REASON(BIO_R_GETSOCKNAME_TRUNCATED_ADDRESS),
- "getsockname truncated address"},
- {ERR_REASON(BIO_R_GETTING_SOCKTYPE), "getting socktype"},
{ERR_REASON(BIO_R_INVALID_ARGUMENT), "invalid argument"},
- {ERR_REASON(BIO_R_INVALID_SOCKET), "invalid socket"},
+ {ERR_REASON(BIO_R_INVALID_IP_ADDRESS), "invalid ip address"},
{ERR_REASON(BIO_R_IN_USE), "in use"},
- {ERR_REASON(BIO_R_LISTEN_V6_ONLY), "listen v6 only"},
- {ERR_REASON(BIO_R_LOOKUP_RETURNED_NOTHING), "lookup returned nothing"},
- {ERR_REASON(BIO_R_MALFORMED_HOST_OR_SERVICE),
- "malformed host or service"},
+ {ERR_REASON(BIO_R_KEEPALIVE), "keepalive"},
{ERR_REASON(BIO_R_NBIO_CONNECT_ERROR), "nbio connect error"},
- {ERR_REASON(BIO_R_NO_ACCEPT_ADDR_OR_SERVICE_SPECIFIED),
- "no accept addr or service specified"},
- {ERR_REASON(BIO_R_NO_HOSTNAME_OR_SERVICE_SPECIFIED),
- "no hostname or service specified"},
+ {ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED), "no accept port specified"},
+ {ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED), "no hostname specified"},
{ERR_REASON(BIO_R_NO_PORT_DEFINED), "no port defined"},
+ {ERR_REASON(BIO_R_NO_PORT_SPECIFIED), "no port specified"},
{ERR_REASON(BIO_R_NO_SUCH_FILE), "no such file"},
{ERR_REASON(BIO_R_NULL_PARAMETER), "null parameter"},
+ {ERR_REASON(BIO_R_TAG_MISMATCH), "tag mismatch"},
{ERR_REASON(BIO_R_UNABLE_TO_BIND_SOCKET), "unable to bind socket"},
{ERR_REASON(BIO_R_UNABLE_TO_CREATE_SOCKET), "unable to create socket"},
- {ERR_REASON(BIO_R_UNABLE_TO_KEEPALIVE), "unable to keepalive"},
{ERR_REASON(BIO_R_UNABLE_TO_LISTEN_SOCKET), "unable to listen socket"},
- {ERR_REASON(BIO_R_UNABLE_TO_NODELAY), "unable to nodelay"},
- {ERR_REASON(BIO_R_UNABLE_TO_REUSEADDR), "unable to reuseaddr"},
- {ERR_REASON(BIO_R_UNAVAILABLE_IP_FAMILY), "unavailable ip family"},
{ERR_REASON(BIO_R_UNINITIALIZED), "uninitialized"},
- {ERR_REASON(BIO_R_UNKNOWN_INFO_TYPE), "unknown info type"},
- {ERR_REASON(BIO_R_UNSUPPORTED_IP_FAMILY), "unsupported ip family"},
{ERR_REASON(BIO_R_UNSUPPORTED_METHOD), "unsupported method"},
- {ERR_REASON(BIO_R_UNSUPPORTED_PROTOCOL_FAMILY),
- "unsupported protocol family"},
{ERR_REASON(BIO_R_WRITE_TO_READ_ONLY_BIO), "write to read only BIO"},
{ERR_REASON(BIO_R_WSASTARTUP), "WSAStartup"},
{0, NULL}
@@ -112,7 +145,7 @@ static ERR_STRING_DATA BIO_str_reasons[] = {
#endif
-int ERR_load_BIO_strings(void)
+void ERR_load_BIO_strings(void)
{
#ifndef OPENSSL_NO_ERR
@@ -121,5 +154,4 @@ int ERR_load_BIO_strings(void)
ERR_load_strings(0, BIO_str_reasons);
}
#endif
- return 1;
}
diff --git a/Cryptlib/OpenSSL/crypto/bio/bio_lcl.h b/Cryptlib/OpenSSL/crypto/bio/bio_lcl.h
index 39178cf5..741884da 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bio_lcl.h
+++ b/Cryptlib/OpenSSL/crypto/bio/bio_lcl.h
@@ -1,154 +1,4 @@
-/*
- * Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
- *
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
- */
-
-#define USE_SOCKETS
-#include "e_os.h"
-
-/* BEGIN BIO_ADDRINFO/BIO_ADDR stuff. */
-
-#ifndef OPENSSL_NO_SOCK
-/*
- * Throughout this file and b_addr.c, the existence of the macro
- * AI_PASSIVE is used to detect the availability of struct addrinfo,
- * getnameinfo() and getaddrinfo(). If that macro doesn't exist,
- * we use our own implementation instead.
- */
-
-/*
- * It's imperative that these macros get defined before openssl/bio.h gets
- * included. Otherwise, the AI_PASSIVE hack will not work properly.
- * For clarity, we check for internal/cryptlib.h since it's a common header
- * that also includes bio.h.
- */
-# ifdef HEADER_CRYPTLIB_H
-# error internal/cryptlib.h included before bio_lcl.h
-# endif
-# ifdef HEADER_BIO_H
-# error openssl/bio.h included before bio_lcl.h
-# endif
-
-/*
- * Undefine AF_UNIX on systems that define it but don't support it.
- */
-# if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VMS)
-# undef AF_UNIX
-# endif
-
-# ifdef AI_PASSIVE
-
-/*
- * There's a bug in VMS C header file netdb.h, where struct addrinfo
- * always is the P32 variant, but the functions that handle that structure,
- * such as getaddrinfo() and freeaddrinfo() adapt to the initial pointer
- * size. The easiest workaround is to force struct addrinfo to be the
- * 64-bit variant when compiling in P64 mode.
- */
-# if defined(OPENSSL_SYS_VMS) && __INITIAL_POINTER_SIZE == 64
-# define addrinfo __addrinfo64
-# endif
-
-# define bio_addrinfo_st addrinfo
-# define bai_family ai_family
-# define bai_socktype ai_socktype
-# define bai_protocol ai_protocol
-# define bai_addrlen ai_addrlen
-# define bai_addr ai_addr
-# define bai_next ai_next
-# else
-struct bio_addrinfo_st {
- int bai_family;
- int bai_socktype;
- int bai_protocol;
- size_t bai_addrlen;
- struct sockaddr *bai_addr;
- struct bio_addrinfo_st *bai_next;
-};
-# endif
-
-union bio_addr_st {
- struct sockaddr sa;
-# ifdef AF_INET6
- struct sockaddr_in6 s_in6;
-# endif
- struct sockaddr_in s_in;
-# ifdef AF_UNIX
- struct sockaddr_un s_un;
-# endif
-};
-#endif
-
-/* END BIO_ADDRINFO/BIO_ADDR stuff. */
-
-#include "internal/cryptlib.h"
-#include <internal/bio.h>
-
-typedef struct bio_f_buffer_ctx_struct {
- /*-
- * Buffers are setup like this:
- *
- * <---------------------- size ----------------------->
- * +---------------------------------------------------+
- * | consumed | remaining | free space |
- * +---------------------------------------------------+
- * <-- off --><------- len ------->
- */
- /*- BIO *bio; *//*
- * this is now in the BIO struct
- */
- int ibuf_size; /* how big is the input buffer */
- int obuf_size; /* how big is the output buffer */
- char *ibuf; /* the char array */
- int ibuf_len; /* how many bytes are in it */
- int ibuf_off; /* write/read offset */
- char *obuf; /* the char array */
- int obuf_len; /* how many bytes are in it */
- int obuf_off; /* write/read offset */
-} BIO_F_BUFFER_CTX;
-
-struct bio_st {
- const BIO_METHOD *method;
- /* bio, mode, argp, argi, argl, ret */
- long (*callback) (struct bio_st *, int, const char *, int, long, long);
- char *cb_arg; /* first argument for the callback */
- int init;
- int shutdown;
- int flags; /* extra storage */
- int retry_reason;
- int num;
- void *ptr;
- struct bio_st *next_bio; /* used by filter BIOs */
- struct bio_st *prev_bio; /* used by filter BIOs */
- int references;
- uint64_t num_read;
- uint64_t num_write;
- CRYPTO_EX_DATA ex_data;
- CRYPTO_RWLOCK *lock;
-};
-
-#ifndef OPENSSL_NO_SOCK
-# ifdef OPENSSL_SYS_VMS
-typedef unsigned int socklen_t;
-# endif
-
-extern CRYPTO_RWLOCK *bio_lookup_lock;
-
-int BIO_ADDR_make(BIO_ADDR *ap, const struct sockaddr *sa);
-const struct sockaddr *BIO_ADDR_sockaddr(const BIO_ADDR *ap);
-struct sockaddr *BIO_ADDR_sockaddr_noconst(BIO_ADDR *ap);
-socklen_t BIO_ADDR_sockaddr_size(const BIO_ADDR *ap);
-socklen_t BIO_ADDRINFO_sockaddr_size(const BIO_ADDRINFO *bai);
-const struct sockaddr *BIO_ADDRINFO_sockaddr(const BIO_ADDRINFO *bai);
-#endif
-
-extern CRYPTO_RWLOCK *bio_type_lock;
-
-void bio_sock_cleanup_int(void);
+#include <openssl/bio.h>
#if BIO_FLAGS_UPLINK==0
/* Shortcut UPLINK calls on most platforms... */
@@ -183,6 +33,4 @@ void bio_sock_cleanup_int(void);
# define UP_lseek lseek
# define UP_close close
# endif
-
#endif
-
diff --git a/Cryptlib/OpenSSL/crypto/bio/bio_lib.c b/Cryptlib/OpenSSL/crypto/bio/bio_lib.c
index 62392c3a..07934f8a 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bio_lib.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bio_lib.c
@@ -1,53 +1,107 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bio_lib.c */
+/* 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)"
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
#include <stdio.h>
#include <errno.h>
#include <openssl/crypto.h>
-#include "bio_lcl.h"
-#include "internal/cryptlib.h"
+#include "cryptlib.h"
+#include <openssl/bio.h>
+#include <openssl/stack.h>
-BIO *BIO_new(const BIO_METHOD *method)
+BIO *BIO_new(BIO_METHOD *method)
{
- BIO *bio = OPENSSL_zalloc(sizeof(*bio));
+ BIO *ret = NULL;
- if (bio == NULL) {
+ ret = (BIO *)OPENSSL_malloc(sizeof(BIO));
+ if (ret == NULL) {
BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
}
+ if (!BIO_set(ret, method)) {
+ OPENSSL_free(ret);
+ ret = NULL;
+ }
+ return (ret);
+}
+int BIO_set(BIO *bio, BIO_METHOD *method)
+{
bio->method = method;
+ bio->callback = NULL;
+ bio->cb_arg = NULL;
+ bio->init = 0;
bio->shutdown = 1;
+ bio->flags = 0;
+ bio->retry_reason = 0;
+ bio->num = 0;
+ bio->ptr = NULL;
+ bio->prev_bio = NULL;
+ bio->next_bio = NULL;
bio->references = 1;
-
- if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data))
- goto err;
-
- bio->lock = CRYPTO_THREAD_lock_new();
- if (bio->lock == NULL) {
- BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE);
- CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data);
- goto err;
- }
-
- if (method->create != NULL && !method->create(bio)) {
- BIOerr(BIO_F_BIO_NEW, ERR_R_INIT_FAIL);
- CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data);
- CRYPTO_THREAD_lock_free(bio->lock);
- goto err;
- }
-
- return bio;
-
-err:
- OPENSSL_free(bio);
- return NULL;
+ bio->num_read = 0L;
+ bio->num_write = 0L;
+ CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data);
+ if (method->create != NULL)
+ if (!method->create(bio)) {
+ CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data);
+ return (0);
+ }
+ return (1);
}
int BIO_free(BIO *a)
@@ -55,59 +109,30 @@ int BIO_free(BIO *a)
int i;
if (a == NULL)
- return 0;
-
- if (CRYPTO_atomic_add(&a->references, -1, &i, a->lock) <= 0)
- return 0;
+ return (0);
- REF_PRINT_COUNT("BIO", a);
+ i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO);
+#ifdef REF_PRINT
+ REF_PRINT("BIO", a);
+#endif
if (i > 0)
- return 1;
- REF_ASSERT_ISNT(i < 0);
+ return (1);
+#ifdef REF_CHECK
+ if (i < 0) {
+ fprintf(stderr, "BIO_free, bad reference count\n");
+ abort();
+ }
+#endif
if ((a->callback != NULL) &&
((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0))
- return i;
-
- if ((a->method != NULL) && (a->method->destroy != NULL))
- a->method->destroy(a);
+ return (i);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data);
- CRYPTO_THREAD_lock_free(a->lock);
-
+ if ((a->method != NULL) && (a->method->destroy != NULL))
+ a->method->destroy(a);
OPENSSL_free(a);
-
- return 1;
-}
-
-void BIO_set_data(BIO *a, void *ptr)
-{
- a->ptr = ptr;
-}
-
-void *BIO_get_data(BIO *a)
-{
- return a->ptr;
-}
-
-void BIO_set_init(BIO *a, int init)
-{
- a->init = init;
-}
-
-int BIO_get_init(BIO *a)
-{
- return a->init;
-}
-
-void BIO_set_shutdown(BIO *a, int shut)
-{
- a->shutdown = shut;
-}
-
-int BIO_get_shutdown(BIO *a)
-{
- return a->shutdown;
+ return (1);
}
void BIO_vfree(BIO *a)
@@ -115,18 +140,6 @@ void BIO_vfree(BIO *a)
BIO_free(a);
}
-int BIO_up_ref(BIO *a)
-{
- int i;
-
- if (CRYPTO_atomic_add(&a->references, 1, &i, a->lock) <= 0)
- return 0;
-
- REF_PRINT_COUNT("BIO", a);
- REF_ASSERT_ISNT(i < 2);
- return ((i > 1) ? 1 : 0);
-}
-
void BIO_clear_flags(BIO *b, int flags)
{
b->flags &= ~flags;
@@ -197,7 +210,7 @@ int BIO_read(BIO *b, void *out, int outl)
i = b->method->bread(b, out, outl);
if (i > 0)
- b->num_read += (uint64_t)i;
+ b->num_read += (unsigned long)i;
if (cb != NULL)
i = (int)cb(b, BIO_CB_READ | BIO_CB_RETURN, out, outl, 0L, (long)i);
@@ -230,7 +243,7 @@ int BIO_write(BIO *b, const void *in, int inl)
i = b->method->bwrite(b, in, inl);
if (i > 0)
- b->num_write += (uint64_t)i;
+ b->num_write += (unsigned long)i;
if (cb != NULL)
i = (int)cb(b, BIO_CB_WRITE | BIO_CB_RETURN, in, inl, 0L, (long)i);
@@ -260,7 +273,7 @@ int BIO_puts(BIO *b, const char *in)
i = b->method->bputs(b, in);
if (i > 0)
- b->num_write += (uint64_t)i;
+ b->num_write += (unsigned long)i;
if (cb != NULL)
i = (int)cb(b, BIO_CB_PUTS | BIO_CB_RETURN, in, 0, 0L, (long)i);
@@ -314,9 +327,9 @@ long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg)
return (BIO_ctrl(b, cmd, larg, (char *)&i));
}
-void *BIO_ptr_ctrl(BIO *b, int cmd, long larg)
+char *BIO_ptr_ctrl(BIO *b, int cmd, long larg)
{
- void *p = NULL;
+ char *p = NULL;
if (BIO_ctrl(b, cmd, larg, (char *)&p) <= 0)
return (NULL);
@@ -455,16 +468,11 @@ int BIO_get_retry_reason(BIO *bio)
return (bio->retry_reason);
}
-void BIO_set_retry_reason(BIO *bio, int reason)
-{
- bio->retry_reason = reason;
-}
-
BIO *BIO_find_type(BIO *bio, int type)
{
int mt, mask;
- if (bio == NULL)
+ if (!bio)
return NULL;
mask = type & 0xff;
do {
@@ -484,16 +492,11 @@ BIO *BIO_find_type(BIO *bio, int type)
BIO *BIO_next(BIO *b)
{
- if (b == NULL)
+ if (!b)
return NULL;
return b->next_bio;
}
-void BIO_set_next(BIO *b, BIO *next)
-{
- b->next_bio = next;
-}
-
void BIO_free_all(BIO *bio)
{
BIO *b;
@@ -559,6 +562,13 @@ void BIO_copy_next_retry(BIO *b)
b->retry_reason = b->next_bio->retry_reason;
}
+int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
+ CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
+{
+ return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp,
+ new_func, dup_func, free_func);
+}
+
int BIO_set_ex_data(BIO *bio, int idx, void *data)
{
return (CRYPTO_set_ex_data(&(bio->ex_data), idx, data));
@@ -569,32 +579,18 @@ void *BIO_get_ex_data(BIO *bio, int idx)
return (CRYPTO_get_ex_data(&(bio->ex_data), idx));
}
-uint64_t BIO_number_read(BIO *bio)
+unsigned long BIO_number_read(BIO *bio)
{
if (bio)
return bio->num_read;
return 0;
}
-uint64_t BIO_number_written(BIO *bio)
+unsigned long BIO_number_written(BIO *bio)
{
if (bio)
return bio->num_write;
return 0;
}
-void bio_free_ex_data(BIO *bio)
-{
- CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data);
-}
-
-void bio_cleanup(void)
-{
-#ifndef OPENSSL_NO_SOCK
- bio_sock_cleanup_int();
- CRYPTO_THREAD_lock_free(bio_lookup_lock);
- bio_lookup_lock = NULL;
-#endif
- CRYPTO_THREAD_lock_free(bio_type_lock);
- bio_type_lock = NULL;
-}
+IMPLEMENT_STACK_OF(BIO)
diff --git a/Cryptlib/OpenSSL/crypto/bio/bio_meth.c b/Cryptlib/OpenSSL/crypto/bio/bio_meth.c
deleted file mode 100644
index c5f9f7e8..00000000
--- a/Cryptlib/OpenSSL/crypto/bio/bio_meth.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
- *
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
- */
-
-#include "bio_lcl.h"
-#include <internal/thread_once.h>
-
-CRYPTO_RWLOCK *bio_type_lock = NULL;
-static CRYPTO_ONCE bio_type_init = CRYPTO_ONCE_STATIC_INIT;
-
-DEFINE_RUN_ONCE_STATIC(do_bio_type_init)
-{
- bio_type_lock = CRYPTO_THREAD_lock_new();
- return bio_type_lock != NULL;
-}
-
-int BIO_get_new_index()
-{
- static int bio_count = BIO_TYPE_START;
- int newval;
-
- if (!RUN_ONCE(&bio_type_init, do_bio_type_init)) {
- BIOerr(BIO_F_BIO_GET_NEW_INDEX, ERR_R_MALLOC_FAILURE);
- return -1;
- }
- if (!CRYPTO_atomic_add(&bio_count, 1, &newval, bio_type_lock))
- return -1;
- return newval;
-}
-
-BIO_METHOD *BIO_meth_new(int type, const char *name)
-{
- BIO_METHOD *biom = OPENSSL_zalloc(sizeof(BIO_METHOD));
-
- if (biom != NULL) {
- biom->type = type;
- biom->name = name;
- }
- return biom;
-}
-
-void BIO_meth_free(BIO_METHOD *biom)
-{
- OPENSSL_free(biom);
-}
-
-int (*BIO_meth_get_write(BIO_METHOD *biom)) (BIO *, const char *, int)
-{
- return biom->bwrite;
-}
-
-int BIO_meth_set_write(BIO_METHOD *biom,
- int (*bwrite) (BIO *, const char *, int))
-{
- biom->bwrite = bwrite;
- return 1;
-}
-
-int (*BIO_meth_get_read(BIO_METHOD *biom)) (BIO *, char *, int)
-{
- return biom->bread;
-}
-
-int BIO_meth_set_read(BIO_METHOD *biom,
- int (*bread) (BIO *, char *, int))
-{
- biom->bread = bread;
- return 1;
-}
-
-int (*BIO_meth_get_puts(BIO_METHOD *biom)) (BIO *, const char *)
-{
- return biom->bputs;
-}
-
-int BIO_meth_set_puts(BIO_METHOD *biom,
- int (*bputs) (BIO *, const char *))
-{
- biom->bputs = bputs;
- return 1;
-}
-
-int (*BIO_meth_get_gets(BIO_METHOD *biom)) (BIO *, char *, int)
-{
- return biom->bgets;
-}
-
-int BIO_meth_set_gets(BIO_METHOD *biom,
- int (*bgets) (BIO *, char *, int))
-{
- biom->bgets = bgets;
- return 1;
-}
-
-long (*BIO_meth_get_ctrl(BIO_METHOD *biom)) (BIO *, int, long, void *)
-{
- return biom->ctrl;
-}
-
-int BIO_meth_set_ctrl(BIO_METHOD *biom,
- long (*ctrl) (BIO *, int, long, void *))
-{
- biom->ctrl = ctrl;
- return 1;
-}
-
-int (*BIO_meth_get_create(BIO_METHOD *biom)) (BIO *)
-{
- return biom->create;
-}
-
-int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *))
-{
- biom->create = create;
- return 1;
-}
-
-int (*BIO_meth_get_destroy(BIO_METHOD *biom)) (BIO *)
-{
- return biom->destroy;
-}
-
-int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *))
-{
- biom->destroy = destroy;
- return 1;
-}
-
-long (*BIO_meth_get_callback_ctrl(BIO_METHOD *biom)) (BIO *, int, bio_info_cb *)
-{
- return biom->callback_ctrl;
-}
-
-int BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
- long (*callback_ctrl) (BIO *, int,
- bio_info_cb *))
-{
- biom->callback_ctrl = callback_ctrl;
- return 1;
-}
diff --git a/Cryptlib/OpenSSL/crypto/bio/bss_acpt.c b/Cryptlib/OpenSSL/crypto/bio/bss_acpt.c
index 6fb971a5..4a5e39bd 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bss_acpt.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bss_acpt.c
@@ -1,35 +1,93 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bss_acpt.c */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
#include <stdio.h>
#include <errno.h>
-#include "bio_lcl.h"
+#define USE_SOCKETS
+#include "cryptlib.h"
+#include <openssl/bio.h>
#ifndef OPENSSL_NO_SOCK
+# ifdef OPENSSL_SYS_WIN16
+# define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
+# else
+# define SOCKET_PROTOCOL IPPROTO_TCP
+# endif
+
+# if (defined(OPENSSL_SYS_VMS) && __VMS_VER < 70000000)
+/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
+# undef FIONBIO
+# endif
+
typedef struct bio_accept_st {
int state;
- int accept_family;
- int bind_mode; /* Socket mode for BIO_listen */
- int accepted_mode; /* Socket mode for BIO_accept (set on accepted sock) */
char *param_addr;
- char *param_serv;
-
int accept_sock;
-
- BIO_ADDRINFO *addr_first;
- const BIO_ADDRINFO *addr_iter;
- BIO_ADDR cache_accepting_addr; /* Useful if we asked for port 0 */
- char *cache_accepting_name, *cache_accepting_serv;
- BIO_ADDR cache_peer_addr;
- char *cache_peer_name, *cache_peer_serv;
-
+ int accept_nbio;
+ char *addr;
+ int nbio;
+ /*
+ * If 0, it means normal, if 1, do a connect on bind failure, and if
+ * there is no-one listening, bind with SO_REUSEADDR. If 2, always use
+ * SO_REUSEADDR.
+ */
+ int bind_mode;
BIO *bio_chain;
} BIO_ACCEPT;
@@ -45,13 +103,10 @@ static BIO_ACCEPT *BIO_ACCEPT_new(void);
static void BIO_ACCEPT_free(BIO_ACCEPT *a);
# define ACPT_S_BEFORE 1
-# define ACPT_S_GET_ADDR 2
-# define ACPT_S_CREATE_SOCKET 3
-# define ACPT_S_LISTEN 4
-# define ACPT_S_ACCEPT 5
-# define ACPT_S_OK 6
+# define ACPT_S_GET_ACCEPT_SOCKET 2
+# define ACPT_S_OK 3
-static const BIO_METHOD methods_acceptp = {
+static BIO_METHOD methods_acceptp = {
BIO_TYPE_ACCEPT,
"socket accept",
acpt_write,
@@ -64,7 +119,7 @@ static const BIO_METHOD methods_acceptp = {
NULL,
};
-const BIO_METHOD *BIO_s_accept(void)
+BIO_METHOD *BIO_s_accept(void)
{
return (&methods_acceptp);
}
@@ -74,7 +129,7 @@ static int acpt_new(BIO *bi)
BIO_ACCEPT *ba;
bi->init = 0;
- bi->num = (int)INVALID_SOCKET;
+ bi->num = INVALID_SOCKET;
bi->flags = 0;
if ((ba = BIO_ACCEPT_new()) == NULL)
return (0);
@@ -88,10 +143,12 @@ static BIO_ACCEPT *BIO_ACCEPT_new(void)
{
BIO_ACCEPT *ret;
- if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
+ if ((ret = (BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL)
return (NULL);
- ret->accept_family = BIO_FAMILY_IPANY;
- ret->accept_sock = (int)INVALID_SOCKET;
+
+ memset(ret, 0, sizeof(BIO_ACCEPT));
+ ret->accept_sock = INVALID_SOCKET;
+ ret->bind_mode = BIO_BIND_NORMAL;
return (ret);
}
@@ -100,14 +157,12 @@ static void BIO_ACCEPT_free(BIO_ACCEPT *a)
if (a == NULL)
return;
- OPENSSL_free(a->param_addr);
- OPENSSL_free(a->param_serv);
- BIO_ADDRINFO_free(a->addr_first);
- OPENSSL_free(a->cache_accepting_name);
- OPENSSL_free(a->cache_accepting_serv);
- OPENSSL_free(a->cache_peer_name);
- OPENSSL_free(a->cache_peer_serv);
- BIO_free(a->bio_chain);
+ if (a->param_addr != NULL)
+ OPENSSL_free(a->param_addr);
+ if (a->addr != NULL)
+ OPENSSL_free(a->addr);
+ if (a->bio_chain != NULL)
+ BIO_free(a->bio_chain);
OPENSSL_free(a);
}
@@ -116,11 +171,11 @@ static void acpt_close_socket(BIO *bio)
BIO_ACCEPT *c;
c = (BIO_ACCEPT *)bio->ptr;
- if (c->accept_sock != (int)INVALID_SOCKET) {
+ if (c->accept_sock != INVALID_SOCKET) {
shutdown(c->accept_sock, 2);
closesocket(c->accept_sock);
- c->accept_sock = (int)INVALID_SOCKET;
- bio->num = (int)INVALID_SOCKET;
+ c->accept_sock = INVALID_SOCKET;
+ bio->num = INVALID_SOCKET;
}
}
@@ -145,203 +200,102 @@ static int acpt_free(BIO *a)
static int acpt_state(BIO *b, BIO_ACCEPT *c)
{
BIO *bio = NULL, *dbio;
- int s = -1, ret = -1;
-
- for (;;) {
- switch (c->state) {
- case ACPT_S_BEFORE:
- if (c->param_addr == NULL && c->param_serv == NULL) {
- BIOerr(BIO_F_ACPT_STATE, BIO_R_NO_ACCEPT_ADDR_OR_SERVICE_SPECIFIED);
- ERR_add_error_data(4,
- "hostname=", c->param_addr,
- " service=", c->param_serv);
- goto exit_loop;
- }
-
- /* Because we're starting a new bind, any cached name and serv
- * are now obsolete and need to be cleaned out.
- * QUESTION: should this be done in acpt_close_socket() instead?
- */
- OPENSSL_free(c->cache_accepting_name);
- c->cache_accepting_name = NULL;
- OPENSSL_free(c->cache_accepting_serv);
- c->cache_accepting_serv = NULL;
- OPENSSL_free(c->cache_peer_name);
- c->cache_peer_name = NULL;
- OPENSSL_free(c->cache_peer_serv);
- c->cache_peer_serv = NULL;
-
- c->state = ACPT_S_GET_ADDR;
- break;
-
- case ACPT_S_GET_ADDR:
- {
- int family = AF_UNSPEC;
- switch (c->accept_family) {
- case BIO_FAMILY_IPV6:
- if (1) { /* This is a trick we use to avoid bit rot.
- * at least the "else" part will always be
- * compiled.
- */
-#ifdef AF_INET6
- family = AF_INET6;
- } else {
-#endif
- BIOerr(BIO_F_ACPT_STATE, BIO_R_UNAVAILABLE_IP_FAMILY);
- goto exit_loop;
- }
- break;
- case BIO_FAMILY_IPV4:
- family = AF_INET;
- break;
- case BIO_FAMILY_IPANY:
- family = AF_UNSPEC;
- break;
- default:
- BIOerr(BIO_F_ACPT_STATE, BIO_R_UNSUPPORTED_IP_FAMILY);
- goto exit_loop;
- }
- if (BIO_lookup(c->param_addr, c->param_serv, BIO_LOOKUP_SERVER,
- family, SOCK_STREAM, &c->addr_first) == 0)
- goto exit_loop;
- }
- if (c->addr_first == NULL) {
- BIOerr(BIO_F_ACPT_STATE, BIO_R_LOOKUP_RETURNED_NOTHING);
- goto exit_loop;
- }
- /* We're currently not iterating, but set this as preparation
- * for possible future development in that regard
- */
- c->addr_iter = c->addr_first;
- c->state = ACPT_S_CREATE_SOCKET;
- break;
-
- case ACPT_S_CREATE_SOCKET:
- ret = BIO_socket(BIO_ADDRINFO_family(c->addr_iter),
- BIO_ADDRINFO_socktype(c->addr_iter),
- BIO_ADDRINFO_protocol(c->addr_iter), 0);
- if (ret == (int)INVALID_SOCKET) {
- SYSerr(SYS_F_SOCKET, get_last_socket_error());
- ERR_add_error_data(4,
- "hostname=", c->param_addr,
- " service=", c->param_serv);
- BIOerr(BIO_F_ACPT_STATE, BIO_R_UNABLE_TO_CREATE_SOCKET);
- goto exit_loop;
- }
- c->accept_sock = ret;
- b->num = ret;
- c->state = ACPT_S_LISTEN;
- break;
-
- case ACPT_S_LISTEN:
- {
- if (!BIO_listen(c->accept_sock,
- BIO_ADDRINFO_address(c->addr_iter),
- c->bind_mode)) {
- BIO_closesocket(c->accept_sock);
- goto exit_loop;
- }
- }
-
- {
- union BIO_sock_info_u info;
-
- info.addr = &c->cache_accepting_addr;
- if (!BIO_sock_info(c->accept_sock, BIO_SOCK_INFO_ADDRESS,
- &info)) {
- BIO_closesocket(c->accept_sock);
- goto exit_loop;
- }
+ int s = -1;
+ int i;
+
+ again:
+ switch (c->state) {
+ case ACPT_S_BEFORE:
+ if (c->param_addr == NULL) {
+ BIOerr(BIO_F_ACPT_STATE, BIO_R_NO_ACCEPT_PORT_SPECIFIED);
+ return (-1);
+ }
+ s = BIO_get_accept_socket(c->param_addr, c->bind_mode);
+ if (s == INVALID_SOCKET)
+ return (-1);
+
+ if (c->accept_nbio) {
+ if (!BIO_socket_nbio(s, 1)) {
+ closesocket(s);
+ BIOerr(BIO_F_ACPT_STATE,
+ BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
+ return (-1);
}
+ }
+ c->accept_sock = s;
+ b->num = s;
+ c->state = ACPT_S_GET_ACCEPT_SOCKET;
+ return (1);
+ /* break; */
+ case ACPT_S_GET_ACCEPT_SOCKET:
+ if (b->next_bio != NULL) {
+ c->state = ACPT_S_OK;
+ goto again;
+ }
+ BIO_clear_retry_flags(b);
+ b->retry_reason = 0;
+ i = BIO_accept(c->accept_sock, &(c->addr));
+
+ /* -2 return means we should retry */
+ if (i == -2) {
+ BIO_set_retry_special(b);
+ b->retry_reason = BIO_RR_ACCEPT;
+ return -1;
+ }
- c->cache_accepting_name =
- BIO_ADDR_hostname_string(&c->cache_accepting_addr, 1);
- c->cache_accepting_serv =
- BIO_ADDR_service_string(&c->cache_accepting_addr, 1);
- c->state = ACPT_S_ACCEPT;
- s = -1;
- ret = 1;
- goto end;
-
- case ACPT_S_ACCEPT:
- if (b->next_bio != NULL) {
- c->state = ACPT_S_OK;
- break;
- }
- BIO_clear_retry_flags(b);
- b->retry_reason = 0;
-
- s = BIO_accept_ex(c->accept_sock, &c->cache_peer_addr,
- c->accepted_mode);
-
- /* If the returned socket is invalid, this might still be
- * retryable
- */
- if (s < 0) {
- if (BIO_sock_should_retry(s)) {
- BIO_set_retry_special(b);
- b->retry_reason = BIO_RR_ACCEPT;
- goto end;
- }
- }
+ if (i < 0)
+ return (i);
- /* If it wasn't retryable, we fail */
- if (s < 0) {
- ret = s;
- goto exit_loop;
- }
+ bio = BIO_new_socket(i, BIO_CLOSE);
+ if (bio == NULL)
+ goto err;
- bio = BIO_new_socket(s, BIO_CLOSE);
- if (bio == NULL)
- goto exit_loop;
-
- BIO_set_callback(bio, BIO_get_callback(b));
- BIO_set_callback_arg(bio, BIO_get_callback_arg(b));
-
- /*
- * If the accept BIO has an bio_chain, we dup it and put the new
- * socket at the end.
- */
- if (c->bio_chain != NULL) {
- if ((dbio = BIO_dup_chain(c->bio_chain)) == NULL)
- goto exit_loop;
- if (!BIO_push(dbio, bio))
- goto exit_loop;
- bio = dbio;
- }
- if (BIO_push(b, bio) == NULL)
- goto exit_loop;
+ BIO_set_callback(bio, BIO_get_callback(b));
+ BIO_set_callback_arg(bio, BIO_get_callback_arg(b));
- c->cache_peer_name =
- BIO_ADDR_hostname_string(&c->cache_peer_addr, 1);
- c->cache_peer_serv =
- BIO_ADDR_service_string(&c->cache_peer_addr, 1);
- c->state = ACPT_S_OK;
- bio = NULL;
- ret = 1;
- goto end;
-
- case ACPT_S_OK:
- if (b->next_bio == NULL) {
- c->state = ACPT_S_ACCEPT;
- break;
+ if (c->nbio) {
+ if (!BIO_socket_nbio(i, 1)) {
+ BIOerr(BIO_F_ACPT_STATE,
+ BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
+ goto err;
}
- ret = 1;
- goto end;
+ }
- default:
- ret = 0;
- goto end;
+ /*
+ * If the accept BIO has an bio_chain, we dup it and put the new
+ * socket at the end.
+ */
+ if (c->bio_chain != NULL) {
+ if ((dbio = BIO_dup_chain(c->bio_chain)) == NULL)
+ goto err;
+ if (!BIO_push(dbio, bio))
+ goto err;
+ bio = dbio;
+ }
+ if (BIO_push(b, bio) == NULL)
+ goto err;
+
+ c->state = ACPT_S_OK;
+ return (1);
+ err:
+ if (bio != NULL)
+ BIO_free(bio);
+ else if (s >= 0)
+ closesocket(s);
+ return (0);
+ /* break; */
+ case ACPT_S_OK:
+ if (b->next_bio == NULL) {
+ c->state = ACPT_S_GET_ACCEPT_SOCKET;
+ goto again;
}
+ return (1);
+ /* break; */
+ default:
+ return (0);
+ /* break; */
}
- exit_loop:
- if (bio != NULL)
- BIO_free(bio);
- else if (s >= 0)
- BIO_closesocket(s);
- end:
- return ret;
}
static int acpt_read(BIO *b, char *out, int outl)
@@ -396,8 +350,6 @@ static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
ret = 0;
data->state = ACPT_S_BEFORE;
acpt_close_socket(b);
- BIO_ADDRINFO_free(data->addr_first);
- data->addr_first = NULL;
b->flags = 0;
break;
case BIO_C_DO_STATE_MACHINE:
@@ -407,49 +359,27 @@ static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_C_SET_ACCEPT:
if (ptr != NULL) {
if (num == 0) {
- char *hold_serv = data->param_serv;
- /* We affect the hostname regardless. However, the input
- * string might contain a host:service spec, so we must
- * parse it, which might or might not affect the service
- */
- OPENSSL_free(data->param_addr);
- data->param_addr = NULL;
- ret = BIO_parse_hostserv(ptr,
- &data->param_addr,
- &data->param_serv,
- BIO_PARSE_PRIO_SERV);
- if (hold_serv != data->param_serv)
- OPENSSL_free(hold_serv);
b->init = 1;
+ if (data->param_addr != NULL)
+ OPENSSL_free(data->param_addr);
+ data->param_addr = BUF_strdup(ptr);
} else if (num == 1) {
- OPENSSL_free(data->param_serv);
- data->param_serv = BUF_strdup(ptr);
- b->init = 1;
+ data->accept_nbio = (ptr != NULL);
} else if (num == 2) {
- data->bind_mode |= BIO_SOCK_NONBLOCK;
- } else if (num == 3) {
- BIO_free(data->bio_chain);
+ if (data->bio_chain != NULL)
+ BIO_free(data->bio_chain);
data->bio_chain = (BIO *)ptr;
- } else if (num == 4) {
- data->accept_family = *(int *)ptr;
- }
- } else {
- if (num == 2) {
- data->bind_mode &= ~BIO_SOCK_NONBLOCK;
}
}
break;
case BIO_C_SET_NBIO:
- if (num != 0)
- data->accepted_mode |= BIO_SOCK_NONBLOCK;
- else
- data->accepted_mode &= ~BIO_SOCK_NONBLOCK;
+ data->nbio = (int)num;
break;
case BIO_C_SET_FD:
b->init = 1;
b->num = *((int *)ptr);
data->accept_sock = b->num;
- data->state = ACPT_S_ACCEPT;
+ data->state = ACPT_S_GET_ACCEPT_SOCKET;
b->shutdown = (int)num;
b->init = 1;
break;
@@ -464,35 +394,9 @@ static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
break;
case BIO_C_GET_ACCEPT:
if (b->init) {
- if (num == 0 && ptr != NULL) {
- pp = (char **)ptr;
- *pp = data->cache_accepting_name;
- } else if (num == 1 && ptr != NULL) {
+ if (ptr != NULL) {
pp = (char **)ptr;
- *pp = data->cache_accepting_serv;
- } else if (num == 2 && ptr != NULL) {
- pp = (char **)ptr;
- *pp = data->cache_peer_name;
- } else if (num == 3 && ptr != NULL) {
- pp = (char **)ptr;
- *pp = data->cache_peer_serv;
- } else if (num == 4) {
- switch (BIO_ADDRINFO_family(data->addr_iter)) {
-#ifdef AF_INET6
- case AF_INET6:
- ret = BIO_FAMILY_IPV6;
- break;
-#endif
- case AF_INET:
- ret = BIO_FAMILY_IPV4;
- break;
- case 0:
- ret = data->accept_family;
- break;
- default:
- ret = -1;
- break;
- }
+ *pp = data->param_addr;
} else
ret = -1;
} else
@@ -548,10 +452,12 @@ BIO *BIO_new_accept(const char *str)
ret = BIO_new(BIO_s_accept());
if (ret == NULL)
return (NULL);
- if (BIO_set_accept_name(ret, str))
+ if (BIO_set_accept_port(ret, str))
return (ret);
- BIO_free(ret);
- return (NULL);
+ else {
+ BIO_free(ret);
+ return (NULL);
+ }
}
#endif
diff --git a/Cryptlib/OpenSSL/crypto/bio/bss_bio.c b/Cryptlib/OpenSSL/crypto/bio/bss_bio.c
index de34f6bf..3dd81877 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bss_bio.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bss_bio.c
@@ -1,10 +1,56 @@
-/*
- * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bss_bio.c */
+/* ====================================================================
+ * Copyright (c) 1998-2003 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.
+ *
+ * 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).
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
*/
/*
@@ -15,17 +61,39 @@
* See ssl/ssltest.c for some hints on how this can be used.
*/
+/* BIO_DEBUG implies BIO_PAIR_DEBUG */
+#ifdef BIO_DEBUG
+# ifndef BIO_PAIR_DEBUG
+# define BIO_PAIR_DEBUG
+# endif
+#endif
+
+/* disable assert() unless BIO_PAIR_DEBUG has been defined */
+#ifndef BIO_PAIR_DEBUG
+# ifndef NDEBUG
+# define NDEBUG
+# endif
+#endif
+
#include <assert.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
-#include "bio_lcl.h"
+#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/crypto.h>
#include "e_os.h"
+/* VxWorks defines SSIZE_MAX with an empty value causing compile errors */
+#if defined(OPENSSL_SYS_VXWORKS)
+# undef SSIZE_MAX
+#endif
+#ifndef SSIZE_MAX
+# define SSIZE_MAX INT_MAX
+#endif
+
static int bio_new(BIO *bio);
static int bio_free(BIO *bio);
static int bio_read(BIO *bio, char *buf, int size);
@@ -36,7 +104,7 @@ static int bio_puts(BIO *bio, const char *str);
static int bio_make_pair(BIO *bio1, BIO *bio2);
static void bio_destroy_pair(BIO *bio);
-static const BIO_METHOD methods_biop = {
+static BIO_METHOD methods_biop = {
BIO_TYPE_BIO,
"BIO pair",
bio_write,
@@ -49,7 +117,7 @@ static const BIO_METHOD methods_biop = {
NULL /* no bio_callback_ctrl */
};
-const BIO_METHOD *BIO_s_bio(void)
+BIO_METHOD *BIO_s_bio(void)
{
return &methods_biop;
}
@@ -74,13 +142,20 @@ struct bio_bio_st {
static int bio_new(BIO *bio)
{
- struct bio_bio_st *b = OPENSSL_zalloc(sizeof(*b));
+ struct bio_bio_st *b;
+ b = OPENSSL_malloc(sizeof *b);
if (b == NULL)
return 0;
+ b->peer = NULL;
+ b->closed = 0;
+ b->len = 0;
+ b->offset = 0;
/* enough for one TLS record (just a default) */
b->size = 17 * 1024;
+ b->buf = NULL;
+ b->request = 0;
bio->ptr = b;
return 1;
@@ -99,7 +174,10 @@ static int bio_free(BIO *bio)
if (b->peer)
bio_destroy_pair(bio);
- OPENSSL_free(b->buf);
+ if (b->buf != NULL) {
+ OPENSSL_free(b->buf);
+ }
+
OPENSSL_free(b);
return 1;
@@ -238,8 +316,8 @@ static ossl_ssize_t bio_nread(BIO *bio, char **buf, size_t num_)
struct bio_bio_st *b, *peer_b;
ossl_ssize_t num, available;
- if (num_ > OSSL_SSIZE_MAX)
- num = OSSL_SSIZE_MAX;
+ if (num_ > SSIZE_MAX)
+ num = SSIZE_MAX;
else
num = (ossl_ssize_t) num_;
@@ -394,8 +472,8 @@ static ossl_ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_)
struct bio_bio_st *b;
ossl_ssize_t num, space;
- if (num_ > OSSL_SSIZE_MAX)
- num = OSSL_SSIZE_MAX;
+ if (num_ > SSIZE_MAX)
+ num = SSIZE_MAX;
else
num = (ossl_ssize_t) num_;
@@ -433,8 +511,10 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
size_t new_size = num;
if (b->size != new_size) {
- OPENSSL_free(b->buf);
- b->buf = NULL;
+ if (b->buf) {
+ OPENSSL_free(b->buf);
+ b->buf = NULL;
+ }
b->size = new_size;
}
ret = 1;
@@ -711,10 +791,14 @@ int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
err:
if (ret == 0) {
- BIO_free(bio1);
- bio1 = NULL;
- BIO_free(bio2);
- bio2 = NULL;
+ if (bio1) {
+ BIO_free(bio1);
+ bio1 = NULL;
+ }
+ if (bio2) {
+ BIO_free(bio2);
+ bio2 = NULL;
+ }
}
*bio1_p = bio1;
diff --git a/Cryptlib/OpenSSL/crypto/bio/bss_conn.c b/Cryptlib/OpenSSL/crypto/bio/bss_conn.c
index dfd0988d..7d15ad29 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bss_conn.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bss_conn.c
@@ -1,28 +1,88 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bss_conn.c */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
#include <stdio.h>
#include <errno.h>
-
-#include "bio_lcl.h"
+#define USE_SOCKETS
+#include "cryptlib.h"
+#include <openssl/bio.h>
#ifndef OPENSSL_NO_SOCK
+# ifdef OPENSSL_SYS_WIN16
+# define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
+# else
+# define SOCKET_PROTOCOL IPPROTO_TCP
+# endif
+
+# if (defined(OPENSSL_SYS_VMS) && __VMS_VER < 70000000)
+/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
+# undef FIONBIO
+# endif
+
typedef struct bio_connect_st {
int state;
- int connect_family;
char *param_hostname;
- char *param_service;
- int connect_mode;
-
- BIO_ADDRINFO *addr_first;
- const BIO_ADDRINFO *addr_iter;
+ char *param_port;
+ int nbio;
+ unsigned char ip[4];
+ unsigned short port;
+ struct sockaddr_in them;
/*
* int socket; this will be kept in bio->num so that it is compatible
* with the bss_sock bio
@@ -48,14 +108,7 @@ static void conn_close_socket(BIO *data);
BIO_CONNECT *BIO_CONNECT_new(void);
void BIO_CONNECT_free(BIO_CONNECT *a);
-#define BIO_CONN_S_BEFORE 1
-#define BIO_CONN_S_GET_ADDR 2
-#define BIO_CONN_S_CREATE_SOCKET 3
-#define BIO_CONN_S_CONNECT 4
-#define BIO_CONN_S_OK 5
-#define BIO_CONN_S_BLOCKED_CONNECT 6
-
-static const BIO_METHOD methods_connectp = {
+static BIO_METHOD methods_connectp = {
BIO_TYPE_CONNECT,
"socket connect",
conn_write,
@@ -71,6 +124,8 @@ static const BIO_METHOD methods_connectp = {
static int conn_state(BIO *b, BIO_CONNECT *c)
{
int ret = -1, i;
+ unsigned long l;
+ char *p, *q;
int (*cb) (const BIO *, int, int) = NULL;
if (c->info_callback != NULL)
@@ -79,103 +134,123 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
for (;;) {
switch (c->state) {
case BIO_CONN_S_BEFORE:
- if (c->param_hostname == NULL && c->param_service == NULL) {
- BIOerr(BIO_F_CONN_STATE, BIO_R_NO_HOSTNAME_OR_SERVICE_SPECIFIED);
- ERR_add_error_data(4,
- "hostname=", c->param_hostname,
- " service=", c->param_service);
+ p = c->param_hostname;
+ if (p == NULL) {
+ BIOerr(BIO_F_CONN_STATE, BIO_R_NO_HOSTNAME_SPECIFIED);
goto exit_loop;
}
- c->state = BIO_CONN_S_GET_ADDR;
- break;
-
- case BIO_CONN_S_GET_ADDR:
- {
- int family = AF_UNSPEC;
- switch (c->connect_family) {
- case BIO_FAMILY_IPV6:
- if (1) { /* This is a trick we use to avoid bit rot.
- * at least the "else" part will always be
- * compiled.
- */
-#ifdef AF_INET6
- family = AF_INET6;
- } else {
-#endif
- BIOerr(BIO_F_CONN_STATE, BIO_R_UNAVAILABLE_IP_FAMILY);
- goto exit_loop;
- }
- break;
- case BIO_FAMILY_IPV4:
- family = AF_INET;
+ for (; *p != '\0'; p++) {
+ if ((*p == ':') || (*p == '/'))
break;
- case BIO_FAMILY_IPANY:
- family = AF_UNSPEC;
- break;
- default:
- BIOerr(BIO_F_CONN_STATE, BIO_R_UNSUPPORTED_IP_FAMILY);
- goto exit_loop;
+ }
+
+ i = *p;
+ if ((i == ':') || (i == '/')) {
+
+ *(p++) = '\0';
+ if (i == ':') {
+ for (q = p; *q; q++)
+ if (*q == '/') {
+ *q = '\0';
+ break;
+ }
+ if (c->param_port != NULL)
+ OPENSSL_free(c->param_port);
+ c->param_port = BUF_strdup(p);
}
- if (BIO_lookup(c->param_hostname, c->param_service,
- BIO_LOOKUP_CLIENT,
- family, SOCK_STREAM, &c->addr_first) == 0)
- goto exit_loop;
}
- if (c->addr_first == NULL) {
- BIOerr(BIO_F_CONN_STATE, BIO_R_LOOKUP_RETURNED_NOTHING);
+
+ if (c->param_port == NULL) {
+ BIOerr(BIO_F_CONN_STATE, BIO_R_NO_PORT_SPECIFIED);
+ ERR_add_error_data(2, "host=", c->param_hostname);
goto exit_loop;
}
- c->addr_iter = c->addr_first;
+ c->state = BIO_CONN_S_GET_IP;
+ break;
+
+ case BIO_CONN_S_GET_IP:
+ if (BIO_get_host_ip(c->param_hostname, &(c->ip[0])) <= 0)
+ goto exit_loop;
+ c->state = BIO_CONN_S_GET_PORT;
+ break;
+
+ case BIO_CONN_S_GET_PORT:
+ if (c->param_port == NULL) {
+ /* abort(); */
+ goto exit_loop;
+ } else if (BIO_get_port(c->param_port, &c->port) <= 0)
+ goto exit_loop;
c->state = BIO_CONN_S_CREATE_SOCKET;
break;
case BIO_CONN_S_CREATE_SOCKET:
- ret = BIO_socket(BIO_ADDRINFO_family(c->addr_iter),
- BIO_ADDRINFO_socktype(c->addr_iter),
- BIO_ADDRINFO_protocol(c->addr_iter), 0);
- if (ret == (int)INVALID_SOCKET) {
+ /* now setup address */
+ memset((char *)&c->them, 0, sizeof(c->them));
+ c->them.sin_family = AF_INET;
+ c->them.sin_port = htons((unsigned short)c->port);
+ l = (unsigned long)
+ ((unsigned long)c->ip[0] << 24L) |
+ ((unsigned long)c->ip[1] << 16L) |
+ ((unsigned long)c->ip[2] << 8L) | ((unsigned long)c->ip[3]);
+ c->them.sin_addr.s_addr = htonl(l);
+ c->state = BIO_CONN_S_CREATE_SOCKET;
+
+ ret = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL);
+ if (ret == INVALID_SOCKET) {
SYSerr(SYS_F_SOCKET, get_last_socket_error());
- ERR_add_error_data(4,
- "hostname=", c->param_hostname,
- " service=", c->param_service);
+ ERR_add_error_data(4, "host=", c->param_hostname,
+ ":", c->param_port);
BIOerr(BIO_F_CONN_STATE, BIO_R_UNABLE_TO_CREATE_SOCKET);
goto exit_loop;
}
b->num = ret;
+ c->state = BIO_CONN_S_NBIO;
+ break;
+
+ case BIO_CONN_S_NBIO:
+ if (c->nbio) {
+ if (!BIO_socket_nbio(b->num, 1)) {
+ BIOerr(BIO_F_CONN_STATE, BIO_R_ERROR_SETTING_NBIO);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":", c->param_port);
+ goto exit_loop;
+ }
+ }
c->state = BIO_CONN_S_CONNECT;
+
+# if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
+ i = 1;
+ i = setsockopt(b->num, SOL_SOCKET, SO_KEEPALIVE, (char *)&i,
+ sizeof(i));
+ if (i < 0) {
+ SYSerr(SYS_F_SOCKET, get_last_socket_error());
+ ERR_add_error_data(4, "host=", c->param_hostname,
+ ":", c->param_port);
+ BIOerr(BIO_F_CONN_STATE, BIO_R_KEEPALIVE);
+ goto exit_loop;
+ }
+# endif
break;
case BIO_CONN_S_CONNECT:
BIO_clear_retry_flags(b);
- ret = BIO_connect(b->num, BIO_ADDRINFO_address(c->addr_iter),
- BIO_SOCK_KEEPALIVE | c->connect_mode);
+ ret = connect(b->num,
+ (struct sockaddr *)&c->them, sizeof(c->them));
b->retry_reason = 0;
- if (ret == 0) {
+ if (ret < 0) {
if (BIO_sock_should_retry(ret)) {
BIO_set_retry_special(b);
c->state = BIO_CONN_S_BLOCKED_CONNECT;
b->retry_reason = BIO_RR_CONNECT;
- ERR_clear_error();
- } else if ((c->addr_iter = BIO_ADDRINFO_next(c->addr_iter))
- != NULL) {
- /*
- * if there are more addresses to try, do that first
- */
- BIO_closesocket(b->num);
- c->state = BIO_CONN_S_CREATE_SOCKET;
- ERR_clear_error();
- break;
} else {
SYSerr(SYS_F_CONNECT, get_last_socket_error());
- ERR_add_error_data(4,
- "hostname=", c->param_hostname,
- " service=", c->param_service);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":", c->param_port);
BIOerr(BIO_F_CONN_STATE, BIO_R_CONNECT_ERROR);
}
goto exit_loop;
- } else {
+ } else
c->state = BIO_CONN_S_OK;
- }
break;
case BIO_CONN_S_BLOCKED_CONNECT:
@@ -183,9 +258,8 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
if (i) {
BIO_clear_retry_flags(b);
SYSerr(SYS_F_CONNECT, i);
- ERR_add_error_data(4,
- "hostname=", c->param_hostname,
- " service=", c->param_service);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":", c->param_port);
BIOerr(BIO_F_CONN_STATE, BIO_R_NBIO_CONNECT_ERROR);
ret = 0;
goto exit_loop;
@@ -202,7 +276,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
}
if (cb != NULL) {
- if ((ret = cb((BIO *)b, c->state, ret)) == 0)
+ if (!(ret = cb((BIO *)b, c->state, ret)))
goto end;
}
}
@@ -219,10 +293,19 @@ BIO_CONNECT *BIO_CONNECT_new(void)
{
BIO_CONNECT *ret;
- if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
+ if ((ret = (BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL)
return (NULL);
ret->state = BIO_CONN_S_BEFORE;
- ret->connect_family = BIO_FAMILY_IPANY;
+ ret->param_hostname = NULL;
+ ret->param_port = NULL;
+ ret->info_callback = NULL;
+ ret->nbio = 0;
+ ret->ip[0] = 0;
+ ret->ip[1] = 0;
+ ret->ip[2] = 0;
+ ret->ip[3] = 0;
+ ret->port = 0;
+ memset((char *)&ret->them, 0, sizeof(ret->them));
return (ret);
}
@@ -231,13 +314,14 @@ void BIO_CONNECT_free(BIO_CONNECT *a)
if (a == NULL)
return;
- OPENSSL_free(a->param_hostname);
- OPENSSL_free(a->param_service);
- BIO_ADDRINFO_free(a->addr_first);
+ if (a->param_hostname != NULL)
+ OPENSSL_free(a->param_hostname);
+ if (a->param_port != NULL)
+ OPENSSL_free(a->param_port);
OPENSSL_free(a);
}
-const BIO_METHOD *BIO_s_connect(void)
+BIO_METHOD *BIO_s_connect(void)
{
return (&methods_connectp);
}
@@ -245,7 +329,7 @@ const BIO_METHOD *BIO_s_connect(void)
static int conn_new(BIO *bi)
{
bi->init = 0;
- bi->num = (int)INVALID_SOCKET;
+ bi->num = INVALID_SOCKET;
bi->flags = 0;
if ((bi->ptr = (char *)BIO_CONNECT_new()) == NULL)
return (0);
@@ -258,12 +342,12 @@ static void conn_close_socket(BIO *bio)
BIO_CONNECT *c;
c = (BIO_CONNECT *)bio->ptr;
- if (bio->num != (int)INVALID_SOCKET) {
+ if (bio->num != INVALID_SOCKET) {
/* Only do a shutdown if things were established */
if (c->state == BIO_CONN_S_OK)
shutdown(bio->num, 2);
- BIO_closesocket(bio->num);
- bio->num = (int)INVALID_SOCKET;
+ closesocket(bio->num);
+ bio->num = INVALID_SOCKET;
}
}
@@ -346,8 +430,6 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
ret = 0;
data->state = BIO_CONN_S_BEFORE;
conn_close_socket(b);
- BIO_ADDRINFO_free(data->addr_first);
- data->addr_first = NULL;
b->flags = 0;
break;
case BIO_C_DO_STATE_MACHINE:
@@ -360,33 +442,27 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_C_GET_CONNECT:
if (ptr != NULL) {
pptr = (const char **)ptr;
- if (num == 0) {
- *pptr = data->param_hostname;
- } else if (num == 1) {
- *pptr = data->param_service;
- } else if (num == 2) {
- *pptr = (const char *)BIO_ADDRINFO_address(data->addr_iter);
- } else if (num == 3) {
- switch (BIO_ADDRINFO_family(data->addr_iter)) {
-# ifdef AF_INET6
- case AF_INET6:
- ret = BIO_FAMILY_IPV6;
- break;
-# endif
- case AF_INET:
- ret = BIO_FAMILY_IPV4;
- break;
- case 0:
- ret = data->connect_family;
- break;
- default:
- ret = -1;
- break;
+ }
+
+ if (b->init) {
+ if (pptr != NULL) {
+ ret = 1;
+ if (num == 0) {
+ *pptr = data->param_hostname;
+ } else if (num == 1) {
+ *pptr = data->param_port;
+ } else if (num == 2) {
+ *pptr = (char *)&(data->ip[0]);
+ } else {
+ ret = 0;
}
- } else {
- ret = 0;
+ }
+ if (num == 3) {
+ ret = data->port;
}
} else {
+ if (pptr != NULL)
+ *pptr = "not initialized";
ret = 0;
}
break;
@@ -394,46 +470,36 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
if (ptr != NULL) {
b->init = 1;
if (num == 0) {
- char *hold_service = data->param_service;
- /* We affect the hostname regardless. However, the input
- * string might contain a host:service spec, so we must
- * parse it, which might or might not affect the service
- */
- OPENSSL_free(data->param_hostname);
- data->param_hostname = NULL;
- ret = BIO_parse_hostserv(ptr,
- &data->param_hostname,
- &data->param_service,
- BIO_PARSE_PRIO_HOST);
- if (hold_service != data->param_service)
- OPENSSL_free(hold_service);
+ if (data->param_hostname != NULL)
+ OPENSSL_free(data->param_hostname);
+ data->param_hostname = BUF_strdup(ptr);
} else if (num == 1) {
- OPENSSL_free(data->param_service);
- data->param_service = BUF_strdup(ptr);
+ if (data->param_port != NULL)
+ OPENSSL_free(data->param_port);
+ data->param_port = BUF_strdup(ptr);
} else if (num == 2) {
- const BIO_ADDR *addr = (const BIO_ADDR *)ptr;
- if (ret) {
- data->param_hostname = BIO_ADDR_hostname_string(addr, 1);
- data->param_service = BIO_ADDR_service_string(addr, 1);
- BIO_ADDRINFO_free(data->addr_first);
- data->addr_first = NULL;
- data->addr_iter = NULL;
- }
+ char buf[16];
+ unsigned char *p = ptr;
+
+ BIO_snprintf(buf, sizeof buf, "%d.%d.%d.%d",
+ p[0], p[1], p[2], p[3]);
+ if (data->param_hostname != NULL)
+ OPENSSL_free(data->param_hostname);
+ data->param_hostname = BUF_strdup(buf);
+ memcpy(&(data->ip[0]), ptr, 4);
} else if (num == 3) {
- data->connect_family = *(int *)ptr;
- } else {
- ret = 0;
+ char buf[DECIMAL_SIZE(int) + 1];
+
+ BIO_snprintf(buf, sizeof buf, "%d", *(int *)ptr);
+ if (data->param_port != NULL)
+ OPENSSL_free(data->param_port);
+ data->param_port = BUF_strdup(buf);
+ data->port = *(int *)ptr;
}
}
break;
case BIO_C_SET_NBIO:
- if (num != 0)
- data->connect_mode |= BIO_SOCK_NONBLOCK;
- else
- data->connect_mode &= ~BIO_SOCK_NONBLOCK;
- break;
- case BIO_C_SET_CONNECT_MODE:
- data->connect_mode = (int)num;
+ data->nbio = (int)num;
break;
case BIO_C_GET_FD:
if (b->init) {
@@ -459,12 +525,11 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_CTRL_DUP:
{
dbio = (BIO *)ptr;
+ if (data->param_port)
+ BIO_set_conn_port(dbio, data->param_port);
if (data->param_hostname)
BIO_set_conn_hostname(dbio, data->param_hostname);
- if (data->param_service)
- BIO_set_conn_port(dbio, data->param_service);
- BIO_set_conn_ip_family(dbio, data->connect_family);
- BIO_set_conn_mode(dbio, data->connect_mode);
+ BIO_set_nbio(dbio, data->nbio);
/*
* FIXME: the cast of the function seems unlikely to be a good
* idea
@@ -538,8 +603,10 @@ BIO *BIO_new_connect(const char *str)
return (NULL);
if (BIO_set_conn_hostname(ret, str))
return (ret);
- BIO_free(ret);
- return (NULL);
+ else {
+ BIO_free(ret);
+ return (NULL);
+ }
}
#endif
diff --git a/Cryptlib/OpenSSL/crypto/bio/bss_dgram.c b/Cryptlib/OpenSSL/crypto/bio/bss_dgram.c
index 6dfcc9ba..bdd7bf88 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bss_dgram.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bss_dgram.c
@@ -1,21 +1,70 @@
+/* crypto/bio/bio_dgram.c */
/*
- * Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * DTLS implementation written by Nagendra Modadugu
+ * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
+ */
+/* ====================================================================
+ * Copyright (c) 1999-2005 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.
+ *
+ * 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).
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include <errno.h>
+#define USE_SOCKETS
+#include "cryptlib.h"
-#include "bio_lcl.h"
+#include <openssl/bio.h>
#ifndef OPENSSL_NO_DGRAM
-# if !(defined(_WIN32) || defined(OPENSSL_SYS_VMS))
-# include <sys/time.h>
-# endif
# if defined(OPENSSL_SYS_VMS)
# include <sys/timeb.h>
# endif
@@ -45,6 +94,12 @@
((a)->s6_addr32[2] == htonl(0x0000ffff)))
# endif
+# ifdef WATT32
+# define sock_write SockWrite /* Watt-32 uses same names */
+# define sock_read SockRead
+# define sock_puts SockPuts
+# endif
+
static int dgram_write(BIO *h, const char *buf, int num);
static int dgram_read(BIO *h, char *buf, int size);
static int dgram_puts(BIO *h, const char *str);
@@ -70,7 +125,7 @@ static int BIO_dgram_should_retry(int s);
static void get_current_time(struct timeval *t);
-static const BIO_METHOD methods_dgramp = {
+static BIO_METHOD methods_dgramp = {
BIO_TYPE_DGRAM,
"datagram socket",
dgram_write,
@@ -84,7 +139,7 @@ static const BIO_METHOD methods_dgramp = {
};
# ifndef OPENSSL_NO_SCTP
-static const BIO_METHOD methods_dgramp_sctp = {
+static BIO_METHOD methods_dgramp_sctp = {
BIO_TYPE_DGRAM_SCTP,
"datagram sctp socket",
dgram_sctp_write,
@@ -99,13 +154,18 @@ static const BIO_METHOD methods_dgramp_sctp = {
# endif
typedef struct bio_dgram_data_st {
- BIO_ADDR peer;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sa_in;
+# if OPENSSL_USE_IPV6
+ struct sockaddr_in6 sa_in6;
+# endif
+ } peer;
unsigned int connected;
unsigned int _errno;
unsigned int mtu;
struct timeval next_timeout;
struct timeval socket_timeout;
- unsigned int peekmode;
} bio_dgram_data;
# ifndef OPENSSL_NO_SCTP
@@ -116,7 +176,13 @@ typedef struct bio_dgram_sctp_save_message_st {
} bio_dgram_sctp_save_message;
typedef struct bio_dgram_sctp_data_st {
- BIO_ADDR peer;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sa_in;
+# if OPENSSL_USE_IPV6
+ struct sockaddr_in6 sa_in6;
+# endif
+ } peer;
unsigned int connected;
unsigned int _errno;
unsigned int mtu;
@@ -134,7 +200,7 @@ typedef struct bio_dgram_sctp_data_st {
} bio_dgram_sctp_data;
# endif
-const BIO_METHOD *BIO_s_datagram(void)
+BIO_METHOD *BIO_s_datagram(void)
{
return (&methods_dgramp);
}
@@ -152,11 +218,17 @@ BIO *BIO_new_dgram(int fd, int close_flag)
static int dgram_new(BIO *bi)
{
- bio_dgram_data *data = OPENSSL_zalloc(sizeof(*data));
+ bio_dgram_data *data = NULL;
+ bi->init = 0;
+ bi->num = 0;
+ data = OPENSSL_malloc(sizeof(bio_dgram_data));
if (data == NULL)
return 0;
+ memset(data, 0x00, sizeof(bio_dgram_data));
bi->ptr = data;
+
+ bi->flags = 0;
return (1);
}
@@ -170,7 +242,8 @@ static int dgram_free(BIO *a)
return 0;
data = (bio_dgram_data *)a->ptr;
- OPENSSL_free(data);
+ if (data != NULL)
+ OPENSSL_free(data);
return (1);
}
@@ -181,7 +254,7 @@ static int dgram_clear(BIO *a)
return (0);
if (a->shutdown) {
if (a->init) {
- BIO_closesocket(a->num);
+ SHUTDOWN2(a->num);
}
a->init = 0;
a->flags = 0;
@@ -244,7 +317,7 @@ static void dgram_adjust_rcv_timeout(BIO *b)
}
/*
- * Adjust socket timeout if next handshake message timer will expire
+ * Adjust socket timeout if next handhake message timer will expire
* earlier.
*/
if ((data->socket_timeout.tv_sec == 0
@@ -298,22 +371,39 @@ static int dgram_read(BIO *b, char *out, int outl)
{
int ret = 0;
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
- int flags = 0;
- BIO_ADDR peer;
- socklen_t len = sizeof(peer);
+ struct {
+ /*
+ * See commentary in b_sock.c. <appro>
+ */
+ union {
+ size_t s;
+ int i;
+ } len;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sa_in;
+# if OPENSSL_USE_IPV6
+ struct sockaddr_in6 sa_in6;
+# endif
+ } peer;
+ } sa;
+
+ sa.len.s = 0;
+ sa.len.i = sizeof(sa.peer);
if (out != NULL) {
clear_socket_error();
- memset(&peer, 0, sizeof(peer));
+ memset(&sa.peer, 0x00, sizeof(sa.peer));
dgram_adjust_rcv_timeout(b);
- if (data->peekmode)
- flags = MSG_PEEK;
- ret = recvfrom(b->num, out, outl, flags,
- BIO_ADDR_sockaddr_noconst(&peer), &len);
+ ret = recvfrom(b->num, out, outl, 0, &sa.peer.sa, (void *)&sa.len);
+ if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) {
+ OPENSSL_assert(sa.len.s <= sizeof(sa.peer));
+ sa.len.i = (int)sa.len.s;
+ }
if (!data->connected && ret >= 0)
- BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &peer);
+ BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &sa.peer);
BIO_clear_retry_flags(b);
if (ret < 0) {
@@ -337,14 +427,18 @@ static int dgram_write(BIO *b, const char *in, int inl)
if (data->connected)
ret = writesocket(b->num, in, inl);
else {
- int peerlen = BIO_ADDR_sockaddr_size(&data->peer);
+ int peerlen = sizeof(data->peer);
+ if (data->peer.sa.sa_family == AF_INET)
+ peerlen = sizeof(data->peer.sa_in);
+# if OPENSSL_USE_IPV6
+ else if (data->peer.sa.sa_family == AF_INET6)
+ peerlen = sizeof(data->peer.sa_in6);
+# endif
# if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK)
- ret = sendto(b->num, (char *)in, inl, 0,
- BIO_ADDR_sockaddr(&data->peer), peerlen);
+ ret = sendto(b->num, (char *)in, inl, 0, &data->peer.sa, peerlen);
# else
- ret = sendto(b->num, in, inl, 0,
- BIO_ADDR_sockaddr(&data->peer), peerlen);
+ ret = sendto(b->num, in, inl, 0, &data->peer.sa, peerlen);
# endif
}
@@ -353,6 +447,13 @@ static int dgram_write(BIO *b, const char *in, int inl)
if (BIO_dgram_should_retry(ret)) {
BIO_set_retry_write(b);
data->_errno = get_last_socket_error();
+
+# if 0 /* higher layers are responsible for querying
+ * MTU, if necessary */
+ if (data->_errno == EMSGSIZE)
+ /* retrieve the new MTU */
+ BIO_ctrl(b, BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL);
+# endif
}
}
return (ret);
@@ -362,31 +463,27 @@ static long dgram_get_mtu_overhead(bio_dgram_data *data)
{
long ret;
- switch (BIO_ADDR_family(&data->peer)) {
+ switch (data->peer.sa.sa_family) {
case AF_INET:
/*
* Assume this is UDP - 20 bytes for IP, 8 bytes for UDP
*/
ret = 28;
break;
-# ifdef AF_INET6
+# if OPENSSL_USE_IPV6
case AF_INET6:
- {
# ifdef IN6_IS_ADDR_V4MAPPED
- struct in6_addr tmp_addr;
- if (BIO_ADDR_rawaddress(&data->peer, &tmp_addr, NULL)
- && IN6_IS_ADDR_V4MAPPED(&tmp_addr))
- /*
- * Assume this is UDP - 20 bytes for IP, 8 bytes for UDP
- */
- ret = 28;
- else
+ if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr))
+ /*
+ * Assume this is UDP - 20 bytes for IP, 8 bytes for UDP
+ */
+ ret = 28;
+ else
# endif
/*
* Assume this is UDP - 40 bytes for IP, 8 bytes for UDP
*/
ret = 48;
- }
break;
# endif
default:
@@ -401,14 +498,20 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
{
long ret = 1;
int *ip;
+ struct sockaddr *to = NULL;
bio_dgram_data *data = NULL;
int sockopt_val = 0;
- int d_errno;
# if defined(OPENSSL_SYS_LINUX) && (defined(IP_MTU_DISCOVER) || defined(IP_MTU))
socklen_t sockopt_len; /* assume that system supporting IP_MTU is
* modern enough to define socklen_t */
socklen_t addr_len;
- BIO_ADDR addr;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in s4;
+# if OPENSSL_USE_IPV6
+ struct sockaddr_in6 s6;
+# endif
+ } addr;
# endif
data = (bio_dgram_data *)b->ptr;
@@ -451,13 +554,35 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
ret = 1;
break;
case BIO_CTRL_DGRAM_CONNECT:
- BIO_ADDR_make(&data->peer, BIO_ADDR_sockaddr((BIO_ADDR *)ptr));
+ to = (struct sockaddr *)ptr;
+# if 0
+ if (connect(b->num, to, sizeof(struct sockaddr)) < 0) {
+ perror("connect");
+ ret = 0;
+ } else {
+# endif
+ switch (to->sa_family) {
+ case AF_INET:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in));
+ break;
+# if OPENSSL_USE_IPV6
+ case AF_INET6:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in6));
+ break;
+# endif
+ default:
+ memcpy(&data->peer, to, sizeof(data->peer.sa));
+ break;
+ }
+# if 0
+ }
+# endif
break;
/* (Linux)kernel sets DF bit on outgoing IP packets */
case BIO_CTRL_DGRAM_MTU_DISCOVER:
# if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO)
addr_len = (socklen_t) sizeof(addr);
- memset(&addr, 0, sizeof(addr));
+ memset((void *)&addr, 0, sizeof(addr));
if (getsockname(b->num, &addr.sa, &addr_len) < 0) {
ret = 0;
break;
@@ -481,14 +606,14 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
ret = -1;
break;
}
-# else
ret = -1;
-# endif
+# else
break;
+# endif
case BIO_CTRL_DGRAM_QUERY_MTU:
# if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU)
addr_len = (socklen_t) sizeof(addr);
- memset(&addr, 0, sizeof(addr));
+ memset((void *)&addr, 0, sizeof(addr));
if (getsockname(b->num, &addr.sa, &addr_len) < 0) {
ret = 0;
break;
@@ -536,22 +661,18 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
break;
case BIO_CTRL_DGRAM_GET_FALLBACK_MTU:
ret = -dgram_get_mtu_overhead(data);
- switch (BIO_ADDR_family(&data->peer)) {
+ switch (data->peer.sa.sa_family) {
case AF_INET:
ret += 576;
break;
# if OPENSSL_USE_IPV6
case AF_INET6:
- {
# ifdef IN6_IS_ADDR_V4MAPPED
- struct in6_addr tmp_addr;
- if (BIO_ADDR_rawaddress(&data->peer, &tmp_addr, NULL)
- && IN6_IS_ADDR_V4MAPPED(&tmp_addr))
- ret += 576;
- else
+ if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr))
+ ret += 576;
+ else
# endif
- ret += 1280;
- }
+ ret += 1280;
break;
# endif
default:
@@ -561,29 +682,67 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
break;
case BIO_CTRL_DGRAM_GET_MTU:
return data->mtu;
+ break;
case BIO_CTRL_DGRAM_SET_MTU:
data->mtu = num;
ret = num;
break;
case BIO_CTRL_DGRAM_SET_CONNECTED:
- if (ptr != NULL) {
+ to = (struct sockaddr *)ptr;
+
+ if (to != NULL) {
data->connected = 1;
- BIO_ADDR_make(&data->peer, BIO_ADDR_sockaddr((BIO_ADDR *)ptr));
+ switch (to->sa_family) {
+ case AF_INET:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in));
+ break;
+# if OPENSSL_USE_IPV6
+ case AF_INET6:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in6));
+ break;
+# endif
+ default:
+ memcpy(&data->peer, to, sizeof(data->peer.sa));
+ break;
+ }
} else {
data->connected = 0;
- memset(&data->peer, 0, sizeof(data->peer));
+ memset(&(data->peer), 0x00, sizeof(data->peer));
}
break;
case BIO_CTRL_DGRAM_GET_PEER:
- ret = BIO_ADDR_sockaddr_size(&data->peer);
- /* FIXME: if num < ret, we will only return part of an address.
- That should bee an error, no? */
+ switch (data->peer.sa.sa_family) {
+ case AF_INET:
+ ret = sizeof(data->peer.sa_in);
+ break;
+# if OPENSSL_USE_IPV6
+ case AF_INET6:
+ ret = sizeof(data->peer.sa_in6);
+ break;
+# endif
+ default:
+ ret = sizeof(data->peer.sa);
+ break;
+ }
if (num == 0 || num > ret)
num = ret;
memcpy(ptr, &data->peer, (ret = num));
break;
case BIO_CTRL_DGRAM_SET_PEER:
- BIO_ADDR_make(&data->peer, BIO_ADDR_sockaddr((BIO_ADDR *)ptr));
+ to = (struct sockaddr *)ptr;
+ switch (to->sa_family) {
+ case AF_INET:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in));
+ break;
+# if OPENSSL_USE_IPV6
+ case AF_INET6:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in6));
+ break;
+# endif
+ default:
+ memcpy(&data->peer, to, sizeof(data->peer.sa));
+ break;
+ }
break;
case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT:
memcpy(&(data->next_timeout), ptr, sizeof(struct timeval));
@@ -706,11 +865,11 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
/* fall-through */
case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP:
# ifdef OPENSSL_SYS_WINDOWS
- d_errno = (data->_errno == WSAETIMEDOUT);
+ if (data->_errno == WSAETIMEDOUT)
# else
- d_errno = (data->_errno == EAGAIN);
+ if (data->_errno == EAGAIN)
# endif
- if (d_errno) {
+ {
ret = 1;
data->_errno = 0;
} else
@@ -783,9 +942,6 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_CTRL_DGRAM_GET_MTU_OVERHEAD:
ret = dgram_get_mtu_overhead(data);
break;
- case BIO_CTRL_DGRAM_SET_PEEK_MODE:
- data->peekmode = (unsigned int)num;
- break;
default:
ret = 0;
break;
@@ -803,7 +959,7 @@ static int dgram_puts(BIO *bp, const char *str)
}
# ifndef OPENSSL_NO_SCTP
-const BIO_METHOD *BIO_s_datagram_sctp(void)
+BIO_METHOD *BIO_s_datagram_sctp(void)
{
return (&methods_dgramp_sctp);
}
@@ -854,13 +1010,16 @@ BIO *BIO_new_dgram_sctp(int fd, int close_flag)
* connected socket won't use it.
*/
sockopt_len = (socklen_t) (sizeof(sctp_assoc_t) + 256 * sizeof(uint8_t));
- authchunks = OPENSSL_zalloc(sockopt_len);
- if (authchunks == NULL) {
+ authchunks = OPENSSL_malloc(sockopt_len);
+ if (!authchunks) {
BIO_vfree(bio);
return (NULL);
}
- ret = getsockopt(fd, IPPROTO_SCTP, SCTP_LOCAL_AUTH_CHUNKS, authchunks,
+ memset(authchunks, 0, sizeof(sockopt_len));
+ ret =
+ getsockopt(fd, IPPROTO_SCTP, SCTP_LOCAL_AUTH_CHUNKS, authchunks,
&sockopt_len);
+
if (ret < 0) {
OPENSSL_free(authchunks);
BIO_vfree(bio);
@@ -883,7 +1042,7 @@ BIO *BIO_new_dgram_sctp(int fd, int close_flag)
# ifdef SCTP_AUTHENTICATION_EVENT
# ifdef SCTP_EVENT
- memset(&event, 0, sizeof(event));
+ memset(&event, 0, sizeof(struct sctp_event));
event.se_assoc_id = 0;
event.se_type = SCTP_AUTHENTICATION_EVENT;
event.se_on = 1;
@@ -940,9 +1099,10 @@ static int dgram_sctp_new(BIO *bi)
bi->init = 0;
bi->num = 0;
- data = OPENSSL_zalloc(sizeof(*data));
+ data = OPENSSL_malloc(sizeof(bio_dgram_sctp_data));
if (data == NULL)
return 0;
+ memset(data, 0x00, sizeof(bio_dgram_sctp_data));
# ifdef SCTP_PR_SCTP_NONE
data->prinfo.pr_policy = SCTP_PR_SCTP_NONE;
# endif
@@ -963,7 +1123,8 @@ static int dgram_sctp_free(BIO *a)
data = (bio_dgram_sctp_data *) a->ptr;
if (data != NULL) {
- OPENSSL_free(data->saved_message.data);
+ if (data->saved_message.data != NULL)
+ OPENSSL_free(data->saved_message.data);
OPENSSL_free(data);
}
@@ -1003,7 +1164,8 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
clear_socket_error();
do {
- memset(&data->rcvinfo, 0, sizeof(data->rcvinfo));
+ memset(&data->rcvinfo, 0x00,
+ sizeof(struct bio_dgram_sctp_rcvinfo));
iov.iov_base = out;
iov.iov_len = outl;
msg.msg_name = NULL;
@@ -1072,13 +1234,9 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
* it can be sent now.
*/
if (data->saved_message.length > 0) {
- i = dgram_sctp_write(data->saved_message.bio,
+ dgram_sctp_write(data->saved_message.bio,
data->saved_message.data,
data->saved_message.length);
- if (i < 0) {
- ret = i;
- break;
- }
OPENSSL_free(data->saved_message.data);
data->saved_message.data = NULL;
data->saved_message.length = 0;
@@ -1086,7 +1244,7 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
/* disable sender dry event */
# ifdef SCTP_EVENT
- memset(&event, 0, sizeof(event));
+ memset(&event, 0, sizeof(struct sctp_event));
event.se_assoc_id = 0;
event.se_type = SCTP_SENDER_DRY_EVENT;
event.se_on = 0;
@@ -1192,11 +1350,11 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
optlen =
(socklen_t) (sizeof(sctp_assoc_t) + 256 * sizeof(uint8_t));
authchunks = OPENSSL_malloc(optlen);
- if (authchunks == NULL) {
+ if (!authchunks) {
BIOerr(BIO_F_DGRAM_SCTP_READ, ERR_R_MALLOC_FAILURE);
return -1;
}
- memset(authchunks, 0, optlen);
+ memset(authchunks, 0, sizeof(optlen));
ii = getsockopt(b->num, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS,
authchunks, &optlen);
@@ -1223,14 +1381,6 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
return (ret);
}
-/*
- * dgram_sctp_write - send message on SCTP socket
- * @b: BIO to write to
- * @in: data to send
- * @inl: amount of bytes in @in to send
- *
- * Returns -1 on error or the sent amount of bytes on success
- */
static int dgram_sctp_write(BIO *b, const char *in, int inl)
{
int ret;
@@ -1258,7 +1408,7 @@ static int dgram_sctp_write(BIO *b, const char *in, int inl)
* parameters and flags.
*/
if (in[0] != 23) {
- memset(&handshake_sinfo, 0, sizeof(handshake_sinfo));
+ memset(&handshake_sinfo, 0x00, sizeof(struct bio_dgram_sctp_sndinfo));
# ifdef SCTP_SACK_IMMEDIATELY
handshake_sinfo.snd_flags = SCTP_SACK_IMMEDIATELY;
# endif
@@ -1269,24 +1419,19 @@ static int dgram_sctp_write(BIO *b, const char *in, int inl)
* If we have to send a shutdown alert message and the socket is not dry
* yet, we have to save it and send it as soon as the socket gets dry.
*/
- if (data->save_shutdown) {
- ret = BIO_dgram_sctp_wait_for_dry(b);
- if (ret < 0) {
+ if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b)) {
+ char *tmp;
+ data->saved_message.bio = b;
+ if (!(tmp = OPENSSL_malloc(inl))) {
+ BIOerr(BIO_F_DGRAM_SCTP_WRITE, ERR_R_MALLOC_FAILURE);
return -1;
}
- if (ret == 0) {
- char *tmp;
- data->saved_message.bio = b;
- if ((tmp = OPENSSL_malloc(inl)) == NULL) {
- BIOerr(BIO_F_DGRAM_SCTP_WRITE, ERR_R_MALLOC_FAILURE);
- return -1;
- }
+ if (data->saved_message.data)
OPENSSL_free(data->saved_message.data);
- data->saved_message.data = tmp;
- memcpy(data->saved_message.data, in, inl);
- data->saved_message.length = inl;
- return inl;
- }
+ data->saved_message.data = tmp;
+ memcpy(data->saved_message.data, in, inl);
+ data->saved_message.length = inl;
+ return inl;
}
iov[0].iov_base = (char *)in;
@@ -1304,7 +1449,7 @@ static int dgram_sctp_write(BIO *b, const char *in, int inl)
cmsg->cmsg_type = SCTP_SNDINFO;
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndinfo));
sndinfo = (struct sctp_sndinfo *)CMSG_DATA(cmsg);
- memset(sndinfo, 0, sizeof(*sndinfo));
+ memset(sndinfo, 0, sizeof(struct sctp_sndinfo));
sndinfo->snd_sid = sinfo->snd_sid;
sndinfo->snd_flags = sinfo->snd_flags;
sndinfo->snd_ppid = sinfo->snd_ppid;
@@ -1317,7 +1462,7 @@ static int dgram_sctp_write(BIO *b, const char *in, int inl)
cmsg->cmsg_type = SCTP_PRINFO;
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_prinfo));
prinfo = (struct sctp_prinfo *)CMSG_DATA(cmsg);
- memset(prinfo, 0, sizeof(*prinfo));
+ memset(prinfo, 0, sizeof(struct sctp_prinfo));
prinfo->pr_policy = pinfo->pr_policy;
prinfo->pr_value = pinfo->pr_value;
msg.msg_controllen += CMSG_SPACE(sizeof(struct sctp_prinfo));
@@ -1327,7 +1472,7 @@ static int dgram_sctp_write(BIO *b, const char *in, int inl)
cmsg->cmsg_type = SCTP_SNDRCV;
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
sndrcvinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
- memset(sndrcvinfo, 0, sizeof(*sndrcvinfo));
+ memset(sndrcvinfo, 0, sizeof(struct sctp_sndrcvinfo));
sndrcvinfo->sinfo_stream = sinfo->snd_sid;
sndrcvinfo->sinfo_flags = sinfo->snd_flags;
# ifdef __FreeBSD__
@@ -1424,7 +1569,7 @@ static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr)
ret = -1;
break;
}
- memset(authkey, 0, sockopt_len);
+ memset(authkey, 0x00, sockopt_len);
authkey->sca_keynumber = authkeyid.scact_keynumber + 1;
# ifndef __FreeBSD__
/*
@@ -1604,24 +1749,10 @@ int BIO_dgram_sctp_notification_cb(BIO *b,
return 0;
}
-/*
- * BIO_dgram_sctp_wait_for_dry - Wait for SCTP SENDER_DRY event
- * @b: The BIO to check for the dry event
- *
- * Wait until the peer confirms all packets have been received, and so that
- * our kernel doesn't have anything to send anymore. This is only received by
- * the peer's kernel, not the application.
- *
- * Returns:
- * -1 on error
- * 0 when not dry yet
- * 1 when dry
- */
int BIO_dgram_sctp_wait_for_dry(BIO *b)
{
int is_dry = 0;
- int sockflags = 0;
- int n, ret;
+ int n, sockflags, ret;
union sctp_notification snp;
struct msghdr msg;
struct iovec iov;
@@ -1635,7 +1766,7 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b)
/* set sender dry event */
# ifdef SCTP_EVENT
- memset(&event, 0, sizeof(event));
+ memset(&event, 0, sizeof(struct sctp_event));
event.se_assoc_id = 0;
event.se_type = SCTP_SENDER_DRY_EVENT;
event.se_on = 1;
@@ -1658,7 +1789,7 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b)
return -1;
/* peek for notification */
- memset(&snp, 0, sizeof(snp));
+ memset(&snp, 0x00, sizeof(union sctp_notification));
iov.iov_base = (char *)&snp;
iov.iov_len = sizeof(union sctp_notification);
msg.msg_name = NULL;
@@ -1680,7 +1811,7 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b)
/* if we find a notification, process it and try again if necessary */
while (msg.msg_flags & MSG_NOTIFICATION) {
- memset(&snp, 0, sizeof(snp));
+ memset(&snp, 0x00, sizeof(union sctp_notification));
iov.iov_base = (char *)&snp;
iov.iov_len = sizeof(union sctp_notification);
msg.msg_name = NULL;
@@ -1705,7 +1836,7 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b)
/* disable sender dry event */
# ifdef SCTP_EVENT
- memset(&event, 0, sizeof(event));
+ memset(&event, 0, sizeof(struct sctp_event));
event.se_assoc_id = 0;
event.se_type = SCTP_SENDER_DRY_EVENT;
event.se_on = 0;
@@ -1739,7 +1870,7 @@ int BIO_dgram_sctp_wait_for_dry(BIO *b)
(void *)&snp);
/* found notification, peek again */
- memset(&snp, 0, sizeof(snp));
+ memset(&snp, 0x00, sizeof(union sctp_notification));
iov.iov_base = (char *)&snp;
iov.iov_len = sizeof(union sctp_notification);
msg.msg_name = NULL;
@@ -1785,7 +1916,7 @@ int BIO_dgram_sctp_msg_waiting(BIO *b)
/* Check if there are any messages waiting to be read */
do {
- memset(&snp, 0, sizeof(snp));
+ memset(&snp, 0x00, sizeof(union sctp_notification));
iov.iov_base = (char *)&snp;
iov.iov_len = sizeof(union sctp_notification);
msg.msg_name = NULL;
@@ -1808,7 +1939,7 @@ int BIO_dgram_sctp_msg_waiting(BIO *b)
dgram_sctp_handle_auth_free_key_event(b, &snp);
# endif
- memset(&snp, 0, sizeof(snp));
+ memset(&snp, 0x00, sizeof(union sctp_notification));
iov.iov_base = (char *)&snp;
iov.iov_len = sizeof(union sctp_notification);
msg.msg_name = NULL;
@@ -1871,6 +2002,12 @@ int BIO_dgram_non_fatal_error(int err)
# if defined(WSAEWOULDBLOCK)
case WSAEWOULDBLOCK:
# endif
+
+# if 0 /* This appears to always be an error */
+# if defined(WSAENOTCONN)
+ case WSAENOTCONN:
+# endif
+# endif
# endif
# ifdef EWOULDBLOCK
diff --git a/Cryptlib/OpenSSL/crypto/bio/bss_fd.c b/Cryptlib/OpenSSL/crypto/bio/bss_fd.c
index 1e56cb62..5f4e3448 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bss_fd.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bss_fd.c
@@ -1,16 +1,65 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bss_fd.c */
+/* 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)"
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
#include <stdio.h>
#include <errno.h>
-
-#include "bio_lcl.h"
+#define USE_SOCKETS
+#include "cryptlib.h"
#if defined(OPENSSL_NO_POSIX_IO)
/*
@@ -31,7 +80,7 @@ int BIO_fd_should_retry(int i)
return 0;
}
-const BIO_METHOD *BIO_s_fd(void)
+BIO_METHOD *BIO_s_fd(void)
{
return NULL;
}
@@ -48,6 +97,8 @@ const BIO_METHOD *BIO_s_fd(void)
* file descriptors can only be provided by application. Therefore
* "UPLINK" calls are due...
*/
+# include "bio_lcl.h"
+
static int fd_write(BIO *h, const char *buf, int num);
static int fd_read(BIO *h, char *buf, int size);
static int fd_puts(BIO *h, const char *str);
@@ -57,7 +108,7 @@ static int fd_new(BIO *h);
static int fd_free(BIO *data);
int BIO_fd_should_retry(int s);
-static const BIO_METHOD methods_fdp = {
+static BIO_METHOD methods_fdp = {
BIO_TYPE_FD, "file descriptor",
fd_write,
fd_read,
@@ -69,7 +120,7 @@ static const BIO_METHOD methods_fdp = {
NULL,
};
-const BIO_METHOD *BIO_s_fd(void)
+BIO_METHOD *BIO_s_fd(void)
{
return (&methods_fdp);
}
@@ -219,6 +270,12 @@ int BIO_fd_should_retry(int i)
if ((i == 0) || (i == -1)) {
err = get_last_sys_error();
+# if defined(OPENSSL_SYS_WINDOWS) && 0/* more microsoft stupidity? perhaps
+ * not? Ben 4/1/99 */
+ if ((i == -1) && (err == 0))
+ return (1);
+# endif
+
return (BIO_fd_non_fatal_error(err));
}
return (0);
diff --git a/Cryptlib/OpenSSL/crypto/bio/bss_file.c b/Cryptlib/OpenSSL/crypto/bio/bss_file.c
index 6af2d9cb..a6e3b3ac 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bss_file.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bss_file.c
@@ -1,10 +1,59 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bss_file.c */
+/* 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.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
/*-
@@ -36,19 +85,24 @@
# include <stdio.h>
# include <errno.h>
+# include "cryptlib.h"
# include "bio_lcl.h"
# include <openssl/err.h>
+# if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
+# include <nwfileio.h>
+# endif
+
# if !defined(OPENSSL_NO_STDIO)
-static int file_write(BIO *h, const char *buf, int num);
-static int file_read(BIO *h, char *buf, int size);
-static int file_puts(BIO *h, const char *str);
-static int file_gets(BIO *h, char *str, int size);
-static long file_ctrl(BIO *h, int cmd, long arg1, void *arg2);
-static int file_new(BIO *h);
-static int file_free(BIO *data);
-static const BIO_METHOD methods_filep = {
+static int MS_CALLBACK file_write(BIO *h, const char *buf, int num);
+static int MS_CALLBACK file_read(BIO *h, char *buf, int size);
+static int MS_CALLBACK file_puts(BIO *h, const char *str);
+static int MS_CALLBACK file_gets(BIO *h, char *str, int size);
+static long MS_CALLBACK file_ctrl(BIO *h, int cmd, long arg1, void *arg2);
+static int MS_CALLBACK file_new(BIO *h);
+static int MS_CALLBACK file_free(BIO *data);
+static BIO_METHOD methods_filep = {
BIO_TYPE_FILE,
"FILE pointer",
file_write,
@@ -61,14 +115,61 @@ static const BIO_METHOD methods_filep = {
NULL,
};
+static FILE *file_fopen(const char *filename, const char *mode)
+{
+ FILE *file = NULL;
+
+# if defined(_WIN32) && defined(CP_UTF8)
+ int sz, len_0 = (int)strlen(filename) + 1;
+ DWORD flags;
+
+ /*
+ * Basically there are three cases to cover: a) filename is
+ * pure ASCII string; b) actual UTF-8 encoded string and
+ * c) locale-ized string, i.e. one containing 8-bit
+ * characters that are meaningful in current system locale.
+ * If filename is pure ASCII or real UTF-8 encoded string,
+ * MultiByteToWideChar succeeds and _wfopen works. If
+ * filename is locale-ized string, chances are that
+ * MultiByteToWideChar fails reporting
+ * ERROR_NO_UNICODE_TRANSLATION, in which case we fall
+ * back to fopen...
+ */
+ if ((sz = MultiByteToWideChar(CP_UTF8, (flags = MB_ERR_INVALID_CHARS),
+ filename, len_0, NULL, 0)) > 0 ||
+ (GetLastError() == ERROR_INVALID_FLAGS &&
+ (sz = MultiByteToWideChar(CP_UTF8, (flags = 0),
+ filename, len_0, NULL, 0)) > 0)
+ ) {
+ WCHAR wmode[8];
+ WCHAR *wfilename = _alloca(sz * sizeof(WCHAR));
+
+ if (MultiByteToWideChar(CP_UTF8, flags,
+ filename, len_0, wfilename, sz) &&
+ MultiByteToWideChar(CP_UTF8, 0, mode, strlen(mode) + 1,
+ wmode, sizeof(wmode) / sizeof(wmode[0])) &&
+ (file = _wfopen(wfilename, wmode)) == NULL &&
+ (errno == ENOENT || errno == EBADF)
+ ) {
+ /*
+ * UTF-8 decode succeeded, but no file, filename
+ * could still have been locale-ized...
+ */
+ file = fopen(filename, mode);
+ }
+ } else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) {
+ file = fopen(filename, mode);
+ }
+# else
+ file = fopen(filename, mode);
+# endif
+ return (file);
+}
+
BIO *BIO_new_file(const char *filename, const char *mode)
{
BIO *ret;
- FILE *file = openssl_fopen(filename, mode);
- int fp_flags = BIO_CLOSE;
-
- if (strchr(mode, 'b') == NULL)
- fp_flags |= BIO_FP_TEXT;
+ FILE *file = file_fopen(filename, mode);
if (file == NULL) {
SYSerr(SYS_F_FOPEN, get_last_sys_error());
@@ -90,7 +191,7 @@ BIO *BIO_new_file(const char *filename, const char *mode)
BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage
* UPLINK */
- BIO_set_fp(ret, file, fp_flags);
+ BIO_set_fp(ret, file, BIO_CLOSE);
return (ret);
}
@@ -101,18 +202,18 @@ BIO *BIO_new_fp(FILE *stream, int close_flag)
if ((ret = BIO_new(BIO_s_file())) == NULL)
return (NULL);
- /* redundant flag, left for documentation purposes */
- BIO_set_flags(ret, BIO_FLAGS_UPLINK);
+ BIO_set_flags(ret, BIO_FLAGS_UPLINK); /* redundant, left for
+ * documentation puposes */
BIO_set_fp(ret, stream, close_flag);
return (ret);
}
-const BIO_METHOD *BIO_s_file(void)
+BIO_METHOD *BIO_s_file(void)
{
return (&methods_filep);
}
-static int file_new(BIO *bi)
+static int MS_CALLBACK file_new(BIO *bi)
{
bi->init = 0;
bi->num = 0;
@@ -121,7 +222,7 @@ static int file_new(BIO *bi)
return (1);
}
-static int file_free(BIO *a)
+static int MS_CALLBACK file_free(BIO *a)
{
if (a == NULL)
return (0);
@@ -139,7 +240,7 @@ static int file_free(BIO *a)
return (1);
}
-static int file_read(BIO *b, char *out, int outl)
+static int MS_CALLBACK file_read(BIO *b, char *out, int outl)
{
int ret = 0;
@@ -150,7 +251,7 @@ static int file_read(BIO *b, char *out, int outl)
ret = fread(out, 1, (int)outl, (FILE *)b->ptr);
if (ret == 0
&& (b->flags & BIO_FLAGS_UPLINK) ? UP_ferror((FILE *)b->ptr) :
- ferror((FILE *)b->ptr)) {
+ ferror((FILE *)b->ptr)) {
SYSerr(SYS_F_FREAD, get_last_sys_error());
BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB);
ret = -1;
@@ -159,7 +260,7 @@ static int file_read(BIO *b, char *out, int outl)
return (ret);
}
-static int file_write(BIO *b, const char *in, int inl)
+static int MS_CALLBACK file_write(BIO *b, const char *in, int inl)
{
int ret = 0;
@@ -180,7 +281,7 @@ static int file_write(BIO *b, const char *in, int inl)
return (ret);
}
-static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
+static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
{
long ret = 1;
FILE *fp = (FILE *)b->ptr;
@@ -217,11 +318,8 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
# if defined(__MINGW32__) && defined(__MSVCRT__) && !defined(_IOB_ENTRIES)
# define _IOB_ENTRIES 20
# endif
+# if defined(_IOB_ENTRIES)
/* Safety net to catch purely internal BIO_set_fp calls */
-# if defined(_MSC_VER) && _MSC_VER>=1900
- if (ptr == stdin || ptr == stdout || ptr == stderr)
- BIO_clear_flags(b, BIO_FLAGS_UPLINK);
-# elif defined(_IOB_ENTRIES)
if ((size_t)ptr >= (size_t)stdin &&
(size_t)ptr < (size_t)(stdin + _IOB_ENTRIES))
BIO_clear_flags(b, BIO_FLAGS_UPLINK);
@@ -239,6 +337,13 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
_setmode(fd, _O_TEXT);
else
_setmode(fd, _O_BINARY);
+# elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
+ int fd = fileno((FILE *)ptr);
+ /* Under CLib there are differences in file modes */
+ if (num & BIO_FP_TEXT)
+ setmode(fd, O_TEXT);
+ else
+ setmode(fd, O_BINARY);
# elif defined(OPENSSL_SYS_MSDOS)
int fd = fileno((FILE *)ptr);
/* Set correct text/binary mode */
@@ -252,7 +357,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
} else
_setmode(fd, _O_BINARY);
}
-# elif defined(OPENSSL_SYS_WIN32_CYGWIN)
+# elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN)
int fd = fileno((FILE *)ptr);
if (num & BIO_FP_TEXT)
setmode(fd, O_TEXT);
@@ -266,27 +371,33 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
b->shutdown = (int)num & BIO_CLOSE;
if (num & BIO_FP_APPEND) {
if (num & BIO_FP_READ)
- OPENSSL_strlcpy(p, "a+", sizeof p);
+ BUF_strlcpy(p, "a+", sizeof p);
else
- OPENSSL_strlcpy(p, "a", sizeof p);
+ BUF_strlcpy(p, "a", sizeof p);
} else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE))
- OPENSSL_strlcpy(p, "r+", sizeof p);
+ BUF_strlcpy(p, "r+", sizeof p);
else if (num & BIO_FP_WRITE)
- OPENSSL_strlcpy(p, "w", sizeof p);
+ BUF_strlcpy(p, "w", sizeof p);
else if (num & BIO_FP_READ)
- OPENSSL_strlcpy(p, "r", sizeof p);
+ BUF_strlcpy(p, "r", sizeof p);
else {
BIOerr(BIO_F_FILE_CTRL, BIO_R_BAD_FOPEN_MODE);
ret = 0;
break;
}
-# if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32_CYGWIN)
+# if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN)
if (!(num & BIO_FP_TEXT))
strcat(p, "b");
else
strcat(p, "t");
# endif
- fp = openssl_fopen(ptr, p);
+# if defined(OPENSSL_SYS_NETWARE)
+ if (!(num & BIO_FP_TEXT))
+ strcat(p, "b");
+ else
+ strcat(p, "t");
+# endif
+ fp = file_fopen(ptr, p);
if (fp == NULL) {
SYSerr(SYS_F_FOPEN, get_last_sys_error());
ERR_add_error_data(5, "fopen('", ptr, "','", p, "')");
@@ -333,7 +444,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
return (ret);
}
-static int file_gets(BIO *bp, char *buf, int size)
+static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size)
{
int ret = 0;
@@ -351,7 +462,7 @@ static int file_gets(BIO *bp, char *buf, int size)
return (ret);
}
-static int file_puts(BIO *bp, const char *str)
+static int MS_CALLBACK file_puts(BIO *bp, const char *str)
{
int n, ret;
@@ -360,60 +471,6 @@ static int file_puts(BIO *bp, const char *str)
return (ret);
}
-#else
-
-static int file_write(BIO *b, const char *in, int inl)
-{
- return -1;
-}
-static int file_read(BIO *b, char *out, int outl)
-{
- return -1;
-}
-static int file_puts(BIO *bp, const char *str)
-{
- return -1;
-}
-static int file_gets(BIO *bp, char *buf, int size)
-{
- return 0;
-}
-static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
-{
- return 0;
-}
-static int file_new(BIO *bi)
-{
- return 0;
-}
-static int file_free(BIO *a)
-{
- return 0;
-}
-
-static const BIO_METHOD methods_filep = {
- BIO_TYPE_FILE,
- "FILE pointer",
- file_write,
- file_read,
- file_puts,
- file_gets,
- file_ctrl,
- file_new,
- file_free,
- NULL,
-};
-
-const BIO_METHOD *BIO_s_file(void)
-{
- return (&methods_filep);
-}
-
-BIO *BIO_new_file(const char *filename, const char *mode)
-{
- return NULL;
-}
-
# endif /* OPENSSL_NO_STDIO */
#endif /* HEADER_BSS_FILE_C */
diff --git a/Cryptlib/OpenSSL/crypto/bio/bss_log.c b/Cryptlib/OpenSSL/crypto/bio/bss_log.c
index 6cbde4d2..1283a525 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bss_log.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bss_log.c
@@ -1,10 +1,56 @@
-/*
- * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bss_log.c */
+/* ====================================================================
+ * Copyright (c) 1999 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
+ * licensing@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.
+ *
+ * 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).
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
*/
/*
@@ -19,8 +65,7 @@
#include <stdio.h>
#include <errno.h>
-#include "bio_lcl.h"
-#include "internal/cryptlib.h"
+#include "cryptlib.h"
#if defined(OPENSSL_SYS_WINCE)
#elif defined(OPENSSL_SYS_WIN32)
@@ -39,6 +84,8 @@ void *_malloc32(__size_t);
# endif /* __INITIAL_POINTER_SIZE == 64 */
# endif /* __INITIAL_POINTER_SIZE && defined
* _ANSI_C_SOURCE */
+#elif defined(__ultrix)
+# include <sys/syslog.h>
#elif defined(OPENSSL_SYS_NETWARE)
# define NO_SYSLOG
#elif (!defined(MSDOS) || defined(WATT32)) && !defined(OPENSSL_SYS_VXWORKS) && !defined(NO_SYSLOG)
@@ -75,16 +122,16 @@ void *_malloc32(__size_t);
# define LOG_DAEMON OPC$M_NM_NTWORK
# endif
-static int slg_write(BIO *h, const char *buf, int num);
-static int slg_puts(BIO *h, const char *str);
-static long slg_ctrl(BIO *h, int cmd, long arg1, void *arg2);
-static int slg_new(BIO *h);
-static int slg_free(BIO *data);
+static int MS_CALLBACK slg_write(BIO *h, const char *buf, int num);
+static int MS_CALLBACK slg_puts(BIO *h, const char *str);
+static long MS_CALLBACK slg_ctrl(BIO *h, int cmd, long arg1, void *arg2);
+static int MS_CALLBACK slg_new(BIO *h);
+static int MS_CALLBACK slg_free(BIO *data);
static void xopenlog(BIO *bp, char *name, int level);
static void xsyslog(BIO *bp, int priority, const char *string);
static void xcloselog(BIO *bp);
-static const BIO_METHOD methods_slg = {
+static BIO_METHOD methods_slg = {
BIO_TYPE_MEM, "syslog",
slg_write,
NULL,
@@ -96,12 +143,12 @@ static const BIO_METHOD methods_slg = {
NULL,
};
-const BIO_METHOD *BIO_s_log(void)
+BIO_METHOD *BIO_s_log(void)
{
return (&methods_slg);
}
-static int slg_new(BIO *bi)
+static int MS_CALLBACK slg_new(BIO *bi)
{
bi->init = 1;
bi->num = 0;
@@ -110,7 +157,7 @@ static int slg_new(BIO *bi)
return (1);
}
-static int slg_free(BIO *a)
+static int MS_CALLBACK slg_free(BIO *a)
{
if (a == NULL)
return (0);
@@ -118,7 +165,7 @@ static int slg_free(BIO *a)
return (1);
}
-static int slg_write(BIO *b, const char *in, int inl)
+static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl)
{
int ret = inl;
char *buf;
@@ -192,7 +239,7 @@ static int slg_write(BIO *b, const char *in, int inl)
/* The default */
};
- if ((buf = OPENSSL_malloc(inl + 1)) == NULL) {
+ if ((buf = (char *)OPENSSL_malloc(inl + 1)) == NULL) {
return (0);
}
strncpy(buf, in, inl);
@@ -210,7 +257,7 @@ static int slg_write(BIO *b, const char *in, int inl)
return (ret);
}
-static long slg_ctrl(BIO *b, int cmd, long num, void *ptr)
+static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, void *ptr)
{
switch (cmd) {
case BIO_CTRL_SET:
@@ -223,7 +270,7 @@ static long slg_ctrl(BIO *b, int cmd, long num, void *ptr)
return (0);
}
-static int slg_puts(BIO *bp, const char *str)
+static int MS_CALLBACK slg_puts(BIO *bp, const char *str)
{
int n, ret;
@@ -275,7 +322,7 @@ static void xsyslog(BIO *bp, int priority, const char *string)
break;
}
- sprintf(pidbuf, "[%lu] ", GetCurrentProcessId());
+ sprintf(pidbuf, "[%u] ", GetCurrentProcessId());
lpszStrings[0] = pidbuf;
lpszStrings[1] = string;
diff --git a/Cryptlib/OpenSSL/crypto/bio/bss_mem.c b/Cryptlib/OpenSSL/crypto/bio/bss_mem.c
index 6dc075dc..b0394a96 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bss_mem.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bss_mem.c
@@ -1,16 +1,65 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bss_mem.c */
+/* 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.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
#include <stdio.h>
#include <errno.h>
-#include "bio_lcl.h"
-#include "internal/cryptlib.h"
+#include "cryptlib.h"
+#include <openssl/bio.h>
static int mem_write(BIO *h, const char *buf, int num);
static int mem_read(BIO *h, char *buf, int size);
@@ -18,12 +67,8 @@ static int mem_puts(BIO *h, const char *str);
static int mem_gets(BIO *h, char *str, int size);
static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int mem_new(BIO *h);
-static int secmem_new(BIO *h);
static int mem_free(BIO *data);
-static int mem_buf_free(BIO *data, int free_all);
-static int mem_buf_sync(BIO *h);
-
-static const BIO_METHOD mem_method = {
+static BIO_METHOD mem_method = {
BIO_TYPE_MEM,
"memory buffer",
mem_write,
@@ -36,159 +81,87 @@ static const BIO_METHOD mem_method = {
NULL,
};
-static const BIO_METHOD secmem_method = {
- BIO_TYPE_MEM,
- "secure memory buffer",
- mem_write,
- mem_read,
- mem_puts,
- mem_gets,
- mem_ctrl,
- secmem_new,
- mem_free,
- NULL,
-};
-
-/* BIO memory stores buffer and read pointer */
-typedef struct bio_buf_mem_st {
- struct buf_mem_st *buf; /* allocated buffer */
- struct buf_mem_st *readp; /* read pointer */
-} BIO_BUF_MEM;
-
/*
* bio->num is used to hold the value to return on 'empty', if it is 0,
* should_retry is not set
*/
-const BIO_METHOD *BIO_s_mem(void)
+BIO_METHOD *BIO_s_mem(void)
{
return (&mem_method);
}
-const BIO_METHOD *BIO_s_secmem(void)
-{
- return(&secmem_method);
-}
BIO *BIO_new_mem_buf(const void *buf, int len)
{
BIO *ret;
BUF_MEM *b;
- BIO_BUF_MEM *bb;
size_t sz;
- if (buf == NULL) {
+ if (!buf) {
BIOerr(BIO_F_BIO_NEW_MEM_BUF, BIO_R_NULL_PARAMETER);
return NULL;
}
sz = (len < 0) ? strlen(buf) : (size_t)len;
- if ((ret = BIO_new(BIO_s_mem())) == NULL)
+ if (!(ret = BIO_new(BIO_s_mem())))
return NULL;
- bb = (BIO_BUF_MEM *)ret->ptr;
- b = bb->buf;
+ b = (BUF_MEM *)ret->ptr;
/* Cast away const and trust in the MEM_RDONLY flag. */
b->data = (void *)buf;
b->length = sz;
b->max = sz;
- *bb->readp = *bb->buf;
ret->flags |= BIO_FLAGS_MEM_RDONLY;
- /* Since this is static data retrying won't help */
+ /* Since this is static data retrying wont help */
ret->num = 0;
return ret;
}
-static int mem_init(BIO *bi, unsigned long flags)
+static int mem_new(BIO *bi)
{
- BIO_BUF_MEM *bb = OPENSSL_zalloc(sizeof(*bb));
+ BUF_MEM *b;
- if (bb == NULL)
- return 0;
- if ((bb->buf = BUF_MEM_new_ex(flags)) == NULL) {
- OPENSSL_free(bb);
- return 0;
- }
- if ((bb->readp = OPENSSL_zalloc(sizeof(*bb->readp))) == NULL) {
- BUF_MEM_free(bb->buf);
- OPENSSL_free(bb);
- return 0;
- }
- *bb->readp = *bb->buf;
+ if ((b = BUF_MEM_new()) == NULL)
+ return (0);
bi->shutdown = 1;
bi->init = 1;
bi->num = -1;
- bi->ptr = (char *)bb;
- return 1;
-}
-
-static int mem_new(BIO *bi)
-{
- return (mem_init(bi, 0L));
-}
-
-static int secmem_new(BIO *bi)
-{
- return (mem_init(bi, BUF_MEM_FLAG_SECURE));
+ bi->ptr = (char *)b;
+ return (1);
}
static int mem_free(BIO *a)
{
- return (mem_buf_free(a, 1));
-}
-
-static int mem_buf_free(BIO *a, int free_all)
-{
if (a == NULL)
return (0);
if (a->shutdown) {
if ((a->init) && (a->ptr != NULL)) {
BUF_MEM *b;
- BIO_BUF_MEM *bb = (BIO_BUF_MEM *)a->ptr;
-
- if (bb != NULL) {
- b = bb->buf;
- if (a->flags & BIO_FLAGS_MEM_RDONLY)
- b->data = NULL;
- BUF_MEM_free(b);
- if (free_all) {
- OPENSSL_free(bb->readp);
- OPENSSL_free(bb);
- }
- }
+ b = (BUF_MEM *)a->ptr;
+ if (a->flags & BIO_FLAGS_MEM_RDONLY)
+ b->data = NULL;
+ BUF_MEM_free(b);
a->ptr = NULL;
}
}
return (1);
}
-/*
- * Reallocate memory buffer if read pointer differs
- */
-static int mem_buf_sync(BIO *b)
-{
- if (b != NULL && b->init != 0 && b->ptr != NULL) {
- BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr;
-
- if (bbm->readp->data != bbm->buf->data) {
- memmove(bbm->buf->data, bbm->readp->data, bbm->readp->length);
- bbm->buf->length = bbm->readp->length;
- bbm->readp->data = bbm->buf->data;
- }
- }
- return (0);
-}
-
static int mem_read(BIO *b, char *out, int outl)
{
int ret = -1;
- BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr;
- BUF_MEM *bm = bbm->readp;
+ BUF_MEM *bm;
+ bm = (BUF_MEM *)b->ptr;
BIO_clear_retry_flags(b);
ret = (outl >= 0 && (size_t)outl > bm->length) ? (int)bm->length : outl;
if ((out != NULL) && (ret > 0)) {
memcpy(out, bm->data, ret);
bm->length -= ret;
- bm->data += ret;
+ if (b->flags & BIO_FLAGS_MEM_RDONLY)
+ bm->data += ret;
+ else {
+ memmove(&(bm->data[0]), &(bm->data[ret]), bm->length);
+ }
} else if (bm->length == 0) {
ret = b->num;
if (ret != 0)
@@ -201,23 +174,24 @@ static int mem_write(BIO *b, const char *in, int inl)
{
int ret = -1;
int blen;
- BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr;
+ BUF_MEM *bm;
+ bm = (BUF_MEM *)b->ptr;
if (in == NULL) {
BIOerr(BIO_F_MEM_WRITE, BIO_R_NULL_PARAMETER);
goto end;
}
+
if (b->flags & BIO_FLAGS_MEM_RDONLY) {
BIOerr(BIO_F_MEM_WRITE, BIO_R_WRITE_TO_READ_ONLY_BIO);
goto end;
}
+
BIO_clear_retry_flags(b);
- blen = bbm->readp->length;
- mem_buf_sync(b);
- if (BUF_MEM_grow_clean(bbm->buf, blen + inl) == 0)
+ blen = bm->length;
+ if (BUF_MEM_grow_clean(bm, blen + inl) != (blen + inl))
goto end;
- memcpy(bbm->buf->data + blen, in, inl);
- *bbm->readp = *bbm->buf;
+ memcpy(&(bm->data[blen]), in, inl);
ret = inl;
end:
return (ret);
@@ -227,32 +201,29 @@ static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
{
long ret = 1;
char **pptr;
- BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr;
- BUF_MEM *bm;
+
+ BUF_MEM *bm = (BUF_MEM *)b->ptr;
switch (cmd) {
case BIO_CTRL_RESET:
- bm = bbm->buf;
if (bm->data != NULL) {
/* For read only case reset to the start again */
- if ((b->flags & BIO_FLAGS_MEM_RDONLY) || (b->flags & BIO_FLAGS_NONCLEAR_RST)) {
+ if (b->flags & BIO_FLAGS_MEM_RDONLY) {
+ bm->data -= bm->max - bm->length;
bm->length = bm->max;
} else {
memset(bm->data, 0, bm->max);
bm->length = 0;
}
- *bbm->readp = *bbm->buf;
}
break;
case BIO_CTRL_EOF:
- bm = bbm->readp;
ret = (long)(bm->length == 0);
break;
case BIO_C_SET_BUF_MEM_EOF_RETURN:
b->num = (int)num;
break;
case BIO_CTRL_INFO:
- bm = bbm->readp;
ret = (long)bm->length;
if (ptr != NULL) {
pptr = (char **)ptr;
@@ -260,16 +231,12 @@ static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
}
break;
case BIO_C_SET_BUF_MEM:
- mem_buf_free(b, 0);
+ mem_free(b);
b->shutdown = (int)num;
- bbm->buf = ptr;
- *bbm->readp = *bbm->buf;
- b->ptr = bbm;
+ b->ptr = ptr;
break;
case BIO_C_GET_BUF_MEM_PTR:
if (ptr != NULL) {
- mem_buf_sync(b);
- bm = bbm->readp;
pptr = (char **)ptr;
*pptr = (char *)bm;
}
@@ -280,11 +247,11 @@ static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_CTRL_SET_CLOSE:
b->shutdown = (int)num;
break;
+
case BIO_CTRL_WPENDING:
ret = 0L;
break;
case BIO_CTRL_PENDING:
- bm = bbm->readp;
ret = (long)bm->length;
break;
case BIO_CTRL_DUP:
@@ -305,8 +272,7 @@ static int mem_gets(BIO *bp, char *buf, int size)
int i, j;
int ret = -1;
char *p;
- BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)bp->ptr;
- BUF_MEM *bm = bbm->readp;
+ BUF_MEM *bm = (BUF_MEM *)bp->ptr;
BIO_clear_retry_flags(bp);
j = bm->length;
diff --git a/Cryptlib/OpenSSL/crypto/bio/bss_null.c b/Cryptlib/OpenSSL/crypto/bio/bss_null.c
index e5c4adc8..6a03fa24 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bss_null.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bss_null.c
@@ -1,16 +1,65 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bss_null.c */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
#include <stdio.h>
#include <errno.h>
-#include "bio_lcl.h"
-#include "internal/cryptlib.h"
+#include "cryptlib.h"
+#include <openssl/bio.h>
static int null_write(BIO *h, const char *buf, int num);
static int null_read(BIO *h, char *buf, int size);
@@ -19,7 +68,7 @@ static int null_gets(BIO *h, char *str, int size);
static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int null_new(BIO *h);
static int null_free(BIO *data);
-static const BIO_METHOD null_method = {
+static BIO_METHOD null_method = {
BIO_TYPE_NULL,
"NULL",
null_write,
@@ -32,7 +81,7 @@ static const BIO_METHOD null_method = {
NULL,
};
-const BIO_METHOD *BIO_s_null(void)
+BIO_METHOD *BIO_s_null(void)
{
return (&null_method);
}
diff --git a/Cryptlib/OpenSSL/crypto/bio/bss_sock.c b/Cryptlib/OpenSSL/crypto/bio/bss_sock.c
index 570e8985..6194d2c0 100644
--- a/Cryptlib/OpenSSL/crypto/bio/bss_sock.c
+++ b/Cryptlib/OpenSSL/crypto/bio/bss_sock.c
@@ -1,28 +1,72 @@
-/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+/* crypto/bio/bss_sock.c */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
- * this file except in compliance with the License. You can obtain a copy
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
+ * 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.]
*/
#include <stdio.h>
#include <errno.h>
#define USE_SOCKETS
-#include "bio_lcl.h"
-#include "internal/cryptlib.h"
+#include "cryptlib.h"
#ifndef OPENSSL_NO_SOCK
# include <openssl/bio.h>
# ifdef WATT32
-/* Watt-32 uses same names */
-# undef sock_write
-# undef sock_read
-# undef sock_puts
-# define sock_write SockWrite
+# define sock_write SockWrite /* Watt-32 uses same names */
# define sock_read SockRead
# define sock_puts SockPuts
# endif
@@ -35,7 +79,7 @@ static int sock_new(BIO *h);
static int sock_free(BIO *data);
int BIO_sock_should_retry(int s);
-static const BIO_METHOD methods_sockp = {
+static BIO_METHOD methods_sockp = {
BIO_TYPE_SOCKET,
"socket",
sock_write,
@@ -48,7 +92,7 @@ static const BIO_METHOD methods_sockp = {
NULL,
};
-const BIO_METHOD *BIO_s_socket(void)
+BIO_METHOD *BIO_s_socket(void)
{
return (&methods_sockp);
}
@@ -79,7 +123,7 @@ static int sock_free(BIO *a)
return (0);
if (a->shutdown) {
if (a->init) {
- BIO_closesocket(a->num);
+ SHUTDOWN2(a->num);
}
a->init = 0;
a->flags = 0;
@@ -171,6 +215,12 @@ int BIO_sock_should_retry(int i)
if ((i == 0) || (i == -1)) {
err = get_last_socket_error();
+# if defined(OPENSSL_SYS_WINDOWS) && 0/* more microsoft stupidity? perhaps
+ * not? Ben 4/1/99 */
+ if ((i == -1) && (err == 0))
+ return (1);
+# endif
+
return (BIO_sock_non_fatal_error(err));
}
return (0);
@@ -179,10 +229,16 @@ int BIO_sock_should_retry(int i)
int BIO_sock_non_fatal_error(int err)
{
switch (err) {
-# if defined(OPENSSL_SYS_WINDOWS)
+# if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_NETWARE)
# if defined(WSAEWOULDBLOCK)
case WSAEWOULDBLOCK:
# endif
+
+# if 0 /* This appears to always be an error */
+# if defined(WSAENOTCONN)
+ case WSAENOTCONN:
+# endif
+# endif
# endif
# ifdef EWOULDBLOCK