1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/FileChecker.cc
13 #include "zypp/base/Logger.h"
14 #include "zypp/FileChecker.h"
15 #include "zypp/ZYppFactory.h"
16 #include "zypp/Digest.h"
17 #include "zypp/KeyRing.h"
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
25 ChecksumFileChecker::ChecksumFileChecker( const CheckSum &checksum )
30 void ChecksumFileChecker::operator()( const Pathname &file ) const
32 callback::SendReport<DigestReport> report;
33 CheckSum real_checksum( _checksum.type(), filesystem::checksum( file, _checksum.type() ));
35 if ( _checksum.empty() )
37 MIL << "File " << file << " has no checksum available." << std::endl;
38 if ( report->askUserToAcceptNoDigest(file) )
40 MIL << "User accepted " << file << " with no checksum." << std::endl;
45 ZYPP_THROW(FileCheckException("No checksum available"));
50 if ( (real_checksum != _checksum) )
52 if ( report->askUserToAcceptWrongDigest( file, _checksum.checksum(), real_checksum.checksum() ) )
54 WAR << "User accepted " << file << " with WRONG CHECKSUM." << std::endl;
59 ZYPP_THROW(FileCheckException("Wrong checksum"));
65 void NullFileChecker::operator()(const Pathname &file ) const
70 void CompositeFileChecker::operator()(const Pathname &file ) const
72 for ( list<FileChecker>::const_iterator it = _checkers.begin(); it != _checkers.end(); ++it )
78 void CompositeFileChecker::add( const FileChecker &checker )
80 _checkers.push_back(checker);
83 SignatureFileChecker::SignatureFileChecker( const Pathname &signature )
84 : _signature(signature)
88 SignatureFileChecker::SignatureFileChecker()
92 void SignatureFileChecker::addPublicKey( const Pathname &publickey )
94 ZYpp::Ptr z = getZYpp();
95 z->keyRing()->importKey(publickey, false);
98 void SignatureFileChecker::operator()(const Pathname &file ) const
100 ZYpp::Ptr z = getZYpp();
101 MIL << "checking " << file << " file validity using digital signature.." << endl;
102 bool valid = z->keyRing()->verifyFileSignatureWorkflow( file, string(), _signature);
104 ZYPP_THROW(FileCheckException("Signature verification failed"));
107 /******************************************************************
109 ** FUNCTION NAME : operator<<
110 ** FUNCTION TYPE : std::ostream &
112 std::ostream & operator<<( std::ostream & str, const FileChecker & obj )
117 /////////////////////////////////////////////////////////////////
119 ///////////////////////////////////////////////////////////////////