Skip to content

Commit 04b3b07

Browse files
author
Dariusz Suchojad
committed
SESPRINGPYTHONPY-155: Updated documentation to match the simplified API.
1 parent 22e9507 commit 04b3b07

2 files changed

Lines changed: 55 additions & 56 deletions

File tree

docs/sphinx/source/remoting.rst

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ Spring Python currently supports and requires the installation of at least one o
3434
* `Hessian <http://hessian.caucho.com/>`_ - support for Hessian has just started. So far, you can call
3535
Python-to-Java based on libraries released from Caucho.
3636

37-
* :ref:`Secure XML-RPC <remoting-secure-xml-rpc>` needs the installation of
38-
`PyOpenSSL <http://pypi.python.org/pypi/pyOpenSSL>`_
39-
4037
Remoting with PYRO (Python Remote Objects)
4138
------------------------------------------
4239

@@ -478,9 +475,9 @@ implemented in other languages and technologies.
478475
To aid with better understanding of how the components work out of the box,
479476
you can download :ref:`sample keys and certificates <remoting-secure-xml-rpc-sample-keys-and-certificates>`
480477
prepared by the Spring Python team.
481-
Be sure **not** to ever use it for anything serious outside your testing environment,
482-
they are working and functional but because of private keys being available for
483-
download they should **only** be used for learning of how Spring Python's
478+
Be sure not to ever use the sample keys & certificates for anything serious outside your
479+
testing environment, they are working and functional but because of private keys being available for
480+
download they should only be used for learning of how Spring Python's
484481
secure XML-RPC works.
485482

486483
Encrypted connection only
@@ -505,9 +502,9 @@ one of CAs the client is aware of::
505502
# -*- coding: utf-8 -*-
506503

507504
# Spring Python
508-
from springpython.remoting.xmlrpc import SSLXMLRPCServer
505+
from springpython.remoting.xmlrpc import SSLServer
509506

510-
class MySSLServer(SSLXMLRPCServer):
507+
class MySSLServer(SSLServer):
511508
def __init__(self, *args, **kwargs):
512509
super(MySSLServer, self).__init__(*args, **kwargs)
513510

@@ -516,23 +513,26 @@ one of CAs the client is aware of::
516513

517514
host = "localhost"
518515
port = 8000
519-
key = "./server-key.pem"
520-
cert = "./server-cert.pem"
516+
keyfile = "./server-key.pem"
517+
certfile = "./server-cert.pem"
521518

522-
server = MySSLServer(host, port, key, cert, verify_depth=2)
519+
server = MySSLServer(host, port, keyfile, certfile)
523520
server.serve_forever()
524521

525522
::
526523

527524
# -*- coding: utf-8 -*-
528525

526+
# stdlib
527+
import ssl
528+
529529
# Spring Python
530-
from springpython.remoting.xmlrpc import SSLXMLRPCClient
530+
from springpython.remoting.xmlrpc import SSLClient
531531

532532
server_location = "https://localhost:8000/RPC2"
533533
ca_certs = "./ca-chain.pem"
534534

535-
client = SSLXMLRPCClient(server_location, ca_certs=ca_certs)
535+
client = SSLClient(server_location, ca_certs)
536536

537537
print client.pow(41, 3)
538538

@@ -549,13 +549,13 @@ known to the client::
549549

550550
# -*- coding: utf-8 -*-
551551

552-
# Spring Python
553-
from springpython.remoting.xmlrpc import SSLXMLRPCServer
552+
# stdlib
553+
import ssl
554554

555-
# PyOpenSSL
556-
from OpenSSL import SSL
555+
# Spring Python
556+
from springpython.remoting.xmlrpc import SSLServer
557557

558-
class MySSLServer(SSLXMLRPCServer):
558+
class MySSLServer(SSLServer):
559559
def __init__(self, *args, **kwargs):
560560
super(MySSLServer, self).__init__(*args, **kwargs)
561561

@@ -564,27 +564,26 @@ known to the client::
564564

565565
host = "localhost"
566566
port = 8000
567-
key = "./server-key.pem"
568-
cert = "./server-cert.pem"
567+
keyfile = "./server-key.pem"
568+
certfile = "./server-cert.pem"
569569
ca_certs = "./ca-chain.pem"
570570

571-
server = MySSLServer(host, port, key, cert, ca_certs, verify_options=SSL.VERIFY_PEER|SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
572-
verify_depth=2)
571+
server = MySSLServer(host, port, keyfile, certfile, ca_certs, cert_reqs=ssl.CERT_REQUIRED)
573572
server.serve_forever()
574573

575574
::
576575

577576
# -*- coding: utf-8 -*-
578577

579578
# Spring Python
580-
from springpython.remoting.xmlrpc import SSLXMLRPCClient
579+
from springpython.remoting.xmlrpc import SSLClient
581580

582581
server_location = "https://localhost:8000/RPC2"
583-
key = "./client-key.pem"
584-
cert = "./client-cert.pem"
582+
keyfile = "./client-key.pem"
583+
certfile = "./client-cert.pem"
585584
ca_certs = "./ca-chain.pem"
586585

587-
client = SSLXMLRPCClient(server_location, key_file=key, cert_file=cert, ca_certs=ca_certs)
586+
client = SSLClient(server_location, ca_certs, keyfile, certfile)
588587

589588
print client.pow(41, 3)
590589

@@ -596,22 +595,23 @@ Server requires the client to have a certificate and checks its fields
596595

597596
Same as above (both sides need to have certificates signed off by trusted CAs)
598597
but this time the server inspects the client certificate’s fields and lets it
599-
in only they match the configuration it was fed with. In the example below
600-
*commonName* must be *Client*, *Organization* must be *The Sample Company* and the
601-
*State* must be *New York*. Server checks for both their existance and value and
602-
if there’s any mismatch the connection won’t be established in which case the
603-
error reason will be logged on the server side but no details of the error
598+
in only if they match the configuration it was fed with. In the example below
599+
*commonName* must be *My Client*, *organizationName* must be *My Company* and the
600+
*stateOrProvinceName* must be *My State*. Server checks for both their existance and value and
601+
if there’s any mismatch the connection will be dropped (client will receive a socket
602+
error) and the error reason will be logged on the server side but no details of the error
604603
will be leaked to the client::
605604

606605
# -*- coding: utf-8 -*-
607606

608-
# Spring Python
609-
from springpython.remoting.xmlrpc import SSLXMLRPCServer
607+
# stdlib
608+
import logging
609+
import ssl
610610

611-
# PyOpenSSL
612-
from OpenSSL import SSL
611+
# Spring Python
612+
from springpython.remoting.xmlrpc import SSLServer
613613

614-
class MySSLServer(SSLXMLRPCServer):
614+
class MySSLServer(SSLServer):
615615
def __init__(self, *args, **kwargs):
616616
super(MySSLServer, self).__init__(*args, **kwargs)
617617

@@ -620,32 +620,31 @@ will be leaked to the client::
620620

621621
host = "localhost"
622622
port = 8000
623-
key = "./server-key.pem"
624-
cert = "./server-cert.pem"
625-
ca = "./ca-chain.pem"
623+
keyfile = "./server-key.pem"
624+
certfile = "./server-cert.pem"
625+
ca_certs = "./ca-chain.pem"
626+
verify_fields = {"commonName": "My Client", "organizationName":"My Company",
627+
"stateOrProvinceName":"My State"}
626628

627-
verify_fields = {"CN": "Client", "O":"The Sample Company", "ST":"New York"}
629+
logging.basicConfig(level=logging.ERROR)
628630

629-
server = MySSLServer(host, port, key, cert, ca, verify_options=SSL.VERIFY_PEER|SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
630-
verify_fields=verify_fields, verify_depth=2)
631+
server = MySSLServer(host, port, keyfile, certfile, ca_certs, cert_reqs=ssl.CERT_REQUIRED,
632+
verify_fields=verify_fields)
631633
server.serve_forever()
632634

633635
::
634636

635637
# -*- coding: utf-8 -*-
636638

637639
# Spring Python
638-
from springpython.remoting.xmlrpc import SSLXMLRPCClient
640+
from springpython.remoting.xmlrpc import SSLClient
639641

640642
server_location = "https://localhost:8000/RPC2"
641-
key = "./client-key.pem"
642-
643-
# Make sure the commonName is set to what the server requires.
644-
cert = "./client-cert.pem"
645-
643+
keyfile = "./client-key.pem"
644+
certfile = "./client-cert.pem"
646645
ca_certs = "./ca-chain.pem"
647646

648-
client = SSLXMLRPCClient(server_location, key_file=key, cert_file=cert, ca_certs=ca_certs)
647+
client = SSLClient(server_location, ca_certs, keyfile, certfile)
649648

650649
print client.pow(41, 3)
651650

src/springpython/remoting/xmlrpc.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ def setup(self):
3333
self.wfile = socket._fileobject(self.request, "wb", self.wbufsize)
3434

3535
class SSLServer(object, SimpleXMLRPCServer):
36-
def __init__(self, host=None, port=None, ca_certs=None, keyfile=None, certfile=None,
37-
cert_reqs=ssl.CERT_OPTIONAL, ssl_version=ssl.PROTOCOL_TLSv1,
36+
def __init__(self, host=None, port=None, keyfile=None, certfile=None,
37+
ca_certs=None, cert_reqs=ssl.CERT_NONE, ssl_version=ssl.PROTOCOL_TLSv1,
3838
do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None, **kwargs):
3939

4040
SimpleXMLRPCServer.__init__(self, (host, port), requestHandler=RequestHandler)
4141
self.logger = logging.getLogger(self.__class__.__name__)
4242

43-
self.ca_certs = ca_certs
4443
self.keyfile = keyfile
4544
self.certfile = certfile
45+
self.ca_certs = ca_certs
4646
self.cert_reqs = cert_reqs
4747
self.ssl_version = ssl_version
4848
self.do_handshake_on_connect = do_handshake_on_connect
@@ -56,7 +56,7 @@ def __init__(self, host=None, port=None, ca_certs=None, keyfile=None, certfile=N
5656
self.register_functions()
5757

5858
def get_request(self):
59-
""" Overridden from Socket.TCPServer.get_request, wraps the socket in
59+
""" Overridden from SocketServer.TCPServer.get_request, wraps the socket in
6060
an SSL context.
6161
"""
6262
sock, from_addr = self.socket.accept()
@@ -76,7 +76,7 @@ def get_request(self):
7676
return sock, from_addr
7777

7878
def verify_request(self, sock, from_addr):
79-
""" Overridden from Socket.TCPServer.verify_request, adds validation of the
79+
""" Overridden from SocketServer.TCPServer.verify_request, adds validation of the
8080
other side's certificate fields.
8181
"""
8282
try:
@@ -136,8 +136,8 @@ def verify_peer(self, cert):
136136
return False, reason
137137

138138
if expected_value != cert_value:
139-
reason = "Expected the subject field '%s' to have value '%s' instead of '%s'" % (
140-
verify_field, expected_value, subject)
139+
reason = "Expected the subject field '%s' to have value '%s' instead of '%s', subject='%s'" % (
140+
verify_field, expected_value, cert_value, subject)
141141
return False, reason
142142

143143
return True, None

0 commit comments

Comments
 (0)