libzypp 17.37.17
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
16#include <zypp-core/fs/WatchFile>
19#include <optional>
20
21namespace zypp {
22
23
32 {
33 const std::list<PublicKeyData> & operator()( const Pathname & keyring_r ) const;
34
35 void setDirty( const Pathname & keyring_r );
36
43 struct Manip {
45 Manip( CachedPublicKeyData & cache_r, Pathname keyring_r );
46
48 private:
51 std::optional<KeyManagerCtx> _context;
52 };
53
54
56 Manip manip( Pathname keyring_r );
57
58 private:
59 struct Cache
60 {
61 Cache();
62
63 void setDirty();
64
65 void assertCache( const Pathname & keyring_r );
66
67 bool hasChanged() const;
68
69 std::list<PublicKeyData> _data;
70
71 private:
72
75 };
76
77 using CacheMap = std::map<Pathname, Cache>;
78
79 const std::list<PublicKeyData> & getData( const Pathname & keyring_r ) const;
80
81 const std::list<PublicKeyData> & getData( const Pathname & keyring_r, Cache & cache_r ) const;
82
84 };
85
90 {
91 public:
92 KeyRingImpl( const Pathname & baseTmpDir );
93
94 void importKey( const PublicKey & key, bool trusted = false );
95 void multiKeyImport( const Pathname & keyfile_r, bool trusted_r = false );
96 void deleteKey( const std::string & id, bool trusted );
97
98 std::string readSignatureKeyId( const Pathname & signature );
99
100 bool isKeyTrusted( const std::string & id )
101 { return bool(publicKeyExists( id, trustedKeyRing() )); }
102 bool isKeyKnown( const std::string & id )
103 { return publicKeyExists( id, trustedKeyRing() ) || publicKeyExists( id, generalKeyRing() ); }
104
105 std::list<PublicKey> trustedPublicKeys()
106 { return publicKeys( trustedKeyRing() ); }
107 std::list<PublicKey> publicKeys()
108 { return publicKeys( generalKeyRing() ); }
109
110 const std::list<PublicKeyData> & trustedPublicKeyData()
111 { return publicKeyData( trustedKeyRing() ); }
112 const std::list<PublicKeyData> & publicKeyData()
113 { return publicKeyData( generalKeyRing() ); }
114
115 void dumpPublicKey( const std::string & id, bool trusted, std::ostream & stream )
116 { dumpPublicKey( id, ( trusted ? trustedKeyRing() : generalKeyRing() ), stream ); }
117
119 { return exportKey( keyData, generalKeyRing() ); }
121 { return exportKey( keyData, trustedKeyRing() ); }
122
123 bool verifyFileSignature( const Pathname & file, const Pathname & signature )
124 { return verifyFile( file, signature, generalKeyRing() ); }
125 bool verifyFileTrustedSignature( const Pathname & file, const Pathname & signature )
126 { return verifyFile( file, signature, trustedKeyRing() ); }
127
128 PublicKeyData publicKeyExists( const std::string & id )
129 { return publicKeyExists(id, generalKeyRing());}
130 PublicKeyData trustedPublicKeyExists( const std::string & id )
131 { return publicKeyExists(id, trustedKeyRing());}
132
133 void allowPreload( bool yesno_r )
134 { _allowPreload = yesno_r; }
135
139
140 bool verifyFile( const Pathname & file, const Pathname & signature, const Pathname & keyring );
141 void importKey( const Pathname & keyfile, const Pathname & keyring );
142
143 PublicKey exportKey( const std::string & id, const Pathname & keyring );
144 PublicKey exportKey( const PublicKeyData & keyData, const Pathname & keyring );
146 { return exportKey( key.keyData(), keyring ); }
147
148 void dumpPublicKey( const std::string & id, const Pathname & keyring, std::ostream & stream );
149 filesystem::TmpFile dumpPublicKeyToTmp( const std::string & id, const Pathname & keyring );
150
151 void deleteKey( const std::string & id, const Pathname & keyring );
152
153 std::list<PublicKey> publicKeys( const Pathname & keyring);
154 const std::list<PublicKeyData> & publicKeyData( const Pathname & keyring )
155 { return cachedPublicKeyData( keyring ); }
156
158 PublicKeyData publicKeyExists( const std::string & id, const Pathname & keyring );
160 void preloadCachedKeys();
161
163 { return _general_tmp_dir.path(); }
165 { return _trusted_tmp_dir.path(); }
166
168 return _sigTrustedKeyAdded;
169 }
170
173 }
174
175 private:
176 // Used for trusted and untrusted keyrings
180 bool _allowPreload = false; //< General keyring may be preloaded with keys cached on the system.
181
188
191 };
192
193}
194
195
196#endif
PublicKey exportKey(const PublicKey &key, const Pathname &keyring)
Definition keyring_p.h:145
zyppng::Signal< void(const PublicKey &)> _sigTrustedKeyAdded
Definition keyring_p.h:189
PublicKeyData publicKeyExists(const std::string &id)
Definition keyring_p.h:128
std::list< PublicKey > trustedPublicKeys()
Definition keyring_p.h:105
const std::list< PublicKeyData > & publicKeyData(const Pathname &keyring)
Definition keyring_p.h:154
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
Definition keyring_p.h:120
zyppng::SignalProxy< void(const PublicKey &)> sigTrustedKeyRemoved()
Definition keyring_p.h:171
void importKey(const PublicKey &key, bool trusted=false)
Definition keyring_p.cc:117
PublicKey exportPublicKey(const PublicKeyData &keyData)
Definition keyring_p.h:118
bool isKeyKnown(const std::string &id)
Definition keyring_p.h:102
void allowPreload(bool yesno_r)
Definition keyring_p.h:133
filesystem::TmpDir _general_tmp_dir
Definition keyring_p.h:178
KeyRingImpl(const Pathname &baseTmpDir)
Definition keyring_p.cc:110
const std::list< PublicKeyData > & publicKeyData()
Definition keyring_p.h:112
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Definition keyring_p.cc:138
std::list< PublicKey > publicKeys()
Definition keyring_p.h:107
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature)
Definition keyring_p.h:125
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:115
zyppng::Signal< void(const PublicKey &)> _sigTrustedKeyRemoved
Definition keyring_p.h:190
const std::list< PublicKeyData > & trustedPublicKeyData()
Definition keyring_p.h:110
const Pathname generalKeyRing() const
Definition keyring_p.h:162
bool verifyFileSignature(const Pathname &file, const Pathname &signature)
Definition keyring_p.h:123
Pathname _base_dir
Definition keyring_p.h:179
const Pathname trustedKeyRing() const
Definition keyring_p.h:164
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:137
PublicKey exportKey(const std::string &id, const Pathname &keyring)
Definition keyring_p.cc:239
bool isKeyTrusted(const std::string &id)
Definition keyring_p.h:100
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:167
PublicKeyData trustedPublicKeyExists(const std::string &id)
Definition keyring_p.h:130
filesystem::TmpDir _trusted_tmp_dir
Definition keyring_p.h:177
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:187
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:188
Provide a new empty temporary file and delete it when no longer needed.
Definition TmpPath.h:128
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:74
void assertCache(const Pathname &keyring_r)
Definition keyring_p.cc:68
std::list< PublicKeyData > _data
Definition keyring_p.h:69
scoped_ptr< WatchFile > _keyringK
Definition keyring_p.h:73
Helper providing on demand a KeyManagerCtx to manip the cached keyring.
Definition keyring_p.h:43
std::optional< KeyManagerCtx > _context
Definition keyring_p.h:51
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:49
Functor returning the keyrings data (cached).
Definition keyring_p.h:32
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:77