Sha256: c24bb2c9e469f61fbf0750cf4a20dfab9b67211aedb3e04ed5934930c1a6dea0

Contents?: true

Size: 1.92 KB

Versions: 136

Compression:

Stored size: 1.92 KB

Contents

/*
 * Copyright (c) 2004-2005 Sergey Lyubka <valenok@gmail.com>
 * All rights reserved
 *
 * "THE BEER-WARE LICENSE" (Revision 42):
 * Sergey Lyubka wrote this file.  As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return.
 */

#include "defs.h"

#if !defined(NO_SSL)
struct ssl_func	ssl_sw[] = {
	{"SSL_free",			{0}},
	{"SSL_accept",			{0}},
	{"SSL_connect",			{0}},
	{"SSL_read",			{0}},
	{"SSL_write",			{0}},
	{"SSL_get_error",		{0}},
	{"SSL_set_fd",			{0}},
	{"SSL_new",			{0}},
	{"SSL_CTX_new",			{0}},
	{"SSLv23_server_method",	{0}},
	{"SSL_library_init",		{0}},
	{"SSL_CTX_use_PrivateKey_file",	{0}},
	{"SSL_CTX_use_certificate_file",{0}},
	{NULL,				{0}}
};

void
_shttpd_ssl_handshake(struct stream *stream)
{
	int	n;

	if ((n = SSL_accept(stream->chan.ssl.ssl)) == 1) {
		DBG(("handshake: SSL accepted"));
		stream->flags |= FLAG_SSL_ACCEPTED;
	} else {
		n = SSL_get_error(stream->chan.ssl.ssl, n);
		if (n != SSL_ERROR_WANT_READ && n != SSL_ERROR_WANT_WRITE)
			stream->flags |= FLAG_CLOSED;
		DBG(("SSL_accept error %d", n));
	}
}

static int
read_ssl(struct stream *stream, void *buf, size_t len)
{
	int	nread = -1;

	assert(stream->chan.ssl.ssl != NULL);

	if (!(stream->flags & FLAG_SSL_ACCEPTED))
		_shttpd_ssl_handshake(stream);

	if (stream->flags & FLAG_SSL_ACCEPTED)
		nread = SSL_read(stream->chan.ssl.ssl, buf, len);

	return (nread);
}

static int
write_ssl(struct stream *stream, const void *buf, size_t len)
{
	assert(stream->chan.ssl.ssl != NULL);
	return (SSL_write(stream->chan.ssl.ssl, buf, len));
}

static void
close_ssl(struct stream *stream)
{
	assert(stream->chan.ssl.sock != -1);
	assert(stream->chan.ssl.ssl != NULL);
	(void) closesocket(stream->chan.ssl.sock);
	SSL_free(stream->chan.ssl.ssl);
}

const struct io_class	_shttpd_io_ssl =  {
	"ssl",
	read_ssl,
	write_ssl,
	close_ssl
};
#endif /* !NO_SSL */

Version data entries

136 entries across 136 versions & 2 rubygems

Version Path
rhodes-7.6.0 platform/shared/shttpd/src/io_ssl.c
rhodes-7.5.1 platform/shared/shttpd/src/io_ssl.c
rhodes-7.4.1 platform/shared/shttpd/src/io_ssl.c
rhodes-7.1.17 platform/shared/shttpd/src/io_ssl.c
rhodes-6.2.0 platform/shared/shttpd/src/io_ssl.c
rhodes-6.0.11 platform/shared/shttpd/src/io_ssl.c
rhodes-5.5.18 platform/shared/shttpd/src/io_ssl.c
rhodes-5.5.17 platform/shared/shttpd/src/io_ssl.c
rhodes-5.5.15 platform/shared/shttpd/src/io_ssl.c
rhodes-5.5.0.22 platform/shared/shttpd/src/io_ssl.c
rhodes-5.5.2 platform/shared/shttpd/src/io_ssl.c
rhodes-5.5.0.7 platform/shared/shttpd/src/io_ssl.c
rhodes-5.5.0.3 platform/shared/shttpd/src/io_ssl.c
rhodes-5.5.0 platform/shared/shttpd/src/io_ssl.c
tauplatform-1.0.3 platform/shared/shttpd/src/io_ssl.c
tauplatform-1.0.2 platform/shared/shttpd/src/io_ssl.c
tauplatform-1.0.1 platform/shared/shttpd/src/io_ssl.c
rhodes-3.5.1.12 platform/shared/shttpd/src/io_ssl.c
rhodes-3.3.5 platform/shared/shttpd/src/io_ssl.c
rhodes-3.4.2 platform/shared/shttpd/src/io_ssl.c