From 1663113cf5ae5c6552087b83ab05e735d44986d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Plo=C3=9F?= Date: Sat, 8 Jan 2022 01:01:57 +0100 Subject: [PATCH 1/3] handle all errors in getProfile --- groupsv2/groupsv2.go | 2 +- profiles/profile.go | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/groupsv2/groupsv2.go b/groupsv2/groupsv2.go index 05500c2..6ab91ae 100644 --- a/groupsv2/groupsv2.go +++ b/groupsv2/groupsv2.go @@ -246,7 +246,7 @@ func HandleGroupsV2(src string, dm *signalservice.DataMessage) (*GroupV2, error) log.Errorln("[textsecure][groupsv2] signature verification failed", err) return nil, err } - log.Debugln("[textsecure][groupsv2] signature verification succesful") + log.Debugln("[textsecure][groupsv2] signature verification successful") } } diff --git a/profiles/profile.go b/profiles/profile.go index a54536a..8cc0865 100644 --- a/profiles/profile.go +++ b/profiles/profile.go @@ -141,21 +141,18 @@ type Profile struct { func GetProfile(UUID string, profileKey []byte) (*Profile, error) { resp, err := transport.Transport.Get(fmt.Sprintf(PROFILE_PATH, UUID)) profile := &Profile{} - - dec := json.NewDecoder(resp.Body) - err = dec.Decode(&profile) - if err != nil { - log.Debugln("[textsecure] GetProfile", err) - return nil, err - } else { + if err == nil { + dec := json.NewDecoder(resp.Body) + err = dec.Decode(&profile) + } + if err == nil { err = decryptProfile(profileKey, profile) - if err != nil { - log.Debugln("[textsecure] ", err) - return nil, err - } } - return profile, nil - + if err == nil { + return profile, nil + } + log.Debugln("[textsecure] GetProfile", err) + return nil, err } func GetProfileAndCredential(UUID string, profileKey []byte) (*Profile, error) { log.Infoln("[textsecure] GetProfileAndCredential") From 638647257d6d399c5efc3b27aa37295370bac4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Plo=C3=9F?= Date: Sat, 8 Jan 2022 14:16:14 +0100 Subject: [PATCH 2/3] immediately return error in getProfile --- profiles/profile.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/profiles/profile.go b/profiles/profile.go index 8cc0865..d326e91 100644 --- a/profiles/profile.go +++ b/profiles/profile.go @@ -140,19 +140,26 @@ type Profile struct { func GetProfile(UUID string, profileKey []byte) (*Profile, error) { resp, err := transport.Transport.Get(fmt.Sprintf(PROFILE_PATH, UUID)) - profile := &Profile{} - if err == nil { - dec := json.NewDecoder(resp.Body) - err = dec.Decode(&profile) + if err != nil { + log.Debugln("[textsecure] GetProfile", err) + return nil, err } - if err == nil { - err = decryptProfile(profileKey, profile) + + dec := json.NewDecoder(resp.Body) + profile := &Profile{} + err = dec.Decode(&profile) + if err != nil { + log.Debugln("[textsecure] GetProfile", err) + return nil, err } - if err == nil { - return profile, nil + + err = decryptProfile(profileKey, profile) + if err != nil { + log.Debugln("[textsecure] GetProfile", err) + return nil, err } - log.Debugln("[textsecure] GetProfile", err) - return nil, err + + return profile, nil } func GetProfileAndCredential(UUID string, profileKey []byte) (*Profile, error) { log.Infoln("[textsecure] GetProfileAndCredential") From 5cada8c8ec64401deb37fbf003cf985742268996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Plo=C3=9F?= Date: Sat, 8 Jan 2022 14:37:26 +0100 Subject: [PATCH 3/3] handle if response is error --- profiles/profile.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/profiles/profile.go b/profiles/profile.go index d326e91..f626afc 100644 --- a/profiles/profile.go +++ b/profiles/profile.go @@ -144,7 +144,11 @@ func GetProfile(UUID string, profileKey []byte) (*Profile, error) { log.Debugln("[textsecure] GetProfile", err) return nil, err } - + if resp.IsError() { + log.Debugln("[textsecure] GetProfile", resp) + return nil, resp + } + dec := json.NewDecoder(resp.Body) profile := &Profile{} err = dec.Decode(&profile)