iT邦幫忙

2024 iThome 鐵人賽

DAY 24
0
Security

Go!帶你探索 FIDO2 資安技術全端應用系列 第 24

【Go!帶你探索 FIDO2 資安技術全端應用】Day 24 - 開始進行前後端串接 (4)

  • 分享至 

  • xImage
  •  

昨天通過了第三關之後,今天要來接續第四關

串接之旅 Part 4

開始測試囉

串接第四關:failed to parse credential creation response, error: Error parsing attestation response

https://ithelp.ithome.com.tw/upload/images/20240922/20140363sVU9TEJEyI.png

從錯誤來看,是在解析 protocol.CredentialCreationResponse 中的 AttestationResponse 時發生錯誤所導致的

還記得前端在提供 attestationObject 給後端時,有用 base64RawURL 進行編碼嗎?
後端收到後,我們少做了 base64RawURL 解碼,就直接傳給 protocol.CredentialCreationResponse,所以才會出現這個錯誤

下面就來針對 attestationObject 進行 base64RawURL 解碼

authenticatorAttestationObject, err := base64.RawURLEncoding.DecodeString(request.Response.AttestationObject)
if err != nil {
    ctx.JSON(
        http.StatusBadRequest,
        api.CommonResponse{
            Status:       "failed",
            ErrorMessage: "failed to decode attestationObject, error: " + err.Error(),
        },
    )
    return
}

並修改 protocol.CredentialCreationResponse 中的 AttestationObject

ccr := protocol.CredentialCreationResponse{
    PublicKeyCredential: protocol.PublicKeyCredential{
        Credential: protocol.Credential{
            ID:   request.Id,
            Type: request.Type,
        },
        RawID:                  []byte(request.Id),
        ClientExtensionResults: request.GetClientExtensionResults,
    },
    AttestationResponse: protocol.AuthenticatorAttestationResponse{
        // 改成用上面 base64RawURL 解碼後的 authenticatorAttestationObject
        AttestationObject: protocol.URLEncodedBase64(authenticatorAttestationObject),
        AuthenticatorResponse: protocol.AuthenticatorResponse{
            ClientDataJSON: authenticatorClientDataJSON,
        },
    },
}

修改後,會像是下面這樣

https://ithelp.ithome.com.tw/upload/images/20240922/20140363x79LSfzvkp.png

https://ithelp.ithome.com.tw/upload/images/20240922/20140363M6SKEkPdaC.png

再重新執行一次,就成功通過第四關了~

明天我們再繼續勇闖第五關!


上一篇
【Go!帶你探索 FIDO2 資安技術全端應用】Day 23 - 開始進行前後端串接 (3)
下一篇
【Go!帶你探索 FIDO2 資安技術全端應用】Day 25 - 開始進行前後端串接 (5)
系列文
Go!帶你探索 FIDO2 資安技術全端應用26
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言