+2001-07-20 [christoph]
+
+ * src/Makefile.am
+ * src/inc.c
+ * src/main.[ch]
+ * src/socket.h
+ * src/ssl.[ch] (new)
+ moved ssl stuff to a seperate file
+
2001-07-20 [darko]
* src/summaryview.c
editvcard.c editvcard.h \
editjpilot.c editjpilot.h \
editldap.c editldap.h \
- editldap_basedn.c editldap_basedn.h
+ editldap_basedn.c editldap_basedn.h \
+ ssl.c ssl.h
EXTRA_DIST = \
quote_fmt_parse.h \
#ifdef USE_SSL
if(pop3_state->ac_prefs->pop_ssl) {
- X509 *server_cert;
-
- if(ssl_ctx == NULL) {
- log_warning(_("SSL not available\n"));
-
+ if(!ssl_init_socket(sockinfo)) {
pop3_automaton_terminate(NULL, atm);
automaton_destroy(atm);
return INC_ERROR;
}
-
- sockinfo->ssl = SSL_new(ssl_ctx);
- if(sockinfo->ssl == NULL) {
- log_warning(_("Error creating ssl context\n"));
-
- pop3_automaton_terminate(NULL, atm);
- automaton_destroy(atm);
-
- return INC_ERROR;
- }
- SSL_set_fd(sockinfo->ssl, sockinfo->sock);
- if(SSL_connect(sockinfo->ssl) == -1) {
- log_warning(_("SSL connect failed\n"));
-
- pop3_automaton_terminate(NULL, atm);
- automaton_destroy(atm);
-
- return INC_ERROR;
- }
-
- /* Get the cipher */
-
- log_print(_("SSL connection using %s\n"), SSL_get_cipher(sockinfo->ssl));
-
- /* Get server's certificate (note: beware of dynamic allocation) */
-
- if((server_cert = SSL_get_peer_certificate(sockinfo->ssl)) != NULL) {
- char *str;
-
- log_print(_("Server certificate:\n"));
-
- if((str = X509_NAME_oneline(X509_get_subject_name (server_cert),0,0)) != NULL) {
- log_print(_(" Subject: %s\n"), str);
- free(str);
- }
-
- if((str = X509_NAME_oneline(X509_get_issuer_name (server_cert),0,0)) != NULL) {
- log_print(_(" Issuer: %s\n"), str);
- free(str);
- }
-
- X509_free(server_cert);
- }
} else {
sockinfo->ssl = NULL;
}
#endif
#if USE_SSL
- if(sockinfo->ssl) {
- SSL_free(sockinfo->ssl);
- }
+ ssl_done_socket(sockinfo);
#endif
automaton_destroy(atm);
# include <gpgme.h>
#endif
+#if USE_SSL
+# include "ssl.h"
+#endif
+
#include "intl.h"
#include "main.h"
#include "mainwindow.h"
static gint lock_socket = -1;
static gint lock_socket_tag = 0;
-#if USE_SSL
-SSL_CTX *ssl_ctx;
-#endif
-
static struct Cmd {
gboolean receive;
gboolean receive_all;
#endif
#if USE_SSL
- {
- SSL_METHOD *meth;
-
- SSLeay_add_ssl_algorithms();
- meth = SSLv2_client_method();
- SSL_load_error_strings();
- ssl_ctx = SSL_CTX_new(meth);
- if(ssl_ctx == NULL) {
- debug_print(_("SSL disabled\n"));
- } else {
- debug_print(_("SSL loaded: \n"));
- }
- }
+ ssl_init();
#endif
prefs_common_save_config();
gtk_main();
#if USE_SSL
- if(ssl_ctx) {
- SSL_CTX_free(ssl_ctx);
- }
+ ssl_done();
#endif
return 0;
#include <glib.h>
#include <gtk/gtkwidget.h>
-#ifdef USE_SSL
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#endif
-
extern gchar *prog_version;
extern gchar *startup_dir;
extern gboolean debug_mode;
-#ifdef USE_SSL
-extern SSL_CTX *ssl_ctx;
-#endif
-
void app_will_exit (GtkWidget *widget, gpointer data);
#endif /* __MAIN_H__ */
# include <pthread.h>
#endif
+typedef struct _SockInfo SockInfo;
+
#if USE_SSL
-# include <openssl/crypto.h>
-# include <openssl/x509.h>
-# include <openssl/pem.h>
-# include <openssl/ssl.h>
-# include <openssl/err.h>
+# include "ssl.h"
#endif
-typedef struct _SockInfo SockInfo;
-
typedef enum
{
CONN_READY,
--- /dev/null
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#if USE_SSL
+
+#include "intl.h"
+#include "utils.h"
+#include "ssl.h"
+
+SSL_CTX *ssl_ctx;
+
+void ssl_init() {
+ SSL_METHOD *meth;
+
+ SSLeay_add_ssl_algorithms();
+ meth = SSLv2_client_method();
+ SSL_load_error_strings();
+ ssl_ctx = SSL_CTX_new(meth);
+ if(ssl_ctx == NULL) {
+ debug_print(_("SSL disabled\n"));
+ } else {
+ debug_print(_("SSL loaded: \n"));
+ }
+}
+
+void ssl_done() {
+ if(ssl_ctx) {
+ SSL_CTX_free(ssl_ctx);
+ }
+}
+
+gboolean ssl_init_socket(SockInfo *sockinfo) {
+ X509 *server_cert;
+
+ if(ssl_ctx == NULL) {
+ log_warning(_("SSL not available\n"));
+
+ return FALSE;
+ }
+
+ sockinfo->ssl = SSL_new(ssl_ctx);
+ if(sockinfo->ssl == NULL) {
+ log_warning(_("Error creating ssl context\n"));
+
+ return FALSE;
+ }
+ SSL_set_fd(sockinfo->ssl, sockinfo->sock);
+ if(SSL_connect(sockinfo->ssl) == -1) {
+ log_warning(_("SSL connect failed\n"));
+
+ return FALSE;
+ }
+
+ /* Get the cipher */
+
+ log_print(_("SSL connection using %s\n"), SSL_get_cipher(sockinfo->ssl));
+
+ /* Get server's certificate (note: beware of dynamic allocation) */
+
+ if((server_cert = SSL_get_peer_certificate(sockinfo->ssl)) != NULL) {
+ char *str;
+
+ log_print(_("Server certificate:\n"));
+
+ if((str = X509_NAME_oneline(X509_get_subject_name (server_cert),0,0)) != NULL) {
+ log_print(_(" Subject: %s\n"), str);
+ free(str);
+ }
+
+ if((str = X509_NAME_oneline(X509_get_issuer_name (server_cert),0,0)) != NULL) {
+ log_print(_(" Issuer: %s\n"), str);
+ free(str);
+ }
+
+ X509_free(server_cert);
+ }
+}
+
+void ssl_done_socket(SockInfo *sockinfo) {
+ if(sockinfo->ssl) {
+ SSL_free(sockinfo->ssl);
+ }
+}
+
+#endif /* USE_SSL */
\ No newline at end of file
--- /dev/null
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#if USE_SSL
+
+#ifndef __SSL_H__
+#define __SSL_H__
+
+#include <openssl/crypto.h>
+#include <openssl/x509.h>
+#include <openssl/pem.h>
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+
+#include "socket.h"
+
+void ssl_init();
+void ssl_done();
+gboolean ssl_init_socket(SockInfo *sockinfo);
+void ssl_done_socket(SockInfo *sockinfo);
+
+#endif /* __SSL_H__ */
+
+#endif /* USE_SSL */