successful auth

This commit is contained in:
Artem Titoulenko 2021-12-16 18:02:48 -05:00
parent 9bebf7c6c3
commit 268cff0963
4 changed files with 44 additions and 6 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
node_modules node_modules
built built
dist dist
aim-oscar

View file

@ -1,9 +1,12 @@
package main package main
import ( import (
"bytes"
"context" "context"
"crypto/md5"
"crypto/rand" "crypto/rand"
"encoding/base32" "encoding/base32"
"io"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/uptrace/bun" "github.com/uptrace/bun"
@ -12,6 +15,7 @@ import (
) )
const CIPHER_LENGTH = 64 const CIPHER_LENGTH = 64
const AIM_MD5_STRING = "AOL Instant Messenger (SM)"
type AuthorizationRegistrationService struct{} type AuthorizationRegistrationService struct{}
@ -72,7 +76,7 @@ func (a *AuthorizationRegistrationService) HandleSNAC(db *bun.DB, session *Sessi
usernameTLV := FindTLV(tlvs, 1) usernameTLV := FindTLV(tlvs, 1)
if usernameTLV == nil { if usernameTLV == nil {
return errors.New("missing username TLV") return errors.New("missing username TLV 0x1")
} }
username := string(usernameTLV.Data) username := string(usernameTLV.Data)
@ -91,10 +95,43 @@ func (a *AuthorizationRegistrationService) HandleSNAC(db *bun.DB, session *Sessi
return session.Send(resp) return session.Send(resp)
} }
snac := NewSNAC(0x17, 0x03) passwordHashTLV := FindTLV(tlvs, 0x25)
resp := NewFLAP(session, 2) if passwordHashTLV == nil {
resp.Data.WriteBinary(snac) return errors.New("missing password hash TLV 0x25")
return session.Send(resp) }
h := md5.New()
io.WriteString(h, user.Cipher)
io.WriteString(h, user.Password)
io.WriteString(h, AIM_MD5_STRING)
expectedPasswordHash := h.Sum(nil)
if !bytes.Equal(expectedPasswordHash, passwordHashTLV.Data) {
// Tell the client this was a bad password
badPasswordSnac := NewSNAC(0x17, 0x03)
badPasswordSnac.Data.WriteBinary(usernameTLV)
badPasswordSnac.Data.WriteBinary(NewTLV(0x08, []byte{0, 4}))
badPasswordFlap := NewFLAP(session, 2)
badPasswordFlap.Data.WriteBinary(badPasswordSnac)
session.Send(badPasswordFlap)
// Tell tem to leave
discoFlap := NewFLAP(session, 4)
return session.Send(discoFlap)
}
// Send BOS response + cookie
authSnac := NewSNAC(0x17, 0x3)
authSnac.Data.WriteBinary(usernameTLV)
authSnac.Data.WriteBinary(NewTLV(0x5, []byte("10.0.1.2:5191")))
authSnac.Data.WriteBinary(NewTLV(0x6, []byte(`{"hello": "uwu"}`)))
authFlap := NewFLAP(session, 2)
authFlap.Data.WriteBinary(authSnac)
session.Send(authFlap)
// Tell tem to leave
discoFlap := NewFLAP(session, 4)
return session.Send(discoFlap)
} }
return nil return nil

BIN
aim-oscar

Binary file not shown.

View file

@ -38,7 +38,7 @@ func prettyBytes(bytes []byte) string {
if err != nil || (n < 32 || n > 126) { if err != nil || (n < 32 || n > 126) {
res += "." res += "."
} else { } else {
res += fmt.Sprint(n) res += string(n)
} }
} }
res += "|\n" res += "|\n"