Skip to content

Commit

Permalink
fix: fixed trust store logic in verify (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Two-Hearts committed Aug 21, 2023
1 parent 7ea89f5 commit 879f728
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/e2e-test-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ jobs:
target_artifact_reference: ${{ env.target_artifact_reference }}
trust_policy: ./tests/e2e/trustpolicy/trustpolicy.json
trust_store: ./tests/e2e/truststore

- name: Verify released artifact again with the same notation configuration
uses: ./verify
with:
target_artifact_reference: ${{ env.target_artifact_reference }}
trust_policy: ./tests/e2e/trustpolicy/trustpolicy.json
trust_store: ./tests/e2e/truststore

- name: Verify released artifact missing target artifact reference
continue-on-error: true
Expand Down Expand Up @@ -143,8 +150,6 @@ jobs:
echo "Verify released artifact with invalid trust store structure should fail, but succeeded."
exit 1
- name: Clean up notation trust store
run: notation cert delete --type ca --store e2e-test -y --all
- name: Verify released artifact without valid cert in trust store
continue-on-error: true
id: invalid-cert
Expand Down
7 changes: 6 additions & 1 deletion dist/verify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/verify.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as fs from 'fs';
import * as path from 'path';
import {getConfigHome} from './lib/install'

const X509 = "x509";

Expand Down Expand Up @@ -72,6 +73,10 @@ async function configTrustStore(dir: string) {
if (!fs.existsSync(trustStoreX509)) {
throw new Error(`cannot find trust store dir: ${trustStoreX509}`);
}
const trustStorePath = path.join(getConfigHome(), 'notation', 'truststore');
if (fs.existsSync(trustStorePath)) {
fs.rmSync(trustStorePath, {recursive: true});
}
let trustStoreTypes = getSubdir(trustStoreX509); // [.github/truststore/x509/ca, .github/truststore/x509/signingAuthority, ...]
for (let i = 0; i < trustStoreTypes.length; ++i) {
let trustStoreType = path.basename(trustStoreTypes[i]);
Expand All @@ -80,7 +85,7 @@ async function configTrustStore(dir: string) {
let trustStore = trustStores[j]; // .github/truststore/x509/ca/<my_store>
let trustStoreName = path.basename(trustStore); // <my_store>
let certFile = getFileFromDir(trustStore); // [.github/truststore/x509/ca/<my_store>/<my_cert1>, .github/truststore/x509/ca/<my_store>/<my_cert2>, ...]
exec.getExecOutput('notation', ['cert', 'add', '-t', trustStoreType, '-s', trustStoreName, ...certFile]);
await exec.getExecOutput('notation', ['cert', 'add', '-t', trustStoreType, '-s', trustStoreName, ...certFile]);
}
}
}
Expand Down

0 comments on commit 879f728

Please sign in to comment.