SSL Test Pt. 1
This commit is contained in:
parent
c6ad412df9
commit
fd62679c25
@ -17,15 +17,35 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#ifdef IBM
|
||||
#endif
|
||||
#ifdef APL
|
||||
#endif
|
||||
#ifdef LIN
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
class Socket
|
||||
{
|
||||
private:
|
||||
#ifdef LIN
|
||||
SSL *ssl;
|
||||
int sock;
|
||||
#endif
|
||||
char lastPath[513] = "";
|
||||
char lastHash[2 * MD5LEN + 1] = "";
|
||||
std::mutex wsLock;
|
||||
std::string url;
|
||||
std::function<void(std::string)> toLog;
|
||||
|
||||
#ifdef LIN
|
||||
void logSSL();
|
||||
#endif
|
||||
|
||||
public:
|
||||
explicit Socket(std::string url,
|
||||
std::function<void(const std::string)> toLog);
|
||||
|
||||
@ -6,6 +6,52 @@ Socket::Socket(std::string url, std::function<void(const std::string)> toLog)
|
||||
#ifdef IBM
|
||||
// WSA INIT
|
||||
int a = 0;
|
||||
#endif
|
||||
#ifdef APL
|
||||
int a = 0;
|
||||
#endif
|
||||
#ifdef LIN
|
||||
int s;
|
||||
s = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (s < 0) {
|
||||
toLog("Error creating socket.");
|
||||
return;
|
||||
}
|
||||
struct sockaddr_in sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_addr.s_addr =
|
||||
inet_addr("136.243.123.153"); // address of german-airlines.de
|
||||
sa.sin_port = htons(443);
|
||||
socklen_t socklen = sizeof(sa);
|
||||
if (connect(s, (struct sockaddr *)&sa, socklen)) {
|
||||
toLog("Error connecting to server.");
|
||||
return;
|
||||
}
|
||||
SSL_library_init();
|
||||
SSLeay_add_ssl_algorithms();
|
||||
SSL_load_error_strings();
|
||||
const SSL_METHOD *meth = TLSv1_2_client_method();
|
||||
SSL_CTX *ctx = SSL_CTX_new(meth);
|
||||
ssl = SSL_new(ctx);
|
||||
if (!ssl) {
|
||||
toLog("Error creating SSL.");
|
||||
logSSL();
|
||||
return;
|
||||
}
|
||||
sock = SSL_get_fd(ssl);
|
||||
SSL_set_fd(ssl, s);
|
||||
int err = SSL_connect(ssl);
|
||||
if (err <= 0) {
|
||||
std::ostringstream msg;
|
||||
msg << "Error creating SSL connection. err=" << err;
|
||||
toLog(msg.str());
|
||||
logSSL();
|
||||
return;
|
||||
}
|
||||
std::ostringstream msg;
|
||||
msg << "SSL connection using " << SSL_get_cipher(ssl);
|
||||
toLog(msg.str());
|
||||
#endif
|
||||
// PLATFORM AGNOSTIC
|
||||
}
|
||||
@ -44,3 +90,16 @@ void Socket::sendData(data d)
|
||||
// SEND
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LIN
|
||||
void Socket::logSSL()
|
||||
{
|
||||
int err;
|
||||
while ((err = ERR_get_error())) {
|
||||
char *str = ERR_error_string(err, 0);
|
||||
if (!str)
|
||||
return;
|
||||
toLog(str);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user