WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 6fb5a7a

Browse files
committed
Fix the response unwrapping
1 parent 3ff1064 commit 6fb5a7a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

client.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,26 @@ func (c *Client) Reauthenticate(ctx context.Context, creds keys.Credentials) (*m
420420
return nil, err
421421
}
422422

423+
resultWrapper := message.SignedResponseWrapper{}
424+
err = json.Unmarshal(resp, &resultWrapper)
425+
if err != nil {
426+
return nil, fmt.Errorf("failed to unmarshal signed response wrapper: %s", err)
427+
}
428+
429+
// Verify the signature
430+
valid := false
431+
for _, caPubkey := range creds.TrustedKeys {
432+
if caPubkey.Verify(resultWrapper.Data.Message, resultWrapper.Data.Signature) {
433+
valid = true
434+
break
435+
}
436+
}
437+
if !valid {
438+
return nil, fmt.Errorf("failed to verify signed API result")
439+
}
440+
423441
var response message.ReauthenticateResponse
424-
if err := json.Unmarshal(resp, &response); err != nil {
442+
if err := json.Unmarshal(resultWrapper.Data.Message, &response); err != nil {
425443
return nil, fmt.Errorf("failed to unmarshal DNClient response: %s", err)
426444
}
427445

client_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ func TestReauthenticate(t *testing.T) {
994994
// make sure we got a login URL back
995995
assert.NotEmpty(t, resp)
996996
assert.NotEmpty(t, resp.LoginURL)
997+
assert.Equal(t, "https://auth.example.com/login?authcode=123", resp.LoginURL)
997998

998999
}
9991000

0 commit comments

Comments
 (0)