1

我正在尝试使用 PHP 连接到 Google Talk XMPP 服务器。我成功建立连接并使用 X-OAUTH2 登录。然后谷歌要求我建立一个 TLS 连接。但是,当尝试将连接升级到 TLS 时,出现异常:stream_socket_enable_crypto(): Peer certificate CN='gmail.com' did not match expected CN='talk.google.com'.

这是我的步骤:

$stream = stream_socket_client('tcp://talk.google.com:5222', $error_num, $error_str);
// ... I login,
//server tells me to use TLS,
//I tell it I am going to,
//it tells me to proceed ...
stream_socket_enable_crypto($stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);

我得到这个错误:

stream_socket_enable_crypto(): Peer certificate CN='gmail.com' did not match expected CN='talk.google.com'

当然,如果我尝试通过tcp://gmail.comor连接到 xmpp 服务器tcp://www.gmail.com,它将无法正常工作。

我还尝试在登录之前建立 TLS(我认为这是更安全的方法),但我遇到了同样的问题。这是错误的整个握手:

Me:     <stream:stream to="gmail.com" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">

Google: <stream:stream from="gmail.com" id="7373AF2152849B51" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">
            <stream:features>
                <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
                    <required/>
                </starttls>
                <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
                    <mechanism>X-OAUTH2</mechanism>
                    <mechanism>X-GOOGLE-TOKEN</mechanism>
                </mechanisms>
            </stream:features>

Me:     <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="X-OAUTH2" auth:service="oauth2" xmlns:auth="http://www.google.com/talk/protocol/auth">Encrypted user and pass</auth>

Google: <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>

Me:     <stream:stream to="gmail.com" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">

Google: <stream:stream from="gmail.com" id="B3A6AD05178A5BF2" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">
            <stream:features>
                <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls">
                    <required/>
                </starttls>
                <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/>
                <session xmlns="urn:ietf:params:xml:ns:xmpp-session"/>
            </stream:features>

Me:     <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>

Google: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
4

1 回答 1

2

我还没有想出如何解决这个问题,但我可以通过从一开始就通过 tls 连接并使用端口 5223 来完全避免它:

stream_socket_client('tls://talk.google.com:5223', $error_num, $error_str);
于 2015-04-09T23:12:50.427 回答