2010-01-18 81 views
3

我已经设置了侦听SSL端口的服务器。我能够连接到它,并有适当的凭据我可以访问服务(回波服务在下面的例子中)pyAMF客户端在哪里(代码中的哪个点)接受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:56467 DEBUG [根]读为响应41个字节看起来可疑,由于响应太短(证书是〜1K),我希望证书传输在调试日志中。

问题:客户端在哪个时间接受证书?它将在哪里被默认存储?哪个配置参数设置了默认位置?

回答

2

PyAMF在底层使用httplib来提供远程请求。当通过https://连接时,使用httplib.HTTPSConnection作为connection属性到RemotingService

它在文档中指出(参考HTTPSConnection):

注:这并不做任何证书验证

所以,在回答你的问题的证书基本上是忽略不计,即使您向connection提供key_file/cert_file参数。

实际忽略完成时connect方法被调用 - 当请求实际上是到网关制成..

[根]发送POST请求/网关

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

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

+0

@njoyce:感谢您的解释和链接。这为这个问题提供了一些启示。我想知道是否有可能强制接受证书。如果我尝试通过浏览器从Flex应用程序访问此网关,我会被要求接受证书。通过查看RemotingService API,我没有看到强制python客户端接受证书的方法。请分享你的想法。 – 2010-01-21 20:01:23