Skip to content
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

Renew certificate fix #159

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

mykola-kobets-epam
Copy link
Contributor

No description provided.

@mykola-kobets-epam mykola-kobets-epam changed the title Renew cert fix Renew certificate fix Sep 24, 2024
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 92.57143% with 13 lines in your changes missing coverage. Please review.

Project coverage is 88.30%. Comparing base (d615de5) to head (21b58da).
Report is 125 commits behind head on develop.

Files with missing lines Patch % Lines
src/iam/certmodules/pkcs11/pkcs11.cpp 73.91% 6 Missing ⚠️
src/iam/certhandler/certhandler.cpp 91.52% 5 Missing ⚠️
src/iam/certmodules/certmodule.cpp 77.77% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #159      +/-   ##
===========================================
+ Coverage    86.56%   88.30%   +1.74%     
===========================================
  Files           85      109      +24     
  Lines         7448     9310    +1862     
  Branches         0     1018    +1018     
===========================================
+ Hits          6447     8221    +1774     
- Misses        1001     1089      +88     

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

@mykola-kobets-epam mykola-kobets-epam changed the title Renew certificate fix [WIP] Renew certificate fix Sep 24, 2024
@mykola-kobets-epam mykola-kobets-epam force-pushed the renew-cert-fix branch 2 times, most recently from 0e89bcb to 4b10802 Compare September 27, 2024 08:15
*
* 1 per client & server + cIAMCertModulesMaxCount for message proxy
*/
constexpr auto cIAMCertSubsMaxCount = cIAMCertModulesMaxCount * 2 + cIAMCertModulesMaxCount;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It should be private of CertHandler const. Also unclear why we need +cIAMCertModulesMaxCount

Copy link
Contributor Author

@mykola-kobets-epam mykola-kobets-epam Oct 3, 2024

Choose a reason for hiding this comment

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

1 per client & server + cIAMCertModulesMaxCount for message proxy
Comment updated, constant moved to private section.

return ErrorEnum::eNone;
}

Error CertHandler::UnsubscribeCertReceiver(CertReceiverItf& certReceiver)
{
LockGuard lock(mMutex);
Copy link
Collaborator

Choose a reason for hiding this comment

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

LockGuard lock {mMutex};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated in a separate pr for all the files.

*
* @param info certificate info.
*/
void UpdateCert(const CertInfo& info)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It should not be part of interface. The client should have access only to required methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

interface updated

@mykola-kobets-epam mykola-kobets-epam force-pushed the renew-cert-fix branch 4 times, most recently from 7b9694e to 218e614 Compare October 3, 2024 19:17
CertInfo certInfo;

for (auto& subscription : mCertReceiverSubscriptions) {
auto err = certModule.GetCertificate(Array<uint8_t>(), Array<uint8_t>(), certInfo);
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't get why GetCertificate is called on each iteration, not before the loop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, it's not needed, fixed. also added a filter for certype in the method

{
LockGuard lock(mMutex);

LOG_DBG() << "Create self signed cert: type = " << certType;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove spaces, so
`Create self signed cert: type='

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 a separate commit for the file

@@ -145,4 +145,18 @@ Error ProvisionManager::GetCert(
return AOS_ERROR_WRAP(mCertHandler->GetCertificate(certType, issuer, serial, resCert));
}

Error ProvisionManager::SubscribeCertReceiver(const String& certType, certhandler::CertReceiverItf& certReceiver)
{
LOG_DBG() << "Subscribe cert receiver: type = " << certType;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove spaces surrounding =

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

class CertReceiverItf {
public:
/**
* Process certificate updates.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Processes

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

* @param certReceiver certificate receiver.
* @returns Error.
*/
virtual Error SubscribeCertReceiver(const String& certType, CertReceiverItf& certReceiver) = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

SubscribeCertChanged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it would be more uniform. changed

@@ -221,16 +271,34 @@ class CertHandler : public CertHandlerItf, private NonCopyable {
virtual ~CertHandler();

private:
// (Two subscriptions for grpc client & server in iam/sm/cm/um) * modules count +
// (one subscription for grpc client in message proxy) * modules count
static constexpr auto cIAMCertSubsMaxCount = cIAMCertModulesMaxCount * 2 + cIAMCertModulesMaxCount;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like in general we need only one subscription per storage. So cIAMCertModulesMaxCount should be enough. Also, we can't have this option as const. Add dedicated define to config.hpp with default value equals to modules max count.

Copy link
Contributor Author

@mykola-kobets-epam mykola-kobets-epam Oct 4, 2024

Choose a reason for hiding this comment

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

I think we need cIAMCertModulesMaxCount * 2 : one per aos service for client & service, because it looks like message-proxy doesn't use IAMServer to receive certificates.
Also there is a correlation between required number of subscriptions & aos-modules, so we don't need additional config value.. the less configuration values we have - the better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I still do not understand why we need 3*cIAMCertModulesMaxCount subscriptions. Could you provide the example?

Please add dedicated configuration into config and set it to appropriate default value. Having config value doesn't mean configuring it all the time. But it make either to change this value in the feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

one for sm/um/cm grpc server in communication manager + one for iam grpc server in iammanager
one for grpc client in sm/um/iam manager
And I was expected that message proxy also requested certificates using iam public interface. But it looks like it's not.
So we only require 2*cert-modules-max-count.

Copy link
Collaborator

@al1img al1img Oct 7, 2024

Choose a reason for hiding this comment

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

I see. MP uses SM and IAM client certificates and probably will use UM client certificates as well. We can't predict future client configuration. That's why config option is REQUIRED. And should be set to 3*AOS_CONFIG_CERTHANDLER_MODULES_MAX_COUNT.

Copy link
Contributor Author

@mykola-kobets-epam mykola-kobets-epam Oct 7, 2024

Choose a reason for hiding this comment

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

Please add dedicated configuration into config and set it to appropriate default value.

Added in a separate commit

@mykola-kobets-epam mykola-kobets-epam force-pushed the renew-cert-fix branch 3 times, most recently from 91fca3c to 278ade4 Compare October 7, 2024 12:21
CertInfo certInfo;

auto err = module->GetCertificate(Array<uint8_t>(), Array<uint8_t>(), certInfo);
if (!err.IsNone()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider this change

Suggested change
if (!err.IsNone()) {
if (!err.IsNone() && !err.Is(ErrorEnum::eNotFound)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed not to do that

@mykola-kobets-epam mykola-kobets-epam changed the title [WIP] Renew certificate fix Renew certificate fix Oct 21, 2024
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