Skip to content

Fixes for TLS with crypto callbacks#7070

Merged
douzzer merged 13 commits intowolfSSL:masterfrom
dgarske:cryptocb_moreinfo
Dec 27, 2023
Merged

Fixes for TLS with crypto callbacks#7070
douzzer merged 13 commits intowolfSSL:masterfrom
dgarske:cryptocb_moreinfo

Conversation

@dgarske
Copy link
Copy Markdown
Member

@dgarske dgarske commented Dec 14, 2023

Description

  • Fixes for TLS v1.3 with crypto callbacks not offloading KDF / HMAC and DeriveKeyMsg computations.
  • Fix TLS v1.2 case where SHA-1 could be used uninitialized.
  • Exclude the SHA1 struct from HS_Hashes when not needed (fixes mix-match of the SHA-1 with NO_OLD_TLS and WOLFSSL_ALLOW_TLS_SHA1)
  • Fix typo with HMAC determination of update/final in crypto callback.
  • Fix random.c health test to use devId.
  • Added support for using devId with one-shot hash functions.
  • Added more information in the DEBUG_CRYPTOCB.

ZD 17134

Testing

./configure --enable-cryptocb --enable-debug CFLAGS="-DDEBUG_CRYPTOCB"
./configure --enable-cryptocb CFLAGS="-DWOLFSSL_ALLOW_TLS_SHA1"

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@dgarske dgarske self-assigned this Dec 14, 2023
@dgarske dgarske changed the title Add more information to the crypto callback DEBUG_CRYPTOCB Fixes for TLS v1.3 and crypto callbacks Dec 18, 2023
@dgarske dgarske force-pushed the cryptocb_moreinfo branch 3 times, most recently from ed65d74 to 1b3afac Compare December 19, 2023 01:35
… Fix random.c health test to use devId. Fix FIPS unused "ssl".
…e SHA1 struct from HS_Hashes when not needed. Fixes mix-match of the SHA-1 with `NO_OLD_TLS` and `WOLFSSL_ALLOW_TLS_SHA1`.
@dgarske dgarske changed the title Fixes for TLS v1.3 and crypto callbacks Fixes for TLS with crypto callbacks Dec 19, 2023
@dgarske dgarske requested a review from wolfSSL-Bot December 20, 2023 19:52
@dgarske
Copy link
Copy Markdown
Member Author

dgarske commented Dec 20, 2023

Retest this please

@dgarske dgarske removed their assignment Dec 20, 2023
…1 on either old TLS or `WOLFSSL_ALLOW_TLS_SHA1`.
@dgarske dgarske assigned dgarske and unassigned dgarske Dec 21, 2023
Comment thread wolfcrypt/src/cryptocb.c Outdated
Comment on lines +189 to +190
printf("Crypto CB: %s %s (%d) (%p ctx)\n", GetAlgoTypeStr(info->algo_type),
GetCipherTypeStr(info->cipher.type), info->cipher.type, info->cipher.ctx);
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.

line length

Comment thread wolfcrypt/src/cryptocb.c Outdated
else if (info->algo_type == WC_ALGO_TYPE_HASH) {
printf("Crypto CB: %s %s (%d)\n", GetAlgoTypeStr(info->algo_type),
GetHashTypeStr(info->hash.type), info->hash.type);
printf("Crypto CB: %s %s (%d) (%p ctx) %s\n", GetAlgoTypeStr(info->algo_type),
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.

line length

Comment thread wolfcrypt/src/cryptocb.c Outdated
Comment on lines +198 to +199
printf("Crypto CB: %s %s (%d) (%p ctx) %s\n", GetAlgoTypeStr(info->algo_type),
GetHashTypeStr(info->hmac.macType), info->hmac.macType, info->hmac.hmac,
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.

line length

Comment thread src/tls13.c
digestType);
if (ret == 0) {
PRIVATE_KEY_UNLOCK();
ret = Tls13HKDFExpandKeyLabel(ssl,
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.

note this is one of the calls to Tls13HKDFExpandKeyLabel() that happens even in FIPS builds. without the fix at line 241 I see this on fips+all builds:

src/tls13.c: In function ‘EchCheckAcceptance’:
d71e214bb6 (<david@wolfssl.com> 2023-12-18 17:16:54 -0800 4825)         ret = Tls13HKDFExpandKeyLabel(ssl,
src/tls13.c:4825:15: error: implicit declaration of function ‘Tls13HKDFExpandKeyLabel’; did you mean ‘Tls13HKDFExpandLabel’? [-Werror=implicit-function-declaration]
 4825 |         ret = Tls13HKDFExpandKeyLabel(ssl,
      |               ^~~~~~~~~~~~~~~~~~~~~~~
      |               Tls13HKDFExpandLabel

@douzzer douzzer assigned dgarske and unassigned wolfSSL-Bot Dec 22, 2023
Copy link
Copy Markdown
Contributor

@douzzer douzzer left a comment

Choose a reason for hiding this comment

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

The gcc sanitizers, due to multilevel inlining, have managed to figure out that there's something wrong with Tls13DeriveKey() in this PR. It's clean on master so it seems to be new to this PR:

[sp-all-asm-sanitizer] [1 of 1] [59155051bb]
    autogen.sh 59155051bb...   real 0m16.249s  user 0m14.299s  sys 0m1.088s
    configure...   real 0m18.709s  user 0m10.000s  sys 0m10.108s
    build...In function ‘Tls13DeriveKey’,
6190666108 (<anthony@wolfssl.com> 2022-09-21 03:21:33 -0400 1095)     return Tls13DeriveKey(ssl, secret, -1, key, finishedLabel,
    inlined from ‘DeriveFinishedSecret’ at src/tls13.c:1095:12:
6190666108 (<anthony@wolfssl.com> 2022-09-21 03:21:33 -0400 502)     ret = Tls13HKDFExpandKeyLabel(ssl, output, outputLen, secret, hashSz,
src/tls13.c:502:11: error: ‘hash’ may be used uninitialized [-Werror=maybe-uninitialized]
  502 |     ret = Tls13HKDFExpandKeyLabel(ssl, output, outputLen, secret, hashSz,
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  503 |                                   protocol, protocolLen, label, labelLen,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  504 |                                   hash, hashOutSz, digestAlg, side);
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/tls13.c: In function ‘DeriveFinishedSecret’:
6190666108 (<anthony@wolfssl.com> 2022-09-21 03:21:33 -0400 248) static int Tls13HKDFExpandKeyLabel(WOLFSSL* ssl, byte* okm, word32 okmLen,
src/tls13.c:248:12: note: by argument 8 of type ‘const byte *’ {aka ‘const unsigned char *’} to ‘Tls13HKDFExpandKeyLabel.constprop’ declared here
  248 | static int Tls13HKDFExpandKeyLabel(WOLFSSL* ssl, byte* okm, word32 okmLen,
      |            ^~~~~~~~~~~~~~~~~~~~~~~
481f4765eb (<david@wolfssl.com> 2018-01-11 09:52:49 -0800 431)     byte        hash[WC_MAX_DIGEST_SIZE];
src/tls13.c:431:17: note: ‘hash’ declared here
  431 |     byte        hash[WC_MAX_DIGEST_SIZE];
      |                 ^~~~
In function ‘Tls13DeriveKey’,
    inlined from ‘DeriveTrafficSecret’ at src/tls13.c:1116:12,
6190666108 (<anthony@wolfssl.com> 2022-09-21 03:21:33 -0400 1538)                 ret = DeriveTrafficSecret(ssl, ssl->clientSecret,
    inlined from ‘DeriveTls13Keys’ at src/tls13.c:1538:23:
6190666108 (<anthony@wolfssl.com> 2022-09-21 03:21:33 -0400 502)     ret = Tls13HKDFExpandKeyLabel(ssl, output, outputLen, secret, hashSz,
src/tls13.c:502:11: error: ‘hash’ may be used uninitialized [-Werror=maybe-uninitialized]
  502 |     ret = Tls13HKDFExpandKeyLabel(ssl, output, outputLen, secret, hashSz,
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  503 |                                   protocol, protocolLen, label, labelLen,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  504 |                                   hash, hashOutSz, digestAlg, side);
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/tls13.c: In function ‘DeriveTls13Keys’:
6190666108 (<anthony@wolfssl.com> 2022-09-21 03:21:33 -0400 248) static int Tls13HKDFExpandKeyLabel(WOLFSSL* ssl, byte* okm, word32 okmLen,
src/tls13.c:248:12: note: by argument 8 of type ‘const byte *’ {aka ‘const unsigned char *’} to ‘Tls13HKDFExpandKeyLabel.constprop’ declared here
  248 | static int Tls13HKDFExpandKeyLabel(WOLFSSL* ssl, byte* okm, word32 okmLen,
      |            ^~~~~~~~~~~~~~~~~~~~~~~
481f4765eb (<david@wolfssl.com> 2018-01-11 09:52:49 -0800 431)     byte        hash[WC_MAX_DIGEST_SIZE];
src/tls13.c:431:17: note: ‘hash’ declared here
  431 |     byte        hash[WC_MAX_DIGEST_SIZE];
      |                 ^~~~

If I just XMEMSET(hash, 0, sizeof hash) at the start of the function, the sanitizing build and make check are clean. But that shouldn't be necessary -- I'm concerned one of the hash functions isn't writing out the hash value correctly.

@dgarske dgarske requested a review from douzzer December 27, 2023 21:57
Copy link
Copy Markdown
Contributor

@douzzer douzzer left a comment

Choose a reason for hiding this comment

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

LGTM. Passing all the extra tests now. The documentation update looks great!

@dgarske dgarske removed their assignment Dec 27, 2023
@dgarske
Copy link
Copy Markdown
Member Author

dgarske commented Dec 27, 2023

Retest this please

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