19 #include <zypp-core/ng/pipelines/Expected> 23 #include <zypp/ng/UserRequest> 41 using zyppng::operators::operator|;
45 return makeReadyTask(
false);
49 return makeReadyTask(
true);
64 if ( !res )
return false;
87 ERR <<
"Key [" <<
_keyId <<
"] from known keyring is not valid" << std::endl;
91 MIL <<
"Key [" <<
_keyId <<
"] " << key.
name() <<
" loaded from cache" << std::endl;
99 MIL <<
"User wants to import key [" <<
_keyId <<
"] " << key.
name() <<
" from cache" << std::endl;
101 _context->keyRing()->importKey( key,
true );
118 zypp_co_return zypp_co_await( impl.
execute () );
128 struct VerifyFileSignatureLogic
130 using ZyppContextRefType = ContextRef;
140 struct FoundKeyData {
146 MaybeAwaitable<FoundKeyData> findKey (
const std::string &
id ) {
148 using zyppng::operators::operator|;
151 return makeReadyTask(FoundKeyData());
155 if ( trustedKeyData )
157 MIL <<
"Key is trusted: " << trustedKeyData << std::endl;
158 return makeReadyTask( FoundKeyData{ trustedKeyData,
Ring::Trusted,
true } );
163 if ( generalKeyData )
166 MIL <<
"Key [" <<
id <<
"] " << key.name() <<
" is not trusted" << std::endl;
175 MIL <<
"User wants to trust key [" <<
id <<
"] " << key.name() << std::endl;
179 MIL <<
"User wants to import key [" <<
id <<
"] " << key.name() << std::endl;
186 return makeReadyTask(FoundKeyData { std::move(generalKeyData), std::move(whichKeyring),
true });
190 MIL <<
"User does not want to trust key [" <<
id <<
"] " << key.name() << std::endl;
191 return makeReadyTask(FoundKeyData { std::move(generalKeyData),
Ring::General,
false });
198 | [
this,
id](
bool success ) {
200 return FoundKeyData();
206 return makeReadyTask(FoundKeyData());
217 MIL <<
"Going to verify signature for " << filedesc <<
" ( " << file <<
" ) with " << signature << std::endl;
223 MIL <<
"askUserToAcceptUnsignedFile: " << res << std::endl;
224 return makeReadyTask( makeReturn(res) );
231 MIL <<
"Failed to read the signature from " << signature << std::endl;
233 return makeReadyTask( makeReturn(
false) );
239 std::list<zypp::PublicKeyData> buddies;
242 WAR <<
"buddy " << sid <<
": key id is too short to safely identify a gpg key. Skipping it." << std::endl;
246 MIL <<
"buddy " << sid <<
": already in trusted key ring. Not needed." << std::endl;
251 WAR <<
"buddy " << sid <<
": not available in the public key ring. Skipping it." << std::endl;
254 if ( pk.providesKey(
id) ) {
255 MIL <<
"buddy " << sid <<
": is the signing key. Handled separately." << std::endl;
258 MIL <<
"buddy " << sid <<
": candidate for auto import. Remeber it." << std::endl;
259 buddies.push_back( pk );
262 using zyppng::operators::operator|;
263 return findKey(
id ) | [
this, id, buddies=std::move(buddies)]( FoundKeyData res ) {
270 if ( res._foundKey ) {
274 return makeReturn(
false);
279 if (
_keyRing->pimpl().verifyFile( file, signature, res._whichKeyRing ) )
284 MIL <<
"Validated with trusted key: importing buddy list..." << std::endl;
285 _keyringReport.reportAutoImportKey( buddies, res._foundKey, keyContext );
286 for (
const auto & kd : buddies ) {
294 bool userAnswer =
_keyringReport.askUserToAcceptVerificationFailed( filedesc,
_keyRing->pimpl().exportKey( res._foundKey, res._whichKeyRing ), keyContext );
295 MIL <<
"askUserToAcceptVerificationFailed: " << userAnswer << std::endl;
296 return makeReturn(userAnswer);
300 MIL <<
"File [" << file <<
"] ( " << filedesc <<
" ) signed with unknown key [" <<
id <<
"]" << std::endl;
302 MIL <<
"askUserToAcceptUnknownKey: " << res << std::endl;
303 return makeReturn(res);
306 return makeReturn(
false);
317 inline std::pair<bool, zypp::keyring::VerifyFileContext> makeReturn(
bool res ){
326 auto kr = zyppContext->keyRing();
327 VerifyFileSignatureLogic impl( std::move(zyppContext), std::move(kr), std::move(context_r) );
328 zypp_co_return zypp_co_await( impl.execute () );
333 VerifyFileSignatureLogic impl( std::move(zyppContext), std::move(keyRing), std::move(context_r) );
334 zypp_co_return zypp_co_await( impl.execute () );
MaybeAwaitable< bool > execute()
bool fileValidated() const
Whether the signature was actually successfully verified.
static bool isSafeKeyId(const std::string &id_r)
Whether this is a long id (64bit/16byte) or even better a fingerprint.
zypp::PublicKeyData _foundKey
The key we found or false.
MaybeAwaitable< bool > provideAndImportKeyFromRepository(ContextRef ctx, std::string id_r, zypp::RepoInfo info_r)
Try to find the id in key cache or repository specified in info.
MaybeAwaitable< expected< void > > fetchGpgKeys(ContextRef ctx, zypp::RepoInfo info)
const std::string & signatureId() const
The id of the gpg key which signed the file.
zypp::keyring::VerifyFileContext _verifyContext
This basically means, we knew the key, but it was not trusted.
Class representing one GPG Public Keys data.
Pathname pubkeyCachePath() const
Path where the pubkey caches.
bool importFromKnownKeyring()
What is known about a repository.
I/O context for KeyRing::verifyFileSignatureWorkflow.
std::string asUserString() const
User string: label (alias or name)
const KeyContext & keyContext() const
KeyContext passed to callbacks
zypp::KeyRing_Ptr KeyRingRef
bool signatureIdTrusted() const
Whether the SignatureId is in the trusted keyring (not temp.
void resetResults()
Reset all result values to safe defaults.
Ring _whichKeyRing
The keyring in which we found the key. Valid only if the key is valid.
Pathname repoManagerRoot() const
The RepoManager root directory.
KeyTrust
User reply options for the askUserToTrustKey callback.
bool trusted
Whether the key may validate data. Keys in Ring::General may if the user temp. trusted.
const Pathname & signature() const
Detached signature or empty.
bool gpgKeyUrlsEmpty() const
Whether gpgkey URLs are defined.
typename Context::ProvideType ProvideType
bool isExist() const
Return whether valid stat info exists.
Interim helper class to collect global options and settings.
KeyRingReportHelper _keyringReport
typename ProvideType::Res ProvideRes
const Pathname & file() const
File to verify.
const BuddyKeys & buddyKeys() const
bool info(std::string msg_r, UserData userData_r=UserData())
send message text
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
const RepoInfo repoInfo() const
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Base class for Exception.
bool empty() const
Is the context unknown?
ImportKeyFromRepoLogic(ContextRef context, std::string &&keyId, zypp::RepoInfo &&info)
Wrapper class for ::stat/::lstat.
typename ProvideType::MediaHandle MediaHandle
bool fileAccepted() const
May return true due to user interaction or global defaults even if the signature was not actually ver...
MaybeAwaitable< std::pair< bool, zypp::keyring::VerifyFileContext > > verifyFileSignature(ContextRef zyppContext, zypp::keyring::VerifyFileContext &&context_r)
Follows a signature verification interacting with the user.
void setRepoInfo(const RepoInfo &repoinfo)
ZyppContextRefType _zyppContext
std::string shortFile() const
Short name for file (default: basename).