KeyRing.h
Go to the documentation of this file.00001
00002
00003
00004
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 & )
00101 {}
00102 virtual void trustedKeyRemoved( const PublicKey & )
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
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
00194 std::string readSignatureKeyId( const Pathname &signature );
00195
00199 bool isKeyTrusted( const std::string &id);
00200
00205 bool isKeyKnown( const std::string &id );
00206
00211 void deleteKey( const std::string &id, bool trusted = false);
00212
00216 std::list<PublicKey> publicKeys();
00217
00221 std::list<PublicKey> trustedPublicKeys();
00222
00226 std::list<std::string> publicKeyIds();
00227
00231 std::list<std::string> trustedPublicKeyIds();
00232
00257 bool verifyFileSignatureWorkflow(
00258 const Pathname &file,
00259 const std::string filedesc,
00260 const Pathname &signature,
00261 const KeyContext &keycontext = KeyContext());
00262
00263
00270 bool verifyFileSignature( const Pathname &file, const Pathname &signature);
00271
00272 bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature);
00273
00275 ~KeyRing();
00276
00277 private:
00279 RWCOW_pointer<Impl> _pimpl;
00280 };
00282
00284 inline std::ostream & operator<<( std::ostream & str, const KeyRing & )
00285 {
00286
00287 return str;
00288 }
00289
00291 ZYPP_DECLARE_OPERATORS_FOR_FLAGS( KeyRing::DefaultAccept );
00292
00294
00295 namespace target
00296 {
00297 namespace rpm
00298 {
00300 struct KeyRingSignals : public ::zypp::KeyRingSignals
00301 {};
00302 }
00303 }
00304
00306 }
00308 #endif // ZYPP_KEYRING_H