簡體   English   中英

使用PHP在Google Talk XMPP TCP連接上使用TLS

[英]Using TLS on Google Talk XMPP TCP connection using PHP

我正在嘗試使用PHP連接到Google Talk XMPP服務器。 我成功建立了連接並使用X-OAUTH2登錄。 然后Google要求我建立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.comtcp://www.gmail.com連接到xmpp服務器,它將無法正常工作。

我還嘗試過在登錄之前建立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"/>

我還沒有弄清楚如何解決該問題,但是我可以通過從一開始就通過tls連接並使用端口5223來完全避免該問題:

stream_socket_client('tls://talk.google.com:5223', $error_num, $error_str);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM