Closed qmuntal closed 1 month ago
I've dug a bit more here. Azure Linux 3 sets the SymCrypt provider as the default provider, but still loads and activates the built-in provider so that the algorithms not supported by SymCrypt are automatically routed to the built-in provider. The SymCrypt provider doesn't announce SHA224 support, so when fetching its implementation we get it from the built-in provider. The SymCrypt provider does announce support from HMAC, but the OpenSSL fetching mechanism doesn't allow to specify the digest here, so we get the implementation from SymCrypt, which doesn't support HMAC-SHA224.
This causes the following situation:
We think that we can support a given digest, but in reality we don't, so the implemented short-circuit doesn't detect this case:
https://github.com/golang-fips/openssl/blob/f8eea431f613cac3064280dbb97d9ce1a39de973/hmac.go#L25-L30
When initializing the HMAC algorithm, the SymCrypt provider returns an error and we panic:
The
hmac.New
function falls back to Go crypto when it is called with a hash function not supported by BoringCrypto's HMAC implementation. This is is signaled by making the bindings return a nil hasher: https://github.com/golang/go/blob/fc9f02c7aec81bcfcc95434d2529e0bb0bc03d66/src/crypto/hmac/hmac.go#L135We tried to replicate the same behavior in
openssl.NewHMAC
:https://github.com/golang-fips/openssl/blob/f8eea431f613cac3064280dbb97d9ce1a39de973/hmac.go#L25-L30
The problem is that some OpenSSL providers return a valid hasher that can't be used as a HMAC hasher. An example is the SymCrypt-OpenSSL provider, which doesn't implement HMAC-SHA224 (see test failure below).
We should instruct
openssl.NewHMAC
to return a nil HMAC object when that happens.