static std::mutex sEDCSAContextsMutex;
void* DCM_HWGetKeyContext(const char* service, const char* usage, const char* keytype) {
-#ifdef USE_DLOG_LOGGING
- LOGD("Create new context for");
-#endif
-
try {
std::unique_ptr<dcm_key_context_internal> context(new dcm_key_context_internal());
return nullptr;
}
+ return context.release();
+ } catch(std::exception& ex) {
#ifdef USE_DLOG_LOGGING
- LOGD("Created context %p", context.get());
+ LOGE("Context creation failure: %s", ex.what());
#endif
-
- return context.release();
+ return nullptr;
} catch(...) {
#ifdef USE_DLOG_LOGGING
LOGE("Context creation failure");
return HWIF_ERR_INVALID_PARAM;
}
-#ifdef USE_DLOG_LOGGING
- LOGD("Delete context %p", keyContext);
-#endif
-
delete reinterpret_cast<dcm_key_context_internal *>(keyContext);
return HWIF_SUCCESS;
return HWIF_ERR_INVALID_PARAM;
}
-#ifdef USE_DLOG_LOGGING
- LOGD("Request certificate chain for session %p", keyContext);
-#endif
-
if(!context->cached_cert_chain.empty()) {
-#ifdef USE_DLOG_LOGGING
- LOGD("Use cached certificate chain");
-#endif
-
*cert_chain = &context->cached_cert_chain[0];
*cert_chain_len = context->cached_cert_chain.size();
return HWIF_SUCCESS;
}
if(mode != MBEDTLS_RSA_PRIVATE) {
+#ifdef USE_DLOG_LOGGING
+ LOGE("Signing mode must be RSA_PRIVATE");
+#endif
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
}
return HWIF_ERR_INVALID_PARAM;
}
-#ifdef USE_DLOG_LOGGING
- LOGD("Setup PK context %p with key context %p", ctx, key_context);
-#endif
-
const auto& key_type(context->connection->key_type());
if(key_type == "RSA") {
#include <google/protobuf/io/coded_stream.h>
#include <protobuf_asio.h>
#include <inttypes.h>
+
#ifdef USE_DLOG_LOGGING
#define LOG_TAG "dcm-client"
#include <dlog.h>
dcm_client_connection::dcm_client_connection()
{
-#ifdef USE_DLOG_LOGGING
- LOGD("dcm_client_connection: Allocated new client connection at %p", this);
-#endif
}
dcm_client_connection::~dcm_client_connection()
{
-#ifdef USE_DLOG_LOGGING
- LOGD("dcm_client_connection: Deallocated client connection at %p", this);
-#endif
}
std::shared_ptr<dcm_client_connection> dcm_client_connection::create()
void dcm_client_connection_impl::sendReceive(RequestMessage& request, ResponseMessage& response)
{
-#ifdef USE_DLOG_LOGGING
- LOGD("Send request to server in connection %p of type %d", this, request.request_oneof_case());
-#endif
-
protobuf_sync_message_serialization(*fSocket).encodeMessage(request);
-
protobuf_sync_message_deserialization(*fSocket).decodeMessage(response);
-
-#ifdef USE_DLOG_LOGGING
- LOGD("Received response from server in connection %p of type %d", this, response.reply_oneof_case());
-#endif
}
bool dcm_client_connection_impl::create_context(const std::string& serviceName,
}
if(!fSocket) {
-#ifdef USE_DLOG_LOGGING
- LOGD("%s: Ensure that socket is connected for session %p", __FUNCTION__, this);
-#endif
try {
ensureSocketConnected();
} catch(std::exception& ex) {
}
}
-#ifdef USE_DLOG_LOGGING
- LOGD("%s: Connection established. Requesting cookie", __FUNCTION__);
-#endif
-
try {
RequestMessage request;
ResponseMessage response;
fCookie = assoc_message.context_cookie();
fKeyType = assoc_message.key_type();
fKeyLength = assoc_message.key_length();
-
-#ifdef USE_DLOG_LOGGING
- LOGD("%s: Received cookie %" PRIx64 " with key type %s and length %zd for session %p",
- __FUNCTION__,
- fCookie,
- this->key_type().c_str(),
- fKeyLength,
- this);
-#endif
} catch(std::exception& ex) {
#ifdef USE_DLOG_LOGGING
LOGE("%s: Caught exception \"%s\" when establishing cookie for session %p", __FUNCTION__, ex.what(), this);
return HWIF_ERR_INVALID_PARAM;
}
-#ifdef USE_DLOG_LOGGING
- LOGD("%s: Requesting certificate chain for session %p", __FUNCTION__, this);
-#endif
-
try {
RequestMessage request;
ResponseMessage response;
// Pad with zero
chain.push_back(0);
}
-
-#ifdef USE_DLOG_LOGGING
- LOGD("%s: Received %zd bytes of certificate for session %p", __FUNCTION__, cert_resp.cert_chain().size(), this);
-#endif
} catch(std::bad_alloc&) {
#ifdef USE_DLOG_LOGGING
LOGE("%s: Out of memory when requesting certificate for session %p", __FUNCTION__, this);
if(!fCookie) {
#ifdef USE_DLOG_LOGGING
- LOGD("%s: Trying to request data signing in object %p but there is no connection", __FUNCTION__);
+ LOGE("%s: Trying to request data signing in object %p but there is no connection", __FUNCTION__);
#endif
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
}
if(hash_size == 0) {
if(digestType == MBEDTLS_MD_NONE) {
#ifdef USE_DLOG_LOGGING
- LOGD("%s: Digest type is NONE and hash size is 0", __FUNCTION__);
+ LOGE("%s: Digest type is NONE and hash size is 0", __FUNCTION__);
#endif
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
}
if(!md_info) {
#ifdef USE_DLOG_LOGGING
- LOGD("%s: Can't find hash data for digest type %d", __FUNCTION__, digestType);
+ LOGE("%s: Can't find hash data for digest type %d", __FUNCTION__, digestType);
#endif
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
}
-#ifdef USE_DLOG_LOGGING
- LOGD("%s: Overriding hash size to %zd bytes", __FUNCTION__, hash_size);
-#endif
hash_size = mbedtls_md_get_size(md_info);
} else if(hash_size != 0 && digestType != MBEDTLS_MD_NONE) {
/*
if(!md_info) {
#ifdef USE_DLOG_LOGGING
- LOGD("%s: Can't find hash data for digest type %d", __FUNCTION__, digestType);
+ LOGE("%s: Can't find hash data for digest type %d", __FUNCTION__, digestType);
#endif
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
}
if(!response.has_sign_data()) {
#ifdef USE_DLOG_LOGGING
- LOGD("%s: Response for hash signature has no signature data", __FUNCTION__);
+ LOGE("%s: Response for hash signature has no signature data", __FUNCTION__);
#endif
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
}
digest.resize(signature.size());
memcpy(&digest[0], signature.c_str(), signature.size());
-
-#ifdef USE_DLOG_LOGGING
- LOGD("%s: Received %zd bytes of signed object for session %p", __FUNCTION__, signature.size(), this);
-#endif
} catch(std::bad_alloc&) {
#ifdef USE_DLOG_LOGGING
LOGE("%s: Out of memory when processing sign request for session %p", __FUNCTION__, this);