xmlrpcssl¶
xmlprcssl is a Python library that provides secure communication (TLS) beetween clients and servers through xmlrpc protocol. It supports plugable handlers to provide user authentication. For now, it has as an example a ldap based authentication handler.
Server configuration¶
>>> from xmlrpcssl import SecureAuthenticatedXMLRPCServer
>>> from xmlrpcssl.handlers import LdapVerifyingRequestHandler
>>> from datetime import datetime
>>> KEY_SSL = '/tmp/server.key'
>>> CRT_SSL = '/tmp/server.crt'
>>> TCP_PORT = 433
>>> SERVER_IP = '10.0.0.1'
>>> LDAP_HOST = 'ldapHost' # User must have access granted to this host in ldap
>>> LDAP_SERVER = 'ldapServer' # ip or name of ldap server
>>> GIDNUMBER = 111 # User must be in this group in order to be authenticated
>>> IS_MASTER_USER = False # True if the user has write permissions in the ldap server
>>> BASE_USR_LOGIN_DN = 'o=Organization,c=US' # user base DN to perform login in
# the ldap server
>>> BASE_SEARCH_DN = 'o=Organization,c=US' # search base DN to perform a search in
# the ldap server base
>>> RequestHandler = LdapVerifyingRequestHandler # a handler that inherits from
# BaseRequestHandler and performs user authentication
>>> OPT_ARGS = {'isMasterUser': IS_MASTER_USER, 'baseUsrLoginDn': BASE_USR_LOGIN_DN,
... 'ldapServer': LDAP_SERVER, 'gidNumber': GIDNUMBER, 'baseSearchDn': BASE_SEARCH_DN,
... 'host': LDAP_HOST, 'RequestHandler': RequestHandler}
>>> server_ssl = SecureAuthenticatedXMLRPCServer((SERVER_IP, TCP_PORT), KEY_SSL,CRT_SSL,
... **OPT_ARGS)
>>> def test():
... # toy test function
... return datetime.now().strftime("%H:%M:%S")
>>> server_ssl.register_function(test)
>>> server_ssl.serve_forever()
Client configuration¶
>>> import ssl
>>> from xmlrpclib import ServerProxy
>>> USERNAME = 'ldapUser'
>>> PASSWORD = 'ldapUserPassword'
>>> TCP_PORT = 433
>>> SERVER_IP = '10.0.0.1'
>>> client_xml = ServerProxy('https://'+USERNAME+':'+PASSWORD+'@'+SERVER_IP+':'+str(TCP_PORT),
context=ssl.SSLContext(ssl.PROTOCOL_TLSv1))
>>> response = client_xml.test()
>>> print·response
Installation¶
To install xmlrpcssl, simply run:
$ pip install xmlrpcssl
xmlrpcssl is compatible with Python 2.6+
Documentation¶
Source Code¶
Feel free to fork, evaluate and contribute to this project.
License¶
GPLv3 licensed.
Credits¶
Credits go to http://code.activestate.com/recipes/496786-simple-xml-rpc-server-over-https and https://github.com/nosmo/python-xmlrpcssl for inspiration.
xmlrpcssl package contents:¶
xmlrpcssl package¶
Subpackages¶
Submodules¶
xmlrpcssl.xmlrpcssl module¶
Xmlrpc server with SSL and configurable authentication plugin method
-
class
xmlrpcssl.xmlrpcssl.
BaseRequestHandler
(req, addr, server)[source]¶ Bases:
xmlrpcssl.xmlrpcssl.SecureXMLRPCRequestHandler
Base Handler providing methods to handle xmlrpc incoming requests
-
authenticate
(headers)[source]¶ Performs user authentication
Parameters: headers ( str
) – http/https headers received from clientReturns: True if user successfully authenticated, False otherwise Return type: ret ( bool
)Returns: Error message if authentication failed, None otherwise Return type: error_msg ( str
)Returns: Error code if authentication failed, None otherwise Return type: error_code ( str
)
-
verify_user_credentials
()[source]¶ Verify the user credentials
Returns: True if user successfully authenticated, False otherwise Return type: ret ( bool
)Returns: Error message if authentication failed, None otherwise Return type: error_msg ( str
)Returns: Error code if authentication failed, None otherwise Return type: error_code ( str
)OBS: Must be overwritten with a proper authentication method in the child class
-
-
class
xmlrpcssl.xmlrpcssl.
SecureAuthenticatedXMLRPCServer
(server_address, keyfile, certfile, **kwargs)[source]¶ Bases:
BaseHTTPServer.HTTPServer
,SocketServer.BaseServer
,SimpleXMLRPCServer.SimpleXMLRPCDispatcher
Xmlrpc server secured with ssl
Parameters: - server_address (
str
) – ip address of the xmlrpc server - keyfile (
str
) – path of the ssl/tls private keyfile generated for the xmlrpc server - certfile (
str
) – path of the ssl/tls certificate file signed by the Certification Authority
Keyword Arguments: - log_requests (
str
,optional, default =True) – enable log all requests - path (
str
,optional, default =’/’) – server http path - RequestHandler (
class
,optional, default =BaseRequestHandler) – class to handle client requests - ssl_version (
int
, optional, default = ssl.PROTOCOL_TLSv1) – ssl protocol version code
- server_address (