17 #include <zypp-media/ng/Provide> 18 #include <zypp-media/ng/ProvideSpec> 19 #include <zypp/ng/Context> 20 #include <zypp/ng/repo/Downloader> 21 #include <zypp-common/PublicKey.h> 35 #undef ZYPP_BASE_LOGGER_LOGGROUP 36 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::repomanager" 44 template <
class Executor,
class OpType >
45 struct DownloadMasterIndexLogic :
public LogicBase<Executor, OpType>
51 using ZyppContextType =
typename remove_smart_ptr_t<DlContextRefType>::ContextType;
52 using ProvideType =
typename ZyppContextType::ProvideType;
53 using MediaHandle =
typename ProvideType::MediaHandle;
54 using ProvideRes =
typename ProvideType::Res;
58 ,
_media(std::move( mediaHandle ))
63 MaybeAsyncRef<expected<DlContextRefType>> execute( ) {
71 auto providerRef =
_dlContext->zyppContext()->provider();
73 |
and_then( [
this]( ProvideRes && masterres ) {
83 | [
this]( expected<zypp::ManagedFile> sigFile ) {
88 _dlContext->files().push_back( std::move(*sigFile) );
92 if ( expKeyId && !
_dlContext->zyppContext()->keyRing()->isKeyKnown(*expKeyId) ) {
94 if (
_dlContext->repoInfo().mirrorListUrl().isValid() ) {
97 JobReportHelper(
_dlContext->zyppContext() ).warning(
_(
"Downloading signature key via mirrors, consider explicitely setting gpgKeyUrl via the repository configuration instead."));
104 _dlContext->files().push_back( std::move(keyFile));
113 | [
this,masterres=std::move(masterres)]( expected<void> ) {
119 |
and_then( std::bind( &DownloadMasterIndexLogic::pluginVerification,
this, std::placeholders::_1 ) )
122 |
and_then( std::bind( &DownloadMasterIndexLogic::signatureCheck,
this, std::placeholders::_1 ) )
138 allFiles.insert( allFiles.begin (), std::move(masterIndex) );
149 MaybeAsyncRef<expected<ProvideRes>> signatureCheck ( ProvideRes &&res ) {
151 if (
_dlContext->repoInfo().repoGpgCheck() ) {
158 if ( isSigned ||
_dlContext->repoInfo().repoGpgCheckIsMandatory() ) {
169 _dlContext->zyppContext()->keyRing()->importKey( zypp::PublicKey(keypathLocal),
false );
177 verifyCtx.keyContext(
_dlContext->repoInfo() );
179 return getExtraKeysInRepomd( std::move(res ) )
180 |
and_then([
this, vCtx = std::move(verifyCtx) ]( ProvideRes &&res )
mutable {
182 DBG <<
"Keyhint remember buddy " << keyData << std::endl;
183 vCtx.addBuddyKey( keyData.id() );
195 WAR <<
"Accept unsigned repository because repoGpgCheck is not mandatory for " <<
_dlContext->repoInfo().alias() << std::endl;
198 WAR <<
"Signature checking disabled in config of repository " <<
_dlContext->repoInfo().alias() << std::endl;
204 expected<ProvideRes> pluginVerification ( ProvideRes &&prevRes ) {
209 if (
_dlContext->pluginRepoverification() &&
_dlContext->pluginRepoverification()->isNeeded() ) {
213 auto kr =
_dlContext->zyppContext()->keyRing();
217 MIL <<
"Failed to read signature from file: " << sigpathLocal << std::endl;
219 std::ofstream os( keypathLocal.c_str() );
220 if ( kr->isKeyKnown(*expKeyId) ) {
223 kr->isKeyTrusted(*expKeyId),
230 _dlContext->pluginRepoverification()->getChecker( sigpathLocal, keypathLocal,
_dlContext->repoInfo() )( prevRes.file() );
242 MaybeAsyncRef<expected<ProvideRes>> getExtraKeysInRepomd ( ProvideRes &&res ) {
249 if ( keyhints.empty() )
251 DBG <<
"Check keyhints: " << keyhints.size() << std::endl;
253 auto keyRing {
_dlContext->zyppContext()->keyRing() };
255 |
transform([
this, keyRing]( std::pair<std::string, std::string> val ) {
257 const auto& [ file, keyid ] = val;
258 auto keyData = keyRing->trustedPublicKeyData( keyid );
260 DBG <<
"Keyhint is already trusted: " << keyid <<
" (" << file <<
")" << std::endl;
264 DBG <<
"Keyhint search key " << keyid <<
" (" << file <<
")" << std::endl;
266 keyData = keyRing->publicKeyData( keyid );
274 return zypp::PublicKey::noThrow(cacheFile)
275 | [ keyid = keyid ](
auto &&key ){
276 if ( key.fileProvidesKey( keyid ) )
281 |
or_else ([
this, file = file, keyid = keyid, cacheFile ] (
auto )
mutable -> MaybeAsyncRef<expected<zypp::PublicKey>> {
282 auto providerRef =
_dlContext->zyppContext()->provider();
283 return providerRef->provide(
_media, file, ProvideFileSpec().setOptional(
true) )
288 _dlContext->files().push_back ( std::move(res) );
290 auto key = zypp::PublicKey::noThrow(
_dlContext->files().back() );
291 if ( not key.fileProvidesKey( keyid ) ) {
292 const std::string
str = (
zypp::str::Str() <<
"Keyhint " << file <<
" does not contain a key with id " << keyid <<
". Skipping it.");
299 return providerRef->copyFile( key.path(), cacheFile )
300 | [ key ]( expected<zypp::ManagedFile> res )
mutable {
303 res->resetDispose ();
309 |
and_then( [ keyRing, keyid = keyid ]( zypp::PublicKey key ){
310 keyRing->importKey( key,
false );
314 | [
this, res = res] ( std::vector<expected<zypp::PublicKeyData>> &&keyHints )
mutable {
315 std::for_each( keyHints.begin(), keyHints.end(), [
this]( expected<zypp::PublicKeyData> &keyData ){
316 if ( keyData && *keyData ) {
317 if ( not zypp::PublicKey::isSafeKeyId( keyData->id() ) ) {
318 WAR <<
"Keyhint " << keyData->id() <<
" for " << *keyData <<
" is not strong enough for auto import. Just caching it." << std::endl;
321 _buddyKeys.push_back ( std::move(keyData.get()) );
325 MIL <<
"Check keyhints done. Buddy keys: " <<
_buddyKeys.size() << std::endl;
357 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
366 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
374 template <
class DlContextRefType,
class MediaHandleType>
375 auto statusImpl ( DlContextRefType dlCtx, MediaHandleType &&mediaHandle ) {
377 constexpr
bool isAsync = std::is_same_v<DlContextRefType,repo::AsyncDownloadContextRef>;
383 switch( dlCtx->repoInfo().type().toEnum()) {
399 return statusImpl( dl, std::move(mediaHandle) );
403 return statusImpl( dl, std::move(mediaHandle) );
408 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
416 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
424 template <
class DlContextRefType,
class MediaHandleType>
425 auto downloadImpl ( DlContextRefType dlCtx, MediaHandleType &&mediaHandle, ProgressObserverRef &&progressObserver ) {
427 constexpr
bool isAsync = std::is_same_v<DlContextRefType,repo::AsyncDownloadContextRef>;
429 switch( dlCtx->repoInfo().type().toEnum()) {
431 return RpmmdWorkflows::download( std::move(dlCtx), std::forward<MediaHandleType>(mediaHandle), std::move(progressObserver) );
446 return downloadImpl( dl, std::move(mediaHandle), std::move(progressObserver) );
451 return downloadImpl( dl, std::move(mediaHandle), std::move(progressObserver) );
457 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
459 return downloadImpl( dl, std::move(handle), std::move(po) );
466 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
468 return downloadImpl( dl, std::move(handle), std::move(po) );
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver=nullptr)
auto mtry(Fun &&function)
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
thrown when it was impossible to determine this repo type.
auto transform(Transformation &&transformation)
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Store and operate with byte count.
Pathname pubkeyCachePath() const
Path where the pubkey caches.
Pathname extend(const std::string &r) const
Append string r to the last component of the path.
zypp::Pathname _masterIndex
String related utilities and Regular expression matching.
zypp::TriBool _repoSigValidated
What is known about a repository.
static expected< std::decay_t< Type >, Err > make_expected_success(Type &&t)
I/O context for KeyRing::verifyFileSignatureWorkflow.
static const Unit MB
1000^2 Byte
std::string basename() const
Return the last component of this path.
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
expected< void > fetchGpgKeys(SyncContextRef ctx, zypp::RepoInfo info)
Pathname repoManagerRoot() const
The RepoManager root directory.
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
auto or_else(Fun &&function)
const Pathname & signature() const
Detached signature or empty.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
bool isExist() const
Return whether valid stat info exists.
Pathname dirname() const
Return all but the last component od this path.
Interim helper class to collect global options and settings.
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > downloadMasterIndex(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, zypp::filesystem::Pathname masterIndex_r)
AsyncOpRef< expected< zypp::RepoStatus > > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
DlContextRefType _dlContext
typename conditional< B, T, F >::type conditional_t
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
static expected success(ConsParams &&...params)
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Reads through a repomd.xml file and collects type, location, checksum and other data about metadata f...
AsyncOpRef< expected< zypp::RepoStatus > > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
Base class for Exception.
expected< zypp::keyring::VerifyFileContext > verifySignature(SyncContextRef ctx, zypp::keyring::VerifyFileContext context)
AsyncOpRef< expected< zypp::RepoStatus > > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
auto and_then(Fun &&function)
Wrapper class for ::stat/::lstat.
Interface of repomd.xml file reader.
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
ResultType and_then(const expected< T, E > &exp, Function &&f)
Track changing files or directories.
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
std::string readSignatureKeyId(const Pathname &signature)
reads the public key id from a signature
std::vector< zypp::PublicKeyData > _buddyKeys