Package transports :: Module m2crypto
[hide private]

Source Code for Module transports.m2crypto

 1  # Officeshots.org - Test your office documents in different applications 
 2  # Copyright (C) 2009 Stichting Lone Wolves 
 3  # Written by Sander Marechal <s.marechal@jejik.com> 
 4  # 
 5  # This program is free software: you can redistribute it and/or modify 
 6  # it under the terms of the GNU Affero General Public License as 
 7  # published by the Free Software Foundation, either version 3 of the 
 8  # License, or (at your option) any later version. 
 9  # 
10  # This program is distributed in the hope that it will be useful, 
11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
13  # GNU Affero General Public License for more details. 
14  # 
15  # You should have received a copy of the GNU Affero General Public License 
16  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
17   
18  """ 
19  This module provides SSLTransport in order to have SSL client authentication 
20  with the standard xmlrpclib. It is based on the M2Crypto library 
21  """ 
22   
23  from M2Crypto import m2xmlrpclib, SSL 
24   
25 -class SSLTransport(m2xmlrpclib.SSL_Transport):
26 """ 27 An SSL-capable transport based off M2Crypto's SSL_Transport 28 """ 29
30 - def __init__(self, key_file, cert_file):
31 ctx = SSL.Context() 32 ctx.load_cert(key_file, cert_file) 33 m2xmlrpclib.SSL_Transport.__init__(self, ctx)
34
35 - def request(self, host, handler, request_body, verbose=0):
36 """ 37 Override m2xmlrpclib.request() because it cannot handle an URL 38 without a port number 39 """ 40 if host.find(':') == -1: 41 host = host + ':443' 42 43 return m2xmlrpclib.SSL_Transport.request(self, host, handler, request_body, verbose)
44