Hello,
I am trying to connect via SSL using the crypto/tls package but I
always got handshake failed error with no more information.
How could I know why it is not working?
For info here is my code :
In Go wich alway return handshake error:
package main
import (
"crypto/tls"
"log"
)
func main() {
conn, err := tls.Dial("tcp", "", "
216.52.236.112:5680")
if conn != nil {
log.Exitf("Error dialling : %s\n", err)
}
log.Printf("Connected.\n")
}
In C, wich is working well :
#include <stdio.h>
#include <openssl/ssl.h>
#include <arpa/inet.h>
int main() {
int sock;
int ssl_ret;
struct sockaddr_in s_in;
SSL* ssl_socket;
SSL_CTX* ctx;
int port = 0;
const char* ip = "0.0.0.0";
// Init
SSL
SSLeay_add_ssl_algorithms();
if ((ctx = SSL_CTX_new(TLSv1_client_method())) == NULL) {
fprintf(stderr, "error ssl_ctx init\n");
return (1);
}
ssl_socket = SSL_new(ctx);
// Connect to
server
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
s_in.sin_family = AF_INET;
s_in.sin_port = htons(port);
s_in.sin_addr.s_addr = inet_addr(ip);
if (connect(sock, (struct sockaddr*)&s_in, sizeof(s_in)) < 0) {
perror("connect");
return (1);
}
// Link the socket to
ssl
if (SSL_set_fd(ssl_socket, sock) == 0) {
fprintf(stderr, "set fd failed\n");
return (1);
}
// Set SSL as
client
SSL_set_connect_state(ssl_socket);
// Finalize the ssl
connection
ssl_ret = SSL_connect(ssl_socket);
if (ssl_ret <= 0) {
fprintf(stderr, "SSL Connection/handshake failed : %d\n",
SSL_get_error(ssl_socket, ssl_ret));
return (1);
}
printf("Connection established\n");
return (0);
}