-
Notifications
You must be signed in to change notification settings - Fork 6
Crypto refactoring #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
al1img
merged 8 commits into
aosedge:feature_unification
from
mykola-kobets-epam:crypto-refactoring
Oct 14, 2025
Merged
Crypto refactoring #382
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a1c9992
gitignore: add .cache to .gitignore
mykola-kobets-epam d4d06b7
crypto: split crypto.hpp on dedicated header files
mykola-kobets-epam 0cf6565
crypto: rename crypto.cpp to asn1.cpp
mykola-kobets-epam 87586f5
crypto: rename cryptoutils to certloader
mykola-kobets-epam 4314cb1
all: fix crypto includes
mykola-kobets-epam 8dd0b17
crypto: adapt crypto module to interface reloacations
mykola-kobets-epam 35d8dc6
common: add WITH_TEST_TOOLS to provide test tools with disabled tests
mykola-kobets-epam 7b8815c
crypto: add crypto documentation
mykola-kobets-epam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
build/* | ||
.vscode/* | ||
.cache/* | ||
.*/*\!.github | ||
CMakeUserPresets.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (C) 2023 Renesas Electronics Corporation. | ||
* Copyright (C) 2023 EPAM Systems, Inc. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef AOS_CORE_COMMON_CRYPTO_CRYPTOUTILS_HPP_ | ||
#define AOS_CORE_COMMON_CRYPTO_CRYPTOUTILS_HPP_ | ||
|
||
#include <core/common/pkcs11/pkcs11.hpp> | ||
#include <core/common/pkcs11/privatekey.hpp> | ||
|
||
#include "itf/certloader.hpp" | ||
#include "itf/crypto.hpp" | ||
|
||
namespace aos::crypto { | ||
|
||
/** | ||
* Loads certificates and keys by URL. | ||
*/ | ||
class CertLoader : public CertLoaderItf { | ||
public: | ||
/** | ||
* Initializes object instance. | ||
* | ||
* @param cryptoProvider crypto provider interface. | ||
* @param pkcs11Manager PKCS11 library manager. | ||
* @return Error. | ||
*/ | ||
Error Init(x509::ProviderItf& cryptoProvider, pkcs11::PKCS11Manager& pkcs11Manager); | ||
|
||
/** | ||
* Loads certificate chain by URL. | ||
* | ||
* @param url input url. | ||
* @return RetWithError<SharedPtr<x509::CertificateChain>>. | ||
*/ | ||
RetWithError<SharedPtr<x509::CertificateChain>> LoadCertsChainByURL(const String& url) override; | ||
|
||
/** | ||
* Loads private key by URL. | ||
* | ||
* @param url input url. | ||
* @return RetWithError<SharedPtr<PrivateKeyItf>>. | ||
*/ | ||
RetWithError<SharedPtr<PrivateKeyItf>> LoadPrivKeyByURL(const String& url) override; | ||
|
||
private: | ||
using PEMCertChainBlob = StaticString<cCertPEMLen * cCertChainSize>; | ||
|
||
static constexpr auto cCertAllocatorSize | ||
= cCertChainsCount * cCertChainSize * sizeof(x509::Certificate) + sizeof(PEMCertChainBlob); | ||
static constexpr auto cKeyAllocatorSize | ||
= AOS_CONFIG_CRYPTO_PRIV_KEYS_COUNT * pkcs11::cPrivateKeyMaxSize + sizeof(cPrivKeyPEMLen); | ||
static constexpr auto cNumAllocation = AOS_CONFIG_CRYPTO_NUM_ALLOCATIONS; | ||
|
||
static constexpr auto cDefaultPKCS11Library = AOS_CONFIG_CRYPTO_DEFAULT_PKCS11_LIB; | ||
|
||
RetWithError<SharedPtr<pkcs11::SessionContext>> OpenSession( | ||
const String& libraryPath, const String& token, const String& userPIN); | ||
RetWithError<pkcs11::SlotID> FindToken(const pkcs11::LibraryContext& library, const String& token); | ||
|
||
RetWithError<SharedPtr<x509::CertificateChain>> LoadCertsFromFile(const String& fileName); | ||
RetWithError<SharedPtr<PrivateKeyItf>> LoadPrivKeyFromFile(const String& fileName); | ||
|
||
x509::ProviderItf* mCryptoProvider = nullptr; | ||
pkcs11::PKCS11Manager* mPKCS11 = nullptr; | ||
|
||
StaticAllocator<cCertAllocatorSize + cKeyAllocatorSize + pkcs11::Utils::cLocalObjectsMaxSize, cNumAllocation> | ||
mAllocator; | ||
}; | ||
|
||
} // namespace aos::crypto | ||
|
||
#endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is produced this folder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is produced by clangd server