Hi OpenSSL-developers,
I compiled OpenSSL under Win98 (VisualC++4.0, MASM).
(1)
I had to patch the following lines in openssl\crypto\asn1\a_strnid.c:
line 107: mask = (unsigned long)(~(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING));
line 109: mask = (unsigned long)(~B_ASN1_T61STRING);
(2)
I have problems with the ssl client code. I can connect a https-Server.
I get the certificate, but calling SSL_write, I get -1 returned !?!?!?
can you help me?
Thanks,
Thomas.
#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)
#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 ***
int 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 ("194.15.183.180"); // sparda-bank
sa.sin_port = htons(443);
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
}
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]