SPARK-959 Implement functions for CME "secure" logon.
This commit is contained in:
1 parent
9abf59170a
commit
ac2fa9b7bc
7 files changed
+156
-4
No files matched your search
Vendored
+1
-1
@@ -111,7 +111,7 @@
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "/home/bts/spark/build/ninja_debug/src/server/sparkd/sparkd",
|
||||
"args": ["test", "-a", "[synthetic]"],
|
||||
"args": ["test", "-a", "LoadSessionKeys"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "/home/bts/spark/build/ninja_debug/src/server/sparkd/",
|
||||
"environment": [],
|
||||
|
||||
+1
-1
Submodule docker/linux updated: 735b688327...4261d624c1.
@@ -1 +1 @@
|
||||
set(sources api/apicore.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/services/AccountService.proto;api/services/ApiUnitTestService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/ShellDiagnosticService.proto;api/services/SyntheticSecurityService.proto;api/services/UserService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/Executor.conf;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/edge.conf;config/defaults/expiration_display_offset.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/testkeys.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/environment.proto;config/protos/expiration_display_offset.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/quickbus_cfg.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPriceLantencyTester.cpp;md/Diag/ShmDumper.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MDRecoverableConsumer.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_tests.cpp;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/windows_test_driver.cpp;utils/Dispatcher.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/download.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp)
|
||||
set(sources api/apicore.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/services/AccountService.proto;api/services/ApiUnitTestService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/ShellDiagnosticService.proto;api/services/SyntheticSecurityService.proto;api/services/UserService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/Executor.conf;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/edge.conf;config/defaults/expiration_display_offset.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/testkeys.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/environment.proto;config/protos/expiration_display_offset.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/quickbus_cfg.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPriceLantencyTester.cpp;md/Diag/ShmDumper.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MDRecoverableConsumer.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_tests.cpp;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/windows_test_driver.cpp;utils/Dispatcher.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SecureLogon.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/download.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp)
|
||||
@@ -104,6 +104,7 @@ else ()
|
||||
protobuf
|
||||
uuid.a
|
||||
sqlite3
|
||||
crypto++
|
||||
-lrt
|
||||
-ldl
|
||||
-static-libgcc
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
#ifndef _WIN32
|
||||
#include "SecureLogon.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/system.pb.h"
|
||||
|
||||
// libcrypto++-dev
|
||||
#include <cryptopp/hmac.h>
|
||||
#include <cryptopp/sha.h>
|
||||
#include <cryptopp/base64.h>
|
||||
#include <cryptopp/filters.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <iostream>
|
||||
// #include "catch/catch.hpp"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
using namespace CryptoPP;
|
||||
using std::string;
|
||||
|
||||
namespace glbx {
|
||||
|
||||
std::tuple<string, string> load_session_keys(const string& session) {
|
||||
using namespace boost;
|
||||
using namespace boost::filesystem;
|
||||
auto path = bts::config::get<bts::config::System>().data_path() + "glbx_logon/";
|
||||
if (is_directory(path)) {
|
||||
// iterate though each file
|
||||
for (const auto& f : directory_iterator(path)) {
|
||||
std::ifstream input(f.path().string());
|
||||
while (input && !input.eof()) {
|
||||
// iterate though each line
|
||||
string line;
|
||||
std::getline(input, line);
|
||||
char_separator<char> sep(", \t");
|
||||
tokenizer<char_separator<char>> tokens(line, sep);
|
||||
auto t = tokens.begin();
|
||||
// if first token matches session return the next 2 tokens
|
||||
if (t != tokens.end() && *t == session) {
|
||||
auto id = *(++t);
|
||||
auto secret = *(++t);
|
||||
return {id,secret};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bts_assert(false);
|
||||
}
|
||||
|
||||
LogonData calculate_hmac(
|
||||
const std::string& session_id,
|
||||
const std::string& msg_seq_num,
|
||||
const std::string& sender_comp_id,
|
||||
const std::string& sender_sub_id,
|
||||
const std::string& sending_time,
|
||||
const std::string& target_sub_id,
|
||||
const std::string& heartbeat_interval,
|
||||
const std::string& sender_location_id,
|
||||
const std::string& application_system_name,
|
||||
const std::string& application_system_version,
|
||||
const std::string& application_system_vendor
|
||||
) {
|
||||
string canonical;
|
||||
canonical += msg_seq_num;
|
||||
canonical += '\n';
|
||||
canonical += sender_comp_id;
|
||||
canonical += '\n';
|
||||
canonical += sender_sub_id;
|
||||
canonical += '\n';
|
||||
canonical += sending_time;
|
||||
canonical += '\n';
|
||||
canonical += target_sub_id;
|
||||
canonical += '\n';
|
||||
canonical += heartbeat_interval;
|
||||
canonical += '\n';
|
||||
canonical += sender_location_id;
|
||||
canonical += '\n';
|
||||
canonical += application_system_name;
|
||||
canonical += '\n';
|
||||
canonical += application_system_version;
|
||||
canonical += '\n';
|
||||
canonical += application_system_vendor;
|
||||
|
||||
string secret_key, access_id;
|
||||
std::tie(access_id, secret_key) = load_session_keys(session_id);
|
||||
|
||||
try {
|
||||
string decoded_key;
|
||||
StringSink key_sink(decoded_key);
|
||||
Base64URLDecoder decoder(&key_sink);
|
||||
StringSource(secret_key, true, &decoder);
|
||||
|
||||
HMAC<SHA256> hmac( (const byte*)decoded_key.c_str(), decoded_key.size());
|
||||
string calculated_hmac;
|
||||
StringSink hmac_sink(calculated_hmac);
|
||||
HashFilter filter(hmac, &hmac_sink);
|
||||
StringSource(canonical, true, &filter);
|
||||
|
||||
string encoded_hmac;
|
||||
StringSink result_sink(encoded_hmac);
|
||||
Base64URLEncoder url_enc(&result_sink);
|
||||
StringSource(calculated_hmac, true, &url_enc);
|
||||
|
||||
return { access_id, encoded_hmac };
|
||||
}
|
||||
catch(const Exception& e) {
|
||||
bts_assert_msg(false, e.what());
|
||||
}
|
||||
bts_assert(false);
|
||||
}
|
||||
|
||||
|
||||
// TEST_CASE("LoadSessionKeys", "") {
|
||||
// std::string session_id = "1U7";
|
||||
// string secret_key, access_id;
|
||||
// std::tie(access_id, secret_key) = load_session_keys(session_id);
|
||||
// REQUIRE(access_id == "ozXmORijPtJriTg6Wwny");
|
||||
// REQUIRE(secret_key == "A1KOwrhH8GojNotjkCfVwHRSi_OS280xihaRZwJLFKo");
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace glbx {
|
||||
|
||||
struct LogonData {
|
||||
std::string access_key;
|
||||
std::string signature;
|
||||
};
|
||||
|
||||
LogonData calculate_hmac(
|
||||
const std::string& session_id,
|
||||
const std::string& msg_seq_num,
|
||||
const std::string& sender_comp_id,
|
||||
const std::string& sender_sub_id,
|
||||
const std::string& sending_time,
|
||||
const std::string& target_sub_id,
|
||||
const std::string& heartbeat_interval,
|
||||
const std::string& sender_location_id,
|
||||
const std::string& application_system_name,
|
||||
const std::string& application_system_version,
|
||||
const std::string& application_system_vendor
|
||||
);
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
#define bts_assert_msg(EXP, msg) \
|
||||
do { \
|
||||
if (!(EXP)) { \
|
||||
LOG(Assert, Fatal, "Assert failure: {} {}", std::string(#EXP), \
|
||||
LOG(Assert, bts::Fatal, "Assert failure: {} {}", std::string(#EXP), \
|
||||
std::string(msg)); \
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1)); \
|
||||
if (is_debugger_present()) \
|
||||
|
||||
Reference in new issue
Block a user