3

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-1800:50:56,467 DEBUG [root]応答が短すぎる(証明書が〜1K)ため、応答の41バイトを読み取ると疑わしいように見え、証明書の転送がデバッグログ。

質問:クライアントはどの時点で証明書を受け入れますか?デフォルトではどこに保存されますか?デフォルトの場所を設定する構成パラメーターはどれですか?

4

1 に答える 1

2

PyAMFはhttplib、内部でリモート要求を強化するために使用します。を介して接続する場合https://httplib.HTTPSConnectionconnectionがへの属性として使用されますRemotingService

ドキュメントには、(HTTPSConnectionに関して)次のように記載されています。

注:これは証明書の検証を行いません

したがって、質問への回答では、にkey_file/cert_file引数を指定しても、証明書は基本的に無視されますconnection

実際の無視は、connectメソッドが呼び出されたとき、つまり、ゲートウェイに対して実際に要求が行われたときに行われます。

[ルート]POSTリクエストを/gatewayに送信しています

Read 41 bytes for the response暗号化されていないhttp応答の長さです。

この回答には、必要なすべての情報が含まれているとは限りませんが、表示されている動作を説明するための何らかの方法が必要です。

于 2010-01-21T01:41:24.707 に答える