|
|
|
@ -94,7 +94,7 @@ static int test_secure_channel_crypto(void) { |
|
|
|
} |
|
|
|
} |
|
|
|
printf("✓ Client crypto context initialized\n"); |
|
|
|
printf("✓ Client crypto context initialized\n"); |
|
|
|
|
|
|
|
|
|
|
|
// For this simple test, we'll manually set peer keys and session ready
|
|
|
|
// For this simple test, we'll manually set peer keys, session ready, and session key
|
|
|
|
// to bypass the ECC key exchange which requires proper ECC initialization
|
|
|
|
// to bypass the ECC key exchange which requires proper ECC initialization
|
|
|
|
memcpy(client_ctx.peer_public_key, server_keys.public_key, SC_PUBKEY_SIZE); |
|
|
|
memcpy(client_ctx.peer_public_key, server_keys.public_key, SC_PUBKEY_SIZE); |
|
|
|
memcpy(server_ctx.peer_public_key, client_keys.public_key, SC_PUBKEY_SIZE); |
|
|
|
memcpy(server_ctx.peer_public_key, client_keys.public_key, SC_PUBKEY_SIZE); |
|
|
|
@ -102,9 +102,17 @@ static int test_secure_channel_crypto(void) { |
|
|
|
client_ctx.session_ready = 1; // This is crucial for encryption to work
|
|
|
|
client_ctx.session_ready = 1; // This is crucial for encryption to work
|
|
|
|
server_ctx.peer_key_set = 1; |
|
|
|
server_ctx.peer_key_set = 1; |
|
|
|
server_ctx.session_ready = 1; // This is crucial for encryption to work
|
|
|
|
server_ctx.session_ready = 1; // This is crucial for encryption to work
|
|
|
|
client_ctx.session_ready = 1; // This is crucial for encryption to work
|
|
|
|
|
|
|
|
server_ctx.session_ready = 1; // This is crucial for encryption to work
|
|
|
|
// Set test session keys manually (16 bytes for AES-128)
|
|
|
|
printf("✓ Peer public keys set manually\n"); |
|
|
|
// In a real implementation, this would be derived from ECDH shared secret
|
|
|
|
|
|
|
|
uint8_t test_session_key[SC_SESSION_KEY_SIZE]; |
|
|
|
|
|
|
|
for (int i = 0; i < SC_SESSION_KEY_SIZE; i++) { |
|
|
|
|
|
|
|
test_session_key[i] = i + 100; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
memcpy(client_ctx.session_key, test_session_key, SC_SESSION_KEY_SIZE); |
|
|
|
|
|
|
|
memcpy(server_ctx.session_key, test_session_key, SC_SESSION_KEY_SIZE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("✓ Peer public keys and session keys set manually\n"); |
|
|
|
|
|
|
|
|
|
|
|
// Test data
|
|
|
|
// Test data
|
|
|
|
uint8_t plaintext[] = TEST_DATA; |
|
|
|
uint8_t plaintext[] = TEST_DATA; |
|
|
|
@ -218,9 +226,13 @@ static int test_etcp_connection_crypto(void) { |
|
|
|
uint8_t decrypted[256]; |
|
|
|
uint8_t decrypted[256]; |
|
|
|
size_t encrypted_len, decrypted_len; |
|
|
|
size_t encrypted_len, decrypted_len; |
|
|
|
|
|
|
|
|
|
|
|
// Self-encryption test (set our own public key as peer)
|
|
|
|
// Self-encryption test (set our own public key as peer and session key)
|
|
|
|
memcpy(conn->crypto_ctx.peer_public_key, keys.public_key, SC_PUBKEY_SIZE); |
|
|
|
memcpy(conn->crypto_ctx.peer_public_key, keys.public_key, SC_PUBKEY_SIZE); |
|
|
|
conn->crypto_ctx.peer_key_set = 1; |
|
|
|
conn->crypto_ctx.peer_key_set = 1; |
|
|
|
|
|
|
|
conn->crypto_ctx.session_ready = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set test session key for self-encryption
|
|
|
|
|
|
|
|
memcpy(conn->crypto_ctx.session_key, keys.public_key, SC_SESSION_KEY_SIZE); // Use public key as session key for test
|
|
|
|
|
|
|
|
|
|
|
|
if (sc_encrypt(&conn->crypto_ctx, test_data, sizeof(test_data)-1, encrypted, &encrypted_len) != SC_OK) { |
|
|
|
if (sc_encrypt(&conn->crypto_ctx, test_data, sizeof(test_data)-1, encrypted, &encrypted_len) != SC_OK) { |
|
|
|
printf("ERROR: Connection encryption failed\n"); |
|
|
|
printf("ERROR: Connection encryption failed\n"); |
|
|
|
|