gofiber / fiber

⚡️ Express inspired web framework written in Go
https://gofiber.io
MIT License
33.38k stars 1.64k forks source link

🤗 [Question]: JA3 #2545

Closed Bagerter closed 1 year ago

Bagerter commented 1 year ago

Question Description

Hello, help pls, how to get ja3 client hash?

Code Snippet (optional)

No response

Checklist:

welcome[bot] commented 1 year ago

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

Bagerter commented 1 year ago

Fixed

func Middleware() fiber.Handler {
    return func(c *fiber.Ctx) error {
        ja3Hash, err := generateJA3Hash(c)
        if err != nil {
            fmt.Println("error get ja3")
        }

        fmt.Println(ja3Hash)
        return c.Next()
    }
}

func generateJA3Hash(c *fiber.Ctx) (string, error) {
    tlsInfo := c.ClientHelloInfo()
    if tlsInfo == nil {
        return "", fmt.Errorf("eror")
    }

    var fingerprint string

    for _, suite := range tlsInfo.CipherSuites[1:] {
        fingerprint += fmt.Sprintf("0x%x,", suite)
    }

    for _, curve := range tlsInfo.SupportedCurves[1:] {
        fingerprint += fmt.Sprintf("0x%x,", curve)
    }

    for _, point := range tlsInfo.SupportedPoints[1:] {
        fingerprint += fmt.Sprintf("0x%x,", point)
    }

    return fingerprint, nil
}