Skip to content

Conversation

mykola-kobets-epam
Copy link
Contributor

No description provided.

Copy link
Member

@mlohvynenko mlohvynenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-by: Mykhailo Lohvynenko <[email protected]>

@al1img
Copy link
Collaborator

al1img commented Sep 11, 2025

Move all crypto interfaces into itf folder and crypto.md with class diagram and basic module description. I've added separate task to add full crypto design document.

* @param[out] urls result URLs.
* @return Error.
*/
Error GetServiceDiscoveryURLs(Array<StaticString<cURLLen>>& urls);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this function should be moved to communication module

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

under discussion

/**
* Stub implementation of CertProviderItf.
*/
class CertProviderStub : public iam::certhandler::CertProviderItf {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be usefull to put it into separate file under common/tests/stubs/certproviderstub.hpp

/**
* Maximum number of private keys in crypto provider.
*/
#ifndef AOS_CONFIG_CRYPTO_MAX_PRIV_KEY_COUNT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have AOS_CONFIG_CRYPTO_KEYS_COUNT I guess it can be used here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* Private
**********************************************************************************************************************/

Time MbedTLSCryptoProvider::mCurrentTime;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to static section

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed in the latest commit

const Array<uint8_t>& cipher, const crypto::DecryptionOptions& options, Array<uint8_t>& result) const
{
CK_MECHANISM mechanism = {CKM_RSA_PKCS, nullptr, 0};
struct PCKS11MechConverter : public StaticVisitor<RetWithError<CK_MECHANISM>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it could be used by some other methods in future

/**
* Max number of certificates.
*/
constexpr auto cMaxNumCertificates = AOS_CONFIG_CRYPTO_MAX_NUM_CERTIFICATES;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move it to types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically, it mostly used in crypto module. all others still have to include crypto to have certificate type. so I'd keep it here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then other consts related to crypto should be moved there, for example:

/**

  • SHA256 size.
    */
    constexpr auto cSHA256Size = 32;

/**

  • SHA3-224 size.
    */
    constexpr auto cSHA3_224Size = 28;

auto worker = [&]() {
LockGuard lock {sem};

int cur = ++currentRunning;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is potential race condition between inc currentRunning and store load max running. Butter to do not use atomic here but just use mutex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed with mutex


static constexpr size_t cReadChunkSize = 1024;

static constexpr auto cMaxSimultaneousThreads = 2;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add AOS_CONFIG_TYPES_MUX_CONCURRENT_ITEMS to types. It will be used for other modules as well.

std::vector<TestData> testData = {
{{online, intermediateCA, secondaryCA}, CreateCertChain("online", {"online", "intermediateCA", "secondaryCA"}),
CreateSigns("online", "RSA/SHA256/PKCS1v1_5")},

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// Verify target certificate.
uint32_t flags = 0;
int ret = mbedtls_x509_crt_verify(&interm, &root, nullptr, nullptr, &flags, nullptr, nullptr);
int ret = mbedtls_x509_crt_verify(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (!err.IsNone()) {
*flags |= MBEDTLS_X509_BADCERT_OTHER;

return 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return MBEDTLS_ERR_X509_CERT_VERIFY_FAILED; ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems MBEDTLS_ERR_X509_CERT_VERIFY_FAILED is an error code, not flag

Signed-off-by: Mykola Kobets <[email protected]>
Copy link

codecov bot commented Sep 19, 2025

Codecov Report

❌ Patch coverage is 70.80925% with 707 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.28%. Comparing base (ae6ed40) to head (32efc60).

Files with missing lines Patch % Lines
src/core/common/crypto/openssl/cryptoprovider.cpp 56.85% 258 Missing ⚠️
src/core/common/crypto/mbedtls/cryptoprovider.cpp 69.31% 205 Missing ⚠️
src/core/common/crypto/cryptohelper.cpp 70.85% 153 Missing ⚠️
src/core/common/pkcs11/privatekey.cpp 17.77% 37 Missing ⚠️
src/core/common/crypto/openssl/opensslprovider.cpp 27.27% 16 Missing ⚠️
...e/common/tests/crypto/providers/opensslfactory.cpp 7.14% 13 Missing ⚠️
src/core/common/tools/fs.cpp 84.78% 7 Missing ⚠️
...rc/core/common/crypto/tests/stubs/certprovider.hpp 73.68% 5 Missing ⚠️
src/core/common/crypto/tests/cryptohelper.cpp 97.19% 3 Missing ⚠️
...e/common/tests/crypto/providers/mbedtlsfactory.cpp 89.28% 3 Missing ⚠️
... and 4 more
Additional details and impacted files
@@                   Coverage Diff                   @@
##           feature_unification     #354      +/-   ##
=======================================================
- Coverage                81.44%   80.28%   -1.17%     
=======================================================
  Files                      179      183       +4     
  Lines                    17231    19487    +2256     
  Branches                  2320     2730     +410     
=======================================================
+ Hits                     14034    15645    +1611     
- Misses                    3197     3842     +645     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots
34.4% Coverage on New Code (required ≥ 80%)
8.7% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link

@MykolaSuperman MykolaSuperman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-by: Mykola Solianko <[email protected]>

* @param[out] buffer destination buffer.
* @return Error.
*/
Error WriteBlock(Array<uint8_t>& buffer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider accepting a const ref and returning RetWithError<size_t> bytes written

@@ -0,0 +1,406 @@
#
# Copyright (C) 2024 Renesas Electronics Corporation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright (C) 2024 Renesas Electronics Corporation.

@@ -0,0 +1,406 @@
#
# Copyright (C) 2024 Renesas Electronics Corporation.
# Copyright (C) 2024 EPAM Systems, Inc.
Copy link
Member

@mlohvynenko mlohvynenko Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright (C) 2024 EPAM Systems, Inc.
# Copyright (C) 2025 EPAM Systems, Inc.

Copy link
Member

@mlohvynenko mlohvynenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-by: Mykhailo Lohvynenko <[email protected]>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants