libzypp  17.36.3
signaturecheckwf.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 
10 #include "signaturecheckwf.h"
11 #include "keyringwf.h"
12 #include "logichelpers.h"
13 
14 #include <zypp/ZYppFactory.h>
15 #include <zypp-core/fs/PathInfo.h>
17 
18 namespace zyppng {
19 
20  namespace {
21 
22  using namespace zyppng::operators;
23 
24  template <class Executor, class OpType>
25  struct VerifySignatureLogic : public LogicBase<Executor,OpType> {
26 
27  ZYPP_ENABLE_LOGIC_BASE(Executor,OpType);
28  using ZyppContextRefType = MaybeAsyncContextRef<OpType>;
29 
30  VerifySignatureLogic( ZyppContextRefType &&zyppCtx, zypp::keyring::VerifyFileContext &&ctx )
31  : _zyppCtx( std::move(zyppCtx) )
32  , _verifyCtx( std::move(ctx) ) { }
33 
34  MaybeAsyncRef<expected<zypp::keyring::VerifyFileContext>> execute () {
35 
36  const zypp::Pathname & sig { _verifyCtx.signature() };
37  if ( not ( sig.empty() || zypp::PathInfo(sig).isExist() ) ) {
39  }
40 
41  MIL << "Checking " << _verifyCtx.file ()<< " file validity using digital signature.." << std::endl;
42 
44  | []( auto &&res ) {
45  if ( not res.first )
46  return expected<zypp::keyring::VerifyFileContext>::error( ZYPP_EXCPT_PTR( zypp::SignatureCheckException( "Signature verification failed for " + res.second.file().basename() ) ) );
47  return expected<zypp::keyring::VerifyFileContext>::success ( std::move( res.second ) );
48  };
49  }
50 
51  protected:
52  ZyppContextRefType _zyppCtx;
54  };
55  }
56 
57  namespace SignatureFileCheckWorkflow {
59  {
60  return SimpleExecutor<VerifySignatureLogic, SyncOp<expected<zypp::keyring::VerifyFileContext>>>::run( std::move(ctx), std::move(context) );
61  }
62 
64  {
65  return SimpleExecutor<VerifySignatureLogic, AsyncOp<expected<zypp::keyring::VerifyFileContext>>>::run( std::move(ctx), std::move(context) );
66  }
67  }
68 }
#define MIL
Definition: Logger.h:100
ZyppContextRefType _zyppCtx
Definition: Arch.h:363
I/O context for KeyRing::verifyFileSignatureWorkflow.
std::pair< bool, zypp::keyring::VerifyFileContext > verifyFileSignature(SyncContextRef zyppContext, zypp::keyring::VerifyFileContext &&context_r)
Follows a signature verification interacting with the user.
Definition: keyringwf.cc:332
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition: Exception.h:428
const Pathname & signature() const
Detached signature or empty.
bool isExist() const
Return whether valid stat info exists.
Definition: PathInfo.h:286
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
Definition: logichelpers.h:223
const Pathname & file() const
File to verify.
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
Definition: asyncop.h:297
static expected success(ConsParams &&...params)
Definition: expected.h:115
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Definition: asyncop.h:255
expected< zypp::keyring::VerifyFileContext > verifySignature(SyncContextRef ctx, zypp::keyring::VerifyFileContext context)
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:225
zypp::keyring::VerifyFileContext _verifyCtx