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
00174
00175
00180 void importKey( const PublicKey &key, bool trusted = false);
00181
00182 void dumpTrustedPublicKey( const std::string &id, std::ostream &stream )
00183 { dumpPublicKey(id, true, stream); }
00184
00185 void dumpUntrustedPublicKey( const std::string &id, std::ostream &stream )
00186 { dumpPublicKey(id, false, stream); }
00187
00188 void dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream );
00189
00193 std::string readSignatureKeyId( const Pathname &signature );
00194
00198 bool isKeyTrusted( const std::string &id);
00199
00204 bool isKeyKnown( const std::string &id );
00205
00210 void deleteKey( const std::string &id, bool trusted = false);
00211
00215 std::list<PublicKey> publicKeys();
00216
00220 std::list<PublicKey> trustedPublicKeys();
00221
00225 std::list<std::string> publicKeyIds();
00226
00230 std::list<std::string> trustedPublicKeyIds();
00231
00256 bool verifyFileSignatureWorkflow(
00257 const Pathname &file,
00258 const std::string filedesc,
00259 const Pathname &signature,
00260 const KeyContext &keycontext = KeyContext());
00261
00262
00269 bool verifyFileSignature( const Pathname &file, const Pathname &signature);
00270
00271 bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature);
00272
00274 ~KeyRing();
00275
00276 private:
00278 RWCOW_pointer<Impl> _pimpl;
00279 };
00281
00283 inline std::ostream & operator<<( std::ostream & str, const KeyRing & )
00284 {
00285
00286 return str;
00287 }
00288
00290 ZYPP_DECLARE_OPERATORS_FOR_FLAGS( KeyRing::DefaultAccept );
00291
00293
00294 namespace target
00295 {
00296 namespace rpm
00297 {
00299 struct KeyRingSignals : public ::zypp::KeyRingSignals
00300 {};
00301 }
00302 }
00303
00305 }
00307 #endif // ZYPP_KEYRING_H