From 3bd3279206fd796fc2247c62e1c4501bc536ee5e Mon Sep 17 00:00:00 2001 From: Kenneth Giusti Date: Thu, 3 Sep 2015 15:20:05 -0400 Subject: [PATCH] Add SASL/SSL configuration options to examples --- examples/recv.py | 22 ++++++++++++++++++++++ examples/send.py | 22 ++++++++++++++++++++++ examples/server.py | 12 +++++++----- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/examples/recv.py b/examples/recv.py index c263462..98b9806 100755 --- a/examples/recv.py +++ b/examples/recv.py @@ -89,12 +89,22 @@ def main(argv=None): help="enable protocol tracing") parser.add_option("--ca", help="Certificate Authority PEM file") + parser.add_option("--ssl-cert-file", + help="Self-identifying certificate (PEM file)") + parser.add_option("--ssl-key-file", + help="Key for self-identifying certificate (PEM file)") + parser.add_option("--ssl-key-password", + help="Password to unlock SSL key file") parser.add_option("--username", type="string", help="User Id for authentication") parser.add_option("--password", type="string", help="User password for authentication") parser.add_option("--sasl-mechs", type="string", help="The list of acceptable SASL mechs") + parser.add_option("--sasl-config-dir", type="string", + help="Path to directory containing sasl config") + parser.add_option("--sasl-config-name", type="string", + help="Name of the sasl config file (without '.config')") opts, extra = parser.parse_args(args=argv) if opts.debug: @@ -111,6 +121,10 @@ def main(argv=None): conn_properties["x-trace-protocol"] = True if opts.ca: conn_properties["x-ssl-ca-file"] = opts.ca + if opts.ssl_cert_file: + conn_properties["x-ssl-identity"] = (opts.ssl_cert_file, + opts.ssl_key_file, + opts.ssl_key_password) if opts.idle_timeout: conn_properties["idle-time-out"] = opts.idle_timeout if opts.username: @@ -119,6 +133,10 @@ def main(argv=None): conn_properties['x-password'] = opts.password if opts.sasl_mechs: conn_properties['x-sasl-mechs'] = opts.sasl_mechs + if opts.sasl_config_dir: + conn_properties["x-sasl-config-dir"] = opts.sasl_config_dir + if opts.sasl_config_name: + conn_properties["x-sasl-config-name"] = opts.sasl_config_name c_handler = pyngus.ConnectionEventHandler() connection = container.create_connection("receiver", @@ -146,6 +164,10 @@ def main(argv=None): else: print("Receive failed due to connection failure!") + # flush any remaining output before closing (optional) + while connection.has_output > 0: + process_connection(connection, my_socket) + receiver.close() connection.close() diff --git a/examples/send.py b/examples/send.py index 4ffeade..93d95b0 100755 --- a/examples/send.py +++ b/examples/send.py @@ -78,12 +78,22 @@ def main(argv=None): help="enable protocol tracing") parser.add_option("--ca", help="Certificate Authority PEM file") + parser.add_option("--ssl-cert-file", + help="Self-identifying certificate (PEM file)") + parser.add_option("--ssl-key-file", + help="Key for self-identifying certificate (PEM file)") + parser.add_option("--ssl-key-password", + help="Password to unlock SSL key file") parser.add_option("--username", type="string", help="User Id for authentication") parser.add_option("--password", type="string", help="User password for authentication") parser.add_option("--sasl-mechs", type="string", help="The list of acceptable SASL mechs") + parser.add_option("--sasl-config-dir", type="string", + help="Path to directory containing sasl config") + parser.add_option("--sasl-config-name", type="string", + help="Name of the sasl config file (without '.config')") opts, payload = parser.parse_args(args=argv) if not payload: @@ -103,6 +113,10 @@ def main(argv=None): conn_properties["x-trace-protocol"] = True if opts.ca: conn_properties["x-ssl-ca-file"] = opts.ca + if opts.ssl_cert_file: + conn_properties["x-ssl-identity"] = (opts.ssl_cert_file, + opts.ssl_key_file, + opts.ssl_key_password) if opts.idle_timeout: conn_properties["idle-time-out"] = opts.idle_timeout if opts.username: @@ -111,6 +125,10 @@ def main(argv=None): conn_properties['x-password'] = opts.password if opts.sasl_mechs: conn_properties['x-sasl-mechs'] = opts.sasl_mechs + if opts.sasl_config_dir: + conn_properties["x-sasl-config-dir"] = opts.sasl_config_dir + if opts.sasl_config_name: + conn_properties["x-sasl-config-name"] = opts.sasl_config_name c_handler = ConnectionEventHandler() connection = container.create_connection("sender", @@ -151,6 +169,10 @@ def main(argv=None): else: print("Send failed due to connection failure!") + # flush any remaining output before closing (optional) + while connection.has_output > 0: + process_connection(connection, my_socket) + sender.close() connection.close() diff --git a/examples/server.py b/examples/server.py index 105380d..ccd4a72 100755 --- a/examples/server.py +++ b/examples/server.py @@ -245,19 +245,21 @@ def main(argv=None): help="enable protocol tracing") parser.add_option("--debug", dest="debug", action="store_true", help="enable debug logging") - parser.add_option("--cert", + parser.add_option("--ca", + help="Certificate Authority PEM file") + parser.add_option("--cert", "--ssl-cert-file", help="PEM File containing the server's certificate") - parser.add_option("--key", + parser.add_option("--key", "--ssl-key-file", help="PEM File containing the server's private key") - parser.add_option("--keypass", + parser.add_option("--keypass", "--ssl-key-password", help="Password used to decrypt key file") parser.add_option("--require-auth", action="store_true", help="Require clients to authenticate") parser.add_option("--sasl-mechs", type="string", help="The list of acceptable SASL mechs") - parser.add_option("--sasl-cfg-name", type="string", + parser.add_option("--sasl-cfg-name", "--sasl-config-name", type="string", help="name of SASL config file (no suffix)") - parser.add_option("--sasl-cfg-dir", type="string", + parser.add_option("--sasl-cfg-dir", "--sasl-config-dir", type="string", help="Path to the SASL config file") opts, arguments = parser.parse_args(args=argv)