1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/KeyRing.h
12 #ifndef ZYPP_KEYRING_H
13 #define ZYPP_KEYRING_H
21 #include "zypp/base/ReferenceCounted.h"
22 #include "zypp/Callback.h"
23 #include "zypp/base/PtrTypes.h"
24 #include "zypp/Locale.h"
25 #include "zypp/PublicKey.h"
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
31 DEFINE_PTR_TYPE(KeyRing);
33 struct KeyRingReport : public callback::ReportBase
36 virtual bool askUserToAcceptUnsignedFile( const std::string &file );
39 * we DONT know the key, only its id, but we have never seen it, the difference
40 * with trust key is that if you dont have it, you can't import it later.
41 * The answer means continue yes or no?
43 virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id );
46 * This basically means, we know the key, but it is not trusted, Continue
47 * yes or no?. Nothing else is performed (import, etc)
49 virtual bool askUserToTrustKey( const PublicKey &key);
54 * This means saving the key in the trusted database so next run it will appear as trusted.
55 * Nothing to do with trustKey, as you CAN trust a key without importing it,
56 * basically you will be asked every time again.
57 * There are programs who prefer to manage the trust keyring on their own and use trustKey
58 * without importing it into rpm.
60 virtual bool askUserToImportKey( const PublicKey &key);
61 virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key );
64 struct KeyRingSignals : public callback::ReportBase
66 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
68 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
72 class KeyRingException : public Exception
75 /** Ctor taking message.
76 * Use \ref ZYPP_THROW to throw exceptions.
79 : Exception( "Bad Key Exception" )
81 /** Ctor taking message.
82 * Use \ref ZYPP_THROW to throw exceptions.
84 KeyRingException( const std::string & msg_r )
88 virtual ~KeyRingException() throw() {};
91 ///////////////////////////////////////////////////////////////////
93 // CLASS NAME : KeyRing
95 /** Class that represent a text and multiple translations.
97 class KeyRing : public base::ReferenceCounted, private base::NonCopyable
99 friend std::ostream & operator<<( std::ostream & str, const KeyRing & obj );
102 /** Implementation */
107 KeyRing(const Pathname &baseTmpDir);
109 //KeyRing(const Pathname &general_kr, const Pathname &trusted_kr);
112 * imports a key from a file.
113 * throw if key was not imported
115 void importKey( const PublicKey &key, bool trusted = false);
117 void dumpTrustedPublicKey( const std::string &id, std::ostream &stream )
118 { dumpPublicKey(id, true, stream); }
120 void dumpUntrustedPublicKey( const std::string &id, std::ostream &stream )
121 { dumpPublicKey(id, false, stream); }
123 void dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream );
126 * reads the public key id from a signature
128 std::string readSignatureKeyId( const Pathname &signature );
131 * true if the key id is trusted
133 bool isKeyTrusted( const std::string &id);
136 * true if the key id is knows, that means
137 * at least exist on the untrusted keyring
139 bool isKeyKnown( const std::string &id );
142 * removes a key from the keyring.
143 * If trusted is true, Remove it from trusted keyring too.
145 void deleteKey( const std::string &id, bool trusted = false);
148 * Get a list of public keys in the keyring
150 std::list<PublicKey> publicKeys();
153 * Get a list of trusted public keys in the keyring
155 std::list<PublicKey> trustedPublicKeys();
158 * Get a list of public key ids in the keyring
160 std::list<std::string> publicKeyIds();
163 * Get a list of trusted public key ids in the keyring
165 std::list<std::string> trustedPublicKeyIds();
168 * Follows a signature verification interacting with the user.
169 * The bool returned depends on user decision to trust or not.
171 bool verifyFileSignatureWorkflow( const Pathname &file, const std::string filedesc, const Pathname &signature);
172 bool verifyFileSignature( const Pathname &file, const Pathname &signature);
173 bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature);
180 /** Synonym for \ref text */
181 //std::string asString() const
185 /** Pointer to implementation */
186 RWCOW_pointer<Impl> _pimpl;
188 ///////////////////////////////////////////////////////////////////
190 /** \relates KeyRing Stream output */
191 inline std::ostream & operator<<( std::ostream & str, const KeyRing & /*obj*/ )
193 //return str << obj.asString();
197 ///////////////////////////////////////////////////////////////////
203 /** Internal connection to rpm database. Not for public use. */
204 struct KeyRingSignals : public ::zypp::KeyRingSignals
209 /////////////////////////////////////////////////////////////////
211 ///////////////////////////////////////////////////////////////////
212 #endif // ZYPP_KEYRING_H