这是一个家庭作业!我使用服务器的证书get_peer_certificate()
和调用dump_certificate将证书转储到变量中.格式是PEM,看起来对我来说.
-----BEGIN CERTIFICATE-----
GIBBERISH................
......................
........................
-----END CERTIFICATE-----
Run Code Online (Sandbox Code Playgroud)
如何从此文件('server.pubkey')中提取服务器的公钥,并plaintext使用RSA算法和任何python库进行加密.在撰写本文时,我正在使用pyOpenSSL
我目前正在尝试编写一个python服务器脚本,该脚本应根据其公钥对当前客户端进行身份验证.因为我正在使用扭曲,扭曲的文档中的例子让我开始.
虽然我可以使用示例代码生成密钥,连接和通信,但我还没有找到一种方法来以可用的格式获取客户端的公钥.在这个stackexchange问题中,有人从OpenSSL.crypto.PKey对象中提取公钥但不能将其转换为可读格式.因为在我可以通过方法或通过我的协议的任何方法访问PKeyx509证书的对象,这将是一个很好的方法.(不接受)答案建议尝试.不幸的是,这并没有真正产生预期的结果:虽然可以通过简单的文本替换功能修复和答案,但是base64字符串似乎与公钥不匹配.我已经提取了这里提到的公钥.它与函数的结果不匹配.verifyCallbackself.transport.getPeerCertificate()crypto.dump_privatekey(PKey)BEGIN PRIVATE KEYBEGIN PRIVATE KEYopenssl rsa -in client.key -pubout > client.pubdump_privatekey
虽然在启动板上仍存在OpenSSL的漏洞,但尚未修复.据报道,19个月前,有一些最近(2012年10月)的活动,我没有希望在回购中快速修复.
您是否有任何其他想法如何以与client.pub我上面提到的文件相当的格式获取公钥?也许存在扭曲或OpenSSL连接特定对象来保存此信息.请注意,我必须将公钥存储在协议对象中,以便以后可以访问它.
对不起,我没想到我无法将证书与连接关联起来.我已经添加了必须将公钥存储在协议实例中的要求.因此,使用JF Sebastian建议peerX509.as_pem()的postConnectionCheck函数内部不起作用.此外,至少在python-m2crypto的0.21.1-2ubuntu3版本中,我必须调用peerX509.get_rsa().as_pem()才能获得正确的公钥.使用peerX509.as_pem(None)(因为peerX509.as_pem()仍然需要密码)会产生与PyOpenSSL完全相同的输出crypto.dump_privatekey(PKey).也许有一个错误.
除此之外,答案向我展示了使用以下Echo协议类编写另一种解决方法的可能方法:
class Echo(Protocol):
def dataReceived(self, data):
"""As soon as any data is received, write it back."""
if self.transport.checked and not self.pubkeyStored:
self.pubkeyStored …Run Code Online (Sandbox Code Playgroud) 我正在使用Titanium 3.0并尝试更新pyOpenSSL.我检查了python网站,只看到Windows的可下载链接.在Tianium论坛中,他们说"如果您使用MacPorts或Homebrew安装Python,请使用相同的实用程序来安装PyOpenSSL和PyCrypto." 我尝试使用自制软件并做"brew install pyopenssl"并收到错误消息"没有可用的pyopenssl公式".有什么建议?
我需要使用pyOpenSSL从Python生成SSL证书.有谁知道是否可以设置subjectAltName?从文档(https://pythonhosted.org/pyOpenSSL/api/crypto.html#x509-objects)来看,它似乎并非如此.实际上,只提供了set_subject方法.有没有办法将其添加到证书中?
每当我尝试使用pip安装任何模块时,我都会收到此错误,但easy_install工作正常.我的Ubuntu 12.04机器中没有配置代理.以前它工作正常,只是知道,它是如何突然停止工作的.
这是我得到的错误,在运行时sudo pip install <any_package_name>:
Exception:
Traceback (most recent call last):
File "/tmp/tmpOA61D3/pip.zip/pip/basecommand.py", line 246, in main
status = self.run(options, args)
File "/tmp/tmpOA61D3/pip.zip/pip/commands/install.py", line 342, in run
requirement_set.prepare_files(finder)
File "/tmp/tmpOA61D3/pip.zip/pip/req/req_set.py", line 345, in prepare_files
functools.partial(self._prepare_file, finder))
File "/tmp/tmpOA61D3/pip.zip/pip/req/req_set.py", line 290, in _walk_req_to_install
more_reqs = handler(req_to_install)
File "/tmp/tmpOA61D3/pip.zip/pip/req/req_set.py", line 415, in _prepare_file
req_to_install, finder)
File "/tmp/tmpOA61D3/pip.zip/pip/req/req_set.py", line 376, in _check_skip_installed
finder.find_requirement(req_to_install, self.upgrade)
File "/tmp/tmpOA61D3/pip.zip/pip/index.py", line 425, in find_requirement
all_versions = self._find_all_versions(req.name)
File "/tmp/tmpOA61D3/pip.zip/pip/index.py", line 349, in _find_all_versions
index_locations …Run Code Online (Sandbox Code Playgroud) 我需要使用PyOpenSSL在Python中获得某个字符串的独立PKCS#7签名.我在.p12文件中有一个密钥.
到目前为止,我正在尝试这样做:
from OpenSSL.crypto import load_pkcs12, sign
pkcs12 = load_pkcs12(key_dat, key_pwd)
algo = pkcs12.get_certificate().get_signature_algorithm()
pkey = pkcs12.get_privatekey()
sg = sign(pkey, manifest, algo)
Run Code Online (Sandbox Code Playgroud)
但这不是必需的.
我搜索过网,但大多数示例都与签署电子邮件块有关,并使用M2Crypto.有没有办法在裸PyOpenSSL中做到这一点?
升级到php 5.6(mac os x sierra)后,我无法在本地测试环境中发送邮件.
但遗憾的是,在Symfony通过swiftmailer发送邮件是行不通的.
这是错误:
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Run Code Online (Sandbox Code Playgroud)
我到现在才发现:
因为php 5.6 openssl似乎是一个要求:http://php.net/manual/en/migration56.openssl.php
因为在更新后我没有能够使用file_get_contents而没有这个错误,所以我做的是 在我的php ini中指定一个 openssl.cafile =就像我在这里找到的那样:https://andrewyager.com/2016/10/ 04/PHP-上的MacOS-Sierra公司-斜面存取SSL的数据/
现在file_get_contents再次工作,但我无法通过smtp发送swiftmailer邮件.
这是我的swiftmailer配置:
swiftmailer:
transport: "smtp"
host: "smtp.gmail.com"
username: "%mailer_user%"
password: "%mailer_password%"
auth_mode: login
port: 587
encryption: tls
delivery_address: "%mailer_delivery_address%"
spool: { type: memory }
Run Code Online (Sandbox Code Playgroud)
我是否必须在symfony/swiftmailer的任何其他地方提供我的咖啡馆?
我已经发现了这个:PHP - 使用STARTTLS和自签名证书的Swiftmailer 但是硬编码这样的解决方案不是一个选项,因为我想部署代码库而不是每次都改变它.我更喜欢在系统级别上解决此问题.
在重新安装python3和python-pip后,当我尝试用pip做任何事情时,我得到了这个.
fran@fran:~$ pip -v
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 13, in <module>
from pip.exceptions import InstallationError, CommandError, PipError
File "/usr/lib/python2.7/dist-packages/pip/exceptions.py", line 6, in <module>
from pip._vendor.six import iteritems
File "/usr/lib/python2.7/dist-packages/pip/_vendor/__init__.py", line 64, in <module>
vendored("cachecontrol")
File "/usr/lib/python2.7/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
__import__(modulename, globals(), locals(), level=0)
File "/usr/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/__init__.py", line 9, in <module>
File "/usr/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/wrapper.py", line 1, in <module>
File "/usr/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/adapter.py", line 3, in <module>
File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/__init__.py", line 53, …Run Code Online (Sandbox Code Playgroud) 在升级pip后,我尝试进行'pip冻结',但是我发现了这个错误:
# pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB)
100% |################################| 1.3MB 737kB/s
Installing collected packages: pip
Found existing installation: pip 9.0.1
Uninstalling pip-9.0.1:
Successfully uninstalled pip-9.0.1
Successfully installed pip-10.0.1
# pip freeze
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/__init__.py", line 42, in <module>
from pip._internal import cmdoptions
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/cmdoptions.py", line 16, in <module>
from pip._internal.index import (
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/index.py", line 15, in <module>
from pip._vendor import html5lib, …Run Code Online (Sandbox Code Playgroud) 我有一个 DER 格式的私钥。我正在尝试将其转换为 PEM 并同时使用密码加密私钥。
这是我用来转换和加密的 openssl 命令:
> openssl rsa -aes256 -inform der -in temp_key.der -outform pem -passout pass:<password>
Run Code Online (Sandbox Code Playgroud)
我正在尝试在 Python 中实现类似的逻辑,其中我拥有 DER 格式的内存中密钥的数据。我想将其更改为 PEM,对其进行加密,然后存储到文件中。
我不太熟悉 Python 的加密库,并且很难找出转换和加密我的关键数据的正确方法。