S
Hi,
was ich gebraucht habe ist ein der generelle Ansatz für ein Client auf Basis von Openssl... also wie ich mit Openssl eine Verbindung zu einem Openssl Server aufbaue.
Hab aber schon was gefunden:
#include <stdio.h>
#include <memory.h>
#include <errno.h>
#include <sys/types.h>
#ifdef WIN32
#include <string.h>
#include <winsock.h>
#include <io.h>
#pragma warning(disable:4270)
#pragma comment(lib,"ws2_32.lib")
#pragma comment(lib,"libeay32.lib")
#pragma comment(lib,"ssleay32.lib")
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#endif
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
void main ()
{
int err;
SSLeay_add_ssl_algorithms();
SSL_METHOD *meth = SSLv2_client_method();
SSL_load_error_strings();
SSL_CTX* ctx = SSL_CTX_new (meth);
#ifdef WIN32
WSADATA wsaData;
WSAStartup(MAKEWORD(1, 1), &wsaData);
#endif
// *** Create Socket ***
SOCKET sd;
sd = socket (AF_INET, SOCK_STREAM, 0);
struct sockaddr_in sa;
memset (&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr ("172.27.0.189"); // sparda-bank
sa.sin_port = htons(1420);
err = connect(sd, (struct sockaddr*) &sa, sizeof(sa));
if (err) { printf("cannot connect\n"); return; }
// *** Start SSL negotiation ***
SSL* ssl = SSL_new (ctx);
SSL_set_fd (ssl, sd);
err = SSL_connect (ssl);
// Cipher, Certificate
printf ("SSL connection using %s\n", SSL_get_cipher (ssl));
X509* server_cert = SSL_get_peer_certificate (ssl);
printf ("\nServer certificate:\n");
char *subject = X509_NAME_oneline (X509_get_subject_name (server_cert),0,0);
char *issuer = X509_NAME_oneline (X509_get_issuer_name (server_cert),0,0);
printf ("\nsubject: %s\n\nissuer: %s\n\n", subject, issuer);
// Free (subject);
// Free (issuer);
X509_free (server_cert);
// *** Send a message and receive a reply ***
char *txt;
txt="GET / HTTP/1.0\n\n";
err = SSL_write (ssl, txt, strlen(txt)); // <<---------- here I get -1 ----------
printf("%d\n",err);
char buf[4096];
err = SSL_read (ssl, buf, sizeof(buf)-1);
buf[err] = 0;
printf ("Got %d chars:'%s'\n", err, buf);
// *** Clean up ***
SSL_shutdown (ssl);
close (sd);
SSL_free (ssl);
SSL_CTX_free (ctx);
#ifdef WIN32
WSACleanup();
#endif
}
Danke für deine Antwort.