libzypp 17.35.19
keyring_p.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_ZYPP_DETAIL_KEYRINGIMPL_H
13#define ZYPP_ZYPP_DETAIL_KEYRINGIMPL_H
14
16#include <zypp-core/fs/WatchFile>
17#include <zypp/KeyManager.h>
18#include <zypp/KeyRing.h>
19
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
55
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
87
88
90 //
91 // CLASS NAME : KeyRing::Impl
92 //
95 {
96 Impl( const Pathname & baseTmpDir );
97
98 void importKey( const PublicKey & key, bool trusted = false );
99 void multiKeyImport( const Pathname & keyfile_r, bool trusted_r = false );
100 void deleteKey( const std::string & id, bool trusted );
101
102 std::string readSignatureKeyId( const Pathname & signature );
103
104 bool isKeyTrusted( const std::string & id )
105 { return bool(publicKeyExists( id, trustedKeyRing() )); }
106 bool isKeyKnown( const std::string & id )
107 { return publicKeyExists( id, trustedKeyRing() ) || publicKeyExists( id, generalKeyRing() ); }
108
109 std::list<PublicKey> trustedPublicKeys()
110 { return publicKeys( trustedKeyRing() ); }
111 std::list<PublicKey> publicKeys()
112 { return publicKeys( generalKeyRing() ); }
113
114 const std::list<PublicKeyData> & trustedPublicKeyData()
115 { return publicKeyData( trustedKeyRing() ); }
116 const std::list<PublicKeyData> & publicKeyData()
117 { return publicKeyData( generalKeyRing() ); }
118
119 void dumpPublicKey( const std::string & id, bool trusted, std::ostream & stream )
120 { dumpPublicKey( id, ( trusted ? trustedKeyRing() : generalKeyRing() ), stream ); }
121
123 { return exportKey( keyData, generalKeyRing() ); }
125 { return exportKey( keyData, trustedKeyRing() ); }
126
127 bool verifyFileSignature( const Pathname & file, const Pathname & signature )
128 { return verifyFile( file, signature, generalKeyRing() ); }
129 bool verifyFileTrustedSignature( const Pathname & file, const Pathname & signature )
130 { return verifyFile( file, signature, trustedKeyRing() ); }
131
132 PublicKeyData publicKeyExists( const std::string & id )
133 { return publicKeyExists(id, generalKeyRing());}
134 PublicKeyData trustedPublicKeyExists( const std::string & id )
135 { return publicKeyExists(id, trustedKeyRing());}
136
139
142 { return cachedPublicKeyData.manip( keyring ); }
143
144 bool verifyFile( const Pathname & file, const Pathname & signature, const Pathname & keyring );
145 void importKey( const Pathname & keyfile, const Pathname & keyring );
146
147 PublicKey exportKey( const std::string & id, const Pathname & keyring );
148 PublicKey exportKey( const PublicKeyData & keyData, const Pathname & keyring );
149 PublicKey exportKey( const PublicKey & key, const Pathname & keyring )
150 { return exportKey( key.keyData(), keyring ); }
151
152 void dumpPublicKey( const std::string & id, const Pathname & keyring, std::ostream & stream );
153 filesystem::TmpFile dumpPublicKeyToTmp( const std::string & id, const Pathname & keyring );
154
155 void deleteKey( const std::string & id, const Pathname & keyring );
156
157 std::list<PublicKey> publicKeys( const Pathname & keyring);
158 const std::list<PublicKeyData> & publicKeyData( const Pathname & keyring )
159 { return cachedPublicKeyData( keyring ); }
160
162 PublicKeyData publicKeyExists( const std::string & id, const Pathname & keyring );
164 void preloadCachedKeys();
165
167 { return _general_tmp_dir.path(); }
169 { return _trusted_tmp_dir.path(); }
170
171 private:
172 // Used for trusted and untrusted keyrings
176 bool _allowPreload = false; //< General keyring may be preloaded with keys cached on the system.
177
184 };
185
186}
187
188
189#endif
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
Class representing one GPG Public Keys data.
Definition PublicKey.h:208
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:365
const PublicKeyData & keyData() const
The public keys data (.
Definition PublicKey.cc:643
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition TmpPath.h:182
Provide a new empty temporary file and delete it when no longer needed.
Definition TmpPath.h:128
Pathname path() const
Definition TmpPath.cc:152
bool trusted
Definition keyringwf.cc:135
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.cc:143
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.cc:124
Manip(CachedPublicKeyData &cache_r, Pathname keyring_r)
Definition KeyRing.cc:119
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.cc:162
const std::list< PublicKeyData > & operator()(const Pathname &keyring_r) const
Definition KeyRing.cc:159
const std::list< PublicKeyData > & getData(const Pathname &keyring_r) const
Definition KeyRing.cc:167
Manip manip(Pathname keyring_r)
Helper providing on demand a KeyManagerCtx to manip the cached keyring.
Definition KeyRing.cc:165
std::map< Pathname, Cache > CacheMap
Definition keyring_p.h:78
KeyRing implementation.
Definition keyring_p.h:95
void importKey(const PublicKey &key, bool trusted=false)
Definition KeyRing.cc:220
PublicKeyData trustedPublicKeyExists(const std::string &id)
Definition keyring_p.h:134
void preloadCachedKeys()
Load key files cached on the system into the generalKeyRing.
Definition KeyRing.cc:296
std::list< PublicKey > trustedPublicKeys()
Definition keyring_p.h:109
CachedPublicKeyData::Manip keyRingManip(const Pathname &keyring)
Impl helper providing on demand a KeyManagerCtx to manip a cached keyring.
Definition keyring_p.h:141
PublicKeyData publicKeyExists(const std::string &id)
Definition keyring_p.h:132
PublicKey exportKey(const std::string &id, const Pathname &keyring)
Definition KeyRing.cc:355
PublicKey exportPublicKey(const PublicKeyData &keyData)
Definition keyring_p.h:122
bool isKeyKnown(const std::string &id)
Definition keyring_p.h:106
const std::list< PublicKeyData > & publicKeyData()
Definition keyring_p.h:116
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature)
Definition keyring_p.h:129
void allowPreload(bool yesno_r)
Definition keyring_p.h:137
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
Definition keyring_p.h:124
Impl(const Pathname &baseTmpDir)
Definition KeyRing.cc:212
bool verifyFile(const Pathname &file, const Pathname &signature, const Pathname &keyring)
Definition KeyRing.cc:433
const Pathname generalKeyRing() const
Definition keyring_p.h:166
const std::list< PublicKeyData > & trustedPublicKeyData()
Definition keyring_p.h:114
filesystem::TmpDir _general_tmp_dir
Definition keyring_p.h:174
bool verifyFileSignature(const Pathname &file, const Pathname &signature)
Definition keyring_p.h:127
CachedPublicKeyData cachedPublicKeyData
Functor returning the keyrings data (cached).
Definition keyring_p.h:183
std::string readSignatureKeyId(const Pathname &signature)
Definition KeyRing.cc:417
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Definition KeyRing.cc:242
std::list< PublicKey > publicKeys()
Definition keyring_p.h:111
const std::list< PublicKeyData > & publicKeyData(const Pathname &keyring)
Definition keyring_p.h:158
void deleteKey(const std::string &id, bool trusted)
Definition KeyRing.cc:247
const Pathname trustedKeyRing() const
Definition keyring_p.h:168
filesystem::TmpFile dumpPublicKeyToTmp(const std::string &id, const Pathname &keyring)
Definition KeyRing.cc:372
PublicKey exportKey(const PublicKey &key, const Pathname &keyring)
Definition keyring_p.h:149
filesystem::TmpDir _trusted_tmp_dir
Definition keyring_p.h:173
bool isKeyTrusted(const std::string &id)
Definition keyring_p.h:104
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
Definition keyring_p.h:119