From ca08c1e5531af7a19b38d1034780ff751589ce9a Mon Sep 17 00:00:00 2001 From: Mark Hymers Date: Fri, 23 May 2008 14:58:18 -0500 Subject: [PATCH] Add support for ssl client certificates This patch adds sslclientcert and sslclientkey configuration options which are passed through to imaplib in order to allow the use of client certificates for authentication. Tue Nov 13 14:44:17 CST 2007 Mark Hymers --- offlineimap.conf | 6 ++++++ offlineimap/imapserver.py | 13 ++++++++++--- offlineimap/repository/IMAP.py | 6 ++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/offlineimap.conf b/offlineimap.conf index e7b80a8..996fe7a 100644 --- a/offlineimap.conf +++ b/offlineimap.conf @@ -221,6 +221,12 @@ remotehost = examplehost # Whether or not to use SSL. ssl = yes +# SSL Client certificate (optional) +# sslclientcert = /path/to/file.crt + +# SSL Client key (optional) +# sslclientkey = /path/to/file.key + # Specify the port. If not specified, use a default port. # remoteport = 993 diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py index 4e37ece..7d99e19 100644 --- a/offlineimap/imapserver.py +++ b/offlineimap/imapserver.py @@ -72,7 +72,7 @@ class IMAPServer: def __init__(self, config, reposname, username = None, password = None, hostname = None, port = None, ssl = 1, maxconnections = 1, tunnel = None, - reference = '""'): + reference = '""', sslclientcert = None, sslclientkey = None): self.reposname = reposname self.config = config self.username = username @@ -83,6 +83,8 @@ class IMAPServer: self.tunnel = tunnel self.port = port self.usessl = ssl + self.sslclientcert = sslclientcert + self.sslclientkey = sslclientkey self.delim = None self.root = None if port == None: @@ -218,7 +220,8 @@ class IMAPServer: success = 1 elif self.usessl: UIBase.getglobalui().connecting(self.hostname, self.port) - imapobj = UsefulIMAP4_SSL(self.hostname, self.port) + imapobj = UsefulIMAP4_SSL(self.hostname, self.port, + self.sslclientkey, self.sslclientcert) else: UIBase.getglobalui().connecting(self.hostname, self.port) imapobj = UsefulIMAP4(self.hostname, self.port) @@ -360,6 +363,8 @@ class ConfigedIMAPServer(IMAPServer): user = self.repos.getuser() port = self.repos.getport() ssl = self.repos.getssl() + sslclientcert = self.repos.getsslclientcert() + sslclientkey = self.repos.getsslclientkey() reference = self.repos.getreference() server = None password = None @@ -379,4 +384,6 @@ class ConfigedIMAPServer(IMAPServer): IMAPServer.__init__(self, self.config, self.repos.getname(), user, password, host, port, ssl, self.repos.getmaxconnections(), - reference = reference) + reference = reference, + sslclientcert = sslclientcert, + sslclientkey = sslclientkey) diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py index 8587040..e5be9ee 100644 --- a/offlineimap/repository/IMAP.py +++ b/offlineimap/repository/IMAP.py @@ -125,6 +125,12 @@ class IMAPRepository(BaseRepository): def getssl(self): return self.getconfboolean('ssl', 0) + def getsslclientcert(self): + return self.getconf('sslclientcert', None) + + def getsslclientkey(self): + return self.getconf('sslclientkey', None) + def getpreauthtunnel(self): return self.getconf('preauthtunnel', None)