无法在两个Intel Edison之间创建SSL连接

时间:2017-06-26 21:52:09

标签: c ssl intel-edison

我正在尝试让两个英特尔Edison通过SSL连接进行通信。其中一个将作为服务器,另一个应作为客户端。但是,我无法让客户端连接到服务器(一切都编译并且没有运行时错误:它只是没有连接)并且无法弄清楚发生了什么。 (我是OpenSSL的新手)。感谢。

以下是客户端代码无效的部分:

int create_socket(char *url_str, BIO *out) {
  int sockfd;
  char hostname[256] = "";
  char    portnum[4] = "5000";
  char      proto[6] = "";
  char      *tmp_ptr = NULL;
  int           port;
  struct hostent *host;
  struct sockaddr_in dest_addr;

  port = atoi(portnum);

  if ( (host = gethostbyname(url_str)) == NULL ) {
    BIO_printf(out, "Error: Cannot resolve hostname %s.\n",  hostname);
    abort();
  }

  sockfd = socket(AF_INET, SOCK_STREAM, 0);

  dest_addr.sin_family=AF_INET;
  dest_addr.sin_port=htons(port);
  inet_aton(url_str, &dest_addr.sin_addr);

  memset(&(dest_addr.sin_zero), '\0', 8);

  tmp_ptr = inet_ntoa(dest_addr.sin_addr);


  if (connect(sockfd, (struct sockaddr *) &dest_addr, sizeof(struct sockaddr)) == -1 ) {
    BIO_printf(out, "Error: Cannot connect to host %s [%s] on port %d.\n", hostname, tmp_ptr, port);
  }

  return sockfd;
}

int main(int argc, char *argv[]){
  char*           dest_url = argv[1];
  BIO              *certbio = NULL;
  BIO               *outbio = NULL;
  X509                *cert = NULL;
  X509_NAME       *certname = NULL;
  const SSL_METHOD *method;
  SSL_CTX *ctx;
  SSL *ssl;
  int server = 0;
  int ret, i;

  OpenSSL_add_all_algorithms();
  ERR_load_BIO_strings();
  ERR_load_crypto_strings();
  SSL_load_error_strings();

  certbio = BIO_new(BIO_s_file());
  outbio  = BIO_new_fp(stdout, BIO_NOCLOSE);

  SSL_library_init();
  method = SSLv23_client_method();
  ctx = SSL_CTX_new(method);
  SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2);
  ssl = SSL_new(ctx);

  server = create_socket(dest_url, outbio);
  SSL_set_fd(ssl, server);
  SSL_connect(ssl); 

  //CODE DOESN'T GET PAST HERE
}

0 个答案:

没有答案