Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Domain objects hold all the data for a given domain name.
Domain names can in theory be anything, from user selected aliases to actual domain names like facebook.com or twitter.com, however the latter is probably recommended as it opens up the possiblity to automatically extract the relevant objects if the user visists the site, such as in a browser extension of similar.
:param name: The identifier for this domain. :param alpabet: The alpabet to restrict key contents to. Default: 'full' :param key_length: The length of the computed key. Can be useful if the site imposes restrictions on password length. Default: 16 """
def entropy(self):
""" Computes the key from the salt and the master password. """
# we fix the scrypt parameters in case the defaults change
""" Fetches the key for the domain. Prompts the user for password.
Thin wrapper around :func:`Domain.derive_key <pwm.core.Domain.derive_key>`. """ master_password = getpass.getpass('Enter your master password: ') return self.derive_key(master_password)
def __repr__(self): # pragma: no cover return 'Domain(name=%s, salt=%s, charset=%s, key_length=%s)' \ % (self.name, self.salt, self.charset, self.key_length)
""" Get a SQLAlchemy compatible database URI.
If a path is given, append sqlite:/// in the front, if protocol details are already provided, return unchanged. """ else:
def _uses_db(func, self, *args, **kwargs): """ Use as a decorator for operations on the database, to ensure connection setup and teardown. Can only be used on methods on objects with a `self.session` attribute. """ finally:
""" This is the main object for interfacing with a pwm database.
:param database_path: The path to the database to use, or a SQLAlchemy-compatible connection URI, like `postgresql://user:pw@host/db`. If not given or None, :func:`PWM.bootstrap <pwm.core.PWM.bootstrap` must be called before doing any operations that operate on the database. """
""" Initialize a database.
:param database_path: The absolute path to the database to initialize. """
def search(self, query): """ Search the database for the given query. Will find partial matches. """
def get_domain(self, domain_name): """ Get the :class:`Domain <pwm.Domain>` object from a name.
:param domain_name: The domain name to fetch the object for. :returns: The :class:`Domain <pwm.core.Domain>` class with this domain_name if found, else None. """ return self._get_domain_from_rest_api(domain_name) else: else:
request_args = { 'params': {'domain': domain} } verify = True server_certificate = self.config.get('server_certificate') if server_certificate: verify = os.path.join(os.path.dirname(server_certificate), server_certificate) _logger.debug('Pinning server with certificate at %s', verify)
# Test for SNI support on python 2 if sys.version_info < (3, 0, 0): try: import urllib3.contrib.pyopenssl urllib3.contrib.pyopenssl.inject_into_urllib3() except ImportError: _logger.warning("Running on python 2 without SNI support, can't verify server certificates.") verify = False request_args['verify'] = verify
if self.config.get('auth'): request_args['cert'] = self.config['auth'] response = requests.get(self.config['database'] + '/get', **request_args) domain = Domain(name=domain, salt=response.json()['salt']) return domain
""" Modify an existing domain.
:param domain_name: The name of the domain to modify. :param new_salt: Whether to generate a new salt for the domain. :param username: If given, change domain username to this value. :returns: The modified :class:`Domain <pwm.core.Domain>` object. """
length=Domain.DEFAULT_KEY_LENGTH): """ Create a new domain entry in the database.
:param username: The username to associate with this domain. :param alphabet: A character set restriction to impose on keys generated for this domain. :param length: The length of the generated key, in case of restrictions on the site. """ # Wrap the actual implementation to do some error handling
def _create_domain(self, domain_name, username, alphabet, length): alphabet=alphabet)
|