+/* *****************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * *****************************************************************/
#include "utils.h"
#include "logger.h"
#include <unistd.h>
#include <fcntl.h>
-#define TAG "CLOUD-CSR"
+#define TAG "OIC_CLOUD_CSR"
//TODO: is it required in CSR response?
-static OCByteString privateKey = {0, 0};
+static OCByteString g_privateKey = {0, 0};
#define MAX_URI_QUERY MAX_URI_LENGTH + MAX_QUERY_LENGTH
OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
return -1;
}
- privateKey.bytes = (uint8_t *)OICMalloc(ret * sizeof(char));
- if (NULL == privateKey.bytes)
+ g_privateKey.bytes = (uint8_t *)OICMalloc(ret * sizeof(char));
+ if (NULL == g_privateKey.bytes)
{
- OIC_LOG(ERROR, TAG, "OICMalloc returned NULL on privateKey.bytes allocation");
+ OIC_LOG(ERROR, TAG, "OICMalloc returned NULL on g_privateKey.bytes allocation");
OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
return -1;
}
- memcpy(privateKey.bytes, buf + bufsize - ret, ret * sizeof(uint8_t));
- privateKey.len = ret;
+ memcpy(g_privateKey.bytes, buf + bufsize - ret, ret * sizeof(uint8_t));
+ g_privateKey.len = ret;
// Public key to output
ret = mbedtls_pk_write_pubkey_der(key, buf, bufsize);
if (ret < 0)
{
OicSecKey_t key =
{
- privateKey.bytes,
- privateKey.len,
+ g_privateKey.bytes,
+ g_privateKey.len,
OIC_ENCODING_DER
};
- OicSecCert_t cert1 =
- {
- cert.data,
- cert.len,
- };
-
uint16_t credId;
- result = SRPSaveOwnCertChain(&cert1, &key, &credId);
+ result = SRPSaveOwnCertChain(&cert, &key, &credId);
if (result != OC_STACK_OK)
{
- OIC_LOG(ERROR, TAG, "Cann't add cert");
+ OIC_LOG(ERROR, TAG, "Can't add cert");
}
}
if (!OCRepPayloadGetPropPubDataType((OCRepPayload *)response->payload,
OC_RSRVD_CACERT, &caCert))
{
- OIC_LOG_V(ERROR, TAG, "Cann't get: %s", OC_RSRVD_CACERT);
+ OIC_LOG_V(ERROR, TAG, "Can't get: %s", OC_RSRVD_CACERT);
result = OC_STACK_ERROR;
}
else
}
}
- OICFree(privateKey.bytes);
- privateKey.bytes = NULL;
- privateKey.len = 0;
+ OICClearMemory(g_privateKey.bytes, g_privateKey.len);
+ OICFree(g_privateKey.bytes);
+ g_privateKey.bytes = NULL;
+ g_privateKey.len = 0;
OIC_LOG_V(DEBUG, TAG, "OUT: %s", __func__);
OIC_LOG_V(DEBUG, TAG, "Certificate Request subject: %s", subject);
- OCByteString request;
+ OCByteString request = {0};
if (0 != GenerateCSR(subject, &request))
{
OIC_LOG(ERROR, TAG, "Cann't get the sertificate request");
OIC_LOG_BUFFER(DEBUG, TAG, request.bytes, request.len);
OIC_LOG(DEBUG, TAG, "Private Key:");
- OIC_LOG_BUFFER(DEBUG, TAG, privateKey.bytes, privateKey.len);
+ OIC_LOG_BUFFER(DEBUG, TAG, g_privateKey.bytes, g_privateKey.len);
OCRepPayload* payload = OCRepPayloadCreate();
if (!payload)