Fix: исправлена ошибка инициализации ключей
- Исправлена функция sc_init_local_keys - валидация ключей происходит после конвертации из hex - Добавлена отладочная информация для диагностики ошибок валидации - Заменены некорректные тестовые ключи на валидные ECC ключи для secp256r1 - Исправлена логическая ошибка: sc_validate_key теперь вызывается с бинарными данными Теперь все ключи проходят валидацию uECC_valid_public_key() успешно.
This commit is contained in:
1 parent
63b0e64763
commit
7eff11ecbc
3 files changed
+32
-10
No files matched your search
+27
-5
@@ -14,6 +14,12 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Simple debug macros
|
||||
#define DEBUG_CATEGORY_CRYPTO 1
|
||||
#define DEBUG_ERROR(category, fmt, ...) fprintf(stderr, "ERROR: " fmt "\n", ##__VA_ARGS__)
|
||||
#define DEBUG_INFO(category, fmt, ...) fprintf(stdout, "INFO: " fmt "\n", ##__VA_ARGS__)
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include "crc32.h"
|
||||
|
||||
@@ -66,7 +72,9 @@ static int sc_validate_key(const uint8_t *public_key)
|
||||
if (!curve) {
|
||||
curve = uECC_secp256r1();
|
||||
}
|
||||
return uECC_valid_public_key(public_key, curve);
|
||||
int result = uECC_valid_public_key(public_key, curve);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "sc_validate_key: uECC_valid_public_key returned %d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
sc_status_t sc_generate_keypair(struct SC_MYKEYS *pk)
|
||||
@@ -102,6 +110,7 @@ static int hex_to_binary(const char *hex_str, uint8_t *binary, size_t binary_len
|
||||
|
||||
sc_status_t sc_init_local_keys(struct SC_MYKEYS *mykeys, const char *public_key, const char *private_key) {
|
||||
if (!mykeys || !public_key || !private_key) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "sc_init_local_keys: invalid arguments");
|
||||
return SC_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@@ -109,13 +118,26 @@ sc_status_t sc_init_local_keys(struct SC_MYKEYS *mykeys, const char *public_key,
|
||||
curve = uECC_secp256r1();
|
||||
}
|
||||
|
||||
/* Validate public key */
|
||||
if (sc_validate_key(public_key) != 0) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "sc_init_local_keys: public_key len=%zu, private_key len=%zu",
|
||||
strlen(public_key), strlen(private_key));
|
||||
|
||||
/* Convert hex to binary first */
|
||||
if (hex_to_binary(public_key, mykeys->public_key, SC_PUBKEY_SIZE)) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "sc_init_local_keys: failed to convert public key from hex");
|
||||
return SC_ERR_INVALID_ARG;
|
||||
}
|
||||
if (hex_to_binary(private_key, mykeys->private_key, SC_PRIVKEY_SIZE)) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "sc_init_local_keys: failed to convert private key from hex");
|
||||
return SC_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (hex_to_binary(public_key, mykeys->public_key, SC_PUBKEY_SIZE)) return SC_ERR_INVALID_ARG;
|
||||
if (hex_to_binary(private_key, mykeys->private_key, SC_PRIVKEY_SIZE)) return SC_ERR_INVALID_ARG;
|
||||
/* Validate the converted binary public key */
|
||||
if (sc_validate_key(mykeys->public_key) != 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "sc_init_local_keys: public key validation failed");
|
||||
return SC_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "sc_init_local_keys: keys initialized successfully");
|
||||
return SC_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[global]
|
||||
my_node_id=0x2222222222222222
|
||||
my_private_key=2313912e5d34768983b0e06530a48c77816d228a5b5605e1ab3dc443d107a3dc
|
||||
my_public_key=ede6cec8a9023339a758f60883ef41534d24a1ffdc09bbb787a5c24ddfd891e3092461835a97d37944c681fc6b2c1f5acde8ad192f7d2cdc9920aa0d3ff78e99
|
||||
my_private_key=4813d31d28b7e9829247f488c6be7672f2bdf61b2508333128e386d1759afed2
|
||||
my_public_key=c594f33c91f3a2222795c2c110c527bf214ad1009197ce14556cb13df3c461b3c373bed8f205a8dd1fc0c364f90bf471d7c6f5db49564c33e4235d268569ac71
|
||||
tun_ip=10.99.0.2/24
|
||||
tun_ifname=tun98
|
||||
|
||||
@@ -11,5 +11,5 @@ type=public
|
||||
|
||||
[client: test_client]
|
||||
keepalive=1
|
||||
peer_public_key=dde6cec8a9023339a758f60883ef41534d24a1ffdc09bbb787a5c24ddfd891e3092461835a97d37944c681fc6b2c1f5acde8ad192f7d2cdc9920aa0d3ff78e99
|
||||
peer_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9
|
||||
link=test:127.0.0.1:9001
|
||||
@@ -1,7 +1,7 @@
|
||||
[global]
|
||||
my_node_id=0x1111111111111111
|
||||
my_private_key=1313912e5d34768983b0e06530a48c77816d228a5b5605e1ab3dc443d107a3dc
|
||||
my_public_key=dde6cec8a9023339a758f60883ef41534d24a1ffdc09bbb787a5c24ddfd891e3092461835a97d37944c681fc6b2c1f5acde8ad192f7d2cdc9920aa0d3ff78e99
|
||||
my_private_key=67b705a92b41bcaae105af2d6a17743faa7b26ccebba8b3b9b0af05e9cd1d5fb
|
||||
my_public_key=1c55e4ccae7c4470707759086738b10681bf88b81f198cc2ab54a647d1556e17c65e6b1833e0c771e5a39382c03067c388915a4c732191bc130480f20f8e00b9
|
||||
tun_ip=10.99.0.1/24
|
||||
tun_ifname=tun99
|
||||
|
||||
|
||||
Reference in new issue
Block a user