1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-10-30 22:56:22 +00:00

Merge branch 'osnma-cesare' of https://github.com/cesaaargm/osnma into osnma-cesare

This commit is contained in:
Carles Fernandez 2024-08-05 13:49:42 +02:00
commit 45ad153c98
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D

View File

@ -1210,6 +1210,28 @@ void Gnss_Crypto::readPublicKeyFromPEM(const std::string& pemFilePath)
} }
const EC_GROUP* group = EC_KEY_get0_group(pubkey); const EC_GROUP* group = EC_KEY_get0_group(pubkey);
int nid = EC_GROUP_get_curve_name(group); int nid = EC_GROUP_get_curve_name(group);
if (nid == 0)
{
BIGNUM* p = BN_new();
if (EC_GROUP_get_curve_GFp(group, p, nullptr, nullptr, nullptr) == 1)
{
char* p_str = BN_bn2hex(p);
const std::string pcstr(p_str);
if (pcstr.size() == 64)
{
d_PublicKeyType = "ECDSA P-256";
}
else if (pcstr.size() == 132)
{
d_PublicKeyType = "ECDSA P-521";
}
OPENSSL_free(p_str);
}
BN_free(p);
}
else
{
const char* curve_name = OBJ_nid2sn(nid); const char* curve_name = OBJ_nid2sn(nid);
const std::string curve_str(curve_name); const std::string curve_str(curve_name);
if (curve_str == "prime256v1") if (curve_str == "prime256v1")
@ -1220,6 +1242,7 @@ void Gnss_Crypto::readPublicKeyFromPEM(const std::string& pemFilePath)
{ {
d_PublicKeyType = "ECDSA P-521"; d_PublicKeyType = "ECDSA P-521";
} }
}
pubkey_copy(pubkey, &d_PublicKey); pubkey_copy(pubkey, &d_PublicKey);
EC_KEY_free(pubkey); EC_KEY_free(pubkey);
@ -1410,9 +1433,16 @@ bool Gnss_Crypto::readPublicKeyFromCRT(const std::string& crtFilePath)
pubkey_copy(pubkey, &d_PublicKey); pubkey_copy(pubkey, &d_PublicKey);
EVP_PKEY_free(pubkey); EVP_PKEY_free(pubkey);
#else // OpenSSL 1.x #else // OpenSSL 1.x
#if USE_OPENSSL_111
// store the key type - needed for the Kroot in case no DSM-PKR available // store the key type - needed for the Kroot in case no DSM-PKR available
const auto ec_key = EVP_PKEY_get0_EC_KEY(pubkey); const auto ec_key = EVP_PKEY_get0_EC_KEY(pubkey);
const EC_GROUP* group = EC_KEY_get0_group(ec_key); const EC_GROUP* group = EC_KEY_get0_group(ec_key);
if (!group)
{
X509_free(cert);
EC_KEY_free(ec_key);
return false;
}
const int nid = EC_GROUP_get_curve_name(group); const int nid = EC_GROUP_get_curve_name(group);
if (nid == NID_X9_62_prime256v1) if (nid == NID_X9_62_prime256v1)
{ {
@ -1422,7 +1452,56 @@ bool Gnss_Crypto::readPublicKeyFromCRT(const std::string& crtFilePath)
{ {
d_PublicKeyType = "ECDSA P-521"; d_PublicKeyType = "ECDSA P-521";
} }
#else
EC_KEY* ec_key = EVP_PKEY_get1_EC_KEY(pubkey);
if (!ec_key)
{
X509_free(cert);
return false;
}
// Get the EC_GROUP from the EC_KEY
const EC_GROUP* group = EC_KEY_get0_group(ec_key);
if (!group)
{
X509_free(cert);
EC_KEY_free(ec_key);
return false;
}
const int nid = EC_GROUP_get_curve_name(group);
if (nid == 0)
{
BIGNUM* p = BN_new();
if (EC_GROUP_get_curve_GFp(group, p, nullptr, nullptr, nullptr) == 1)
{
char* p_str = BN_bn2hex(p);
const std::string pcstr(p_str);
if (pcstr.size() == 64)
{
d_PublicKeyType = "ECDSA P-256";
}
else if (pcstr.size() == 132)
{
d_PublicKeyType = "ECDSA P-521";
}
OPENSSL_free(p_str);
}
BN_free(p);
}
else
{
const char* curve_name = OBJ_nid2sn(nid);
const std::string curve_str(curve_name);
if (curve_str == "prime256v1")
{
d_PublicKeyType = "ECDSA P-256";
}
else if (curve_str == "secp521r1")
{
d_PublicKeyType = "ECDSA P-521";
}
}
#endif
EC_KEY* ec_pubkey = EVP_PKEY_get1_EC_KEY(pubkey); EC_KEY* ec_pubkey = EVP_PKEY_get1_EC_KEY(pubkey);
EVP_PKEY_free(pubkey); EVP_PKEY_free(pubkey);
if (!ec_pubkey) if (!ec_pubkey)