This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 160
feat: CL Anoncreds Crypto API #3275
Merged
sudeshrshetty
merged 1 commit into
hyperledger-archives:main
from
kgoncharov:cl-crypto-api-tink
Aug 11, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
//go:build ursa | ||
// +build ursa | ||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since the crypto api was updated to add the new CL functions, the framework won't compile without this build tag. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as discussed in today's planning, since there are empty stubs in the non-ursa build, the framework should be ok. Further changes will be needed on the server side of KMS. |
||
|
||
/* | ||
Copyright Avast Software. All Rights Reserved. | ||
|
||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package tinkcrypto | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/google/tink/go/keyset" | ||
|
||
bld "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/cl/blinder" | ||
sgn "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/cl/signer" | ||
) | ||
|
||
// Blind will blind provided values with MasterSecret provided in a kh | ||
// returns: | ||
// blinded values in []byte | ||
// error in case of errors | ||
func (t *Crypto) Blind(kh interface{}, values ...map[string]interface{}) ([][]byte, error) { | ||
keyHandle, ok := kh.(*keyset.Handle) | ||
if !ok { | ||
return nil, errBadKeyHandleFormat | ||
} | ||
|
||
blinder, err := bld.NewBlinder(keyHandle) | ||
if err != nil { | ||
return nil, fmt.Errorf("create new CL blinder: %w", err) | ||
} | ||
|
||
defer blinder.Free() // nolint: errcheck | ||
|
||
if len(values) == 0 { | ||
blinded, err := blinder.Blind(map[string]interface{}{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return [][]byte{blinded}, nil | ||
} | ||
|
||
blindedList := make([][]byte, len(values)) | ||
|
||
for i, val := range values { | ||
blinded, err := blinder.Blind(val) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
blindedList[i] = blinded | ||
} | ||
|
||
return blindedList, nil | ||
} | ||
|
||
// GetCorrectnessProof will return correctness proof for a public key handle | ||
// returns: | ||
// correctness proof in []byte | ||
// error in case of errors | ||
func (t *Crypto) GetCorrectnessProof(kh interface{}) ([]byte, error) { | ||
keyHandle, ok := kh.(*keyset.Handle) | ||
if !ok { | ||
return nil, errBadKeyHandleFormat | ||
} | ||
|
||
signer, err := sgn.NewSigner(keyHandle) | ||
if err != nil { | ||
return nil, fmt.Errorf("create new CL signer: %w", err) | ||
} | ||
|
||
defer signer.Free() // nolint: errcheck | ||
|
||
correctnessProof, err := signer.GetCorrectnessProof() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return correctnessProof, nil | ||
} | ||
|
||
// SignWithSecrets will generate a signature and related correctness proof | ||
// for the provided values using secrets and related DID | ||
// returns: | ||
// signature in []byte | ||
// correctness proof in []byte | ||
// error in case of errors | ||
func (t *Crypto) SignWithSecrets(kh interface{}, values map[string]interface{}, | ||
secrets []byte, correctnessProof []byte, nonces [][]byte, did string) ([]byte, []byte, error) { | ||
keyHandle, ok := kh.(*keyset.Handle) | ||
if !ok { | ||
return nil, nil, errBadKeyHandleFormat | ||
} | ||
|
||
signer, err := sgn.NewSigner(keyHandle) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("create new CL signer: %w", err) | ||
} | ||
|
||
defer signer.Free() // nolint: errcheck | ||
|
||
signature, signatureCorrectnessProof, err := signer.Sign(values, secrets, correctnessProof, nonces, did) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return signature, signatureCorrectnessProof, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//go:build !ursa | ||
// +build !ursa | ||
|
||
/* | ||
Copyright Avast Software. All Rights Reserved. | ||
|
||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package tinkcrypto | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
// Blind will blind provided values with MasterSecret provided in a kh | ||
// returns: | ||
// blinded values in []byte | ||
// error in case of errors | ||
// STUB. | ||
func (t *Crypto) Blind(kh interface{}, values ...map[string]interface{}) ([][]byte, error) { | ||
return nil, errors.New("not implemented") | ||
} | ||
|
||
// GetCorrectnessProof will return correctness proof for a public key handle | ||
// returns: | ||
// correctness proof in []byte | ||
// error in case of errors | ||
// STUB. | ||
func (t *Crypto) GetCorrectnessProof(kh interface{}) ([]byte, error) { | ||
return nil, errors.New("not implemented") | ||
} | ||
|
||
// SignWithSecrets will generate a signature and related correctness proof | ||
// for the provided values using secrets and related DID | ||
// returns: | ||
// signature in []byte | ||
// correctness proof in []byte | ||
// error in case of errors | ||
// STUB. | ||
func (t *Crypto) SignWithSecrets(kh interface{}, values map[string]interface{}, | ||
secrets []byte, correctnessProof []byte, nonces [][]byte, did string) ([]byte, []byte, error) { | ||
return nil, nil, errors.New("not implemented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build !ursa | ||
// +build !ursa | ||
|
||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
|
||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package tinkcrypto | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCLStubs(t *testing.T) { | ||
c := Crypto{} | ||
|
||
t.Run("test CL methods return not implemented", func(t *testing.T) { | ||
errNotImplemented := errors.New("not implemented") | ||
var err error | ||
|
||
_, err = c.GetCorrectnessProof(nil) | ||
require.EqualError(t, err, errNotImplemented.Error()) | ||
|
||
_, _, err = c.SignWithSecrets(nil, map[string]interface{}{}, nil, nil, nil, "") | ||
require.EqualError(t, err, errNotImplemented.Error()) | ||
|
||
_, err = c.Blind(nil, map[string]interface{}{}) | ||
require.EqualError(t, err, errNotImplemented.Error()) | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like
ursa
tagged files are not included in our linterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems it'll take
ursa
andcgo
to be provided ingolangci-lint
Docker container.should we create a new image for lint with these dependencies inside and use it in
check_lint.sh
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it seems the default golangci-lint won't have these tools, might as well create a new dedicated image. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Baha-sk Where should I keep related
Dockerfile
and push the corresponding image?Also, we could try to make a separate github job as Alex did for ursa tests - it'll use docker with pre-installed
ursa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can create a
ursa
subfolder underimages
and have a new dockerfile there.as for the job, i would recommend simply updating
scripts/check_lint.sh
with new entries forursa
linting using your new image.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Baha-sk can we postpone this chage to the next PR?
Currently, I'm not a contributor to af-go, since I haven't made any commit to the repo. Therefore, pipelines would be not started automatically. And it'll be painful to ask you to start pipeline on each of me changes during debug.
Although, I ran
golangci-lint
locally withursa
tag and made the fixes according to all lint warnings.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no issues @kgoncharov, this is not mandatory, but a suggestion if you need to have a separate dockerfile for ursa builds.