Skip to content

Commit

Permalink
support user search and icq2000->icq2001 user auth
Browse files Browse the repository at this point in the history
- Implement SNACs required for search to work in ICQ 20001.
- Authorization from ICQ 2000 to ICQ 2001 works, but not vice-versa.
- Add new methods for retrieving values from TLVs for ICQ. Rename
  existing methods with "-BE" big endian suffix.
  • Loading branch information
mk6i committed Sep 1, 2024
1 parent ebe48cf commit 5cc3a60
Show file tree
Hide file tree
Showing 56 changed files with 2,498 additions and 716 deletions.
38 changes: 19 additions & 19 deletions foodgroup/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,29 @@ func (s AdminService) InfoQuery(_ context.Context, sess *state.Session, frame wi

tlvList := wire.TLVList{}

if _, hasRegStatus := body.TLVRestBlock.Slice(wire.AdminTLVRegistrationStatus); hasRegStatus {
if _, hasRegStatus := body.TLVRestBlock.Bytes(wire.AdminTLVRegistrationStatus); hasRegStatus {
regStatus, err := s.accountManager.RegStatusByName(sess.IdentScreenName())
if err != nil {
return wire.SNACMessage{}, err
}
tlvList.Append(wire.NewTLV(wire.AdminTLVRegistrationStatus, regStatus))
tlvList.Append(wire.NewTLVBE(wire.AdminTLVRegistrationStatus, regStatus))
return getAdminInfoReply(tlvList), nil
}

if _, hasEmail := body.TLVRestBlock.Slice(wire.AdminTLVEmailAddress); hasEmail {
if _, hasEmail := body.TLVRestBlock.Bytes(wire.AdminTLVEmailAddress); hasEmail {
e, err := s.accountManager.EmailAddressByName(sess.IdentScreenName())
if errors.Is(err, state.ErrNoEmailAddress) {
tlvList.Append(wire.NewTLV(wire.AdminTLVEmailAddress, ""))
tlvList.Append(wire.NewTLVBE(wire.AdminTLVEmailAddress, ""))
} else if err != nil {
return wire.SNACMessage{}, err
} else {
tlvList.Append(wire.NewTLV(wire.AdminTLVEmailAddress, e.Address))
tlvList.Append(wire.NewTLVBE(wire.AdminTLVEmailAddress, e.Address))
}
return getAdminInfoReply(tlvList), nil
}

if _, hasNickName := body.TLVRestBlock.Slice(wire.AdminTLVScreenNameFormatted); hasNickName {
tlvList.Append(wire.NewTLV(wire.AdminTLVScreenNameFormatted, sess.DisplayScreenName().String()))
if _, hasNickName := body.TLVRestBlock.Bytes(wire.AdminTLVScreenNameFormatted); hasNickName {
tlvList.Append(wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, sess.DisplayScreenName().String()))
return getAdminInfoReply(tlvList), nil
}

Expand Down Expand Up @@ -196,11 +196,11 @@ func (s AdminService) InfoChangeRequest(ctx context.Context, sess *state.Session

tlvList := wire.TLVList{}

if sn, hasScreenNameFormatted := body.TLVRestBlock.Slice(wire.AdminTLVScreenNameFormatted); hasScreenNameFormatted {
if sn, hasScreenNameFormatted := body.TLVRestBlock.Bytes(wire.AdminTLVScreenNameFormatted); hasScreenNameFormatted {
proposedName := state.DisplayScreenName(sn)
if ok, errorCode := validateProposedName(proposedName); !ok {
tlvList.Append(wire.NewTLV(wire.AdminTLVErrorCode, errorCode))
tlvList.Append(wire.NewTLV(wire.AdminTLVUrl, ""))
tlvList.Append(wire.NewTLVBE(wire.AdminTLVErrorCode, errorCode))
tlvList.Append(wire.NewTLVBE(wire.AdminTLVUrl, ""))
return getAdminChangeReply(tlvList), nil
}
if err := s.accountManager.UpdateDisplayScreenName(proposedName); err != nil {
Expand All @@ -219,26 +219,26 @@ func (s AdminService) InfoChangeRequest(ctx context.Context, sess *state.Session
TLVUserInfo: sess.TLVUserInfo(),
},
})
tlvList.Append(wire.NewTLV(wire.AdminTLVScreenNameFormatted, proposedName.String()))
tlvList.Append(wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, proposedName.String()))
return getAdminChangeReply(tlvList), nil
}

if emailAddress, hasEmailAddress := body.TLVRestBlock.Slice(wire.AdminTLVEmailAddress); hasEmailAddress {
if emailAddress, hasEmailAddress := body.TLVRestBlock.Bytes(wire.AdminTLVEmailAddress); hasEmailAddress {
e, errorCode := validateProposedEmailAddress(emailAddress)
if errorCode != 0 {
tlvList.Append(wire.NewTLV(wire.AdminTLVErrorCode, errorCode))
tlvList.Append(wire.NewTLV(wire.AdminTLVUrl, ""))
tlvList.Append(wire.NewTLVBE(wire.AdminTLVErrorCode, errorCode))
tlvList.Append(wire.NewTLVBE(wire.AdminTLVUrl, ""))
return getAdminChangeReply(tlvList), nil

}
if err := s.accountManager.UpdateEmailAddress(e, sess.IdentScreenName()); err != nil {
return wire.SNACMessage{}, err
}
tlvList.Append(wire.NewTLV(wire.AdminTLVEmailAddress, e.Address))
tlvList.Append(wire.NewTLVBE(wire.AdminTLVEmailAddress, e.Address))
return getAdminChangeReply(tlvList), nil
}

if regStatus, hasRegStatus := body.TLVRestBlock.Uint16(wire.AdminTLVRegistrationStatus); hasRegStatus {
if regStatus, hasRegStatus := body.TLVRestBlock.Uint16BE(wire.AdminTLVRegistrationStatus); hasRegStatus {
switch regStatus {
case
wire.AdminInfoRegStatusFullDisclosure,
Expand All @@ -247,11 +247,11 @@ func (s AdminService) InfoChangeRequest(ctx context.Context, sess *state.Session
if err := s.accountManager.UpdateRegStatus(regStatus, sess.IdentScreenName()); err != nil {
return wire.SNACMessage{}, err
}
tlvList.Append(wire.NewTLV(wire.AdminTLVRegistrationStatus, regStatus))
tlvList.Append(wire.NewTLVBE(wire.AdminTLVRegistrationStatus, regStatus))
return getAdminChangeReply(tlvList), nil
}
tlvList.Append(wire.NewTLV(wire.AdminTLVErrorCode, wire.AdminInfoErrorInvalidRegistrationPreference))
tlvList.Append(wire.NewTLV(wire.AdminTLVUrl, ""))
tlvList.Append(wire.NewTLVBE(wire.AdminTLVErrorCode, wire.AdminInfoErrorInvalidRegistrationPreference))
tlvList.Append(wire.NewTLVBE(wire.AdminTLVUrl, ""))
return getAdminChangeReply(tlvList), nil
}

Expand Down
71 changes: 36 additions & 35 deletions foodgroup/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"net/mail"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

"github.com/mk6i/retro-aim-server/config"
"github.com/mk6i/retro-aim-server/state"
"github.com/mk6i/retro-aim-server/wire"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestAdminService_ConfirmRequest(t *testing.T) {
Expand Down Expand Up @@ -236,7 +237,7 @@ func TestAdminService_InfoQuery(t *testing.T) {
Body: wire.SNAC_0x07_0x02_AdminInfoQuery{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVRegistrationStatus, uint16(0x00))},
wire.NewTLVBE(wire.AdminTLVRegistrationStatus, uint16(0x00))},
},
},
},
Expand All @@ -250,7 +251,7 @@ func TestAdminService_InfoQuery(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVRegistrationStatus, wire.AdminInfoRegStatusLimitDisclosure),
wire.NewTLVBE(wire.AdminTLVRegistrationStatus, wire.AdminInfoRegStatusLimitDisclosure),
},
},
},
Expand Down Expand Up @@ -279,7 +280,7 @@ func TestAdminService_InfoQuery(t *testing.T) {
Body: wire.SNAC_0x07_0x02_AdminInfoQuery{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVEmailAddress, uint16(0x00))},
wire.NewTLVBE(wire.AdminTLVEmailAddress, uint16(0x00))},
},
},
},
Expand All @@ -293,7 +294,7 @@ func TestAdminService_InfoQuery(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVEmailAddress, "[email protected]"),
wire.NewTLVBE(wire.AdminTLVEmailAddress, "[email protected]"),
},
},
},
Expand Down Expand Up @@ -324,7 +325,7 @@ func TestAdminService_InfoQuery(t *testing.T) {
Body: wire.SNAC_0x07_0x02_AdminInfoQuery{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVEmailAddress, uint16(0x00))},
wire.NewTLVBE(wire.AdminTLVEmailAddress, uint16(0x00))},
},
},
},
Expand All @@ -338,7 +339,7 @@ func TestAdminService_InfoQuery(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVEmailAddress, ""),
wire.NewTLVBE(wire.AdminTLVEmailAddress, ""),
},
},
},
Expand Down Expand Up @@ -367,7 +368,7 @@ func TestAdminService_InfoQuery(t *testing.T) {
Body: wire.SNAC_0x07_0x02_AdminInfoQuery{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVScreenNameFormatted, uint16(0x00))},
wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, uint16(0x00))},
},
},
},
Expand All @@ -381,7 +382,7 @@ func TestAdminService_InfoQuery(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVScreenNameFormatted, "ChattingChuck"),
wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, "ChattingChuck"),
},
},
},
Expand All @@ -399,7 +400,7 @@ func TestAdminService_InfoQuery(t *testing.T) {
Body: wire.SNAC_0x07_0x02_AdminInfoQuery{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(uint16(0x99), uint16(0x00))},
wire.NewTLVBE(uint16(0x99), uint16(0x00))},
},
},
},
Expand Down Expand Up @@ -511,7 +512,7 @@ func TestAdminService_InfoChangeRequest_ScreenName(t *testing.T) {
Body: wire.SNAC_0x07_0x04_AdminInfoChangeRequest{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVScreenNameFormatted, "Chatting Chuck"),
wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, "Chatting Chuck"),
},
},
},
Expand All @@ -526,7 +527,7 @@ func TestAdminService_InfoChangeRequest_ScreenName(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVScreenNameFormatted, "Chatting Chuck"),
wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, "Chatting Chuck"),
},
},
},
Expand All @@ -544,7 +545,7 @@ func TestAdminService_InfoChangeRequest_ScreenName(t *testing.T) {
Body: wire.SNAC_0x07_0x04_AdminInfoChangeRequest{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVScreenNameFormatted, "c h a t t i n g c h u c k")},
wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, "c h a t t i n g c h u c k")},
},
},
},
Expand All @@ -558,8 +559,8 @@ func TestAdminService_InfoChangeRequest_ScreenName(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVErrorCode, wire.AdminInfoErrorInvalidNickNameLength),
wire.NewTLV(wire.AdminTLVUrl, ""),
wire.NewTLVBE(wire.AdminTLVErrorCode, wire.AdminInfoErrorInvalidNickNameLength),
wire.NewTLVBE(wire.AdminTLVUrl, ""),
},
},
},
Expand All @@ -577,7 +578,7 @@ func TestAdminService_InfoChangeRequest_ScreenName(t *testing.T) {
Body: wire.SNAC_0x07_0x04_AdminInfoChangeRequest{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVScreenNameFormatted, "QuietQuinton")},
wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, "QuietQuinton")},
},
},
},
Expand All @@ -591,8 +592,8 @@ func TestAdminService_InfoChangeRequest_ScreenName(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVErrorCode, wire.AdminInfoErrorValidateNickName),
wire.NewTLV(wire.AdminTLVUrl, ""),
wire.NewTLVBE(wire.AdminTLVErrorCode, wire.AdminInfoErrorValidateNickName),
wire.NewTLVBE(wire.AdminTLVUrl, ""),
},
},
},
Expand All @@ -610,7 +611,7 @@ func TestAdminService_InfoChangeRequest_ScreenName(t *testing.T) {
Body: wire.SNAC_0x07_0x04_AdminInfoChangeRequest{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVScreenNameFormatted, "ChattingChuck ")},
wire.NewTLVBE(wire.AdminTLVScreenNameFormatted, "ChattingChuck ")},
},
},
},
Expand All @@ -624,8 +625,8 @@ func TestAdminService_InfoChangeRequest_ScreenName(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVErrorCode, wire.AdminInfoErrorInvalidNickName),
wire.NewTLV(wire.AdminTLVUrl, ""),
wire.NewTLVBE(wire.AdminTLVErrorCode, wire.AdminInfoErrorInvalidNickName),
wire.NewTLVBE(wire.AdminTLVUrl, ""),
},
},
},
Expand Down Expand Up @@ -725,7 +726,7 @@ func TestAdminService_InfoChangeRequest_EmailAddress(t *testing.T) {
Body: wire.SNAC_0x07_0x04_AdminInfoChangeRequest{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVEmailAddress, "[email protected]"),
wire.NewTLVBE(wire.AdminTLVEmailAddress, "[email protected]"),
},
},
},
Expand All @@ -740,7 +741,7 @@ func TestAdminService_InfoChangeRequest_EmailAddress(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVEmailAddress, "[email protected]"),
wire.NewTLVBE(wire.AdminTLVEmailAddress, "[email protected]"),
},
},
},
Expand All @@ -758,7 +759,7 @@ func TestAdminService_InfoChangeRequest_EmailAddress(t *testing.T) {
Body: wire.SNAC_0x07_0x04_AdminInfoChangeRequest{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVEmailAddress, "chattingchuck@@@@@@@aol.com"),
wire.NewTLVBE(wire.AdminTLVEmailAddress, "chattingchuck@@@@@@@aol.com"),
},
},
},
Expand All @@ -773,8 +774,8 @@ func TestAdminService_InfoChangeRequest_EmailAddress(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVErrorCode, wire.AdminInfoErrorInvalidEmail),
wire.NewTLV(wire.AdminTLVUrl, ""),
wire.NewTLVBE(wire.AdminTLVErrorCode, wire.AdminInfoErrorInvalidEmail),
wire.NewTLVBE(wire.AdminTLVUrl, ""),
},
},
},
Expand All @@ -792,7 +793,7 @@ func TestAdminService_InfoChangeRequest_EmailAddress(t *testing.T) {
Body: wire.SNAC_0x07_0x04_AdminInfoChangeRequest{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVEmailAddress, longEmailAddress),
wire.NewTLVBE(wire.AdminTLVEmailAddress, longEmailAddress),
},
},
},
Expand All @@ -807,8 +808,8 @@ func TestAdminService_InfoChangeRequest_EmailAddress(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVErrorCode, wire.AdminInfoErrorInvalidEmailLength),
wire.NewTLV(wire.AdminTLVUrl, ""),
wire.NewTLVBE(wire.AdminTLVErrorCode, wire.AdminInfoErrorInvalidEmailLength),
wire.NewTLVBE(wire.AdminTLVUrl, ""),
},
},
},
Expand Down Expand Up @@ -885,7 +886,7 @@ func TestAdminService_InfoChangeRequest_RegStatus(t *testing.T) {
Body: wire.SNAC_0x07_0x04_AdminInfoChangeRequest{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVRegistrationStatus, wire.AdminInfoRegStatusNoDisclosure),
wire.NewTLVBE(wire.AdminTLVRegistrationStatus, wire.AdminInfoRegStatusNoDisclosure),
},
},
},
Expand All @@ -900,7 +901,7 @@ func TestAdminService_InfoChangeRequest_RegStatus(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVRegistrationStatus, wire.AdminInfoRegStatusNoDisclosure),
wire.NewTLVBE(wire.AdminTLVRegistrationStatus, wire.AdminInfoRegStatusNoDisclosure),
},
},
},
Expand All @@ -918,7 +919,7 @@ func TestAdminService_InfoChangeRequest_RegStatus(t *testing.T) {
Body: wire.SNAC_0x07_0x04_AdminInfoChangeRequest{
TLVRestBlock: wire.TLVRestBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVRegistrationStatus, uint16(0x1337)),
wire.NewTLVBE(wire.AdminTLVRegistrationStatus, uint16(0x1337)),
},
},
},
Expand All @@ -933,8 +934,8 @@ func TestAdminService_InfoChangeRequest_RegStatus(t *testing.T) {
Permissions: wire.AdminInfoPermissionsReadWrite,
TLVBlock: wire.TLVBlock{
TLVList: wire.TLVList{
wire.NewTLV(wire.AdminTLVErrorCode, wire.AdminInfoErrorInvalidRegistrationPreference),
wire.NewTLV(wire.AdminTLVUrl, ""),
wire.NewTLVBE(wire.AdminTLVErrorCode, wire.AdminInfoErrorInvalidRegistrationPreference),
wire.NewTLVBE(wire.AdminTLVUrl, ""),
},
},
},
Expand Down
Loading

0 comments on commit 5cc3a60

Please sign in to comment.