2021-11-16 16:44:29 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-12-15 19:55:43 -05:00
|
|
|
"errors"
|
2021-11-16 16:44:29 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type AuthorizationRegistrationService struct{}
|
|
|
|
|
2021-12-15 19:55:43 -05:00
|
|
|
func (a *AuthorizationRegistrationService) HandleSNAC(session *Session, snac *SNAC) error {
|
|
|
|
switch snac.Header.Subtype {
|
2021-11-16 16:44:29 -05:00
|
|
|
// Request MD5 Auth Key
|
2021-12-15 19:55:43 -05:00
|
|
|
case 0x06:
|
|
|
|
tlvs, err := UnmarshalTLVs(snac.Data)
|
|
|
|
panicIfError(err)
|
|
|
|
|
|
|
|
usernameTLV := FindTLV(tlvs, 1)
|
|
|
|
if usernameTLV == nil {
|
|
|
|
return errors.New("missing username TLV")
|
|
|
|
}
|
2021-11-16 16:44:29 -05:00
|
|
|
|
2021-12-15 19:55:43 -05:00
|
|
|
// Create cipher for this user
|
|
|
|
cipher := "howdy"
|
|
|
|
db.Set("cipher-"+string(usernameTLV.Data), cipher)
|
|
|
|
cipherData := []byte(cipher)
|
2021-11-16 16:44:29 -05:00
|
|
|
|
2021-12-15 19:55:43 -05:00
|
|
|
snac := NewSNAC(0x17, 0x07, cipherData)
|
|
|
|
snacBytes, err := snac.MarshalBinary()
|
|
|
|
panicIfError(err)
|
|
|
|
|
|
|
|
resp := NewFLAP(session, 2, snacBytes)
|
|
|
|
return session.Send(resp)
|
2021-11-16 16:44:29 -05:00
|
|
|
}
|
2021-12-15 19:55:43 -05:00
|
|
|
|
|
|
|
return nil
|
2021-11-16 16:44:29 -05:00
|
|
|
}
|