def get_password(self): """ Get password with decryption :return: """ mpw = master_pass.MPW(self.user, self.master_password) return UcsmServer.fix_ucsm_password(mpw.password(self.ucs_server))
def __init__(self): super().__init__() self.username = "******" self.mpw = "Server" self.url = '127.0.0.1' self.password = master_password.MPW(self.username, self.mpw).password( self.url).replace('/', '')
def choose_password(self, password, mpw) -> str: """ Returns vcenter password. Master_password has precedence. One param may be None. :param password: Normal vcenter password. :param mpw: if not None it has precedence :return: password """ if mpw is not None: # vcenter does not support slash char '/' return master_password.MPW(self.user, mpw).password(self.host).replace('/', '') elif password is not None: return password else: raise ValueError('No vcenter password provided')
def main(argv=sys.argv[1:]): parser = argparse.ArgumentParser(description='Master Password CLI', prog='master_password', formatter_class=RawFormatter) parser.add_argument('-u', metavar='name', help=_HELP['name'], default=os.environ.get(_ENV['name'])) type_default = os.environ.get(_ENV['template'], '').strip().lower() if type_default not in _TYPE_CHOICES: type_default = None parser.add_argument('-t', metavar='type', help=_HELP['type'], choices=_TYPE_CHOICES, default=type_default) counter_default = os.environ.get(_ENV['counter'], 1) try: counter_default = int(counter_default) except ValueError: counter_default = 1 parser.add_argument('-c', metavar='counter', help=_HELP['counter'], type=int, default=counter_default) version_default = os.environ.get(_ENV['version'], 3) try: version_default = int(version_default) if version_default not in _VERSION_CHOICES: version_default = 3 except ValueError: version_default = 3 parser.add_argument('-a', metavar='version', help=_HELP['version'], type=int, default=version_default, choices=_VERSION_CHOICES) parser.add_argument('-V', metavar='variant', help=_HELP['variant'], default='password', choices=('p', 'password', 'l', 'login', 'a', 'answer')) parser.add_argument('-C', metavar='context', help=_HELP['context'], default=None) parser.add_argument('site', help=_HELP['site'], nargs='?', default=None) parser.add_argument('-i', help=_HELP['identicon'], action='store_false') parser.add_argument('-P', metavar='password', help=argparse.SUPPRESS, default=None) args = parser.parse_args(argv) full_name = args.u template = args.t counter = args.c version = args.a namespace = args.V context = args.C site = args.site mpw = args.P # Do not use. Insecure. For testing purposes only. if full_name is None: full_name = input('Your full name: ') if site is None: site = input('Site name: ') namespace = { 'p': 'password', 'password': '******', 'l': 'login', 'login': '******', 'a': 'answer', 'answer': 'answer' }[namespace] if template is None: template = { 'password': '******', 'login': '******', 'answer': 'phrase' }[namespace] debug = mpw is not None if debug: print(args) print('Full name: ' + repr(full_name)) print('Template: ' + repr(template)) print('Counter: ' + repr(counter)) print('Version: ' + repr(version)) print('Namespace: ' + repr(namespace)) print('Context: ' + repr(context)) print('Site: ' + repr(site)) print('Password: '******'{}\'s password for {}:\n'.format(full_name, site)) if args.i: identicon = master_password.MPW.identicon(full_name, mpw) if debug: print('Identicon: ' + repr(identicon.encode('utf-8')) + '\n') try: sys.stdout.write(u'[ {} ]: '.format(identicon)) except UnicodeError as e: sys.stderr.write( '\nError writing identicon: {}\n'.format(e) + 'Please pass the -i argument to avoid attempting to ' 'display the identicon.\n') sys.stdout.flush() mpw = master_password.MPW(full_name, mpw, version=version) print(mpw.generate(site, counter, context, template, namespace)) if debug: print('Key: ' + repr(mpw.key)) print('Seed: ' + repr(mpw.seed(site, namespace, counter, context)))
def generate_pw_handle(self): return master_password.MPW(self.user, self.mpw)
def generate_pw(self, user, mpw, url): handle = master_password.MPW(user, mpw) return handle.password(url).replace('/', '')