go: TLSv1.3 causes panic on certified FIPS 140-3 linux instances
Using an ubuntu certified AMI (which has a FIPS 140-3 certification), and the latest microsoft/go (v1.24.2 at the time of reporting), operations that require TLSv1.3 cause a panic.
This can be tested with the following program:
package main
import (
"crypto/tls"
"log"
"net/http"
)
func main() {
client := http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
MinVersion: tls.VersionTLS13,
},
},
}
resp, err := client.Get("https://www.google.com")
if err != nil {
panic(err)
}
log.Default().Printf("Request status: %d\n", resp.StatusCode)
}
When executed with GOEXPERIMENT=systemcrypto CGO_ENABLED=1 go run main.go, the following panic occurs:
panic: EVP_KDF_derive
openssl error(s):
error:1C800069:Provider routines::invalid key length
../providers/implementations/kdfs/hkdf.c:163
goroutine 5 [running]:
crypto/tls/internal/tls13.ExpandLabel[...](0xc0000258c8, {0xc0000b4620, 0x20, 0x20}, {0x72c473, 0x2}, {0x0, 0x0, 0x0}, 0xc)
/usr/local/go/src/crypto/tls/internal/tls13/tls13.go:41 +0x27f
crypto/tls.(*cipherSuiteTLS13).trafficKey(0x9b7540, {0xc0000b4620, 0x20, 0x20})
/usr/local/go/src/crypto/tls/key_schedule.go:29 +0x10d
crypto/tls.(*halfConn).setTrafficSecret(0xc000190220, 0x9b7540, 0xc0000b45e0?, {0xc0000b4620?, 0x20?, 0x72e255?})
/usr/local/go/src/crypto/tls/conn.go:234 +0x67
crypto/tls.(*clientHandshakeStateTLS13).establishHandshakeKeys(0xc000025c48)
/usr/local/go/src/crypto/tls/handshake_client_tls13.go:525 +0x374
crypto/tls.(*clientHandshakeStateTLS13).handshake(0xc000025c48)
/usr/local/go/src/crypto/tls/handshake_client_tls13.go:134 +0x73e
crypto/tls.(*Conn).clientHandshake(0xc000190008, {0x7a3c40, 0xc000192000})
/usr/local/go/src/crypto/tls/handshake_client.go:379 +0x810
crypto/tls.(*Conn).handshakeContext(0xc000190008, {0x7a3c40, 0xc0000dc0f0})
/usr/local/go/src/crypto/tls/conn.go:1568 +0x39a
crypto/tls.(*Conn).HandshakeContext(...)
/usr/local/go/src/crypto/tls/conn.go:1508
net/http.(*persistConn).addTLS.func2()
/usr/local/go/src/net/http/transport.go:1703 +0x6e
created by net/http.(*persistConn).addTLS in goroutine 20
/usr/local/go/src/net/http/transport.go:1699 +0x309
exit status 2
Where the key length check from the OpenSSL provider is:
int ossl_kdf_check_keylen(OSSL_LIB_CTX *ctx, size_t len)
{
#if !defined(OPENSSL_NO_FIPS_SECURITYCHECKS)
if (ossl_securitycheck_enabled(ctx))
return len >= 14;
#endif /* OPENSSL_NO_FIPS_SECURITYCHECKS */
return 1;
}
but the nonce length is hard coded to 12 bytes.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 21 (17 by maintainers)
Without it, many modules fail Ubuntu 20.04 22.04 FIPS, Wolfcrypt, and others.
24.04 FIPS is not public yet, but is likely affected too.
The branch is set up to point at what the microsoft/go 1.24 release branch is currently pointing at. By backporting to it (cherry picking or manually, not merging) it’s easier to make sure that a backport won’t destabilize 1.24 by pulling in other changes. We don’t plan to add to it ourselves at the moment, but it’s ready for contributions.
Yep, a git cherry-pick may give you a starting point, but in any case, reapplying the changes onto the support branch and to microsoft/go are the next steps.
Check out
src/internal/goexperiment/flags.goand https://github.com/microsoft/go/blob/microsoft/main/patches/0001-Add-crypto-backend-GOEXPERIMENTs.patch.We expect upstream to make a 1.24.3 release, and if so, we’ll make a 1.24.3-1 release of our repo that incorporates the upstream changes. If all this work is done by then, it’ll make it into 1.24.3-1 because this feature will be sitting in the branch at that time.
(The next upstream release after that is expected June 2.)