當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。