Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdk 2235 share v 2 retrieve receipt #289

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
be2b96b
SDK-2235 added retrieve receipt
mehmet-yoti Oct 23, 2023
6f50c88
SDK-2235 Added Retrieve Receipt
mehmet-yoti Oct 25, 2023
fb79e33
SDK-2235 Added Retrieve Receipt
mehmet-yoti Oct 25, 2023
1586dea
SDK-2235 Added Retrieve Receipt
mehmet-yoti Oct 25, 2023
c2d3b6c
SDK-2235 Added Retrieve Receipt
mehmet-yoti Oct 25, 2023
ae46a53
SDK-2254 Resolved pr comments
mehmet-yoti Nov 1, 2023
22bbe7d
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
9a619e8
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
bc20038
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
00ef7b0
SDK-2254 Resolved pr comments
mehmet-yoti Nov 1, 2023
4cf2791
SDK-2254:updated pr changes
mehmet-yoti Nov 2, 2023
ad1f3f9
SDK-2254 removed unused builder
mehmet-yoti Nov 5, 2023
87d61de
SDK-2259:added retrieve qr code structs
mehmet-yoti Oct 22, 2023
6c2d312
SDK-2254 Removed unused examples and updated function namings
mehmet-yoti Nov 1, 2023
d40c218
SDK-2259:removed unused example files
mehmet-yoti Nov 1, 2023
f8657c2
SDK-2254 Removed unused examples and updated function namings
mehmet-yoti Nov 1, 2023
4c019b3
SDK-2259:removed unused example files
mehmet-yoti Nov 1, 2023
a841a3e
SDK-2235:error handling, updated comments
mehmet-yoti Nov 7, 2023
87f5098
SDK-2235:updated method descriptions and addedd error handlers with d…
mehmet-yoti Nov 8, 2023
2492915
SDK-2235:added some error handling, updated comments, added error han…
mehmet-yoti Nov 10, 2023
5bf052f
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
9661755
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
75502ef
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
b7d7b23
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
8e20b5e
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
b893957
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
4993e35
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
e52a26c
Update cryptoutil/crypto_utils.go
mehmet-yoti Nov 23, 2023
b9d8fed
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
c09c2c2
Update cryptoutil/crypto_utils.go
mehmet-yoti Nov 23, 2023
8dd3c7c
SDK-2235: added error details, cleaned unneccessary func and merged i…
mehmet-yoti Nov 24, 2023
f705d44
Merge branch 'SDK-2259-go-retrieve-qr-code' into SDK-2235-share-v-2-r…
mehmet-yoti Nov 24, 2023
a4775d2
Update cryptoutil/crypto_utils.go
mehmet-yoti Dec 7, 2023
3da5372
SDK-2235:reduced complexity
mehmet-yoti Dec 7, 2023
9d403b8
SDK-2235 removed unused method, added panic controls, added error con…
mehmet-yoti Dec 12, 2023
af99524
SDK-2235 added error contexts
mehmet-yoti Dec 12, 2023
a3d8314
Update digitalidentity/service.go
mehmet-yoti Dec 14, 2023
5f1ec57
Update digitalidentity/service.go
mehmet-yoti Dec 14, 2023
3fb2de7
SDK-2235 updated error context text
mehmet-yoti Dec 14, 2023
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
1 change: 1 addition & 0 deletions _examples/digitalidentity/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func generateSession(w http.ResponseWriter, r *http.Request) {
didClient, err := initialiseDigitalIdentityClient()
if err != nil {
fmt.Fprintf(w, string("Client could't be generated"))
klaidas marked this conversation as resolved.
Show resolved Hide resolved
return
}

sessionReq, err := buildDigitalIdentitySessionReq()
Expand Down
2 changes: 1 addition & 1 deletion consts/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package consts

const (
SDKIdentifier = "Go"
SDKVersionIdentifier = "3.12.0"
SDKVersionIdentifier = "3.9.0"
)
2 changes: 1 addition & 1 deletion digitalidentity/requests/signed_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestRequestShouldBuildForValid(t *testing.T) {
assert.Check(t, urlCheck)
assert.Check(t, signed.Header.Get("X-Yoti-Auth-Digest") != "")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK"), "Go")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK-Version"), "3.12.0")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK-Version"), "3.9.0")
}

func TestRequestShouldAddHeaders(t *testing.T) {
Expand Down
64 changes: 42 additions & 22 deletions digitalidentity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package digitalidentity
import (
"crypto/rsa"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -223,6 +224,10 @@ func GetShareReceipt(httpClient requests.HttpClient, receiptId string, clientSdk
return receipt, err
}

if err := validateReceiptResponse(receiptResponse); err != nil {
return receipt, err
}

itemKeyId := receiptResponse.WrappedItemKeyId

encryptedItemKeyResponse, err := getReceiptItemKey(httpClient, itemKeyId, clientSdkId, apiUrl, key)
Expand All @@ -235,19 +240,9 @@ func GetShareReceipt(httpClient requests.HttpClient, receiptId string, clientSdk
return receipt, fmt.Errorf("failed to unwrap receipt content key: %v", err)
}

aattr, err := cryptoutil.DecryptReceiptContent(receiptResponse.Content.Profile, receiptContentKey)
if err != nil {
return receipt, fmt.Errorf("failed to decrypt receipt content profile: %v", err)
}

aextra, err := cryptoutil.DecryptReceiptContent(receiptResponse.Content.ExtraData, receiptContentKey)
attrData, aextra, err := decryptReceiptContent(receiptResponse.Content, receiptContentKey)
if err != nil {
return receipt, fmt.Errorf("failed to decrypt receipt content extra data: %v", err)
}

attrData := &yotiprotoattr.AttributeList{}
if err := proto.Unmarshal(aattr, attrData); err != nil {
return receipt, fmt.Errorf("failed to unmarshal application attribute list: %v", err)
return receipt, err
mehmet-yoti marked this conversation as resolved.
Show resolved Hide resolved
}

applicationProfile := newApplicationProfile(attrData)
Expand All @@ -256,17 +251,9 @@ func GetShareReceipt(httpClient requests.HttpClient, receiptId string, clientSdk
return receipt, fmt.Errorf("failed to build application extra data: %v", err)
}

uattr, err := cryptoutil.DecryptReceiptContent(receiptResponse.OtherPartyContent.Profile, receiptContentKey)
if err != nil {
return receipt, fmt.Errorf("failed to decrypt other party receipt content profile: %v", err)
}
uextra, err := cryptoutil.DecryptReceiptContent(receiptResponse.OtherPartyContent.ExtraData, receiptContentKey)
uattrData, uextra, err := decryptReceiptContent(receiptResponse.OtherPartyContent, receiptContentKey)
if err != nil {
return receipt, fmt.Errorf("failed to decrypt other party receipt content extra data: %v", err)
}
uattrData := &yotiprotoattr.AttributeList{}
if err := proto.Unmarshal(uattr, uattrData); err != nil {
return receipt, fmt.Errorf("failed to unmarshal attribute list: %v", err)
return receipt, err
mehmet-yoti marked this conversation as resolved.
Show resolved Hide resolved
klaidas marked this conversation as resolved.
Show resolved Hide resolved
}

userProfile := newUserProfile(uattrData)
Expand All @@ -292,3 +279,36 @@ func GetShareReceipt(httpClient requests.HttpClient, receiptId string, clientSdk
Error: receiptResponse.Error,
}, nil
}

func validateReceiptResponse(receiptResponse ReceiptResponse) error {
klaidas marked this conversation as resolved.
Show resolved Hide resolved
if receiptResponse.Content == nil || len(receiptResponse.Content.Profile) == 0 {
return errors.New("received unexpectedly empty content or profile")
}
return nil
}

func decryptReceiptContent(content *Content, key []byte) (attrData *yotiprotoattr.AttributeList, aextra []byte, err error) {
aattr := []byte{}
if content != nil {
if len(content.Profile) > 0 {
aattr, err = cryptoutil.DecryptReceiptContent(content.Profile, key)
if err != nil {
return nil, nil, fmt.Errorf("failed to decrypt receipt content profile: %v", err)
}
}

if len(content.ExtraData) > 0 {
aextra, err = cryptoutil.DecryptReceiptContent(content.ExtraData, key)
if err != nil {
return nil, nil, fmt.Errorf("failed to decrypt receipt content extra data: %v", err)
}
}

attrData = &yotiprotoattr.AttributeList{}
if err := proto.Unmarshal(aattr, attrData); err != nil {
return nil, nil, fmt.Errorf("failed to unmarshal attribute list: %v", err)
}
klaidas marked this conversation as resolved.
Show resolved Hide resolved
}

return attrData, aextra, nil
}
2 changes: 1 addition & 1 deletion requests/signed_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestRequestShouldBuildForValid(t *testing.T) {
assert.Check(t, urlCheck)
assert.Check(t, signed.Header.Get("X-Yoti-Auth-Digest") != "")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK"), "Go")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK-Version"), "3.12.0")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK-Version"), "3.9.0")
}

func TestRequestShouldAddHeaders(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sonar.organization = getyoti
sonar.projectKey = getyoti:go
sonar.projectName = Go SDK
sonar.projectVersion = 3.12.0
sonar.projectVersion = 3.9.0
sonar.exclusions = **/yotiprotoattr/*.go,**/yotiprotocom/*.go,**/yotiprotoshare/*.go,**/**_test.go,_examples/**/*
sonar.links.scm = https://github.com/getyoti/yoti-go-sdk
sonar.host.url = https://sonarcloud.io
Expand Down
Loading