当前位置: 首页 > 面试题库 >

使用证书在https上起泡

孔波
2023-03-14
问题内容

我在带ssl的Apache下有肥皂服务,而没有ssl的suds效果很好。
我有客户端证书(my.crt和user.p12文件)。 我如何配置suds客户端,使其与通过https的服务一起使用?

我没有证书

urllib2.URLError:<URLopen错误[Errno 1] _ssl.c:499:错误:14094410:SSL例程:SSL3_READ_BYTES:sslv3警报握手失败>

问题答案:

听起来您想使用 客户端 证书而不是某些注释中所述的 服务器
证书进行身份验证。我遇到了同样的问题,并且能够为SUDS编写自定义传输。这是对我有用的代码。

您需要PEM格式的证书才能正常工作;OpenSSL可以轻松执行此转换,尽管我不记得确切的语法。

import urllib2, httplib, socket
from suds.client import Client
from suds.transport.http import HttpTransport, Reply, TransportError

class HTTPSClientAuthHandler(urllib2.HTTPSHandler):
    def __init__(self, key, cert):
        urllib2.HTTPSHandler.__init__(self)
        self.key = key
        self.cert = cert

    def https_open(self, req):
        #Rather than pass in a reference to a connection class, we pass in
        # a reference to a function which, for all intents and purposes,
        # will behave as a constructor
        return self.do_open(self.getConnection, req)

    def getConnection(self, host, timeout=300):
        return httplib.HTTPSConnection(host,
                                       key_file=self.key,
                                       cert_file=self.cert)

class HTTPSClientCertTransport(HttpTransport):
    def __init__(self, key, cert, *args, **kwargs):
        HttpTransport.__init__(self, *args, **kwargs)
        self.key = key
        self.cert = cert

    def u2open(self, u2request):
        """
        Open a connection.
        @param u2request: A urllib2 request.
        @type u2request: urllib2.Requet.
        @return: The opened file-like urllib2 object.
        @rtype: fp
        """
        tm = self.options.timeout
        url = urllib2.build_opener(HTTPSClientAuthHandler(self.key, self.cert))
        if self.u2ver() < 2.6:
            socket.setdefaulttimeout(tm)
            return url.open(u2request)
        else:
            return url.open(u2request, timeout=tm)

# These lines enable debug logging; remove them once everything works.
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)

c = Client('https://YOUR_URL_HERE',
    transport = HTTPSClientCertTransport('PRIVATE_KEY.pem',
                                         'CERTIFICATE_CHAIN.pem'))
print c


 类似资料:
  • 我正在尝试将Wildfly(10)配置为使用HTTPS的SSL证书。它似乎对8443工作正常(使用HTTPS://example.com:8443--没有错误,证书显示它是由CA签名的),但是当我将HTTPS切换到端口443时,每当我访问站点时(通过HTTPS://example.com,它会告诉我我的证书安装不正确,连接不安全,使用的是自签名密钥)。 以下是我的standalone.xml文件中

  • 也许我会在这里找到帮助。我想在spring boot应用程序上启用SSL。我的配置如下: 服务器:端口:8999 SSL:enabled:true key-store:classpath:keystore.jks key-store-password:mypass key-password:mypass 问题是我的密钥库。我已将*crt文件导入别名为“tomcat”的密钥存储库: 但是,我仍然无法

  • 问题内容: 是否可以在不使用Java证书的情况下将ssl与httpconnection一起使用?我想使用随机数或密钥。 感谢Raihan 问题答案: 尽管SSL / TLS并非严格要求证书,但HTTPS 要求使用证书,因为RFC 2818 (尤其是第3.1节)明确提到了X.509证书。 您可以在ServerFault的此答案中找到一个非常类似的问题的更多详细信息。 没有证书的任何操作都将超出RFC

  • 绑定域名 进入应用页面,点击域名选项 点击添加,输入自己的域名和备案号 请耐心等待,审核完成后您可在域名服务商处将自有域名的 CNAME 指向我们为您生成的 ***.daoapp.me 即可。 上传 HTTPS 证书 域名通过审核后可以点击上传证书,输入证书链和私钥,点击确认即可。