]> code.citadel.org Git - citadel.git/blobdiff - citadel/client_crypto.c
* Full-screen curses support for Citadel text client
[citadel.git] / citadel / client_crypto.c
index 5b1aba58396ebb5372833423b8b5090290a51963..73b58658b8773916503ee56f6b05b1a3f9f6301b 100644 (file)
@@ -13,6 +13,7 @@
 #include <sys/types.h>
 #include "citadel.h"
 #include "client_crypto.h"
+#include "screen.h"
 
 #ifdef HAVE_OPENSSL
 SSL *ssl;
@@ -42,7 +43,7 @@ void serv_read_ssl(char *buf, int bytes)
        while (len < bytes) {
                if (SSL_want_read(ssl)) {
                        if ((SSL_write(ssl, junk, 0)) < 1) {
-                               fprintf(stderr, "SSL_write in serv_read:\n");
+                               err_printf("SSL_write in serv_read:\n");
                                ERR_print_errors_fp(stderr);
                        }
                }
@@ -62,7 +63,7 @@ void serv_read_ssl(char *buf, int bytes)
                                serv_read(&buf[len], bytes - len);
                                return;
                        }
-                       fprintf(stderr, "SSL_read in serv_read:\n");
+                       err_printf("SSL_read in serv_read:\n");
                        ERR_print_errors_fp(stderr);
                        connection_died();
                        return;
@@ -84,7 +85,7 @@ void serv_write_ssl(char *buf, int nbytes)
        while (bytes_written < nbytes) {
                if (SSL_want_write(ssl)) {
                        if ((SSL_read(ssl, junk, 0)) < 1) {
-                               fprintf(stderr, "SSL_read in serv_write:\n");
+                               err_printf("SSL_read in serv_write:\n");
                                ERR_print_errors_fp(stderr);
                        }
                }
@@ -106,7 +107,7 @@ void serv_write_ssl(char *buf, int nbytes)
                                                nbytes - bytes_written);
                                return;
                        }
-                       fprintf(stderr, "SSL_write in serv_write:\n");
+                       err_printf("SSL_write in serv_write:\n");
                        ERR_print_errors_fp(stderr);
                        connection_died();
                        return;
@@ -162,13 +163,13 @@ int starttls(void)
        ssl_method = SSLv23_client_method();
        ssl_ctx = SSL_CTX_new(ssl_method);
        if (!ssl_ctx) {
-               fprintf(stderr, "SSL_CTX_new failed: %s\n",
+               err_printf("SSL_CTX_new failed: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                return 0;
        }
        /* Any reasonable cipher we can get */
        if (!(SSL_CTX_set_cipher_list(ssl_ctx, CIT_CIPHERS))) {
-               fprintf(stderr, "No ciphers available for encryption\n");
+               err_printf("No ciphers available for encryption\n");
                SSL_CTX_free(ssl_ctx);
                ssl_ctx = NULL;
                return 0;
@@ -178,17 +179,17 @@ int starttls(void)
        /* Load DH parameters into the context */
        dh = DH_new();
        if (!dh) {
-               fprintf(stderr, "Can't allocate a DH object: %s\n",
+               err_printf("Can't allocate a DH object: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                return 0;
        }
        if (!(BN_hex2bn(&(dh->p), DH_P))) {
-               fprintf(stderr, "Can't assign DH_P: %s\n",
+               err_printf("Can't assign DH_P: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                return 0;
        }
        if (!(BN_hex2bn(&(dh->g), DH_G))) {
-               fprintf(stderr, "Can't assign DH_G: %s\n",
+               err_printf("Can't assign DH_G: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                return 0;
        }
@@ -221,7 +222,7 @@ int starttls(void)
        /* New SSL object */
        ssl = SSL_new(ssl_ctx);
        if (!ssl) {
-               fprintf(stderr, "SSL_new failed: %s\n",
+               err_printf("SSL_new failed: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                SSL_CTX_free(ssl_ctx);
                ssl_ctx = NULL;
@@ -232,13 +233,13 @@ int starttls(void)
        SSL_set_session_id_context(ssl, "Citadel/UX SID", 14);
 #endif
        if (!RAND_status()) {
-               fprintf(stderr, "PRNG not properly seeded\n");
+               err_printf("PRNG not properly seeded\n");
                return 0;
        }
 
        /* Associate network connection with SSL object */
        if (SSL_set_fd(ssl, serv_sock) < 1) {
-               fprintf(stderr, "SSL_set_fd failed: %s\n",
+               err_printf("SSL_set_fd failed: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                SSL_CTX_free(ssl_ctx);
                ssl_ctx = NULL;
@@ -247,20 +248,20 @@ int starttls(void)
                return 0;
        }
 
-       printf("Requesting encryption...\r");
-       fflush(stdout);
+       sln_printf("Requesting encryption...\r");
+       sln_flush();
 
        /* Ready to start SSL/TLS */
        serv_puts("STLS");
        serv_gets(buf);
        if (buf[0] != '2') {
-               fprintf(stderr, "Server can't start TLS: %s\n", &buf[4]);
+               err_printf("Server can't start TLS: %s\n", &buf[4]);
                return 0;
        }
 
        /* Do SSL/TLS handshake */
        if ((a = SSL_connect(ssl)) < 1) {
-               fprintf(stderr, "SSL_connect failed: %s\n",
+               err_printf("SSL_connect failed: %s\n",
                                ERR_reason_error_string(ERR_get_error()));
                SSL_CTX_free(ssl_ctx);
                ssl_ctx = NULL;
@@ -273,7 +274,7 @@ int starttls(void)
                int bits, alg_bits;
 
                bits = SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &alg_bits);
-               printf("Encrypting with %s cipher %s (%d of %d bits)\n",
+               sln_printf("Encrypting with %s cipher %s (%d of %d bits)\n",
                                SSL_CIPHER_get_version(SSL_get_current_cipher(ssl)),
                                SSL_CIPHER_get_name(SSL_get_current_cipher(ssl)),
                                bits, alg_bits);