libzypp 9.41.1
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_KEYRING_H 00013 #define ZYPP_KEYRING_H 00014 00015 #include <iosfwd> 00016 #include <map> 00017 #include <list> 00018 #include <set> 00019 #include <string> 00020 00021 #include "zypp/base/ReferenceCounted.h" 00022 #include "zypp/base/Flags.h" 00023 #include "zypp/Callback.h" 00024 #include "zypp/base/PtrTypes.h" 00025 #include "zypp/Locale.h" 00026 #include "zypp/PublicKey.h" 00027 #include "zypp/KeyContext.h" 00028 00030 namespace zypp 00031 { 00032 00033 DEFINE_PTR_TYPE(KeyRing); 00034 00044 struct KeyRingReport : public callback::ReportBase 00045 { 00051 enum KeyTrust 00052 { 00056 KEY_DONT_TRUST = 0, 00061 KEY_TRUST_TEMPORARILY, 00070 KEY_TRUST_AND_IMPORT 00071 }; 00072 00077 virtual KeyTrust askUserToAcceptKey( const PublicKey &key, const KeyContext &keycontext = KeyContext() ); 00078 00079 virtual bool askUserToAcceptUnsignedFile( const std::string &file, const KeyContext &keycontext = KeyContext() ); 00080 00087 virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const KeyContext &keycontext = KeyContext() ); 00088 00094 virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key, const KeyContext &keycontext = KeyContext() ); 00095 00096 }; 00097 00098 struct KeyRingSignals : public callback::ReportBase 00099 { 00100 virtual void trustedKeyAdded( const PublicKey &/*key*/ ) 00101 {} 00102 virtual void trustedKeyRemoved( const PublicKey &/*key*/ ) 00103 {} 00104 }; 00105 00106 class KeyRingException : public Exception 00107 { 00108 public: 00112 KeyRingException() 00113 : Exception( "Bad Key Exception" ) 00114 {} 00118 KeyRingException( const std::string & msg_r ) 00119 : Exception( msg_r ) 00120 {} 00122 virtual ~KeyRingException() throw() {}; 00123 }; 00124 00126 // 00127 // CLASS NAME : KeyRing 00128 // 00132 class KeyRing : public base::ReferenceCounted, private base::NonCopyable 00133 { 00134 friend std::ostream & operator<<( std::ostream & str, const KeyRing & obj ); 00135 00136 public: 00148 enum DefaultAcceptBits 00149 { 00150 ACCEPT_NOTHING = 0x0000, 00151 ACCEPT_UNSIGNED_FILE = 0x0001, 00152 ACCEPT_UNKNOWNKEY = 0x0002, 00153 TRUST_KEY_TEMPORARILY = 0x0004, 00154 TRUST_AND_IMPORT_KEY = 0x0008, 00155 ACCEPT_VERIFICATION_FAILED = 0x0010, 00156 }; 00157 ZYPP_DECLARE_FLAGS( DefaultAccept, DefaultAcceptBits ); 00158 00160 static DefaultAccept defaultAccept(); 00161 00163 static void setDefaultAccept( DefaultAccept value_r ); 00165 00166 public: 00168 class Impl; 00169 00170 public: 00172 KeyRing(const Pathname &baseTmpDir); 00173 00178 void importKey( const PublicKey &key, bool trusted = false); 00179 00181 void multiKeyImport( const Pathname & keyfile_r, bool trusted_r = false ); 00182 00183 void dumpTrustedPublicKey( const std::string &id, std::ostream &stream ) 00184 { dumpPublicKey(id, true, stream); } 00185 00186 void dumpUntrustedPublicKey( const std::string &id, std::ostream &stream ) 00187 { dumpPublicKey(id, false, stream); } 00188 00189 void dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream ); 00190 00192 PublicKey exportPublicKey( const PublicKeyData & keyData ); 00193 00195 PublicKey exportTrustedPublicKey( const PublicKeyData & keyData ); 00196 00200 std::string readSignatureKeyId( const Pathname &signature ); 00201 00205 bool isKeyTrusted( const std::string &id ); 00206 00211 bool isKeyKnown( const std::string &id ); 00212 00217 void deleteKey( const std::string &id, bool trusted = false ); 00218 00222 std::list<PublicKey> publicKeys(); 00223 00227 std::list<PublicKey> trustedPublicKeys(); 00228 00232 std::list<PublicKeyData> publicKeyData(); 00233 00237 std::list<PublicKeyData> trustedPublicKeyData(); 00238 00243 std::list<std::string> publicKeyIds() ZYPP_DEPRECATED; 00244 00249 std::list<std::string> trustedPublicKeyIds() ZYPP_DEPRECATED; 00250 00275 bool verifyFileSignatureWorkflow( 00276 const Pathname &file, 00277 const std::string filedesc, 00278 const Pathname &signature, 00279 const KeyContext &keycontext = KeyContext()); 00280 00281 00288 bool verifyFileSignature( const Pathname &file, const Pathname &signature ); 00289 00290 bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature ); 00291 00293 ~KeyRing(); 00294 00295 private: 00297 RWCOW_pointer<Impl> _pimpl; 00298 }; 00300 00302 inline std::ostream & operator<<( std::ostream & str, const KeyRing & /*obj*/ ) 00303 { 00304 //return str << obj.asString(); 00305 return str; 00306 } 00307 00309 ZYPP_DECLARE_OPERATORS_FOR_FLAGS( KeyRing::DefaultAccept ); 00310 00312 00313 namespace target 00314 { 00315 namespace rpm 00316 { 00318 struct KeyRingSignals : public ::zypp::KeyRingSignals 00319 {}; 00320 } 00321 } 00322 00324 } // namespace zypp 00326 #endif // ZYPP_KEYRING_H