Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in tls_set_credential #23209

Closed
md-jamal opened this issue Mar 3, 2020 · 1 comment
Closed

Bug in tls_set_credential #23209

md-jamal opened this issue Mar 3, 2020 · 1 comment
Assignees
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug

Comments

@md-jamal
Copy link

md-jamal commented Mar 3, 2020

Hi Guys,

This is the code present in subsys/net/lib/sockets/sockets_tls.c

static int tls_set_credential(struct tls_context *tls,
			      struct tls_credential *cred)
{
	switch (cred->type) {
	case TLS_CREDENTIAL_CA_CERTIFICATE:
		return tls_add_ca_certificate(tls, cred);

	case TLS_CREDENTIAL_SERVER_CERTIFICATE:
	{
		struct tls_credential *priv_key =
			credential_get(cred->tag, TLS_CREDENTIAL_PRIVATE_KEY);
		if (!priv_key) {
			return -ENOENT;
		}

		return tls_set_own_cert(tls, cred, priv_key);
	}

	case TLS_CREDENTIAL_PRIVATE_KEY:
		/* Ignore private key - it will be used together
		 * with public certificate
		 */
		break;

Here in this you can see when it tries to set TLS_CREDENTIAL_SERVER_CERTIFICATE, it will always fail with ENOENT, because we are using the tag of TLS_CREDENTIAL_SERVER_CERTIFICATE and type of PRIVATE_KEY.

@md-jamal md-jamal added the bug The issue is a bug, or the PR is fixing a bug label Mar 3, 2020
@rlubos
Copy link
Contributor

rlubos commented Mar 3, 2020

It's not a bug, TLS_CREDENTIAL_SERVER_CERTIFICATE has to be combined with a corresponding TLS_CREDENTIAL_PRIVATE_KEY. Such a pair is sharing the same tag, it's documented here:
https://docs.zephyrproject.org/latest/reference/networking/sockets.html#_CPPv49sec_tag_t
https://docs.zephyrproject.org/latest/reference/networking/sockets.html#_CPPv4N15tls_credentials33TLS_CREDENTIAL_SERVER_CERTIFICATEE

@rlubos rlubos closed this as completed Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

No branches or pull requests

3 participants