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


Python gnupg.GPG属性代码示例

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


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

示例1: _generate_signature

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def _generate_signature(self, stream, timestamp_url, gnupghome):  # pragma: no cover
        # generate the signature
        gpg = gnupg.GPG(gnupghome=gnupghome)
        signature = gpg.sign_file(stream, detach=True)

        # have the signature remotely timestamped
        try:
            response = requests.post(
                timestamp_url, files={"file": signature.data}, timeout=2
            )
        except requests.Timeout:
            raise SPKSignError("Timestamp server did not respond in time")

        # check the response status
        if response.status_code != 200:
            raise SPKSignError(
                "Timestamp server returned with status code %d" % response.status_code
            )

        # verify the timestamp
        if not gpg.verify(response.content):
            raise SPKSignError("Cannot verify timestamp")

        response.encoding = "ascii"
        return response.text 
开发者ID:SynoCommunity,项目名称:spkrepo,代码行数:27,代码来源:utils.py

示例2: prompt_for_install

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def prompt_for_install(self):
        """
        Prompt user to install untrusted repo signing key
        """
        print(self.key_info)
        repo_key_url = "{0}/{1}".format(self.url, self.repo_signing_key)
        print(("warning: Repository key untrusted \n"
               "Importing GPG key 0x{0}:\n"
               "  Userid: \"{1}\"\n"
               "  From  : {2}".format(self.key_info['fingerprint'],
                                      self.key_info['uids'][0],
                                      repo_key_url)))
        response = prompt(u'Is this ok: [y/N] ')
        if response == 'y':
            self.install_key(self.raw_key)
            return True
        else:
            return False 
开发者ID:ThreatResponse,项目名称:margaritashotgun,代码行数:20,代码来源:repository.py

示例3: get_publickeys

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def get_publickeys(self):
        """
        This returns the public GPG key to be displayed in the Import Dialog.
        The administrator can send this public key to his token vendor and
        the token vendor can use this public key to encrypt the token import
        file.
        :return: a dictionary of public keys with fingerprint
        """
        public_keys = {}
        if path.isdir(self.gnupg_home):
            keys = self.gpg.list_keys(secret=True)
        else:
            keys = []
            log.warning(u"Directory {} does not exists!".format(self.gnupg_home))

        for key in keys:
            ascii_armored_public_key = self.gpg.export_keys(key.get("keyid"))
            public_keys[key.get("keyid")] = {"armor": ascii_armored_public_key,
                                             "fingerprint": key.get(
                                                 "fingerprint")}
        return public_keys 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:23,代码来源:importotp.py

示例4: add_pgp_key

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def add_pgp_key(self, public_key, signature, guid):
        """
        Adds a pgp public key to the profile. The user must have submitted a
        valid signature covering the guid otherwise the key will not be added to
        the profile.
        """
        gpg = gnupg.GPG()
        gpg.import_keys(public_key)
        if gpg.verify(signature) and guid in signature:
            p = self.profile.PublicKey()
            p.public_key = public_key
            p.signature = signature
            self.profile.pgp_key.MergeFrom(p)
            self.db.profile.set_proto(self.profile.SerializeToString())
            return True
        else:
            return False 
开发者ID:OpenBazaar,项目名称:OpenBazaar-Server,代码行数:19,代码来源:profile.py

示例5: read_key

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def read_key(path, gpg_bin, gpg_opts):
    """Read and decrypt a single key file.

    :param str path: The path to the key to decrypt.

    :param str gpg_bin: The path to the gpg binary.

    :param list gpg_opts: The options for gpg.

    :rtype: str
    :returns: The unencrypted content of the file at `path`.

    """
    gpg = GPG(gpgbinary=gpg_bin, options=gpg_opts)
    with open(path, 'rb') as key_file:
        return str(gpg.decrypt_file(key_file)) 
开发者ID:bfrascher,项目名称:passpy,代码行数:18,代码来源:gpg.py

示例6: write_key

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def write_key(path, key_data, gpg_bin, gpg_opts):
    """Encrypt and write a single key file.

    :param str path: The path to the key to decrypt.

    :param str gpg_bin: The path to the gpg binary.

    :param list gpg_opts: The options for gpg.

    """
    gpg = GPG(gpgbinary=gpg_bin, options=gpg_opts)
    gpg_recipients = _get_gpg_recipients(path)
    # pass always ends it's files with an endline
    if not key_data.endswith('\n'):
        key_data += '\n'
    key_data_enc = gpg.encrypt(key_data, gpg_recipients).data
    with open(path, 'wb') as key_file:
        key_file.write(key_data_enc) 
开发者ID:bfrascher,项目名称:passpy,代码行数:20,代码来源:gpg.py

示例7: _reencrypt_key

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def _reencrypt_key(path, gpg, gpg_recipients):
    """Reencrypt a single key.

    Gets called from :func:`passpy.gpg._reencrypt_path`.

    :param str path: The path to a gpg encrypted file.

    :param gpg: The gpg object.
    :type gpg: :class:`gnupg.GPG`

    :param list gpg_recipients: The list of GPG Ids to encrypt the key
        with.

    """
    with open(path, 'rb') as key_file:
        key_data = gpg.decrypt_file(key_file).data
    key_data_enc = gpg.encrypt(key_data, gpg_recipients).data
    with open(path, 'wb') as key_file:
        key_file.write(key_data_enc) 
开发者ID:bfrascher,项目名称:passpy,代码行数:21,代码来源:gpg.py

示例8: test_check_signature_of_commit_key_not_found

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def test_check_signature_of_commit_key_not_found():
    gpg_flexmock = flexmock(GPG)

    # No key present
    gpg_flexmock.should_receive("list_keys").and_return(flexmock(fingerprints=[]))

    # No key received
    gpg_flexmock.should_receive("recv_keys").and_return(flexmock(fingerprints=[]))

    # Signature cannot be checked
    repo_mock = flexmock(git=flexmock().should_receive("show").and_return("E").mock())

    verifier = CommitVerifier()
    with pytest.raises(PackitException) as ex:
        verifier.check_signature_of_commit(
            commit=flexmock(hexsha="abcd", repo=repo_mock),
            possible_key_fingerprints=["a"],
        )
    assert "Cannot receive" in str(ex)


# This could possibly but unlikely fail if all the default key servers are down. 
开发者ID:packit-service,项目名称:packit,代码行数:24,代码来源:test_security.py

示例9: decrypt_file

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def decrypt_file(encrypted_filename, decrypted_filename, key_filename='insecure_secret.key'):
    """
    Decrypts an encrypted file.

    Arguments:
        encrypted_filename (str): The full path to the PGP encrypted file.
        decrypted_filename (str): The full path of the the file to write the decrypted data to.
        key_filename (str): The name of the key file to use to decrypt the data. It should correspond to one of the
            keys found in the gpg-keys directory.

    """
    gpg_home_dir = tempfile.mkdtemp()
    try:
        gpg = gnupg.GPG(gnupghome=gpg_home_dir)
        gpg.encoding = 'utf-8'
        with open(os.path.join('gpg-keys', key_filename), 'r') as key_file:
            gpg.import_keys(key_file.read())

        with open(encrypted_filename, 'r') as encrypted_file:
            gpg.decrypt_file(encrypted_file, output=decrypted_filename)
    finally:
        shutil.rmtree(gpg_home_dir) 
开发者ID:edx,项目名称:edx-analytics-pipeline,代码行数:24,代码来源:fs.py

示例10: _decrypt

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def _decrypt(self):
        decrypted_eval_data = []
        for row in EvalRow.objects.all():
            decrypted_row = {
                "pk": row.pk,
                "user": row.user_identifier,
                "record": row.record_identifier,
                "action": row.action,
                "timestamp": row.timestamp.__str__(),
            }
            gpg = gnupg.GPG()
            gpg.import_keys(settings.CALLISTO_EVAL_PRIVATE_KEY)
            decrypted_eval_row = six.text_type(gpg.decrypt(six.binary_type(row.row)))
            if decrypted_eval_row:
                decrypted_row.update(json.loads(decrypted_eval_row))
            decrypted_eval_data.append(decrypted_row)
        return decrypted_eval_data 
开发者ID:project-callisto,项目名称:callisto-core,代码行数:19,代码来源:decrypt_eval_data.py

示例11: configure_gpg

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def configure_gpg(self, key: str, password: Optional[str]) -> None:
        """Configure the repo to sign tags with GPG."""
        home = os.environ["GNUPGHOME"] = mkdtemp(prefix="tagbot_gpg_")
        os.chmod(home, S_IREAD | S_IWRITE | S_IEXEC)
        logger.debug(f"Set GNUPGHOME to {home}")
        gpg = GPG(gnupghome=home, use_agent=True)
        # For some reason, this doesn't require the password even though the CLI does.
        import_result = gpg.import_keys(self._maybe_b64(key))
        if import_result.sec_imported != 1:
            logger.warning(import_result.stderr)
            raise Abort("Importing key failed")
        key_id = import_result.fingerprints[0]
        logger.debug(f"GPG key ID: {key_id}")
        if password:
            # Sign some dummy data to put our password into the GPG agent,
            # so that we don't need to supply the password when we create a tag.
            sign_result = gpg.sign("test", passphrase=password)
            if sign_result.status != "signature created":
                logger.warning(sign_result.stderr)
                raise Abort("Testing GPG key failed")
        self._git.config("user.signingKey", key_id)
        self._git.config("tag.gpgSign", "true") 
开发者ID:JuliaRegistries,项目名称:TagBot,代码行数:24,代码来源:repo.py

示例12: __init__

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def __init__(self):
        gnupg.GPG.__init__(self, gnupghome=Settings.get_default().gpg_location) 
开发者ID:bilelmoussaoui,项目名称:Authenticator,代码行数:4,代码来源:gnupg.py

示例13: get_default

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def get_default():
        if GPG.instance is None:
            GPG.instance = GPG()
        return GPG.instance 
开发者ID:bilelmoussaoui,项目名称:Authenticator,代码行数:6,代码来源:gnupg.py

示例14: mock_gpg_get_version

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def mock_gpg_get_version(monkeypatch):
    def _setver(self):
        self.binary_version = GPG_VERSION
    monkeypatch.setattr(
        GPG, '_check_sane_and_get_gpg_version', _setver)


#
# generic speed test creator
# 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:12,代码来源:test_openpgp_speed.py

示例15: gpg_init_only

# 需要导入模块: import gnupg [as 别名]
# 或者: from gnupg import GPG [as 别名]
def gpg_init_only(tmpdir, benchmark, openpgp_keys, monkeypatch, num_keys):
    keys = openpgp_keys[0:num_keys]
    gpg = GPG(homedir=tmpdir.dirname)
    for key in keys:
        gpg.import_keys(key.key_data) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:7,代码来源:test_openpgp_speed.py


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