I'm using some code from the nrf/samples/net/https_client sample to provision certificates in the nRF9160 modem. The (slightly modified) code looks like so:
int err; bool exists; int mismatch; err = modem_key_mgmt_exists(tag, cred_type_modem, &exists); if (err) { LOG_ERR("Failed to check for modem credential, err %d\n", err); return err; } if (exists) { mismatch = modem_key_mgmt_cmp(tag, cred_type_modem, pem, strlen(pem)); if (!mismatch) { LOG_INF("Modem credential match\n"); return 0; } LOG_INF("Modem credential mismatch\n"); err = modem_key_mgmt_delete(tag, cred_type_modem); if (err) { LOG_ERR("Failed to delete existing modem credential, err %d\n", err); } } /* Provision certificate to the modem */ err = modem_key_mgmt_write(tag, cred_type_modem, pem, strlen(pem) - 1); if (err) { LOG_ERR("Failed to provision modem credential, err %d\n", err); return err; } LOG_INF("Successfully provisioned modem credential");
The modem_key_mgmt_cmp function is throwing a warning though:
<wrn> modem_key_mgmt: Key access refused
I've searched for this error and cannot find any other posts about it. Am I missing a config option of some sort, or otherwise doing something wrong here?
As a separate, unrelated question about the same code: is there any reason why it's using strlen(cert) for the modem_key_mgmt_cmp function (here), but sizeof(cert) - 1 for the modem_key_mgmt_write function (here)? These should return the same length, no?