in src/oslogin_utils.cc [745:799]
std::vector<string> ParseJsonToSshKeysSk(const string& json) {
std::vector<string> result;
json_object* root = ParseJsonRoot(json);
if (root == NULL) {
return result;
}
// Locate the securityKeys array.
json_object* login_profiles;
if (!json_object_object_get_ex(root, "loginProfiles", &login_profiles)) {
goto cleanup;
}
if (json_object_get_type(login_profiles) != json_type_array) {
goto cleanup;
}
login_profiles = json_object_array_get_idx(login_profiles, 0);
json_object* security_keys;
if (!json_object_object_get_ex(login_profiles, "securityKeys", &security_keys)) {
goto cleanup;
}
if (json_object_get_type(security_keys) != json_type_array) {
goto cleanup;
}
{
size_t number_of_keys = 0;
size_t idx;
json_object* security_key = NULL;
json_object* public_key = NULL;
string key_to_add = "";
number_of_keys = json_object_array_length(security_keys);
for (idx = 0; idx < number_of_keys; idx++) {
security_key = json_object_array_get_idx(security_keys, idx);
if (json_object_get_type(security_key) != json_type_object) {
goto cleanup;
}
if (!json_object_object_get_ex(security_key, "publicKey", &public_key)) {
goto cleanup;
}
key_to_add = json_object_get_string(public_key);
result.push_back(key_to_add);
key_to_add.clear();
}
}
cleanup:
json_object_put(root);
return result;
}