|
|
8ad293 |
From b8800d3e1b43f2eb28b2df7adb2bcb323bf2d1f1 Mon Sep 17 00:00:00 2001
|
|
|
8ad293 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
8ad293 |
Date: Sat, 14 Nov 2020 17:52:35 +0100
|
|
|
8ad293 |
Subject: [PATCH 15/16] pam_sss: add certificate label to reply to pam_sss
|
|
|
8ad293 |
|
|
|
8ad293 |
Add the certificate label to the data send back and forth to the pam
|
|
|
8ad293 |
module to avoid the ambiguity if two certificates use the same key.
|
|
|
8ad293 |
|
|
|
8ad293 |
Resolves: https://github.com/SSSD/sssd/issues/5400
|
|
|
8ad293 |
|
|
|
8ad293 |
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
|
|
|
8ad293 |
---
|
|
|
8ad293 |
src/responder/pam/pamsrv_p11.c | 13 ++++++++++---
|
|
|
8ad293 |
src/sss_client/pam_sss.c | 15 +++++++++++++++
|
|
|
8ad293 |
src/tests/cmocka/test_pam_srv.c | 20 ++++++++++++++++----
|
|
|
8ad293 |
3 files changed, 41 insertions(+), 7 deletions(-)
|
|
|
8ad293 |
|
|
|
8ad293 |
diff --git a/src/responder/pam/pamsrv_p11.c b/src/responder/pam/pamsrv_p11.c
|
|
|
8ad293 |
index 23f94927a..e1fd72e64 100644
|
|
|
8ad293 |
--- a/src/responder/pam/pamsrv_p11.c
|
|
|
8ad293 |
+++ b/src/responder/pam/pamsrv_p11.c
|
|
|
8ad293 |
@@ -1086,11 +1086,13 @@ static errno_t pack_cert_data(TALLOC_CTX *mem_ctx, const char *sysdb_username,
|
|
|
8ad293 |
const char *token_name;
|
|
|
8ad293 |
const char *module_name;
|
|
|
8ad293 |
const char *key_id;
|
|
|
8ad293 |
+ const char *label;
|
|
|
8ad293 |
char *prompt;
|
|
|
8ad293 |
size_t user_len;
|
|
|
8ad293 |
size_t token_len;
|
|
|
8ad293 |
size_t module_len;
|
|
|
8ad293 |
size_t key_id_len;
|
|
|
8ad293 |
+ size_t label_len;
|
|
|
8ad293 |
size_t prompt_len;
|
|
|
8ad293 |
size_t nss_name_len;
|
|
|
8ad293 |
const char *username = "";
|
|
|
8ad293 |
@@ -1113,16 +1115,18 @@ static errno_t pack_cert_data(TALLOC_CTX *mem_ctx, const char *sysdb_username,
|
|
|
8ad293 |
token_name = sss_cai_get_token_name(cert_info);
|
|
|
8ad293 |
module_name = sss_cai_get_module_name(cert_info);
|
|
|
8ad293 |
key_id = sss_cai_get_key_id(cert_info);
|
|
|
8ad293 |
+ label = sss_cai_get_label(cert_info);
|
|
|
8ad293 |
|
|
|
8ad293 |
user_len = strlen(username) + 1;
|
|
|
8ad293 |
token_len = strlen(token_name) + 1;
|
|
|
8ad293 |
module_len = strlen(module_name) + 1;
|
|
|
8ad293 |
key_id_len = strlen(key_id) + 1;
|
|
|
8ad293 |
+ label_len = strlen(label) + 1;
|
|
|
8ad293 |
prompt_len = strlen(prompt) + 1;
|
|
|
8ad293 |
nss_name_len = strlen(nss_username) +1;
|
|
|
8ad293 |
|
|
|
8ad293 |
- msg_len = user_len + token_len + module_len + key_id_len + prompt_len
|
|
|
8ad293 |
- + nss_name_len;
|
|
|
8ad293 |
+ msg_len = user_len + token_len + module_len + key_id_len + label_len
|
|
|
8ad293 |
+ + prompt_len + nss_name_len;
|
|
|
8ad293 |
|
|
|
8ad293 |
msg = talloc_zero_size(mem_ctx, msg_len);
|
|
|
8ad293 |
if (msg == NULL) {
|
|
|
8ad293 |
@@ -1136,8 +1140,11 @@ static errno_t pack_cert_data(TALLOC_CTX *mem_ctx, const char *sysdb_username,
|
|
|
8ad293 |
memcpy(msg + user_len + token_len, module_name, module_len);
|
|
|
8ad293 |
memcpy(msg + user_len + token_len + module_len, key_id, key_id_len);
|
|
|
8ad293 |
memcpy(msg + user_len + token_len + module_len + key_id_len,
|
|
|
8ad293 |
+ label, label_len);
|
|
|
8ad293 |
+ memcpy(msg + user_len + token_len + module_len + key_id_len + label_len,
|
|
|
8ad293 |
prompt, prompt_len);
|
|
|
8ad293 |
- memcpy(msg + user_len + token_len + module_len + key_id_len + prompt_len,
|
|
|
8ad293 |
+ memcpy(msg + user_len + token_len + module_len + key_id_len + label_len
|
|
|
8ad293 |
+ + prompt_len,
|
|
|
8ad293 |
nss_username, nss_name_len);
|
|
|
8ad293 |
talloc_free(prompt);
|
|
|
8ad293 |
|
|
|
8ad293 |
diff --git a/src/sss_client/pam_sss.c b/src/sss_client/pam_sss.c
|
|
|
8ad293 |
index cffbfa770..c539d6de6 100644
|
|
|
8ad293 |
--- a/src/sss_client/pam_sss.c
|
|
|
8ad293 |
+++ b/src/sss_client/pam_sss.c
|
|
|
8ad293 |
@@ -142,6 +142,7 @@ static void free_cai(struct cert_auth_info *cai)
|
|
|
8ad293 |
free(cai->token_name);
|
|
|
8ad293 |
free(cai->module_name);
|
|
|
8ad293 |
free(cai->key_id);
|
|
|
8ad293 |
+ free(cai->label);
|
|
|
8ad293 |
free(cai->prompt_str);
|
|
|
8ad293 |
free(cai->choice_list_id);
|
|
|
8ad293 |
free(cai);
|
|
|
8ad293 |
@@ -936,6 +937,20 @@ static int parse_cert_info(struct pam_items *pi, uint8_t *buf, size_t len,
|
|
|
8ad293 |
goto done;
|
|
|
8ad293 |
}
|
|
|
8ad293 |
|
|
|
8ad293 |
+ cai->label = strdup((char *) &buf[*p + offset]);
|
|
|
8ad293 |
+ if (cai->label == NULL) {
|
|
|
8ad293 |
+ D(("strdup failed"));
|
|
|
8ad293 |
+ ret = ENOMEM;
|
|
|
8ad293 |
+ goto done;
|
|
|
8ad293 |
+ }
|
|
|
8ad293 |
+
|
|
|
8ad293 |
+ offset += strlen(cai->label) + 1;
|
|
|
8ad293 |
+ if (offset >= len) {
|
|
|
8ad293 |
+ D(("Cert message size mismatch"));
|
|
|
8ad293 |
+ ret = EINVAL;
|
|
|
8ad293 |
+ goto done;
|
|
|
8ad293 |
+ }
|
|
|
8ad293 |
+
|
|
|
8ad293 |
cai->prompt_str = strdup((char *) &buf[*p + offset]);
|
|
|
8ad293 |
if (cai->prompt_str == NULL) {
|
|
|
8ad293 |
D(("strdup failed"));
|
|
|
8ad293 |
diff --git a/src/tests/cmocka/test_pam_srv.c b/src/tests/cmocka/test_pam_srv.c
|
|
|
8ad293 |
index cb05042de..5506fbf34 100644
|
|
|
8ad293 |
--- a/src/tests/cmocka/test_pam_srv.c
|
|
|
8ad293 |
+++ b/src/tests/cmocka/test_pam_srv.c
|
|
|
8ad293 |
@@ -62,13 +62,16 @@
|
|
|
8ad293 |
#define TEST_TOKEN_NAME "SSSD Test Token"
|
|
|
8ad293 |
#define TEST_TOKEN2_NAME "SSSD Test Token Number 2"
|
|
|
8ad293 |
#define TEST_KEY_ID "C554C9F82C2A9D58B70921C143304153A8A42F17"
|
|
|
8ad293 |
+#define TEST_LABEL "SSSD test cert 0001"
|
|
|
8ad293 |
#define TEST_MODULE_NAME SOFTHSM2_PATH
|
|
|
8ad293 |
#define TEST_PROMPT "SSSD test cert 0001\nCN=SSSD test cert 0001,OU=SSSD test,O=SSSD"
|
|
|
8ad293 |
#define TEST2_PROMPT "SSSD test cert 0002\nCN=SSSD test cert 0002,OU=SSSD test,O=SSSD"
|
|
|
8ad293 |
#define TEST5_PROMPT "SSSD test cert 0005\nCN=SSSD test cert 0005,OU=SSSD test,O=SSSD"
|
|
|
8ad293 |
|
|
|
8ad293 |
#define TEST2_KEY_ID "5405842D56CF31F0BB025A695C5F3E907051C5B9"
|
|
|
8ad293 |
+#define TEST2_LABEL "SSSD test cert 0002"
|
|
|
8ad293 |
#define TEST5_KEY_ID "1195833C424AB00297F582FC43FFFFAB47A64CC9"
|
|
|
8ad293 |
+#define TEST5_LABEL "SSSD test cert 0005"
|
|
|
8ad293 |
|
|
|
8ad293 |
static char CACHED_AUTH_TIMEOUT_STR[] = "4";
|
|
|
8ad293 |
static const int CACHED_AUTH_TIMEOUT = 4;
|
|
|
8ad293 |
@@ -673,6 +676,7 @@ static int test_pam_cert_check_gdm_smartcard(uint32_t status, uint8_t *body,
|
|
|
8ad293 |
+ sizeof(TEST_TOKEN_NAME)
|
|
|
8ad293 |
+ sizeof(TEST_MODULE_NAME)
|
|
|
8ad293 |
+ sizeof(TEST_KEY_ID)
|
|
|
8ad293 |
+ + sizeof(TEST_LABEL)
|
|
|
8ad293 |
+ sizeof(TEST_PROMPT)
|
|
|
8ad293 |
+ sizeof("pamuser")));
|
|
|
8ad293 |
|
|
|
8ad293 |
@@ -692,6 +696,10 @@ static int test_pam_cert_check_gdm_smartcard(uint32_t status, uint8_t *body,
|
|
|
8ad293 |
assert_string_equal(body + rp, TEST_KEY_ID);
|
|
|
8ad293 |
rp += sizeof(TEST_KEY_ID);
|
|
|
8ad293 |
|
|
|
8ad293 |
+ assert_int_equal(*(body + rp + sizeof(TEST_LABEL) - 1), 0);
|
|
|
8ad293 |
+ assert_string_equal(body + rp, TEST_LABEL);
|
|
|
8ad293 |
+ rp += sizeof(TEST_LABEL);
|
|
|
8ad293 |
+
|
|
|
8ad293 |
assert_int_equal(*(body + rp + sizeof(TEST_PROMPT) - 1), 0);
|
|
|
8ad293 |
assert_string_equal(body + rp, TEST_PROMPT);
|
|
|
8ad293 |
rp += sizeof(TEST_PROMPT);
|
|
|
8ad293 |
@@ -740,6 +748,7 @@ static int test_pam_cert_check_ex(uint32_t status, uint8_t *body, size_t blen,
|
|
|
8ad293 |
TEST_TOKEN_NAME,
|
|
|
8ad293 |
TEST_MODULE_NAME,
|
|
|
8ad293 |
TEST_KEY_ID,
|
|
|
8ad293 |
+ TEST_LABEL,
|
|
|
8ad293 |
TEST_PROMPT,
|
|
|
8ad293 |
NULL,
|
|
|
8ad293 |
NULL };
|
|
|
8ad293 |
@@ -749,6 +758,7 @@ static int test_pam_cert_check_ex(uint32_t status, uint8_t *body, size_t blen,
|
|
|
8ad293 |
TEST_TOKEN_NAME,
|
|
|
8ad293 |
TEST_MODULE_NAME,
|
|
|
8ad293 |
TEST2_KEY_ID,
|
|
|
8ad293 |
+ TEST2_LABEL,
|
|
|
8ad293 |
TEST2_PROMPT,
|
|
|
8ad293 |
NULL,
|
|
|
8ad293 |
NULL };
|
|
|
8ad293 |
@@ -756,10 +766,10 @@ static int test_pam_cert_check_ex(uint32_t status, uint8_t *body, size_t blen,
|
|
|
8ad293 |
assert_int_equal(status, 0);
|
|
|
8ad293 |
|
|
|
8ad293 |
check_strings[0] = name;
|
|
|
8ad293 |
- check_strings[5] = nss_name;
|
|
|
8ad293 |
+ check_strings[6] = nss_name;
|
|
|
8ad293 |
check_len = check_string_array_len(check_strings);
|
|
|
8ad293 |
check2_strings[0] = name;
|
|
|
8ad293 |
- check2_strings[5] = nss_name;
|
|
|
8ad293 |
+ check2_strings[6] = nss_name;
|
|
|
8ad293 |
check2_len = check_string_array_len(check2_strings);
|
|
|
8ad293 |
|
|
|
8ad293 |
|
|
|
8ad293 |
@@ -843,6 +853,7 @@ static int test_pam_cert2_token2_check_ex(uint32_t status, uint8_t *body,
|
|
|
8ad293 |
TEST_TOKEN2_NAME,
|
|
|
8ad293 |
TEST_MODULE_NAME,
|
|
|
8ad293 |
TEST2_KEY_ID,
|
|
|
8ad293 |
+ TEST2_LABEL,
|
|
|
8ad293 |
TEST2_PROMPT,
|
|
|
8ad293 |
NULL,
|
|
|
8ad293 |
NULL };
|
|
|
8ad293 |
@@ -850,7 +861,7 @@ static int test_pam_cert2_token2_check_ex(uint32_t status, uint8_t *body,
|
|
|
8ad293 |
assert_int_equal(status, 0);
|
|
|
8ad293 |
|
|
|
8ad293 |
check2_strings[0] = name;
|
|
|
8ad293 |
- check2_strings[5] = nss_name;
|
|
|
8ad293 |
+ check2_strings[6] = nss_name;
|
|
|
8ad293 |
check2_len = check_string_array_len(check2_strings);
|
|
|
8ad293 |
|
|
|
8ad293 |
SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
|
|
|
8ad293 |
@@ -895,7 +906,7 @@ static int test_pam_cert_X_token_X_check_ex(uint32_t status, uint8_t *body,
|
|
|
8ad293 |
assert_int_equal(status, 0);
|
|
|
8ad293 |
|
|
|
8ad293 |
check_strings[0] = name;
|
|
|
8ad293 |
- check_strings[5] = nss_name;
|
|
|
8ad293 |
+ check_strings[6] = nss_name;
|
|
|
8ad293 |
check_len = check_string_array_len(check_strings);
|
|
|
8ad293 |
|
|
|
8ad293 |
SAFEALIGN_COPY_UINT32(&val, body + rp, &rp);
|
|
|
8ad293 |
@@ -946,6 +957,7 @@ static int test_pam_cert5_check(uint32_t status, uint8_t *body, size_t blen)
|
|
|
8ad293 |
TEST_TOKEN_NAME,
|
|
|
8ad293 |
TEST_MODULE_NAME,
|
|
|
8ad293 |
TEST5_KEY_ID,
|
|
|
8ad293 |
+ TEST5_LABEL,
|
|
|
8ad293 |
TEST5_PROMPT,
|
|
|
8ad293 |
NULL,
|
|
|
8ad293 |
NULL };
|
|
|
8ad293 |
--
|
|
|
8ad293 |
2.21.3
|
|
|
8ad293 |
|