Author: mlandres
Date: Fri Jun 27 11:31:23 2008
New Revision: 10476
URL: http://svn.opensuse.org/viewcvs/zypp?rev=10476&view=rev
Log:
- Import newer gpg keys if a trusted key is updated
(bnc#393160)
Added:
branches/SuSE-Linux-10_2-Branch/libzypp/devel/devel.ma/GpgKeyz.cc
Modified:
branches/SuSE-Linux-10_2-Branch/libzypp/VERSION
branches/SuSE-Linux-10_2-Branch/libzypp/devel/devel.ma/Tools.h
branches/SuSE-Linux-10_2-Branch/libzypp/package/libzypp.changes
branches/SuSE-Linux-10_2-Branch/libzypp/zypp/KeyRing.cc
branches/SuSE-Linux-10_2-Branch/libzypp/zypp/PublicKey.cc
branches/SuSE-Linux-10_2-Branch/libzypp/zypp/PublicKey.h
branches/SuSE-Linux-10_2-Branch/libzypp/zypp/base/String.h
branches/SuSE-Linux-10_2-Branch/libzypp/zypp/target/rpm/RpmDb.cc
branches/SuSE-Linux-10_2-Branch/libzypp/zypp/target/rpm/RpmDb.h
Modified: branches/SuSE-Linux-10_2-Branch/libzypp/VERSION
URL: http://svn.opensuse.org/viewcvs/zypp/branches/SuSE-Linux-10_2-Branch/libzypp/VERSION?rev=10476&r1=10475&r2=10476&view=diff
==============================================================================
--- branches/SuSE-Linux-10_2-Branch/libzypp/VERSION (original)
+++ branches/SuSE-Linux-10_2-Branch/libzypp/VERSION Fri Jun 27 11:31:23 2008
@@ -49,17 +49,17 @@
dnl
dnl **************************************************
dnl
-dnl CAUTION: SuSE-SLE-10-SP2-Branch starts with 2.16.50
+dnl CAUTION: SuSE-SLE-10-SP2-Branch starts with 2.16.50
dnl
dnl KEEP LIBZYPP_PATCH BELOW 50 !!!
-dnl
+dnl
dnl **************************************************
dnl ==================================================
m4_define([LIBZYPP_MAJOR], [2])
dnl ==================================================
-m4_define([LIBZYPP_MINOR], [16])
+dnl KEEP LLIBZYPP_MINOR BELOW 30 !!!
+m4_define([LIBZYPP_MINOR], [17])
m4_define([LIBZYPP_COMPATMINOR], [15])
dnl ==================================================
-dnl KEEP LIBZYPP_PATCH BELOW 50 !!!
-m4_define([LIBZYPP_PATCH], [3])
+m4_define([LIBZYPP_PATCH], [0])
dnl ==================================================
Added: branches/SuSE-Linux-10_2-Branch/libzypp/devel/devel.ma/GpgKeyz.cc
URL: http://svn.opensuse.org/viewcvs/zypp/branches/SuSE-Linux-10_2-Branch/libzypp/devel/devel.ma/GpgKeyz.cc?rev=10476&view=auto
==============================================================================
--- branches/SuSE-Linux-10_2-Branch/libzypp/devel/devel.ma/GpgKeyz.cc (added)
+++ branches/SuSE-Linux-10_2-Branch/libzypp/devel/devel.ma/GpgKeyz.cc Fri Jun 27 11:31:23 2008
@@ -0,0 +1,135 @@
+#include "Tools.h"
+#include <iostream>
+#include <fstream>
+#include <list>
+#include <map>
+#include <set>
+
+#include
+#include
+#include
+#include "zypp/base/Exception.h"
+#include "zypp/base/InputStream.h"
+#include "zypp/base/DefaultIntegral.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+using namespace zypp;
+
+///////////////////////////////////////////////////////////////////
+
+static const Pathname sysRoot( "/Local/ma/GPG" );
+
+///////////////////////////////////////////////////////////////////
+
+struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
+{
+ KeyRingSignalsReceive()
+ {
+ connect();
+ }
+ virtual void trustedKeyAdded( const KeyRing &/*keyring*/, const PublicKey &/*key*/ )
+ {
+ USR << endl;
+ }
+ virtual void trustedKeyRemoved( const KeyRing &/*keyring*/, const PublicKey &/*key*/ )
+ {
+ USR << endl;
+ }
+};
+
+///////////////////////////////////////////////////////////////////
+
+void ltrusted()
+{
+ list<PublicKey> trustedPublicKeys;
+ {
+ //zypp::base::LogControl::TmpLineWriter shutUp;
+ KeyRing_Ptr p( getZYpp()->keyRing() );
+ trustedPublicKeys = p->trustedPublicKeys();
+ }
+ USR << "Trusted Keys " << trustedPublicKeys.size() << endl;
+ for_( it, trustedPublicKeys.begin(), trustedPublicKeys.end() )
+ {
+ USR << *it << endl;
+ USR << " Creat: " << (*it).created() << endl;
+ USR << " Expir: " << (*it).expires() << endl;
+ }
+}
+
+///////////////////////////////////////////////////////////////////
+/******************************************************************
+**
+** FUNCTION NAME : main
+** FUNCTION TYPE : int
+*/
+int main( int argc, char * argv[] )
+{
+ INT << "===[START]==========================================" << endl;
+ --argc;
+ ++argv;
+ KeyRingSignalsReceive r;
+
+ if ( 1 )
+ {
+ //zypp::base::LogControl::TmpLineWriter shutUp;
+ getZYpp()->initTarget( sysRoot );
+ }
+
+ Source_Ref a( createSource( "dir:///schnell/CD-ARCHIVE/11.0/GM/DVD/i386/DVD1", "fifi" ) );
+
+ INT << "===[DONE]===========================================" << endl;
+ zypp::base::LogControl::TmpLineWriter shutUp;
+ return 0;
+}
+
+/******************************************************************
+**
+** FUNCTION NAME : main
+** FUNCTION TYPE : int
+*/
+int main2( int argc, char * argv[] )
+{
+ INT << "===[START]==========================================" << endl;
+ --argc;
+ ++argv;
+ KeyRingSignalsReceive r;
+
+
+ KeyRing_Ptr p( getZYpp()->keyRing() );
+
+ //PublicKey ka("/Local/ma/GPG/all-keys/build-9c800aca-40d8063e.asc");
+ PublicKey kb("/Local/ma/GPG/all-keys/build-9c800aca-481f343a.asc");
+
+ SEC << "============================================" << endl;
+ ltrusted();
+ //p->importKey( ka, true );
+ //ltrusted();
+ p->importKey( kb, true );
+ ltrusted();
+
+ SEC << "============================================" << endl;
+
+ if ( 1 )
+ {
+ zypp::base::LogControl::TmpLineWriter shutUp;
+ getZYpp()->initTarget( sysRoot );
+ }
+
+
+
+ INT << "===[DONE]===========================================" << endl;
+ zypp::base::LogControl::TmpLineWriter shutUp;
+ return 0;
+}
+
Modified: branches/SuSE-Linux-10_2-Branch/libzypp/devel/devel.ma/Tools.h
URL: http://svn.opensuse.org/viewcvs/zypp/branches/SuSE-Linux-10_2-Branch/libzypp/devel/devel.ma/Tools.h?rev=10476&r1=10475&r2=10476&view=diff
==============================================================================
--- branches/SuSE-Linux-10_2-Branch/libzypp/devel/devel.ma/Tools.h (original)
+++ branches/SuSE-Linux-10_2-Branch/libzypp/devel/devel.ma/Tools.h Fri Jun 27 11:31:23 2008
@@ -20,6 +20,10 @@
using std::endl;
///////////////////////////////////////////////////////////////////
+
+#define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
+
+///////////////////////////////////////////////////////////////////
//
template<class _Condition>
Modified: branches/SuSE-Linux-10_2-Branch/libzypp/package/libzypp.changes
URL: http://svn.opensuse.org/viewcvs/zypp/branches/SuSE-Linux-10_2-Branch/libzypp/package/libzypp.changes?rev=10476&r1=10475&r2=10476&view=diff
==============================================================================
--- branches/SuSE-Linux-10_2-Branch/libzypp/package/libzypp.changes (original)
+++ branches/SuSE-Linux-10_2-Branch/libzypp/package/libzypp.changes Fri Jun 27 11:31:23 2008
@@ -1,4 +1,12 @@
-------------------------------------------------------------------
+Fri Jun 27 11:29:09 CEST 2008 - ma@suse.de
+
+- Import newer gpg keys if a trusted key is updated
+ (bnc#393160)
+- version 2.17.0
+- revision 10476
+
+-------------------------------------------------------------------
Fri Oct 12 12:36:49 CEST 2007 - ma@suse.de
- SMBIOS DMI modalias matching added (#333152)
Modified: branches/SuSE-Linux-10_2-Branch/libzypp/zypp/KeyRing.cc
URL: http://svn.opensuse.org/viewcvs/zypp/branches/SuSE-Linux-10_2-Branch/libzypp/zypp/KeyRing.cc?rev=10476&r1=10475&r2=10476&view=diff
==============================================================================
--- branches/SuSE-Linux-10_2-Branch/libzypp/zypp/KeyRing.cc (original)
+++ branches/SuSE-Linux-10_2-Branch/libzypp/zypp/KeyRing.cc Fri Jun 27 11:31:23 2008
@@ -75,10 +75,10 @@
bool KeyRingReport::askUserToImportKey( const PublicKey &key)
{ return _keyRingDefaultAccept; }
-
+
bool KeyRingReport::askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key )
{ return _keyRingDefaultAccept; }
-
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : KeyRing::Impl
@@ -107,12 +107,12 @@
void importKey( const PublicKey &key, bool trusted = false);
void deleteKey( const std::string &id, bool trusted );
-
+
std::string readSignatureKeyId( const Pathname &signature );
-
+
bool isKeyTrusted( const std::string &id);
bool isKeyKnown( const std::string &id );
-
+
std::list<PublicKey> trustedPublicKeys();
std::list<PublicKey> publicKeys();
@@ -168,9 +168,11 @@
void KeyRing::Impl::importKey( const PublicKey &key, bool trusted)
{
- callback::SendReport<KeyRingSignals> emitSignal;
-
importKey( key.path(), trusted ? trustedKeyRing() : generalKeyRing() );
+ if ( trusted )
+ {
+ callback::SendReport<KeyRingSignals>()->trustedKeyAdded( trustedKeyRing(), key );
+ }
}
void KeyRing::Impl::deleteKey( const std::string &id, bool trusted)
@@ -202,7 +204,7 @@
{
return publicKeyExists( id, trustedKeyRing() );
}
-
+
bool KeyRing::Impl::isKeyKnown( const std::string &id )
{
if ( publicKeyExists( id, trustedKeyRing() ) )
@@ -210,7 +212,7 @@
else
return publicKeyExists( id, generalKeyRing() );
}
-
+
bool KeyRing::Impl::publicKeyExists( std::string id, const Pathname &keyring)
{
MIL << "Searching key [" << id << "] in keyring " << keyring << std::endl;
@@ -222,13 +224,13 @@
}
return false;
}
-
+
PublicKey KeyRing::Impl::exportKey( std::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());
dumpPublicKey( id, keyring, os );
@@ -252,7 +254,7 @@
{
dumpPublicKey( id, ( trusted ? trustedKeyRing() : generalKeyRing() ), stream );
}
-
+
void KeyRing::Impl::dumpPublicKey( const std::string &id, const Pathname &keyring, std::ostream &stream )
{
const char* argv[] =
@@ -303,7 +305,20 @@
if ( publicKeyExists( id, trustedKeyRing() ) )
{
PublicKey key = exportKey( id, trustedKeyRing() );
-
+
+ // lets look if there is an updated key in the
+ // general keyring
+ if ( publicKeyExists( id, generalKeyRing() ) )
+ {
+ PublicKey untkey = exportKey( id, generalKeyRing() );
+ if ( untkey.created() > key.created() )
+ {
+ MIL << "Key " << key << " was updated. Saving new version into trusted keyring." << endl;
+ importKey( untkey, true );
+ key = untkey;
+ }
+ }
+
MIL << "Key " << id << " " << key.name() << " is trusted" << std::endl;
// it exists, is trusted, does it validates?
if ( verifyFile( file, signature, trustedKeyRing() ) )
@@ -422,9 +437,9 @@
if ( what[1] == "pub" )
{
id = what[5];
-
+
std::string line2;
- for(line2 = prog.receiveLine(); !line2.empty(); line2 = prog.receiveLine(), count++ )
+ for( line2 = prog.receiveLine(); !line2.empty(); line2 = prog.receiveLine(), count++ )
{
str::smatch what2;
if (str::regex_match(line2, what2, rxColonsFpr, str::match_extra))
@@ -446,12 +461,12 @@
prog.close();
return keys;
}
-
+
void KeyRing::Impl::importKey( const Pathname &keyfile, const Pathname &keyring)
{
if ( ! PathInfo(keyfile).isExist() )
ZYPP_THROW(KeyRingException("Tried to import not existant key " + keyfile.asString() + " into keyring " + keyring.asString()));
-
+
const char* argv[] =
{
"gpg",
@@ -629,12 +644,12 @@
//
///////////////////////////////////////////////////////////////////
-
+
void KeyRing::importKey( const PublicKey &key, bool trusted )
{
- _pimpl->importKey( key.path(), trusted );
+ _pimpl->importKey( key, trusted );
}
-
+
std::string KeyRing::readSignatureKeyId( const Pathname &signature )
{
return _pimpl->readSignatureKeyId(signature);
@@ -679,12 +694,12 @@
{
return _pimpl->isKeyTrusted(id);
}
-
+
bool KeyRing::isKeyKnown( const std::string &id )
{
return _pimpl->isKeyTrusted(id);
}
-
+
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
Modified: branches/SuSE-Linux-10_2-Branch/libzypp/zypp/PublicKey.cc
URL: http://svn.opensuse.org/viewcvs/zypp/branches/SuSE-Linux-10_2-Branch/libzypp/zypp/PublicKey.cc?rev=10476&r1=10475&r2=10476&view=diff
==============================================================================
--- branches/SuSE-Linux-10_2-Branch/libzypp/zypp/PublicKey.cc (original)
+++ branches/SuSE-Linux-10_2-Branch/libzypp/zypp/PublicKey.cc Fri Jun 27 11:31:23 2008
@@ -10,21 +10,25 @@
*
*/
#include <iostream>
-//#include "zypp/base/Logger.h"
+#include <vector>
+#include "zypp/base/Logger.h"
+#include "zypp/base/Exception.h"
#include "zypp/base/String.h"
-#include "zypp/PublicKey.h"
+
#include "zypp/ExternalProgram.h"
+#include "zypp/PublicKey.h"
#include "zypp/TmpPath.h"
#include "zypp/PathInfo.h"
-#include "zypp/base/Exception.h"
-#include "zypp/base/Logger.h"
+#include "zypp/Date.h"
+
+//#include <ctime>
using std::endl;
///////////////////////////////////////////////////////////////////
namespace zypp
-{ /////////////////////////////////////////////////////////////////
+{ /////////////////////////////////////////////////////////////////
//
// CLASS NAME : PublicKey::Impl
//
@@ -39,7 +43,7 @@
readFromFile(file);
MIL << "Done reading key" << std::endl;
}
-
+
public:
/** Offer default Impl. */
static shared_ptr<Impl> nullimpl()
@@ -48,51 +52,55 @@
return _nullimpl;
}
-
+#warning FIX asString ====================================================================================
std::string asString() const
{
- return "[" + id() + "] [" + name() + "] [" + fingerprint() + "]";
+ return "[" + id() + "-" + str::hexstring(created(),8).substr(2) + "] [" + name() + "] [" + fingerprint() + "]";
}
-
+
std::string armoredData() const
{ return _data; }
-
+
std::string id() const
{ return _id; }
-
+
std::string name() const
{ return _name; }
-
+
std::string fingerprint() const
{ return _fingerprint; }
-
+
+ Date created() const
+ { return _created; }
+
+ Date expires() const
+ { return _expires; }
+
Pathname path() const
- {
+ {
return _data_file.path();
//return _data_file;
}
-
+
protected:
-
+
void readFromFile( const Pathname &keyfile)
{
+
PathInfo info(keyfile);
- MIL << "Reading pubkey from " << keyfile << " of size " << info.size() << " and sha1 " << filesystem::checksum(keyfile, "sha1")<< endl;
+ MIL << "Reading pubkey from " << keyfile << " of size " << info.size() << " and sha1 " << filesystem::checksum(keyfile, "sha1")<< endl;
if ( !info.isExist() )
ZYPP_THROW(Exception("Can't read public key from " + keyfile.asString() + ", file not found"));
-
+
if ( copy( keyfile, _data_file.path() ) != 0 )
ZYPP_THROW(Exception("Can't copy public key data from " + keyfile.asString() + " to " + _data_file.path().asString() ));
-
- filesystem::TmpDir dir;
-
const char* argv[] =
{
"gpg",
+ "-v",
"--no-default-keyring",
- "--homedir",
- dir.path().asString().c_str(),
+ "--fixed-list-mode",
"--with-fingerprint",
"--with-colons",
"--quiet",
@@ -104,47 +112,85 @@
_data_file.path().asString().c_str(),
NULL
};
-
+
ExternalProgram prog(argv,ExternalProgram::Discard_Stderr, false, -1, true);
-
+
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++ )
+ bool sawpub = false;
+ bool sawsig = false;
+
+ // pub:-:1024:17:A84EDAE89C800ACA:971961473:1214043198::-:SuSE Package Signing Key :
+ // fpr:::::::::79C179B2E1C820C1890F9994A84EDAE89C800ACA:
+ // sig:::17:A84EDAE89C800ACA:1087899198:::::[selfsig]::13x:
+ // sig:::17:9E40E310000AABA4:980442706::::[User ID not found]:10x:
+ // sig:::1:77B2E6003D25D3D9:980443247::::[User ID not found]:10x:
+ // sub:-:2048:16:197448E88495160C:971961490:1214043258::: [expires: 2008-06-21]
+ // sig:::17:A84EDAE89C800ACA:1087899258:::::[keybind]::18x:
+
+ for ( line = prog.receiveLine(); !line.empty(); line = prog.receiveLine() )
{
- //MIL << "[" << line << "]" << std::endl;
- str::smatch what;
- if(str::regex_match(line, what, rxColons, str::match_extra))
+ // trim trailing NL.
+ if ( line.empty() )
+ continue;
+ if ( line[line.size()-1] == '\n' )
+ line.erase( line.size()-1 );
+
+ // split at ':'
+ std::vectorstd::string words;
+ str::splitFields( line, std::back_inserter(words), ":" );
+ if( words.empty() )
+ continue;
+
+ if ( words[0] == "pub" )
+ {
+ if ( sawpub )
+ continue;
+ sawpub = true;
+ // take default from pub
+ _id = words[4];
+ _name = words[9];
+ _created = Date(str::strtonumDate::ValueType(words[5]));
+ _expires = Date(str::strtonumDate::ValueType(words[6]));
+
+ }
+ else if ( words[0] == "sig" )
+ {
+ if ( sawsig || words[words.size()-2] != "13x" )
+ continue;
+ sawsig = true;
+ // update creation and expire dates from 1st signature type "13x"
+ if ( ! words[5].empty() )
+ _created = Date(str::strtonumDate::ValueType(words[5]));
+ if ( ! words[6].empty() )
+ _expires = Date(str::strtonumDate::ValueType(words[6]));
+ }
+ else if ( words[0] == "fpr" )
{
- if ( what[1] == "pub" )
- {
- _id = what[5];
- _name = what[10];
- //return key;
- }
- else if ( what[1] == "fpr" )
- {
- _fingerprint = what[10];
- }
- //dumpRegexpResults(what);
+ _fingerprint = words[9];
+ }
+ else if ( words[0] == "uid" )
+ {
+ if ( ! words[9].empty() )
+ _name = words[9];
}
}
prog.close();
-
- if (_id.size() == 0 )
- ZYPP_THROW(BadKeyException("File " + keyfile.asString() + " doesn't contain public key data" , keyfile));
+
+ if ( _id.size() == 0 )
+ ZYPP_THROW( BadKeyException( "File " + keyfile.asString() + " doesn't contain public key data" , keyfile ) );
+
+ //replace all escaped semicolon with real ':'
+ str::replace_all( _name, "\\x3a", ":" );
}
-
+
private:
std::string _id;
std::string _name;
std::string _fingerprint;
std::string _data;
filesystem::TmpFile _data_file;
+ Date _created;
+ Date _expires;
//Pathname _data_file;
private:
friend Impl * rwcowClone<Impl>( const Impl * rhs );
@@ -165,7 +211,9 @@
PublicKey::PublicKey( const Pathname &file )
: _pimpl( new Impl(file) )
- {}
+ {
+ MIL << *this << endl;
+ }
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : PublicKey::~PublicKey
@@ -184,22 +232,51 @@
{
return _pimpl->asString();
}
-
+
std::string PublicKey::armoredData() const
{ return _pimpl->armoredData(); }
-
+
std::string PublicKey::id() const
{ return _pimpl->id(); }
-
+
std::string PublicKey::name() const
{ return _pimpl->name(); }
-
+
std::string PublicKey::fingerprint() const
{ return _pimpl->fingerprint(); }
-
+
+ Date PublicKey::created() const
+ { return _pimpl->created(); }
+
+ Date PublicKey::expires() const
+ { return _pimpl->expires(); }
+
Pathname PublicKey::path() const
{ return _pimpl->path(); }
+ bool PublicKey::operator==( PublicKey b ) const
+ {
+ return( b.id() == id()
+ && b.fingerprint() == fingerprint()
+ && b.created() == created() );
+ }
+
+ bool PublicKey::operator==( std::string sid ) const
+ {
+ return sid == id();
+ }
+
+ std::ostream & dumpOn( std::ostream & str, const PublicKey & obj )
+ {
+ str << "[" << obj.name() << "]" << endl;
+ str << " fpr " << obj.fingerprint() << endl;
+ str << " id " << obj.id() << endl;
+ str << " cre " << obj.created() << endl;
+ str << " exp " << obj.expires() << endl;
+ str << "]";
+ return str;
+ }
+
/////////////////////////////////////////////////////////////////
} // namespace zypp
-///////////////////////////////////////////////////////////////////
\ No newline at end of file
+///////////////////////////////////////////////////////////////////
Modified: branches/SuSE-Linux-10_2-Branch/libzypp/zypp/PublicKey.h
URL: http://svn.opensuse.org/viewcvs/zypp/branches/SuSE-Linux-10_2-Branch/libzypp/zypp/PublicKey.h?rev=10476&r1=10475&r2=10476&view=diff
==============================================================================
--- branches/SuSE-Linux-10_2-Branch/libzypp/zypp/PublicKey.h (original)
+++ branches/SuSE-Linux-10_2-Branch/libzypp/zypp/PublicKey.h Fri Jun 27 11:31:23 2008
@@ -25,8 +25,11 @@
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
-
-
+
+ /**
+ * Exception thrown when the supplied key is
+ * not a valid gpg key
+ */
class BadKeyException : public Exception
{
public:
@@ -36,10 +39,10 @@
BadKeyException()
: Exception( "Bad Key Exception" )
{}
-
+
Pathname keyFile() const
{ return _keyfile; }
-
+
/** Ctor taking message.
* Use \ref ZYPP_THROW to throw exceptions.
*/
@@ -51,14 +54,18 @@
private:
Pathname _keyfile;
};
-
-
+
+
+ // forward declaration of class Date
+ class Date;
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : PublicKey
//
- /** Class that represent a GPG Public Key
- */
+ /**
+ * Class that represent a GPG Public Key
+ */
class PublicKey
{
friend std::ostream & operator<<( std::ostream & str, const PublicKey & obj );
@@ -69,29 +76,38 @@
public:
PublicKey();
- /** Ctor
+ /** Ctor
* \throws when data does not make a key
*/
PublicKey(const Pathname &file);
-
+
~PublicKey();
-
+
bool isValid() const
{ return ( ! id().empty() && ! fingerprint().empty() && !path().empty() ); }
-
+
std::string asString() const;
std::string armoredData() const;
std::string id() const;
std::string name() const;
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(); }
-
+
+ /**
+ * Date when the key was created (time is 00:00:00)
+ */
+ Date created() const;
+
+ /**
+ * Date when the key expires (time is 00:00:00)
+ * If the key never expires the date is Date() (i.e. 0 seconds since the epoch (1.1.1970))
+ */
+ Date expires() const;
+
+ Pathname path() const;
+
+ bool operator==( PublicKey b ) const;
+ bool operator==( std::string sid ) const;
+
private:
/** Pointer to implementation */
RWCOW_pointer<Impl> _pimpl;
@@ -102,7 +118,10 @@
inline std::ostream & operator<<( std::ostream & str, const PublicKey & obj )
{ return str << obj.asString(); }
- /////////////////////////////////////////////////////////////////
+ /** \relates PublicKey Detailed stream output */
+ std::ostream & dumpOn( std::ostream & str, const PublicKey & obj );
+
+ /////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
#endif // ZYPP_PUBLICKEY_H
Modified: branches/SuSE-Linux-10_2-Branch/libzypp/zypp/base/String.h
URL: http://svn.opensuse.org/viewcvs/zypp/branches/SuSE-Linux-10_2-Branch/libzypp/zypp/base/String.h?rev=10476&r1=10475&r2=10476&view=diff
==============================================================================
--- branches/SuSE-Linux-10_2-Branch/libzypp/zypp/base/String.h (original)
+++ branches/SuSE-Linux-10_2-Branch/libzypp/zypp/base/String.h Fri Jun 27 11:31:23 2008
@@ -204,6 +204,23 @@
inline _It strtonum( const std::string & str, _It & i )
{ return i = strtonum<_It>( str ); }
//@}
+ ///////////////////////////////////////////////////////////////////
+
+ /**
+ * Looks for text in string and replaces it in place
+ *
+ * \note It only performs substtution in one pass
+ */
+ inline std::string & replace_all( std::string & str, const std::string & from, const std::string & to )
+ {
+ std::string::size_type pos = 0;
+ while( pos < str.length() && (pos = str.find( from, pos )) != std::string::npos )
+ {
+ str.replace( pos, from.size(), to );
+ pos += to.size();
+ }
+ return str;
+ }
///////////////////////////////////////////////////////////////////
/** \name Split. */
@@ -241,6 +258,57 @@
}
return ret;
}
+
+ /** Split \a line_r into fields.
+ * Any single character in \a sepchars_r is treated as a
+ * field separator. The words are passed to OutputIterator
+ * \a result_r.
+ * \code
+ * "" -> words 0
+ * ":" -> words 2 |||
+ * "a" -> words 1 |a|
+ * ":a" -> words 2 ||a|
+ * "a:" -> words 2 |a||
+ * ":a:" -> words 3 ||a||
+ *
+ * \endcode
+ *
+ * \code
+ * std::vectorstd::string words;
+ * str::split( "some line", std::back_inserter(words) )
+ * \endcode
+ *
+ */
+ template<class _OutputIterator>
+ unsigned splitFields( const std::string & line_r,
+ _OutputIterator result_r,
+ const std::string & sepchars_r = ":" )
+ {
+ const char * beg = line_r.c_str();
+ const char * cur = beg;
+ unsigned ret = 0;
+ for ( beg = cur; *beg; beg = cur, ++result_r )
+ {
+ // skip non sepchars
+ while( *cur && !::strchr( sepchars_r.c_str(), *cur ) )
+ ++cur;
+ // build string
+ *result_r = std::string( beg, cur-beg );
+ ++ret;
+ // skip sepchar
+ if ( *cur )
+ {
+ ++cur;
+ if ( ! *cur ) // ending with sepchar
+ {
+ *result_r = std::string(); // add final empty field
+ ++ret;
+ break;
+ }
+ }
+ }
+ return ret;
+ }
//@}
///////////////////////////////////////////////////////////////////
Modified: branches/SuSE-Linux-10_2-Branch/libzypp/zypp/target/rpm/RpmDb.cc
URL: http://svn.opensuse.org/viewcvs/zypp/branches/SuSE-Linux-10_2-Branch/libzypp/zypp/target/rpm/RpmDb.cc?rev=10476&r1=10475&r2=10476&view=diff
==============================================================================
--- branches/SuSE-Linux-10_2-Branch/libzypp/zypp/target/rpm/RpmDb.cc (original)
+++ branches/SuSE-Linux-10_2-Branch/libzypp/zypp/target/rpm/RpmDb.cc Fri Jun 27 11:31:23 2008
@@ -87,15 +87,23 @@
disconnect();
}
- virtual void trustedKeyAdded( const KeyRing &keyring, const PublicKey &key )
+ virtual void trustedKeyAdded( const KeyRing &, const PublicKey &key )
{
- MIL << "trusted key added to zypp Keyring. Syncronizing keys with rpm keyring" << std::endl;
- _rpmdb.importZyppKeyRingTrustedKeys();
- _rpmdb.exportTrustedKeysInZyppKeyRing();
+ MIL << "Trusted key added to zypp Keyring. Importing" << endl;
+ // now import the key in rpm
+ try
+ {
+ _rpmdb.importPubkey( key );
+ }
+ catch (RpmException &e)
+ {
+ 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 KeyRing &, const PublicKey &key )
{
+ ERR << "Can't remove key " << key << " from rpm database." << endl;
}
RpmDb &_rpmdb;
@@ -957,7 +965,7 @@
// now import the key in rpm
try
{
- importPubkey((*it).path());
+ importPubkey(*it);
MIL << "Trusted key " << (*it).id() << " (" << (*it).name() << ") imported in rpm database." << std::endl;
}
catch (RpmException &e)
@@ -975,13 +983,47 @@
// METHOD TYPE : PMError
//
void RpmDb::importPubkey( const Pathname & pubkey_r )
+ { importPubkey( PublicKey(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();
+ string keyshortid = pubkey_r.id().substr(8,8);
+ MIL << "Comparing '" << keyshortid << "' to: ";
+ for ( set<Edition>::const_iterator it = rpm_keys.begin(); it != rpm_keys.end(); ++it)
+ {
+ string id = str::toUpper( (*it).version() );
+ MIL << ", '" << id << "'";
+ if ( id == keyshortid )
+ {
+ // they match id
+ // now check if timestamp is different
+ Date date = Date(str::strtonumDate::ValueType("0x" + (*it).release()));
+ if ( date == pubkey_r.created() )
+ {
+
+ MIL << endl << "Key " << pubkey_r << " is already in the rpm trusted keyring." << endl;
+ return;
+ }
+ else
+ {
+ MIL << endl << "Key " << pubkey_r << " has another version in keyring. ( " << date << " & " << pubkey_r.created() << ")" << endl;
+
+ }
+
+ }
+ }
+ // key does not exists, lets import it
+ MIL << endl;
+
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.
@@ -1006,11 +1048,11 @@
if ( rpm_status != 0 )
{
- ZYPP_THROW(RpmSubprocessException(string("Failed to import public key from file ") + pubkey_r.asString() + string(": rpm returned ") + str::numstring(rpm_status)));
+ ZYPP_THROW(RpmSubprocessException(string("Failed to import public key from file ") + pubkey_r.path().asString() + string(": rpm returned ") + str::numstring(rpm_status)));
}
else
{
- MIL << "Imported public key from file " << pubkey_r << endl;
+ MIL << "Imported public key from file " << pubkey_r.path() << endl;
}
}
Modified: branches/SuSE-Linux-10_2-Branch/libzypp/zypp/target/rpm/RpmDb.h
URL: http://svn.opensuse.org/viewcvs/zypp/branches/SuSE-Linux-10_2-Branch/libzypp/zypp/target/rpm/RpmDb.h?rev=10476&r1=10475&r2=10476&view=diff
==============================================================================
--- branches/SuSE-Linux-10_2-Branch/libzypp/zypp/target/rpm/RpmDb.h (original)
+++ branches/SuSE-Linux-10_2-Branch/libzypp/zypp/target/rpm/RpmDb.h Fri Jun 27 11:31:23 2008
@@ -220,7 +220,15 @@
**/
void importPubkey( const Pathname & pubkey_r );
- /**
+ /**
+ * Import ascii armored public key in file pubkey_r.
+ *
+ * \throws RpmException
+ *
+ **/
+ void importPubkey( const PublicKey & pubkey_r );
+
+ /**
* Return the long ids of all installed public keys.
**/
std::list<PublicKey> pubkeys() const;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org