libzypp  17.38.7
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 <zypp-core/base/Logger.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  struct VerifySignatureLogic {
25 
26  VerifySignatureLogic( ContextRef &&zyppCtx, zypp::keyring::VerifyFileContext &&ctx )
27  : _zyppCtx( std::move(zyppCtx) )
28  , _verifyCtx( std::move(ctx) ) { }
29 
30  MaybeAwaitable<expected<zypp::keyring::VerifyFileContext>> execute () {
31 
32  const zypp::Pathname & sig { _verifyCtx.signature() };
33  if ( not ( sig.empty() || zypp::PathInfo(sig).isExist() ) ) {
34  return makeReadyTask( expected<zypp::keyring::VerifyFileContext>::error(ZYPP_EXCPT_PTR( zypp::SignatureCheckException("Signature " + sig.asString() + " not found.") )));
35  }
36 
37  MIL << "Checking " << _verifyCtx.file ()<< " file validity using digital signature.." << std::endl;
38 
40  | []( auto &&res ) {
41  if ( not res.first )
42  return expected<zypp::keyring::VerifyFileContext>::error( ZYPP_EXCPT_PTR( zypp::SignatureCheckException( "Signature verification failed for " + res.second.file().basename() ) ) );
43  return expected<zypp::keyring::VerifyFileContext>::success ( std::move( res.second ) );
44  };
45  }
46 
47  protected:
48  ContextRef _zyppCtx;
50  };
51  }
52 
53  namespace SignatureFileCheckWorkflow {
54  MaybeAwaitable<expected<zypp::keyring::VerifyFileContext> > verifySignature(ContextRef ctx, zypp::keyring::VerifyFileContext context )
55  {
56  VerifySignatureLogic impl( std::move(ctx), std::move(context) );
57  zypp_co_return zypp_co_await( impl.execute () );
58  }
59  }
60 }
#define MIL
Definition: Logger.h:103
Definition: ansi.h:854
I/O context for KeyRing::verifyFileSignatureWorkflow.
ContextRef _zyppCtx
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition: Exception.h:463
const Pathname & signature() const
Detached signature or empty.
bool isExist() const
Return whether valid stat info exists.
Definition: PathInfo.h:286
MaybeAwaitable< expected< zypp::keyring::VerifyFileContext > > verifySignature(ContextRef ctx, zypp::keyring::VerifyFileContext context)
const Pathname & file() const
File to verify.
static expected success(ConsParams &&...params)
Definition: expected.h:178
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:225
MaybeAwaitable< std::pair< bool, zypp::keyring::VerifyFileContext > > verifyFileSignature(ContextRef zyppContext, zypp::keyring::VerifyFileContext &&context_r)
Follows a signature verification interacting with the user.
Definition: keyringwf.cc:324
zypp::keyring::VerifyFileContext _verifyCtx