当前位置: 首页>>代码示例>>Python>>正文


Python GnuPG.sign方法代码示例

本文整理汇总了Python中mailpile.crypto.gpgi.GnuPG.sign方法的典型用法代码示例。如果您正苦于以下问题:Python GnuPG.sign方法的具体用法?Python GnuPG.sign怎么用?Python GnuPG.sign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mailpile.crypto.gpgi.GnuPG的用法示例。


在下文中一共展示了GnuPG.sign方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _check_password

# 需要导入模块: from mailpile.crypto.gpgi import GnuPG [as 别名]
# 或者: from mailpile.crypto.gpgi.GnuPG import sign [as 别名]
 def _check_password(self, password, account=None, fingerprint=None):
     if account:
         # We're going to keep punting on this for a while...
         return True
     elif fingerprint:
         sps = SecurePassphraseStorage(password)
         gpg = GnuPG(self.session.config)
         status, sig = gpg.sign('OK', fromkey=fingerprint, passphrase=sps)
         return (status == 0)
     else:
         return True
开发者ID:mailpile,项目名称:Mailpile,代码行数:13,代码来源:auth.py

示例2: _do_login

# 需要导入模块: from mailpile.crypto.gpgi import GnuPG [as 别名]
# 或者: from mailpile.crypto.gpgi.GnuPG import sign [as 别名]
    def _do_login(self, user, password, load_index=False, redirect=False):
        session, config = self.session, self.session.config
        session_id = self.session.ui.html_variables.get('http_session')

        # This prevents folks from sending us a DEFAULT user (upper case),
        # which is an internal security bypass below.
        user = user and user.lower()

        if not user:
            from mailpile.config import SecurePassphraseStorage
            sps = SecurePassphraseStorage(password)
            password = ''
            try:
                # Verify the passphrase
                gpg = GnuPG(use_agent=False)
                if gpg.is_available():
                    gpg.passphrase = sps.get_reader()
                    assert(gpg.sign('Sign This!')[0] == 0)

                    # Store the varified passphrase
                    config.gnupg_passphrase.data = sps.data

                    # Load the config and index, if necessary
                    if not config.loaded_config:
                        self._config()
                        if load_index:
                            self._idx()
                        else:
                            pass  # FIXME: Start load in background

                    session.ui.debug('Good passphrase for %s' % session_id)
                    return self._logged_in(redirect=redirect)
                else:
                    session.ui.debug('No GnuPG, checking DEFAULT user')
                    # No GnuPG, see if there is a DEFAULT user in the config
                    user = 'DEFAULT'

            except (AssertionError, IOError):
                session.ui.debug('Bad passphrase for %s' % session_id)
                return self._error(_('Invalid passphrase, please try again'))

        if user in config.logins or user == 'DEFAULT':
            # FIXME: Salt and hash the password, check if it matches
            #        the entry in our user/password list (TODO).
            # NOTE:  This hack effectively disables auth without GnUPG
            if user == 'DEFAULT':
                session.ui.debug('FIXME: Unauthorized login allowed')
                return self._logged_in(redirect=redirect)
            raise Exception('FIXME')

        self._error(_('Incorrect username or password'))
开发者ID:DarkKV,项目名称:Mailpile,代码行数:53,代码来源:auth.py

示例3: VerifyAndStorePassphrase

# 需要导入模块: from mailpile.crypto.gpgi import GnuPG [as 别名]
# 或者: from mailpile.crypto.gpgi.GnuPG import sign [as 别名]
def VerifyAndStorePassphrase(config, passphrase=None, sps=None):
    if passphrase and not sps:
        from mailpile.config import SecurePassphraseStorage
        sps = SecurePassphraseStorage(passphrase)
        passphrase = 'this probably does not really overwrite :-( '

    assert(sps is not None)
    gpg = GnuPG(use_agent=False)
    if gpg.is_available():
        gpg.passphrase = sps.get_reader()
        gpgr = config.prefs.gpg_recipient
        gpgr = gpgr if (gpgr not in (None, '', '!CREATE')) else None
        assert(gpg.sign('Sign This!', fromkey=gpgr)[0] == 0)

    return sps
开发者ID:dkm,项目名称:Mailpile,代码行数:17,代码来源:auth.py

示例4: VerifyAndStorePassphrase

# 需要导入模块: from mailpile.crypto.gpgi import GnuPG [as 别名]
# 或者: from mailpile.crypto.gpgi.GnuPG import sign [as 别名]
def VerifyAndStorePassphrase(config, passphrase=None, sps=None,
                                     key=None):
    if passphrase and not sps:
        from mailpile.config import SecurePassphraseStorage
        sps = SecurePassphraseStorage(passphrase)
        passphrase = 'this probably does not really overwrite :-( '

    assert(sps is not None)
    gpg = GnuPG(None, use_agent=False)
    if gpg.is_available():
        gpg.passphrase = sps.get_reader()
        gpgr = config.prefs.gpg_recipient
        gpgr = key or (gpgr if (gpgr not in (None, '', '!CREATE')) else None)
        assert(gpg.sign('Sign This!', fromkey=gpgr)[0] == 0)

    # Fun side effect: changing the passphrase invalidates the message cache
    import mailpile.mailutils
    mailpile.mailutils.ClearParseCache(full=True)

    return sps
开发者ID:Kriss-Kross,项目名称:Mailpile,代码行数:22,代码来源:auth.py

示例5: PrepareMail

# 需要导入模块: from mailpile.crypto.gpgi import GnuPG [as 别名]
# 或者: from mailpile.crypto.gpgi.GnuPG import sign [as 别名]
def PrepareMail(config, mailobj, sender=None, rcpts=None):
    if not sender or not rcpts:
        tree = mailobj.get_message_tree()
        sender = sender or tree['headers_lc']['from']
        if not rcpts:
            rcpts = ExtractEmails(tree['headers_lc'].get('to', ''))
            rcpts += ExtractEmails(tree['headers_lc'].get('cc', ''))
            rcpts += ExtractEmails(tree['headers_lc'].get('bcc', ''))
            if not rcpts:
                raise NoRecipientError()
            rcpts += [sender]

    # Cleanup...
    sender = ExtractEmails(sender)[0]
    sender_keyid = None
    if config.prefs.openpgp_header:
        try:
            gnupg = GnuPG()
            seckeys = dict([(x["email"], y["fingerprint"])
                            for y in gnupg.list_secret_keys().values()
                            for x in y["uids"]])
            sender_keyid = seckeys[sender]
        except:
            pass

    rcpts, rr = [sender], rcpts
    for r in rr:
        for e in ExtractEmails(r):
            if e not in rcpts:
                rcpts.append(e)

    msg = copy.deepcopy(mailobj.get_msg())

    # Remove headers we don't want to expose
    for bcc in ('bcc', 'Bcc', 'BCc', 'BCC', 'BcC', 'bcC'):
        if bcc in msg:
            del msg[bcc]

    if 'date' not in msg:
        msg['Date'] = email.utils.formatdate()

    if sender_keyid and config.prefs.openpgp_header:
        msg["OpenPGP"] = "id=%s; preference=%s" % (sender_keyid,
                                                   config.prefs.openpgp_header)

    # Sign and encrypt
    signatureopt = bool(int(tree['headers_lc'].get('do_sign', 0)))
    encryptopt = bool(int(tree['headers_lc'].get('do_encrypt', 0)))
    gnupg = GnuPG()
    if signatureopt:
        signingstring = MessageAsString(msg)
        signature = gnupg.sign(signingstring, fromkey=sender, armor=True)

        # FIXME: Create attachment, attach signature.
        if signature[0] == 0:
            # sigblock = MIMEMultipart(_subtype="signed",
            #                          protocol="application/pgp-signature")
            # sigblock.attach(msg)
            msg.set_type("multipart/signed")
            msg.set_param("micalg", "pgp-sha1")  # need to find this!
            msg.set_param("protocol", "application/pgp-signature")
            sigblock = MIMEText(str(signature[1]), _charset=None)
            sigblock.set_type("application/pgp-signature")
            sigblock.set_param("name", "signature.asc")
            sigblock.add_header("Content-Description",
                                "OpenPGP digital signature")
            sigblock.add_header("Content-Disposition",
                                "attachment; filename=\"signature.asc\"")
            msg.attach(sigblock)
        else:
            # Raise stink about signing having failed.
            pass
        #print signature

    #if encryptopt:
    #    encrypt_to = tree['headers_lc'].get('encrypt_to')
    #    newmsg = gnupg.encrypt(msg.as_string(), encrypt_to)
    #    # TODO: Replace unencrypted message

    # When a mail has been signed or encrypted, it should be saved as such.

    del(msg["do_sign"])
    del(msg["do_encrypt"])
    del(msg["encrypt_to"])

    return (sender, set(rcpts), msg)
开发者ID:crameth,项目名称:Mailpile,代码行数:88,代码来源:mailutils.py


注:本文中的mailpile.crypto.gpgi.GnuPG.sign方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。