Be user-friendly when opening a pfx/p12 file

Before this change the user had to provide a password callback, even if the
PKCS#12 encoded file has no or an empty password.

This changes the behavior, so we first try to open the file without a
password and only then ask the user to provide one.

This fixes #204.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel
2022-05-05 16:11:21 +02:00
parent 91d6dac985
commit d8c9ca49e1
6 changed files with 57 additions and 21 deletions

BIN
tests/cert.emptypass.pfx Normal file

Binary file not shown.

BIN
tests/cert.nopass.pfx Normal file

Binary file not shown.

View File

@@ -33,10 +33,15 @@ int main()
xmpp_ctx_t *ctx;
xmpp_conn_t *conn;
xmpp_log_t *log;
char *client_cert[][2] = {
{"tests/cert.pem", "tests/key.pem"},
{"tests/cert.pem", "tests/key_encrypted.pem"},
{NULL, "tests/cert.pfx"},
struct {
int needs_callback;
char *pem, *key;
} client_cert[] = {
{0, "tests/cert.pem", "tests/key.pem"},
{1, "tests/cert.pem", "tests/key_encrypted.pem"},
{0, NULL, "tests/cert.emptypass.pfx"},
{0, NULL, "tests/cert.nopass.pfx"},
{1, NULL, "tests/cert.pfx"},
};
char xmppaddr_num[] = "0";
@@ -49,9 +54,10 @@ int main()
for (m = 0; m < sizeof(client_cert) / sizeof(client_cert[0]); ++m) {
conn = xmpp_conn_new(ctx);
xmpp_conn_set_password_callback(conn, password_callback, NULL);
if (client_cert[m].needs_callback)
xmpp_conn_set_password_callback(conn, password_callback, NULL);
xmpp_conn_set_client_cert(conn, client_cert[m][0], client_cert[m][1]);
xmpp_conn_set_client_cert(conn, client_cert[m].pem, client_cert[m].key);
xmppaddr_num[0] = '0' + xmpp_conn_cert_xmppaddr_num(conn);