Ejemplo n.º 1
0
    def has_credentials(self):
        try:

            if self._key == gkey.ITEM_NETWORK_PASSWORD:
                attrs = {"server": self._server, "protocol": self._protocol}
                items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
                return len(items) > 0
            if self._key == gkey.ITEM_GENERIC_SECRET:
                attrs = {"name": self._name}
                items = gkey.find_items_sync(gkey.ITEM_GENERIC_SECRET, attrs)
                return len(items) > 0
        except gkey.DeniedError:
            return False
Ejemplo n.º 2
0
    def has_credentials(self):
        try:

            if self._key == gkey.ITEM_NETWORK_PASSWORD:
                attrs = {"server": self._server, "protocol": self._protocol}
                items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
                return len(items) > 0
            if self._key == gkey.ITEM_GENERIC_SECRET:
                attrs = {"name": self._name}
                items = gkey.find_items_sync(gkey.ITEM_GENERIC_SECRET, attrs)
                return len(items) > 0
        except gkey.DeniedError:
            return False
Ejemplo n.º 3
0
    def store_password(self, datasource):
        """Update password.

        If the gnomekeyring bindings are available, the password is stored
        in the keyring. Otherwise it's stored in datasources.cfg.

        It's assumed, that the data source has an ID. So, this method
        *must* be called after the data source has been saved once.

        :param datasource: A data source.
        """
        if not USE_KEYRING:
            return

        item_type = gnomekeyring.ITEM_GENERIC_SECRET
        attrs = {"crunchyfrog": datasource.id}
        try:
            entry = gnomekeyring.find_items_sync(item_type, attrs)
            entry = entry[0]
        except gnomekeyring.NoMatchError:
            entry = None
        if datasource.url.password is not None:
            gnomekeyring.item_create_sync(None, item_type,
                                          'crunchyfrog/%s' % datasource.id,
                                          attrs, datasource.url.password, True)
        elif entry is not None:
            gnomekeyring.item_delete_sync(None, entry.item_id)
Ejemplo n.º 4
0
 def has_credentials(self):
     try:
         attrs = {"server": self._server, "protocol": self._protocol}
         items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
         return len(items) > 0
     except gkey.DeniedError:
         return False
Ejemplo n.º 5
0
  def __init__(self, account=None, dialog=None):
    """Creates the account pane for configuring Twitter accounts"""
    gtk.VBox.__init__( self, False, 20 )
    self.ui = gtk.Builder()
    self.ui.set_translation_domain ("gwibber")
    self.ui.add_from_file (gwibber.resources.get_ui_asset("gwibber-accounts-twitter.ui"))
    self.ui.connect_signals(self)
    self.vbox_settings = self.ui.get_object("vbox_settings")
    self.pack_start(self.vbox_settings, False, False)
    self.show_all()

    self.account = account or {}
    self.dialog = dialog
    has_secret_key = True
    if self.account.has_key("id"):
      try:
        value = gnomekeyring.find_items_sync(gnomekeyring.ITEM_GENERIC_SECRET, {"id": str("%s/%s" % (self.account["id"], "secret_token"))})[0].secret
      except gnomekeyring.NoMatchError:
        has_secret_key = False

    try:
      if self.account.has_key("access_token") and self.account.has_key("secret_token") and self.account.has_key("username") and has_secret_key:
        self.ui.get_object("hbox_twitter_auth").hide()
        self.ui.get_object("fb_auth_done_label").set_label(_("%s has been authorized by Twitter") % self.account["username"])
        self.ui.get_object("hbox_twitter_auth_done").show()
      else:
        self.ui.get_object("hbox_twitter_auth_done").hide()
        self.ui.get_object("twitter_auth_button").modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("red"))
        if self.dialog:
          self.dialog.get_object('vbox_create').hide()
    except:
      self.ui.get_object("hbox_twitter_auth_done").hide()
      if self.dialog:
        self.dialog.get_object("vbox_create").hide()
Ejemplo n.º 6
0
Archivo: gktool.py Proyecto: ssato/misc
    def find(self, attrs, single=False):
        """Search for secret with $attrs in all of the keyrings.
        """
        self.check_attributes(attrs)

        results = []
        try:
            for k in gk.find_items_sync(self.type, attrs):
                x = {"keyring": k.keyring, "id": k.item_id, "attributes": k.attributes, "secret": k.secret}
                try:
                    x["display_name"] = gk.item_get_info_sync(k.keyring, k.item_id).get_display_name()
                except gk.DeniedError:
                    raise  # should not happen.

                logging.info(" x = %s" % str(x))
                results.append(x)

                if single:
                    return results

        except gk.NoMatchError:
            pass
        except:
            raise

        return results
Ejemplo n.º 7
0
 def get_credentials(self, scheme, host, port=None, user=None, path=None, 
                     realm=None):
     if gnomekeyring is None:
         return None
     attrs = {
         "protocol": scheme.encode("utf-8"),
         "server": host.encode("utf-8"),
         }
     # TODO: realm ?
     if port is not None:
         attrs["port"] = port
     if user is not None:
         attrs["user"] = user.encode("utf-8")
     credentials = { "scheme": scheme, "host": host, "port": port, 
         "realm": realm, "user": user}
     try:
         items = gnomekeyring.find_items_sync(
             gnomekeyring.ITEM_NETWORK_PASSWORD, attrs)
         credentials["user"] = items[0].attributes["user"]
         credentials["password"] = items[0].secret
         return credentials
     except (gnomekeyring.NoMatchError, gnomekeyring.DeniedError, gnomekeyring.NoKeyringDaemonError,
             gnomekeyring.IOError), e:
         from bzrlib import trace
         trace.mutter('Unable to obtain credentials for %r from GNOME keyring: %r',
                      attrs, e)
         return None
 def has_credentials(self):
     try:
         attrs = {"server": self._server, "protocol": self._protocol}
         items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
         return len(items) > 0
     except gkey.DeniedError:
         return False
Ejemplo n.º 9
0
 def __get_credentials(self, key_name):
     try:
         items = gnomekeyring.find_items_sync(
             gnomekeyring.ITEM_GENERIC_SECRET, {"key_name": key_name})
         return items[0].attributes["user"], items[0].secret
     except (gnomekeyring.DeniedError, gnomekeyring.NoMatchError):
         return None, None
  def _GetNameAndPassword(self):
    """Display a modal dialog asking for a name and password.

    This info is used for login when deploying the applications; it is
    saved in GNOME keyring.

    Returns:
      wx.ID_OK or wx.ID_CANCEL
    """
    self._ConfigureDialog()
    rtn = self.dialog.ShowModal()
    if rtn == wx.ID_OK:
      self._authname = str(self.dialog.name_text_ctrl.GetValue())
      self._password = self.dialog.password_text_ctrl.GetValue()
      # Store information in keyring
      try:
        items = gk.find_items_sync(gk.ITEM_NETWORK_PASSWORD, self._gkAttr)
        for item in items:
          if item.attributes["user"] != self._authname:
            gk.item_delete_sync('login', item.item_id)
      except gk.NoMatchError:
        pass

      self._gkAttr["user"] = self._authname
      gk.item_create_sync('login', gk.ITEM_NETWORK_PASSWORD, 'Google App Engine Credentials', self._gkAttr, self._password, True)

    return rtn
Ejemplo n.º 11
0
    def test_keyring_populate(self):
        attr = { 'token' : 'the-token',
                 'consumer-key' : 'the-consumer-key',
                 'usage' : 'software-center-agent-token',
                 }
        secret = 'consumer_secret=xxx&token=xxx&consumer_key=xxx&token_secret=xxx&name=s-c'

        keyring_names = gk.list_keyring_names_sync()
        print keyring_names
        self.assertFalse(self.KEYRING_NAME in keyring_names)
        gk.create_sync(self.KEYRING_NAME, "")
        keyring_names = gk.list_keyring_names_sync()
        self.assertTrue(self.KEYRING_NAME in keyring_names)
        res = gk.item_create_sync(self.KEYRING_NAME,
                                  gk.ITEM_GENERIC_SECRET, 
                                  "Software Center Agent token",
                                  attr,
                                  secret,
                                  True) # update if exists
        self.assertTrue(res)

        # get the token from the keyring using the 'usage' field
        # in the attr
        search_attr = { 'usage' :  'software-center-agent-token',
                        }
        found = gk.find_items_sync(gk.ITEM_GENERIC_SECRET,
                                   search_attr)
        self.assertEqual(len(found), 1)
        for item in found:
            self.assertEqual(item.keyring, self.KEYRING_NAME)
            #print item.item_id, item.attributes
            self.assertEqual(item.secret, secret)
Ejemplo n.º 12
0
 def get_credentials(self):
     """
     Get a key.
     """
     attrs = {"server": self._server, "protocol": self._protocol}
     items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
     return (items[0].attributes["user"], items[0].secret)
Ejemplo n.º 13
0
    def ask_password(self, method, key, message, first):
        """Query for a password."""
        display_name = "submit password %s.%s" % (method, key)
        attrs = dict(submit=1, method=method, key=key)
        try:
            # first try: perhaps the correct password is in the keyring
            if first:
                try:
                    items = gnomekeyring.find_items_sync(
                            gnomekeyring.ITEM_GENERIC_SECRET, attrs)
                    return items[0].secret
                except gnomekeyring.NoMatchError:
                    pass

            # no, it isn’t; show a dialog to get the password
            password, store = self.password_dialog(
                    method, key, message, first, True)
            if password is None: return None

            if store:
                gnomekeyring.item_create_sync(
                        self.keyring, gnomekeyring.ITEM_GENERIC_SECRET,
                        display_name, attrs, password, True)

            return password

        except gnomekeyring.DeniedError:
            raise AuthenticationFailedError(
                    n_("Unable to access GNOME keyring."))
Ejemplo n.º 14
0
 def __init__(self, account=None, dialog=None):
   """Creates the account pane for configuring facebook accounts"""
   gtk.VBox.__init__( self, False, 20 )
   self.ui = gtk.Builder()
   self.ui.set_translation_domain ("gwibber")
   self.ui.add_from_file (resources.get_ui_asset("gwibber-accounts-facebook.ui"))
   self.ui.connect_signals(self)
   self.vbox_settings = self.ui.get_object("vbox_settings")
   self.pack_start(self.vbox_settings, False, False)
   self.show_all()
   if account:
     self.account = account
   else:
     self.account = {}
   self.dialog = dialog
   has_access_token = True
   if self.account.has_key("id"):
     try:
       value = gnomekeyring.find_items_sync(gnomekeyring.ITEM_GENERIC_SECRET, {"id": str("%s/%s" % (self.account["id"], "access_token"))})[0].secret
     except gnomekeyring.NoMatchError:
       has_access_token = False
   try:
     if self.account["access_token"] and self.account["username"] and has_access_token and not self.dialog.condition:
       self.ui.get_object("hbox_facebook_auth").hide()
       self.ui.get_object("fb_auth_done_label").set_label(_("%s has been authorized by Facebook") % str(self.account["username"]))
       self.ui.get_object("hbox_facebook_auth_done").show()
     else:
       self.ui.get_object("hbox_facebook_auth_done").hide()
       if self.dialog.ui:
         self.dialog.ui.get_object('vbox_create').hide()
   except:
     self.ui.get_object("hbox_facebook_auth_done").hide()
     if self.dialog.ui:
       self.dialog.ui.get_object("vbox_create").hide()
Ejemplo n.º 15
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.º 16
0
 def get_credentials(self):
     """
     Get a key.
     """
     attrs = {"server": self._server, "protocol": self._protocol}
     items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
     return (items[0].attributes["user"], items[0].secret)
Ejemplo n.º 17
0
 def get_passwd(self, user):
     self.attributes['user'] = user
     try:
         items = gkey.find_items_sync(self.scheme, self.attributes)
         return (items[0].attributes["user"], items[0].secret)
     except (gkey.NoMatchError, gkey.CancelledError, IndexError):
         return None
Ejemplo n.º 18
0
 def get_passwd(self, user):
     self.attributes['user'] = user
     try:
         items = gkey.find_items_sync(self.scheme, self.attributes)
         return (items[0].attributes["user"], items[0].secret)
     except (gkey.NoMatchError, gkey.CancelledError, IndexError):
         return None
Ejemplo n.º 19
0
  def __init__(self, account=None, dialog=None):
    """Creates the account pane for configuring identi.ca accounts"""
    gtk.VBox.__init__( self, False, 20 )
    self.ui = gtk.Builder()
    self.ui.set_translation_domain ("gwibber")
    self.ui.add_from_file (resources.get_ui_asset("gwibber-accounts-identica.ui"))
    self.ui.connect_signals(self)
    self.vbox_settings = self.ui.get_object("vbox_settings")
    self.pack_start(self.vbox_settings, False, False)
    self.show_all()

    self.account = account or {}
    self.dialog = dialog
    self.url_prefix = "https://identi.ca"
    has_secret_key = True
    if self.account.has_key("id"):
      try:
        value = gnomekeyring.find_items_sync(gnomekeyring.ITEM_GENERIC_SECRET, {"id": str("%s/%s" % (self.account["id"], "secret_token"))})[0].secret
      except gnomekeyring.NoMatchError:
        has_secret_key = False

    try:
      if self.account.has_key("access_token") and self.account.has_key("secret_token") and self.account.has_key("username") and has_secret_key:
        self.ui.get_object("hbox_statusnet_auth").hide()
        self.ui.get_object("statusnet_auth_done_label").set_label(_("%s has been authorized by %s") % (self.account["username"]))
        self.ui.get_object("hbox_statusnet_auth_done").show()
      else:
        self.ui.get_object("hbox_statusnet_auth_done").hide()
        if self.dialog.ui:
          self.dialog.ui.get_object('vbox_create').hide()
    except:
      self.ui.get_object("hbox_statusnet_auth_done").hide()
      if self.dialog.ui:
        self.dialog.ui.get_object("vbox_create").hide()
Ejemplo n.º 20
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.º 21
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.º 22
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
Ejemplo n.º 23
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.º 24
0
def clear_cc_details():

    print "clearing CC details"
    try:
        ids = gnomekeyring.find_items_sync (gnomekeyring.ITEM_GENERIC_SECRET, keyring_attributes)
        gnomekeyring.item_delete_sync (keyring, id[0])
    except Exception, e:
        print e
Ejemplo n.º 25
0
def get_cc_details():
    print "getting CC details"
    try:
        ids = gnomekeyring.find_items_sync (gnomekeyring.ITEM_GENERIC_SECRET, keyring_attributes)
        data =  ids[0].secret
        return string.split(data, "\n")       
    except Exception, e:
        print e
 def get_password(self, user):
     attrs = {
         "server": self._server,
         "protocol": self._protocol,
         "user": user
     }
     items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
     return items[0].secret
Ejemplo n.º 27
0
 def __get_credentials(self, key_name):
     try:
         items = gnomekeyring.find_items_sync(
             gnomekeyring.ITEM_GENERIC_SECRET,
             {"key_name": key_name})
         return items[0].attributes["user"], items[0].secret
     except (gnomekeyring.DeniedError, gnomekeyring.NoMatchError):
         return None, None
Ejemplo n.º 28
0
 def get_password(self, volume):
     params = dict(appname = "truecrypt-control", volume = volume.encode('ascii','replace'))
     try:
         matches = gnomekeyring.find_items_sync(gnomekeyring.ITEM_GENERIC_SECRET, params)
         return matches[0].secret
     except gnomekeyring.NoMatchError:
         print "password not found"
         return None
Ejemplo n.º 29
0
 def has_credentials(self):
     try:
         attrs = {"server": self._server}
         items = gkey.find_items_sync(self._type, attrs)
         return len(items) > 0
     except gkey.DeniedError:
         return False
     except gkey.NoMatchError:
         return False
Ejemplo n.º 30
0
 def delete_credentials(self):
     attrs = {
         "server": self._server,
         "protocol": self._protocol,
         "user": self._user
     }
     items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
     id = items[0].item_id
     gkey.item_delete_sync(gkey.get_default_keyring_sync(), id)
Ejemplo n.º 31
0
	def delete_credentials(self, user, pw=None):
		attrs = {
				"user":user,
				"server":self._server,
				"protocol":self._protocol,
				}
		items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
		for item in items:
			gkey.item_delete_sync(None, item.item_id)
Ejemplo n.º 32
0
 def get_credentials(self, server, protocol=None):
     try:
         attrs = {"server": server}
         if protocol:
             attrs["protocol"] = protocol
         items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
         return (items[0].attributes["user"], items[0].secret)
     except gkey.NoMatchError:
         return None
Ejemplo n.º 33
0
def get_password():
    """Look up the account's IMAP password from the Gnome Keyring."""
    return gkey.find_items_sync(
        gkey.ITEM_NETWORK_PASSWORD,
        {
            "protocol": "imap",
            "server": "mail.messagingengine.com",
            "user": "******"
        }
    )[0].secret
Ejemplo n.º 34
0
	def get_credentials(self, user):
		attrs = {"server": self._server, "protocol": self._protocol}
		try:
			items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
			for item in items:
				if item.attributes["user"] == user:
					return item.secret
		except gkey.NoMatchError:
			pass
		return None
Ejemplo n.º 35
0
 def search_key(self,query):
     """
     Search for a key into the keyrings using query parameters
     """
     try:
         result_list = gk.find_items_sync(gk.ITEM_GENERIC_SECRET, query)
     except gk.NoMatchError:
         return None
     
     return result_list
Ejemplo n.º 36
0
def get_secret(id):
    value = ""
    try:
        value = gnomekeyring.find_items_sync(gnomekeyring.ITEM_GENERIC_SECRET,
                                             {"id": str(id)})[0].secret
        #mlock(value)
    except gnomekeyring.NoMatchError:
        print id
        raise exceptions.GwibberServiceError("keyring")

    return value
Ejemplo n.º 37
0
Archivo: key.py Proyecto: fheinle/mutt
def get_password(username, server):
    attrs = {
        'user':username,
        'server':server,
        'protocol':'imap'
    }
    items = gkey.find_items_sync(
        gkey.ITEM_NETWORK_PASSWORD,
        attrs
    )
    return items[0].secret
Ejemplo n.º 38
0
 def getPassword(self, user):
     attrs = {
         "server": self._server,
         'protocol': self._protocol,
         'user': str(user)
     }
     try:
         items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
         if items != []: return items[0].secret
         return False
     except:
         return False
Ejemplo n.º 39
0
def get_secret(id):
  value = ""
  try:
    value = gnomekeyring.find_items_sync(
        gnomekeyring.ITEM_GENERIC_SECRET,
        {"id": str(id)})[0].secret
    #mlock(value)
  except gnomekeyring.NoMatchError:
    print id
    raise exceptions.GwibberServiceError("keyring")

  return value
Ejemplo n.º 40
0
 def get_credentials(self):
     """
     @return: A tuple C{(user, password)} or throws an exception if the
         credentials for the account are not known
     """
     attrs = {"server": self._host, "protocol": self._protocol}
     items = gnomekeyring.find_items_sync(gnomekeyring.ITEM_NETWORK_PASSWORD, attrs)
     
     if (len(items) > 1):
         LOGGER.warn ("More than one account found for %s" % self._host)
     
     return (items[0].attributes["user"], items[0].secret)
  def _GetDataFromKeyring(self):
    """Get authname and password from GNOME keyring"""
    authname = ""
    password = ""
    try:
      items = gk.find_items_sync(gk.ITEM_NETWORK_PASSWORD, self._gkAttr)
      authname = items[0].attributes["user"]
      password = items[0].secret
    except gk.NoMatchError:
      pass

    return [authname, password]
Ejemplo n.º 42
0
 def deletePassword(self, user):
     attrs = {
         "server": self._server,
         'protocol': self._protocol,
         'user': str(user)
     }
     try:
         items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
     except:
         return
     for item in items:
         gkey.item_delete_sync(item.keyring, item.item_id)
Ejemplo n.º 43
0
 def getpass(self):
     try:
         result_list = gnomekeyring.find_items_sync(
             gnomekeyring.ITEM_GENERIC_SECRET, dict(appname=APP_NAME))
     except gnomekeyring.NoMatchError:
         # Create new credentials if nothing was found
         self.newpass()
     except BaseException as e:
         # Todo: add some logging
         pass
     else:
         self.login, self.password = result_list[0].secret.split('\n')
     return self.login, self.password
Ejemplo n.º 44
0
 def from_gnomekeyring(self):
     # Try for gtk gui specific credentials.
     try:
         items = gnomekeyring.find_items_sync(
             gnomekeyring.ITEM_GENERIC_SECRET, {
                 "aws-host": "aws.amazon.com",
             })
     except (gnomekeyring.NoMatchError, gnomekeyring.DeniedError):
         self.show_a_password_dialog()
         return None
     else:
         key_id, secret_key = items[0].secret.split(":")
         return AWSCredentials(access_key=key_id, secret_key=secret_key)
Ejemplo n.º 45
0
 def get_password_from_keyring(self, datasource):
     """Retrieve password from keyring and set it to datasource."""
     if not USE_KEYRING or datasource.url.password:
         return
     item_type = gnomekeyring.ITEM_GENERIC_SECRET
     attrs = {"crunchyfrog": datasource.id}
     try:
         entry = gnomekeyring.find_items_sync(item_type, attrs)
         entry = entry[0]
     except gnomekeyring.NoMatchError:
         entry = None
     if entry is not None:
         datasource.url.password = entry.secret
Ejemplo n.º 46
0
 def get_credentials(self, acc):
     self.lock.acquire()
     try:
         logger.debug("Getting credentials with gnome keyring for account %s" % (acc.get_name()))
         attrs = {"account_name": acc.get_name()}
         try:
             items = gk.find_items_sync(gk.ITEM_NETWORK_PASSWORD, attrs)
         except gk.NoMatchError, e:
             items = list()
         if len(items) < 1:
             raise KeyringException("Cannot find the keyring data for the account %s" % (acc.get_name()))
         
         logger.debug("items ok")
         return Credentials (items[0].attributes["username"], items[0].secret)
Ejemplo n.º 47
0
def get_item_id():
    global _item_id

    if _item_id:
        return _item_id

    try:
        results = gk.find_items_sync(gk.ITEM_GENERIC_SECRET, _attrs)
        _item_id = results[0].item_id
    except gk.NoMatchError:
        # Create item
        _item_id = gk.item_create_sync(_keyring, _type, _display_name, _attrs,
                                       '', True)
    return _item_id
Ejemplo n.º 48
0
 def hasPassword(self, user):
     try:
         attrs = {
             "server": self._server,
             'protocol': self._protocol,
             'user': str(user)
         }
         items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
         if items != []: return True
         return False
         #print items[0].attributes['user']
     except gkey.DeniedError:
         return False
     except gkey.NoMatchError:
         return False
Ejemplo n.º 49
0
def get_item_id():
    global _item_id

    if _item_id:
        return _item_id

    try:
        results = gk.find_items_sync(gk.ITEM_GENERIC_SECRET, _attrs)
        _item_id = results[0].item_id
    except gk.NoMatchError:
        # Check if ''_keyring'' has been created.
        if _keyring not in gk.list_keyring_names_sync():
            # if it is missing then create a new keyring called ''_keyring''
            gk.create_sync(_keyring, _keyring)
        # Create item
        _item_id = gk.item_create_sync(_keyring, _type, _display_name, _attrs,
                                       '', True)
    return _item_id
Ejemplo n.º 50
0
 def __init__(self, account=None, dialog=None):
     """Creates the account pane for configuring facebook accounts"""
     gtk.VBox.__init__(self, False, 20)
     self.ui = gtk.Builder()
     self.ui.set_translation_domain("gwibber")
     self.ui.add_from_file(
         gwibber.resources.get_ui_asset("gwibber-accounts-facebook.ui"))
     self.ui.connect_signals(self)
     self.vbox_settings = self.ui.get_object("vbox_settings")
     self.pack_start(self.vbox_settings, False, False)
     self.show_all()
     if account:
         self.account = account
     else:
         self.account = {}
     self.dialog = dialog
     has_secret_key = True
     if self.account.has_key("id"):
         try:
             value = gnomekeyring.find_items_sync(
                 gnomekeyring.ITEM_GENERIC_SECRET,
                 {"id": str("%s/%s" %
                            (self.account["id"], "secret_key"))})[0].secret
         except gnomekeyring.NoMatchError:
             has_secret_key = False
     try:
         if self.account["session_key"] and self.account[
                 "secret_key"] and self.account[
                     "username"] and has_secret_key:
             self.ui.get_object("hbox_facebook_auth").hide()
             self.ui.get_object("fb_auth_done_label").set_label(
                 _("%s has been authorized by Facebook") %
                 str(self.account["username"]))
             self.ui.get_object("hbox_facebook_auth_done").show()
         else:
             self.ui.get_object("hbox_facebook_auth_done").hide()
             self.ui.get_object("facebook_auth_button").modify_bg(
                 gtk.STATE_NORMAL, gtk.gdk.color_parse("red"))
             if self.dialog:
                 self.dialog.get_object('vbox_create').hide()
     except:
         self.ui.get_object("hbox_facebook_auth_done").hide()
         if self.dialog:
             self.dialog.get_object("vbox_create").hide()
Ejemplo n.º 51
0
def get_keychain_pass(account=None, server=None):
    if sys.platform == 'darwin':
        command = 'sudo -u ' + user + \
            ' /usr/bin/security -v find-internet-password -g -a ' + account +\
            ' -s ' + server + ' ' + home + '/Library/Keychains/login.keychain'
        output = subprocess.check_output(command, shell=True,
                                         stderr=subprocess.STDOUT)
        outtext = [l for l in output.splitlines()
                   if l.startswith('password: '******'password: "******"', outtext).group(1)

    elif sys.platform == 'linux2':

        attrs = {'server': server, 'protocol': 'http'}
        items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
        return (items[0].attributes['user'], items[0].secret)[1]

    else:
        raise Exception('Platform "' + sys.platform + '" not supported.')
Ejemplo n.º 52
0
    def LoginDetails(self, warning=False):
        """
		Displays the account details dialog.
		
		Parameters:
			warning -- True if the validation failed and the user must be informed.
		"""
        xmlString = pkg_resources.resource_string(__name__, "LoginDialog.ui")
        gtkBuilder = gtk.Builder()
        gtkBuilder.add_from_string(xmlString)

        signals = {
            "on_buttonOK_clicked": self.OnAcceptDetails,
            "on_buttonCancel_clicked": self.OnCancelDetails
        }
        gtkBuilder.connect_signals(signals)

        self.entryUsername = gtkBuilder.get_object("entryUsername")
        self.entryPassword = gtkBuilder.get_object("entryPassword")
        self.labelWarning = gtkBuilder.get_object("labelWarning")
        self.buttonOK = gtkBuilder.get_object("buttonOK")
        self.loginWindow = gtkBuilder.get_object("LoginDetailsDialog")

        self.entryUsername.set_activates_default(True)
        self.entryPassword.set_activates_default(True)
        self.buttonOK.set_flags(gtk.CAN_DEFAULT)
        self.buttonOK.grab_default()
        self.api.set_window_icon(self.loginWindow)

        # set the entry text to the saved values
        username = self.api.get_config_value("fsUsername")
        if username is not None and keyring:
            password = None
            try:
                items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD,
                                             {"username": username})
                if len(items) > 0:
                    password = items[0].secret
            except gkey.DeniedError, gkey.NoMatchError:
                pass
Ejemplo n.º 53
0
 def get_from_keyring(self, acctid, name):
   item = {"id": str("%s/%s" % (acctid, name))}
   try:
     return gnomekeyring.find_items_sync(gnomekeyring.ITEM_GENERIC_SECRET, item)[0].secret
   except gnomekeyring.NoMatchError:
     return None
Ejemplo n.º 54
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
Ejemplo n.º 55
0
def get_refresh_token(repo):
    # modified from
    # https://jason.the-graham.com/2011/01/16/gnome_keyring_with_msmtp_imapfilter_offlineimap/
    attrs = {"repo": repo}
    items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
    return (items[0].attributes["user"], items[0].secret)
Ejemplo n.º 56
0
def get_credentials(repo):
    keyring = gkey.get_default_keyring_sync()
    attrs = {"repo": repo}
    items = gkey.find_items_sync(gkey.ITEM_NETWORK_PASSWORD, attrs)
    return (items[0].attributes["user"], items[0].secret)