标签: pyopenssl

X.509证书序列号到十六进制转换

我正在尝试使用Pythons OpenSSL库获取X.509证书的序列号.

如果我像这样加载我的证书:

 x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, cert)
Run Code Online (Sandbox Code Playgroud)

然后打印序列号,如下所示:

print x509.get_serial_number()
Run Code Online (Sandbox Code Playgroud)

它看起来像这样:

5.283978953499081e+37 
Run Code Online (Sandbox Code Playgroud)

如果我将它转换为十六进制,如下所示:

'{0:x}'.format(int(5.283978953499081e+37))
Run Code Online (Sandbox Code Playgroud)

它返回:

27c092c344a6c2000000000000000000
Run Code Online (Sandbox Code Playgroud)

但是,从命令行使用OpenSSL打印证书序列号会返回此信息.

27:c0:92:c3:44:a6:c2:35:29:8f:d9:a2:fb:16:f9:b7
Run Code Online (Sandbox Code Playgroud)

为什么序列号的一半被转换为零?

python pyopenssl

6
推荐指数
1
解决办法
1964
查看次数

使用 python OpenSSL 从私钥获取公钥

好吧,我用 pyOpenSSL 生成一个私钥,如下所示:

from OpenSSL import crypto
k = crypto.PKey()
k.generate_key(crypto.TYPE_RSA, 2048)
print crypto.dump_privatekey(crypto.FILETYPE_PEM, k)
Run Code Online (Sandbox Code Playgroud)

如何从中获取公钥字符串?我仍然没有找到这个库的什么方法。谢谢

python openssl pyopenssl

5
推荐指数
1
解决办法
2944
查看次数

OpenSSL 识别“错误证书”的原因

我正在使用 pyOpenSSL,它是 OpenSSL 的包装器。我有一个客户端程序试图连接到我的服务器并且反复连接到sslv3 alert bad certificate服务器。直到我意识到是由于客户的时钟设置不当,我才能够找出问题所在。我猜测客户端看到服务器的证书在“未来”中过时并且以某种方式导致服务器上的证书sslv3 alert bad certificate

有没有办法更好地描述特定证书失败的原因?我假设在这种情况下,由于时钟设置不正确,客户端验证失败,但服务器端的错误与发送错误证书并且服务器端验证失败一样。

ssl openssl pyopenssl

5
推荐指数
1
解决办法
2万
查看次数

如何在 pyOpenSSL 中使用最新的 openssl 库?

我目前正在使用pyOpenssl,它使用1.0.1f系统安装的openssl 。现在我1.0.1j从源代码安装openssl ,并将新版本库路径设置为LD_LIBRARY_PATH,这时候,当我运行我的py文件时,它会产生错误:

File "sslcert.py", line 5, in <module>
from OpenSSL import SSL, _util, crypto
...

File "/usr/local/lib/python2.7/dist-packages/cffi-0.8.6-py2.7-linux-x86_64.egg/cffi/vengine_cpy.py", line 149, in load_library
    raise ffiplatform.VerificationError(error)
cffi.ffiplatform.VerificationError:  
importing '/usr/local/lib/python2.7/dist-packages/cryptography-0.6.1-py2.7-linux-x86_64.egg/cryptography/_Cryptography_cffi_36a40ff0x2bad1bae.so':    
/usr/local/lib/python2.7/dist-packages/cryptography-0.6.1-py2.7-linux-x86_64.egg/cryptography/_Cryptography_cffi_36a40ff0x2bad1bae.so:  
symbol EC_GFp_nistp521_method, version OPENSSL_1.0.1 not defined in file libcrypto.so.1.0.0 with link time reference
Run Code Online (Sandbox Code Playgroud)

我想知道为 pyOpenssl 使用最新的 openssl 库,如何解决这个问题?

python openssl pyopenssl

5
推荐指数
1
解决办法
4098
查看次数

Python SSLError,sslv3 警报握手失败,用于 wallhaven.cc

Python 版本:3.5.2

操作系统:OS X 10.12

OpenSSL 版本:OpenSSL 1.1.0b 2016 年 9 月 26 日

我正在尝试请求“ https://alpha.wallhaven.cc ”。

import urllib.request
init_page=urllib.request.urlopen("https://alpha.wallhaven.cc")
Run Code Online (Sandbox Code Playgroud)

然后得到

ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:645)
Run Code Online (Sandbox Code Playgroud)

During handling of the above exception, another exception occurred:
...
urllib.error.URLError: <urlopen error [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:645)>
Run Code Online (Sandbox Code Playgroud)

以下解决方案不起作用:

import requests.packages.urllib3.util.ssl_
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS='ALL'

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

import requests
print(requests.get("https://alpha.wallhaven.cc",verify=False))
Run Code Online (Sandbox Code Playgroud)

或更改 /APNSWrapper/connection.py 第 131 行:

ssl_version = self.ssl_module.PROTOCOL_SSLv3,
Run Code Online (Sandbox Code Playgroud)

进入

ssl_version = self.ssl_module.PROTOCOL_TLSv1,
Run Code Online (Sandbox Code Playgroud)

那么问题是什么?如何解决?非常感谢!

python ssl pyopenssl

5
推荐指数
1
解决办法
1万
查看次数

在 Python 中使用 ssl context.set_servername_callback

我的目标是允许 ssl 客户端从服务器的许多有效证书对中进行选择。客户端有一个 CA 证书,它将用来验证来自服务器的证书。

因此,为了尝试实现这一点,我ssl.SSLContext.set_servername_callback()将服务器上的 与ssl.SSLSocket.wrap_socket's parameter:server_hostname`结合使用,以尝试允许客户端指定要使用的密钥对。代码如下所示:

服务器代码:

import sys
import pickle
import ssl
import socket
import select

request = {'msgtype': 0, 'value': 'Ping', 'test': [chr(i) for i in range(256)]}
response = {'msgtype': 1, 'value': 'Pong'}

def handle_client(c, a):
    print("Connection from {}:{}".format(*a))
    req_raw = c.recv(10000)
    req = pickle.loads(req_raw)
    print("Received message: {}".format(req))
    res = pickle.dumps(response)
    print("Sending message: {}".format(response))
    c.send(res)

def run_server(hostname, port):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.bind((hostname, port))
    s.listen(8)
    print("Serving on {}:{}".format(hostname, port)) …
Run Code Online (Sandbox Code Playgroud)

python ssl pyopenssl

5
推荐指数
1
解决办法
3374
查看次数

Python OpenSSL:openssl s_client -connect

sudo openssl s_client -connect在 python open ssl 中的等价物是什么?

我查看了文档,但还没有找到任何有用的东西。我想将结果与验证者库进行比较,因为我不认为验证者库实际上是准确的。我只想得到以下内容:

---
New, TLSv1/SSLv3, Cipher is AES128-SHA
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : AES128-SHA
    Session-ID: CEB4CF30EA4F1074039F5596CDDCA1073D683FFAC6D1DA1F68FCBA0FDDADDD38
    Session-ID-ctx:
    Master-Key: F5929F0740A855C32F6755ED45710D467314AF16BE52962FC8664A6E5105A6004DEC9E64B92DFEFAC6FE80FDDE65C814
    Key-Arg   : None
    Start Time: 1490843868
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---
Run Code Online (Sandbox Code Playgroud)

我会在命令行调用中得到。

基本上,我想要一个相当于以下内容:

cert = CertInfo(host=hostname, port=443)  # ('RC4-SHA', 'TLSv1/SSLv3', 128)
info = cert.cipher()
Run Code Online (Sandbox Code Playgroud)

除了域之外,我不知道有关主机的任何信息,因此我试图弄清楚如何进行裸连接。这显然是不正确的,因为它错误:

context = ssl.create_default_context()

conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=hostname)
conn.connect(('google.com', …
Run Code Online (Sandbox Code Playgroud)

python ssl openssl pyopenssl

5
推荐指数
0
解决办法
2460
查看次数

Http request from Chrome hangs python webserver

I have a very basic python (2.7.12) web server (I've stripped it down as much as possible), code given below

import time
import ssl
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler

class Management(SimpleHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        SimpleHTTPRequestHandler.end_headers(self)
        self.wfile.write(time.asctime() + "\n")

httpd = HTTPServer(('', 4443), Management)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='./server.pem', server_side=True)
httpd.serve_forever()
Run Code Online (Sandbox Code Playgroud)

All it does is return the time. It works fine when I access it via https, but when I access it via http using (the latest version …

google-chrome pyopenssl python-2.7 python-3.x

5
推荐指数
2
解决办法
1778
查看次数

RemoveError: 'pyopenssl' 是 conda 的依赖项,无法从 conda 的运行环境中删除

我正在尝试在 Windows 10 上的 Ananconda 3.7 上安装和更新软件包。

当我运行代码时:

 conda update --all
Run Code Online (Sandbox Code Playgroud)

甚至

 conda install pandas
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

 RemoveError: 'pyopenssl' is a dependency of conda and cannot be removed from conda's operating environment
Run Code Online (Sandbox Code Playgroud)

我不确定这是为什么?也不确定是否pyopenssl应该删除这个包,如果它无论如何都会有所帮助。

python pyopenssl anaconda

5
推荐指数
1
解决办法
2024
查看次数

OpenSSL 的 Python 部分链命令

我正在尝试使用OpenSSLPython 中的模块进行证书验证。

我有窗口的openssl命令为:

openssl verify -partial_chain -CAfile Intermediate.pem UserCert.pem

你能建议我在 Python 中等效吗?

要求:这需要由OpenSSL或任何 Python3 模块完成。使用os.system将解决问题,但这不会满足要求。

python openssl pyopenssl x509certificate pycrypto

5
推荐指数
0
解决办法
169
查看次数