mirror of
https://github.com/MariaDB/server.git
synced 2025-01-28 01:34:17 +01:00
eb6ab467ce
extra/yassl/README: Import patch yassl.diff extra/yassl/examples/client/client.cpp: Import patch yassl.diff extra/yassl/examples/echoclient/echoclient.cpp: Import patch yassl.diff extra/yassl/examples/echoserver/echoserver.cpp: Import patch yassl.diff extra/yassl/examples/server/server.cpp: Import patch yassl.diff extra/yassl/include/factory.hpp: Import patch yassl.diff extra/yassl/include/openssl/ssl.h: Import patch yassl.diff extra/yassl/include/socket_wrapper.hpp: Import patch yassl.diff extra/yassl/include/yassl_error.hpp: Import patch yassl.diff extra/yassl/include/yassl_imp.hpp: Import patch yassl.diff extra/yassl/include/yassl_int.hpp: Import patch yassl.diff extra/yassl/include/yassl_types.hpp: Import patch yassl.diff extra/yassl/src/handshake.cpp: Import patch yassl.diff extra/yassl/src/make.bat: Import patch yassl.diff extra/yassl/src/socket_wrapper.cpp: Import patch yassl.diff extra/yassl/src/ssl.cpp: Import patch yassl.diff extra/yassl/src/yassl_error.cpp: Import patch yassl.diff extra/yassl/src/yassl_imp.cpp: Import patch yassl.diff extra/yassl/src/yassl_int.cpp: Import patch yassl.diff extra/yassl/taocrypt/benchmark/make.bat: Import patch yassl.diff extra/yassl/taocrypt/include/aes.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/algebra.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/arc4.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/asn.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/block.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/blowfish.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/des.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/integer.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/md5.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/misc.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/modes.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/ripemd.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/rsa.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/sha.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/twofish.hpp: Import patch yassl.diff extra/yassl/taocrypt/src/aes.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/algebra.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/arc4.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/blowfish.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/des.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/integer.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/make.bat: Import patch yassl.diff extra/yassl/taocrypt/src/md4.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/md5.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/misc.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/random.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/ripemd.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/sha.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/twofish.cpp: Import patch yassl.diff extra/yassl/taocrypt/test/make.bat: Import patch yassl.diff extra/yassl/taocrypt/test/test.cpp: Import patch yassl.diff extra/yassl/testsuite/make.bat: Import patch yassl.diff extra/yassl/testsuite/test.hpp: Import patch yassl.diff extra/yassl/include/openssl/prefix_ssl.h: New prefic file for ssl.h generated
113 lines
2.5 KiB
C++
113 lines
2.5 KiB
C++
/* server.cpp */
|
|
|
|
|
|
#include "../../testsuite/test.hpp"
|
|
|
|
|
|
void ServerError(SSL_CTX* ctx, SSL* ssl, SOCKET_T& sockfd, const char* msg)
|
|
{
|
|
SSL_CTX_free(ctx);
|
|
SSL_free(ssl);
|
|
tcp_close(sockfd);
|
|
err_sys(msg);
|
|
}
|
|
|
|
|
|
#ifdef NON_BLOCKING
|
|
void NonBlockingSSL_Accept(SSL* ssl, SSL_CTX* ctx, SOCKET_T& clientfd)
|
|
{
|
|
int ret = SSL_accept(ssl);
|
|
while (ret != SSL_SUCCESS && SSL_get_error(ssl, 0) ==
|
|
SSL_ERROR_WANT_READ) {
|
|
printf("... server would block\n");
|
|
#ifdef _WIN32
|
|
Sleep(1000);
|
|
#else
|
|
sleep(1);
|
|
#endif
|
|
ret = SSL_accept(ssl);
|
|
}
|
|
if (ret != SSL_SUCCESS)
|
|
ServerError(ctx, ssl, clientfd, "SSL_accept failed");
|
|
}
|
|
#endif
|
|
|
|
|
|
THREAD_RETURN YASSL_API server_test(void* args)
|
|
{
|
|
#ifdef _WIN32
|
|
WSADATA wsd;
|
|
WSAStartup(0x0002, &wsd);
|
|
#endif
|
|
|
|
SOCKET_T sockfd = 0;
|
|
SOCKET_T clientfd = 0;
|
|
int argc = 0;
|
|
char** argv = 0;
|
|
|
|
set_args(argc, argv, *static_cast<func_args*>(args));
|
|
tcp_accept(sockfd, clientfd, *static_cast<func_args*>(args));
|
|
|
|
tcp_close(sockfd);
|
|
|
|
SSL_METHOD* method = TLSv1_server_method();
|
|
SSL_CTX* ctx = SSL_CTX_new(method);
|
|
|
|
//SSL_CTX_set_cipher_list(ctx, "RC4-SHA:RC4-MD5");
|
|
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
|
|
set_serverCerts(ctx);
|
|
DH* dh = set_tmpDH(ctx);
|
|
|
|
SSL* ssl = SSL_new(ctx);
|
|
SSL_set_fd(ssl, clientfd);
|
|
|
|
#ifdef NON_BLOCKING
|
|
NonBlockingSSL_Accept(ssl, ctx, clientfd);
|
|
#else
|
|
if (SSL_accept(ssl) != SSL_SUCCESS)
|
|
ServerError(ctx, ssl, clientfd, "SSL_accept failed");
|
|
#endif
|
|
|
|
showPeer(ssl);
|
|
printf("Using Cipher Suite: %s\n", SSL_get_cipher(ssl));
|
|
|
|
char command[1024];
|
|
int input = SSL_read(ssl, command, sizeof(command));
|
|
if (input > 0) {
|
|
command[input] = 0;
|
|
printf("First client command: %s\n", command);
|
|
}
|
|
|
|
char msg[] = "I hear you, fa shizzle!";
|
|
if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg))
|
|
ServerError(ctx, ssl, clientfd, "SSL_write failed");
|
|
|
|
DH_free(dh);
|
|
SSL_CTX_free(ctx);
|
|
SSL_shutdown(ssl);
|
|
SSL_free(ssl);
|
|
|
|
tcp_close(clientfd);
|
|
|
|
((func_args*)args)->return_code = 0;
|
|
return 0;
|
|
}
|
|
|
|
|
|
#ifndef NO_MAIN_DRIVER
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
func_args args;
|
|
|
|
args.argc = argc;
|
|
args.argv = argv;
|
|
|
|
server_test(&args);
|
|
yaSSL_CleanUp();
|
|
|
|
return args.return_code;
|
|
}
|
|
|
|
#endif // NO_MAIN_DRIVER
|
|
|