Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Be more careful with secondary public keys
Browse files Browse the repository at this point in the history
If we did not store a secondary public key (migrated from old storage
for example):
- store it later when we get it
- do not compare against the actual one, but do it on subsequent tries

Signed-off-by: Laurent Bonnans <laurent.bonnans@here.com>
  • Loading branch information
lbonn committed Feb 12, 2020
1 parent 16091a2 commit 0d0ece5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/libaktualizr-posix/ipuptanesecondary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ SecondaryInterface::Ptr IpUptaneSecondary::connectAndCheck(const std::string& ad
return nullptr;
}
auto p = sec->getPublicKey();
if (p != pub_key) {
LOG_WARNING << "Mismatch between public keys " << p.Value() << " and " << pub_key.Value() << " for secondary "
if (pub_key.Type() == KeyType::kUnknown) {
LOG_INFO << "Secondary " << s << " do not have a known public key";
} else if (p != pub_key) {
LOG_ERROR << "Mismatch between public keys " << p.Value() << " and " << pub_key.Value() << " for secondary "
<< serial;
return nullptr;
}
return sec;
}
Expand Down
7 changes: 5 additions & 2 deletions src/libaktualizr/primary/sotauptaneclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ void SotaUptaneClient::addSecondary(const std::shared_ptr<Uptane::SecondaryInter
Uptane::EcuSerial serial = sec->getSerial();

SecondaryInfo info;
if (!storage->loadSecondaryInfo(serial, &info) || info.type == "") {
if (!storage->loadSecondaryInfo(serial, &info) || info.type == "" || info.pub_key.Type() == KeyType::kUnknown) {
info.serial = serial;
info.hw_id = sec->getHwId();
info.type = sec->Type();
info.pub_key = sec->getPublicKey();
const PublicKey &p = sec->getPublicKey();
if (p.Type() != KeyType::kUnknown) {
info.pub_key = sec->getPublicKey();
}
storage->saveSecondaryInfo(info.serial, info.type, info.pub_key);
}

Expand Down

0 comments on commit 0d0ece5

Please sign in to comment.