pquerna / otp

TOTP library for Go
Apache License 2.0
2.32k stars 224 forks source link

Must use AlgorithmSHA1 with iOS version of Google Authenticator #55

Closed yghazi closed 3 years ago

yghazi commented 4 years ago
        key,_ := totp.Generate(totp.GenerateOpts{ 
              AccountName: "XYZ Test", 
              Issuer: "some.domain.com", 
              Algorithm: otp.AlgorithmSHA512, 
        })

        var buff bytes.Buffer
    img, _ := key.Image(256,256)
    f, _ := os.Create("test.html")
    png.Encode(&buff, img)
    encodedString := base64.StdEncoding.EncodeToString(buff.Bytes())
    htmlImage := "<img src=\"data:image/png;base64," + encodedString + "\" />"
    l, err := f.WriteString(htmlImage)
    if err != nil {
        log.Println(err)
    }

The resultant test.html shows a QR code that provides correct codes when scanned with Google Authenticator on Android, but not on iPhone.

pquerna commented 4 years ago

Try using Algorithm: otp.AlgorithmSHA1 - I think the iOS version supports less algorithms for the TOTP.

ledongthuc commented 4 years ago

hi @yghazi @pquerna I got same issue today when using Algo SHA512 on Iphone google authenticator. Switch to SHA1, it works.

(SHA512 still works with Iphone Authen and Android Google Authenticator)

So I think best way to support Iphone GG authenticator is switch it to SHA1