2012-01-13 7 views
0

我可能失去了一些東西真的傻了,錯過了Google Federated Login文檔中,但如何在谷歌OpenID登錄實際上確保對請求的網站?請求網站如何知道細節來自Google,而不僅僅是有人在URL中輸入查詢字符串參數?保護的谷歌的OpenID細節潛在欺騙到請求站點

爲了說明這一點,我在PHP中實現了一個基本的OpenID登錄序列,並且所有似乎返回的結果都是URL中的一串查詢字符串參數,我可以使用它來獲取OpenID詳細信息,這非常有效。問題是,如果我只是手動輸入到地址欄而沒有實際登錄Google,我的請求站點如何知道它們的區別?

首先,形式請求細節:

<form method='post' action='https://www.google.com/accounts/o8/ud'> 

    <input type='hidden' name='openid.return_to' value='http://www.example/com/logged-in' /> 

    <input type='hidden' name='openid.mode' value='checkid_setup' /> 
    <input type='hidden' name='openid.ns' value='http://specs.openid.net/auth/2.0' /> 
    <input type='hidden' name='openid.claimed_id' value='http://specs.openid.net/auth/2.0/identifier_select' /> 
    <input type='hidden' name='openid.identity' value='http://specs.openid.net/auth/2.0/identifier_select' /> 

    <input type='hidden' name='openid.ns.ax' value='http://openid.net/srv/ax/1.0' /> 
    <input type='hidden' name='openid.ax.mode' value='fetch_request' /> 
    <input type='hidden' name='openid.ax.required' value='email,firstname,lastname' /> 
    <input type='hidden' name='openid.ax.type.email' value='http://axschema.org/contact/email' /> 
    <input type='hidden' name='openid.ax.type.firstname' value='http://axschema.org/namePerson/first' /> 
    <input type='hidden' name='openid.ax.type.lastname' value='http://axschema.org/namePerson/last' /> 

    <input type='submit' value='Login With Google Account' /> 

</form> 

...偉大的工程,有一大堆的URL參數,如下圖所示送我回請求站點http://www.example.com/logged-in(從PHP print_r調用):

Array 
(
    [openid_ns] => http://specs.openid.net/auth/2.0 
    [openid_mode] => id_res 
    [openid_return_to] => http://www.example.com/logged-in 
    [openid_ext1_type_firstname] => http://axschema.org/namePerson/first 
    [openid_ext1_value_firstname] => {user's first name} 
    [openid_ext1_type_email] => http://axschema.org/contact/email 
    [openid_ext1_value_email] => {user's e-mail address} 
    [openid_ext1_type_lastname] => http://axschema.org/namePerson/last 
    [openid_ext1_value_lastname] => {user's last name} 
) 

...這是真棒,但我怎麼知道,這其實就是一個合法的要求,而不是有人在上面的參數輸入到地址欄?

感謝您的幫助,道歉,如果這已被要求已經(找不到任何副本!),如果我失去了一些東西明顯!

回答

1

沒有進入太多細節(閱讀OpenID的規範,如果你需要的血淋淋的細節)OpenID協議已制定保障措施這一點。您收到的斷言是有簽名和可驗證的,ID的命名空間有限制,以防止提供者欺騙對方的ID。如果您使用的是已建立的庫(例如,php-openid很好),您不必太擔心這件事,因爲它通常會在封面下面進行處理。如果你試圖推出自己的實現....好吧,只是不要...

這就是說,有一些事情,不是協議覆蓋。例如,儘管在響應中籤名屬性,但除非您信任特定提供商,否則不能認爲它們是準確的。有些應用程序會檢查提供斷言的提供商的URL /主機名(驗證響應後),並將已知的身份提供商列入白名單,以便進行適當的電子郵件驗證。如果你需要一個經過驗證的電子郵件,這樣做會使用戶獲得更好的UX。但是,如果斷言來自未知的身份提供者,則不要假設該電子郵件地址實際上屬於該用戶,除非您自己驗證擁有權。

+0

只是不?真的嗎?你知道你讓我想更多地調查這個,對嗎? ; P我最近遇到了另一個利用OpenID的方面,特別是Google登錄,稱爲'nonce'。基本上只使用一次的隨機數,這些隨機數的可以用來幫助保護認證,但它仍然看起來像一個狂熱的黑客可以在上面和僞造仍然跳自己的方式。感謝您抽出寶貴時間來回應史蒂夫! – 2012-01-27 09:40:14