Skip to content

Fix cipher property NIDs for SSL_get_current_cipher and add PSK kx mapping#10639

Draft
julek-wolfssl wants to merge 2 commits into
wolfSSL:masterfrom
julek-wolfssl:fix-current-cipher-kx-nid
Draft

Fix cipher property NIDs for SSL_get_current_cipher and add PSK kx mapping#10639
julek-wolfssl wants to merge 2 commits into
wolfSSL:masterfrom
julek-wolfssl:fix-current-cipher-kx-nid

Conversation

@julek-wolfssl

Copy link
Copy Markdown
Member

Description

The cipher property helpers (SSL_CIPHER_get_kx_nid / get_auth_nid /
get_cipher_nid / get_digest_nid / is_aead) parse the cipher name that
GetCipherSegment() looks up via cipher->offset. That offset is only
populated when the cipher is obtained through wolfSSL_get_ciphers_compat()
(SSL_get_ciphers()). When the cipher comes from SSL_get_current_cipher(),
offset is left at 0, so these helpers parsed cipher_names[0] (a TLS 1.3
suite) instead of the negotiated cipher — e.g. returning NID_kx_any for a
plain PSK suite while SSL_CIPHER_get_name() (which uses the suite bytes)
reported the correct name.

Changes

  • GetCipherSegment(): resolve the cipher_names entry from the
    always-populated suite bytes (cipherSuite0 / cipherSuite), falling back to
    cipher->offset when no match is found.
  • wolfSSL_CIPHER_get_kx_nid(): add the missing plain "PSK" -> NID_kx_psk
    entry to the kx lookup table so PSK suites report NID_kx_psk instead of
    NID_undef.
  • Add a regression test that drives the SSL_get_current_cipher() path for
    TLS_PSK_WITH_AES_128_GCM_SHA256 and checks all five property helpers.

Testing

Added an API regression test exercising the SSL_get_current_cipher() path.

…pping

The cipher property helpers (SSL_CIPHER_get_kx_nid / get_auth_nid /
get_cipher_nid / get_digest_nid / is_aead) parse the cipher name looked
up via cipher->offset in GetCipherSegment(). That offset is only
populated when the cipher is obtained through wolfSSL_get_ciphers_compat()
(SSL_get_ciphers()). When the cipher comes from SSL_get_current_cipher(),
offset is left at 0, so these helpers parsed cipher_names[0] (a TLS 1.3
suite) instead of the negotiated cipher - e.g. returning NID_kx_any for a
plain PSK suite while SSL_CIPHER_get_name() (which uses the suite bytes)
reported the correct name.

Resolve the cipher_names entry from the always-populated suite bytes in
GetCipherSegment(), falling back to cipher->offset when no match is found.

Also add the missing plain "PSK" -> NID_kx_psk entry to the kx lookup
table so PSK suites report NID_kx_psk instead of NID_undef.

Add a regression test that drives the SSL_get_current_cipher() path for
TLS_PSK_WITH_AES_128_GCM_SHA256 and checks all five property helpers.
Copilot AI review requested due to automatic review settings June 8, 2026 18:20
@julek-wolfssl julek-wolfssl self-assigned this Jun 8, 2026

Copilot AI left a comment

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.

Pull request overview

This PR fixes OpenSSL-compat cipher property helpers so they report properties for the negotiated cipher when the cipher object comes from SSL_get_current_cipher() (where cipher->offset is not populated). It also corrects PSK key-exchange NID mapping and adds a regression test to cover the SSL_get_current_cipher() path.

Changes:

  • Update GetCipherSegment() to resolve the cipher_names entry using the cipher suite bytes (cipherSuite0/cipherSuite) instead of relying solely on cipher->offset.
  • Add missing "PSK" -> NID_kx_psk mapping in wolfSSL_CIPHER_get_kx_nid().
  • Add an API regression test for TLS_PSK_WITH_AES_128_GCM_SHA256 validating all five cipher property helpers via SSL_get_current_cipher().

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/api.c Adds a regression test covering cipher property helpers when using SSL_get_current_cipher() for a plain PSK suite.
src/ssl.c Adds missing "PSK" entry to the kx-to-NID mapping table.
src/internal.c Makes GetCipherSegment() resolve cipher name table entries via suite bytes to avoid incorrect parsing when offset is unset.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/internal.c
Comment on lines 28750 to 28767
offset = cipher->offset;

/* offset is not set via wolfSSL_get_current_cipher(), so resolve it from
* the always-populated suite bytes. */
for (i = 0; i < GetCipherNamesSize(); i++) {
if (cipher_names[i].cipherSuite0 == cipher->cipherSuite0 &&
cipher_names[i].cipherSuite == cipher->cipherSuite
#ifndef NO_CIPHER_SUITE_ALIASES
&& (!(cipher_names[i].flags & WOLFSSL_CIPHER_SUITE_FLAG_NAMEALIAS))
#endif
) {
offset = (unsigned long)i;
break;
}
}

if (offset >= (unsigned long)GetCipherNamesSize())
return NULL;
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.

2 participants