gpt4 book ai didi

python - pyAMF 客户端在哪里(代码中的哪一点)接受 SSL 证书?

转载 作者:行者123 更新时间:2023-11-28 17:54:52 50 4
gpt4 key购买 nike

我已经设置了一个监听 SSL 端口的服务器。我能够连接到它并使用适当的凭据我能够访问服务(下面示例中的 echo 服务)

下面的代码工作正常,但我不明白客户端在什么时候接受了证书

服务器:

import os.path
import logging
import cherrypy
from pyamf.remoting.gateway.wsgi import WSGIGateway

logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(levelname)-5.5s [%(name)s] %(message)s'
)

def auth(username, password):
users = {"user": "pwd"}
if (users.has_key(username) and users[username] == password):
return True
return False

def echo(data):
return data

class Root(object):
@cherrypy.expose
def index(self):
return "This is your main website"

gateway = WSGIGateway({'myservice.echo': echo,}, logger=logging, debug=True, authenticator=auth)

localDir = os.path.abspath(os.path.dirname(__file__))
CA = os.path.join(localDir, 'new.cert.cert')
KEY = os.path.join(localDir, 'new.cert.key')
global_conf = {'global': {'server.socket_port': 8443,
'environment': 'production',
'log.screen': True,
'server.ssl_certificate': CA,
'server.ssl_private_key': KEY}}

cherrypy.tree.graft(gateway, '/gateway/')
cherrypy.quickstart(Root(), config=global_conf)

客户:

import logging
from pyamf.remoting.client import RemotingService

logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(levelname)-5.5s [%(name)s] %(message)s'
)

client = RemotingService('https://localhost:8443/gateway', logger=logging)
client.setCredentials('user', 'pwd')

service = client.getService('myservice')
print service.echo('Echo this')

现在,当我运行它时,它运行OK,客户端日志如下:

2010-01-18 00:50:56,323 INFO  [root] Connecting to https://localhost:8443/gateway
2010-01-18 00:50:56,323 DEBUG [root] Referer: None
2010-01-18 00:50:56,323 DEBUG [root] User-Agent: PyAMF/0.5.1
2010-01-18 00:50:56,323 DEBUG [root] Adding request myservice.echo('Echo this',)
2010-01-18 00:50:56,324 DEBUG [root] Executing single request: /1
2010-01-18 00:50:56,324 DEBUG [root] AMF version: 0
2010-01-18 00:50:56,324 DEBUG [root] Client type: 0
2010-01-18 00:50:56,326 DEBUG [root] Sending POST request to /gateway
2010-01-18 00:50:56,412 DEBUG [root] Waiting for response...
2010-01-18 00:50:56,467 DEBUG [root] Got response status: 200
2010-01-18 00:50:56,467 DEBUG [root] Content-Type: application/x-amf
2010-01-18 00:50:56,467 DEBUG [root] Content-Length: 41
2010-01-18 00:50:56,467 DEBUG [root] Server: PyAMF/0.5.1 Python/2.5.2
2010-01-18 00:50:56,467 DEBUG [root] Read 41 bytes for the response
2010-01-18 00:50:56,468 DEBUG [root] Response: <Envelope amfVersion=0 clientType=0>
(u'/1', <Response status=/onResult>u'Echo this'</Response>)
</Envelope>
2010-01-18 00:50:56,468 DEBUG [root] Removing request: /1
Echo this

2010-01-18 00:50:56,467 DEBUG [root] Read 41 bytes for the response 看起来很可疑,因为响应太短(证书约为 1K)而且我希望证书传输在调试日志中。

问题:客户端在什么时候接受证书?默认情况下它将存储在哪里?哪个配置参数设置默认位置?

最佳答案

PyAMF 在后台使用 httplib 来支持远程处理请求。通过 https:// 连接时,httplib.HTTPSConnection用作 RemotingServiceconnection 属性。

它在文档中指出(引用 HTTPSConnection):

Note: This does not do any certificate verification

因此,在回答您的问题时,证书基本上会被忽略,即使您向 connection 提供 key_file/cert_file 参数也是如此。

实际的忽略是在 connect 方法被调用时完成的——当请求实际发送到网关时..

[root] Sending POST request to /gateway

Read 41 bytes for the response是未加密的http响应长度。

此答案可能不包含您需要的所有信息,但应该以某种方式解释您所看到的行为。

关于python - pyAMF 客户端在哪里(代码中的哪一点)接受 SSL 证书?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2084292/

50 4 0
文章推荐: css -