3 #include "logging/logging.h" 4 #include "partialverificationsecondary.h" 5 #include "primary/secondaryinterface.h" 6 #include "utilities/exceptions.h" 11 : sconfig(
std::move(sconfig_in)), root_(Root::Policy::kAcceptAll) {
12 boost::filesystem::create_directories(sconfig.metadata_path);
15 std::string public_key_string;
16 if (!loadKeys(&public_key_string, &private_key_)) {
17 if (!Crypto::generateKeyPair(sconfig.key_type, &public_key_string, &private_key_)) {
18 LOG_ERROR <<
"Could not generate keys for secondary " << PartialVerificationSecondary::getSerial() <<
"@" 19 << sconfig.ecu_hardware_id;
20 throw std::runtime_error(
"Unable to generate secondary keys");
22 storeKeys(public_key_string, private_key_);
24 public_key_ =
PublicKey(public_key_string, sconfig.key_type);
30 detected_attack_.clear();
32 std::string director_root;
33 std::string director_targets;
34 if (!secondary_provider_->getDirectorMetadata(&director_root, &director_targets)) {
35 LOG_ERROR <<
"Unable to read Director metadata.";
40 root_ =
Uptane::Root(RepositoryType::Director(), Utils::parseJSON(director_root), root_);
41 Uptane::Targets targets(RepositoryType::Director(), Role::Targets(), Utils::parseJSON(director_targets),
42 std::make_shared<Uptane::Root>(root_));
43 if (meta_targets_.version() > targets.version()) {
44 detected_attack_ =
"Rollback attack detected";
47 meta_targets_ = targets;
56 int PartialVerificationSecondary::getRootVersion(
bool director)
const {
82 void PartialVerificationSecondary::storeKeys(
const std::string &public_key,
const std::string &private_key) {
83 Utils::writeFile((sconfig.full_client_dir / sconfig.ecu_private_key), private_key);
84 Utils::writeFile((sconfig.full_client_dir / sconfig.ecu_public_key), public_key);
87 bool PartialVerificationSecondary::loadKeys(std::string *public_key, std::string *private_key) {
88 boost::filesystem::path public_key_path = sconfig.full_client_dir / sconfig.ecu_public_key;
89 boost::filesystem::path private_key_path = sconfig.full_client_dir / sconfig.ecu_private_key;
91 if (!boost::filesystem::exists(public_key_path) || !boost::filesystem::exists(private_key_path)) {
95 *private_key = Utils::readFile(private_key_path.string());
96 *public_key = Utils::readFile(public_key_path.string());
Metadata verification failed.
SWM Internal integrity error.
Base data types that are used in The Update Framework (TUF), part of Uptane.