diff --git a/activation.h b/activation.h index 714fcf8..fb820ce 100644 --- a/activation.h +++ b/activation.h @@ -8,7 +8,7 @@ #include -#define PROTOCOL_VERSION "4.0.0" +#define PROTOCOL_VERSION "4.1.0" #ifdef _WIN32 #define convertstring to_utf16string diff --git a/main.cpp b/main.cpp index 300268c..6fbf990 100644 --- a/main.cpp +++ b/main.cpp @@ -63,7 +63,7 @@ int main(int argc, char* argv[]) std::string arg_info; bool arg_verbose = false; bool arg_nocertcheck = false; - bool secureHostBasedConfig = false; + bool shbc_config = false; if (argc == 1) { @@ -187,7 +187,7 @@ int main(int argc, char* argv[]) memset(&lms_socket, 0, sizeof(SOCKET)); // set receive handler - client.set_message_handler([&client, &mx, &cv, &lms_socket, arg_verbose, &secureHostBasedConfig](web::websockets::client::websocket_incoming_message ret_msg) + client.set_message_handler([&client, &mx, &cv, &lms_socket, arg_verbose, &shbc_config](web::websockets::client::websocket_incoming_message ret_msg) { // kick the timer std::chrono::time_point now = std::chrono::system_clock::now(); @@ -292,25 +292,21 @@ int main(int argc, char* argv[]) config_host_based_settings amt_cert; server_cert.algorithm = certAlgo; server_cert.hash = certHash; - if (cmd_start_config_host_based(server_cert, amt_cert)) - { - // create the response - std::string response; - if (!shbc_create_response(amt_cert.algorithm, amt_cert.hash, response)) return; + bool sbhc_success = cmd_start_config_host_based(server_cert, amt_cert); + + // create the response + std::string response; + if (!shbc_create_response(amt_cert.algorithm, amt_cert.hash, sbhc_success, response)) return; - // send it - web::websockets::client::websocket_outgoing_message send_websocket_msg; - std::string send_websocket_buffer(response); - send_websocket_msg.set_utf8_message(send_websocket_buffer); - client.send(send_websocket_msg).wait(); - - // use secure host post for LMS going forward - secureHostBasedConfig = true; - - return; - - } + // send it + web::websockets::client::websocket_outgoing_message send_websocket_msg; + std::string send_websocket_buffer(response); + send_websocket_msg.set_utf8_message(send_websocket_buffer); + client.send(send_websocket_msg).wait(); + // use secure host post for LMS going forward + shbc_config = sbhc_success; + return; } @@ -365,7 +361,7 @@ int main(int argc, char* argv[]) try { // conntect to lms - lms_socket = lms_connect(secureHostBasedConfig); + lms_socket = lms_connect(shbc_config); } catch (...) { diff --git a/shbc.cpp b/shbc.cpp index 3c0d273..4bbe245 100644 --- a/shbc.cpp +++ b/shbc.cpp @@ -33,7 +33,7 @@ bool get_response_payload(std::string cert_algo, std::string cert_hash, web::jso return true; } -bool shbc_create_response(std::string cert_algo, std::string cert_hash, std::string& response) +bool shbc_create_response(std::string cert_algo, std::string cert_hash, bool config_status, std::string& response) { web::json::value msg; @@ -49,21 +49,32 @@ bool shbc_create_response(std::string cert_algo, std::string cert_hash, std::str tmp = utility::conversions::convertstring(PROTOCOL_VERSION); msg[U("protocolVersion")] = web::json::value::string(tmp); - tmp = utility::conversions::convertstring(""); - msg[U("status")] = web::json::value::string(tmp); - tmp = utility::conversions::convertstring(""); msg[U("message")] = web::json::value::string(tmp); - // get the activation payload - web::json::value responsePayload; - if (!get_response_payload(cert_algo, cert_hash, responsePayload)) return false; + if (config_status) + { + // get the activation payload + web::json::value responsePayload; + if (!get_response_payload(cert_algo, cert_hash, responsePayload)) return false; - // serialize payload - std::string serializedPayload = utility::conversions::to_utf8string(responsePayload.serialize()); - std::string encodedPayload = util_encode_base64(serializedPayload); - utility::string_t payload = utility::conversions::to_string_t(encodedPayload); - msg[U("payload")] = web::json::value::string(payload); + // serialize payload + std::string serializedPayload = utility::conversions::to_utf8string(responsePayload.serialize()); + std::string encodedPayload = util_encode_base64(serializedPayload); + utility::string_t payload = utility::conversions::to_string_t(encodedPayload); + msg[U("payload")] = web::json::value::string(payload); + + tmp = utility::conversions::convertstring("success"); + msg[U("status")] = web::json::value::string(tmp); + } + else + { + tmp = utility::conversions::convertstring(""); + msg[U("payload")] = web::json::value::string(tmp); + + tmp = utility::conversions::convertstring("failed"); + msg[U("status")] = web::json::value::string(tmp); + } // serialize the entire message response = utility::conversions::to_utf8string(msg.serialize()); diff --git a/shbc.h b/shbc.h index 73d5b99..751b482 100644 --- a/shbc.h +++ b/shbc.h @@ -14,6 +14,6 @@ #define convertstring to_utf8string #endif -bool shbc_create_response(std::string cert_algo, std::string cert_hash, std::string& response); +bool shbc_create_response(std::string cert_algo, std::string cert_hash, bool config_status, std::string& response); #endif \ No newline at end of file