Ejemplo n.º 1
0
 def password(self):
     n = self._password
     if n is None:
         if gtkpresence:
             try:
                 keyring = gnomekeyring.get_default_keyring_sync()
                 keyring_info = gnomekeyring.get_info_sync(keyring)
                 if keyring_info.get_is_locked():
                     nof_tries = 3
                     for i in range(nof_tries):
                         keyring_pass = getpass('Enter password to unlock your default keychain: ')
                         try:
                             gnomekeyring.unlock_sync(keyring, keyring_pass)
                             break
                         except gnomekeyring.DeniedError:
                             if i+1==nof_tries:
                                 sys.stderr.write('\nFailed to unlock keychain (%s times)\n' % (i+1))
                             else:
                                 sys.stderr.write("\nInvalid password, try again...\n")
                 items = gnomekeyring.find_items_sync(gnomekeyring.ITEM_NETWORK_PASSWORD, 
                                                      {"server": self.server, 
                                                       "protocol": "ftp", 
                                                       "user": self.username})
                 if len(items) > 0:
                     n = items[0].secret
             except gnomekeyring.DeniedError:
                 sys.stderr.write("\nGnome keyring error : Access denied ..\n")
             except gnomekeyring.NoMatchError:
                 sys.stderr.write("\nGnome keyring error : No credential for %s..\n" % self.server)
             except Exception, msg:
                 sys.stderr.write("\nGnome keyring error : %s\n" % (msg))
             sys.stderr.flush()
         if n is None:
             n = getpass('Enter password for ftp://%s@%s: ' % (self.username, self.server))
         self._password = n
Ejemplo n.º 2
0
 def password(self):
     n = self._password
     if n is None:
         if gtkpresence:
             try:
                 keyring = gnomekeyring.get_default_keyring_sync()
                 keyring_info = gnomekeyring.get_info_sync(keyring)
                 if keyring_info.get_is_locked():
                     nof_tries = 3
                     for i in range(nof_tries):
                         keyring_pass = getpass("Enter password to unlock your default keychain: ")
                         try:
                             gnomekeyring.unlock_sync(keyring, keyring_pass)
                             break
                         except gnomekeyring.DeniedError:
                             if i + 1 == nof_tries:
                                 sys.stderr.write("\nFailed to unlock keychain (%s times)\n" % (i + 1))
                             else:
                                 sys.stderr.write("\nInvalid password, try again...\n")
                 items = gnomekeyring.find_items_sync(
                     gnomekeyring.ITEM_NETWORK_PASSWORD,
                     {"server": self.server, "protocol": "ftp", "user": self.username},
                 )
                 if len(items) > 0:
                     n = items[0].secret
             except gnomekeyring.DeniedError:
                 sys.stderr.write("\nGnome keyring error : Access denied ..\n")
             except gnomekeyring.NoMatchError:
                 sys.stderr.write("\nGnome keyring error : No credential for %s..\n" % self.server)
             except Exception, msg:
                 sys.stderr.write("\nGnome keyring error : %s\n" % (msg))
             sys.stderr.flush()
         if n is None:
             n = getpass("Enter password for ftp://%s@%s: " % (self.username, self.server))
         self._password = n
Ejemplo n.º 3
0
    def connect(self):
        try:
            auth = netrc().authenticators(self.host)
            # TODO check if the host exists in netrc
        except IOError as msgio:
            if gtkpresence:
                try:
                    keyring = gnomekeyring.get_default_keyring_sync()
                    keyring_info = gnomekeyring.get_info_sync(keyring)
                    if keyring_info.get_is_locked():
                        keyring_pass = getpass('Enter password to unlock your '
                                               'keychain [%s]: ' % (keyring))
                        try:
                            gnomekeyring.unlock_sync(keyring, keyring_pass)
                        except Exception as msg:
                            sys.stderr.write("\nUnable to unlock your "
                                             "keychain: %s\n" % msg)
                        else:
                            _log().debug("+ [%s] unlocked." % keyring)
                            itempass = gnomekeyring.ITEM_NETWORK_PASSWORD
                            pars = {
                                "server": self.host,
                                "protocol": "ftp",
                                "user": self.user
                            }
                            items = gnomekeyring.find_items_sync(
                                itempass, pars)
                            if len(items) > 0:
                                ftp = ftplib.FTP(self.host, self.user,
                                                 items[0].secret)
                            else:
                                raise Exception('gnomekeyring', 'NoMatchError')
                except gnomekeyring.DeniedError:
                    sys.stderr.write("\nGnome keyring error : "
                                     "Access denied ..\n"
                                     "netrc error: %s\n" % (msgio))
                    sys.exit(1)
                except gnomekeyring.NoMatchError:
                    sys.stderr.write("\nGnome keyring error : "
                                     "No credential for %s..\n"
                                     "netrc error: %s\n" % (self.host, msgio))
                    sys.exit(1)
                except Exception as msg:
                    sys.stderr.write("\nGnome keyring error : %s\n"
                                     "netrc error: %s\n" % (msg, msgio))
                    sys.exit(1)

        else:
            assert self.user == auth[0]
            ftp = ftplib.FTP()
            ftp.connect(self.host, self.port)
            ftp.login(auth[0], auth[2])
        try:
            ftp.cwd(self.path)
        except ftplib.error_perm:
            ftp.mkd(self.path)
            ftp.cwd(self.path)
        self.ftp = ftp
        self.dirs = set()
Ejemplo n.º 4
0
    def connect(self):
        try:
            auth = netrc().authenticators(self.host)
            # TODO check if the host exists in netrc
        except IOError as msgio:
            if gtkpresence:
                try:
                    keyring = gnomekeyring.get_default_keyring_sync()
                    keyring_info = gnomekeyring.get_info_sync(keyring)
                    if keyring_info.get_is_locked():
                        keyring_pass = getpass('Enter password to unlock your '
                                               'keychain [%s]: ' % (keyring))
                        try:
                            gnomekeyring.unlock_sync(keyring, keyring_pass)
                        except Exception as msg:
                            sys.stderr.write("\nUnable to unlock your "
                                             "keychain: %s\n" % msg)
                        else:
                            _log().debug("+ [%s] unlocked." % keyring)
                            itempass = gnomekeyring.ITEM_NETWORK_PASSWORD
                            pars = {
                                "server": self.host,
                                "protocol": "ftp",
                                "user": self.user
                            }
                            items = gnomekeyring.find_items_sync(
                                itempass, pars)
                            if len(items) > 0:
                                ftp = ftplib.FTP(self.host, self.user,
                                                 items[0].secret)
                            else:
                                raise Exception('gnomekeyring', 'NoMatchError')
                except gnomekeyring.DeniedError:
                    sys.stderr.write("\nGnome keyring error : "
                                     "Access denied ..\n"
                                     "netrc error: %s\n" % (msgio))
                    sys.exit(1)
                except gnomekeyring.NoMatchError:
                    sys.stderr.write("\nGnome keyring error : "
                                     "No credential for %s..\n"
                                     "netrc error: %s\n" % (self.host, msgio))
                    sys.exit(1)
                except Exception as msg:
                    sys.stderr.write("\nGnome keyring error : %s\n"
                                     "netrc error: %s\n" % (msg, msgio))
                    sys.exit(1)

        else:
            assert self.user == auth[0]
            ftp = ftplib.FTP()
            ftp.connect(self.host, self.port)
            ftp.login(auth[0], auth[2])
        try:
            ftp.cwd(self.path)
        except ftplib.error_perm:
            ftp.mkd(self.path)
            ftp.cwd(self.path)
        self.ftp = ftp
        self.dirs = set()
Ejemplo n.º 5
0
def gnomekeyring_unlock():
    """Tries to unlock the gnome keyring. Returns True on success."""
    try:
        gnomekeyring.unlock_sync(None, getpass.getpass('Keyring password: '******'Failed to unlock keyring: %s' % e
        return False
Ejemplo n.º 6
0
def gnomekeyring_unlock():
    """Tries to unlock the gnome keyring. Returns True on success."""
    try:
        gnomekeyring.unlock_sync(
                None, getpass.getpass('Keyring password: '******'Failed to unlock keyring: %s' % e
        return False
Ejemplo n.º 7
0
    def unlock(self):
        '''Unlock a keyring.
        '''

        try:
            gk.unlock_sync(self.keyring, self.secret)
        except gk.Error, e:
            print >>sys.stderr, 'Error unlocking keyring!\nDetails:\n%s'%e
            return False
Ejemplo n.º 8
0
    def unlock(self):
        '''Unlock a keyring.
        '''

        try:
            gk.unlock_sync(self.keyring, self.secret)
        except gk.Error, e:
            print >> sys.stderr, 'Error unlocking keyring!\nDetails:\n%s' % e
            return False
Ejemplo n.º 9
0
 def _unlock_keyring():
   """Tries to unlock the gnome keyring. Returns True on success."""
   if not os.environ.get('DISPLAY') or not gnomekeyring:
     return False
   try:
     gnomekeyring.unlock_sync(None, getpass.getpass('Keyring password: '******'Failed to unlock keyring: %s' % e
     return False
Ejemplo n.º 10
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
Ejemplo n.º 11
0
	def __init__(self):
		GLib.set_application_name('mailnag')
		self.was_locked = False											# True if Dialog shown. Required for Sortorder problem
		self.keyring_password = ''
		self.defaultKeyring = gnomekeyring.get_default_keyring_sync()
		if self.defaultKeyring == None:
			self.defaultKeyring = 'login'

		while gnomekeyring.get_info_sync(self.defaultKeyring).get_is_locked():		# Keyring locked?
			self.message_response = 'cancel'							# default response for message dialog
			try:
				try: gnomekeyring.unlock_sync(self.defaultKeyring, \
						self.keyring_password)
				except gnomekeyring.IOError:
					self.show_keyring_dialog()							# get keyring password
					Gtk.main()											# wait until dialog is closed
					result = gnomekeyring.unlock_sync(self.defaultKeyring, \
								self.keyring_password)
			except gnomekeyring.IOError:
				self.show_message(_('Failed to unlock Keyring "{0}".\nWrong password.\n\nDo you want to try again?').format(self.defaultKeyring))
				Gtk.main()												# wait until dialog is closed
				if self.message_response == 'cancel': exit(1)			# close application (else: continue getting password)
Ejemplo n.º 12
0
 def __get_each_secret(self):
     try:
         for casket in gnomekeyring.list_item_ids_sync(self.keyring):
             yield gnomekeyring.item_get_info_sync(self.keyring, casket)
     except gnomekeyring.IOError:
         keyring_error = self.clerk.get_keyring_error()
         if self.clerk.is_problem(KeyringErrors.LOCKED_KEYRING, keyring_error):
             # the keyring is locked - ask for the key to unlock it
             keyring_pass = self.clerk.ask_for_keyring_pass(self.keyring)
             try:
                 gnomekeyring.unlock_sync(self.keyring, str(keyring_pass))
                 keyring_pass = self.shred_password(keyring_pass)
                 for secret in self.__get_each_secret():
                     yield secret
             except gnomekeyring.IOError:
                 keyring_error = self.clerk.get_keyring_error()
                 if self.clerk.is_problem(KeyringErrors.WRONG_PASSWORD, keyring_error):
                     self.clerk.close_shop('The password for keyring "{}"'
                                    ' was incorrect'.format(self.keyring))
                 else:
                     self.clerk.close_shop(keyring_error)
         else:
             self.clerk.close_shop(keyring_error)
Ejemplo n.º 13
0
    def getPasswd(cls, key):
        if not gnomekeyring.is_available(): 
            err_str = "Cannot get passwords for " + key + " from gnome keyring: not available"
            logging.error(err_str)
            pynotify.init(self.username)
            notification = pynotify.Notification(err_str)
            notification.show()
            return None
        keys = gnomekeyring.list_item_ids_sync("login")
        for k in keys:
            try:
                item = gnomekeyring.item_get_info_sync("login", k)
                if key in item.get_display_name(): return item.get_secret()
            except Exception as ex:
                logging.info("Need to unlock login keyring: " + ex.message)
                gnomekeyring.unlock_sync("login", getpass.getpass('Password: '))

        err_str = "Cannot get passwords for " + key + " from gnome keyring: not found"
        logging.error(err_str)
        pynotify.init(self.username)
        notification = pynotify.Notification(err_str)
        notification.show()
        return None
Ejemplo n.º 14
0
    def getPasswd(cls, key):
        if not gnomekeyring.is_available(): 
            err_str = "Cannot get passwords for " + key + " from gnome keyring: not available"
            logging.error(err_str)
            pynotify.init(self.username)
            notification = pynotify.Notification(err_str)
            notification.show()
            return None
        keys = gnomekeyring.list_item_ids_sync("login")
        for k in keys:
            try:
                item = gnomekeyring.item_get_info_sync("login", k)
                if key in item.get_display_name(): return item.get_secret()
            except Exception as ex:
                logging.info("Need to unlock login keyring: " + ex.message)
                gnomekeyring.unlock_sync("login", getpass.getpass('Password: '))

        err_str = "Cannot get passwords for " + key + " from gnome keyring: not found"
        logging.error(err_str)
        pynotify.init(self.username)
        notification = pynotify.Notification(err_str)
        notification.show()
        return None
Ejemplo n.º 15
0
	def __init__(self):
		keyrings = gnomekeyring.list_keyring_names_sync()

		if KEYRING_NAME not in keyrings:
			gnomekeyring.create_sync(KEYRING_NAME, KEYRING_PASSWD)

		keyring = gnomekeyring.list_item_ids_sync(KEYRING_NAME)

		for user in CONFIG['accounts']:
			user = user.encode('utf8')
			found = False

			for item in keyring:
				gnomekeyring.unlock_sync(KEYRING_NAME, KEYRING_PASSWD)
				info = gnomekeyring.item_get_info_sync(KEYRING_NAME, item)
				gnomekeyring.lock_sync(KEYRING_NAME)

				if user == info.get_display_name():
					found = True
					break

			if not found:
				self.save_user_credentials(user)
Ejemplo n.º 16
0
	def __unlock_keyring(self):
		"""Unlock keyring and schedule automatic lock"""
		result = False

		dialog = InputDialog(self._application)
		dialog.set_title(_('Unlock keyring'))
		dialog.set_label(_('Please enter your keyring password:'))
		dialog.set_password()

		response = dialog.get_response()

		if response[0] == gtk.RESPONSE_OK:
			# try to unlock keyring
			keyring.unlock_sync(self.KEYRING_NAME, response[1])

			# update status information
			self.__update_info()

			if not self.is_locked():
				# set timeout for automatic locking
				self.__reset_timeout()
				result = True

		return result
Ejemplo n.º 17
0
 def unlock_keyring(self):
     info = gkr.get_info_sync(self.keyring)
     if info.get_is_locked():
         found_pos = self._auto_unlock_key_position()
         item_info = gkr.item_get_info_sync(self.default_keyring, found_pos)
         gkr.unlock_sync(self.keyring, item_info.get_secret()) 
Ejemplo n.º 18
0
def keyring_unlock_password(keyring_id):
    try:
        gkr.unlock_sync(keyring_id, getpass.getpass())
    except gkr.IOError:
        raise KeyringPasswordError("invalid password")
Ejemplo n.º 19
0
    return int(p.sub("", data))


glib.set_application_name(APP_NAME)
keyrings = gk.list_keyring_names_sync()
if KEYRING_NAME not in keyrings:
    print "Keyring", KEYRING_NAME, "not found"
    exit()
if gk.get_info_sync(KEYRING_NAME).get_is_locked():

    message = "Give password for keyring"
    while True:
        password = get_password(message)
        if password is not None:
            try:
                gk.unlock_sync(KEYRING_NAME, password)
                break
            except gk.IOError:
                message = "Password is wrong. Try again."
        else:
            exit()
GMAIL_PASS = search_secret(KEYRING_NAME, GMAIL_LOGIN)
# OWA_PASS = search_secret(KEYRING_NAME, OWA_LOGIN)
mailserver = "imap4-3.uni.lu"
mailbox = "INBOX"
port = 993
# check gmail
com = (
    "wget -q -O - https://" + GMAIL_LOGIN + ":" + GMAIL_PASS + "@mail.google.com/mail/feed/atom --no-check-certificate"
)
# com=["wget","-q","-O","-","https://"+GMAIL_LOGIN+":"+GMAIL_PASS+"@mail.google.com/mail/feed/atom --no-check-certificate"]
Ejemplo n.º 20
0
    # from the docs: "update_if_exists:  If true, then another item matching
    # the type, and attributes will be updated instead of creating a new item."
    # So we either store unique attributes with each, or set update_if_exists
    # to False.
    # If we do both, additional keys with the same name and different IDs
    # will get created.
    gnomekeyring.item_create_sync(keyring, gnomekeyring.ITEM_GENERIC_SECRET,
            item_name, {'name': item_name}, secret, True)

if __name__ == '__main__':
    args = parse_args()

    '''Sometimes the 'login' keyring is not automatically marked as default
    (the user needs to do it manually). If no keyring is marked as default,
    fall back to the 'login' keyring.'''
    default_keyring = gnomekeyring.get_default_keyring_sync() or 'login'

    keyring_pass = get_secret(default_keyring, args.keyring)
    if not keyring_pass:
        keyring_pass = getpass.getpass(
                'New password for keyring ' + args.keyring + ': ')
        gnomekeyring.create_sync(args.keyring, keyring_pass)
        store_secret(default_keyring, args.keyring, keyring_pass)

    gnomekeyring.unlock_sync(args.keyring, keyring_pass)
    secret = get_secret(args.keyring, args.item_name)
    if not secret:
        secret = getpass.getpass('New password for ' + args.item_name + ': ')
        store_secret(args.keyring, args.item_name, secret)
    print(secret)
Ejemplo n.º 21
0
#!/usr/bin/env python
# -*- mode: python; coding: utf-8 -*-

import getpass
import gnomekeyring

pw = getpass.getpass('keyring password: ')
gnomekeyring.unlock_sync(None, pw)
Ejemplo n.º 22
0
 def __init__(self, keyring = 'passwords'):
     self.keyring = 'passwords'
     if gk.get_info_sync(self.keyring).get_is_locked():
         print "The %s keyring is locked, please type the password" % self.keyring
         password = getpass()
         gk.unlock_sync(self.keyring, password)
Ejemplo n.º 23
0
 def Unlock(self):
     gk.unlock_sync(self.keyring_name, self.__keyring_password)
Ejemplo n.º 24
0
   def __init__(self):
      global keyring
      self.username  = None
      self.password  = None
      self.multiline = False
      self.separator = False
      self.gconf     = gconf.client_get_default()
      self.appname   = "gtracker"

      self.username_key   = "/apps/gtracker/username"
      self.password_key   = "/apps/gtracker/password"
      self.interval_key   = "/apps/gtracker/interval"
      self.multi_key      = "/apps/gtracker/multiline"
      self.sep_key        = "/apps/gtracker/separator"

      self.interval = self.gconf.get_int(self.interval_key)
      if self.interval<1:
         self.interval = 15
         self.gconf.set_int(self.interval_key,self.interval)

      self.multiline = self.gconf.get_bool(self.multi_key)
      if self.multiline==None:
         self.multiline = True
         self.gconf.set_bool(self.multi_key,self.multiline)

      self.separator = self.gconf.get_bool(self.sep_key)
      if self.separator==None:
         self.separator = True
         self.gconf.set_bool(self.sep_key,self.separator)

      if keyring:
         try:
            glib.set_application_name(self.appname)
         except:
            pass
         if gk.is_available():
            names = gk.list_keyring_names_sync()
            if not self.appname in names:
               gk.create_sync(self.appname,"")

            keys = gk.list_item_ids_sync(self.appname)
            if len(keys)==1:
               gk.unlock_sync(self.appname,"")
               info = gk.item_get_info_sync(self.appname,keys[0])
               self.username  = info.get_display_name() 
               self.password  = info.get_secret()
            else:
               self.username  = ""
               self.password  = ""
         else:
            keyring = False

      if not keyring:
         self.username = self.gconf.get_string(self.username_key)
         if self.username==None or len(self.username)<1:
            self.username = ""
            self.gconf.set_string(self.username_key,"")

         self.password = self.gconf.get_string(self.password_key)
         if self.password==None or len(self.password)<1:
            self.password = ""
            self.gconf.set_string(self.password_key,self.password)
      else:
         self.gconf.unset(self.username_key)
         self.gconf.unset(self.password_key)
Ejemplo n.º 25
0
#!/usr/bin/env python

import gnomekeyring
import getpass

locked=gnomekeyring.get_info_sync(gnomekeyring.get_default_keyring_sync()).get_is_locked()

if(locked):
  gnomekeyring.unlock_sync(None, getpass.getpass('Password: '******'already unlocked'
Ejemplo n.º 26
0
    def __init__(self):
        global keyring
        self.username = None
        self.password = None
        self.multiline = False
        self.separator = False
        self.gconf = gconf.client_get_default()
        self.appname = "gtracker"

        self.username_key = "/apps/gtracker/username"
        self.password_key = "/apps/gtracker/password"
        self.interval_key = "/apps/gtracker/interval"
        self.multi_key = "/apps/gtracker/multiline"
        self.sep_key = "/apps/gtracker/separator"

        self.interval = self.gconf.get_int(self.interval_key)
        if self.interval < 1:
            self.interval = 15
            self.gconf.set_int(self.interval_key, self.interval)

        self.multiline = self.gconf.get_bool(self.multi_key)
        if self.multiline == None:
            self.multiline = True
            self.gconf.set_bool(self.multi_key, self.multiline)

        self.separator = self.gconf.get_bool(self.sep_key)
        if self.separator == None:
            self.separator = True
            self.gconf.set_bool(self.sep_key, self.separator)

        if keyring:
            try:
                glib.set_application_name(self.appname)
            except:
                pass
            if gk.is_available():
                names = gk.list_keyring_names_sync()
                if not self.appname in names:
                    gk.create_sync(self.appname, "")

                keys = gk.list_item_ids_sync(self.appname)
                if len(keys) == 1:
                    gk.unlock_sync(self.appname, "")
                    info = gk.item_get_info_sync(self.appname, keys[0])
                    self.username = info.get_display_name()
                    self.password = info.get_secret()
                else:
                    self.username = ""
                    self.password = ""
            else:
                keyring = False

        if not keyring:
            self.username = self.gconf.get_string(self.username_key)
            if self.username == None or len(self.username) < 1:
                self.username = ""
                self.gconf.set_string(self.username_key, "")

            self.password = self.gconf.get_string(self.password_key)
            if self.password == None or len(self.password) < 1:
                self.password = ""
                self.gconf.set_string(self.password_key, self.password)
        else:
            self.gconf.unset(self.username_key)
            self.gconf.unset(self.password_key)
Ejemplo n.º 27
0
		def decorator(self, *args, **kwargs):
			gnomekeyring.unlock_sync(KEYRING_NAME, KEYRING_PASSWD)
			ret = fn(self, *args, **kwargs)
			gnomekeyring.lock_sync(KEYRING_NAME)
			return ret
Ejemplo n.º 28
0
 def unlock_app(self):
     inf = gk.get_info_sync(self._app_name)
     if inf.get_is_locked():
         gk.unlock_sync(self._app_name, self._app_pass)