2015-05-27 09:19:56 -06:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
|
2015-03-25 13:17:47 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014-2015 Intel, Inc. All rights reserved.
|
2015-05-27 09:19:56 -06:00
|
|
|
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
2015-03-25 13:17:47 -07:00
|
|
|
* $COPYRIGHT$
|
2015-06-23 20:59:57 -07:00
|
|
|
*
|
2015-03-25 13:17:47 -07:00
|
|
|
* Additional copyrights may follow
|
2015-06-23 20:59:57 -07:00
|
|
|
*
|
2015-03-25 13:17:47 -07:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "opal_config.h"
|
|
|
|
#include "opal/constants.h"
|
|
|
|
|
|
|
|
#include "opal/mca/mca.h"
|
2015-03-28 20:34:26 -07:00
|
|
|
#include "opal/util/error.h"
|
2015-03-25 13:17:47 -07:00
|
|
|
#include "opal/util/output.h"
|
|
|
|
#include "opal/mca/base/base.h"
|
|
|
|
#include "opal/dss/dss_types.h"
|
|
|
|
|
|
|
|
#include "opal/mca/sec/base/base.h"
|
|
|
|
|
2015-03-28 20:34:26 -07:00
|
|
|
static void cleanup_cred(opal_sec_cred_t *cred)
|
|
|
|
{
|
|
|
|
if (NULL == cred) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (NULL != cred->method) {
|
|
|
|
free(cred->method);
|
2015-05-27 09:19:56 -06:00
|
|
|
cred->method = NULL;
|
2015-03-28 20:34:26 -07:00
|
|
|
}
|
|
|
|
if (NULL != cred->credential) {
|
|
|
|
free(cred->credential);
|
2015-05-27 09:19:56 -06:00
|
|
|
cred->credential = NULL;
|
2015-03-28 20:34:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 13:17:47 -07:00
|
|
|
int opal_sec_base_get_cred(char *method,
|
|
|
|
opal_process_name_t *my_id,
|
2015-03-28 07:59:20 -07:00
|
|
|
char **payload, size_t *size)
|
2015-03-25 13:17:47 -07:00
|
|
|
{
|
|
|
|
opal_sec_handle_t *hdl;
|
2015-03-28 07:59:20 -07:00
|
|
|
opal_sec_cred_t cred;
|
|
|
|
opal_buffer_t buf;
|
2015-03-28 20:34:26 -07:00
|
|
|
int rc;
|
2015-06-23 20:59:57 -07:00
|
|
|
|
2015-03-25 13:17:47 -07:00
|
|
|
opal_output_verbose(5, opal_sec_base_framework.framework_output,
|
|
|
|
"Requesting credential from source %s",
|
|
|
|
(NULL == method) ? "ANY" : method);
|
2015-03-28 07:59:20 -07:00
|
|
|
|
|
|
|
OBJ_CONSTRUCT(&buf, opal_buffer_t);
|
2015-03-25 13:17:47 -07:00
|
|
|
OPAL_LIST_FOREACH(hdl, &opal_sec_base_actives, opal_sec_handle_t) {
|
|
|
|
if (NULL != method && 0 != strcmp(method, hdl->component->mca_component_name)) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-06-18 09:53:20 -07:00
|
|
|
if (OPAL_SUCCESS == hdl->module->get_my_credential(my_id, &cred)) {
|
2015-03-25 13:17:47 -07:00
|
|
|
opal_output_verbose(5, opal_sec_base_framework.framework_output,
|
|
|
|
"Created credential from source %s", hdl->component->mca_component_name);
|
2015-03-28 07:59:20 -07:00
|
|
|
/* pack the credential */
|
2015-03-28 20:34:26 -07:00
|
|
|
if (OPAL_SUCCESS != (rc = opal_dss.pack(&buf, &cred.method, 1, OPAL_STRING))) {
|
|
|
|
OPAL_ERROR_LOG(rc);
|
|
|
|
cleanup_cred(&cred);
|
|
|
|
OBJ_DESTRUCT(&buf);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
if (OPAL_SUCCESS != (rc = opal_dss.pack(&buf, &cred.size, 1, OPAL_SIZE))) {
|
|
|
|
OPAL_ERROR_LOG(rc);
|
|
|
|
cleanup_cred(&cred);
|
|
|
|
OBJ_DESTRUCT(&buf);
|
|
|
|
return rc;
|
2015-03-28 07:59:20 -07:00
|
|
|
}
|
2015-03-28 20:34:26 -07:00
|
|
|
if (0 < cred.size) {
|
|
|
|
if (OPAL_SUCCESS != (rc = opal_dss.pack(&buf, cred.credential, cred.size, OPAL_BYTE))) {
|
|
|
|
OPAL_ERROR_LOG(rc);
|
|
|
|
cleanup_cred(&cred);
|
|
|
|
OBJ_DESTRUCT(&buf);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
opal_output_verbose(5, opal_sec_base_framework.framework_output,
|
|
|
|
"opal_sec: Created credential %s of size %lu",
|
|
|
|
cred.credential, (unsigned long)cred.size);
|
|
|
|
cleanup_cred(&cred);
|
2015-03-25 13:17:47 -07:00
|
|
|
}
|
|
|
|
}
|
2015-03-28 20:34:26 -07:00
|
|
|
if (0 == buf.bytes_used) {
|
|
|
|
OBJ_DESTRUCT(&buf);
|
|
|
|
return OPAL_ERROR;
|
|
|
|
}
|
|
|
|
*payload = buf.base_ptr;
|
|
|
|
*size = buf.bytes_used;
|
|
|
|
buf.base_ptr = NULL;
|
|
|
|
buf.bytes_used = 0;
|
|
|
|
OBJ_DESTRUCT(&buf);
|
|
|
|
return OPAL_SUCCESS;
|
2015-03-25 13:17:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-28 20:34:26 -07:00
|
|
|
int opal_sec_base_validate(char *payload, size_t size, char **method)
|
2015-03-25 13:17:47 -07:00
|
|
|
{
|
|
|
|
opal_sec_handle_t *hdl;
|
2015-03-28 07:59:20 -07:00
|
|
|
opal_buffer_t buf;
|
2015-03-28 20:34:26 -07:00
|
|
|
int cnt, rc;
|
2015-05-27 09:19:56 -06:00
|
|
|
opal_sec_cred_t cred = {.method = NULL, .credential = NULL};
|
2015-06-23 20:59:57 -07:00
|
|
|
|
2015-03-25 13:17:47 -07:00
|
|
|
opal_output_verbose(5, opal_sec_base_framework.framework_output,
|
2015-03-28 20:34:26 -07:00
|
|
|
"opal_sec: Received credential of size %lu",
|
|
|
|
(unsigned long)size);
|
2015-06-23 20:59:57 -07:00
|
|
|
|
2015-03-28 07:59:20 -07:00
|
|
|
OBJ_CONSTRUCT(&buf, opal_buffer_t);
|
2015-03-28 20:34:26 -07:00
|
|
|
opal_dss.load(&buf, payload, size);
|
2015-06-23 20:59:57 -07:00
|
|
|
|
2015-03-28 07:59:20 -07:00
|
|
|
cnt = 1;
|
2015-03-28 20:34:26 -07:00
|
|
|
while (OPAL_SUCCESS == (rc = opal_dss.unpack(&buf, &cred.method, &cnt, OPAL_STRING))) {
|
|
|
|
opal_output_verbose(5, opal_sec_base_framework.framework_output,
|
|
|
|
"Received credential from source %s", cred.method);
|
|
|
|
cnt=1;
|
|
|
|
if (OPAL_SUCCESS != (rc = opal_dss.unpack(&buf, &cred.size, &cnt, OPAL_SIZE))) {
|
|
|
|
OPAL_ERROR_LOG(rc);
|
|
|
|
cleanup_cred(&cred);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
opal_output_verbose(5, opal_sec_base_framework.framework_output,
|
|
|
|
"Received credential of size %lu", (unsigned long)cred.size);
|
|
|
|
if (0 < cred.size) {
|
|
|
|
cred.credential = (char*)malloc(cred.size);
|
|
|
|
cnt=cred.size;
|
|
|
|
if (OPAL_SUCCESS != (rc = opal_dss.unpack(&buf, cred.credential, &cnt, OPAL_BYTE))) {
|
|
|
|
OPAL_ERROR_LOG(rc);
|
|
|
|
cleanup_cred(&cred);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
opal_output_verbose(5, opal_sec_base_framework.framework_output,
|
|
|
|
"Received credential %s", cred.credential);
|
|
|
|
}
|
2015-03-28 07:59:20 -07:00
|
|
|
OPAL_LIST_FOREACH(hdl, &opal_sec_base_actives, opal_sec_handle_t) {
|
2015-03-28 20:34:26 -07:00
|
|
|
if (NULL != cred.method &&
|
|
|
|
0 != strcmp(cred.method, hdl->component->mca_component_name)) {
|
2015-03-28 07:59:20 -07:00
|
|
|
continue;
|
|
|
|
}
|
2015-03-28 20:34:26 -07:00
|
|
|
if (OPAL_SUCCESS == hdl->module->authenticate(&cred)) {
|
|
|
|
rc = OPAL_SUCCESS;
|
|
|
|
/* record the method */
|
|
|
|
if (NULL != method) {
|
|
|
|
if (NULL != *method) {
|
|
|
|
free(*method);
|
|
|
|
}
|
|
|
|
*method = strdup(cred.method);
|
|
|
|
}
|
|
|
|
cleanup_cred(&cred);
|
|
|
|
goto done;
|
2015-03-28 07:59:20 -07:00
|
|
|
}
|
2015-03-25 13:17:47 -07:00
|
|
|
}
|
2015-03-28 20:34:26 -07:00
|
|
|
cleanup_cred(&cred);
|
2015-03-28 07:59:20 -07:00
|
|
|
cnt = 1;
|
2015-03-25 13:17:47 -07:00
|
|
|
}
|
2015-03-28 20:34:26 -07:00
|
|
|
/* if we get here, then nothing authenticated */
|
|
|
|
rc = OPAL_ERR_AUTHENTICATION_FAILED;
|
2015-06-23 20:59:57 -07:00
|
|
|
|
2015-03-28 20:34:26 -07:00
|
|
|
done:
|
2015-03-28 07:59:20 -07:00
|
|
|
buf.base_ptr = NULL;
|
|
|
|
OBJ_DESTRUCT(&buf);
|
2015-03-28 20:34:26 -07:00
|
|
|
return rc;
|
2015-03-25 13:17:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|