pyAMF客户端在代码中的哪个位置接受SSL证书?
我设置了一个服务器,监听SSL端口。我可以连接到这个服务器,并且用正确的凭证访问服务(下面的例子是回显服务)。
下面的代码运行得很好,但我不太明白客户端在什么时刻接受证书。
服务器:
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')
现在,当我运行这个时,它运行得很好,客户端的日志如下:
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] 读取了41字节的响应看起来有点可疑,因为响应太短了(证书大约是1K),我本来期待证书的传输会在调试日志中显示出来。
问题:客户端在什么时刻接受证书?默认情况下,它会存储在哪里?哪个配置参数设置了默认位置?
1 个回答
2
PyAMF在后台使用httplib
来处理远程请求。当通过https://
连接时,它会使用httplib.HTTPSConnection作为RemotingService
的connection
属性。
文档中提到(关于HTTPSConnection):
注意:这并不进行任何证书验证
所以,回答你的问题,证书基本上是被忽略的,即使你给connection
提供了key_file
和cert_file
参数。
实际上,忽略是在调用connect
方法时发生的——也就是当请求真正发送到网关时……
[root] 正在向 /gateway 发送POST请求
Read 41 bytes for the response
表示未加密的http响应长度。
这个回答可能没有包含你所需的所有信息,但应该能帮助你理解你所看到的行为。