libzypp 17.31.23
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 <map>
17#include <list>
18#include <set>
19#include <string>
20
21#include <zypp/base/Iterable.h>
22#include <zypp/base/PtrTypes.h>
23#include <zypp/base/Exception.h>
25#include <zypp/Pathname.h>
26#include <zypp/Edition.h>
27#include <zypp/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, const Pathname &keyfile = Pathname() )
65 : Exception( msg_r ), _keyfile(keyfile)
66 {}
68 virtual ~BadKeyException() throw() {};
69 private:
71 };
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 };
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
171 bool inTrustedRing() const;
172
174 bool inKnownRing() const;
175
182 std::string asString() const;
183
184 private:
185 struct Impl;
187 friend class PublicKeyData;
188 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
189 PublicKeySignatureData(const _gpgme_key_sig *rawKeySignatureData);
190 };
192
194 inline std::ostream & operator<<( std::ostream & str, const PublicKeySignatureData & obj )
195 { return str << obj.asString(); }
196
207 {
208 public:
211
213
215 explicit operator bool() const;
216
217 public:
219 std::string id() const;
220
222 std::string name() const;
223
225 std::string fingerprint() const;
226
228 std::string algoName() const;
229
231 Date created() const;
232
234 Date expires() const;
235
237 bool expired() const;
238
244 int daysToLive() const;
245
258 std::string expiresAsString() const;
259
261 std::string gpgPubkeyVersion() const;
262
264 std::string gpgPubkeyRelease() const;
265
267 std::string rpmName () const;
268
271 { return Edition( gpgPubkeyVersion(), gpgPubkeyRelease() ); }
272
279 std::string asString() const;
280
281 public:
284
286 bool hasSubkeys() const;
287
290
293
297 bool providesKey( const std::string & id_r ) const;
298
302 static bool isSafeKeyId( const std::string & id_r )
303 { return id_r.size() >= 16; }
304
305 public:
307 bool hasSignatures() const;
308
309 public:
312
319 AsciiArt asciiArt() const;
320
321 private:
322 struct Impl;
324
325 friend class KeyManagerCtx;
326 static PublicKeyData fromGpgmeKey(_gpgme_key *data);
327
328 PublicKeyData(shared_ptr<Impl> data);
329 friend std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
330 };
332
334 inline std::ostream & operator<<( std::ostream & str, const PublicKeyData & obj )
335 { return str << obj.asString(); }
336
338 std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj );
339
341 bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs );
342
344 inline bool operator!=( const PublicKeyData & lhs, const PublicKeyData & rhs )
345 { return !( lhs == rhs ); }
346
359 {
360 public:
362 struct Impl;
363
364 public:
366 PublicKey();
367
376 explicit PublicKey( const Pathname & keyFile_r );
377
384 explicit PublicKey( const filesystem::TmpFile & sharedFile_r );
385
386 ~PublicKey();
387
389 static PublicKey noThrow( const Pathname & keyFile_r );
390
391 public:
393 const PublicKeyData & keyData() const;
394
396
397 bool isValid() const
398 { return ! ( id().empty() || fingerprint().empty() ); }
399
400 std::string id() const;
401 std::string name() const;
402 std::string fingerprint() const;
403 std::string algoName() const;
404 Date created() const;
405 Date expires() const;
406 std::string expiresAsString() const;
407 bool expired() const;
408 int daysToLive() const;
409 std::string gpgPubkeyVersion() const;
410 std::string gpgPubkeyRelease() const;
411 std::string asString() const;
412 std::string rpmName () const;
413
415 { return keyData().gpgPubkeyEdition(); }
416
417 bool hasSubkeys() const
418 { return keyData().hasSubkeys(); }
419
421 { return keyData().subkeys(); }
422
423 bool providesKey( const std::string & id_r ) const
424 { return keyData().providesKey( id_r ); }
425
426 static bool isSafeKeyId( const std::string & id_r )
427 { return PublicKeyData::isSafeKeyId(id_r); }
428
429 public:
431
433 { return keyData().asciiArt(); }
434
435 public:
437 Pathname path() const;
438
440 const std::list<PublicKeyData> & hiddenKeys() const;
441
445 bool fileProvidesKey( const std::string & id_r ) const;
446
447 public:
448 bool operator==( const PublicKey & rhs ) const;
449 bool operator!=( const PublicKey & rhs ) const
450 { return not operator==( rhs ); }
451 bool operator==( const std::string & sid ) const;
452 bool operator!=( const std::string & sid ) const
453 { return not operator==( sid ); }
454
455 private:
456 friend class KeyRing;
458 PublicKey( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r );
460 explicit PublicKey( const PublicKeyData & keyData_r );
461
462 private:
465 };
467
469 inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
470 { return str << obj.asString(); }
471
473 std::ostream & dumpOn( std::ostream & str, const PublicKey & obj );
474
476} // namespace zypp
478#endif // ZYPP_PUBLICKEY_H
Wrapper for GPGME.
Exception thrown when the supplied key is not a valid gpg key.
Definition: PublicKey.h:49
BadKeyException(const std::string &msg_r, const Pathname &keyfile=Pathname())
Ctor taking message.
Definition: PublicKey.h:64
Pathname keyFile() const
Definition: PublicKey.h:58
virtual ~BadKeyException()
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:61
Base class for Exception.
Definition: Exception.h:146
Gpg key handling.
Definition: KeyRing.h:187
Class representing one GPG Public Keys data.
Definition: PublicKey.h:207
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.cc:488
Iterable< KeySignatureIterator > signatures() const
Iterate all key signatures.
Definition: PublicKey.cc:471
Date created() const
Creation / last modification date (latest selfsig).
Definition: PublicKey.cc:429
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:435
std::string name() const
Key name.
Definition: PublicKey.cc:420
bool hasSignatures() const
Whether signatures is not empty.
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Definition: PublicKey.cc:468
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:438
bool operator!=(const PublicKeyData &lhs, const PublicKeyData &rhs)
NotEqual.
Definition: PublicKey.h:344
const PublicKeySignatureData * KeySignatureIterator
Definition: PublicKey.h:283
std::string rpmName() const
Gpg-pubkey name as computed by rpm.
Definition: PublicKey.cc:450
bool hasSubkeys() const
Whether subkeys is not empty.
Definition: PublicKey.cc:465
PublicKeyData()
Default constructed: empty data.
Definition: PublicKey.cc:400
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:432
std::string algoName() const
Key algorithm string like RSA 2048
Definition: PublicKey.cc:426
static bool isSafeKeyId(const std::string &id_r)
Whether this is a long id (64bit/16byte) or even better a fingerprint.
Definition: PublicKey.h:302
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:323
const PublicSubkeyData * SubkeyIterator
Definition: PublicKey.h:282
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:474
std::string id() const
Key ID.
Definition: PublicKey.cc:417
std::string fingerprint() const
Key fingerprint.
Definition: PublicKey.cc:423
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created)
Definition: PublicKey.cc:447
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
Definition: PublicKey.cc:444
static PublicKeyData fromGpgmeKey(_gpgme_key *data)
Definition: PublicKey.cc:411
std::string expiresAsString() const
Definition: PublicKey.cc:441
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
Definition: PublicKey.h:311
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
Definition: PublicKey.cc:485
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:453
Edition gpgPubkeyEdition() const
Gpg-pubkey Edition built from version and release.
Definition: PublicKey.h:270
std::ostream & operator<<(std::ostream &str, const PublicKeyData &obj)
Stream output.
Definition: PublicKey.h:334
Class representing a signature on a GPG Public Key.
Definition: PublicKey.h:137
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.cc:488
Date created() const
Creation date.
Definition: PublicKey.cc:262
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:274
bool inKnownRing() const
Whether the key has been seen before.
Definition: PublicKey.cc:292
PublicKeySignatureData()
Default constructed: empty data.
Definition: PublicKey.cc:237
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:186
bool inTrustedRing() const
Whether the signature is trusted in rpmdb.
Definition: PublicKey.cc:289
int daysToLive() const
Number of days (24h) until the key expires (or since it expired).
Definition: PublicKey.cc:271
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:268
std::string id() const
The key ID of key used to create the signature.
Definition: PublicKey.cc:256
std::ostream & operator<<(std::ostream &str, const PublicKeySignatureData &obj)
Stream output.
Definition: PublicKey.h:194
std::string name() const
The user ID associated with this key, if present.
Definition: PublicKey.cc:259
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:265
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:359
Pathname path() const
File containing the ASCII armored key.
Definition: PublicKey.cc:645
Edition gpgPubkeyEdition() const
!<
Definition: PublicKey.h:414
PublicKeyData::SubkeyIterator SubkeyIterator
Definition: PublicKey.h:395
std::string expiresAsString() const
Definition: PublicKey.cc:686
bool fileProvidesKey(const std::string &id_r) const
Extends providesKey to look at the hidden keys too.
Definition: PublicKey.cc:651
bool operator==(const PublicKey &rhs) const
Definition: PublicKey.cc:701
AsciiArt asciiArt() const
!<
Definition: PublicKey.h:432
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PublicKey.h:464
PublicKeyData::AsciiArt AsciiArt
Definition: PublicKey.h:430
Date created() const
Definition: PublicKey.cc:674
PublicKey()
Default ctor.
Definition: PublicKey.cc:616
bool expired() const
Definition: PublicKey.cc:680
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob contains multiple keys.
Definition: PublicKey.cc:648
static bool isSafeKeyId(const std::string &id_r)
!<
Definition: PublicKey.h:426
std::string rpmName() const
Definition: PublicKey.cc:698
std::string name() const
Definition: PublicKey.cc:665
Date expires() const
Definition: PublicKey.cc:677
const PublicKeyData & keyData() const
The public keys data (.
Definition: PublicKey.cc:642
std::string gpgPubkeyRelease() const
Definition: PublicKey.cc:692
std::string asString() const
Definition: PublicKey.cc:695
std::string fingerprint() const
Definition: PublicKey.cc:668
std::ostream & operator<<(std::ostream &str, const PublicKey &obj)
Stream output.
Definition: PublicKey.h:469
std::string id() const
Definition: PublicKey.cc:662
std::string algoName() const
Definition: PublicKey.cc:671
int daysToLive() const
Definition: PublicKey.cc:683
std::string gpgPubkeyVersion() const
Definition: PublicKey.cc:689
bool operator!=(const std::string &sid) const
Definition: PublicKey.h:452
bool operator!=(const PublicKey &rhs) const
Definition: PublicKey.h:449
static PublicKey noThrow(const Pathname &keyFile_r)
Static ctor returning an empty PublicKey rather than throwing.
Definition: PublicKey.cc:639
bool hasSubkeys() const
!<
Definition: PublicKey.h:417
bool providesKey(const std::string &id_r) const
!<
Definition: PublicKey.h:423
Iterable< SubkeyIterator > subkeys() const
!<
Definition: PublicKey.h:420
bool isValid() const
Definition: PublicKey.h:397
Class representing a GPG Public Keys subkeys.
Definition: PublicKey.h:80
friend std::ostream & dumpOn(std::ostream &str, const PublicKeyData &obj)
Definition: PublicKey.cc:488
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:120
std::string id() const
Subkey ID.
Definition: PublicKey.cc:180
PublicSubkeyData()
Default constructed: empty data.
Definition: PublicKey.cc:162
std::ostream & operator<<(std::ostream &str, const PublicSubkeyData &obj)
Stream output.
Definition: PublicKey.h:128
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:192
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:186
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:195
Date created() const
Creation date.
Definition: PublicKey.cc:183
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:189
Random art fingerprint visualization Visualize fingerprint data on a [17x9] (SSH) or [19x11] (GPG) or...
Definition: DrunkenBishop.h:62
Provide a new empty temporary file and delete it when no longer needed.
Definition: TmpPath.h:128
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:580
PublicKeyData implementation.
Definition: PublicKey.cc:301
PublicKeySignatureData implementation.
Definition: PublicKey.cc:206
PublicKey implementation.
Definition: PublicKey.cc:512
PublicSubkeyData implementation.
Definition: PublicKey.cc:132
RW_pointer supporting 'copy on write' functionality.
Definition: PtrTypes.h:459