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

Include FIPS mode in OpenSSL_version return value #1689

Merged

Conversation

WillChilds-Klein
Copy link
Contributor

@WillChilds-Klein WillChilds-Klein commented Jul 3, 2024

Issues:

Resolves t/P138681213

Description of changes:

This backports PR 1419 to the 2022 FIPS branch. Confirmed that modifying crypto.c does not affect the FIPS module.

Call-outs:

  • n/a

Testing:

  • CI
  • verified FIPS module hash is unchanged

Setup

$ git diff
diff --git a/util/fipstools/inject_hash/inject_hash.go b/util/fipstools/inject_hash/inject_hash.go
index e4905be6b..0ba118fb3 100644
--- a/util/fipstools/inject_hash/inject_hash.go
+++ b/util/fipstools/inject_hash/inject_hash.go
@@ -24,6 +24,7 @@ import (
        "debug/elf"
        "debug/macho"
        "encoding/binary"
+       "encoding/hex"
        "errors"
        "flag"
        "fmt"
@@ -390,7 +391,10 @@ func do(outPath, oInput string, arInput string, appleOS bool) error {
        } else {
                mac.Write(moduleText)
        }
+
        calculated := mac.Sum(nil)
+       fmt.Fprintf(os.Stdout, "CALCULATED MODULE HASH: %s\n", hex.EncodeToString(calculated[:]))
+       return nil

        // Replace the default hash value in the object with the calculated
        // value and write it out.

Before this PR

$ git show -q
commit d0c62be0b9083ffc20056649b0719c3990f553d0 (HEAD -> pr-1419-fips-backport)
Author: Will Childs-Klein <[email protected]>
Date:   Wed Jul 3 14:54:50 2024 +0000

    Revert "Include FIPS mode in OpenSSL_version return value (#1419)"

    This reverts commit 3f78067363523cc2aaaeeb31b75c450571cfcd56.

$ rm -rf build && cmake-build.sh && go run util/fipstools/inject_hash/inject_hash.go -in-object ./build/crypto/libcrypto.so
...
CALCULATED MODULE HASH: 02af10f6b9bbfe07a126c8c883e1be339f52a94ba3c69e6dad78605ad5ffcb5a

After this PR

$ git show -q
commit 3f78067363523cc2aaaeeb31b75c450571cfcd56 (HEAD -> pr-1419-fips-backport, origin/pr-1419-fips-backport)
Author: Will Childs-Klein <[email protected]>
Date:   Thu Feb 15 18:54:44 2024 -0500

    Include FIPS mode in OpenSSL_version return value (#1419)

    This change includes FIPS mode information in the return value of
    `OpenSSL_version(OPENSSL_VERSION)`. This will allow consumers of CPython (and
    likely other tools or language runtimes) to detect FIPS mode without calling to
    an AWS-LC-specific API, which would require either patching or forking the
    language or tool in question.

$ rm -rf build && cmake-build.sh && go run util/fipstools/inject_hash/inject_hash.go -in-object ./build/crypto/libcrypto.so
...
CALCULATED MODULE HASH: 02af10f6b9bbfe07a126c8c883e1be339f52a94ba3c69e6dad78605ad5ffcb5a

Ensure that Modifying Module Source Affects Hash

$ git diff
diff --git a/crypto/fipsmodule/sha/sha256.c b/crypto/fipsmodule/sha/sha256.c
index 38164535c..8f5a9b534 100644
--- a/crypto/fipsmodule/sha/sha256.c
+++ b/crypto/fipsmodule/sha/sha256.c
@@ -87,7 +87,7 @@ int SHA256_Init(SHA256_CTX *sha) {
   sha->h[3] = 0xa54ff53aUL;
   sha->h[4] = 0x510e527fUL;
   sha->h[5] = 0x9b05688cUL;
-  sha->h[6] = 0x1f83d9abUL;
+  sha->h[6] = 0x1f83d9acUL;
   sha->h[7] = 0x5be0cd19UL;
   sha->md_len = SHA256_DIGEST_LENGTH;
   return 1;
diff --git a/util/fipstools/inject_hash/inject_hash.go b/util/fipstools/inject_hash/inject_hash.go
index e4905be6b..0ba118fb3 100644
--- a/util/fipstools/inject_hash/inject_hash.go
+++ b/util/fipstools/inject_hash/inject_hash.go
@@ -24,6 +24,7 @@ import (
        "debug/elf"
        "debug/macho"
        "encoding/binary"
+       "encoding/hex"
        "errors"
        "flag"
        "fmt"
@@ -390,7 +391,10 @@ func do(outPath, oInput string, arInput string, appleOS bool) error {
        } else {
                mac.Write(moduleText)
        }
+
        calculated := mac.Sum(nil)
+       fmt.Fprintf(os.Stdout, "CALCULATED MODULE HASH: %s\n", hex.EncodeToString(calculated[:]))
+       return nil

        // Replace the default hash value in the object with the calculated
        // value and write it out.

$ rm -rf build && cmake-build.sh && go run util/fipstools/inject_hash/inject_hash.go -in-object ./build/crypto/libcrypto.so
...
CALCULATED MODULE HASH: 3fe78abfc13f00d09fd2b2483e4dbe61c99b4119d369b2d40044d2965b8ea944

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

This change includes FIPS mode information in the return value of
`OpenSSL_version(OPENSSL_VERSION)`. This will allow consumers of CPython (and
likely other tools or language runtimes) to detect FIPS mode without calling to
an AWS-LC-specific API, which would require either patching or forking the
language or tool in question.
@WillChilds-Klein WillChilds-Klein changed the title Include FIPS mode in OpenSSL_version return value (#1419) Include FIPS mode in OpenSSL_version return value Jul 3, 2024
@WillChilds-Klein WillChilds-Klein marked this pull request as ready for review July 3, 2024 15:00
@WillChilds-Klein WillChilds-Klein requested review from a team as code owners July 3, 2024 15:00
torben-hansen
torben-hansen previously approved these changes Jul 3, 2024
darylmartin100
darylmartin100 previously approved these changes Jul 3, 2024
darylmartin100
darylmartin100 previously approved these changes Jul 3, 2024
torben-hansen
torben-hansen previously approved these changes Jul 3, 2024
skmcgrail
skmcgrail previously approved these changes Jul 3, 2024
macOS 11 has [been deprecated][1] by GitHub actions runners.

[1]: actions/runner-images#9255 (comment)
@WillChilds-Klein WillChilds-Klein force-pushed the pr-1419-fips-backport branch from 73e83bf to f61fc60 Compare July 3, 2024 19:26
graebm added a commit to awslabs/aws-c-cal that referenced this pull request Jul 3, 2024
**Issue**:
The libcrypto runtime check isn't working with latest [AWS-LC-FIPS-2.0.13](https://github.com/aws/aws-lc/releases/tag/AWS-LC-FIPS-2.0.13) release. It's not returning the expected version string.

AWS-LC is working on a fix here: aws/aws-lc#1689

**Description of changes:**
This reverts commit 0cdbf2b.

We'll bring this check right back once AWS-LC-FIPS has this fix in its latest release (on Github, and internally at Amazon).

It seems simpler to remove the check entirely, and bring it back once things are working. Vs patching it now, and then patching it again, and then we have all these different versions of aws-lc/aws-c-cal that aren't compatible...
@WillChilds-Klein WillChilds-Klein merged commit ad4b47b into aws:fips-2022-11-02 Jul 3, 2024
7 of 9 checks passed
@WillChilds-Klein WillChilds-Klein deleted the pr-1419-fips-backport branch July 5, 2024 15:21
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.

4 participants