OpenSSL Ignore Self-signed certificate error

后端 未结 6 1923
独厮守ぢ
独厮守ぢ 2021-02-19 07:42

I\'m writing a small program with the OpenSSL library that is suppose to establish a connection with an SSLv3 server. This server dispenses a self-signed certificate, which caus

6条回答
  •  忘掉有多难
    2021-02-19 08:22

    My sample client code (link) works fine with self signed server cert. I have the below code after SSL_connect and have full control over self signed certificates acceptability in my client

    SSL_CTX* ctx = SSL_CTX_new(SSLv3_method());
    
    // TCP connection and SSL handshake ...
    
    /* Check the certificate */
    
    rc = SSL_get_verify_result(ssl);
    if(rc != X509_V_OK) {
      if (rc == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT || rc == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) {
        fprintf(stderr, "self signed certificate\n");
      }
      else {
        fprintf(stderr, "Certificate verification error: %ld\n", SSL_get_verify_result(ssl));
        SSL_CTX_free(ctx);
        return 0;
      }
    }
    

提交回复
热议问题