[Python +脚本关于/usr/lib64/python2.7下的密码失败

问题描述 投票:1回答:1

我创建以下python脚本

此python脚本会将文件/lpp/airflow/.sec/rmq_pass读取到var-pass_hash

并将其解密为decrypted_pass

more security_test.py
import sys
import os
import base64
from cryptography.fernet import Fernet

key_file = "/lpp/airflow/.sec/key"
rmq_pass_file = "/lpp/airflow/.sec/rmq_pass"

key = open(key_file, 'r')
f = Fernet(key.read())

pass_hash  = open(rmq_pass_file, 'r')
#decrypting the password from "pass_file" file using the key from the "key_file".
decrypted_pass = f.decrypt(pass_hash.read())
ConnStr = "amqp://airflow:" + decrypted_pass  + "@localhost:5672//"

当我运行脚本时它在/usr/lib64/python2.7/site-packages/cryptography/fernet.py或/usr/lib64/python2.7/site-packages/cryptography下的任何失败

我们尝试重新安装软件包加密法,但这没有帮助

并且知道可能是什么?

python  security_test.py
Traceback (most recent call last):
  File "security_test.py", line 14, in <module>
    decrypted_pass = f.decrypt(pass_hash.read())
  File "/usr/lib64/python2.7/site-packages/cryptography/fernet.py", line 75, in decrypt
    return self._decrypt_data(data, timestamp, ttl)
  File "/usr/lib64/python2.7/site-packages/cryptography/fernet.py", line 117, in _decrypt_data
    self._verify_signature(data)
  File "/usr/lib64/python2.7/site-packages/cryptography/fernet.py", line 101, in _verify_signature
    h = HMAC(self._signing_key, hashes.SHA256(), backend=self._backend)
  File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/hmac.py", line 31, in __init__
    self._ctx = self._backend.create_hmac_ctx(key, self.algorithm)
  File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 207, in create_hmac_ctx
    return _HMACContext(self, key, algorithm)
  File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/hmac.py", line 34, in __init__
    key_ptr = self._backend._ffi.from_buffer(key)
TypeError: from_buffer() cannot return the address of the raw string within a str or unicode or bytearray object

重要提示-在其他计算机上,此脚本运行正常

什么是解决它的最佳方法?通过删除所有模块并再次安装它们?或通过重新安装python?

我创建了以下python脚本,此python脚本会将文件/lpp/airflow/.sec/rmq_pass读取到var-pass_hash并将其解密为解密_pass更多security_test.py import sys ...

python python-2.7 cryptography airflow rhel
1个回答
0
投票
[如果此文件是由pip安装的,那么此问题是由于cffi包已过期(我能够通过在cffi中强制安装virtualenv 1.5来重现此问题) 。较新版本的cryptography需要cffi >= 1.8,但pip并不总是能正确解决此问题(取决于其他各种情况)。您可以pip install -U cffi查看是否可以解决该问题,但是通常,您应该强烈考虑在virtualenv内部运行Python代码,而不是将软件包安装到全局软件包空间中。 OS软件包管理器假定它拥有全局软件包,并且如果将分发软件包与pip安装混合并匹配,则可能导致安装问题。
© www.soinside.com 2019 - 2024. All rights reserved.