Loading Rakefile +34 −13 Original line number Diff line number Diff line Loading @@ -131,23 +131,21 @@ namespace :java_sim do report_banner "Starting Kinetic Java Simulator" # Validate JAVA_HOME raise "JAVA_HOME must be set!" unless ENV["JAVA_HOME"] java = File.join(ENV['JAVA_HOME'], 'bin', 'java') java_home = ENV.fetch('JAVA_HOME', '/usr') java = File.join(java_home, 'bin/java') # Find the java simulator jar sim_jars = Dir["vendor/kinetic-java/kinetic-simulator*.jar"] raise "No Kinetic Java simulator .jar files found!" if sim_jars.empty? jars = Dir["vendor/kinetic-java/kinetic-simulator*.jar"] raise "No Kinetic Java simulator .jar files found!" if jars.empty? # Configure the classpath ENV['CLASSPATH'] = '' unless ENV['CLASSPATH'] jars = [File.join(ENV['JAVA_HOME'], 'lib', 'tools.jar')] + sim_jars jars.each do |jar| ENV['CLASSPATH'] += ':' + jar end sleep 2 jars += [File.join(java_home, 'lib/tools.jar')] jars.each {|jar| ENV['CLASSPATH'] += ':' + jar } $java_sim = spawn("#{java} -classpath #{ENV['CLASSPATH']} com.seagate.kinetic.simulator.internal.SimulatorRunner") sleep 5 sleep 5 # wait for simulator to start up and server ready to receive connections # TODO: use netstat or something to just wait until the server opens the port # since it might take longer than the hardcoded sleep(x) above :-/ end def java_sim_shutdown Loading Loading @@ -193,6 +191,29 @@ namespace :ruby_sim do end task 'test/integration/test_kinetic_socket.c' => ['ruby_sim:start'] # task 'test/system/test_kinetic_api_system.c' => ['java_sim:shutdown', 'ruby_sim:start'] task 'test/system/test_kinetic_api_system.c' => ['ruby_sim:shutdown', 'java_sim:start'] namespace :system do desc "Run system tests w/KineticRuby for message inspection" task :test_sniff do [ 'java_sim:shutdown', 'ruby_sim:start', ].each do |task| Rake::Task[task].reenable Rake::Task[task].invoke end [ 'test/system/test_kinetic_api_system.c' ].each do |task| Rake::Task[task].clear_prerequisites Rake::Task[task].invoke end end end desc "Run client test utility" task :run do Loading Loading @@ -236,10 +257,10 @@ task :test_all do shutdown_ruby_server report_banner "Running System Tests" java_sim_start # java_sim_start Rake::Task['test:path'].reenable Rake::Task['test:path'].invoke('test/system') java_sim_shutdown # java_sim_shutdown report_banner "Finished executing all test suites" end Loading src/lib/kinetic_api.c +11 −15 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ bool KineticApi_Connect( bool KineticApi_ConfigureExchange( KineticExchange* exchange, KineticConnection* connection, int64_t clusterVersion, int64_t identity, const char* key, size_t keyLength) Loading @@ -78,6 +79,7 @@ bool KineticApi_ConfigureExchange( } KineticExchange_Init(exchange, identity, key, keyLength, connection); KineticExchange_SetClusterVersion(exchange, clusterVersion); KineticExchange_ConfigureConnectionID(exchange); return true; Loading @@ -87,8 +89,7 @@ KineticOperation KineticApi_CreateOperation( KineticExchange* exchange, KineticPDU* request, KineticMessage* requestMsg, KineticPDU* response, KineticMessage* responseMsg) KineticPDU* response) { KineticOperation op; Loading Loading @@ -116,23 +117,18 @@ KineticOperation KineticApi_CreateOperation( assert(response != NULL); } if (responseMsg == NULL) { LOG("Specified response KineticMessage is NULL!"); assert(responseMsg != NULL); } KineticMessage_Init(requestMsg); KineticPDU_Init(request, exchange, requestMsg, NULL, 0); KineticMessage_Init(responseMsg); KineticPDU_Init(response, exchange, responseMsg, NULL, 0); // KineticMessage_Init(responseMsg); KineticPDU_Init(response, exchange, NULL, NULL, 0); op.exchange = exchange; op.request = request; op.request->protobuf = requestMsg; op.request->message = requestMsg; op.response = response; op.response->protobuf = responseMsg; op.response->message = NULL; op.response->proto = NULL; return op; } Loading @@ -145,9 +141,9 @@ KineticProto_Status_StatusCode KineticApi_NoOp(KineticOperation* operation) assert(operation->exchange != NULL); assert(operation->exchange->connection != NULL); assert(operation->request != NULL); assert(operation->request->protobuf != NULL); assert(operation->request->message != NULL); assert(operation->response != NULL); assert(operation->response->protobuf != NULL); assert(operation->response->message == NULL); // Initialize request KineticExchange_IncrementSequence(operation->exchange); Loading @@ -162,7 +158,7 @@ KineticProto_Status_StatusCode KineticApi_NoOp(KineticOperation* operation) // Receive the response if (KineticPDU_Receive(operation->response)) { status = operation->response->protobuf->command.status->code; status = operation->response->proto->command->status->code; } return status; Loading src/lib/kinetic_api.h +22 −21 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ bool KineticApi_Connect( * * @param exchange KineticExchange instance to configure with exchange info * @param connection KineticConnection to associate with exchange * @param clusterVersion Cluster version for the exchange * @param identity Identity to use for the exchange * @param key Key to use for HMAC calculations * @param keyLength Length of HMAC key Loading @@ -62,6 +63,7 @@ bool KineticApi_Connect( bool KineticApi_ConfigureExchange( KineticExchange* exchange, KineticConnection* connection, int64_t clusterVersion, int64_t identity, const char* key, size_t keyLength); Loading @@ -80,8 +82,7 @@ KineticOperation KineticApi_CreateOperation( KineticExchange* exchange, KineticPDU* request, KineticMessage* requestMsg, KineticPDU* response, KineticMessage* responseMsg); KineticPDU* response); /** * @brief Executes a NOOP command to test whether the Kinetic Device is operational Loading src/lib/kinetic_hmac.c +16 −34 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ void KineticHMAC_Init(KineticHMAC * hmac, KineticProto_Security_ACL_HMACAlgorith { hmac->algorithm = algorithm; memset(hmac->value, 0, KINETIC_HMAC_MAX_LEN); hmac->valueLength = 0; hmac->valueLength = KINETIC_HMAC_MAX_LEN; } else { Loading @@ -40,25 +40,18 @@ void KineticHMAC_Init(KineticHMAC * hmac, KineticProto_Security_ACL_HMACAlgorith } } void KineticHMAC_Populate( KineticHMAC* hmac, KineticMessage* message, const char* const key, size_t keyLen) void KineticHMAC_Populate(KineticHMAC* hmac, KineticProto* proto, const char* const key, size_t keyLen) { KineticHMAC_Init(hmac, hmac->algorithm); KineticHMAC_Compute(hmac, &message->proto, key, keyLen); KineticHMAC_Init(hmac, KINETIC_PROTO_SECURITY_ACL_HMACALGORITHM_HmacSHA1); KineticHMAC_Compute(hmac, proto, key, keyLen); // Copy computed HMAC into message memcpy(message->proto.hmac.data, hmac->value, hmac->valueLength); message->proto.hmac.len = hmac->valueLength; message->proto.has_hmac = true; memcpy(proto->hmac.data, hmac->value, hmac->valueLength); proto->hmac.len = hmac->valueLength; proto->has_hmac = true; } bool KineticHMAC_Validate( const KineticProto* proto, const char* const key, size_t keyLen) bool KineticHMAC_Validate(const KineticProto* proto, const char* const key, size_t keyLen) { size_t i; int result = 0; Loading @@ -69,7 +62,7 @@ bool KineticHMAC_Validate( return false; } KineticHMAC_Init(&tempHMAC, KINETIC_PROTO_SECURITY_ACL_HMACALGORITHM_INVALID_HMAC_ALGORITHM); KineticHMAC_Init(&tempHMAC, KINETIC_PROTO_SECURITY_ACL_HMACALGORITHM_HmacSHA1); KineticHMAC_Compute(&tempHMAC, proto, key, keyLen); if (proto->hmac.len != tempHMAC.valueLength) Loading @@ -85,35 +78,24 @@ bool KineticHMAC_Validate( return (result == 0); } static void KineticHMAC_Compute( KineticHMAC* hmac, const KineticProto* proto, const char* const key, size_t keyLen) static void KineticHMAC_Compute(KineticHMAC* hmac, const KineticProto* proto, const char* const key, size_t keyLen) { HMAC_CTX ctx; unsigned int len = protobuf_c_message_get_packed_size((ProtobufCMessage*)proto->command); uint8_t* command = malloc(len); protobuf_c_message_pack((ProtobufCMessage*)proto->command, command); uint8_t* packed = malloc(len); protobuf_c_message_pack((ProtobufCMessage*)proto->command, packed); #pragma push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" uint32_t messageLengthNBO = htonl(len); HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, key, keyLen, EVP_sha1(), NULL); if (keyLen != 0) { uint32_t messageLengthNBO = htonl(keyLen); HMAC_Update(&ctx, (uint8_t*)(&messageLengthNBO), sizeof(uint32_t)); HMAC_Update(&ctx, command, len); } HMAC_Update(&ctx, (uint8_t*)&messageLengthNBO, sizeof(uint32_t)); HMAC_Update(&ctx, packed, len); HMAC_Final(&ctx, hmac->value, &hmac->valueLength); HMAC_CTX_cleanup(&ctx); #pragma pop free(command); free(packed); } src/lib/kinetic_hmac.h +1 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ typedef struct _KineticHMAC } KineticHMAC; void KineticHMAC_Init(KineticHMAC * hmac, KineticProto_Security_ACL_HMACAlgorithm algorithm); void KineticHMAC_Populate(KineticHMAC* hmac, KineticMessage* message, const char* const key, size_t keyLen); void KineticHMAC_Populate(KineticHMAC* hmac, KineticProto* proto, const char* const key, size_t keyLen); bool KineticHMAC_Validate(const KineticProto* proto, const char* const key, size_t keyLen); #endif // _KINETIC_HMAC_H Loading
Rakefile +34 −13 Original line number Diff line number Diff line Loading @@ -131,23 +131,21 @@ namespace :java_sim do report_banner "Starting Kinetic Java Simulator" # Validate JAVA_HOME raise "JAVA_HOME must be set!" unless ENV["JAVA_HOME"] java = File.join(ENV['JAVA_HOME'], 'bin', 'java') java_home = ENV.fetch('JAVA_HOME', '/usr') java = File.join(java_home, 'bin/java') # Find the java simulator jar sim_jars = Dir["vendor/kinetic-java/kinetic-simulator*.jar"] raise "No Kinetic Java simulator .jar files found!" if sim_jars.empty? jars = Dir["vendor/kinetic-java/kinetic-simulator*.jar"] raise "No Kinetic Java simulator .jar files found!" if jars.empty? # Configure the classpath ENV['CLASSPATH'] = '' unless ENV['CLASSPATH'] jars = [File.join(ENV['JAVA_HOME'], 'lib', 'tools.jar')] + sim_jars jars.each do |jar| ENV['CLASSPATH'] += ':' + jar end sleep 2 jars += [File.join(java_home, 'lib/tools.jar')] jars.each {|jar| ENV['CLASSPATH'] += ':' + jar } $java_sim = spawn("#{java} -classpath #{ENV['CLASSPATH']} com.seagate.kinetic.simulator.internal.SimulatorRunner") sleep 5 sleep 5 # wait for simulator to start up and server ready to receive connections # TODO: use netstat or something to just wait until the server opens the port # since it might take longer than the hardcoded sleep(x) above :-/ end def java_sim_shutdown Loading Loading @@ -193,6 +191,29 @@ namespace :ruby_sim do end task 'test/integration/test_kinetic_socket.c' => ['ruby_sim:start'] # task 'test/system/test_kinetic_api_system.c' => ['java_sim:shutdown', 'ruby_sim:start'] task 'test/system/test_kinetic_api_system.c' => ['ruby_sim:shutdown', 'java_sim:start'] namespace :system do desc "Run system tests w/KineticRuby for message inspection" task :test_sniff do [ 'java_sim:shutdown', 'ruby_sim:start', ].each do |task| Rake::Task[task].reenable Rake::Task[task].invoke end [ 'test/system/test_kinetic_api_system.c' ].each do |task| Rake::Task[task].clear_prerequisites Rake::Task[task].invoke end end end desc "Run client test utility" task :run do Loading Loading @@ -236,10 +257,10 @@ task :test_all do shutdown_ruby_server report_banner "Running System Tests" java_sim_start # java_sim_start Rake::Task['test:path'].reenable Rake::Task['test:path'].invoke('test/system') java_sim_shutdown # java_sim_shutdown report_banner "Finished executing all test suites" end Loading
src/lib/kinetic_api.c +11 −15 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ bool KineticApi_Connect( bool KineticApi_ConfigureExchange( KineticExchange* exchange, KineticConnection* connection, int64_t clusterVersion, int64_t identity, const char* key, size_t keyLength) Loading @@ -78,6 +79,7 @@ bool KineticApi_ConfigureExchange( } KineticExchange_Init(exchange, identity, key, keyLength, connection); KineticExchange_SetClusterVersion(exchange, clusterVersion); KineticExchange_ConfigureConnectionID(exchange); return true; Loading @@ -87,8 +89,7 @@ KineticOperation KineticApi_CreateOperation( KineticExchange* exchange, KineticPDU* request, KineticMessage* requestMsg, KineticPDU* response, KineticMessage* responseMsg) KineticPDU* response) { KineticOperation op; Loading Loading @@ -116,23 +117,18 @@ KineticOperation KineticApi_CreateOperation( assert(response != NULL); } if (responseMsg == NULL) { LOG("Specified response KineticMessage is NULL!"); assert(responseMsg != NULL); } KineticMessage_Init(requestMsg); KineticPDU_Init(request, exchange, requestMsg, NULL, 0); KineticMessage_Init(responseMsg); KineticPDU_Init(response, exchange, responseMsg, NULL, 0); // KineticMessage_Init(responseMsg); KineticPDU_Init(response, exchange, NULL, NULL, 0); op.exchange = exchange; op.request = request; op.request->protobuf = requestMsg; op.request->message = requestMsg; op.response = response; op.response->protobuf = responseMsg; op.response->message = NULL; op.response->proto = NULL; return op; } Loading @@ -145,9 +141,9 @@ KineticProto_Status_StatusCode KineticApi_NoOp(KineticOperation* operation) assert(operation->exchange != NULL); assert(operation->exchange->connection != NULL); assert(operation->request != NULL); assert(operation->request->protobuf != NULL); assert(operation->request->message != NULL); assert(operation->response != NULL); assert(operation->response->protobuf != NULL); assert(operation->response->message == NULL); // Initialize request KineticExchange_IncrementSequence(operation->exchange); Loading @@ -162,7 +158,7 @@ KineticProto_Status_StatusCode KineticApi_NoOp(KineticOperation* operation) // Receive the response if (KineticPDU_Receive(operation->response)) { status = operation->response->protobuf->command.status->code; status = operation->response->proto->command->status->code; } return status; Loading
src/lib/kinetic_api.h +22 −21 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ bool KineticApi_Connect( * * @param exchange KineticExchange instance to configure with exchange info * @param connection KineticConnection to associate with exchange * @param clusterVersion Cluster version for the exchange * @param identity Identity to use for the exchange * @param key Key to use for HMAC calculations * @param keyLength Length of HMAC key Loading @@ -62,6 +63,7 @@ bool KineticApi_Connect( bool KineticApi_ConfigureExchange( KineticExchange* exchange, KineticConnection* connection, int64_t clusterVersion, int64_t identity, const char* key, size_t keyLength); Loading @@ -80,8 +82,7 @@ KineticOperation KineticApi_CreateOperation( KineticExchange* exchange, KineticPDU* request, KineticMessage* requestMsg, KineticPDU* response, KineticMessage* responseMsg); KineticPDU* response); /** * @brief Executes a NOOP command to test whether the Kinetic Device is operational Loading
src/lib/kinetic_hmac.c +16 −34 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ void KineticHMAC_Init(KineticHMAC * hmac, KineticProto_Security_ACL_HMACAlgorith { hmac->algorithm = algorithm; memset(hmac->value, 0, KINETIC_HMAC_MAX_LEN); hmac->valueLength = 0; hmac->valueLength = KINETIC_HMAC_MAX_LEN; } else { Loading @@ -40,25 +40,18 @@ void KineticHMAC_Init(KineticHMAC * hmac, KineticProto_Security_ACL_HMACAlgorith } } void KineticHMAC_Populate( KineticHMAC* hmac, KineticMessage* message, const char* const key, size_t keyLen) void KineticHMAC_Populate(KineticHMAC* hmac, KineticProto* proto, const char* const key, size_t keyLen) { KineticHMAC_Init(hmac, hmac->algorithm); KineticHMAC_Compute(hmac, &message->proto, key, keyLen); KineticHMAC_Init(hmac, KINETIC_PROTO_SECURITY_ACL_HMACALGORITHM_HmacSHA1); KineticHMAC_Compute(hmac, proto, key, keyLen); // Copy computed HMAC into message memcpy(message->proto.hmac.data, hmac->value, hmac->valueLength); message->proto.hmac.len = hmac->valueLength; message->proto.has_hmac = true; memcpy(proto->hmac.data, hmac->value, hmac->valueLength); proto->hmac.len = hmac->valueLength; proto->has_hmac = true; } bool KineticHMAC_Validate( const KineticProto* proto, const char* const key, size_t keyLen) bool KineticHMAC_Validate(const KineticProto* proto, const char* const key, size_t keyLen) { size_t i; int result = 0; Loading @@ -69,7 +62,7 @@ bool KineticHMAC_Validate( return false; } KineticHMAC_Init(&tempHMAC, KINETIC_PROTO_SECURITY_ACL_HMACALGORITHM_INVALID_HMAC_ALGORITHM); KineticHMAC_Init(&tempHMAC, KINETIC_PROTO_SECURITY_ACL_HMACALGORITHM_HmacSHA1); KineticHMAC_Compute(&tempHMAC, proto, key, keyLen); if (proto->hmac.len != tempHMAC.valueLength) Loading @@ -85,35 +78,24 @@ bool KineticHMAC_Validate( return (result == 0); } static void KineticHMAC_Compute( KineticHMAC* hmac, const KineticProto* proto, const char* const key, size_t keyLen) static void KineticHMAC_Compute(KineticHMAC* hmac, const KineticProto* proto, const char* const key, size_t keyLen) { HMAC_CTX ctx; unsigned int len = protobuf_c_message_get_packed_size((ProtobufCMessage*)proto->command); uint8_t* command = malloc(len); protobuf_c_message_pack((ProtobufCMessage*)proto->command, command); uint8_t* packed = malloc(len); protobuf_c_message_pack((ProtobufCMessage*)proto->command, packed); #pragma push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" uint32_t messageLengthNBO = htonl(len); HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, key, keyLen, EVP_sha1(), NULL); if (keyLen != 0) { uint32_t messageLengthNBO = htonl(keyLen); HMAC_Update(&ctx, (uint8_t*)(&messageLengthNBO), sizeof(uint32_t)); HMAC_Update(&ctx, command, len); } HMAC_Update(&ctx, (uint8_t*)&messageLengthNBO, sizeof(uint32_t)); HMAC_Update(&ctx, packed, len); HMAC_Final(&ctx, hmac->value, &hmac->valueLength); HMAC_CTX_cleanup(&ctx); #pragma pop free(command); free(packed); }
src/lib/kinetic_hmac.h +1 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ typedef struct _KineticHMAC } KineticHMAC; void KineticHMAC_Init(KineticHMAC * hmac, KineticProto_Security_ACL_HMACAlgorithm algorithm); void KineticHMAC_Populate(KineticHMAC* hmac, KineticMessage* message, const char* const key, size_t keyLen); void KineticHMAC_Populate(KineticHMAC* hmac, KineticProto* proto, const char* const key, size_t keyLen); bool KineticHMAC_Validate(const KineticProto* proto, const char* const key, size_t keyLen); #endif // _KINETIC_HMAC_H