libzypp 17.37.10

FileChecker.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <utility>
14#include <zypp/base/Logger.h>
15#include <zypp/FileChecker.h>
16#include <zypp/ZYppFactory.h>
17#include <zypp/Digest.h>
18#include <zypp/KeyRing.h>
19#include <zypp/ng/workflows/keyringwf.h>
20#include <zypp/ng/workflows/checksumwf.h>
21#include <zypp/ng/workflows/signaturecheckwf.h>
22
23 using std::endl;
24
25#undef ZYPP_BASE_LOGGER_LOGGROUP
26#define ZYPP_BASE_LOGGER_LOGGROUP "FileChecker"
27
29 namespace zypp
30{
31
32 ChecksumFileChecker::ChecksumFileChecker( CheckSum checksum )
33 : _checksum(std::move(checksum))
34 {}
35
36 void ChecksumFileChecker::operator()( const Pathname &file ) const
37 {
38 const auto &res = zyppng::CheckSumWorkflow::verifyChecksum ( zyppng::SyncContext::create(), _checksum, file );
39 if ( !res ) {
40 std::rethrow_exception( res.error ( ) );
41 }
42 }
43
44 void NullFileChecker::operator()(const Pathname &file ) const
45 {
46 MIL << "+ null check on " << file << endl;
47 return;
48 }
49
50 void CompositeFileChecker::operator()(const Pathname &file ) const
51 {
52 //MIL << _checkers.size() << " checkers" << endl;
53 for ( std::list<FileChecker>::const_iterator it = _checkers.begin(); it != _checkers.end(); ++it )
54 {
55 if ( *it )
56 {
57 //MIL << "+ chk" << endl;
58 (*it)(file);
59 }
60 else
61 {
62 ERR << "Invalid checker" << endl;
63 }
64 }
65 }
66
67 void CompositeFileChecker::add( const FileChecker &checker )
68 { _checkers.push_back(checker); }
69
70
71 SignatureFileChecker::SignatureFileChecker()
72 {}
73
74 SignatureFileChecker::SignatureFileChecker( Pathname signature_r )
75 { _verifyContext.signature( std::move(signature_r) ); }
76
77 void SignatureFileChecker::addPublicKey( const Pathname & publickey_r )
78 { addPublicKey( PublicKey(publickey_r) ); }
79
80 void SignatureFileChecker::addPublicKey( const PublicKey & publickey_r )
81 { getZYpp()->keyRing()->importKey( publickey_r, false ); }
82
83 void SignatureFileChecker::operator()( const Pathname & file_r ) const
84 {
85 // const_cast because the workflow is allowed to store result values here
86 SignatureFileChecker & self { const_cast<SignatureFileChecker&>(*this) };
87 self._verifyContext.file( file_r );
88
89 auto res = zyppng::SignatureFileCheckWorkflow::verifySignature ( zyppng::SyncContext::create(), keyring::VerifyFileContext(_verifyContext) );
90 if ( !res ) {
91 std::rethrow_exception( res.error ( ) );
92 }
93 self._verifyContext = std::move( *res );
94 }
95
96 keyring::VerifyFileContext &SignatureFileChecker::verifyContext()
97 {
98 return _verifyContext;
99 }
100
101 const keyring::VerifyFileContext &SignatureFileChecker::verifyContext() const
102 {
103 return _verifyContext;
104 }
105
106 /******************************************************************
107 **
108 ** FUNCTION NAME : operator<<
109 ** FUNCTION TYPE : std::ostream &
110 */
111 std::ostream & operator<<( std::ostream & str, const FileChecker & obj )
112 {
113 return str;
114 }
115
117} // namespace zypp
FileChecker.h
KeyRing.h
ZYppFactory.h
checksumwf.h
zypp::CheckSum
Definition CheckSum.h:34
zypp::ChecksumFileChecker::operator()
void operator()(const Pathname &file) const
Try to validate the file.
Definition FileChecker.cc:36
zypp::ChecksumFileChecker::ChecksumFileChecker
ChecksumFileChecker(CheckSum checksum)
Constructor.
Definition FileChecker.cc:32
zypp::ChecksumFileChecker::_checksum
CheckSum _checksum
Definition FileChecker.h:64
zypp::CompositeFileChecker::_checkers
std::list< FileChecker > _checkers
Definition FileChecker.h:146
zypp::CompositeFileChecker::add
void add(const FileChecker &checker)
Definition FileChecker.cc:67
zypp::CompositeFileChecker::operator()
void operator()(const Pathname &file) const
Definition FileChecker.cc:50
zypp::NullFileChecker::operator()
void operator()(const Pathname &file) const
Definition FileChecker.cc:44
zypp::SignatureFileChecker::operator()
void operator()(const Pathname &file_r) const
Call KeyRing::verifyFileSignatureWorkflow to verify the file.
Definition FileChecker.cc:83
zypp::SignatureFileChecker::verifyContext
keyring::VerifyFileContext & verifyContext()
Definition FileChecker.cc:96
zypp::SignatureFileChecker::addPublicKey
void addPublicKey(const PublicKey &publickey_r)
Add a public key to the list of known keys.
Definition FileChecker.cc:80
zypp::SignatureFileChecker::_verifyContext
keyring::VerifyFileContext _verifyContext
Definition FileChecker.h:108
zypp::SignatureFileChecker::SignatureFileChecker
SignatureFileChecker()
Default Ctor for unsigned files.
Definition FileChecker.cc:71
zypp::ZYppFactory::getZYpp
ZYpp::Ptr getZYpp()
Convenience to get the Pointer to the ZYpp instance.
Definition ZYppFactory.h:77
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::keyring::VerifyFileContext
I/O context for KeyRing::verifyFileSignatureWorkflow.
Definition KeyRingContexts.h:30
zypp::keyring::VerifyFileContext::file
const Pathname & file() const
File to verify.
Definition KeyRingContexts.cc:73
keyringwf.h
std
Definition Arch.h:364
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition SerialNumber.cc:52
zypp::FileChecker
function< void(const Pathname &file)> FileChecker
Functor signature used to check files.
Definition FileChecker.h:38
zyppng::CheckSumWorkflow::verifyChecksum
expected< void > verifyChecksum(SyncContextRef zyppCtx, zypp::CheckSum checksum, zypp::Pathname file)
Definition checksumwf.cc:115
zyppng::SignatureFileCheckWorkflow::verifySignature
expected< zypp::keyring::VerifyFileContext > verifySignature(SyncContextRef ctx, zypp::keyring::VerifyFileContext context)
Definition signaturecheckwf.cc:58
signaturecheckwf.h
MIL
#define MIL
Definition Logger.h:100
ERR
#define ERR
Definition Logger.h:102
Digest.h
Logger.h