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

OTA-2499: Move IpUptaneSecondary & IpSecondaryDiscovery from libaktualizr #1175

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ unset(AKTUALIZR_CHECKED_SRCS CACHE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# find all required libraries
set(BOOST_COMPONENTS log_setup log filesystem program_options)
set(BOOST_COMPONENTS log_setup log system filesystem program_options)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need system again?

set(Boost_USE_STATIC_LIBS OFF)
add_definitions(-DBOOST_LOG_DYN_LINK)

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ endif()
add_subdirectory("libaktualizr")
add_subdirectory("sota_tools")
add_subdirectory("aktualizr_primary")
add_subdirectory("libaktualizr-posix")
add_subdirectory("aktualizr_secondary")
add_subdirectory("aktualizr_info")
add_subdirectory("aktualizr_repo")
Expand Down
4 changes: 3 additions & 1 deletion src/aktualizr_check_discovery/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
set(AKTUALIZR_CHECK_DISCOVERY_SRC main.cc )

add_executable(aktualizr-check-discovery ${AKTUALIZR_CHECK_DISCOVERY_SRC})
target_link_libraries(aktualizr-check-discovery aktualizr_static_lib ${AKTUALIZR_EXTERNAL_LIBS})
target_link_libraries(aktualizr-check-discovery aktualizr-posix ${AKTUALIZR_EXTERNAL_LIBS})

install(TARGETS aktualizr-check-discovery
COMPONENT aktualizr
RUNTIME DESTINATION bin)

target_include_directories(aktualizr-check-discovery PUBLIC ${PROJECT_SOURCE_DIR}/src/libaktualizr-posix)

aktualizr_source_file_checks(${AKTUALIZR_CHECK_DISCOVERY_SRC})

# vim: set tabstop=4 shiftwidth=4 expandtab:
2 changes: 1 addition & 1 deletion src/aktualizr_check_discovery/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "uptane/secondaryfactory.h"
#include "uptane/secondaryinterface.h"

#include "ipsecondarydiscovery.h"
#include "logging/logging.h"
#include "uptane/ipsecondarydiscovery.h"

namespace po = boost::program_options;

Expand Down
6 changes: 4 additions & 2 deletions src/aktualizr_secondary/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ set(AKTUALIZR_SECONDARY_LIB_SRC

add_library(aktualizr_secondary_static_lib STATIC
${AKTUALIZR_SECONDARY_LIB_SRC}
$<TARGET_OBJECTS:asn1>
$<TARGET_OBJECTS:asn1_lib>
$<TARGET_OBJECTS:bootloader>
$<TARGET_OBJECTS:crypto>
$<TARGET_OBJECTS:jsoncpp>
Expand All @@ -22,6 +20,8 @@ add_library(aktualizr_secondary_static_lib STATIC
$<TARGET_OBJECTS:uptane>
$<TARGET_OBJECTS:socket_activation>)

target_link_libraries(aktualizr_secondary_static_lib aktualizr-posix)

set(OPCUA_SECONDARY_SRC
opcuaserver_secondary_delegate.cc
aktualizr_secondary_opcua.cc
Expand All @@ -39,6 +39,7 @@ endif (BUILD_OPCUA)
target_include_directories(aktualizr_secondary_static_lib PUBLIC
$<TARGET_PROPERTY:socket_activation,INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:asn1_lib,INCLUDE_DIRECTORIES>
${PROJECT_SOURCE_DIR}/src/libaktualizr-posix
)

add_executable(aktualizr-secondary ${AKTUALIZR_SECONDARY_SRC})
Expand Down Expand Up @@ -81,6 +82,7 @@ if(BUILD_OSTREE)

add_aktualizr_test(NAME aktualizr_secondary_uptane
SOURCES uptane_test.cc
LIBRARIES aktualizr-posix
ARGS ${PROJECT_BINARY_DIR}/ostree_repo PROJECT_WORKING_DIRECTORY)
else(BUILD_OSTREE)
list(APPEND TEST_SOURCES aktualizr_secondary_discovery_test.cc uptane_test.cc)
Expand Down
2 changes: 1 addition & 1 deletion src/aktualizr_secondary/aktualizr_secondary_discovery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <sys/types.h>

#include "asn1/asn1-cerstream.h"
#include "ipsecondarydiscovery.h"
#include "logging/logging.h"
#include "socket_activation/socket_activation.h"
#include "uptane/ipsecondarydiscovery.h"
#include "utilities/sockaddr_io.h"
#include "utilities/utils.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "aktualizr_secondary_discovery.h"
#include "config/config.h"
#include "uptane/ipsecondarydiscovery.h" // to test from the other side
#include "ipsecondarydiscovery.h" // to test from the other side

#include "logging/logging.h"

Expand Down
29 changes: 29 additions & 0 deletions src/libaktualizr-posix/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
add_subdirectory("asn1")

set(SOURCES
ipuptanesecondary.cc
ipsecondarydiscovery.cc)

set(HEADERS
ipuptanesecondary.h
ipsecondarydiscovery.h)

set(TARGET aktualizr-posix)

add_library(${TARGET} STATIC
${SOURCES}
$<TARGET_OBJECTS:asn1>
$<TARGET_OBJECTS:asn1_lib>
)

get_property(ASN1_INCLUDE_DIRS TARGET asn1_lib PROPERTY INCLUDE_DIRECTORIES)
target_include_directories(${TARGET} PUBLIC ${ASN1_INCLUDE_DIRS})

target_link_libraries(${TARGET} aktualizr_static_lib)

add_aktualizr_test(NAME discovery_secondary
SOURCES ipsecondary_discovery_test.cc
LIBRARIES ${TARGET}
PROJECT_WORKING_DIRECTORY)

aktualizr_source_file_checks(${HEADERS} ${SOURCES} ipsecondary_discovery_test.cc)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ compile_asn1_lib(SOURCES
messages/tlsconfig.asn1
)

add_aktualizr_test(NAME asn1 SOURCES asn1_test.cc)
add_aktualizr_test(NAME asn1 LIBRARIES asn1 asn1_lib SOURCES asn1_test.cc)

aktualizr_source_file_checks(${SOURCES} ${HEADERS} ${TEST_SOURCES})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "asn1/asn1-cer.h"
#include "asn1-cer.h"
#include <algorithm>

static std::string cer_encode_length(size_t len) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "asn1/asn1-cerstream.h"
#include "asn1-cerstream.h"

namespace asn1 {

Expand Down Expand Up @@ -278,4 +278,5 @@ Deserializer& Deserializer::operator>>(const Token& tok) {
// seq_consumed.pop();
return *this;
}

} // namespace asn1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef ASN1_CER_STREAM_H
#define ASN1_CER_STREAM_H

#include "asn1/asn1-cer.h"
#include "asn1-cer.h"

#include <stack>
#include <utility>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "asn1/asn1_message.h"
#include "asn1_message.h"
#include "logging/logging.h"
#include "utilities/dequeue_buffer.h"
#include "utilities/sockaddr_io.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,50 @@
#include <iostream>
#include <string>

#include "asn1/asn1_message.h"
#include "asn1-cerstream.h"
#include "asn1_message.h"
#include "config/config.h"
#include "der_encoder.h"

asn1::Serializer& operator<<(asn1::Serializer& ser, CryptoSource cs) {
ser << asn1::implicit<kAsn1Enum>(static_cast<const int32_t&>(static_cast<int>(cs)));

return ser;
}

asn1::Serializer& operator<<(asn1::Serializer& ser, const TlsConfig& tls_conf) {
ser << asn1::seq << asn1::implicit<kAsn1Utf8String>(tls_conf.server)
<< asn1::implicit<kAsn1Utf8String>(tls_conf.server_url_path.string()) << tls_conf.ca_source
<< tls_conf.pkey_source << tls_conf.cert_source << asn1::endseq;
return ser;
}

asn1::Deserializer& operator>>(asn1::Deserializer& des, CryptoSource& cs) {
int32_t cs_i;
des >> asn1::implicit<kAsn1Enum>(cs_i);

if (cs_i < static_cast<int>(CryptoSource::kFile) || cs_i > static_cast<int>(CryptoSource::kPkcs11)) {
throw deserialization_error();
}

cs = static_cast<CryptoSource>(cs_i);

return des;
}

asn1::Deserializer& operator>>(asn1::Deserializer& des, boost::filesystem::path& path) {
std::string path_string;
des >> asn1::implicit<kAsn1Utf8String>(path_string);
path = path_string;
return des;
}

asn1::Deserializer& operator>>(asn1::Deserializer& des, TlsConfig& tls_conf) {
des >> asn1::seq >> asn1::implicit<kAsn1Utf8String>(tls_conf.server) >> tls_conf.server_url_path >>
tls_conf.ca_source >> tls_conf.pkey_source >> tls_conf.cert_source >> asn1::endseq;
return des;
}

void printStringHex(const std::string& s) {
for (char c : s) {
std::cerr << std::setfill('0') << std::setw(2) << std::hex << (((unsigned int)c) & 0xFF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <boost/program_options.hpp>

#include "config/config.h"
#include "ipsecondarydiscovery.h"
#include "logging/logging.h"
#include "test_utils.h"
#include "uptane/ipsecondarydiscovery.h"

std::string port;

Expand Down
3 changes: 0 additions & 3 deletions src/libaktualizr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
add_subdirectory("utilities")
add_subdirectory("asn1")
add_subdirectory("bootloader")
add_subdirectory("bootstrap")
add_subdirectory("campaign")
Expand All @@ -23,8 +22,6 @@ if (BUILD_OPCUA)
endif (BUILD_OPCUA)

add_library(aktualizr_static_lib STATIC
$<TARGET_OBJECTS:asn1>
$<TARGET_OBJECTS:asn1_lib>
$<TARGET_OBJECTS:bootloader>
$<TARGET_OBJECTS:bootstrap>
$<TARGET_OBJECTS:campaign>
Expand Down
39 changes: 0 additions & 39 deletions src/libaktualizr/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,42 +275,3 @@ void Config::writeToStream(std::ostream& sink) const {
WriteSectionToStream(telemetry, "telemetry", sink);
WriteSectionToStream(bootloader, "bootloader", sink);
}

asn1::Serializer& operator<<(asn1::Serializer& ser, CryptoSource cs) {
ser << asn1::implicit<kAsn1Enum>(static_cast<const int32_t&>(static_cast<int>(cs)));

return ser;
}

asn1::Serializer& operator<<(asn1::Serializer& ser, const TlsConfig& tls_conf) {
ser << asn1::seq << asn1::implicit<kAsn1Utf8String>(tls_conf.server)
<< asn1::implicit<kAsn1Utf8String>(tls_conf.server_url_path.string()) << tls_conf.ca_source
<< tls_conf.pkey_source << tls_conf.cert_source << asn1::endseq;
return ser;
}

asn1::Deserializer& operator>>(asn1::Deserializer& des, CryptoSource& cs) {
int32_t cs_i;
des >> asn1::implicit<kAsn1Enum>(cs_i);

if (cs_i < static_cast<int>(CryptoSource::kFile) || cs_i > static_cast<int>(CryptoSource::kPkcs11)) {
throw deserialization_error();
}

cs = static_cast<CryptoSource>(cs_i);

return des;
}

asn1::Deserializer& operator>>(asn1::Deserializer& des, boost::filesystem::path& path) {
std::string path_string;
des >> asn1::implicit<kAsn1Utf8String>(path_string);
path = path_string;
return des;
}

asn1::Deserializer& operator>>(asn1::Deserializer& des, TlsConfig& tls_conf) {
des >> asn1::seq >> asn1::implicit<kAsn1Utf8String>(tls_conf.server) >> tls_conf.server_url_path >>
tls_conf.ca_source >> tls_conf.pkey_source >> tls_conf.cert_source >> asn1::endseq;
return des;
}
5 changes: 0 additions & 5 deletions src/libaktualizr/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <boost/property_tree/ini_parser.hpp>

#include "asn1/asn1-cerstream.h"
#include "bootloader/bootloader.h"
#include "crypto/keymanager_config.h"
#include "crypto/p11_config.h"
Expand Down Expand Up @@ -48,9 +46,6 @@ struct TlsConfig {
void writeToStream(std::ostream& out_stream) const;
};

asn1::Serializer& operator<<(asn1::Serializer& ser, const TlsConfig& tls_conf);
asn1::Deserializer& operator>>(asn1::Deserializer& des, TlsConfig& tls_conf);

struct ProvisionConfig {
std::string server;
std::string p12_password;
Expand Down
6 changes: 0 additions & 6 deletions src/libaktualizr/primary/sotauptaneclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ SotaUptaneClient::SotaUptaneClient(Config &config_in, std::shared_ptr<INvStorage
bootloader->setBootOK();
}

if (config.discovery.ipuptane) {
IpSecondaryDiscovery ip_uptane_discovery{config.network};
auto ipuptane_secs = ip_uptane_discovery.discover();
config.uptane.secondary_configs.insert(config.uptane.secondary_configs.end(), ipuptane_secs.begin(),
ipuptane_secs.end());
}
std::vector<Uptane::SecondaryConfig>::const_iterator it;
for (it = config.uptane.secondary_configs.begin(); it != config.uptane.secondary_configs.end(); ++it) {
auto sec = Uptane::SecondaryFactory::makeSecondary(*it);
Expand Down
1 change: 0 additions & 1 deletion src/libaktualizr/primary/sotauptaneclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "uptane/exceptions.h"
#include "uptane/fetcher.h"
#include "uptane/imagesrepository.h"
#include "uptane/ipsecondarydiscovery.h"
#include "uptane/iterator.h"
#include "uptane/secondaryinterface.h"

Expand Down
8 changes: 0 additions & 8 deletions src/libaktualizr/uptane/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
set(SOURCES
fetcher.cc
ipsecondarydiscovery.cc
ipuptanesecondary.cc
iterator.cc
managedsecondary.cc
metawithkeys.cc
Expand All @@ -19,8 +17,6 @@ set(SOURCES
set(HEADERS
exceptions.h
fetcher.h
ipsecondarydiscovery.h
ipuptanesecondary.h
iterator.h
managedsecondary.h
partialverificationsecondary.h
Expand All @@ -46,10 +42,6 @@ if (BUILD_ISOTP)
target_include_directories(uptane PRIVATE ${PROJECT_SOURCE_DIR}/third_party/isotp-c/src)
endif (BUILD_ISOTP)

get_property(ASN1_INCLUDE_DIRS TARGET asn1_lib PROPERTY INCLUDE_DIRECTORIES)
target_include_directories(uptane PUBLIC ${ASN1_INCLUDE_DIRS})

add_aktualizr_test(NAME discovery_secondary SOURCES ipsecondary_discovery_test.cc PROJECT_WORKING_DIRECTORY)
add_aktualizr_test(NAME tuf SOURCES tuf_test.cc PROJECT_WORKING_DIRECTORY)
add_aktualizr_test(NAME tuf_hash SOURCES tuf_hash_test.cc PROJECT_WORKING_DIRECTORY)

Expand Down
3 changes: 0 additions & 3 deletions src/libaktualizr/uptane/secondaryfactory.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "uptane/secondaryfactory.h"

#include "logging/logging.h"
#include "uptane/ipuptanesecondary.h"
#include "uptane/virtualsecondary.h"

#ifdef ISOTP_SECONDARY_ENABLED
Expand All @@ -21,8 +20,6 @@ std::shared_ptr<SecondaryInterface> SecondaryFactory::makeSecondary(const Second
case SecondaryType::kLegacy:
LOG_ERROR << "Legacy secondary support is deprecated.";
return std::shared_ptr<SecondaryInterface>(); // NULL-equivalent
case SecondaryType::kIpUptane:
return std::make_shared<IpUptaneSecondary>(sconfig);
case SecondaryType::kIsoTpUptane:
#ifdef ISOTP_SECONDARY_ENABLED
return std::make_shared<IsoTpSecondary>(sconfig);
Expand Down