Commit 70db11b9 authored by Kishen Maloor's avatar Kishen Maloor

oc_cred and oc_roles: minor fixes

Change-Id: I2eba6d40736074029a3843e5e71909e2e45a1c1f
Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/27881
parent fda0265b
......@@ -219,6 +219,8 @@ void
oc_sec_cred_default(size_t device)
{
oc_sec_clear_creds(device);
memset(devices[device].rowneruuid.id, 0, 16);
oc_sec_dump_cred(device);
}
void
......@@ -496,7 +498,7 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client,
else if (kp) {
oc_new_string(&cred->privatedata.data, (const char *)kp->private_key,
kp->private_key_size);
cred->privatedata.encoding = OC_ENCODING_DER;
cred->privatedata.encoding = OC_ENCODING_RAW;
}
#endif /* OC_PKI */
......@@ -531,7 +533,7 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client,
oc_tls_refresh_trust_anchors();
}
#if defined(OC_PKI) && defined(OC_CLIENT)
if (!roles_resource && credusage == OC_CREDUSAGE_ROLE_CERT) {
if (!roles_resource && credusage == OC_CREDUSAGE_ROLE_CERT && role) {
oc_sec_add_role_cred(role, authority);
}
#endif /* OC_PKI && OC_CLIENT */
......@@ -697,6 +699,8 @@ oc_sec_encode_cred(bool persist, size_t device)
return_encoding_string(cr->privatedata.encoding);
if (encoding_string) {
oc_rep_set_text_string(privatedata, encoding, encoding_string);
} else {
oc_rep_set_text_string(privatedata, encoding, "oic.sec.encoding.raw");
}
oc_rep_close_object(creds, privatedata);
#ifdef OC_PKI
......
......@@ -221,7 +221,7 @@ pki_add_identity_cert(size_t device, const unsigned char *cert,
int credid = oc_sec_add_new_cred(
device, false, NULL, -1, OC_CREDTYPE_CERT, credusage,
oc_string(subjectuuid), OC_ENCODING_DER, private_key_size,
oc_string(subjectuuid), OC_ENCODING_RAW, private_key_size,
privkbuf + (200 - private_key_size), OC_ENCODING_DER, cert1.raw.len,
cert1.raw.p, NULL, NULL);
......
......@@ -52,12 +52,12 @@ find_role_cred(const char *role, const char *authority)
{
oc_role_t *role_cred = (oc_role_t *)oc_list_head(role_creds);
size_t role_len = strlen(role);
size_t authority_len = strlen(authority);
size_t authority_len = (authority ? strlen(authority) : 0);
while (role_cred) {
if ((oc_string_len(role_cred->role) == role_len) &&
(memcmp(oc_string(role_cred->role), role, role_len) == 0)) {
if ((oc_string_len(role_cred->authority) == authority_len) &&
if (authority && (oc_string_len(role_cred->authority) == authority_len) &&
(memcmp(oc_string(role_cred->authority), authority, authority_len) ==
0)) {
return role_cred;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment