+
Skip to content

Use SHA-256 hashing #123

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 6 commits into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{
"name": "Run Extension",
"type": "extensionHost",
"problemMatcher": "$tsc",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't supported anymore, it seems

"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ But the jobs still only run locally.

Local CI has no server that runs jobs, so the site has no knowledge of the jobs or any data from them.

If you have entered a license key, it only sends to the [Local CI site](https://getlocalci.com) a `GET` request with the license key and an `md5` hash of your VS Code [machineId](https://code.visualstudio.com/api/references/vscode-api#env).
If you have entered a license key, it only sends to the [Local CI site](https://getlocalci.com) a `GET` request with the license key and a `SHA-256` hash of your VS Code [machineId](https://code.visualstudio.com/api/references/vscode-api#env).

This is to verify that the license key is only used on 1 machine.

Expand Down
51 changes: 19 additions & 32 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@
"@cloudflare/binary-install": "^0.2.0",
"@fluffy-spoon/substitute": "^1.208.0",
"@types/glob": "^7.1.3",
"@types/js-md5": "0.4.3",
"@types/js-yaml": "^4.0.1",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.23",
Expand Down Expand Up @@ -306,8 +305,8 @@
"webpack-cli": "^4.9.2"
},
"dependencies": {
"@vscode/extension-telemetry": "^0.5.1",
"axios": "^0.26.1",
"js-md5": "0.7.3",
"@vscode/extension-telemetry": "^0.5.1"
"cross-sha256": "^1.2.0"
}
}
3 changes: 0 additions & 3 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ interface SaveCache {
// See https://circleci.com/docs/2.0/configuration-reference/
interface FullStep {
checkout?: Record<string, unknown> | string;
// eslint-disable-next-line @typescript-eslint/naming-convention
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already ignored in .eslintrc.json

attach_workspace?: {
at: string;
};
// eslint-disable-next-line @typescript-eslint/naming-convention
persist_to_workspace?: {
root: string;
paths: Array<string>;
Expand Down Expand Up @@ -39,7 +37,6 @@ type Step = FullStep | string | 'checkout';
interface Job {
docker?: Array<Record<string, string>>;
steps?: Step[];
// eslint-disable-next-line @typescript-eslint/naming-convention
working_directory?: string;
machine?: { image?: string };
}
Expand Down
1 change: 0 additions & 1 deletion src/test/suite/utils/getAttachWorkspaceCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ suite('getAttachWorkspaceCommand', () => {
test('With attach_workspace', () => {
assert.strictEqual(
normalize(
// eslint-disable-next-line @typescript-eslint/naming-convention
getAttachWorkspaceCommand({ attach_workspace: { at: '/foo/baz' } })
),
normalize(
Expand Down
29 changes: 29 additions & 0 deletions src/test/suite/utils/getHash.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as assert from 'assert';
import getHash from '../../../utils/getHash';

suite('getHash', () => {
test('empty string', () => {
assert.strictEqual(
getHash(''),
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
);
});

test('possible machineId 1', () => {
assert.strictEqual(
getHash(
'a923bcf3da6acff9c9bf4f129135ffd56adbfa294aeb8117c7264164c1a9382ca'
),
'ea5320a945bfe117f3d9ee12268734180b697913fb7ff498549a5bb201255b09'
);
});

test('possible machineId 2', () => {
assert.strictEqual(
getHash(
'52ab60b09f4e8fae2bcb8ac38871cfa8613ee4a1d566dcec5659e320148dc366e'
),
'f600f144c3c96701f3c34ddd9fb65089af27fb8264fcba12f40af8d6cbbddeeb'
);
});
});
9 changes: 3 additions & 6 deletions src/test/suite/utils/getImageFromJob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@ import getImageFromJob from '../../../utils/getImageFromJob';
suite('getImageFromJob', () => {
test('No docker value', () => {
assert.deepStrictEqual(
getImageFromJob({ working_directory: 'foo/baz' }), // eslint-disable-line @typescript-eslint/naming-convention
getImageFromJob({ working_directory: 'foo/baz' }),
''
);
});

test('Empty docker array', () => {
assert.deepStrictEqual(
getImageFromJob({ docker: [] }), // eslint-disable-line @typescript-eslint/naming-convention
''
);
assert.deepStrictEqual(getImageFromJob({ docker: [] }), '');
});

test('With docker image', () => {
assert.deepStrictEqual(
getImageFromJob({ docker: [{ image: 'foo-image' }] }), // eslint-disable-line @typescript-eslint/naming-convention
getImageFromJob({ docker: [{ image: 'foo-image' }] }),
'foo-image'
);
});
Expand Down
6 changes: 3 additions & 3 deletions src/test/suite/utils/getPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ mocha.afterEach(() => {
suite('getPath', () => {
test('On Linux', () => {
sinon.mock(os).expects('type').once().returns('Linux');
sinon.stub(process, 'env').value({ PATH: '' }); // eslint-disable-line @typescript-eslint/naming-convention
sinon.stub(process, 'env').value({ PATH: '' });
assert.strictEqual(getPath(), '');
});

test('On Mac without the bin path', () => {
sinon.mock(os).expects('type').once().returns('Darwin');
sinon.stub(process, 'env').value({ PATH: 'Users/Foo/' }); // eslint-disable-line @typescript-eslint/naming-convention
sinon.stub(process, 'env').value({ PATH: 'Users/Foo/' });
assert.strictEqual(getPath(), 'Users/Foo/:/usr/local/bin');
});

test('On Mac with the bin path', () => {
sinon.mock(os).expects('type').once().returns('Darwin');
sinon.stub(process, 'env').value({ PATH: 'Users/Foo/:/usr/local/bin' }); // eslint-disable-line @typescript-eslint/naming-convention
sinon.stub(process, 'env').value({ PATH: 'Users/Foo/:/usr/local/bin' });
assert.strictEqual(getPath(), 'Users/Foo/:/usr/local/bin');
});
});
2 changes: 0 additions & 2 deletions src/test/suite/utils/getRestoreCacheCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ suite('getRestoreCacheCommand', () => {
normalize(
getRestoreCacheCommand(
{
// eslint-disable-next-line @typescript-eslint/naming-convention
restore_cache: {
key: 'v2-deps-{{ checksum "package-lock.json" }}',
},
Expand Down Expand Up @@ -62,7 +61,6 @@ suite('getRestoreCacheCommand', () => {
normalize(
getRestoreCacheCommand(
{
// eslint-disable-next-line @typescript-eslint/naming-convention
restore_cache: {
keys: ['v2-deps-{{ checksum "package-lock.json" }}', 'v2-deps'],
},
Expand Down
5 changes: 5 additions & 0 deletions src/utils/getHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { sha256 } from 'cross-sha256';

export default function getHash(toHash: string): string {
return new sha256().update(toHash).digest('hex');
}
1 change: 0 additions & 1 deletion src/utils/getLicenseErrorMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
const errors = {
missing: 'License does not exist.',
missing_url: 'URL not provided.',
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getSpawnOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function getSpawnOptions(cwd?: string): SpawnOptions {
cwd: cwd || getFirstWorkspaceRootPath(),
env: {
...process.env,
PATH: getPath(), // eslint-disable-line @typescript-eslint/naming-convention
PATH: getPath(),
},
};
}
10 changes: 5 additions & 5 deletions src/utils/isLicenseValid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import axios from 'axios';
import * as md5 from 'js-md5';
import * as vscode from 'vscode';
import {
LICENSE_ERROR,
Expand All @@ -8,6 +7,7 @@ import {
LICENSE_VALIDITY,
LICENSE_VALIDITY_CACHE_EXPIRATION,
} from '../constants';
import getHash from './getHash';

const licenseValidationEndpoint = 'https://getlocalci.com';
const fiveMinutesInMilliseconds = 300000;
Expand Down Expand Up @@ -41,12 +41,12 @@ export default async function isLicenseValid(
response = await axios.get(licenseValidationEndpoint, {
params: {
headers: {
'Cache-Control': 'no-cache', // eslint-disable-line @typescript-eslint/naming-convention
'Cache-Control': 'no-cache',
},
license: encodeURI(String(trimmedLicenseKey)),
edd_action: 'activate_license', // eslint-disable-line @typescript-eslint/naming-convention
item_id: LICENSE_ITEM_ID, // eslint-disable-line @typescript-eslint/naming-convention
url: md5(vscode.env.machineId),
edd_action: 'activate_license',
item_id: LICENSE_ITEM_ID,
url: getHash(vscode.env.machineId),
},
});
} catch (e) {
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载