diff options
-rw-r--r-- | botan_version.py | 6 | ||||
-rw-r--r-- | doc/examples/socket.h | 102 | ||||
-rw-r--r-- | doc/examples/tls_client.cpp | 8 | ||||
-rw-r--r-- | doc/examples/tls_server.cpp | 3 | ||||
-rw-r--r-- | doc/log.txt | 12 | ||||
-rw-r--r-- | readme.txt | 2 | ||||
-rw-r--r-- | src/codec/hex/hex.cpp | 9 | ||||
-rw-r--r-- | src/ssl/tls_record.h | 8 |
8 files changed, 110 insertions, 40 deletions
diff --git a/botan_version.py b/botan_version.py index d3d79a3ad..491cdc204 100644 --- a/botan_version.py +++ b/botan_version.py @@ -1,6 +1,6 @@ release_major = 1 -release_minor = 9 -release_patch = 17 +release_minor = 10 +release_patch = 0 -release_datestamp = 20110429 +release_datestamp = 0 diff --git a/doc/examples/socket.h b/doc/examples/socket.h index c4fa46600..6d28afacf 100644 --- a/doc/examples/socket.h +++ b/doc/examples/socket.h @@ -10,13 +10,55 @@ #include <stdexcept> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <netinet/in.h> -#include <netdb.h> -#include <unistd.h> -#include <errno.h> +#if defined(_MSC_VER) + #define SOCKET_IS_WINSOCK 1 +#endif + +#if !defined(SOCKET_IS_WINSOCK) + #define SOCKET_IS_WINSOCK 0 +#endif + +#if SOCKET_IS_WINSOCK + #include <winsock.h> + + typedef SOCKET socket_t; + const socket_t invalid_socket = INVALID_SOCKET; + #define socket_error_code WSAGetLastError() + + class SocketInitializer + { + public: + SocketInitializer() + { + WSADATA wsadata; + WSAStartup(MAKEWORD(2, 2), &wsadata); + } + + ~SocketInitializer() + { + WSACleanup(); + } + }; +#else + #include <sys/types.h> + #include <sys/socket.h> + #include <sys/time.h> + #include <netinet/in.h> + #include <netdb.h> + #include <unistd.h> + #include <errno.h> + + typedef int socket_t; + const socket_t invalid_socket = -1; + #define socket_error_code errno + + class SocketInitializer {}; +#endif + +#if !defined(MSG_NOSIGNAL) + #define MSG_NOSIGNAL 0 +#endif + #include <string.h> class Socket @@ -29,15 +71,15 @@ class Socket void close() { - if(sockfd != -1) + if(sockfd != invalid_socket) { if(::close(sockfd) != 0) throw std::runtime_error("Socket::close failed"); - sockfd = -1; + sockfd = invalid_socket; } } - Socket(int fd, const std::string& peer_id = "") : + Socket(socket_t fd, const std::string& peer_id = "") : peer(peer_id), sockfd(fd) { } @@ -46,7 +88,7 @@ class Socket ~Socket() { close(); } private: std::string peer; - int sockfd; + socket_t sockfd; }; class Server_Socket @@ -57,26 +99,26 @@ class Server_Socket */ Socket* accept() { - int retval = ::accept(sockfd, 0, 0); - if(retval == -1) + socket_t retval = ::accept(sockfd, 0, 0); + if(retval == invalid_socket) throw std::runtime_error("Server_Socket: accept failed"); return new Socket(retval); } void close() { - if(sockfd != -1) + if(sockfd != invalid_socket) { if(::close(sockfd) != 0) throw std::runtime_error("Server_Socket::close failed"); - sockfd = -1; + sockfd = invalid_socket; } } Server_Socket(unsigned short); ~Server_Socket() { close(); } private: - int sockfd; + socket_t sockfd; }; /** @@ -84,7 +126,7 @@ class Server_Socket */ Socket::Socket(const std::string& host, unsigned short port) : peer(host) { - sockfd = -1; + sockfd = invalid_socket; hostent* host_addr = ::gethostbyname(host.c_str()); @@ -93,8 +135,8 @@ Socket::Socket(const std::string& host, unsigned short port) : peer(host) if(host_addr->h_addrtype != AF_INET) // FIXME throw std::runtime_error("Socket: " + host + " has IPv6 address"); - int fd = ::socket(PF_INET, SOCK_STREAM, 0); - if(fd == -1) + socket_t fd = ::socket(PF_INET, SOCK_STREAM, 0); + if(fd == invalid_socket) throw std::runtime_error("Socket: Unable to acquire socket"); sockaddr_in socket_info; @@ -122,21 +164,22 @@ Socket::Socket(const std::string& host, unsigned short port) : peer(host) */ size_t Socket::read(unsigned char buf[], size_t length) { - if(sockfd == -1) + if(sockfd == invalid_socket) throw std::runtime_error("Socket::read: Socket not connected"); size_t got = 0; while(length) { - ssize_t this_time = ::recv(sockfd, buf + got, length, MSG_NOSIGNAL); + ssize_t this_time = ::recv(sockfd, (char*)buf + got, + length, MSG_NOSIGNAL); if(this_time == 0) break; if(this_time == -1) { - if(errno == EINTR) + if(socket_error_code == EINTR) this_time = 0; else throw std::runtime_error("Socket::read: Socket read failed"); @@ -153,17 +196,18 @@ size_t Socket::read(unsigned char buf[], size_t length) */ void Socket::write(const unsigned char buf[], size_t length) { - if(sockfd == -1) + if(sockfd == invalid_socket) throw std::runtime_error("Socket::write: Socket not connected"); size_t offset = 0; while(length) { - ssize_t sent = ::send(sockfd, buf + offset, length, MSG_NOSIGNAL); + ssize_t sent = ::send(sockfd, (const char*)buf + offset, + length, MSG_NOSIGNAL); if(sent == -1) { - if(errno == EINTR) + if(socket_error_code == EINTR) sent = 0; else throw std::runtime_error("Socket::write: Socket write failed"); @@ -179,10 +223,10 @@ void Socket::write(const unsigned char buf[], size_t length) */ Server_Socket::Server_Socket(unsigned short port) { - sockfd = -1; + sockfd = invalid_socket; - int fd = ::socket(PF_INET, SOCK_STREAM, 0); - if(fd == -1) + socket_t fd = ::socket(PF_INET, SOCK_STREAM, 0); + if(fd == invalid_socket) throw std::runtime_error("Server_Socket: Unable to acquire socket"); sockaddr_in socket_info; @@ -199,7 +243,7 @@ Server_Socket::Server_Socket(unsigned short port) throw std::runtime_error("Server_Socket: bind failed"); } - if(listen(fd, 100) != 0) // FIXME: totally arbitrary + if(::listen(fd, 100) != 0) // FIXME: totally arbitrary { ::close(fd); throw std::runtime_error("Server_Socket: listen failed"); diff --git a/doc/examples/tls_client.cpp b/doc/examples/tls_client.cpp index eb4a98817..4896a28f8 100644 --- a/doc/examples/tls_client.cpp +++ b/doc/examples/tls_client.cpp @@ -35,13 +35,15 @@ int main(int argc, char* argv[]) try { - LibraryInitializer init; + LibraryInitializer botan_init; std::string host = argv[1]; u32bit port = argc == 3 ? Botan::to_u32bit(argv[2]) : 443; printf("Connecting to %s:%d...\n", host.c_str(), port); + SocketInitializer socket_init; + Socket sock(argv[1], port); AutoSeeded_RNG rng; @@ -54,8 +56,12 @@ int main(int argc, char* argv[]) printf("Handshake extablished...\n"); +#if 0 std::string http_command = "GET / HTTP/1.1\r\n" "Server: " + host + ':' + to_string(port) + "\r\n\r\n"; +#else + std::string http_command = "GET / HTTP/1.0\r\n\r\n"; +#endif tls.write((const byte*)http_command.c_str(), http_command.length()); diff --git a/doc/examples/tls_server.cpp b/doc/examples/tls_server.cpp index be5677c12..0c68ead3d 100644 --- a/doc/examples/tls_server.cpp +++ b/doc/examples/tls_server.cpp @@ -39,7 +39,8 @@ int main(int argc, char* argv[]) try { - LibraryInitializer init; + LibraryInitializer botan_init; + SocketInitializer socket_init; AutoSeeded_RNG rng; diff --git a/doc/log.txt b/doc/log.txt index b5207ea8f..92b6505f3 100644 --- a/doc/log.txt +++ b/doc/log.txt @@ -4,6 +4,18 @@ Release Notes ======================================== +Series 1.10 +---------------------------------------- + +Version 1.10.0, Not Yet Released +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* Add support for compiling SSL using Visual C++ 2010's TR1 + implementation. + +* Fix a bug under Visual C++ 2010 which would cause ``hex_encode`` to + crash if given a zero-sized input to encode. + Series 1.9 ---------------------------------------- diff --git a/readme.txt b/readme.txt index cc4ec178c..ef6f2c77d 100644 --- a/readme.txt +++ b/readme.txt @@ -1,4 +1,4 @@ -Botan 1.9.17, 2011-04-29 +Botan 1.10.0, Not Yet Released http://botan.randombit.net/ Botan is a C++ class library for performing a wide variety of diff --git a/src/codec/hex/hex.cpp b/src/codec/hex/hex.cpp index 49d6e7190..41ba1298d 100644 --- a/src/codec/hex/hex.cpp +++ b/src/codec/hex/hex.cpp @@ -37,9 +37,7 @@ void hex_encode(char output[], std::string hex_encode(const MemoryRegion<byte>& input, bool uppercase) { - return hex_encode(&input[0], - input.size(), - uppercase); + return hex_encode(&input[0], input.size(), uppercase); } std::string hex_encode(const byte input[], @@ -47,7 +45,10 @@ std::string hex_encode(const byte input[], bool uppercase) { std::string output(2 * input_length, 0); - hex_encode(&output[0], input, input_length, uppercase); + + if(input_length) + hex_encode(&output[0], input, input_length, uppercase); + return output; } diff --git a/src/ssl/tls_record.h b/src/ssl/tls_record.h index 7a223095f..09fd921c6 100644 --- a/src/ssl/tls_record.h +++ b/src/ssl/tls_record.h @@ -16,7 +16,13 @@ #include <vector> #if defined(BOTAN_USE_STD_TR1) - #include <tr1/functional> + +#if defined(BOTAN_BUILD_COMPILER_IS_MSVC) + #include <functional> +#else + #include <tr1/functional> +#endif + #elif defined(BOTAN_USE_BOOST_TR1) #include <boost/tr1/functional.hpp> #else |