diff options
author | Bruno Wagner <bwgpro@gmail.com> | 2015-06-15 16:40:19 -0300 |
---|---|---|
committer | Bruno Wagner <bwgpro@gmail.com> | 2015-06-15 16:40:29 -0300 |
commit | 1af60867f8f85f87d2186a66ce911392d7b08a05 (patch) | |
tree | 8e69dd7c496fef01f0f9bfa8fd29c596f6314e67 /service/pixelated | |
parent | 96616d25a0f4abf1b4c4c9360a5aa8de1ecfad79 (diff) |
Register now understands fingerprint and certificate arguments again
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/config/arguments.py | 5 | ||||
-rw-r--r-- | service/pixelated/register.py | 27 |
2 files changed, 24 insertions, 8 deletions
diff --git a/service/pixelated/config/arguments.py b/service/pixelated/config/arguments.py index 72ae6141..56f83421 100644 --- a/service/pixelated/config/arguments.py +++ b/service/pixelated/config/arguments.py @@ -24,6 +24,7 @@ def parse_user_agent_args(): parser_add_default_arguments(parser) parser.add_argument('--host', default='127.0.0.1', help='the host to run the user agent on') + parser.add_argument('--organization-mode', help='Runs the user agent in organization mode, the credentials will be received from the stdin', default=False, action='store_true', dest='organization_mode') parser.add_argument('--port', type=int, default=3333, help='the port to run the user agent on') parser.add_argument('-sk', '--sslkey', metavar='<server.key>', default=None, help='use specified file as web server\'s SSL key (when using the user-agent together with the pixelated-dispatcher)') parser.add_argument('-sc', '--sslcert', metavar='<server.crt>', default=None, help='use specified file as web server\'s SSL certificate (when using the user-agent together with the pixelated-dispatcher)') @@ -50,12 +51,14 @@ def parse_register_args(): parser = argparse.ArgumentParser(description='Pixelated register') parser.add_argument('provider', metavar='provider', action='store') parser.add_argument('username', metavar='username', action='store') + parser.add_argument('-lc', '--leap-provider-cert', metavar='<leap-provider.crt>', default=None, help='use specified file for LEAP provider cert authority certificate (url https://<LEAP-provider-domain>/ca.crt)') + parser.add_argument('-lf', '--leap-provider-cert-fingerprint', metavar='<leap provider certificate fingerprint>', default=None, help='use specified fingerprint to validate connection with LEAP provider', dest='leap_provider_cert_fingerprint') + parser.add_argument('--leap-home', help='The folder where the user agent stores its data. Defaults to ~/.leap', dest='leap_home', default=os.path.join(os.path.expanduser("~"), '.leap')) return parser.parse_args() def parser_add_default_arguments(parser): parser.add_argument('--debug', action='store_true', help='DEBUG mode.') - parser.add_argument('--organization-mode', help='Runs the user agent in organization mode, the credentials will be received from the stdin', default=False, action='store_true', dest='organization_mode') parser.add_argument('-c', '--config', dest='credentials_file', metavar='<credentials_file>', default=None, help='use specified file for credentials (for test purposes only)') parser.add_argument('--leap-home', help='The folder where the user agent stores its data. Defaults to ~/.leap', dest='leap_home', default=os.path.join(os.path.expanduser("~"), '.leap')) parser.add_argument('-lc', '--leap-provider-cert', metavar='<leap-provider.crt>', default=None, help='use specified file for LEAP provider cert authority certificate (url https://<LEAP-provider-domain>/ca.crt)') diff --git a/service/pixelated/register.py b/service/pixelated/register.py index 47c9c3f5..11ec9b1f 100644 --- a/service/pixelated/register.py +++ b/service/pixelated/register.py @@ -17,31 +17,39 @@ import re import getpass import logging -from pixelated.bitmask_libraries import session as leap_session from pixelated.config import arguments from pixelated.config import logger as logger_config from pixelated.bitmask_libraries.certs import LeapCertificate from pixelated.bitmask_libraries.config import LeapConfig from pixelated.bitmask_libraries.provider import LeapProvider +from pixelated.bitmask_libraries.session import LeapSessionFactory from leap.auth import SRPAuth logger = logging.getLogger(__name__) -def register(server_name, username): +def register( + server_name, + username, + leap_home, + provider_cert, + provider_cert_fingerprint): + try: validate_username(username) except ValueError: print('Only lowercase letters, digits, . - and _ allowed.') - config = LeapConfig() - provider = LeapProvider(server_name, config) password = getpass.getpass('Please enter password for %s: ' % username) + + LeapCertificate.set_cert_and_fingerprint(provider_cert, provider_cert_fingerprint) + config = LeapConfig(leap_home=leap_home) + provider = LeapProvider(server_name, config) + LeapCertificate(provider).setup_ca_bundle() srp_auth = SRPAuth(provider.api_uri, LeapCertificate(provider).provider_api_cert) if srp_auth.register(username, password): - session = leap_session.open_leap_session(username, password, server_name) - session.nicknym.generate_openpgp_key() + session = LeapSessionFactory(provider).create(username, password) else: logger.error("Register failed") @@ -55,4 +63,9 @@ def validate_username(username): def initialize(): logger_config.init(debug=False) args = arguments.parse_register_args() - register(args.provider, args.username) + register( + args.provider, + args.username, + args.leap_home, + args.leap_provider_cert, + args.leap_provider_cert_fingerprint) |