[PATCH] Sanity checks for SSL cacertfile configuration

Sebastian Spaeth Sebastian at SSpaeth.de
Tue Mar 15 10:18:19 GMT 2011


We were not able to handle ~/... type of path configurations and we
crashed with mysterious SSL errors when no file was found at the
configured location. Expand '~' and bomb out with usable error messages
in case such a file does not exist. This will still not protect against
corrupt cacert files but it goes a long way towards user friendliness.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
This patch is against current next branch but will proably apply to 
master too. This is also a request that came up earlier on this list
(protect against misconfigurations).

 offlineimap/repository/IMAP.py |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py
index c4066d5..18e3b4e 100644
--- a/offlineimap/repository/IMAP.py
+++ b/offlineimap/repository/IMAP.py
@@ -141,7 +141,17 @@ class IMAPRepository(BaseRepository):
         return self.getconf('sslclientkey', None)
 
     def getsslcacertfile(self):
-        return self.getconf('sslcacertfile', None)
+        """Return the absolute path of the CA certfile to use, if any"""
+        cacertfile = self.getconf('sslcacertfile', None)
+        if cacertfile is None:
+            return None
+        cacertfile = os.path.expanduser(cacertfile)
+        cacertfile = os.path.abspath(cacertfile)
+        if not os.path.isfile(cacertfile):
+            raise SyntaxWarning("CA certfile for repository '%s' could "
+                                "not be found. No such file: '%s'" \
+                                % (self.name, cacertfile))
+        return cacertfile
 
     def getpreauthtunnel(self):
         return self.getconf('preauthtunnel', None)
-- 
1.7.1





More information about the OfflineIMAP-project mailing list