Skip to content

Commit

Permalink
test: add nonce generator
Browse files Browse the repository at this point in the history
Signed-off-by: Allain Magyar <allain.magyar@iohk.io>
  • Loading branch information
amagyar-iohk committed Mar 28, 2024
1 parent 1e4d78a commit 6e4e3b5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Expand Up @@ -8,4 +8,3 @@ Feature: Provide proof
When Cloud Agent asks for presentation of AnonCred proof
And Edge Agent sends the present-proof
Then Cloud Agent should see the present-proof is verified

2 changes: 1 addition & 1 deletion integration-tests/e2e-tests/features/provide_proof.feature
@@ -1,4 +1,4 @@
@proof
@jwt @proof
Feature: Provide proof
The Edge Agent should provide proof to Cloud Agent

Expand Down
19 changes: 17 additions & 2 deletions integration-tests/e2e-tests/src/Utils.ts
@@ -1,4 +1,5 @@
import {appendFile, writeFileSync} from "fs"
import { appendFile, writeFileSync } from "fs"
import crypto from 'crypto'

export class Utils {
static prepareNotes() {
Expand All @@ -8,7 +9,7 @@ export class Utils {
static appendToNotes(message: string) {
console.info("Adding to notes:", message)
appendFile("notes", message + "\n", (err) => {
if(err) console.error(err)
if (err) console.error(err)
})
}

Expand All @@ -34,4 +35,18 @@ export class Utils {
error.stack = delegateError.stack
throw error
}

static generateNonce(length: number): string {
const bytesNeeded = Math.ceil(length * 0.75)
const randomBytes = crypto.randomBytes(bytesNeeded)

let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(i * 0.75)
const randomByte = randomBytes[randomIndex];
const randomDigit = randomByte % 10

Check failure

Code scanning / CodeQL

Creating biased random numbers from a cryptographically secure source High

Using modulo on a
cryptographically secure random number
produces biased results.
result += randomDigit.toString()
}
return result;
}
}
Expand Up @@ -13,6 +13,7 @@ import {
RequestPresentationInput,
} from "@hyperledger-labs/open-enterprise-agent-ts-client"
import {CloudAgentConfiguration} from "../configuration/CloudAgentConfiguration"
import { Utils } from "../Utils"

export class CloudAgentWorkflow {
static async createConnection(cloudAgent: Actor, label?: string, goalCode?: string, goal?: string) {
Expand Down Expand Up @@ -170,7 +171,7 @@ export class CloudAgentWorkflow {
}
},
name: "proof_req_1",
nonce: "1103253414365527824079144",
nonce: Utils.generateNonce(25),
version: "0.1"
},
proofs: [],
Expand Down

0 comments on commit 6e4e3b5

Please sign in to comment.