-
Notifications
You must be signed in to change notification settings - Fork 204
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
feat(anoncreds): use legacy prover did #1374
feat(anoncreds): use legacy prover did #1374
Conversation
Signed-off-by: Ariel Gentile <[email protected]>
Signed-off-by: Ariel Gentile <[email protected]>
Signed-off-by: Ariel Gentile <[email protected]>
Signed-off-by: Ariel Gentile <[email protected]>
Signed-off-by: Ariel Gentile <[email protected]>
) | ||
} | ||
|
||
if (!credentialDefinitionId.match(legacyIndyCredentialDefinitionIdRegex)) { |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data
if (!credOffer.schema_id || !credOffer.cred_def_id) { | ||
if ( | ||
!credOffer.schema_id.match(legacyIndySchemaIdRegex) || | ||
!credOffer.cred_def_id.match(legacyIndyCredentialDefinitionIdRegex) |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data
@@ -226,6 +234,11 @@ | |||
|
|||
const credentialOffer = offerAttachment.getDataAsJson<AnonCredsCredentialOffer>() | |||
|
|||
if (!credentialOffer.cred_def_id.match(legacyIndyCredentialDefinitionIdRegex)) { |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data
credentialDefinition: CredentialDefinition.load(JSON.stringify(credentialDefinition)), | ||
credentialOffer: CredentialOffer.load(JSON.stringify(credentialOffer)), | ||
masterSecret: MasterSecret.load(JSON.stringify({ value: { ms: linkSecretRecord.value } })), | ||
const isLegacyIdentifier = credentialOffer.cred_def_id.match(legacyIndyCredentialDefinitionIdRegex) |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data
Codecov Report
@@ Coverage Diff @@
## main #1374 +/- ##
==========================================
- Coverage 87.23% 87.20% -0.03%
==========================================
Files 780 780
Lines 18728 18747 +19
Branches 3211 3221 +10
==========================================
+ Hits 16337 16349 +12
- Misses 2384 2391 +7
Partials 7 7
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
…vice Signed-off-by: Ariel Gentile <[email protected]>
@@ -499,6 +505,10 @@ | |||
const credentialDefinitions: { [key: string]: AnonCredsCredentialDefinition } = {} | |||
|
|||
for (const credentialDefinitionId of credentialDefinitionIds) { | |||
if (!credentialDefinitionId.match(legacyIndyCredentialDefinitionIdRegex)) { |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data
What's the blocker for this PR @genaris? |
It was hyperledger/anoncreds-rs#137 Now it's merged but waiting for the release in npm integrating it. |
Cool! Release is cooking now: https://github.com/hyperledger/anoncreds-rs/releases/tag/v0.1.0-dev.10 |
Signed-off-by: Ariel Gentile <[email protected]>
createReturnObj = CredentialRequest.create({ | ||
entropy: anoncreds.generateNonce(), // FIXME: find a better source of entropy | ||
entropy: !useLegacyProverDid || !isLegacyIdentifier ? anoncreds.generateNonce() : undefined, // FIXME: find a better source of entropy |
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.
Another option for generating entropy can be calling agentContext.wallet.generateWalletKey
, which in AskarWallet creates an ephemeral key and converts its private key to a base58 string (I guess IndySdkWallet does more or less the same thing). However I'm not sure if it's good to rely on wallet implementation for that (unless we strictly specify the requirements for such generateWalletKey
in API).
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 feels like we're misusing the generateWalletKey in that case. I think a nonce should provide enough randomness right?
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.
IMHO the nonce generated by anoncreds, apart from being convenient for us, is enough for the purposes of giving some entropy in credential generation. But just trying to find an alternative that provides a true 'alphanumeric' random string as stated in the spec.
createReturnObj = CredentialRequest.create({ | ||
entropy: anoncreds.generateNonce(), // FIXME: find a better source of entropy | ||
entropy: !useLegacyProverDid || !isLegacyIdentifier ? anoncreds.generateNonce() : undefined, // FIXME: find a better source of entropy | ||
proverDid: useLegacyProverDid ? generateLegacyProverDidLikeString() : undefined, |
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.
As it should be random, do wr need to make this a secure ranom generation? E.g. nonce and then encode it as base58?
We could also add a getRandomBytes method to the wallet?
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.
I copied it from anoncreds/indy-sdk package implementation, but also thought that could be a good idea to rely in anoncreds native library instead of uuid as it's being done currently in generateLegacyProverDidLikeString
.
Any 22-bytes long base58 string will be good for that purpose, right?
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.
As it's used for entropy, it may be needed for the string to be generated with actual secure random bytes instead of a random string?
|
||
const legacySchemaId = getLegacySchemaId(legacyIssuerId, options.schema.name, options.schema.version) |
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.
The old implementation supported both for convenience, why is this needed?
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.
If schema issuerId is an unqualified did, parseIndyDid
threw an error. Maybe I can do it 'automatic' (i.e. without config flag and a try-catch?)
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's for tests, so whatever works
Is fine. Just curious
c7d385a
to
cc03c05
Compare
Signed-off-by: Ariel Gentile <[email protected]>
LGTM!! |
Signed-off-by: Ariel Gentile <[email protected]>
Adds
useLegacyProverDid
flag for credential request creation, which is always set when dealing with legacy indy identifiers. Some checks were added inLegacyIndyCredentialFormatService
to make sure we are using legacy ones.When using IndySdk, only legacy prover_did can be used, while in AnonCredsRs through this flag we can select between prover_did and entropy, unless we are using new identifiers where only entropy can be generated.