Skip to content

Migrate file upload digest algorithm from MD5 to SHA-384 (FIPS 140-3 + NCS) - #1884

Open
vkalapov wants to merge 5 commits into
masterfrom
fips-file-digest-sha256
Open

Migrate file upload digest algorithm from MD5 to SHA-384 (FIPS 140-3 + NCS)#1884
vkalapov wants to merge 5 commits into
masterfrom
fips-file-digest-sha256

Conversation

@vkalapov

Copy link
Copy Markdown
Contributor

What

Change Constants.DIGEST_ALGORITHM from "MD5" to "SHA-384" and update all test fixtures accordingly.

Why

SHA-384 satisfies both FIPS 140-3 (FIPS 180-4) and NCS MODERATE requirements. MD5 and SHA-256 are not approved at NCS MODERATE level.

Compatibility

Backward compatible — no breaking change.

The server always computes and stores its own digest on upload (DatabaseFileServiceSqlFileQueryProvider). No client-sent digest is ever read or verified on the server side.

  • Old CLI users: isFileAlreadyUploaded will hit "Unsupported digest algorithm" for the SHA-384 entries returned by GET /files, re-upload on every retry instead of skipping — deploys complete successfully.
  • First deploy after DS restart: UploadAppStep detects mismatch between freshly computed SHA-384 and the MD5 value stored in the CF app environment → one-time forced re-upload of every app binary. Self-heals on the second deploy.

LMCROSSITXSADEPLOY-3224

public static final String VARIABLE_NAME_SERVICE_ID = "__SERVICE_ID";

public static final String DIGEST_ALGORITHM = "MD5";
public static final String DIGEST_ALGORITHM = "SHA-384";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we use SHA3 alrogirthm instead of SHA2? Also recommended length isn't it 512 instead of 384?

Another important thing is what will happen when this change is applied during blue-green update and there are running mta operations or files upload?

What will happen if files were uploaded and persisted with md5 digest and then read/retrieved from updated instance of deploy service and try to parse stored md5 checksums as SHA-384? I think we have to implement some backwards compatible logic in order to avoid breaking running mta operations/running file uploads.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SHA3 is needed for ADVANCED requirements, SHA-384 satisfies the moderate requirements in our case.

Mid operation swap was tasted without failures. After the initial upload, the digest is only fetched and checked during write operations (i.e. uploading a new file).
Also tested directly through the API endpoints to upload and start deploy operations separately with the initial being a md5 digest and the latter being after swap with sha-384 changes.

public static final String VARIABLE_NAME_SERVICE_ID = "__SERVICE_ID";

public static final String DIGEST_ALGORITHM = "MD5";
public static final String DIGEST_ALGORITHM = "SHA-384";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a performance degradation when the new algorithm is used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For file uploads, the operation is typically I/O-bound rather than hash-bound, so we don't expect a meaningful performance difference in practice. Either way, the mandatory performance tests should reveal any regressions.

@IvanBorislavovDimitrov

Copy link
Copy Markdown
Contributor

We also use MD5 in MtaMetadataUtil to hash the mta id. Do we need to change the algorithm there?

@vkalapov

Copy link
Copy Markdown
Contributor Author

We also use MD5 in MtaMetadataUtil to hash the mta id. Do we need to change the algorithm there?

The MD5 in MtaMetadataUtil is out of scope for this PR - this one addresses file upload digest only. Since it requires a migration strategy to avoid breaking detection of existing deployed MTAs.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants