diff options
| author | Kyren223 <Kyren223@proton.me> | 2025-07-08 19:10:26 +0300 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2025-07-08 19:10:26 +0300 |
| commit | 046b17959f2296a32a62d3b4f6174d47cdfbd4e9 (patch) | |
| tree | a4c614728ae19a42fc484ca904ada4311b81a647 /internal/client/gateway | |
| parent | 56acb0d51e93ddd528422253137a3692d9bdc8de (diff) | |
Finished implementing authentication on the client-side
Diffstat (limited to 'internal/client/gateway')
| -rw-r--r-- | internal/client/gateway/gateway.go | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/internal/client/gateway/gateway.go b/internal/client/gateway/gateway.go index f98a3fb..20ca777 100644 --- a/internal/client/gateway/gateway.go +++ b/internal/client/gateway/gateway.go @@ -2,10 +2,8 @@ package gateway import ( "context" - "crypto/ed25519" "crypto/tls" "crypto/x509" - "encoding/binary" "errors" "log" "net" @@ -103,56 +101,6 @@ func connect(ctx context.Context) error { return nil } -func handleAuth(ctx context.Context, conn net.Conn, privKey ed25519.PrivateKey) (snowflake.ID, error) { - const nonceSize = 32 - const packetSize = 1 + nonceSize // For version byte - challengeRequest := make([]byte, packetSize) - - deadline, _ := ctx.Deadline() - err := conn.SetDeadline(deadline) - assert.NoError(err, "setting deadline should not error") - defer func() { - err := conn.SetDeadline(time.Time{}) - assert.NoError(err, "unsetting deadline should not error") - }() - - bytesRead := 0 - for bytesRead < packetSize { - n, err := conn.Read(challengeRequest[bytesRead:]) - if err != nil { - return 0, err - } - bytesRead += n - } - - assert.Assert(challengeRequest[0] == packet.VERSION, "client should always have the same version as the server") - - challengeResponse := make([]byte, 1+ed25519.PublicKeySize+ed25519.SignatureSize) - challengeResponse[0] = packet.VERSION - copy(challengeResponse[1:1+ed25519.PublicKeySize], privKey.Public().(ed25519.PublicKey)) - signedNonce := ed25519.Sign(privKey, challengeRequest[1:]) - n := copy(challengeResponse[1+ed25519.PublicKeySize:], signedNonce) - assert.Assert(n == ed25519.SignatureSize, "copy should've copied the entire signature exactly") - - _, err = conn.Write(challengeResponse) - if err != nil { - return 0, err - } - - var idBytes [8]byte - bytesRead = 0 - for bytesRead < 8 { - n, err := conn.Read(idBytes[:]) - if err != nil { - return 0, err - } - bytesRead += n - } - id := snowflake.ID(binary.BigEndian.Uint64(idBytes[:])) // #nosec G115 - - return id, nil -} - func readForever(conn net.Conn) { buffer := make([]byte, 512) for { |
