Author: dmacvicar
Date: Wed May 9 18:44:13 2007
New Revision: 5525
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5525&view=rev
Log:
Fixed importing of rpm keys, and lot of cleanup to the code.
(#270125)
Modified:
trunk/libzypp/tests/zypp/KeyRing.cc
trunk/libzypp/zypp/KeyRing.cc
trunk/libzypp/zypp/KeyRing.h
trunk/libzypp/zypp/PublicKey.cc
trunk/libzypp/zypp/PublicKey.h
trunk/libzypp/zypp/target/rpm/RpmDb.cc
trunk/libzypp/zypp/target/rpm/RpmDb.h
Modified: trunk/libzypp/tests/zypp/KeyRing.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/KeyRing.cc?rev=5525&r1=5524&r2=5525&view=diff
==============================================================================
--- trunk/libzypp/tests/zypp/KeyRing.cc (original)
+++ trunk/libzypp/tests/zypp/KeyRing.cc Wed May 9 18:44:13 2007
@@ -153,7 +153,7 @@
disconnect();
}
- virtual void trustedKeyAdded( const KeyRing &keyring, const PublicKey &key )
+ virtual void trustedKeyAdded( const PublicKey &key )
{
MIL << "TEST: trusted key added to zypp Keyring. Syncronizing keys with fake rpm keyring" << std::endl;
_trusted_key_added_called = true;
@@ -162,7 +162,7 @@
//_rpmdb.exportTrustedKeysInZyppKeyRing();
}
- virtual void trustedKeyRemoved( const KeyRing &keyring, const PublicKey &key )
+ virtual void trustedKeyRemoved( const PublicKey &key )
{
}
Modified: trunk/libzypp/zypp/KeyRing.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/KeyRing.cc?rev=5525&r1=5524&r2=5525&view=diff
==============================================================================
--- trunk/libzypp/zypp/KeyRing.cc (original)
+++ trunk/libzypp/zypp/KeyRing.cc Wed May 9 18:44:13 2007
@@ -26,9 +26,8 @@
#include "zypp/ExternalProgram.h"
#include "zypp/TmpPath.h"
-using std::endl;
-using namespace zypp::filesystem;
using namespace std;
+using namespace zypp::filesystem;
#undef ZYPP_BASE_LOGGER_LOGGROUP
#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::KeyRing"
@@ -39,9 +38,9 @@
IMPL_PTR_TYPE(KeyRing);
- static bool printLine( const std::string &line )
+ static bool printLine( const string &line )
{
- MIL << line << std::endl;
+ MIL << line << endl;
return true;
}
@@ -50,10 +49,10 @@
bool _keyRingDefaultAccept( getenv("ZYPP_KEYRING_DEFAULT_ACCEPT_ALL") );
}
- bool KeyRingReport::askUserToAcceptUnsignedFile( const std::string &file )
+ bool KeyRingReport::askUserToAcceptUnsignedFile( const string &file )
{ return _keyRingDefaultAccept; }
- bool KeyRingReport::askUserToAcceptUnknownKey( const std::string &file, const std::string &id )
+ bool KeyRingReport::askUserToAcceptUnknownKey( const string &file, const string &id )
{ return _keyRingDefaultAccept; }
bool KeyRingReport::askUserToTrustKey( const PublicKey &key )
@@ -62,7 +61,7 @@
bool KeyRingReport::askUserToImportKey( const PublicKey &key)
{ return _keyRingDefaultAccept; }
- bool KeyRingReport::askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key )
+ bool KeyRingReport::askUserToAcceptVerificationFailed( const string &file, const PublicKey &key )
{ return _keyRingDefaultAccept; }
///////////////////////////////////////////////////////////////////
@@ -92,32 +91,37 @@
*/
void importKey( const PublicKey &key, bool trusted = false);
- void deleteKey( const std::string &id, bool trusted );
+ void deleteKey( const string &id, bool trusted );
- std::string readSignatureKeyId( const Pathname &signature );
+ string readSignatureKeyId( const Pathname &signature );
- bool isKeyTrusted( const std::string &id);
- bool isKeyKnown( const std::string &id );
+ bool isKeyTrusted( const string &id);
+ bool isKeyKnown( const string &id );
- std::list<PublicKey> trustedPublicKeys();
- std::list<PublicKey> publicKeys();
+ list<PublicKey> trustedPublicKeys();
+ list<PublicKey> publicKeys();
+
+ list<string> trustedPublicKeyIds();
+ list<string> publicKeyIds();
- void dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream );
+ void dumpPublicKey( const string &id, bool trusted, ostream &stream );
- bool verifyFileSignatureWorkflow( const Pathname &file, const std::string filedesc, const Pathname &signature);
+ bool verifyFileSignatureWorkflow( const Pathname &file, const string filedesc, const Pathname &signature);
bool verifyFileSignature( const Pathname &file, const Pathname &signature);
bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature);
private:
- //mutable std::map translations;
+ //mutable map translations;
bool verifyFile( const Pathname &file, const Pathname &signature, const Pathname &keyring);
void importKey( const Pathname &keyfile, const Pathname &keyring);
- PublicKey exportKey( std::string id, const Pathname &keyring);
- void dumpPublicKey( const std::string &id, const Pathname &keyring, std::ostream &stream );
- void deleteKey( const std::string &id, const Pathname &keyring );
- std::list<PublicKey> publicKeys(const Pathname &keyring);
-
- bool publicKeyExists( std::string id, const Pathname &keyring);
+ PublicKey exportKey( string id, const Pathname &keyring);
+ void dumpPublicKey( const string &id, const Pathname &keyring, ostream &stream );
+ void deleteKey( const string &id, const Pathname &keyring );
+
+ list<PublicKey> publicKeys(const Pathname &keyring);
+ list<string> publicKeyIds(const Pathname &keyring);
+
+ bool publicKeyExists( string id, const Pathname &keyring);
const Pathname generalKeyRing() const;
const Pathname trustedKeyRing() const;
@@ -154,24 +158,40 @@
void KeyRing::Impl::importKey( const PublicKey &key, bool trusted)
{
+ callback::SendReport<KeyRingSignals> emitSignal;
+
importKey( key.path(), trusted ? trustedKeyRing() : generalKeyRing() );
+
+ if ( trusted )
+ emitSignal->trustedKeyAdded( key );
+
}
- void KeyRing::Impl::deleteKey( const std::string &id, bool trusted)
+ void KeyRing::Impl::deleteKey( const string &id, bool trusted)
{
deleteKey( id, trusted ? trustedKeyRing() : generalKeyRing() );
}
- std::list<PublicKey> KeyRing::Impl::publicKeys()
+ list<PublicKey> KeyRing::Impl::publicKeys()
{
return publicKeys( generalKeyRing() );
}
- std::list<PublicKey> KeyRing::Impl::trustedPublicKeys()
+ list<PublicKey> KeyRing::Impl::trustedPublicKeys()
{
return publicKeys( trustedKeyRing() );
}
+ list<string> KeyRing::Impl::publicKeyIds()
+ {
+ return publicKeyIds( generalKeyRing() );
+ }
+
+ list<string> KeyRing::Impl::trustedPublicKeyIds()
+ {
+ return publicKeyIds( trustedKeyRing() );
+ }
+
bool KeyRing::Impl::verifyFileTrustedSignature( const Pathname &file, const Pathname &signature)
{
return verifyFile( file, signature, trustedKeyRing() );
@@ -182,25 +202,25 @@
return verifyFile( file, signature, generalKeyRing() );
}
- bool KeyRing::Impl::isKeyTrusted( const std::string &id)
+ bool KeyRing::Impl::isKeyTrusted( const string &id)
{
return publicKeyExists( id, trustedKeyRing() );
}
- bool KeyRing::Impl::isKeyKnown( const std::string &id )
+ bool KeyRing::Impl::isKeyKnown( const string &id )
{
- MIL << std::endl;
+ MIL << endl;
if ( publicKeyExists( id, trustedKeyRing() ) )
return true;
else
return publicKeyExists( id, generalKeyRing() );
}
- bool KeyRing::Impl::publicKeyExists( std::string id, const Pathname &keyring)
+ bool KeyRing::Impl::publicKeyExists( string id, const Pathname &keyring)
{
- MIL << "Searching key [" << id << "] in keyring " << keyring << std::endl;
- std::list<PublicKey> keys = publicKeys(keyring);
- for (std::list<PublicKey>::const_iterator it = keys.begin(); it != keys.end(); it++)
+ MIL << "Searching key [" << id << "] in keyring " << keyring << endl;
+ list<PublicKey> keys = publicKeys(keyring);
+ for (list<PublicKey>::const_iterator it = keys.begin(); it != keys.end(); it++)
{
if ( id == (*it).id() )
return true;
@@ -208,14 +228,14 @@
return false;
}
- PublicKey KeyRing::Impl::exportKey( std::string id, const Pathname &keyring)
+ PublicKey KeyRing::Impl::exportKey( string id, const Pathname &keyring)
{
TmpFile tmp_file( _base_dir, "pubkey-"+id+"-" );
Pathname keyfile = tmp_file.path();
MIL << "Going to export key " << id << " from " << keyring << " to " << keyfile << endl;
try {
- std::ofstream os(keyfile.asString().c_str());
+ ofstream os(keyfile.asString().c_str());
dumpPublicKey( id, keyring, os );
os.close();
PublicKey key(keyfile);
@@ -223,22 +243,22 @@
}
catch (BadKeyException &e)
{
- ERR << "Cannot create public key " << id << " from " << keyring << " keyring to file " << e.keyFile() << std::endl;
+ ERR << "Cannot create public key " << id << " from " << keyring << " keyring to file " << e.keyFile() << endl;
ZYPP_THROW(Exception("Cannot create public key " + id + " from " + keyring.asString() + " keyring to file " + e.keyFile().asString() ) );
}
- catch (std::exception &e)
+ catch (exception &e)
{
- ERR << "Cannot export key " << id << " from " << keyring << " keyring to file " << keyfile << std::endl;
+ ERR << "Cannot export key " << id << " from " << keyring << " keyring to file " << keyfile << endl;
}
return PublicKey();
}
- void KeyRing::Impl::dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream )
+ void KeyRing::Impl::dumpPublicKey( const string &id, bool trusted, ostream &stream )
{
dumpPublicKey( id, ( trusted ? trustedKeyRing() : generalKeyRing() ), stream );
}
- void KeyRing::Impl::dumpPublicKey( const std::string &id, const Pathname &keyring, std::ostream &stream )
+ void KeyRing::Impl::dumpPublicKey( const string &id, const Pathname &keyring, ostream &stream )
{
const char* argv[] =
{
@@ -257,7 +277,7 @@
NULL
};
ExternalProgram prog(argv,ExternalProgram::Discard_Stderr, false, -1, true);
- std::string line;
+ string line;
int count;
for(line = prog.receiveLine(), count=0; !line.empty(); line = prog.receiveLine(), count++ )
{
@@ -267,11 +287,11 @@
}
- bool KeyRing::Impl::verifyFileSignatureWorkflow( const Pathname &file, const std::string filedesc, const Pathname &signature)
+ bool KeyRing::Impl::verifyFileSignatureWorkflow( const Pathname &file, const string filedesc, const Pathname &signature)
{
callback::SendReport<KeyRingReport> report;
//callback::SendReport<KeyRingSignals> emitSignal;
- MIL << "Going to verify signature for " << file << " with " << signature << std::endl;
+ MIL << "Going to verify signature for " << file << " with " << signature << endl;
// if signature does not exists, ask user if he wants to accept unsigned file.
if( signature.empty() || (!PathInfo(signature).isExist()) )
@@ -282,14 +302,14 @@
}
// get the id of the signature
- std::string id = readSignatureKeyId(signature);
+ string id = readSignatureKeyId(signature);
// doeskey exists in trusted keyring
if ( publicKeyExists( id, trustedKeyRing() ) )
{
PublicKey key = exportKey( id, trustedKeyRing() );
- MIL << "Key " << id << " " << key.name() << " is trusted" << std::endl;
+ MIL << "Key " << id << " " << key.name() << " is trusted" << endl;
// it exists, is trusted, does it validates?
if ( verifyFile( file, signature, trustedKeyRing() ) )
return true;
@@ -301,19 +321,19 @@
if ( publicKeyExists( id, generalKeyRing() ) )
{
PublicKey key = exportKey( id, generalKeyRing());
- MIL << "Exported key " << id << " to " << key.path() << std::endl;
- MIL << "Key " << id << " " << key.name() << " is not trusted" << std::endl;
+ MIL << "Exported key " << id << " to " << key.path() << endl;
+ MIL << "Key " << id << " " << key.name() << " is not trusted" << endl;
// ok the key is not trusted, ask the user to trust it or not
#warning We need the key details passed to the callback
if ( report->askUserToTrustKey( key ) )
{
- MIL << "User wants to trust key " << id << " " << key.name() << std::endl;
+ MIL << "User wants to trust key " << id << " " << key.name() << endl;
//dumpFile(unKey.path());
Pathname which_keyring;
if ( report->askUserToImportKey( key ) )
{
- MIL << "User wants to import key " << id << " " << key.name() << std::endl;
+ MIL << "User wants to import key " << id << " " << key.name() << endl;
importKey( key, true );
which_keyring = trustedKeyRing();
}
@@ -325,42 +345,42 @@
// emit key added
if ( verifyFile( file, signature, which_keyring ) )
{
- MIL << "File signature is verified" << std::endl;
+ MIL << "File signature is verified" << endl;
return true;
}
else
{
- MIL << "File signature check fails" << std::endl;
+ MIL << "File signature check fails" << endl;
if ( report->askUserToAcceptVerificationFailed( filedesc, key ) )
{
- MIL << "User continues anyway." << std::endl;
+ MIL << "User continues anyway." << endl;
return true;
}
else
{
- MIL << "User does not want to continue" << std::endl;
+ MIL << "User does not want to continue" << endl;
return false;
}
}
}
else
{
- MIL << "User does not want to trust key " << id << " " << key.name() << std::endl;
+ MIL << "User does not want to trust key " << id << " " << key.name() << endl;
return false;
}
}
else
{
// unknown key...
- MIL << "File [" << file << "] ( " << filedesc << " ) signed with unknown key [" << id << "]" << std::endl;
+ MIL << "File [" << file << "] ( " << filedesc << " ) signed with unknown key [" << id << "]" << endl;
if ( report->askUserToAcceptUnknownKey( filedesc, id ) )
{
- MIL << "User wants to accept unknown key " << id << std::endl;
+ MIL << "User wants to accept unknown key " << id << endl;
return true;
}
else
{
- MIL << "User does not want to accept unknown key " << id << std::endl;
+ MIL << "User does not want to accept unknown key " << id << endl;
return false;
}
}
@@ -368,11 +388,13 @@
return false;
}
- std::list<PublicKey> KeyRing::Impl::publicKeys(const Pathname &keyring)
+ list<string> KeyRing::Impl::publicKeyIds(const Pathname &keyring)
{
static str::regex rxColons("^([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):\n$");
static str::regex rxColonsFpr("^([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):\n$");
+ list<string> ids;
+
const char* argv[] =
{
"gpg",
@@ -390,24 +412,24 @@
keyring.asString().c_str(),
NULL
};
- std::list<PublicKey> keys;
-
+
ExternalProgram prog(argv,ExternalProgram::Discard_Stderr, false, -1, true);
- std::string line;
+ string line;
int count = 0;
for(line = prog.receiveLine(), count=0; !line.empty(); line = prog.receiveLine(), count++ )
{
- //MIL << line << std::endl;
+ //MIL << line << endl;
str::smatch what;
if(str::regex_match(line, what, rxColons, str::match_extra))
{
string id;
+ string fingerprint;
if ( what[1] == "pub" )
{
id = what[5];
- std::string line2;
+ string line2;
for(line2 = prog.receiveLine(); !line2.empty(); line2 = prog.receiveLine(), count++ )
{
str::smatch what2;
@@ -415,19 +437,35 @@
{
if ( (what2[1] == "fpr") && (what2[1] != "pub") && (what2[1] !="sub"))
{
- //key.fingerprint = what2[10];
+ fingerprint = what2[10];
break;
}
}
}
- PublicKey key(exportKey( id, keyring ));
- keys.push_back(key);
- MIL << "Found key " << "[" << key.id() << "]" << " [" << key.name() << "]" << " [" << key.fingerprint() << "]" << std::endl;
+
+ ids.push_back(id);
+ MIL << "Found key " << "[" << id << "]" << endl;
}
//dumpRegexpResults(what);
}
}
prog.close();
+ return ids;
+ }
+
+ list<PublicKey> KeyRing::Impl::publicKeys(const Pathname &keyring)
+ {
+
+ list<PublicKey> keys;
+
+ list<string> ids = publicKeyIds(keyring);
+
+ for ( list<string>::const_iterator it = ids.begin(); it != ids.end(); ++it )
+ {
+ PublicKey key(exportKey( *it, keyring ));
+ keys.push_back(key);
+ MIL << "Found key " << "[" << key.id() << "]" << " [" << key.name() << "]" << " [" << key.fingerprint() << "]" << endl;
+ }
return keys;
}
@@ -461,7 +499,7 @@
// ZYPP_THROW(Exception("failed to import key"));
}
- void KeyRing::Impl::deleteKey( const std::string &id, const Pathname &keyring )
+ void KeyRing::Impl::deleteKey( const string &id, const Pathname &keyring )
{
const char* argv[] =
{
@@ -486,13 +524,13 @@
if ( code )
ZYPP_THROW(Exception("Failed to delete key."));
else
- MIL << "Deleted key " << id << " from keyring " << keyring << std::endl;
+ MIL << "Deleted key " << id << " from keyring " << keyring << endl;
}
- std::string KeyRing::Impl::readSignatureKeyId(const Pathname &signature )
+ string KeyRing::Impl::readSignatureKeyId(const Pathname &signature )
{
- MIL << "Deetermining key id if signature " << signature << std::endl;
+ MIL << "Deetermining key id if signature " << signature << endl;
// HACK create a tmp keyring with no keys
TmpDir dir(_base_dir, "fake-keyring");
TmpFile fakeData(_base_dir, "fake-data");
@@ -517,14 +555,14 @@
ExternalProgram prog(argv,ExternalProgram::Discard_Stderr, false, -1, true);
- std::string line;
+ string line;
int count = 0;
str::regex rxNoKey("^\\[GNUPG:\\] NO_PUBKEY (.+)\n$");
- std::string id;
+ string id;
for(line = prog.receiveLine(), count=0; !line.empty(); line = prog.receiveLine(), count++ )
{
- //MIL << "[" << line << "]" << std::endl;
+ //MIL << "[" << line << "]" << endl;
str::smatch what;
if(str::regex_match(line, what, rxNoKey, str::match_extra))
{
@@ -533,7 +571,7 @@
//dumpRegexpResults(what);
}
}
- MIL << "Determined key id [" << id << "] for signature " << signature << std::endl;
+ MIL << "Determined key id [" << id << "] for signature " << signature << endl;
prog.close();
return id;
}
@@ -616,34 +654,40 @@
void KeyRing::importKey( const PublicKey &key, bool trusted )
{
- callback::SendReport<KeyRingSignals> emitSignal;
- _pimpl->importKey( key.path(), trusted );
-
- if ( trusted )
- emitSignal->trustedKeyAdded( (const KeyRing &)(*this), key );
+ _pimpl->importKey( key.path(), trusted );
}
- std::string KeyRing::readSignatureKeyId( const Pathname &signature )
+ string KeyRing::readSignatureKeyId( const Pathname &signature )
{
return _pimpl->readSignatureKeyId(signature);
}
- void KeyRing::deleteKey( const std::string &id, bool trusted )
+ void KeyRing::deleteKey( const string &id, bool trusted )
{
_pimpl->deleteKey(id, trusted);
}
- std::list<PublicKey> KeyRing::publicKeys()
+ list<PublicKey> KeyRing::publicKeys()
{
return _pimpl->publicKeys();
}
- std::list<PublicKey> KeyRing::trustedPublicKeys()
+ list<PublicKey> KeyRing::trustedPublicKeys()
{
return _pimpl->trustedPublicKeys();
}
- bool KeyRing::verifyFileSignatureWorkflow( const Pathname &file, const std::string filedesc, const Pathname &signature)
+ list<string> KeyRing::publicKeyIds()
+ {
+ return _pimpl->publicKeyIds();
+ }
+
+ list<string> KeyRing::trustedPublicKeyIds()
+ {
+ return _pimpl->trustedPublicKeyIds();
+ }
+
+ bool KeyRing::verifyFileSignatureWorkflow( const Pathname &file, const string filedesc, const Pathname &signature)
{
return _pimpl->verifyFileSignatureWorkflow(file, filedesc, signature);
}
@@ -658,17 +702,17 @@
return _pimpl->verifyFileTrustedSignature(file, signature);
}
- void KeyRing::dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream )
+ void KeyRing::dumpPublicKey( const string &id, bool trusted, ostream &stream )
{
_pimpl->dumpPublicKey( id, trusted, stream);
}
- bool KeyRing::isKeyTrusted( const std::string &id )
+ bool KeyRing::isKeyTrusted( const string &id )
{
return _pimpl->isKeyTrusted(id);
}
- bool KeyRing::isKeyKnown( const std::string &id )
+ bool KeyRing::isKeyKnown( const string &id )
{
return _pimpl->isKeyKnown(id);
}
Modified: trunk/libzypp/zypp/KeyRing.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/KeyRing.h?rev=5525&r1=5524&r2=5525&view=diff
==============================================================================
--- trunk/libzypp/zypp/KeyRing.h (original)
+++ trunk/libzypp/zypp/KeyRing.h Wed May 9 18:44:13 2007
@@ -63,9 +63,9 @@
struct KeyRingSignals : public callback::ReportBase
{
- virtual void trustedKeyAdded( const KeyRing &/*keyring*/, const PublicKey &/*key*/ )
+ virtual void trustedKeyAdded( const PublicKey &/*key*/ )
{}
- virtual void trustedKeyRemoved( const KeyRing &/*keyring*/, const PublicKey &/*key*/ )
+ virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
{}
};
@@ -144,9 +144,26 @@
*/
void deleteKey( const std::string &id, bool trusted = false);
+ /**
+ * Get a list of public keys in the keyring
+ */
std::list<PublicKey> publicKeys();
+
+ /**
+ * Get a list of trusted public keys in the keyring
+ */
std::list<PublicKey> trustedPublicKeys();
-
+
+ /**
+ * Get a list of public key ids in the keyring
+ */
+ std::liststd::string publicKeyIds();
+
+ /**
+ * Get a list of trusted public key ids in the keyring
+ */
+ std::liststd::string trustedPublicKeyIds();
+
/**
* Follows a signature verification interacting with the user.
* The boolr eturned depends on user desicion to trust or not.
Modified: trunk/libzypp/zypp/PublicKey.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PublicKey.cc?rev=5525&r1=5524&r2=5525&view=diff
==============================================================================
--- trunk/libzypp/zypp/PublicKey.cc (original)
+++ trunk/libzypp/zypp/PublicKey.cc Wed May 9 18:44:13 2007
@@ -76,6 +76,8 @@
void readFromFile( const Pathname &keyfile)
{
+ static str::regex rxColons("^([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):\n$");
+
PathInfo info(keyfile);
MIL << "Reading pubkey from " << keyfile << " of size " << info.size() << " and sha1 " << filesystem::checksum(keyfile, "sha1")<< endl;
if ( !info.isExist() )
@@ -110,8 +112,6 @@
std::string line;
int count = 0;
- str::regex rxColons("^([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):\n$");
-
// pub:-:1024:17:A84EDAE89C800ACA:2000-10-19:2008-06-21::-:SuSE Package Signing Key :
for(line = prog.receiveLine(), count=0; !line.empty(); line = prog.receiveLine(), count++ )
@@ -200,6 +200,16 @@
Pathname PublicKey::path() const
{ return _pimpl->path(); }
+ bool PublicKey::operator==( PublicKey b ) const
+ {
+ return (b.id() == id()) && (b.fingerprint() == fingerprint() );
+ }
+
+ bool PublicKey::operator==( std::string sid ) const
+ {
+ return sid == id();
+ }
+
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
Modified: trunk/libzypp/zypp/PublicKey.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PublicKey.h?rev=5525&r1=5524&r2=5525&view=diff
==============================================================================
--- trunk/libzypp/zypp/PublicKey.h (original)
+++ trunk/libzypp/zypp/PublicKey.h Wed May 9 18:44:13 2007
@@ -90,11 +90,8 @@
std::string fingerprint() const;
Pathname path() const;
- bool operator==( PublicKey b )
- { return (b.id() == id()) && (b.fingerprint() == fingerprint() ); }
-
- bool operator==( std::string sid )
- { return sid == id(); }
+ bool operator==( PublicKey b ) const;
+ bool operator==( std::string sid ) const;
private:
/** Pointer to implementation */
Modified: trunk/libzypp/zypp/target/rpm/RpmDb.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/target/rpm/RpmDb.cc?rev=5525&r1=5524&r2=5525&view=diff
==============================================================================
--- trunk/libzypp/zypp/target/rpm/RpmDb.cc (original)
+++ trunk/libzypp/zypp/target/rpm/RpmDb.cc Wed May 9 18:44:13 2007
@@ -61,11 +61,11 @@
namespace
{
const char* quoteInFilename_m = " \t";
-inline std::string rpmQuoteFilename( const Pathname & path_r )
+inline string rpmQuoteFilename( const Pathname & path_r )
{
- std::string path( path_r.asString() );
- for ( std::string::size_type pos = path.find_first_of( quoteInFilename_m );
- pos != std::string::npos;
+ string path( path_r.asString() );
+ for ( string::size_type pos = path.find_first_of( quoteInFilename_m );
+ pos != string::npos;
pos = path.find_first_of( quoteInFilename_m, pos ) )
{
path.insert( pos, "\\" );
@@ -87,22 +87,21 @@
disconnect();
}
- virtual void trustedKeyAdded( const KeyRing &keyring, const PublicKey &key )
+ virtual void trustedKeyAdded( const PublicKey &key )
{
- MIL << "trusted key added to zypp Keyring. Importing" << std::endl;
+ MIL << "trusted key added to zypp Keyring. Importing" << endl;
// now import the key in rpm
try
{
- _rpmdb.importPubkey( key.path() );
- MIL << "Trusted key " << key.id() << " (" << key.name() << ") imported in rpm database." << std::endl;
+ _rpmdb.importPubkey( key );
}
catch (RpmException &e)
{
- ERR << "Could not import key " << key.id() << " (" << key.name() << " from " << key.path() << " in rpm database" << std::endl;
+ ERR << "Could not import key " << key.id() << " (" << key.name() << " from " << key.path() << " in rpm database" << endl;
}
}
- virtual void trustedKeyRemoved( const KeyRing &keyring, const PublicKey &key )
+ virtual void trustedKeyRemoved( const PublicKey &key )
{}
RpmDb &_rpmdb;
@@ -110,7 +109,7 @@
static shared_ptr<KeyRingSignalReceiver> sKeyRingReceiver;
-unsigned diffFiles(const std::string file1, const std::string file2, std::string& out, int maxlines)
+unsigned diffFiles(const string file1, const string file2, string& out, int maxlines)
{
const char* argv[] =
{
@@ -213,7 +212,7 @@
{
public:
listPackage::Ptr _list;
- mapstd::string,Package::Ptr _index;
+ map _index;
bool _valid;
Packages() : _valid( false )
{}
@@ -329,9 +328,9 @@
//
//
// METHOD NAME : RpmDb::dumpOn
-// METHOD TYPE : std::ostream &
+// METHOD TYPE : ostream &
//
-std::ostream & RpmDb::dumpOn( std::ostream & str ) const
+ostream & RpmDb::dumpOn( ostream & str ) const
{
str << "RpmDb[";
@@ -454,8 +453,9 @@
}
#endif
- MIL << "Syncronizing keys with zypp keyring" << std::endl;
- importZyppKeyRingTrustedKeys();
+ MIL << "Syncronizing keys with zypp keyring" << endl;
+ // we do this one by one now.
+ //importZyppKeyRingTrustedKeys();
exportTrustedKeysInZyppKeyRing();
// Close the database in case any write acces (create/convert)
@@ -887,89 +887,55 @@
void RpmDb::exportTrustedKeysInZyppKeyRing()
{
- MIL << "Exporting rpm keyring into zypp trusted keyring" <keyRing()->trustedPublicKeys();
- for ( std::set<Edition>::const_iterator it = rpm_keys.begin(); it != rpm_keys.end(); ++it)
+ for ( set<Edition>::const_iterator it = rpm_keys.begin(); it != rpm_keys.end(); ++it)
+ {
+ // search the zypp key into the rpm keys
+ // long id is edition version + release
+ string id = str::toUpper( (*it).version() + (*it).release());
+ list<PublicKey>::iterator ik = find( zypp_keys.begin(), zypp_keys.end(), id);
+ if ( ik != zypp_keys.end() )
{
- // search the zypp key into the rpm keys
- // long id is edition version + release
- std::string id = str::toUpper( (*it).version() + (*it).release());
- std::list<PublicKey>::iterator ik = find( zypp_keys.begin(), zypp_keys.end(), id);
- if ( ik != zypp_keys.end() )
+ MIL << "Key " << (*it) << " is already in zypp database." << endl;
+ }
+ else
+ {
+ // we export the rpm key into a file
+ RpmHeader::constPtr result = new RpmHeader();
+ getData( string("gpg-pubkey"), *it, result );
+ TmpFile file(getZYpp()->tmpPath());
+ ofstream os;
+ try
{
- MIL << "Key " << (*it) << " is already in zypp database." << std::endl;
+ os.open(file.path().asString().c_str());
+ // dump rpm key into the tmp file
+ os << result->tag_description();
+ //MIL << "-----------------------------------------------" << endl;
+ //MIL << result->tag_description() <tmpPath());
- std::ofstream os;
- try
- {
- os.open(file.path().asString().c_str());
- // dump rpm key into the tmp file
- os << result->tag_description();
- //MIL << "-----------------------------------------------" << std::endl;
- //MIL << result->tag_description() <keyRing()->importKey( file.path(), true /*trusted*/);
- MIL << "Trusted key " << (*it) << " imported in zypp keyring." << std::endl;
- }
- catch (Exception &e)
- {
- ERR << "Could not import key " << (*it) << " in zypp keyring" << std::endl;
- }
+ ERR << "Could not dump key " << (*it) << " in tmp file " << file.path() << endl;
+ // just ignore the key
}
- }
-}
-void RpmDb::importZyppKeyRingTrustedKeys()
-{
- MIL << "Importing zypp trusted keyring" << std::endl;
-
- std::list<PublicKey> rpm_keys = pubkeys();
-
- std::list<PublicKey> zypp_keys;
-
- zypp_keys = getZYpp()->keyRing()->trustedPublicKeys();
-
- for ( std::list<PublicKey>::const_iterator it = zypp_keys.begin(); it != zypp_keys.end(); ++it)
- {
- // we find only the left part of the long gpg key, as rpm does not support long ids
- std::list<PublicKey>::iterator ik = find( rpm_keys.begin(), rpm_keys.end(), (*it));
- if ( ik != rpm_keys.end() )
- {
- MIL << "Key " << (*it).id() << " (" << (*it).name() << ") is already in rpm database." << std::endl;
- }
- else
- {
- // now import the key in rpm
+ // now import the key in zypp
try
{
- importPubkey((*it).path());
- MIL << "Trusted key " << (*it).id() << " (" << (*it).name() << ") imported in rpm database." << std::endl;
+ getZYpp()->keyRing()->importKey( file.path(), true /*trusted*/);
+ MIL << "Trusted key " << (*it) << " imported in zypp keyring." << endl;
}
- catch (RpmException &e)
+ catch (Exception &e)
{
- ERR << "Could not import key " << (*it).id() << " (" << (*it).name() << " from " << (*it).path() << " in rpm database" << std::endl;
+ ERR << "Could not import key " << (*it) << " in zypp keyring" << endl;
}
}
}
@@ -981,14 +947,32 @@
// METHOD NAME : RpmDb::importPubkey
// METHOD TYPE : PMError
//
-void RpmDb::importPubkey( const Pathname & pubkey_r )
+void RpmDb::importPubkey( const PublicKey & pubkey_r )
{
FAILIFNOTINITIALIZED;
+ // check if the key is already in the rpm database and just
+ // return if it does.
+ set<Edition> rpm_keys = pubkeyEditions();
+ for ( set<Edition>::const_iterator it = rpm_keys.begin(); it != rpm_keys.end(); ++it)
+ {
+ string id = str::toUpper( (*it).version() );
+ string keyshortid = pubkey_r.id().substr(0,8);
+ MIL << "Comparing '" << id << "' to '" << keyshortid << "'" << endl;
+ if ( id == keyshortid )
+ {
+ // they match id
+ // FIXME id is not sufficient?
+ MIL << "Key " << pubkey_r << " is already in the rpm trusted keyring." << endl;
+ return;
+ }
+ }
+ // key does not exists, lets import it
+
RpmArgVec opts;
opts.push_back ( "--import" );
opts.push_back ( "--" );
- opts.push_back ( pubkey_r.asString().c_str() );
+ opts.push_back ( pubkey_r.path().asString().c_str() );
// don't call modifyDatabase because it would remove the old
// rpm3 database, if the current database is a temporary one.
@@ -1017,7 +1001,7 @@
}
else
{
- MIL << "Imported public key from file " << pubkey_r << endl;
+ MIL << "Key " << pubkey_r << " imported in rpm trusted keyring." << endl;
}
}
@@ -1039,25 +1023,25 @@
{
// we export the rpm key into a file
RpmHeader::constPtr result = new RpmHeader();
- getData( std::string("gpg-pubkey"), edition, result );
+ getData( string("gpg-pubkey"), edition, result );
TmpFile file(getZYpp()->tmpPath());
- std::ofstream os;
+ ofstream os;
try
{
os.open(file.path().asString().c_str());
// dump rpm key into the tmp file
os << result->tag_description();
- //MIL << "-----------------------------------------------" << std::endl;
- //MIL << result->tag_description() <tag_description() <Package::Ptr &
+// METHOD TYPE : const listPackage::Ptr &
//
// DESCRIPTION :
//
-const std::listPackage::Ptr & RpmDb::getPackages()
+const listPackage::Ptr & RpmDb::getPackages()
{
callback::SendReport<ScanDBReport> report;
@@ -1106,7 +1090,7 @@
try
{
- const std::listPackage::Ptr & ret = doGetPackages(report);
+ const listPackage::Ptr & ret = doGetPackages(report);
report->finish(ScanDBReport::NO_ERROR, "");
return ret;
}
@@ -1116,7 +1100,7 @@
ZYPP_RETHROW(excpt_r);
}
#warning fixme
- static const std::listPackage::Ptr empty_list;
+ static const listPackage::Ptr empty_list;
return empty_list;
}
@@ -1125,7 +1109,7 @@
// make Package::Ptr from RpmHeader
// return NULL on error
//
-Package::Ptr RpmDb::makePackageFromHeader( const RpmHeader::constPtr header, std::setstd::string * filerequires, const Pathname & location, Source_Ref source )
+Package::Ptr RpmDb::makePackageFromHeader( const RpmHeader::constPtr header, set<string> * filerequires, const Pathname & location, Source_Ref source )
{
if ( ! header )
return 0;
@@ -1229,7 +1213,7 @@
}
-const std::listPackage::Ptr & RpmDb::doGetPackages(callback::SendReport<ScanDBReport> & report)
+const listPackage::Ptr & RpmDb::doGetPackages(callback::SendReport<ScanDBReport> & report)
{
if ( packagesValid() )
{
@@ -1309,10 +1293,10 @@
//
// DESCRIPTION :
//
-std::list<FileInfo>
-RpmDb::fileList( const std::string & name_r, const Edition & edition_r ) const
+list<FileInfo>
+RpmDb::fileList( const string & name_r, const Edition & edition_r ) const
{
- std::list<FileInfo> result;
+ list<FileInfo> result;
librpmDb::db_const_iterator it;
bool found;
@@ -1339,7 +1323,7 @@
//
// DESCRIPTION :
//
-bool RpmDb::hasFile( const std::string & file_r, const std::string & name_r ) const
+bool RpmDb::hasFile( const string & file_r, const string & name_r ) const
{
librpmDb::db_const_iterator it;
bool res;
@@ -1365,7 +1349,7 @@
//
// DESCRIPTION :
//
-std::string RpmDb::whoOwnsFile( const std::string & file_r) const
+string RpmDb::whoOwnsFile( const string & file_r) const
{
librpmDb::db_const_iterator it;
if (it.findByFile( file_r ))
@@ -1383,7 +1367,7 @@
//
// DESCRIPTION :
//
-bool RpmDb::hasProvides( const std::string & tag_r ) const
+bool RpmDb::hasProvides( const string & tag_r ) const
{
librpmDb::db_const_iterator it;
return it.findByProvides( tag_r );
@@ -1397,7 +1381,7 @@
//
// DESCRIPTION :
//
-bool RpmDb::hasRequiredBy( const std::string & tag_r ) const
+bool RpmDb::hasRequiredBy( const string & tag_r ) const
{
librpmDb::db_const_iterator it;
return it.findByRequiredBy( tag_r );
@@ -1411,7 +1395,7 @@
//
// DESCRIPTION :
//
-bool RpmDb::hasConflicts( const std::string & tag_r ) const
+bool RpmDb::hasConflicts( const string & tag_r ) const
{
librpmDb::db_const_iterator it;
return it.findByConflicts( tag_r );
@@ -1471,7 +1455,7 @@
//
// DESCRIPTION :
//
-void RpmDb::getData( const std::string & name_r, const Edition & ed_r,
+void RpmDb::getData( const string & name_r, const Edition & ed_r,
RpmHeader::constPtr & result_r ) const
{
librpmDb::db_const_iterator it;
@@ -1742,7 +1726,7 @@
break;
}
file += Date(Date::now()).form("config_diff_%Y_%m_%d.log");
- ofstream notify(file.asString().c_str(), std::ios::out|std::ios::app);
+ ofstream notify(file.asString().c_str(), ios::out|ios::app);
if (!notify)
{
ERR << "Could not open " << file << endl;
@@ -1880,7 +1864,7 @@
opts.push_back("--");
// rpm requires additional quoting of special chars:
- std::string quotedFilename( rpmQuoteFilename( filename ) );
+ string quotedFilename( rpmQuoteFilename( filename ) );
opts.push_back ( quotedFilename.c_str() );
modifyDatabase(); // BEFORE run_rpm
@@ -2139,7 +2123,7 @@
return false;
}
- std::ofstream fp ( filestobackupfile.asString().c_str(), std::ios::out|std::ios::trunc );
+ ofstream fp ( filestobackupfile.asString().c_str(), ios::out|ios::trunc );
if (!fp)
{
Modified: trunk/libzypp/zypp/target/rpm/RpmDb.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/target/rpm/RpmDb.h?rev=5525&r1=5524&r2=5525&view=diff
==============================================================================
--- trunk/libzypp/zypp/target/rpm/RpmDb.h (original)
+++ trunk/libzypp/zypp/target/rpm/RpmDb.h Wed May 9 18:44:13 2007
@@ -218,7 +218,7 @@
* \throws RpmException
*
**/
- void importPubkey( const Pathname & pubkey_r );
+ void importPubkey( const PublicKey & pubkey_r );
/**
* Return the long ids of all installed public keys.
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org