我有一个代码如下:
headers = {'content-type': 'ContentType.APPLICATION_XML'}
uri = "www.client.url.com/hit-here/"
clientCert = "path/to/cert/abc.crt"
clientKey = "path/to/key/abc.key"
PROTOCOL = ssl.PROTOCOL_TLSv1
context = ssl.SSLContext(PROTOCOL)
context.load_default_certs()
context.load_cert_chain(clientCert, clientKey)
conn = httplib.HTTPSConnection(uri, some_port, context=context)
Run Code Online (Sandbox Code Playgroud)
我不是一个真正的网络程序员,所以我做了一些谷歌握手连接,发现ssl.SSLContext(PROTOCOL)作为所需的功能,代码工作正常.
然后我遇到了障碍,我的本地版本为2.7.10但是所有的生产框都有2.7.3,所以SSLContext不支持升级python版本不是一个选项/控制.
我尝试读取ssl - 用于套接字对象的SSL包装器,但无法理解它.
我尝试了什么(徒劳):
s_ = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s = ssl.wrap_socket(s_, keyfile=clientKey, certfile=clientCert, cert_reqs=ssl.CERT_REQUIRED)
new_conn = s.connect((uri, some_port))
Run Code Online (Sandbox Code Playgroud)
但回报:
SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)')
Run Code Online (Sandbox Code Playgroud)
问题 - 如何在旧版本上生成SSL上下文以便建立安全的https连接?
我正在尝试通过NiFi 1.5.0中的GetHTTP处理器连接到REST端点。我面临的问题是SSL证书已颁发给域,但是我只能直接访问IP:Port地址(公司防火墙)。因此,我遇到了一个问题,即主机名和证书所有者不匹配,并且IP未添加为使用者替代名称。
当我尝试连接时,出现以下错误消息:
javax.net.ssl.SSLPeerUnverifiedException:<[IP-ADDRESS]>的证书与任何主题备用名称都不匹配:[]
有没有办法绕过主机名验证?我找到了这张NiFi Jira门票,但似乎尚未解决。有没有可以使用的解决方法?
应该如何转换javax.net.ssl.SSLContext为io.netty.handler.ssl.SslContext?我可以访问 SSLContext,但需要在我的客户端库中设置 SSlContext。
在使用 java8 的 Spring Boot 应用程序中,我将 httpClient 连接的底层 SSLConext 设置如下:
import javax.net.ssl.SSLContext;
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, null, null);
CloseableHttpClient httpClient = HttpClientBuilder
.create()
.setConnectionManager(myConnectionManager)
.setDefaultRequestConfig(rqConfig)
.setSSLContext(sslContext)
.build();
Run Code Online (Sandbox Code Playgroud)
我需要将底层 TLS1.2 安全连接的密码套件设置为我选择的更强大的东西。我没有看到通过在代码中创建 sslContext 的方式来做到这一点的方法。
有人可以帮我用 sslContext 设置密码套件吗?
===============更新=================
This is how I have now created my HttpClient
CloseableHttpClient httpClient = HttpClientBuilder
.create()
.setConnectionManager(myConnectionManager)
.setDefaultRequestConfig(rqConfig)
.setSSLSocketFactory(new SSLConnectionSocketFactory(
SSLContexts.createSystemDefault(),
new String[]{"TLSv1.2"},
new String[] {"some-gibberish-cipher-suite"},
SSLConnectionSocketFactory.getDefaultHostnameVerifier()))
.build();
Run Code Online (Sandbox Code Playgroud) 我想在 Android 上使用硬件支持的密钥进行客户端双向 TLS。钥匙应该通过生物识别技术解锁。
我找到了如何在 Android 上生成硬件支持的密钥对:
KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance( KeyProperties.KEY_ALGORITHM_RSA, "AndroidKeyStore");
keyGenerator.initialize(
new KeyGenParameterSpec.Builder(myAlias, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA512)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
.setUserAuthenticationRequired(true)
.build());
keyGenerator.generateKeyPair();
Run Code Online (Sandbox Code Playgroud)
以及如何使用指纹解锁硬件支持的私钥:
FingerprintManager fingerprintManager = (FingerprintManager) this.getSystemService(Context.FINGERPRINT_SERVICE);
PrivateKey key = (PrivateKey) keyStore.getKey(myAlias, null);
Cipher cipher = Cipher.getInstance(cipherAlgorithm, "AndroidKeyStore");
cipher.init(Cipher.DECRYPT_MODE, key);
FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
fingerprintManager.authenticate(cryptoObject, cancellationSignal, 0, authenticationCallback, null);
Run Code Online (Sandbox Code Playgroud)
我还可以将 HttpClient 配置为使用客户端证书:
// I have loaded the PrivateKey privateKey and Certificate certificate from PEM files
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(null);
final char pseudoSecretPassword[] = ("##" …Run Code Online (Sandbox Code Playgroud) import cloudscraper
import requests
scraper = cloudscraper.create_scraper() # returns a CloudScraper instance
# Or: scraper = cloudscraper.CloudScraper() # CloudScraper inherits from requests.Session
print (scraper.get("https://www.youtube.com/").text )
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-459-1f19dc044105> in <module>
2 import requests
3
----> 4 scraper = cloudscraper.create_scraper() # returns a CloudScraper instance
5 # Or: scraper = cloudscraper.CloudScraper() # CloudScraper inherits from requests.Session
6 print (scraper.get("https://www.youtube.com/").text )
~/.local/lib/python3.6/site-packages/cloudscraper/__init__.py in create_scraper(cls, sess, **kwargs)
315 Convenience function for creating a ready-to-go CloudScraper object.
316
--> …Run Code Online (Sandbox Code Playgroud)