-
Notifications
You must be signed in to change notification settings - Fork 430
Implemented Veracode Policy Name Validation #20
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
681540c
Implemented Veracode Policy Name Validation
veeranjaneya-reddy a396cd2
Added Break Build for Policy validation
veeranjaneya-reddy 113dea0
updated veracode-code-analysis.yml
veeranjaneya-reddy 5980eaa
Implemented Annotation Object to display annotations
veeranjaneya-reddy 9341d9b
change in generate_signature file
veeranjaneya-reddy d63ec00
Update veracode-update-check-run.yml
veeranjaneya-reddy 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 hidden or 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 hidden or 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 hidden or 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,118 @@ | ||
| name: Veracode Check Run Updation | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| run_id: | ||
| description: 'ID of workflow run (provided via GitHub syntax `github.run_id`)' | ||
| required: true | ||
| type: string | ||
| repository_owner: | ||
| description: 'repository_owner of original commit (provided by GitHub app via `github.event.client_payload.repository.owner`)' | ||
| required: true | ||
| type: string | ||
| repository_name: | ||
| description: 'repository_name of original commit (provided by GitHub app via `github.event.client_payload.repository.name`)' | ||
| required: true | ||
| type: string | ||
| check_run_name: | ||
| description: 'Name of check (Use `github.workflow` to use the name of the workflow)' | ||
| required: true | ||
| type: string | ||
| head_sha: | ||
| description: 'head_sha of original commit (provided by GitHub app via `github.event.client_payload.sha`)' | ||
| required: true | ||
| type: string | ||
| github_token: | ||
| description: 'github_token is a token (provided by GitHub app via `github.event.client_payload.token`)' | ||
| required: true | ||
| type: string | ||
| event_type: | ||
| description: 'event_type triggered by the GitHub App (provided by GitHub app via `github.event.client_payload.event_type`)' | ||
| required: true | ||
| type: string | ||
| show_annotation: | ||
| description: 'Boolean flag to indicate if the annotation has to be displayed' | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
| message: | ||
| description: 'Annotation message that needs to be displayed' | ||
| required: false | ||
| type: string | ||
| conclusion: | ||
| description: 'Workflow conclusion' | ||
| required: false | ||
| type: string | ||
| status: | ||
| description: 'Workflow status' | ||
| required: false | ||
| type: string | ||
| title: | ||
| description: 'title of Annotation' | ||
| required: false | ||
| type: string | ||
| annotation_level: | ||
| description: 'Annotation level is whether warning or failure' | ||
| required: false | ||
| type: string | ||
| start_line: | ||
| description: 'Start line of the Policy' | ||
| required: false | ||
| type: string | ||
| end_line: | ||
| description: 'End line of the Policy' | ||
| required: false | ||
| type: string | ||
| summary: | ||
| description: 'Summary of the Annotation' | ||
| required: false | ||
| type: string | ||
| path: | ||
| description: 'Path for Configuration file' | ||
| required: false | ||
| type: string | ||
| break_build_policy_findings: | ||
| description: 'Breaking the build' | ||
| required: false | ||
| type: string | ||
| jobs: | ||
| update_check_run: | ||
| name: Update Check Run Job | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Update Check | ||
| uses: octokit/request-action@v2.x | ||
| id: update_check_run | ||
| env: | ||
| GITHUB_TOKEN: ${{ inputs.github_token }} | ||
| with: | ||
| route: PATCH /repos/${{ inputs.repository_owner }}/${{ inputs.repository_name }}/check-runs/${{ inputs.run_id }} | ||
| name: "Veracode Policy Name Validation" | ||
| conclusion: ${{ inputs.conclusion }} | ||
| status: ${{ inputs.status }} | ||
| output: | | ||
| title: ${{ inputs.title }} | ||
| summary: ${{ inputs.summary }} | ||
| annotations: | ||
| - path: ${{ inputs.path }} | ||
| title: ${{ inputs.title }} | ||
| annotation_level: ${{ inputs.annotation_level }} | ||
| message: ${{ inputs.message }} | ||
| start_line: ${{ inputs.start_line }} | ||
| end_line: ${{ inputs.end_line }} | ||
|
|
||
| - name: Show annotations | ||
| if: ${{ inputs.show_annotation == true && inputs.break_build_policy_findings == 'false' }} | ||
| run: | | ||
| echo "::error::${{ inputs.message }}" | ||
|
|
||
|
|
||
| - name: Fail the Execution | ||
| if: ${{ inputs.break_build_policy_findings == 'true' }} | ||
| uses: actions/github-script@v7.0.1 | ||
| with: | ||
| script: | | ||
| core.setFailed( "${{ inputs.message }}") |
This file contains hidden or 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,55 @@ | ||
| const crypto = require('crypto'); | ||
| var url = require('url'); | ||
|
|
||
| const authorizationScheme = 'VERACODE-HMAC-SHA-256'; | ||
| const requestVersion = "vcode_request_version_1"; | ||
| const nonceSize = 16; | ||
|
|
||
| function computeHashHex(message, key_hex) { | ||
| // return CryptoJS.HmacSHA256(message, CryptoJS.enc.Hex.parse(key_hex)).toString(CryptoJS.enc.Hex); | ||
| hmac1 = crypto.createHmac('sha256', Buffer.from(key_hex,'hex')); | ||
| hmac1.update(message); | ||
|
|
||
| // Return the digest in hexadecimal format | ||
| return hmac1.digest('hex'); | ||
| } | ||
|
|
||
| function calculateDataSignature(apikey, nonceBytes, dateStamp, data) { | ||
| let kNonce = computeHashHex(nonceBytes, apikey); | ||
| let kDate = computeHashHex(dateStamp, kNonce); | ||
| let kSig = computeHashHex(requestVersion, kDate); | ||
| return computeHashHex(data, kSig); | ||
| } | ||
|
|
||
| function newNonce() { | ||
| // return CryptoJS.lib.WordArray.random(nonceSize).toString().toUpperCase(); | ||
| return crypto.randomBytes(nonceSize).toString('hex').toUpperCase() | ||
| } | ||
|
|
||
| function toHexBinary(input) { | ||
| // return CryptoJS.enc.Hex.stringify(CryptoJS.enc.Utf8.parse(input)); | ||
| return Buffer.from(input,'utf-8').toString('hex'); | ||
| } | ||
|
|
||
| function removePrefixFromApiCredential(input) { | ||
| return input.split('-').at(-1); | ||
| } | ||
|
|
||
| function calculateVeracodeAuthHeader(requestUrl, httpMethod, host, id, key) { | ||
| const formattedId = removePrefixFromApiCredential(id); | ||
| const formattedKey = removePrefixFromApiCredential(key); | ||
|
|
||
| let parsedUrl = url.parse(requestUrl); | ||
| let data = `id=${formattedId}&host=${host}&url=${parsedUrl.path}&method=${httpMethod}`; | ||
| let dateStamp = Date.now().toString(); | ||
| let nonceBytes = newNonce(); | ||
| let dataSignature = calculateDataSignature(formattedKey, nonceBytes, dateStamp, data); | ||
| let authorizationParam = `id=${formattedId},ts=${dateStamp},nonce=${toHexBinary(nonceBytes)},sig=${dataSignature}`; | ||
| let hmac = authorizationScheme + " " + authorizationParam; | ||
| console.log(hmac) | ||
| } | ||
|
|
||
|
|
||
| module.exports = { | ||
| calculateVeracodeAuthHeader: calculateVeracodeAuthHeader | ||
| }; |
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.
Uh oh!
There was an error while loading. Please reload this page.