libzypp 17.38.7
PublicKey.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_PUBLICKEY_H
13#define ZYPP_PUBLICKEY_H
14
15#include <iosfwd>
16#include <list>
17#include <string>
18#include <utility>
19
21
25#include <zypp-core/Pathname.h>
26#include <zypp/Edition.h>
27#include <zypp-core/Date.h>
28
29struct _gpgme_key;
30struct _gpgme_subkey;
31struct _gpgme_key_sig;
32
34namespace zypp
35{
36
37 namespace filesystem
38 {
39 class TmpFile;
40 }
41 class PublicKeyData;
42 class KeyManagerCtx;
43
49 {
50 public:
55 : Exception( "Bad Key Exception" )
56 {}
57
59 { return _keyfile; }
60
64 BadKeyException( const std::string & msg_r, Pathname keyfile = Pathname() )
65 : Exception( msg_r ), _keyfile(std::move(keyfile))
66 {}
67
68 ~BadKeyException() throw() override {};
69 private:
71 };
72
73
80 {
81 public:
84
86
88 explicit operator bool() const;
89
90 public:
92 std::string id() const;
93
95 Date created() const;
96
98 Date expires() const;
99
101 bool expired() const;
102
108 int daysToLive() const;
109
116 std::string asString() const;
117
118 private:
119 struct Impl;
121 friend class PublicKeyData;
122 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
123 PublicSubkeyData(const _gpgme_subkey *rawSubKeyData);
124 };
125
126
128 inline std::ostream & operator<<( std::ostream & str, const PublicSubkeyData & obj )
129 { return str << obj.asString(); }
130
137 {
138 public:
141
143
145 explicit operator bool() const;
146
147 public:
149 std::string id() const;
150
152 std::string name() const;
153
155 Date created() const;
156
158 Date expires() const;
159
161 bool expired() const;
162
168 int daysToLive() const;
169
176 std::string asString() const;
177
178 private:
179 struct Impl;
181 friend class PublicKeyData;
182 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
183 PublicKeySignatureData(const _gpgme_key_sig *rawKeySignatureData);
184 };
185
186
188 inline std::ostream & operator<<( std::ostream & str, const PublicKeySignatureData & obj )
189 { return str << obj.asString(); }
190
201 {
202 public:
205
207
208 PublicKeyData(const PublicKeyData &) = default;
209 PublicKeyData(PublicKeyData &&) noexcept = default;
210 PublicKeyData &operator=(const PublicKeyData &) = default;
211 PublicKeyData &operator=(PublicKeyData &&) noexcept = default;
212
214 explicit operator bool() const;
215
216 public:
218 std::string id() const;
219
221 std::string name() const;
222
224 std::string fingerprint() const;
225
227 std::string algoName() const;
228
230 Date created() const;
231
233 Date expires() const;
234
236 bool expired() const;
237
243 int daysToLive() const;
244
257 std::string expiresAsString() const;
258
260 std::string gpgPubkeyVersion() const;
261
263 std::string gpgPubkeyRelease() const;
264
266 std::string rpmName () const;
267
271
278 std::string asString() const;
279
284 bool isUpdateFor( const PublicKeyData & rhs ) const
285 {
286 // bnc #393160: Comment #30: Compare at least the fingerprint
287 // in case an attacker created a key the the same id.
288 //
289 // bsc#1008325: For keys using subkeys, we'd actually need to compare
290 // the subkey sets, to tell whether a key was updated. because created()
291 // remains unchanged if the primary key is not touched.
292 // For now we wait until a new subkey signs any metadata and treat it as
293 // a new key then (see VerifyFileSignatureLogic)
294 return not rhs || ( fingerprint() == rhs.fingerprint() && created() > rhs.created() );
295 }
296
297 public:
300
302 bool hasSubkeys() const;
303
306
309
313 bool providesKey( const std::string & id_r ) const;
314
318 static bool isSafeKeyId( const std::string & id_r )
319 { return id_r.size() >= 16; }
320
321 public:
323 bool hasSignatures() const;
324
325 public:
328
335 AsciiArt asciiArt() const;
336
337 private:
338 struct Impl;
340
341 friend class KeyManagerCtx;
342 static PublicKeyData fromGpgmeKey(_gpgme_key *data);
343
345 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
346 };
347
348
350 inline std::ostream & operator<<( std::ostream & str, const PublicKeyData & obj )
351 { return str << obj.asString(); }
352
354 std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj ) ZYPP_API;
355
357 bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs ) ZYPP_API;
358
360 inline bool operator!=( const PublicKeyData & lhs, const PublicKeyData & rhs )
361 { return !( lhs == rhs ); }
362
375 {
376 public:
378 struct Impl;
379
380 public:
382 PublicKey();
383
392 explicit PublicKey( const Pathname & keyFile_r );
393
400 explicit PublicKey( const filesystem::TmpFile & sharedFile_r );
401
402 ~PublicKey();
403
405 static PublicKey noThrow( const Pathname & keyFile_r );
406
407 public:
409 const PublicKeyData & keyData() const;
410
412
413 bool isValid() const
414 { return ! ( id().empty() || fingerprint().empty() ); }
415
416 std::string id() const;
417 std::string name() const;
418 std::string fingerprint() const;
419 std::string algoName() const;
420 Date created() const;
421 Date expires() const;
422 std::string expiresAsString() const;
423 bool expired() const;
424 int daysToLive() const;
425 std::string gpgPubkeyVersion() const;
426 std::string gpgPubkeyRelease() const;
427 std::string asString() const;
428 std::string rpmName () const;
429
431 { return keyData().gpgPubkeyEdition(); }
432
433 bool hasSubkeys() const
434 { return keyData().hasSubkeys(); }
435
437 { return keyData().subkeys(); }
438
439 bool providesKey( const std::string & id_r ) const
440 { return keyData().providesKey( id_r ); }
441
442 static bool isSafeKeyId( const std::string & id_r )
443 { return PublicKeyData::isSafeKeyId(id_r); }
444
445 public:
447
449 { return keyData().asciiArt(); }
450
451 public:
453 Pathname path() const;
454
455 bool hasHiddenKeys() const
456 { return not hiddenKeys().empty(); }
457
459 const std::list<PublicKeyData> & hiddenKeys() const;
460
464 bool fileProvidesKey( const std::string & id_r ) const;
465
466 public:
467 bool operator==( const PublicKey & rhs ) const;
468 bool operator!=( const PublicKey & rhs ) const
469 { return not operator==( rhs ); }
470 bool operator==( const std::string & sid ) const;
471 bool operator!=( const std::string & sid ) const
472 { return not operator==( sid ); }
473
474 private:
475 friend class KeyRingImpl;
477 PublicKey( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r );
479 explicit PublicKey( const PublicKeyData & keyData_r );
480
481 private:
484 };
485
486
488 inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
489 { return str << obj.asString(); }
490
492 std::ostream & dumpOn( std::ostream & str, const PublicKey & obj ) ZYPP_API;
493
495} // namespace zypp
497#endif // ZYPP_PUBLICKEY_H
#define ZYPP_API
Definition Globals.h:69
Pathname keyFile() const
Definition PublicKey.h:58
BadKeyException(const std::string &msg_r, Pathname keyfile=Pathname())
Ctor taking message.
Definition PublicKey.h:64
~BadKeyException() override
Dtor.
Definition PublicKey.h:68
BadKeyException()
Ctor taking message.
Definition PublicKey.h:54
Store and operate on date (time_t).
Definition Date.h:33
Edition represents [epoch:]version[-release].
Definition Edition.h:60
Exception()
Default ctor.
Definition Exception.cc:94
Class representing one GPG Public Keys data.
Definition PublicKey.h:201
Iterable< KeySignatureIterator > signatures() const
Iterate all key signatures.
Definition PublicKey.cc:466
Date created() const
Creation / last modification date (latest selfsig).
Definition PublicKey.cc:424
bool expired() const
Whether the key has expired.
Definition PublicKey.cc:430
std::string name() const
Key name.
Definition PublicKey.cc:415
bool hasSignatures() const
Whether signatures is not empty.
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Definition PublicKey.cc:463
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition PublicKey.cc:433
friend class KeyManagerCtx
Definition PublicKey.h:341
std::string rpmName() const
Gpg-pubkey name as computed by rpm.
Definition PublicKey.cc:445
bool hasSubkeys() const
Whether subkeys is not empty.
Definition PublicKey.cc:460
bool isUpdateFor(const PublicKeyData &rhs) const
Whether this could replace rhs in a keyring.
Definition PublicKey.h:284
PublicKeyData()
Default constructed: empty data.
Definition PublicKey.cc:395
const PublicSubkeyData * SubkeyIterator
Definition PublicKey.h:298
Date expires() const
Expiry date, or Date() if the key never expires.
Definition PublicKey.cc:427
std::string algoName() const
Key algorithm string like RSA 2048.
Definition PublicKey.cc:421
PublicKeyData(const PublicKeyData &)=default
static bool isSafeKeyId(const std::string &id_r)
Whether this is a long id (64bit/16byte) or even better a fingerprint.
Definition PublicKey.h:318
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:339
bool providesKey(const std::string &id_r) const
Whether id_r is the id or fingerprint of the primary key or of a subkey.
Definition PublicKey.cc:469
std::string fingerprint() const
Key fingerprint.
Definition PublicKey.cc:418
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created).
Definition PublicKey.cc:442
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id).
Definition PublicKey.cc:439
PublicKeyData(PublicKeyData &&) noexcept=default
static PublicKeyData fromGpgmeKey(_gpgme_key *data)
Definition PublicKey.cc:406
std::string expiresAsString() const
Definition PublicKey.cc:436
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
Definition PublicKey.cc:480
std::string asString() const
Simple string representation.
Definition PublicKey.cc:448
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
Definition PublicKey.h:327
Edition gpgPubkeyEdition() const
Gpg-pubkey Edition built from version and release.
Definition PublicKey.h:269
const PublicKeySignatureData * KeySignatureIterator
Definition PublicKey.h:299
Class representing a signature on a GPG Public Key.
Definition PublicKey.h:137
Date created() const
Creation date.
Definition PublicKey.cc:263
std::string asString() const
Simple string representation.
Definition PublicKey.cc:275
PublicKeySignatureData()
Default constructed: empty data.
Definition PublicKey.cc:238
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:180
int daysToLive() const
Number of days (24h) until the key expires (or since it expired).
Definition PublicKey.cc:272
bool expired() const
Whether the key has expired.
Definition PublicKey.cc:269
std::string id() const
The key ID of key used to create the signature.
Definition PublicKey.cc:257
std::string name() const
The user ID associated with this key, if present.
Definition PublicKey.cc:260
Date expires() const
Expiry date, or Date() if the key never expires.
Definition PublicKey.cc:266
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:375
Edition gpgPubkeyEdition() const
!<
Definition PublicKey.h:430
PublicKeyData::AsciiArt AsciiArt
Definition PublicKey.h:446
AsciiArt asciiArt() const
!<
Definition PublicKey.h:448
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition PublicKey.h:483
PublicKey()
Default ctor.
Definition PublicKey.cc:611
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob contains multiple keys.
Definition PublicKey.cc:643
static bool isSafeKeyId(const std::string &id_r)
!<
Definition PublicKey.h:442
const PublicKeyData & keyData() const
The public keys data (.
Definition PublicKey.cc:637
std::string asString() const
Definition PublicKey.cc:690
std::string fingerprint() const
Definition PublicKey.cc:663
std::string id() const
Definition PublicKey.cc:657
bool operator!=(const std::string &sid) const
Definition PublicKey.h:471
bool operator!=(const PublicKey &rhs) const
Definition PublicKey.h:468
PublicKeyData::SubkeyIterator SubkeyIterator
Definition PublicKey.h:411
bool hasHiddenKeys() const
Definition PublicKey.h:455
friend class KeyRingImpl
Definition PublicKey.h:475
static PublicKey noThrow(const Pathname &keyFile_r)
Static ctor returning an empty PublicKey rather than throwing.
Definition PublicKey.cc:634
bool hasSubkeys() const
!<
Definition PublicKey.h:433
bool providesKey(const std::string &id_r) const
!<
Definition PublicKey.h:439
Iterable< SubkeyIterator > subkeys() const
!<
Definition PublicKey.h:436
bool isValid() const
Definition PublicKey.h:413
Class representing a GPG Public Keys subkeys.
Definition PublicKey.h:80
RWCOW_pointer< Impl > _pimpl
Definition PublicKey.h:120
std::string id() const
Subkey ID.
Definition PublicKey.cc:181
PublicSubkeyData()
Default constructed: empty data.
Definition PublicKey.cc:163
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition PublicKey.cc:193
Date expires() const
Expiry date, or Date() if the key never expires.
Definition PublicKey.cc:187
friend class PublicKeyData
Definition PublicKey.h:121
std::string asString() const
Simple string representation.
Definition PublicKey.cc:196
Date created() const
Creation date.
Definition PublicKey.cc:184
bool expired() const
Whether the key has expired.
Definition PublicKey.cc:190
Random art fingerprint visualization Visualize fingerprint data on a [17x9] (SSH) or [19x11] (GPG) or...
Provide a new empty temporary file and delete it when no longer needed.
Definition TmpPath.h:118
Definition ansi.h:855
String related utilities and Regular expression matching.
Types and functions for filesystem operations.
Definition Glob.cc:24
Easy-to use interface to the ZYPP dependency resolver.
bool operator!=(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:313
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:309
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
relates: Capability Detailed stream output
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
Definition Patch.cc:122
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
PublicKeyData implementation.
Definition PublicKey.cc:296
PublicKeySignatureData implementation.
Definition PublicKey.cc:207
PublicKey implementation.
Definition PublicKey.cc:507
PublicSubkeyData implementation.
Definition PublicKey.cc:133
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469