Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Abraham committed Mar 21, 2012
0 parents commit eefee1c
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
log
bin
obj
*.cbp
*.depend
*.layout
test.conf

1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example skeleton openssl server, which does nothing but prints the read data to stdout
83 changes: 83 additions & 0 deletions SSLServer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "SSLServer.h"

SSLServer::SSLServer()
{
SSL_library_init();
SSL_load_error_strings();
ERR_load_BIO_strings();
ERR_load_SSL_strings();
cert = "/home/roa/programming/examples/ssl_conn/ssl_example/servercert.pem";
key = "/home/roa/programming/examples/ssl_conn/ssl_example/private.key";
host = "localhost:9037";

ctx = SSL_CTX_new(SSLv3_server_method());
SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM);
SSL_CTX_use_PrivateKey_file(ctx, key, SSL_FILETYPE_PEM);
abio = BIO_new_accept(host);
if(abio == NULL)
{
abort();
}
}

void SSLServer::run()
{
if(BIO_do_accept(abio) <= 0)
{
abort();
}

fd_set fds;

int afd = BIO_get_fd(abio,NULL);

while(true)
{
FD_ZERO(&fds);
FD_SET(afd,&fds);

select(afd+1,&fds,NULL,NULL,NULL);
if(FD_ISSET(afd,&fds) && BIO_do_accept(abio) > 0)
{
int r;
char rbuf[4096];
client = BIO_pop(abio);
ssl = SSL_new(ctx);
SSL_set_accept_state(ssl);
SSL_set_bio(ssl, client, client);

handleClient();
}
}
}
void SSLServer::handleClient()
{
fd_set rfds, wfds;
int cfd = BIO_get_fd(client, NULL);
int r;
char rbuf[4096];
std::string tempstr;

for(;;)
{
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_SET(cfd, &rfds);

r = select(cfd+1, &rfds, &wfds, NULL, NULL);

if(FD_ISSET(cfd, &rfds))
{
r = SSL_read(ssl, rbuf, sizeof(rbuf)-1);
if( r <= 0 )
{
break;
}
rbuf[r] = '\0';
tempstr.append(rbuf);
}
}
std::cout << "huch" << std::endl;
std::cout << tempstr << std::endl;
}

31 changes: 31 additions & 0 deletions SSLServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef SSLSERVER_H
#define SSLSERVER_H

#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <iostream>

class SSLServer
{
public:
SSLServer();

void run();

protected:
SSL_CTX* ctx;
char *cert;
char *key;
BIO *abio;
BIO *client;
SSL *ssl;
char *host;

void handleClient();
};

#endif
9 changes: 9 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "SSLServer.h"

int main()
{
SSLServer *s;
s = new SSLServer;
s->run();
return 0;
}
16 changes: 16 additions & 0 deletions private.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-----BEGIN PRIVATE KEY-----
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANvAoh2gM3x715cm
a9aHC9jUhNZreiyRwJU4n5R/Qd+umsnvHKgpATk2A1hLQhwZyN4VXSqNMOKne2Hp
mkWU7AjyHWZ10kW4eRhJBt5FpYMK81RzJQyv3h1ncSFrmbarSUhMQmBpSUwt1PtF
NJfZnKPoHsysB2aynTHpoG1FL44RAgMBAAECgYB/fQlQULGuBZb0zMiBRAW+fMS4
NNBDbSeiKqCCITYRVBXfE0a31FouW8SjA75N2TOsjA5p8lGrHOk6y7DBr30jPEZk
lQGeemplSSXSmYk0kqRqCk1o/8JgsCRI/Hg28HcoSKIhWyd0brkOlkC4C9Jiibv8
3JhqjJ1PLWIo58VYAQJBAO09Etl2MVC/mk1QgouDPF2YBBBzHIFmhMLmlBTTsgnX
WK+mD7VCiQiDyU3PeMNX1d2BHl9jkN6snlaaZ57f+4ECQQDtIY0iyPwUAzVWALUG
q6viPRyCPJkbjtsuxAFFgG9tRPsKDgEKsI+Yhjkg2wJ3s2u+a59xMu7twyEZj/7I
RxqRAkEAr/5Av4ZI62hYpcZ2Md03qQ8e5L0ghnZxQs0fSZwKVfalWhjNSmCDnAd4
DPs+0VuV0m75AzavwCE6jXCaMmhjAQJAFhjJSROHgenmn3QDanK22qctL+mrrsi6
Hfp/z9UvDPSfnAlACZn4V5MyYaBm83aRtLXcrrS7VQaY4APuDwWpMQJBALkugz/9
TbQo29U8s+B0MFMJ33PYcGkhbwUWX/4liUQxKaYsByOQJX5BPgbhdTh8RCR8YTMO
VtpRP0jokMhIryE=
-----END PRIVATE KEY-----
15 changes: 15 additions & 0 deletions servercert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-----BEGIN CERTIFICATE-----
MIICXzCCAcgCCQDx8zCuCKCP2zANBgkqhkiG9w0BAQUFADB0MQswCQYDVQQGEwJV
UzERMA8GA1UECAwIQ29sb3JhZG8xGjAYBgNVBAcMEUNoZXllbm5lIE1vdW50YWlu
MQ0wCwYDVQQKDARVU0FGMQ4wDAYDVQQLDAVOT1JBRDEXMBUGA1UEAwwOd29wci5u
b3JhZC5taWwwHhcNMTIwMzIwMTUxMDU0WhcNMTMwMzIwMTUxMDU0WjB0MQswCQYD
VQQGEwJVUzERMA8GA1UECAwIQ29sb3JhZG8xGjAYBgNVBAcMEUNoZXllbm5lIE1v
dW50YWluMQ0wCwYDVQQKDARVU0FGMQ4wDAYDVQQLDAVOT1JBRDEXMBUGA1UEAwwO
d29wci5ub3JhZC5taWwwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANvAoh2g
M3x715cma9aHC9jUhNZreiyRwJU4n5R/Qd+umsnvHKgpATk2A1hLQhwZyN4VXSqN
MOKne2HpmkWU7AjyHWZ10kW4eRhJBt5FpYMK81RzJQyv3h1ncSFrmbarSUhMQmBp
SUwt1PtFNJfZnKPoHsysB2aynTHpoG1FL44RAgMBAAEwDQYJKoZIhvcNAQEFBQAD
gYEAWnxLW/+T8jEHvTUlC9T/0Jimea9hW70DaCf2MTIwMjk3HcPM3HCIwMhHKqto
I/1wuMzEGv3R5yNSw0+KJUpcip5AQvEJLbPN9QGtoxSRqS4Up8NYdg+sxxBoHKDN
bJthxlSXk5HPJdBXGQv9b5ztwDUwEu9jm9FhGhO+fjw6rgE=
-----END CERTIFICATE-----
12 changes: 12 additions & 0 deletions servercsr.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-----BEGIN CERTIFICATE REQUEST-----
MIIBtDCCAR0CAQAwdDELMAkGA1UEBhMCVVMxETAPBgNVBAgMCENvbG9yYWRvMRow
GAYDVQQHDBFDaGV5ZW5uZSBNb3VudGFpbjENMAsGA1UECgwEVVNBRjEOMAwGA1UE
CwwFTk9SQUQxFzAVBgNVBAMMDndvcHIubm9yYWQubWlsMIGfMA0GCSqGSIb3DQEB
AQUAA4GNADCBiQKBgQDbwKIdoDN8e9eXJmvWhwvY1ITWa3oskcCVOJ+Uf0HfrprJ
7xyoKQE5NgNYS0IcGcjeFV0qjTDip3th6ZpFlOwI8h1mddJFuHkYSQbeRaWDCvNU
cyUMr94dZ3Eha5m2q0lITEJgaUlMLdT7RTSX2Zyj6B7MrAdmsp0x6aBtRS+OEQID
AQABoAAwDQYJKoZIhvcNAQEFBQADgYEAjXwOrXPDoVz8ci1NgsjA0CW4yhG70to+
0Ct8sOgfqK5fRtr3DdZOC/XFvywp8ARG3wBHmot1ZQOlUhwA8kgQJvbwRz2EtmNE
+aC1yr8BRQxePFH//t71XISgs5sf/PbgrqwNf6ldHF6RrQH6nrwKH6Fm/vIJOuSF
UmC1rWoXUHc=
-----END CERTIFICATE REQUEST-----

0 comments on commit eefee1c

Please sign in to comment.