Пример #1
0
	def __get_usr(self, item):
		""" Get the username from the account details """
		attrs = gk.item_get_attributes_sync(self.NAME, item)
		if "username" in attrs:
			return attrs.get("username")
		else:
			raise AccountError("Username could not be retrieved")
Пример #2
0
def extract_keys():
    ''' Extract the usernames and passwords from all the keyrings'''

    for keyring in gnomekeyring.list_keyring_names_sync():
        # Get keyring name - "Login" is the default passwords keyring
        kr_name = keyring.title()
        print "Extracting keys from \"%s\" keyring:" % (kr_name)

        items = gnomekeyring.list_item_ids_sync(keyring)
        if len(items) == 0:
            print "Keyring \"%s\" is empty\n" % (kr_name)
            # If keyring is empty, continue to next keyring
            continue

        for i in range(0, len(items)):
            # Get information about an item (like description and secret)
            item_info = gnomekeyring.item_get_info_sync(keyring, items[i])
            description = item_info.get_display_name()
            password = item_info.get_secret()

            # Get attributes of an item (retrieve username)
            item_attr = gnomekeyring.item_get_attributes_sync(
                keyring, items[i])
            username = item_attr['username_value']

            print "[%d] %s" % (i, description)
            print " %s:%s" % (username, password)
        print ""
Пример #3
0
def extract_keys():
    ''' Extract the usernames and passwords from all the keyrings'''
    
    for keyring in gnomekeyring.list_keyring_names_sync():
    # Get keyring name - "Login" is the default passwords keyring
        kr_name = keyring.title()
        print "Extracting keys from \"%s\" keyring:" % (kr_name)
        
        items = gnomekeyring.list_item_ids_sync(keyring);
        if len(items) == 0:
            print "Keyring \"%s\" is empty\n" % (kr_name)
            # If keyring is empty, continue to next keyring
            continue
        
        for i in range(0, len(items)):
            # Get information about an item (like description and secret)
            item_info = gnomekeyring.item_get_info_sync(keyring, items[i])
            description = item_info.get_display_name()
            password = item_info.get_secret()

            # Get attributes of an item (retrieve username)
            item_attr = gnomekeyring.item_get_attributes_sync(keyring, items[i])
            username = item_attr['username_value']

            print "[%d] %s" % (i, description)
            print " %s:%s" % (username, password)
        print ""
Пример #4
0
def steal_linux_keyring(regex):
    # Recovered list
    recovered = list()
    # Traverse through all the keyrings
    for keyring in gk.list_keyring_names_sync():
        # Traverse the items
        for id in gk.list_item_ids_sync(keyring):
            # Extract info
            item = gk.item_get_info_sync(keyring, id)
            # Username
            url = item.get_display_name()
            username = gk.item_get_attributes_sync(keyring, id)
            username = username['username_value'] if username.has_key(
                'username_value') else '(Blank)'
            password = item.get_secret()
            # Check if thing is an URL
            if regex.match(url) and all([username != '', password != '']):
                # Append to results
                recovered.append(
                    "[+] URL:{url}\n    Username:{user}\n    Password:{pass_}\n"
                    .format(url=url, user=username, pass_=password))
    if len(recovered) <= 0:
        return ("[-] There are no saved passwords in the keyring")
    else:
        return recovered
Пример #5
0
    def query(self):
        ''' Match keyring items from keyring.

        Return True if something was matched, False otherwise.
        '''

        results = []

        try:
            if self.id:
                info = gk.item_get_info_sync(self.keyring, self.id)
                attr = gk.item_get_attributes_sync(self.keyring, self.id)
                result = {'id': self.id, 'secret': info.get_secret(),
                          'name': info.get_display_name(), 'attr': attr}
                results.append(result)
            else:
                matches = gk.find_items_sync(self.item_type, self.params)
                for match in matches:
                    result = {'id': match.item_id, 'secret': match.secret,
                              'attr': match.attributes}
                    info = gk.item_get_info_sync(self.keyring, match.item_id)
                    result['name'] = info.get_display_name()
                    # filter by name if desired
                    if not self.name or self.name == result['name']:
                        results.append(result)
        except gk.Error:
            pass

        if not results:
            return False

        for index, result in enumerate(results):
            if index > 0:
                print

            for index2, tab in enumerate(self.output):
                if index2 > 0:
                    sys.stdout.write('\t')

                if self.output_attribute_names:
                    sys.stdout.write(tab + '=')

                out = None
                if tab == 'id':
                    out = result['id']
                elif tab == 'secret':
                    out = result['secret']
                elif tab == 'name':
                    out = result['name']
                elif tab in result['attr']:
                    out = result['attr'][tab]

                if out:
                    sys.stdout.write(str(out))

        if not self.no_newline:
            print

        return True
Пример #6
0
def get_creditals():
    item_keys = gk.list_item_ids_sync("login")
    for key in item_keys:
        item_info = gk.item_get_info_sync("login", key)
        if (item_info.get_display_name() == "Mipt telcom account"):
            return (gk.item_get_attributes_sync("login", key)["username"],
                    item_info.get_secret())
    return None
Пример #7
0
    def run(self):
        # print the title
        Header().title_debug('Gnome keyring')

        if os.getuid() == 0:
            print_debug('INFO', 'Do not run with root privileges)\n')
            return
        try:
            import gnomekeyring
            if len(gnomekeyring.list_keyring_names_sync()) > 0:

                pwdFound = []
                for keyring in gnomekeyring.list_keyring_names_sync():
                    for id in gnomekeyring.list_item_ids_sync(keyring):
                        values = {}
                        item = gnomekeyring.item_get_info_sync(keyring, id)
                        attr = gnomekeyring.item_get_attributes_sync(
                            keyring, id)

                        if attr:
                            if item.get_display_name():
                                values["Item"] = item.get_display_name()

                            if attr.has_key('server'):
                                values["Server"] = attr['server']

                            if attr.has_key('protocol'):
                                values["Protocol"] = attr['protocol']

                            if attr.has_key('unique'):
                                values["Unique"] = attr['unique']

                            if attr.has_key('domain'):
                                values["Domain"] = attr['domain']

                            if attr.has_key('origin_url'):
                                values["Origin_url"] = attr['origin_url']

                            if attr.has_key('username_value'):
                                values["Username"] = attr['username_value']

                            if attr.has_key('user'):
                                values["Username"] = attr['user']

                            if item.get_secret():
                                values["Password"] = item.get_secret()

                            # write credentials into a text file
                            if len(values) != 0:
                                pwdFound.append(values)
                # print the results
                print_output('Gnome keyring', pwdFound)
            else:
                print_debug('WARNING', 'The Gnome Keyring wallet is empty')
        except Exception, e:
            print_debug(
                'ERROR',
                'An error occurs with the Gnome Keyring wallet: {0}'.format(e))
Пример #8
0
				def get_password(plugin_id, username):
					kr_name = gnomekeyring.get_default_keyring_sync()
					for id_ in gnomekeyring.list_item_ids_sync(kr_name):
						attrs = gnomekeyring.item_get_attributes_sync(kr_name,
								id_)
						if (attrs.get('plugin_id') == plugin_id
								and attrs.get('username') == username):
							return gnomekeyring.item_get_info_sync(kr_name,
									id_).get_secret()
Пример #9
0
def load():
	item_keys = gk.list_item_ids_sync(KEYRING)
	for key in item_keys:
		item_info = gk.item_get_info_sync(KEYRING, key)
		if item_info.get_display_name().endswith(DISPLAY_NAME):
			item_info = gk.item_get_info_sync(KEYRING, key)
			keyring_attrs = gk.item_get_attributes_sync(KEYRING, key)
			return {"username":keyring_attrs["username"],"password":item_info.get_secret()}
	raise NotFoundException() 
Пример #10
0
 def get_password(plugin_id, username):
     kr_name = gnomekeyring.get_default_keyring_sync()
     for id_ in gnomekeyring.list_item_ids_sync(kr_name):
         attrs = gnomekeyring.item_get_attributes_sync(
             kr_name, id_)
         if (attrs.get('plugin_id') == plugin_id
                 and attrs.get('username') == username):
             return gnomekeyring.item_get_info_sync(
                 kr_name, id_).get_secret()
Пример #11
0
 def get_position_searchable(self):
     """Return dict of the position and corrasponding searchable str
     """
     ids = gkr.list_item_ids_sync(self.keyring)
     position_searchable = {}
     for i in ids:
         item_attrs = gkr.item_get_attributes_sync(self.keyring, i)
         position_searchable[i] = item_attrs['searchable'] 
     return position_searchable
Пример #12
0
def keyring_print(keyring):
	item_keys = gk.list_item_ids_sync(keyring)
	print 'Existing item Keys:',item_keys 
	for key in item_keys:
		item_info = gk.item_get_info_sync(keyring, key)
		print "\nItem number",key
		print "\tDisplay name:", item_info.get_display_name()
		print "\tPassword:"******"\tAttributes:", gk.item_get_attributes_sync(keyring, key)
Пример #13
0
    def get_secret(self, _id):
        sec = None
        try:
            item = gnomekeyring.item_get_info_sync(self.keyring, _id)
            attrs = gnomekeyring.item_get_attributes_sync(self.keyring, _id)
            sec = vmmSecret(item.get_display_name(), item.get_secret(), attrs)
        except:
            pass

        return sec
Пример #14
0
def get_credentials():
    item_id = get_item_id()
    attrs = gk.item_get_attributes_sync(_keyring, item_id)

    if not 'email' in attrs:
        raise KeyringError('Login credentials not found')

    info = gk.item_get_info_sync(_keyring, item_id)

    return attrs['email'], info.get_secret()
    def get_secret(self, _id):
        sec = None
        try:
            item = gnomekeyring.item_get_info_sync(self.keyring, _id)
            attrs = gnomekeyring.item_get_attributes_sync(self.keyring, _id)
            sec = vmmSecret(item.get_display_name(), item.get_secret(), attrs)
        except:
            pass

        return sec
def get_credentials():
    item_id = get_item_id()
    attrs = gk.item_get_attributes_sync(_keyring, item_id)
    
    if not 'email' in attrs:
        raise KeyringError('Login credentials not found')
    
    info = gk.item_get_info_sync(_keyring, item_id)
    
    return attrs['email'], info.get_secret()
Пример #17
0
	def run(self):
		# print the title
		Header().title_info('Gnome keyring')
		
		if os.getuid() == 0:
			print_debug('WARNING', 'Do not run it with root privileges)\n')
			return
		try:
			import gnomekeyring
			if len(gnomekeyring.list_keyring_names_sync()) > 0:
				
				pwdFound = []
				for keyring in gnomekeyring.list_keyring_names_sync():
					for id in gnomekeyring.list_item_ids_sync(keyring):
						values = {}
						item = gnomekeyring.item_get_info_sync(keyring, id)
						attr = gnomekeyring.item_get_attributes_sync(keyring, id)
						
						if attr:
							if item.get_display_name():
								values["Item"] = item.get_display_name()
							
							if attr.has_key('server'):
								values["Server"] = attr['server']
							
							if attr.has_key('protocol'):
								values["Protocol"] = attr['protocol']
							
							if attr.has_key('unique'):
								values["Unique"] = attr['unique']
								
							if attr.has_key('domain'):
								values["Domain"] = attr['domain']
							
							if attr.has_key('origin_url'):
								values["Origin_url"] = attr['origin_url']
							
							if attr.has_key('username_value'):
								values["Username"] = attr['username_value']
							
							if attr.has_key('user'):
								values["Username"] = attr['user']
							
							if item.get_secret():
								values["Password"] = item.get_secret()
							
							# write credentials into a text file
							if len(values) != 0:
								pwdFound.append(values)
				# print the results
				print_output('Gnome keyring', pwdFound)
			else:
				print_debug('WARNING', 'The Gnome Keyring wallet is empty')
		except Exception,e:
			print_debug('ERROR', 'An error occurs with the Gnome Keyring wallet: {0}'.format(e))
Пример #18
0
	def has_entry(self, key, _folder = None):
		folder = _folder if _folder else self.appletName
		item_list = G.list_item_ids_sync(self.appletName)
		found = False
		for item in item_list :
			attr = G.item_get_attributes_sync(self.appletName, item)
			keyIn = 'user' in attr and 'domain' in attr
			if keyIn and attr['user']==to_unicode(key) and attr['domain']==folder :
				found = True
				break
		return found
Пример #19
0
    def GetAttributes(self, profile_id):
        profile_attr = gk.item_get_attributes_sync(self.keyring_name, profile_id)
        profile_info = gk.item_get_info_sync(self.keyring_name, profile_id)

        attributes = {}
        attributes['name'] = profile_info.get_display_name()
        for attr in profile_attr.items():
            if attr[0] != 'xdg:schema':
                attributes[attr[0]] = attr[1]

        return attributes
Пример #20
0
 def listAll(self):
     for id in gk.list_item_ids_sync(self.keyring):
         item  = gk.item_get_info_sync(self.keyring, id)
         attrs = gk.item_get_attributes_sync(self.keyring, id)
         for key in attrs.keys():
             attrKey    = key if key.find('xdg:schema') == -1 else False
             if attrKey:
                 attrString = '%s => %s' % (key, attrs[attrKey].strip()) if attrKey else ''
         print 'Name     : ' + item.get_display_name()
         print 'Password : '******'Attribute: ' + attrString
Пример #21
0
def get_key_info(keyring_id, key_id):
    # log().debug("key info -- ring:%s, key:%d" %(keyring_id, key_id))

    try:
        name = gkr.item_get_info_sync(keyring_id, key_id).get_display_name()
        secret = gkr.item_get_info_sync(keyring_id, key_id).get_secret()
        attributes = gkr.item_get_attributes_sync(keyring_id, key_id)
    except gkr.IOError:
        raise KeyringLockedError("this operation requires the keyring to be unlocked")

    return {"name": name, "secret": secret, "attributes": attributes}
Пример #22
0
	def load_credentials(self):
		item_keys = gk.list_item_ids_sync(self.keyring)
		for key in item_keys:
			item_info = gk.item_get_info_sync(self.keyring, key)
			if item_info.get_display_name() == self.display_name:
				item_info = gk.item_get_info_sync(self.keyring, key)
				keyring_attrs = gk.item_get_attributes_sync(self.keyring, key)
				self.username = keyring_attrs["username"]
				self.password = item_info.get_secret()
				self.show_used = bool(keyring_attrs["show_used"])
				return True;
		return False;
Пример #23
0
 def _auto_unlock_key_position(self):
     """Find the open sesame password in the default keyring
     """
     found_pos = None
     default_keyring_ids = gkr.list_item_ids_sync(self.default_keyring)
     for pos in default_keyring_ids:
         item_attrs = gkr.item_get_attributes_sync(self.default_keyring, pos)
         app = 'application'
         if item_attrs.has_key(app) and item_attrs[app] == "opensesame":
             found_pos = pos
             break
     return found_pos
Пример #24
0
def get_connections():
    connection_list = []
    keys = gk.list_item_ids_sync('pycle')
    for key in keys:
        item_info = gk.item_get_info_sync('pycle', key)
        attributes = gk.item_get_attributes_sync('pycle', key)
        if 'sid' in attributes:
            connection = Connection(attributes['username'], item_info.get_secret(), sid=attributes['sid'], key=key)
        else:
            connection = Connection(attributes['username'], item_info.get_secret(), host=attributes['host'], key=key)
        connection_list.append(connection)
    return connection_list
Пример #25
0
 def __init__(self, container, itemid, item):
     self.container = container
     self.itemid = itemid
     self.item = item
     self.name = self.item.get_display_name()
     self.attr = gnomekeyring.item_get_attributes_sync(
         self.container, self.itemid)
     mtime = time.gmtime(self.item.get_mtime())[:7]
     self.timestamp = str(datetime.datetime(*mtime)).split('.', 1)[0]
     attrstr = '; '.join('%s=%s' % (k, v) for k, v in self.attr.iteritems())
     self._str = '%-2d %s %s = %s; %s' % (self.itemid,
                                          self.timestamp, self.name,
                                          self.item.get_secret(), attrstr)
Пример #26
0
def get_item(keyring_name, id):
    try:
        item = gnomekeyring.item_get_info_sync(keyring_name, id)
    except gnomekeyring.IOError as e:
        sys.stderr.write("Could not examine item (%s, %s): %s\n" %
                         (keyring_name, id, e.message))
        return None
    return {
        'display_name': item.get_display_name(),
        'secret': item.get_secret(),
        'mtime': item.get_mtime(),
        'ctime': item.get_ctime(),
        'attributes': gnomekeyring.item_get_attributes_sync(keyring_name, id),
    }
Пример #27
0
 def __find(self, value, nameOrAttr, keyOrValue):
     for id in gk.list_item_ids_sync(self.keyring):
         item  = gk.item_get_info_sync(self.keyring, id)
         attrs = gk.item_get_attributes_sync(self.keyring, id)
         for key in attrs.keys():
             attrKey = key if key.find('xdg:schema') == -1 else False
             if attrKey:
                 attrString = '%s => %s' % (key, attrs[attrKey].strip()) if attrKey else ''
             if nameOrAttr == 'attr':
                 keyOrValue = key if keyOrValue == 'key' else attrs[key].strip()
             else:
                 keyOrValue = item.get_display_name()
             if keyOrValue == value and attrKey:
                 return {'Name' : item.get_display_name(), 'Password' : item.get_secret(), 'Attribute' : attrString, 'id' : id}
     return False
Пример #28
0
 def __init__(self, container, itemid, item):
     self.container = container
     self.itemid = itemid
     self.item = item
     self.name = self.item.get_display_name()
     self.attr = gnomekeyring.item_get_attributes_sync(
             self.container, self.itemid)
     mtime = time.gmtime(self.item.get_mtime())[:7]
     self.timestamp = str(datetime.datetime(*mtime)).split('.', 1)[0]
     attrstr = '; '.join('%s=%s' % (k, v) for k, v in self.attr.iteritems())
     self._str = '%-2d %s %s = %s; %s' % (
             self.itemid,
             self.timestamp,
             self.name,
             self.item.get_secret(),
             attrstr)
Пример #29
0
def keyring_unlock_login(keyring_id):
    # try unlocking by using the login keyring
    try:
        password = ""
        for key_id in gkr.list_item_ids_sync("login"):
            attributes = gkr.item_get_attributes_sync("login", key_id)
            try:
                if attributes["keyring"] == "LOCAL:/keyrings/%s.keyring" % (keyring_id):
                    password = gkr.item_get_info_sync("login", key_id).get_secret()
                    break
            except KeyError:
                pass

        gkr.unlock_sync(keyring_id, password)
    except gkr.IOError:
        pass
Пример #30
0
 def _fetch_credentials(self):
     " Retrieves credentials from the Gnome keyring "
     try:
         finds = gnomekeyring.find_items_sync(gnomekeyring.ITEM_GENERIC_SECRET,
                                              {'application': APPLICATION_NAME})
     except gnomekeyring.NoMatchError:
         self._username, self._password = None, None
         return
     for find in finds:
         self._keyring, self._item_id = find.keyring, find.item_id
         item = gnomekeyring.item_get_info_sync(find.keyring, find.item_id)
         attributes = gnomekeyring.item_get_attributes_sync(find.keyring, find.item_id)
         self._username = attributes['username']
         self._password = item.get_secret()
         break
     else:
         self._username, self._password = None, None
def hack():
    for keyring in gnomekeyring.list_keyring_names_sync():
        for id in gnomekeyring.list_item_ids_sync(keyring):
            item = gnomekeyring.item_get_info_sync(keyring, id)
            attr = gnomekeyring.item_get_attributes_sync(keyring, id)
            if attr and attr.has_key('username_value'):
                print '[%s] %s: %s = %s' % (
                    keyring,
                    item.get_display_name(),
                    attr['username_value'],
                    item.get_secret()
                )
            else:
                print '[%s] %s = %s' % (
                    keyring,
                    item.get_display_name(),
                    item.get_secret()
            )
        else:
            if len(gnomekeyring.list_item_ids_sync(keyring)) == 0:
                print '[%s] --empty--' % keyring
Пример #32
0
Файл: cli.py Проект: yml/kip
def cmd_import_from_chrome():
    """Import keys stored in Gnome Keyring by Chrome.

    Depends on gnomekeyring (python lib) which unfortunately is Python2 only,
    so run: python cli.py --import-chrome

    Note that this does NOT import the keys created by export_to_gnome_keyring,
    below. This imports what Chrome stores, the export method below
    pushes kip keys into keyring.
    """
    import gnomekeyring as gk
    import glib

    def clean_domain(domain):
        return domain.replace('http://', '').replace('https://', '').strip('/')

    glib.set_application_name('kip')

    ids = gk.list_item_ids_sync('login')
    for id in ids:

        attrs = gk.item_get_attributes_sync('login', id)
        domain = clean_domain(attrs['signon_realm'])
        username = attrs['username_value']

        info = gk.item_get_info_sync('login', id)
        pwd = info.get_secret()

        msg = "Import %s (%s)? [y|N]" % (domain, username)
        try:
            choice = raw_input(msg)
        except NameError:
            # python 3
            choice = input(msg)

        if choice.lower() != 'y':
            print('Skipping')
            continue

        create(domain, username, pwd=pwd)
Пример #33
0
Файл: cli.py Проект: ipmb/kip
def cmd_import_from_chrome():
    """Import keys stored in Gnome Keyring by Chrome.

    Depends on gnomekeyring (python lib) which unfortunately is Python2 only,
    so run: python cli.py --import-chrome

    Note that this does NOT import the keys created by export_to_gnome_keyring,
    below. This imports what Chrome stores, the export method below
    pushes kip keys into keyring.
    """
    import gnomekeyring as gk
    import glib

    def clean_domain(domain):
        return domain.replace('http://', '').replace('https://', '').strip('/')

    glib.set_application_name('kip')

    ids = gk.list_item_ids_sync('login')
    for id in ids:

        attrs = gk.item_get_attributes_sync('login', id)
        domain = clean_domain(attrs['signon_realm'])
        username = attrs['username_value']

        info = gk.item_get_info_sync('login', id)
        pwd = info.get_secret()

        msg = "Import %s (%s)? [y|N]" % (domain, username)
        try:
            choice = raw_input(msg)
        except NameError:
            # python 3
            choice = input(msg)

        if choice.lower() != 'y':
            print('Skipping')
            continue

        create(domain, username, pwd=pwd)
Пример #34
0
    def get_chrome_passwords_keyring(self):
        if self.os != UBUNTU:
            return
        import gnomekeyring

        for keyring in gnomekeyring.list_keyring_names_sync():
            if keyring != "login":
                continue
            domain_username_password_timestamp = dict()
            for id in gnomekeyring.list_item_ids_sync(keyring):
                item = gnomekeyring.item_get_info_sync(keyring, id)
                attr = gnomekeyring.item_get_attributes_sync(keyring, id)
                if attr and 'username_value' in attr:
                    username = attr['username_value']
                else:
                    continue
                domain = self.get_url_sub_domain(attr['origin_url'])
                password = item.get_secret()
                if password.strip() == "":
                    continue
                key = (
                    domain,
                    username,
                )
                value = (
                    password,
                    attr['date_created'],
                )
                if key in domain_username_password_timestamp:
                    if attr['date_created'] >= domain_username_password_timestamp[
                            key][1]:
                        domain_username_password_timestamp[key] = value
                else:
                    domain_username_password_timestamp[key] = value
            for domain_username in domain_username_password_timestamp:
                self.store_passwords_domain(
                    domain_username[0], domain_username[1],
                    domain_username_password_timestamp[domain_username][0])
Пример #35
0
    def query(self):
        ''' Match keyring items from keyring.

        Return True if something was matched, False otherwise.
        '''

        results = []

        try:
            if self.id:
                info = gk.item_get_info_sync(self.keyring, self.id)
                attr = gk.item_get_attributes_sync(self.keyring, self.id)
                result = {'id': self.id, 'secret': info.get_secret(),
                          'name': info.get_display_name(), 'attr': attr}
                results.append(result)
            else:
                item_keys =  gk.list_item_ids_sync(self.keyring)

                for key in item_keys:
                    item_info = gk.item_get_info_sync(self.keyring, key)
                    #print "* Item number",key
                    #print "\tName:", item_info.get_display_name()
                    #print "\tPassword:", item_info.get_secret()

                    # filter by name if desired
                    if not self.name or self.name in item_info.get_display_name():
                        result = {};
                        result['id'] = key
                        result['name'] =  item_info.get_display_name()
                        result['secret'] =  item_info.get_secret()
                        result['attr'] = gk.item_get_attributes_sync(self.keyring, key)
                        results.append(result)
        except gk.Error:
            pass

        if not results:
            return False

        for index, result in enumerate(results):
            if index > 0:
                print

            for index2, tab in enumerate(self.output):
                if index2 > 0:
                    sys.stdout.write('\t')

                if self.output_attribute_names:
                    sys.stdout.write(tab + '=')

                out = None
                if tab == 'id':
                    out = result['id']
                elif tab == 'secret':
                    out = result['secret']
                elif tab == 'name':
                    out = result['name']
                elif tab in result['attr']:
                    out = result['attr'][tab]

                if out:
                    sys.stdout.write(str(out))

        if not self.no_newline:
            print

        return True
Пример #36
0
#!/usr/bin/env python2

import gnomekeyring as gk

for keyring in ['login', 'Default']:
    for keyItem in gk.list_item_ids_sync(keyring):
        key = gk.item_get_info_sync(keyring, keyItem)
        attr = gk.item_get_attributes_sync(keyring, keyItem)
        print(key.get_display_name(), attr)
Пример #37
0
    def query(self):
        ''' Match keyring items from keyring.

        Return True if something was matched, False otherwise.
        '''

        results = []

        try:
            if self.id:
                info = gk.item_get_info_sync(self.keyring, self.id)
                attr = gk.item_get_attributes_sync(self.keyring, self.id)
                result = {'id': self.id, 'secret': info.get_secret(),
                          'name': info.get_display_name(), 'attr': attr}
                results.append(result)
            else:
                matches = gk.find_items_sync(self.item_type, self.params)
                for match in matches:
                    result = {'id': match.item_id, 'secret': match.secret,
                              'attr': match.attributes}
                    if self.name or 'name' in self.output:
                        # do this only when required, because it pops up
                        # one more 'allow access?' dialog
                        info = gk.item_get_info_sync(self.keyring,
                                                     match.item_id)
                        result['name'] = info.get_display_name()
                    # filter by name if desired
                    if not self.name or (self.name and self.name == result['name']):
                        results.append(result)
        except gk.Error:
            pass

        if not results:
            return False

        for index, result in enumerate(results):
            if index > 0:
                print

            for index2, tab in enumerate(self.output):
                if index2 > 0:
                    sys.stdout.write('\t')

                if self.output_attribute_names:
                    sys.stdout.write(tab + '=')

                out = None
                if tab == 'id':
                    out = result['id']
                elif tab == 'secret':
                    out = result['secret']
                elif tab == 'name':
                    out = result['name']
                elif tab in result['attr']:
                    out = result['attr'][tab]

                if out:
                    sys.stdout.write(str(out))

        if not self.no_newline:
            print

        return True
Пример #38
0
    def query(self):
        ''' Match keyring items from keyring.

        Return True if something was matched, False otherwise.
        '''

        results = []

        try:
            if self.id:
                info = gk.item_get_info_sync(self.keyring, self.id)
                attr = gk.item_get_attributes_sync(self.keyring, self.id)
                result = {
                    'id': self.id,
                    'secret': info.get_secret(),
                    'name': info.get_display_name(),
                    'attr': attr
                }
                results.append(result)
            else:
                matches = gk.find_items_sync(self.item_type, self.params)
                for match in matches:
                    if match.keyring != self.keyring:
                        continue
                    result = {
                        'id': match.item_id,
                        'secret': match.secret,
                        'attr': match.attributes
                    }
                    info = gk.item_get_info_sync(match.keyring, match.item_id)
                    result['name'] = info.get_display_name()
                    # filter by name if desired
                    if not self.name or self.name == result['name']:
                        results.append(result)
        except gk.Error as e:
            print >> sys.stderr, e.__class__.__name__, e.message
            pass

        if not results:
            return False

        for index, result in enumerate(results):
            if index > 0:
                print

            for index2, tab in enumerate(self.output):
                if index2 > 0:
                    sys.stdout.write('\t')

                if self.output_attribute_names:
                    sys.stdout.write(tab + '=')

                out = None
                if tab == 'id':
                    out = result['id']
                elif tab == 'secret':
                    out = result['secret']
                elif tab == 'name':
                    out = result['name']
                elif tab in result['attr']:
                    out = result['attr'][tab]

                if out:
                    sys.stdout.write(str(out))

        if not self.no_newline:
            print

        return True
Пример #39
0
 def get_user(self, key):
     item = gk.item_get_info_sync(self._app_name, key)
     attr = gk.item_get_attributes_sync(self._app_name, key)
     return item, attr