5 /* For callbacks generating output, here are their file-descriptors. */
6 static FILE *fp_cb_ssl_info = NULL;
7 static FILE *fp_cb_ssl_verify = NULL;
9 /* Other static rubbish (to mirror s_cb.c where required) */
10 static int int_verify_depth = 10;
11 static int int_verify_error = X509_V_OK;
13 /* This function is largely borrowed from the one used in OpenSSL's "s_client"
14 * and "s_server" utilities. */
15 void cb_ssl_info(SSL *s, int where, int ret)
23 w = where & ~SSL_ST_MASK;
24 str1 = (w & SSL_ST_CONNECT ? "SSL_connect" : (w & SSL_ST_ACCEPT ?
25 "SSL_accept" : "undefined")),
26 str2 = SSL_state_string_long(s);
28 if (where & SSL_CB_LOOP)
29 fprintf(fp_cb_ssl_info, "%s:%s\n", str1, str2);
30 else if (where & SSL_CB_EXIT) {
32 fprintf(fp_cb_ssl_info, "%s:failed in %s\n", str1, str2);
34 fprintf(fp_cb_ssl_info, "%s:error in %s\n", str1, str2);
38 void cb_ssl_info_set_output(FILE *fp)
43 /* Stolen wholesale from apps/s_cb.c :-) */
44 int cb_ssl_verify(int ok, X509_STORE_CTX *ctx)
53 /* There's no <damned>FILE*</damned> version of ASN1_TIME_print */
54 bio = BIO_new_fp(fp_cb_ssl_verify, BIO_NOCLOSE);
55 err_cert = X509_STORE_CTX_get_current_cert(ctx);
56 err = X509_STORE_CTX_get_error(ctx);
57 depth = X509_STORE_CTX_get_error_depth(ctx);
59 X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256);
60 fprintf(fp_cb_ssl_verify, "depth=%d %s\n", depth, buf);
62 fprintf(fp_cb_ssl_verify,"verify error:num=%d:%s\n",err,
63 X509_verify_cert_error_string(err));
64 if((int)int_verify_depth >= depth)
65 int_verify_error = err;
67 int_verify_error = X509_V_ERR_CERT_CHAIN_TOO_LONG;
70 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
71 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),
73 fprintf(fp_cb_ssl_verify, "issuer= %s\n", buf);
75 case X509_V_ERR_CERT_NOT_YET_VALID:
76 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
77 fprintf(fp_cb_ssl_verify, "notBefore=");
78 ASN1_TIME_print(bio, X509_get_notBefore(ctx->current_cert));
79 fprintf(fp_cb_ssl_verify, "\n");
81 case X509_V_ERR_CERT_HAS_EXPIRED:
82 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
83 fprintf(fp_cb_ssl_verify, "notAfter=");
84 ASN1_TIME_print(bio, X509_get_notAfter(ctx->current_cert));
85 fprintf(fp_cb_ssl_verify, "\n");
88 fprintf(fp_cb_ssl_verify, "verify return:%d\n",ok);
92 void cb_ssl_verify_set_output(FILE *fp)
94 fp_cb_ssl_verify = fp;
97 void cb_ssl_verify_set_depth(unsigned int verify_depth)
99 int_verify_depth = verify_depth;
102 #endif /* !defined(NO_OPENSSL) */