Skip to content

Commit cca7995

Browse files
rluboskrish2718
authored andcommitted
[nrf fromtree] net: lib: tls_credentials: Rename TLS_CREDENTIAL_SERVER_CERTIFICATE
TLS_CREDENTIAL_SERVER_CERTIFICATE credential type is misleading, as in fact it just represents a public certificate, it does not matter if the certificate belongs to a server or a client. And actually, it was already used in-tree for clients as well, for example in LwM2M. Therefore rename the credential type to a more generic TLS_CREDENTIAL_PUBLIC_CERTIFICATE and deprecate the old one. Signed-off-by: Robert Lubos <[email protected]> (cherry picked from commit a61287e)
1 parent 6b778f3 commit cca7995

File tree

19 files changed

+42
-31
lines changed

19 files changed

+42
-31
lines changed

doc/connectivity/networking/api/sockets.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ socket options.
9393
The following TLS credential types can be registered in the system:
9494

9595
- ``TLS_CREDENTIAL_CA_CERTIFICATE``
96-
- ``TLS_CREDENTIAL_SERVER_CERTIFICATE``
96+
- ``TLS_CREDENTIAL_PUBLIC_CERTIFICATE``
9797
- ``TLS_CREDENTIAL_PRIVATE_KEY``
9898
- ``TLS_CREDENTIAL_PSK``
9999
- ``TLS_CREDENTIAL_PSK_ID``

doc/releases/migration-guide-4.2.rst

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ Networking
7272
(because the addr is not a pointer) and must be changed to ``if (lladdr->len == 0)``
7373
if the code wants to check that the link address is not set.
7474

75+
* TLS credential type ``TLS_CREDENTIAL_SERVER_CERTIFICATE`` was renamed to
76+
more generic :c:enumerator:`TLS_CREDENTIAL_PUBLIC_CERTIFICATE` to better
77+
reflect the purpose of this credential type.
78+
7579
SPI
7680
===
7781

doc/releases/release-notes-4.2.rst

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ Deprecated APIs and options
5757
renamed and deprecated. Use :kconfig:option:`CONFIG_SCHED_SIMPLE` and
5858
:kconfig:option:`CONFIG_WAITQ_SIMPLE` instead.
5959

60+
* TLS credential type ``TLS_CREDENTIAL_SERVER_CERTIFICATE`` was renamed and
61+
deprecated, use :c:enumerator:`TLS_CREDENTIAL_PUBLIC_CERTIFICATE` instead.
62+
6063
===========================
6164

6265
New APIs and options

drivers/wifi/eswifi/eswifi_socket_offload.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static int map_credentials(int sd, const void *optval, socklen_t optlen)
191191
case TLS_CREDENTIAL_CA_CERTIFICATE:
192192
id = 0;
193193
break;
194-
case TLS_CREDENTIAL_SERVER_CERTIFICATE:
194+
case TLS_CREDENTIAL_PUBLIC_CERTIFICATE:
195195
id = 1;
196196
break;
197197
case TLS_CREDENTIAL_PRIVATE_KEY:

drivers/wifi/simplelink/simplelink_sockets.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ static int map_credentials(int sd, const void *optval, socklen_t optlen)
674674
case TLS_CREDENTIAL_CA_CERTIFICATE:
675675
opt = SL_SO_SECURE_FILES_CA_FILE_NAME;
676676
break;
677-
case TLS_CREDENTIAL_SERVER_CERTIFICATE:
677+
case TLS_CREDENTIAL_PUBLIC_CERTIFICATE:
678678
opt = SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME;
679679
break;
680680
case TLS_CREDENTIAL_PRIVATE_KEY:

include/zephyr/net/tls_credentials.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ enum tls_credential_type {
3636
*/
3737
TLS_CREDENTIAL_CA_CERTIFICATE,
3838

39-
/** A public server certificate. Use this to register your own server
39+
/** A public client or server certificate. Use this to register your own
4040
* certificate. Should be registered together with a corresponding
4141
* private key. Used with certificate-based ciphersuites.
4242
*/
43-
TLS_CREDENTIAL_SERVER_CERTIFICATE,
43+
TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
44+
45+
/** @deprecated Use TLS_CREDENTIAL_PUBLIC_CERTIFICATE instead.
46+
*/
47+
TLS_CREDENTIAL_SERVER_CERTIFICATE = TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
4448

4549
/** Private key. Should be registered together with a corresponding
4650
* public certificate. Used with certificate-based ciphersuites.
@@ -64,7 +68,7 @@ enum tls_credential_type {
6468
* in the system.
6569
*
6670
* @note Some TLS credentials come in pairs:
67-
* - TLS_CREDENTIAL_SERVER_CERTIFICATE with TLS_CREDENTIAL_PRIVATE_KEY,
71+
* - TLS_CREDENTIAL_PUBLIC_CERTIFICATE with TLS_CREDENTIAL_PRIVATE_KEY,
6872
* - TLS_CREDENTIAL_PSK with TLS_CREDENTIAL_PSK_ID.
6973
* Such pairs of credentials must be assigned the same secure tag to be
7074
* correctly handled in the system.

modules/thrift/src/thrift/transport/TSSLSocket.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ void TSSLSocketFactory::loadCertificateFromBuffer(const char *aCertificate, cons
450450

451451
if (strcmp(format, "PEM") == 0) {
452452
const int status = tls_credential_add(Thrift_TLS_SERVER_CERT_TAG,
453-
TLS_CREDENTIAL_SERVER_CERTIFICATE,
453+
TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
454454
aCertificate, strlen(aCertificate) + 1);
455455

456456
if (status != 0) {

samples/net/prometheus/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static void setup_tls(void)
120120
}
121121
#endif /* defined(CONFIG_NET_SAMPLE_CERTS_WITH_SC) */
122122

123-
err = tls_credential_add(HTTP_SERVER_CERTIFICATE_TAG, TLS_CREDENTIAL_SERVER_CERTIFICATE,
123+
err = tls_credential_add(HTTP_SERVER_CERTIFICATE_TAG, TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
124124
server_certificate, sizeof(server_certificate));
125125
if (err < 0) {
126126
LOG_ERR("Failed to register public certificate: %d", err);

samples/net/sockets/dumb_http_server_mt/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ int main(void)
413413
{
414414
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
415415
int err = tls_credential_add(SERVER_CERTIFICATE_TAG,
416-
TLS_CREDENTIAL_SERVER_CERTIFICATE,
416+
TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
417417
server_certificate,
418418
sizeof(server_certificate));
419419
if (err < 0) {

samples/net/sockets/echo_server/src/echo-server.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static void init_app(void)
153153
#endif /* defined(CONFIG_NET_SAMPLE_CERTS_WITH_SC) */
154154

155155
err = tls_credential_add(SERVER_CERTIFICATE_TAG,
156-
TLS_CREDENTIAL_SERVER_CERTIFICATE,
156+
TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
157157
server_certificate,
158158
sizeof(server_certificate));
159159
if (err < 0) {

samples/net/sockets/http_server/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static void setup_tls(void)
312312
int err;
313313

314314
err = tls_credential_add(HTTP_SERVER_CERTIFICATE_TAG,
315-
TLS_CREDENTIAL_SERVER_CERTIFICATE,
315+
TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
316316
server_certificate,
317317
sizeof(server_certificate));
318318
if (err < 0) {

samples/subsys/mgmt/updatehub/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int main(void)
8989

9090
#if defined(CONFIG_UPDATEHUB_DTLS)
9191
if (tls_credential_add(CA_CERTIFICATE_TAG,
92-
TLS_CREDENTIAL_SERVER_CERTIFICATE,
92+
TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
9393
server_certificate,
9494
sizeof(server_certificate)) < 0) {
9595
LOG_ERR("Failed to register server certificate");

subsys/net/lib/lwm2m/lwm2m_engine.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ static void delete_tls_credentials(sec_tag_t tag)
922922
{
923923
tls_credential_delete(tag, TLS_CREDENTIAL_PSK_ID);
924924
tls_credential_delete(tag, TLS_CREDENTIAL_PSK);
925-
tls_credential_delete(tag, TLS_CREDENTIAL_SERVER_CERTIFICATE);
925+
tls_credential_delete(tag, TLS_CREDENTIAL_PUBLIC_CERTIFICATE);
926926
tls_credential_delete(tag, TLS_CREDENTIAL_PRIVATE_KEY);
927927
tls_credential_delete(tag, TLS_CREDENTIAL_CA_CERTIFICATE);
928928
}
@@ -1003,7 +1003,7 @@ static int lwm2m_load_x509_credentials(struct lwm2m_ctx *ctx)
10031003

10041004
delete_tls_credentials(ctx->tls_tag);
10051005

1006-
ret = load_tls_type(ctx, 3, TLS_CREDENTIAL_SERVER_CERTIFICATE);
1006+
ret = load_tls_type(ctx, 3, TLS_CREDENTIAL_PUBLIC_CERTIFICATE);
10071007
if (ret < 0) {
10081008
return ret;
10091009
}

subsys/net/lib/sockets/sockets_tls.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ static int tls_set_credential(struct tls_context *tls,
10781078
case TLS_CREDENTIAL_CA_CERTIFICATE:
10791079
return tls_add_ca_certificate(tls, cred);
10801080

1081-
case TLS_CREDENTIAL_SERVER_CERTIFICATE:
1081+
case TLS_CREDENTIAL_PUBLIC_CERTIFICATE:
10821082
return tls_add_own_cert(tls, cred);
10831083

10841084
case TLS_CREDENTIAL_PRIVATE_KEY:
@@ -1133,7 +1133,7 @@ static int tls_mbedtls_set_credentials(struct tls_context *tls)
11331133

11341134
if (cred->type == TLS_CREDENTIAL_CA_CERTIFICATE) {
11351135
ca_cert_present = true;
1136-
} else if (cred->type == TLS_CREDENTIAL_SERVER_CERTIFICATE) {
1136+
} else if (cred->type == TLS_CREDENTIAL_PUBLIC_CERTIFICATE) {
11371137
own_cert_present = true;
11381138
}
11391139
}

subsys/net/lib/tls_credentials/tls_credentials_shell.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ static const struct cred_type_string type_strings[] = {
4040
{"CA_CERT", TLS_CREDENTIAL_CA_CERTIFICATE},
4141
{"CA", TLS_CREDENTIAL_CA_CERTIFICATE},
4242

43-
{"SERVER_CERT", TLS_CREDENTIAL_SERVER_CERTIFICATE},
44-
{"CLIENT_CERT", TLS_CREDENTIAL_SERVER_CERTIFICATE},
45-
{"SELF_CERT", TLS_CREDENTIAL_SERVER_CERTIFICATE},
46-
{"SELF", TLS_CREDENTIAL_SERVER_CERTIFICATE},
47-
{"CLIENT", TLS_CREDENTIAL_SERVER_CERTIFICATE},
48-
{"SERV", TLS_CREDENTIAL_SERVER_CERTIFICATE},
43+
{"SERVER_CERT", TLS_CREDENTIAL_PUBLIC_CERTIFICATE},
44+
{"CLIENT_CERT", TLS_CREDENTIAL_PUBLIC_CERTIFICATE},
45+
{"SELF_CERT", TLS_CREDENTIAL_PUBLIC_CERTIFICATE},
46+
{"SELF", TLS_CREDENTIAL_PUBLIC_CERTIFICATE},
47+
{"CLIENT", TLS_CREDENTIAL_PUBLIC_CERTIFICATE},
48+
{"SERV", TLS_CREDENTIAL_PUBLIC_CERTIFICATE},
4949

5050
{"PRIVATE_KEY", TLS_CREDENTIAL_PRIVATE_KEY},
5151
{"PK", TLS_CREDENTIAL_PRIVATE_KEY},

tests/net/lib/http_server/tls/src/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static void *setup(void)
239239
zassert_equal(ret, 0, "failed to add CA Certificate (%d)", ret);
240240

241241
ret = tls_credential_add(SERVER_CERTIFICATE_TAG,
242-
TLS_CREDENTIAL_SERVER_CERTIFICATE,
242+
TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
243243
server, sizeof(server));
244244
zassert_equal(ret, 0, "failed to add Server Certificate (%d)", ret);
245245

@@ -249,7 +249,7 @@ static void *setup(void)
249249
zassert_equal(ret, 0, "failed to add Server Private Key (%d)", ret);
250250

251251
ret = tls_credential_add(CLIENT_CERTIFICATE_TAG,
252-
TLS_CREDENTIAL_SERVER_CERTIFICATE,
252+
TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
253253
client, sizeof(client));
254254
zassert_equal(ret, 0, "failed to add Client Certificate (%d)", ret);
255255

tests/net/lib/lwm2m/lwm2m_engine/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ ZTEST(lwm2m_engine, test_security)
467467
zassert_equal(z_impl_zsock_setsockopt_fake.arg2_history[1], TLS_PEER_VERIFY);
468468
zassert_equal(z_impl_zsock_setsockopt_fake.arg2_history[2], TLS_CIPHERSUITE_LIST);
469469
zassert_true(tls_credential_add_fake.call_count == 3);
470-
zassert_equal(tls_credential_add_fake.arg1_history[0], TLS_CREDENTIAL_SERVER_CERTIFICATE);
470+
zassert_equal(tls_credential_add_fake.arg1_history[0], TLS_CREDENTIAL_PUBLIC_CERTIFICATE);
471471
zassert_equal(tls_credential_add_fake.arg1_history[1], TLS_CREDENTIAL_PRIVATE_KEY);
472472
zassert_equal(tls_credential_add_fake.arg1_history[2], TLS_CREDENTIAL_CA_CERTIFICATE);
473473
zassert_equal(lwm2m_engine_stop(&ctx), 0);

tests/net/lib/tls_credentials/src/main.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ static void test_credential_add(void)
3434
/* Function should allow to add credentials of different types
3535
* with the same tag
3636
*/
37-
ret = tls_credential_add(common_tag, TLS_CREDENTIAL_SERVER_CERTIFICATE,
37+
ret = tls_credential_add(common_tag, TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
3838
test_server_cert, sizeof(test_server_cert));
3939
zassert_equal(ret, 0, "Failed to add credential %d %d",
40-
common_tag, TLS_CREDENTIAL_SERVER_CERTIFICATE);
40+
common_tag, TLS_CREDENTIAL_PUBLIC_CERTIFICATE);
4141

4242
ret = tls_credential_add(common_tag, TLS_CREDENTIAL_PRIVATE_KEY,
4343
test_server_key, sizeof(test_server_key));
@@ -87,7 +87,7 @@ static void test_credential_get(void)
8787

8888
/* Try to read with too small buffer */
8989
credlen = sizeof(test_server_cert) - 1;
90-
ret = tls_credential_get(common_tag, TLS_CREDENTIAL_SERVER_CERTIFICATE,
90+
ret = tls_credential_get(common_tag, TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
9191
cred, &credlen);
9292
zassert_equal(ret, -EFBIG, "Should have failed with EFBIG");
9393
}
@@ -121,7 +121,7 @@ static void test_credential_internal_iterate(void)
121121
cert = temp;
122122
}
123123

124-
zassert_equal(cert->type, TLS_CREDENTIAL_SERVER_CERTIFICATE,
124+
zassert_equal(cert->type, TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
125125
"Invalid type for cert");
126126
zassert_equal(cert->tag, common_tag, "Invalid tag for cert");
127127
zassert_equal(cert->len, sizeof(test_server_cert),

tests/net/socket/tls_ext/src/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static void *setup(void)
447447
zassert_equal(r, 0, "failed to add CA Certificate (%d)", r);
448448

449449
r = tls_credential_add(SERVER_CERTIFICATE_TAG,
450-
TLS_CREDENTIAL_SERVER_CERTIFICATE,
450+
TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
451451
server, sizeof(server));
452452
zassert_equal(r, 0, "failed to add Server Certificate (%d)", r);
453453

@@ -457,7 +457,7 @@ static void *setup(void)
457457
zassert_equal(r, 0, "failed to add Server Private Key (%d)", r);
458458

459459
r = tls_credential_add(CLIENT_CERTIFICATE_TAG,
460-
TLS_CREDENTIAL_SERVER_CERTIFICATE,
460+
TLS_CREDENTIAL_PUBLIC_CERTIFICATE,
461461
client, sizeof(client));
462462
zassert_equal(r, 0, "failed to add Client Certificate (%d)", r);
463463

0 commit comments

Comments
 (0)