14#include <zypp-media/ng/Provide>
15#include <zypp-media/ng/ProvideSpec>
16#include <zypp/ng/Context>
17#include <zypp/ng/repo/Downloader>
18#include <zypp-common/PublicKey.h>
30#undef ZYPP_BASE_LOGGER_LOGGROUP
31#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::repomanager"
39 template <
class Executor,
class OpType >
40 struct DownloadMasterIndexLogic :
public LogicBase<Executor, OpType>
47 using ProvideType =
typename ZyppContextType::ProvideType;
48 using MediaHandle =
typename ProvideType::MediaHandle;
52 : _dlContext( std::move(ctxRef) )
53 , _media(std::move( mediaHandle ))
54 , _masterIndex(std::move( masterIndex_r ))
58 MaybeAsyncRef<expected<DlContextRefType>> execute( ) {
60 _sigpath = _masterIndex.extend(
".asc" );
61 _keypath = _masterIndex.extend(
".key" );
62 _destdir = _dlContext->destDir();
64 auto providerRef = _dlContext->zyppContext()->provider();
71 |
and_then( ProvideType::copyResultToDest ( provider(), _destdir / _sigpath ) ),
73 |
and_then( ProvideType::copyResultToDest ( provider(), _destdir / _keypath ) ),
76 | [
this,masterres=std::move(masterres)]( std::vector<expected<zypp::ManagedFile>> &&res ) {
78 std::for_each( res.begin (), res.end(),
81 _dlContext->files().push_back( std::move(f.get()));
89 |
and_then( std::bind( &DownloadMasterIndexLogic::pluginVerification,
this, std::placeholders::_1 ) )
92 |
and_then( std::bind( &DownloadMasterIndexLogic::signatureCheck,
this, std::placeholders::_1 ) )
95 |
and_then( ProvideType::copyResultToDest ( providerRef, _destdir / _masterIndex ) )
100 _dlContext->repoInfo().setMetadataPath( _destdir );
101 _dlContext->repoInfo().setValidRepoSignature( _repoSigValidated );
104 _media = MediaHandle();
105 auto &allFiles = _dlContext->files();
108 allFiles.insert( allFiles.begin (), std::move(masterIndex) );
116 return _dlContext->zyppContext()->provider();
119 MaybeAsyncRef<expected<ProvideRes>> signatureCheck (
ProvideRes &&res ) {
121 if ( _dlContext->repoInfo().repoGpgCheck() ) {
128 if ( isSigned || _dlContext->repoInfo().repoGpgCheckIsMandatory() ) {
134 verifyCtx.signature( sigpathLocal );
139 _dlContext->zyppContext()->keyRing()->importKey( zypp::PublicKey(keypathLocal),
false );
147 verifyCtx.keyContext( _dlContext->repoInfo() );
149 return getExtraKeysInRepomd( std::move(res ) )
151 for (
const auto &keyData : _buddyKeys ) {
152 DBG <<
"Keyhint remember buddy " << keyData << std::endl;
153 vCtx.addBuddyKey( keyData.id() );
165 WAR <<
"Accept unsigned repository because repoGpgCheck is not mandatory for " << _dlContext->repoInfo().alias() << std::endl;
168 WAR <<
"Signature checking disabled in config of repository " << _dlContext->repoInfo().alias() << std::endl;
178 if ( _dlContext->pluginRepoverification() && _dlContext->pluginRepoverification()->isNeeded() ) {
180 _dlContext->pluginRepoverification()->getChecker( sigpathLocal, keypathLocal, _dlContext->repoInfo() )( prevRes.file() );
192 MaybeAsyncRef<expected<ProvideRes>> getExtraKeysInRepomd (
ProvideRes &&res ) {
194 if ( _masterIndex.basename() !=
"repomd.xml" ) {
199 if ( keyhints.empty() )
201 DBG <<
"Check keyhints: " << keyhints.size() << std::endl;
203 auto keyRing { _dlContext->zyppContext()->keyRing() };
205 |
transform([
this, keyRing]( std::pair<std::string, std::string> val ) {
207 const auto& [ file, keyid ] = val;
208 auto keyData = keyRing->trustedPublicKeyData( keyid );
210 DBG <<
"Keyhint is already trusted: " << keyid <<
" (" << file <<
")" << std::endl;
214 DBG <<
"Keyhint search key " << keyid <<
" (" << file <<
")" << std::endl;
216 keyData = keyRing->publicKeyData( keyid );
221 const zypp::ZConfig & conf = _dlContext->zyppContext()->config();
224 return zypp::PublicKey::noThrow(cacheFile)
225 | [ keyid = keyid ](
auto &&key ){
226 if ( key.fileProvidesKey( keyid ) )
232 auto providerRef = _dlContext->zyppContext()->provider();
233 return providerRef->provide( _media, file,
ProvideFileSpec().setOptional(
true) )
234 |
and_then( ProvideType::copyResultToDest( providerRef, _destdir / file ) )
238 _dlContext->files().push_back ( std::move(res) );
240 auto key = zypp::PublicKey::noThrow( _dlContext->files().back() );
241 if ( not key.fileProvidesKey( keyid ) ) {
242 const std::string
str = (
zypp::str::Str() <<
"Keyhint " << file <<
" does not contain a key with id " << keyid <<
". Skipping it.");
249 return providerRef->copyFile( key.path(), cacheFile )
253 res->resetDispose ();
259 |
and_then( [ keyRing, keyid = keyid ]( zypp::PublicKey key ){
260 keyRing->importKey( key,
false );
266 if ( keyData && *keyData ) {
267 if ( not zypp::PublicKey::isSafeKeyId( keyData->id() ) ) {
268 WAR <<
"Keyhint " << keyData->id() <<
" for " << *keyData <<
" is not strong enough for auto import. Just caching it." << std::endl;
271 _buddyKeys.push_back ( std::move(keyData.get()) );
275 MIL <<
"Check keyhints done. Buddy keys: " << _buddyKeys.size() << std::endl;
280 DlContextRefType _dlContext;
289 std::vector<zypp::PublicKeyData> _buddyKeys;
307 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
316 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
324 template <
class DlContextRefType,
class MediaHandleType>
325 auto statusImpl ( DlContextRefType dlCtx, MediaHandleType &&mediaHandle ) {
327 constexpr bool isAsync = std::is_same_v<DlContextRefType,repo::AsyncDownloadContextRef>;
333 switch( dlCtx->repoInfo().type().toEnum()) {
349 return statusImpl( dl, std::move(mediaHandle) );
353 return statusImpl( dl, std::move(mediaHandle) );
358 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
366 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
374 template <
class DlContextRefType,
class MediaHandleType>
375 auto downloadImpl ( DlContextRefType dlCtx, MediaHandleType &&mediaHandle, ProgressObserverRef &&progressObserver ) {
377 constexpr bool isAsync = std::is_same_v<DlContextRefType,repo::AsyncDownloadContextRef>;
379 switch( dlCtx->repoInfo().type().toEnum()) {
381 return RpmmdWorkflows::download( std::move(dlCtx), std::forward<MediaHandleType>(mediaHandle), std::move(progressObserver) );
396 return downloadImpl( dl, std::move(mediaHandle), std::move(progressObserver) );
401 return downloadImpl( dl, std::move(mediaHandle), std::move(progressObserver) );
407 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
409 return downloadImpl( dl, std::move(handle), std::move(po) );
416 return dl->zyppContext()->provider()->attachMediaIfNeeded( mediaHandle )
418 return downloadImpl( dl, std::move(handle), std::move(po) );
Interface of repomd.xml file reader.
Store and operate with byte count.
static const Unit MB
1000^2 Byte
Base class for Exception.
Track changing files or directories.
Interim helper class to collect global options and settings.
Pathname repoManagerRoot() const
The RepoManager root directory.
Pathname pubkeyCachePath() const
Path where the pubkey caches.
Wrapper class for stat/lstat.
bool isExist() const
Return whether valid stat info exists.
Pathname dirname() const
Return all but the last component od this path.
I/O context for KeyRing::verifyFileSignatureWorkflow.
bool fileValidated() const
Whether the signature was actually successfully verified.
Reads through a repomd.xml file and collects type, location, checksum and other data about metadata f...
std::vector< std::pair< std::string, std::string > > keyhints() const
gpg key hits shipped in keywords (bsc#1184326)
thrown when it was impossible to determine this repo type.
A ProvideRes object is a reference counted ownership of a resource in the cache provided by a Provide...
static expected success(ConsParams &&...params)
static expected error(ConsParams &&...params)
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
typename conditional< B, T, F >::type conditional_t
String related utilities and Regular expression matching.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
AsyncOpRef< expected< zypp::RepoStatus > > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver=nullptr)
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)
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
AsyncOpRef< expected< zypp::RepoStatus > > repoStatus(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle)
expected< zypp::keyring::VerifyFileContext > verifySignature(SyncContextRef ctx, zypp::keyring::VerifyFileContext context)
auto and_then(Fun &&function)
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
std::shared_ptr< AsyncOp< T > > AsyncOpRef
typename remove_smart_ptr< T >::type remove_smart_ptr_t
static expected< std::decay_t< Type >, Err > make_expected_success(Type &&t)
LazyMediaHandle< Provide > AsyncLazyMediaHandle
ResultType or_else(const expected< T, E > &exp, Function &&f)
ResultType and_then(const expected< T, E > &exp, Function &&f)
LazyMediaHandle< MediaSyncFacade > SyncLazyMediaHandle
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.