Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

WIP: Refactor GetProfile() #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions profiles/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,44 +157,46 @@ type Profile struct {
Credential []byte `json:"credential"`
}

func GetProfile(UUID string, profileKey []byte) (*Profile, error) {
unidentifiedAccess, err := unidentifiedAccess.GetAccessForSync(config.ConfigFile.ProfileKey, config.ConfigFile.Certificate)
func getProfile(UUID string, unidentifiedAccessKey []byte) (*Profile, error) {
resp, err := transport.Transport.GetWithUnidentifiedAccessKey(fmt.Sprintf(PROFILE_PATH, UUID), unidentifiedAccessKey)
if err != nil {
return nil, err
}
resp, err := transport.Transport.GetWithUnidentifiedAccessKey(fmt.Sprintf(PROFILE_PATH, UUID), unidentifiedAccess.UnidentifiedAccessKey)
if resp.IsError() {
return nil, resp
}

bytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
profile := &Profile{}
bytes, err := io.ReadAll(resp.Body)
err = json.Unmarshal(bytes, profile)
if err != nil {
return nil, err
}
err = json.Unmarshal(bytes, profile)
return profile, nil
}

func GetProfile(UUID string, profileKey []byte) (*Profile, error) {
unidentifiedAccess, err := unidentifiedAccess.GetAccessForSync(config.ConfigFile.ProfileKey, config.ConfigFile.Certificate)
if err != nil {
return nil, err
}
profile, err := getProfile(UUID, unidentifiedAccess.UnidentifiedAccessKey)
if err != nil {
log.Debugln("[textsecure] GetProfile decode error", err)
return nil, err
} else {
err = decryptProfile(profileKey, profile)
if err != nil {
log.Errorln("[textsecure] decrypt profile error", err)
// return nil, err
}
resp, err = transport.Transport.GetWithUnidentifiedAccessKey(fmt.Sprintf(PROFILE_PATH, UUID), []byte(profile.UnidentifiedAccess))
if err != nil {
return profile, err
}
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(bytes, profile)
if err != nil {
log.Debugln("[textsecure] GetProfile decode error", err)
return nil, err
}
}

err = decryptProfile(profileKey, profile)
if err != nil {
log.Errorln("[textsecure] decrypt profile error", err)
// return nil, err
}
profile, err = getProfile(UUID, []byte(profile.UnidentifiedAccess))
if err != nil {
return nil, err
}
return profile, nil

Expand Down