libzypp 17.38.3
keyring_p.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_PRIVATE_KEYRINGIMPL_H
13#define ZYPP_PRIVATE_KEYRINGIMPL_H
14
17#include <zypp-core/fs/WatchFile>
20#include <optional>
21
22namespace zypp {
23
24
33 {
34 const std::list<PublicKeyData> & operator()( const Pathname & keyring_r ) const;
35
36 void setDirty( const Pathname & keyring_r );
37
44 struct Manip {
46 Manip( CachedPublicKeyData & cache_r, Pathname keyring_r );
47
49 private:
52 std::optional<KeyManagerCtx> _context;
53 };
54
55
57 Manip manip( Pathname keyring_r );
58
59 private:
60 struct Cache
61 {
62 Cache();
63
64 void setDirty();
65
66 void assertCache( const Pathname & keyring_r );
67
68 bool hasChanged() const;
69
70 std::list<PublicKeyData> _data;
71
72 private:
73
76 };
77
78 using CacheMap = std::map<Pathname, Cache>;
79
80 const std::list<PublicKeyData> & getData( const Pathname & keyring_r ) const;
81
82 const std::list<PublicKeyData> & getData( const Pathname & keyring_r, Cache & cache_r ) const;
83
85 };
86
91 {
92 public:
93 KeyRingImpl( const Pathname & baseTmpDir );
94
95 void importKey( const PublicKey & key, bool trusted = false );
96 void multiKeyImport( const Pathname & keyfile_r, bool trusted_r = false );
97 void deleteKey( const std::string & id, bool trusted );
98
99 std::string readSignatureKeyId( const Pathname & signature );
100
101 bool isKeyTrusted( const std::string & id )
102 { return bool(publicKeyExists( id, trustedKeyRing() )); }
103 bool isKeyKnown( const std::string & id )
104 { return publicKeyExists( id, trustedKeyRing() ) || publicKeyExists( id, generalKeyRing() ); }
105
106 std::list<PublicKey> trustedPublicKeys()
107 { return publicKeys( trustedKeyRing() ); }
108 std::list<PublicKey> publicKeys()
109 { return publicKeys( generalKeyRing() ); }
110
111 const std::list<PublicKeyData> & trustedPublicKeyData()
112 { return publicKeyData( trustedKeyRing() ); }
113 const std::list<PublicKeyData> & publicKeyData()
114 { return publicKeyData( generalKeyRing() ); }
115
116 void dumpPublicKey( const std::string & id, bool trusted, std::ostream & stream )
117 { dumpPublicKey( id, ( trusted ? trustedKeyRing() : generalKeyRing() ), stream ); }
118
120 { return exportKey( keyData, generalKeyRing() ); }
122 { return exportKey( keyData, trustedKeyRing() ); }
123
124 bool verifyFileSignature( const Pathname & file, const Pathname & signature )
125 { return verifyFile( file, signature, generalKeyRing() ); }
126 bool verifyFileTrustedSignature( const Pathname & file, const Pathname & signature )
127 { return verifyFile( file, signature, trustedKeyRing() ); }
128
129 PublicKeyData publicKeyExists( const std::string & id )
130 { return publicKeyExists(id, generalKeyRing());}
131 PublicKeyData trustedPublicKeyExists( const std::string & id )
132 { return publicKeyExists(id, trustedKeyRing());}
133
134 void allowPreload( bool yesno_r )
135 { _allowPreload = yesno_r; }
136
140
141 bool verifyFile( const Pathname & file, const Pathname & signature, const Pathname & keyring );
142 void importKey( const Pathname & keyfile, const Pathname & keyring );
143
144 PublicKey exportKey( const std::string & id, const Pathname & keyring );
145 PublicKey exportKey( const PublicKeyData & keyData, const Pathname & keyring );
147 { return exportKey( key.keyData(), keyring ); }
148
149 void dumpPublicKey( const std::string & id, const Pathname & keyring, std::ostream & stream );
150 filesystem::TmpFile dumpPublicKeyToTmp( const std::string & id, const Pathname & keyring );
151
152 void deleteKey( const std::string & id, const Pathname & keyring );
153
154 std::list<PublicKey> publicKeys( const Pathname & keyring);
155 const std::list<PublicKeyData> & publicKeyData( const Pathname & keyring )
156 { return cachedPublicKeyData( keyring ); }
157
159 PublicKeyData publicKeyExists( const std::string & id, const Pathname & keyring );
161 void preloadCachedKeys();
162
164 { return _general_tmp_dir.path(); }
166 { return _trusted_tmp_dir.path(); }
167
169 return _sigTrustedKeyAdded;
170 }
171
174 }
175
176 private:
177 // Used for trusted and untrusted keyrings
181 bool _allowPreload = false; //< General keyring may be preloaded with keys cached on the system.
182
189
192 };
193
194}
195
196
197#endif
PublicKey exportKey(const PublicKey &key, const Pathname &keyring)
Definition keyring_p.h:146
zyppng::Signal< void(const PublicKey &)> _sigTrustedKeyAdded
Definition keyring_p.h:190
PublicKeyData publicKeyExists(const std::string &id)
Definition keyring_p.h:129
std::list< PublicKey > trustedPublicKeys()
Definition keyring_p.h:106
const std::list< PublicKeyData > & publicKeyData(const Pathname &keyring)
Definition keyring_p.h:155
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
Definition keyring_p.h:121
zyppng::SignalProxy< void(const PublicKey &)> sigTrustedKeyRemoved()
Definition keyring_p.h:172
void importKey(const PublicKey &key, bool trusted=false)
Definition keyring_p.cc:117
PublicKey exportPublicKey(const PublicKeyData &keyData)
Definition keyring_p.h:119
bool isKeyKnown(const std::string &id)
Definition keyring_p.h:103
void allowPreload(bool yesno_r)
Definition keyring_p.h:134
filesystem::TmpDir _general_tmp_dir
Definition keyring_p.h:179
KeyRingImpl(const Pathname &baseTmpDir)
Definition keyring_p.cc:110
const std::list< PublicKeyData > & publicKeyData()
Definition keyring_p.h:113
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Definition keyring_p.cc:138
std::list< PublicKey > publicKeys()
Definition keyring_p.h:108
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature)
Definition keyring_p.h:126
void preloadCachedKeys()
Load key files cached on the system into the generalKeyRing.
Definition keyring_p.cc:180
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
Definition keyring_p.h:116
zyppng::Signal< void(const PublicKey &)> _sigTrustedKeyRemoved
Definition keyring_p.h:191
const std::list< PublicKeyData > & trustedPublicKeyData()
Definition keyring_p.h:111
const Pathname generalKeyRing() const
Definition keyring_p.h:163
bool verifyFileSignature(const Pathname &file, const Pathname &signature)
Definition keyring_p.h:124
Pathname _base_dir
Definition keyring_p.h:180
const Pathname trustedKeyRing() const
Definition keyring_p.h:165
std::string readSignatureKeyId(const Pathname &signature)
Definition keyring_p.cc:301
CachedPublicKeyData::Manip keyRingManip(const Pathname &keyring)
Impl helper providing on demand a KeyManagerCtx to manip a cached keyring.
Definition keyring_p.h:138
PublicKey exportKey(const std::string &id, const Pathname &keyring)
Definition keyring_p.cc:239
bool isKeyTrusted(const std::string &id)
Definition keyring_p.h:101
bool verifyFile(const Pathname &file, const Pathname &signature, const Pathname &keyring)
Definition keyring_p.cc:317
void deleteKey(const std::string &id, bool trusted)
Definition keyring_p.cc:143
zyppng::SignalProxy< void(const PublicKey &)> sigTrustedKeyAdded()
Definition keyring_p.h:168
PublicKeyData trustedPublicKeyExists(const std::string &id)
Definition keyring_p.h:131
filesystem::TmpDir _trusted_tmp_dir
Definition keyring_p.h:178
filesystem::TmpFile dumpPublicKeyToTmp(const std::string &id, const Pathname &keyring)
Definition keyring_p.cc:256
CachedPublicKeyData cachedPublicKeyData
Functor returning the keyrings data (cached).
Definition keyring_p.h:188
Class representing one GPG Public Keys data.
Definition PublicKey.h:201
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:358
const PublicKeyData & keyData() const
The public keys data (.
Definition PublicKey.cc:637
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition TmpPath.h:173
Provide a new empty temporary file and delete it when no longer needed.
Definition TmpPath.h:118
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition NonCopyable.h:26
Easy-to use interface to the ZYPP dependency resolver.
scoped_ptr< WatchFile > _keyringP
Definition keyring_p.h:75
void assertCache(const Pathname &keyring_r)
Definition keyring_p.cc:68
std::list< PublicKeyData > _data
Definition keyring_p.h:70
scoped_ptr< WatchFile > _keyringK
Definition keyring_p.h:74
Helper providing on demand a KeyManagerCtx to manip the cached keyring.
Definition keyring_p.h:44
std::optional< KeyManagerCtx > _context
Definition keyring_p.h:52
KeyManagerCtx & keyManagerCtx()
Definition keyring_p.cc:49
Manip(CachedPublicKeyData &cache_r, Pathname keyring_r)
Definition keyring_p.cc:44
CachedPublicKeyData & _cache
Definition keyring_p.h:50
Functor returning the keyrings data (cached).
Definition keyring_p.h:33
void setDirty(const Pathname &keyring_r)
Definition keyring_p.cc:87
const std::list< PublicKeyData > & operator()(const Pathname &keyring_r) const
Definition keyring_p.cc:84
const std::list< PublicKeyData > & getData(const Pathname &keyring_r) const
Definition keyring_p.cc:92
Manip manip(Pathname keyring_r)
Helper providing on demand a KeyManagerCtx to manip the cached keyring.
Definition keyring_p.cc:90
std::map< Pathname, Cache > CacheMap
Definition keyring_p.h:78