libzypp: zypp/ng/workflows/signaturecheckwf.cc Source File

libzypp 17.38.13

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>
16#include <zypp-media/filecheckexception.h>
17
18namespace 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
39 return KeyRingWorkflow::verifyFileSignature( _zyppCtx, zypp::keyring::VerifyFileContext( _verifyCtx ) )
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;
49 zypp::keyring::VerifyFileContext _verifyCtx;
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}
ZYPP_EXCPT_PTR
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:463
Logger.h
MIL
#define MIL
Definition Logger.h:103
ZYppFactory.h
zypp::filesystem::Pathname::asString
const std::string & asString() const
String representation.
Definition Pathname.h:94
zypp::filesystem::Pathname::empty
bool empty() const
Test for an empty path.
Definition Pathname.h:117
zypp::keyring::VerifyFileContext
I/O context for KeyRing::verifyFileSignatureWorkflow.
Definition KeyRingContexts.h:30
zyppng::expected::success
static expected success(ConsParams &&...params)
Definition expected.h:178
zyppng::expected::error
E & error()
Definition expected.h:288
filecheckexception.h
keyringwf.h
zyppng::KeyRingWorkflow::verifyFileSignature
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
zyppng::SignatureFileCheckWorkflow
Definition signaturecheckwf.cc:53
zyppng::SignatureFileCheckWorkflow::verifySignature
MaybeAwaitable< expected< zypp::keyring::VerifyFileContext > > verifySignature(ContextRef ctx, zypp::keyring::VerifyFileContext context)
Definition signaturecheckwf.cc:54
zyppng
Definition MediaNetworkRequestExecutor.h:16
signaturecheckwf.h
PathInfo.h