/* Priorities for TLS algorithms to use. */
-#if GNUTLS_VERSION_NUMBER < 0x030400
+# if GNUTLS_VERSION_NUMBER < 0x030400
static const int protocol_priority[16] = { GNUTLS_TLS1, GNUTLS_SSL3, 0 };
static const int kx_priority[16] = {
0 };
static const int comp_priority[16] = { GNUTLS_COMP_NULL, 0 };
-#endif
+# endif
#endif /*HAVE_GNUTLS*/
#ifdef HAVE_TLS
char * ocsp_stapling = NULL;
+char * pri_string = NULL;
#endif
}
-if (!(sk = chain_from_pem_file(ocsp_stapling)))
+if (!(sk = chain_from_pem_file((const uschar *)ocsp_stapling)))
{
BIO_printf(arg, "error in cert setup\n");
return 0;
{
rc = gnutls_certificate_set_x509_key_file(x509_cred, CS certificate,
CS privatekey, GNUTLS_X509_FMT_PEM);
- if (rc < 0) gnutls_error("gnutls_certificate", rc);
+ if (rc < 0) gnutls_error(US"gnutls_certificate", rc);
}
/* Associate the parameters with the x509 credentials structure. */
gnutls_init(&session, GNUTLS_CLIENT | GNUTLS_NO_EXTENSIONS);
-#if GNUTLS_VERSION_NUMBER < 0x030400
+# if GNUTLS_VERSION_NUMBER < 0x030400
gnutls_cipher_set_priority(session, default_cipher_priority);
gnutls_compression_set_priority(session, comp_priority);
gnutls_kx_set_priority(session, kx_priority);
gnutls_mac_set_priority(session, mac_priority);
gnutls_cred_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
-#else
-gnutls_set_default_priority(session);
+# else
+if (pri_string)
+ {
+ gnutls_priority_t priority_cache;
+ const char * errpos;
+
+ gnutls_priority_init(&priority_cache, pri_string, &errpos);
+ gnutls_priority_set(session, priority_cache);
+ }
+else
+ gnutls_set_default_priority(session);
gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred);
-#endif
+# endif
gnutls_dh_set_prime_bits(session, DH_BITS);
gnutls_db_set_cache_expiration(session, ssl_session_timeout);
/* Expect incoming */
if ( strncmp(CS outbuffer, "???", 3) == 0
- && (outbuffer[3] == ' ' || outbuffer[3] == '*')
+ && (outbuffer[3] == ' ' || outbuffer[3] == '*' || outbuffer[3] == '?')
)
{
unsigned char *lineptr;
unsigned exp_eof = outbuffer[3] == '*';
+ unsigned resp_optional = outbuffer[3] == '?';
printf("%s\n", outbuffer);
n = unescape_buf(outbuffer, n);
+nextinput:
if (*inptr == 0) /* Refill input buffer */
{
+ alarm(timeout);
if (srv->tls_active)
{
- #ifdef HAVE_OPENSSL
- rc = SSL_read (srv->ssl, inbuffer, bsiz - 1);
- #endif
- #ifdef HAVE_GNUTLS
+#ifdef HAVE_OPENSSL
+ int error;
+ rc = SSL_read(srv->ssl, inbuffer, bsiz - 1);
+ if (rc <= 0)
+ switch (error = SSL_get_error(srv->ssl, rc))
+ {
+ case SSL_ERROR_ZERO_RETURN:
+ break;
+ case SSL_ERROR_SYSCALL:
+ printf("%s\n", ERR_error_string(ERR_get_error(), NULL)); break;
+ rc = -1;
+ case SSL_ERROR_SSL:
+ printf("%s\n", ERR_error_string(ERR_get_error(), NULL)); break;
+ SSL_shutdown(srv->ssl);
+ SSL_free(srv->ssl);
+ srv->tls_active = FALSE;
+ goto nextinput;
+ default:
+ printf("SSL error code %d\n", error);
+ }
+
+#endif
+#ifdef HAVE_GNUTLS
rc = gnutls_record_recv(tls_session, CS inbuffer, bsiz - 1);
- #endif
+#endif
}
else
- {
- alarm(timeout);
rc = read(srv->sock, inbuffer, bsiz);
- alarm(0);
- }
+ alarm(0);
if (rc < 0)
{
printf("Expected EOF read\n");
continue;
}
+ else if (resp_optional)
+ continue; /* next scriptline */
else
{
printf("Unexpected EOF read\n");
if (*inptr == '\n') inptr++;
}
- printf("<<< %s\n", lineptr);
if (strncmp(CS lineptr, CS outbuffer + 4, n - 4) != 0)
- {
- printf("\n******** Input mismatch ********\n");
- exit(79);
- }
+ if (resp_optional)
+ {
+ inptr = lineptr; /* consume scriptline, not inputline */
+ continue;
+ }
+ else
+ {
+ printf("<<< %s\n", lineptr);
+ printf("\n******** Input mismatch ********\n");
+ exit(79);
+ }
+
+ /* input matched script */
+
+ if (resp_optional)
+ goto nextinput; /* consume inputline, not scriptline */
+
+ printf("<<< %s\n", lineptr);
#ifdef HAVE_TLS
if (srv->sent_starttls)
{
if (lineptr[0] == '2')
{
-int rc;
unsigned int verify;
printf("Attempting to start TLS\n");
else if (strncmp(CS outbuffer, "<<< ", 4) == 0)
{
FILE * new_f;
- if (!(new_f = fopen(outbuffer+4 , "r")))
+ if (!(new_f = fopen((const char *)outbuffer+4 , "r")))
{
printf("Unable to open '%s': %s", inptr, strerror(errno));
exit(74);
"\
[-tls-on-connect]\n\
[-ocsp]\n"
+# ifdef HAVE_GNUTLS
+"\
+ [-p priority-string]\n"
+# endif
#endif
"\
[-tn] n seconds timeout\n\
}
ocsp_stapling = argv[argi++];
}
+# ifdef HAVE_GNUTLS
+ else if (strcmp(argv[argi], "-p") == 0)
+ {
+ if (argc < ++argi + 1)
+ {
+ fprintf(stderr, "Missing priority string\n");
+ exit(96);
+ }
+ pri_string = argv[argi++];
+ }
+#endif
#endif
else if (argv[argi][1] == 't' && isdigit(argv[argi][2]))
#ifdef HAVE_GNUTLS
if (certfile != NULL) printf("Certificate file = %s\n", certfile);
if (keyfile != NULL) printf("Key file = %s\n", keyfile);
-tls_init(certfile, keyfile);
+tls_init(US certfile, US keyfile);
tls_session = tls_session_init();
#ifdef HAVE_OCSP
if (ocsp_stapling)
printf("End of script\n");
shutdown(srv.sock, SHUT_WR);
-while (read(srv.sock, inbuffer, sizeof(inbuffer)) > 0) ;
+if (fcntl(srv.sock, F_SETFL, O_NONBLOCK) == 0)
+ while (read(srv.sock, inbuffer, sizeof(inbuffer)) > 0) ;
close(srv.sock);
exit(0);