我是python的新手,仍在学习它,所以我的问题可能有点天真.请忍受它;)
问题是客户端将发送CSR,我想用我的CA根证书签名并将签名的证书返回给客户端.
我一直在使用此命令使用命令行来执行此操作
openssl x509 -req -in device.csr -CA root.pem -CAkey root.key -CAcreateserial -out device.crt -days 500
同样的事我想用python实现.我遇到过openssl pyopenssl的 python库
是否有可能使用这个库?怎么样 ?或者shoudl我去M2Crypto?
我正在使用以下requirements.txtpip:
Django==1.4.3
Pillow==2.4.0
South==0.7.5
amqp==1.4.5
anyjson==0.3.3
argparse==1.2.1
billiard==3.3.0.18
boto==2.4.1
celery==3.1.12
cffi==0.8.6
cryptography==0.5.4
dj-database-url==0.2.0
django-annoying==0.7.6
django-appconf==0.6
django-articles==2.4.1
django-celery==3.1.10
django-compressor==1.3
django-debug-toolbar==1.2.1
django-jsonfield==0.9.13
django-pdb==0.4.0
django-postmark==0.1.6
django-s3-folder-storage==0.2
django-storages==1.1.4
docopt==0.6.1
facebook-sdk==0.4.0
google-api-python-client==1.2
gunicorn==0.15.0
httplib2==0.9
ipython==2.1.0
itsdangerous==0.24
kombu==3.0.20
mailchimp==2.0.8
path-and-address==0.2.0
psycopg2==2.4.5
pyOpenSSL==0.14
pycparser==2.10
pyparsing==2.0.2
python-dateutil==2.2
pytz==2013b
requests==2.3.0
six==1.8.0
sqlparse==0.1.11
tweepy==2.3.0
wsgiref==0.1.2
Run Code Online (Sandbox Code Playgroud)
在我添加之前,事情一直在进行
cffi==0.8.6
cryptography==0.5.4
google-api-python-client==1.2
httplib2==0.9
pyOpenSSL==0.14
pycparser==2.10
pyparsing==2.0.2
Run Code Online (Sandbox Code Playgroud)
我为了使用谷歌日历API而添加,因为它SignedJwtAssertionCredentials取决于pyOpenSSL.
现在,当我推送到heroku时,我在构建过程中遇到了错误,看似与之相关six,cffi或者cyrptography:
完整的构建日志在这里,但一些相关的片段:
Fetching repository, done.
-----> Python app detected
-----> Noticed cffi. …Run Code Online (Sandbox Code Playgroud) 我在 Windows 10 机器上安装了 python 2.7.17。然后我想通过在 python 中运行以下命令来测试它的 openssl 版本:
import ssl
print ssl.OPENSSL_VERSION_INFO
Run Code Online (Sandbox Code Playgroud)
我(1, 0, 2, 20, 15)
想升级到 1.1.1 版。做点冻结我得到:
import ssl
print ssl.OPENSSL_VERSION_INFO
Run Code Online (Sandbox Code Playgroud)
这些似乎是 pyOpenSSL 和密码学的最新 pip。
我安装的 openssl(作为 git bash 的一部分)是 1.1.1,但是,这与 python 中使用的版本不同。
如何将 python 中包含的 openssl 版本升级到 1.1.1 或更高版本?
编辑: 为了回应评论,以下是 python -m OpenSSL.debug 的结果:
C:\Users\assaf>python -m OpenSSL.debug
pyOpenSSL: 19.1.0
cryptography: 2.8
cffi: 1.14.0
cryptography's compiled against OpenSSL: OpenSSL 1.1.1d 10 Sep 2019
cryptography's linked OpenSSL: OpenSSL 1.1.1d 10 Sep 2019
Pythons's OpenSSL: …Run Code Online (Sandbox Code Playgroud) 我在ec2上使用亚马逊Linux的第一个默认AMI,似乎无法安装pyOpenSSL.我试过:sudo wget http://launchpad.net/pyopenssl/main/0.11/+download/pyOpenSSL-0.11.tar.gz&& easy_install pyOpenSSL-0.11.tar.gz.
Results were:
error: can't create or remove files in install directory
The following error occurred while trying to add or remove files in the
installation directory:
[Errno 13] Permission denied: '/usr/lib/python2.6/site-packages/test-easy-install-21047.write-test'
Run Code Online (Sandbox Code Playgroud)
还试过:结果是:sudo python setup.py build
/usr/lib/python2.6/distutils/dist.py:266: UserWarning: Unknown distribution option: 'zip_safe'
warnings.warn(msg)
running build
running build_py
running build_ext
building 'OpenSSL.crypto' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=pentium4 -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用openssl_sign()函数对文件进行签名。我有以下私钥:
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIDzQVg9bJ1kZFsZDoLeqadA4OTgKc40ukSmQ3MVzcV0soAcGBSuBBAAK
oUQDQgAEvzUNKCE3UVimCLUePomOUH/kfy0ujHdN5Kmn7ez3TtokJDy5ksVnOgf6
WzpmzY46zvKAnQ44Cgx5Kdqx5dVDiw==
-----END EC PRIVATE KEY-----
我正在使用以下功能:openssl_sign("test", $signature, $private_key, OPENSSL_ALGO_SHA256);.
我有一台可以使用给定密钥进行签名的服务器,而另一台则不能。一个有 PHP 5.6 ,另一个没有 PHP 7.1 。为什么一台服务器可以使用密钥而另一台则不能?
我们想在centos 7中升级OpenSSL但没有成功,原因可能是这样的。 通过 yum install openssl11 将 CentOS 7 升级到 OpenSSL 1.1.1
我开始知道 openssl11 是用于“现场”使用的。我们可以将 python / pyOpenssl 与 openssl11 链接起来吗?如果可以请给我流程
我正在尝试安装一些软件包并开始出现错误。然后在ubuntu中使用多个命令更新一些东西,但错误是相似的
pip install -U pip setuptools
or
python3 -m pip install --upgrade pip
or
sudo -H pip3 install --upgrade pip
Run Code Online (Sandbox Code Playgroud)
以下是错误示例
user@machine:~$ pip install cryptography
Traceback (most recent call last):
File "/usr/bin/pip", line 11, in <module>
load_entry_point('pip==20.0.2', 'console_scripts', 'pip')()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 490, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2854, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2445, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2451, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in …Run Code Online (Sandbox Code Playgroud) 因此,在用户需要为Scrapy安装的许多软件包中,我认为我遇到了pyOpenSSL问题.
当我尝试创建一个教程Scrapy项目时,我得到以下输出:
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 168, in <module>
execute()
File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 122, in execute
cmds = _get_commands_dict(settings, inproject)
File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 46, in _get_comma
nds_dict
cmds = _get_commands_from_module('scrapy.commands', inproject)
File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 29, in _get_comma
nds_from_module
for cmd in _iter_command_classes(module):
File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 20, in _iter_comm
and_classes
for module in walk_modules(module_name):
File "C:\Python27\lib\site-packages\scrapy\utils\misc.py", line …Run Code Online (Sandbox Code Playgroud) 因此,我使用 JIRA-Python 模块连接到我公司的 JIRA 实例,它要求我为此传递证书和密钥。但是,使用 OpenSSL 模块,我无法读取本地证书和密钥来将其传递给请求。
阅读代码如下
import OpenSSL.crypto
c = open('/Users/mpadakan/.certs/mpadakan-blr-mpsot-20160704.crt').read()
cert = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, c)
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
Traceback (most recent call last):
File "flaskApp.py", line 19, in <module>
cert = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, c)
TypeError: must be X509, not str
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何将本地 .crt 和 .key 文件读入 x509 对象吗?
用例:我想通过 python 请求模块找出主机名支持多少密码。
我找不到提供密码名称来请求模块挂钩的方法。任何人都可以建议提供指定密码的方法。
import ssl
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
class Ssl3HttpAdapter(HTTPAdapter):
""""Transport adapter" that allows us to use SSLv3."""
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(
num_pools=connections, maxsize=maxsize,
block=block, ssl_version=ssl.PROTOCOL_SSLv3)
Run Code Online (Sandbox Code Playgroud) pyopenssl ×10
python ×6
openssl ×3
python-2.7 ×3
python-3.x ×2
amazon-ec2 ×1
centos7 ×1
cryptography ×1
easy-install ×1
heroku ×1
https ×1
m2crypto ×1
php ×1
pip ×1
python-jira ×1
scrapy ×1
ubuntu ×1
windows ×1
windows-10 ×1