Skip to content
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

Use FIPS-approved SHA256 instead of weak MD5 #8379

Merged
merged 2 commits into from
Sep 14, 2020
Merged

Use FIPS-approved SHA256 instead of weak MD5 #8379

merged 2 commits into from
Sep 14, 2020

Conversation

azatsarynnyy
Copy link
Member

@azatsarynnyy azatsarynnyy commented Aug 13, 2020

Signed-off-by: Artem Zatsarynnyi azatsary@redhat.com

What it does

Fixes #8378 by removing MD5 usage.

How to test

The simplest variant to test it is to run Theia and see that there's no unusual error logged, frontend is loaded as usual and Task of types process/shell works as expected.

If it's possible, you can check the same in an OS with FIPS mode enabled. E.g. here's the instructions for Red Hat Enterprise Linux 7.

Review checklist

Reminder for reviewers

Copy link
Member

@paul-marechal paul-marechal left a comment

Choose a reason for hiding this comment

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

LGTM!

@vince-fugnitto vince-fugnitto added the security issues related to security label Aug 13, 2020
@akosyakov
Copy link
Member

akosyakov commented Aug 14, 2020

Is it a breaking change for all workspace and plugin storages out there? All data will be lost? We need a migration?

@akosyakov
Copy link
Member

akosyakov commented Aug 14, 2020

I've noticed also that we bogusly encode workspace roots into workspace id leading to bugs like #7472

I think the proper solution will be to align with VS Code implementation, maybe it does not even require usage of crypto. There is not a real security concern in affected code. It seems to be misusage of crypto to generate identifiers. Plus we should make sure that data are not lost, but migrated.

@akosyakov akosyakov added the vscode issues related to VSCode compatibility label Aug 14, 2020
@@ -1457,7 +1457,7 @@ export class ProcessExecution {
}

public computeId(): string {
const hash = crypto.createHash('md5');
const hash = crypto.createHash('sha256');
Copy link
Member

Choose a reason for hiding this comment

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

Not sure about backward computability consequences of changing this file. Do we store them somewhere and should read again or it is pure runtime thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

As I see, it's used at runtime only.
BTW I've found that it has been reworked in VS Code to generate IDs based on the command line instead of hashes.
microsoft/vscode@36d9d04
We need to update it in Theia correspondingly. I'll take a look at whether it can be done within this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed the IDs generation according to the current VS Code state. Now, it doesn't require crypto Node module.

@azatsarynnyy
Copy link
Member Author

It breaks the Tasks list.

With the changes:
image

From master branch:
image

Also, NPM SCRIPTS view is empty:
image

Need to investigate how it's related.

@azatsarynnyy
Copy link
Member Author

I can reproduce both issues (mentioned above) on master branch as well. They are randomly reproducible and are not related to the PR changes.

@azatsarynnyy azatsarynnyy changed the title Use FIPS-approved SHA256 instead of weak MD5 [WIP] Use FIPS-approved SHA256 instead of weak MD5 Sep 2, 2020
@benoitf
Copy link
Contributor

benoitf commented Sep 3, 2020

I'm restarting travis job that failed on macos

@akosyakov
Copy link
Member

@azatsarynnyy it is good, but we cannot switch algorithm for global and plugin state without providing migrations for old state. It will wipe out all state for VS Code extensions for existing installations.

@azatsarynnyy
Copy link
Member Author

@azatsarynnyy it is good, but we cannot switch algorithm for global and plugin state without providing migrations for old state. It will wipe out all state for VS Code extensions for existing installations.

@akosyakov I agree that we should migrate the plugins' data.
I think we can keep the migration code for one release (1.6.0) with a note in the changelogs. And then remove the migration and MD5 usage in the next release - 1.7.0. WDYT?

@akosyakov
Copy link
Member

akosyakov commented Sep 3, 2020

I think we can keep the migration code for one release (1.6.0) with a note in the changelogs. And then remove the migration and MD5 usage in the next release - 1.7.0. WDYT?

What would happen if someone migrated from 1.0.0 to 1.8.0? user data will be erased? Probably it is just should stay in codebase forever in the same way since it touches end user data.

@azatsarynnyy
Copy link
Member Author

I think we can keep the migration code for one release (1.6.0) with a note in the changelogs. And then remove the migration and MD5 usage in the next release - 1.7.0. WDYT?

What would happen if someone migrated from 1.0.0 to 1.8.0? user data will be erased? Probably it is just should stay in codebase forever in the same way since it touches end user data.

You are right @akosyakov. Thanks. I'll look for another way to fix #8378
Probably, we need to detect somehow whether we're running in a FIPS environment and then use SHA-256 instead of MD5.

// md5 is not FIPS-approved but we have to continue use it as there're existing storage folders based on it
return crypto.createHash('md5').update(str).digest('hex');
} catch (e) {
// FIPS-compliant
Copy link
Member

Choose a reason for hiding this comment

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

Can we narrow down the error and log in all other cases? to avoid false positively creating sha256 hashes?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Artem Zatsarynnyi <azatsary@redhat.com>
Signed-off-by: Artem Zatsarynnyi <azatsary@redhat.com>
Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

code wise looks good to me, but someone has to try it out

@azatsarynnyy
Copy link
Member Author

Here are several screenshots made in the downstream product.
With FIPS mode enabled, storage folders names are generated with SHA256
image

With FIPS mode disabled, storage folders names are generated with MD5 - with no changes comparing to master branch
image

Shell task is running well in both modes, without any changes
image

If there're no objections, I'll merge it by the EOD.

@azatsarynnyy azatsarynnyy merged commit 4378748 into master Sep 14, 2020
@azatsarynnyy azatsarynnyy deleted the az/crypto branch September 14, 2020 19:04
@azatsarynnyy azatsarynnyy changed the title [WIP] Use FIPS-approved SHA256 instead of weak MD5 Use FIPS-approved SHA256 instead of weak MD5 Sep 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security issues related to security vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Theia should work on a FIPS-compliant system
5 participants