Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix certificate saving after policy table update #2218

Merged
merged 5 commits into from
Jun 18, 2018

Conversation

AKalinich-Luxoft
Copy link
Contributor

@AKalinich-Luxoft AKalinich-Luxoft commented May 25, 2018

Fixes #2191

This PR is ready for review.

Risk

This PR makes no API changes.

Testing Plan

Will be tested on the integration branch
Unit tests

Summary

SDL Core should update the module certificate in the local file system when a policy table update occurs. Currently SDL core is retrieving its certificate directly out of the policy table. This fix provides functionality for saving module certificate to the file system.

NOTE
This fix is closely related to #2217 and should be merged after it.
This fix should be merged after #2105 and #2068.

Changelog

Following changes were done:

  • Added getters for CertificatePath and KeyPath parameters in SecurityManagerSettings class to provide another components an access to these properties
  • Added methods for saving certificate and private key data to the files specified by CertificatePath and KeyPath keywords
  • CryptoManager component implementation was updated. Now this component also saves certificate data to files (if write permission allowed) after PTU

CLA

@@ -331,6 +336,8 @@ bool CryptoManagerImpl::set_certificate(const std::string& cert_data) {
return false;
}

// TODO(AKalinich): remove all lines below till the end of function when
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please remove the todo, as we can't merge these comments into develop?

Copy link
Contributor Author

@AKalinich-Luxoft AKalinich-Luxoft May 25, 2018

Choose a reason for hiding this comment

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

@mrapitis sure, but we should not forget to remove redundant lines of code after these two pull requests is merged
Fixed in 389a64f

@@ -300,7 +305,7 @@ const CryptoManagerSettings& CryptoManagerImpl::get_settings() const {
return *settings_;
}

bool CryptoManagerImpl::set_certificate(const std::string& cert_data) {
bool CryptoManagerImpl::SaveCertificateData(const std::string& cert_data) {
LOG4CXX_AUTO_TRACE(logger_);
Copy link
Contributor

Choose a reason for hiding this comment

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

Function doesn't change internal state, it should be const
It would be better function will be called with prefix "Is", IsSaveCertificateData

Copy link
Contributor

Choose a reason for hiding this comment

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

@AKalinich-Luxoft Agree with const , disagree with prefix Is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KVGrygoriev also disagree with prefix Is
Const added in 389a64f

@@ -411,4 +407,59 @@ void CryptoManagerImpl::InitCertExpTime() {
strptime("1 Jan 1970 00:00:00", "%d %b %Y %H:%M:%S", &expiration_time_);
}

bool CryptoManagerImpl::SaveModuleCertificateToFile(X509* certificate) const {
Copy link

Choose a reason for hiding this comment

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

Same as for PR #2217 - I suppose we should free allocated resources...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@olohvinenko thanks, fixed in 389a64f

@@ -300,7 +305,7 @@ const CryptoManagerSettings& CryptoManagerImpl::get_settings() const {
return *settings_;
}

bool CryptoManagerImpl::set_certificate(const std::string& cert_data) {
bool CryptoManagerImpl::SaveCertificateData(const std::string& cert_data) {
LOG4CXX_AUTO_TRACE(logger_);
Copy link
Contributor

Choose a reason for hiding this comment

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

@AKalinich-Luxoft Agree with const , disagree with prefix Is.


const std::string key_path = get_settings().module_key_path();
BIO* bio_key = BIO_new_file(key_path.c_str(), "w");
if (NULL == bio_key) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@AKalinich-Luxoft Use please if (!bio_key)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AByzhynar fixed in 389a64f

utils::ScopeGuard bio_guard = utils::MakeGuard(BIO_free, bio_key);
UNUSED(bio_guard);

if (0 == PEM_write_bio_PrivateKey(bio_key, key, NULL, NULL, 0, NULL, NULL)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@AKalinich-Luxoft Use please (!PEM_write_bio_PrivateKey...)
Like described here: PEM_write_bio_PrivateKey

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AByzhynar fixed in 389a64f

bool CryptoManagerImpl::SaveModuleKeyToFile(EVP_PKEY* key) const {
LOG4CXX_AUTO_TRACE(logger_);

if (NULL == key) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@AKalinich-Luxoft Same as above - if(!key)...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AByzhynar fixed in 389a64f

This was referenced May 29, 2018
@AKalinich-Luxoft AKalinich-Luxoft force-pushed the fix/fix_certificate_saving_after_ptu branch 2 times, most recently from cb0575a to 9ecb880 Compare May 30, 2018 10:50
@mrapitis
Copy link
Contributor

mrapitis commented Jun 5, 2018

@theresalech this PR is ready for review.

Currently, SDL Core ignores both the CertificatePath and KeyPath
keywords that would allow the system integrator to specify certificates
for their environment, instead SDL Core only processes the certificate
provided via the policy table.

This fix makes these keywords functional. Following changes were done:
- Added getters for CertificatePath and KeyPath parameters in
SecurityManagerSettings class to provide another components an access
to these properties
- Added methods for loading certificate and private key data from the
files specified by CertificatePath and KeyPath keywords
- CryptoManager component implementation was updated. Now this component
also read certificate data from files (if they are present and accessible)
on its own initialization
SDL Core should update the module certificate in the local file system when
a policy table update occurs. Currently SDL core is retrieving its
certificate directly out of the policy table.

This fix provides functionality for saving module certificate to the file
system. Following changes were done:
- Added getters for CertificatePath and KeyPath parameters in
SecurityManagerSettings class to provide another components an access
to these properties
- Added methods for saving certificate and private key data to the
files specified by CertificatePath and KeyPath keywords
- CryptoManager component implementation was updated. Now this component
also saves certificate data to files (if write permission allowed) after
PTU
Added new expectations for a security tests due to some
changes in the security flow
@Jack-Byrne
Copy link
Collaborator

@AKalinich-Luxoft Please resolve merge conflicts.

Conflicts:
	src/components/security_manager/src/crypto_manager_impl.cc
is_ptu_triggered_ = false;
#endif // ENABLE_SECURITY
}
void ProtocolHandlerImpl::OnPTUFinished(const bool ptu_result) {}
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 just remove this function if it doesn't do anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JackLivio yes, it has default empty implementation in base class.
Fixed in 0a7317d

Also was removed redundant logic
@AKalinich-Luxoft AKalinich-Luxoft force-pushed the fix/fix_certificate_saving_after_ptu branch from c0a84c8 to 0a7317d Compare June 18, 2018 19:13
@AKalinich-Luxoft
Copy link
Contributor Author

@JackLivio all conflicts was resolved

@Jack-Byrne Jack-Byrne merged commit a920e71 into develop Jun 18, 2018
@Jack-Byrne Jack-Byrne deleted the fix/fix_certificate_saving_after_ptu branch June 18, 2018 20:39
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants