@@ -8236,6 +8236,75 @@ int wolfSSL_set_session_secret_cb(WOLFSSL* ssl, SessionSecretCb cb, void* ctx)
82368236 return WOLFSSL_SUCCESS;
82378237}
82388238
8239+ int wolfSSL_set_secret_cb(WOLFSSL* ssl, TlsSecretCb cb, void* ctx)
8240+ {
8241+ WOLFSSL_ENTER("wolfSSL_set_secret_cb");
8242+ if (ssl == NULL)
8243+ return WOLFSSL_FATAL_ERROR;
8244+
8245+ ssl->tlsSecretCb = cb;
8246+ ssl->tlsSecretCtx = ctx;
8247+
8248+ return WOLFSSL_SUCCESS;
8249+ }
8250+
8251+ #ifdef SHOW_SECRETS
8252+ int tlsShowSecrets(WOLFSSL* ssl, void* secret, int secretSz,
8253+ void* ctx)
8254+ {
8255+ /* Wireshark Pre-Master-Secret Format:
8256+ * CLIENT_RANDOM <clientrandom> <mastersecret>
8257+ */
8258+ const char* CLIENT_RANDOM_LABEL = "CLIENT_RANDOM";
8259+ int i, pmsPos = 0;
8260+ char pmsBuf[13 + 1 + 64 + 1 + 96 + 1 + 1];
8261+ byte clientRandom[RAN_LEN];
8262+ int clientRandomSz;
8263+
8264+ (void)ctx;
8265+
8266+ clientRandomSz = (int)wolfSSL_get_client_random(ssl, clientRandom,
8267+ sizeof(clientRandom));
8268+
8269+ if (clientRandomSz <= 0) {
8270+ printf("Error getting server random %d\n", clientRandomSz);
8271+ return BAD_FUNC_ARG;
8272+ }
8273+
8274+ XSNPRINTF(&pmsBuf[pmsPos], sizeof(pmsBuf) - pmsPos, "%s ",
8275+ CLIENT_RANDOM_LABEL);
8276+ pmsPos += XSTRLEN(CLIENT_RANDOM_LABEL) + 1;
8277+ for (i = 0; i < clientRandomSz; i++) {
8278+ XSNPRINTF(&pmsBuf[pmsPos], sizeof(pmsBuf) - pmsPos, "%02x",
8279+ clientRandom[i]);
8280+ pmsPos += 2;
8281+ }
8282+ XSNPRINTF(&pmsBuf[pmsPos], sizeof(pmsBuf) - pmsPos, " ");
8283+ pmsPos += 1;
8284+ for (i = 0; i < secretSz; i++) {
8285+ XSNPRINTF(&pmsBuf[pmsPos], sizeof(pmsBuf) - pmsPos, "%02x",
8286+ ((byte*)secret)[i]);
8287+ pmsPos += 2;
8288+ }
8289+ XSNPRINTF(&pmsBuf[pmsPos], sizeof(pmsBuf) - pmsPos, "\n");
8290+ pmsPos += 1;
8291+
8292+ /* print master secret */
8293+ puts(pmsBuf);
8294+
8295+ #if !defined(NO_FILESYSTEM) && defined(WOLFSSL_SSLKEYLOGFILE)
8296+ {
8297+ FILE* f = XFOPEN(WOLFSSL_SSLKEYLOGFILE_OUTPUT, "a");
8298+ if (f != XBADFILE) {
8299+ XFWRITE(pmsBuf, 1, pmsPos, f);
8300+ XFCLOSE(f);
8301+ }
8302+ }
8303+ #endif
8304+ return 0;
8305+ }
8306+ #endif /* SHOW_SECRETS */
8307+
82398308#endif
82408309
82418310
0 commit comments