testsuite/target/Makefile \
testsuite/target/tests/Makefile \
testsuite/media/Makefile \
+ tools/Makefile \
+ tools/zmart/Makefile \
examples/Makefile \
zypp/Makefile \
zypp/base/Makefile \
--- /dev/null
+#include <iostream>
+
+#include <zypp/base/Logger.h>
+#include <zypp/ZYpp.h>
+#include <zypp/ZYppFactory.h>
+
+#include "zypp/Product.h"
+#include "zypp/Package.h"
+#include "zypp/detail/PackageImplIf.h"
+#include "zypp/source/PackageDelta.h"
+#include "zypp/detail/ImplConnect.h"
+
+#include "zypp/SourceFactory.h"
+#include "testsuite/src/utils/TestUtils.h"
+
+using namespace std;
+using namespace zypp;
+using namespace zypp::detail;
+using namespace zypp::source;
+using namespace zypp::packagedelta;
+//using namespace DbXml;
+
+int main()
+{
+ try
+ {
+ ZYpp::Ptr z = getZYpp();
+ //z->initializeTarget("/");
+
+ //SourceManager_Ptr manager = SourceManager::sourceManager();
+
+ //Source_Ref source = SourceFactory().createFrom( Url("dir:/space/rpms/duncan/vim/i386"), "/", "bleh", Pathname() );
+ //Source_Ref source = SourceFactory().createFrom( Url("http://ftp.gwdg.de/pub/suse/update/10.1"), "/", "bleh", Pathname() );
+ Source_Ref source = SourceFactory().createFrom( Url("dir:/mounts/mirror/SuSE/ftp.suse.com/pub/suse/update/10.1"), "/", "bleh", Pathname() );
+ ResStore store = source.resolvables();
+ //zypp::testsuite::utils::dump(store, true, true);
+
+ for (ResStore::const_iterator it = store.begin(); it != store.end(); ++it)
+ {
+ zypp::Package::Ptr res = asKind<zypp::Package>( *it );
+ std::cout << "------------------------------------------" << std::endl;
+ std::cout << res->name() << " " << res->edition() << " " << res->location() << std::endl;
+
+ ResImplTraits<Package::Impl>::constPtr impl( ImplConnect::resimpl( res ) );
+ std::cout << " delta rpms -----------------------------" << std::endl;
+ for ( std::list<DeltaRpm>::const_iterator it = impl->deltaRpms().begin(); it != impl->deltaRpms().end(); ++it )
+ {
+ std::cout << " " << *it << std::endl;
+ }
+ std::cout << " patch rpms -----------------------------" << std::endl;
+ for ( std::list<PatchRpm>::const_iterator it = impl->patchRpms().begin(); it != impl->patchRpms().end(); ++it )
+ {
+ //std::cout << " " << *it << std::endl;
+ }
+ }
+
+ }
+ catch ( const Exception &e )
+ {
+ std::cout << "Sorry, bye" << endl;
+ }
+}
+
+
+
+#include <iostream>
+
#include <zypp/base/Logger.h>
#include <zypp/ZYpp.h>
#include <zypp/ZYppFactory.h>
#include "zypp/Product.h"
#include "zypp/Package.h"
+#include "zypp/PublicKey.h"
+#include "zypp/detail/PackageImplIf.h"
+#include "zypp/source/PackageDelta.h"
+#include "zypp/detail/ImplConnect.h"
#include "zypp/SourceFactory.h"
#include "testsuite/src/utils/TestUtils.h"
-using namespace zypp::detail;
-
using namespace std;
using namespace zypp;
+using namespace zypp::detail;
using namespace zypp::source;
+using namespace zypp::packagedelta;
//using namespace DbXml;
-#define TestKind Selection
-
int main()
{
try
{
ZYpp::Ptr z = getZYpp();
- //z->initializeTarget("/");
-
- //SourceManager_Ptr manager = SourceManager::sourceManager();
-
- Source_Ref source = SourceFactory().createFrom( Url("dir:/space/rpms/duncan/vim/i386"), "/", "bleh", Pathname() );
- ResStore store = source.resolvables();
- //zypp::testsuite::utils::dump(store, true, true);
- for (ResStore::const_iterator it = store.begin(); it != store.end(); ++it)
- {
- zypp::Package::Ptr res = asKind<zypp::Package>( *it );
- MIL << res->name() << " " << res->edition() << " " << res->location() << std::endl;
- }
+ PublicKey key("repomd.xml.key");
+ cout << key << endl;
}
catch ( const Exception &e )
{
- MIL << "Sorry, bye" << endl;
+ std::cout << e.msg() << endl;
}
}
-------------------------------------------------------------------
+Thu Aug 24 15:34:45 CEST 2006 - dmacvicar@suse.de
+
+- new keyring callbacks
+- separate trust key from import key
+- use PublicKey class instead of params, to be able
+ to add more info like photos later (pending #181682)
+- update zmart with those callbacks.
+- better error handling (Exception types)
+- make tmp file names more readable depending on the context
+- r4026
+
+-------------------------------------------------------------------
+Tue Aug 22 22:35:30 CEST 2006 - dmacvicar@suse.de
+
+- decouple probing from source creation, using the new
+ media test for existence functions.
+- r4019
+
+-------------------------------------------------------------------
+
Tue Aug 22 17:56:53 CEST 2006 - mt@suse.de
- Fixed getDoesFileExist to reset the transfer range
void publickey_test()
{
- BOOST_CHECK_THROW( zypp::devel::PublicKey("nonexistant"), Exception );
+ BOOST_CHECK_THROW( zypp::PublicKey("nonexistant"), Exception );
filesystem::TmpFile file;
ofstream str(file.path().asString().c_str(),ofstream::out);
str.flush();
str.close();
- zypp::devel::PublicKey k2(file.path());
+ zypp::PublicKey k2(file.path());
BOOST_CHECK_EQUAL( k2.id(), "A84EDAE89C800ACA" );
BOOST_CHECK_EQUAL( k2.name(), "SuSE Package Signing Key <build@suse.de>" );
BOOST_CHECK_EQUAL( k2.fingerprint(), "79C179B2E1C820C1890F9994A84EDAE89C800ACA" );
-
+ BOOST_REQUIRE( k2.path() != Pathname() );
+ BOOST_REQUIRE( k2 == k2 );
+ // test for a empty key
+ zypp::PublicKey empty_key;
+ BOOST_REQUIRE( ! empty_key.isValid() );
}
test_suite*
## ##################################################
zmart_SOURCES = zmart.cc
-zmart_LDFLAGS = -static
+#zmart_LDFLAGS = -static
.PHONY: always
// or '1\n' -> true
// reads characters from stdin until newline. Defaults to 'false'
static bool
- readCallbackAnswer()
+ readBoolAnswer()
{
+ char c = 0;
+ int count = 0;
+ while ( (c != 'y') && (c != 'Y') && (c != 'N') && (c != 'n') )
+ cin >> c ;
+
+ if ( ( c == 'y' ) || ( c == 'Y' ) )
return true;
+ else
+ return false;
}
///////////////////////////////////////////////////////////////////
{
virtual bool askUserToAcceptUnsignedFile( const std::string &file )
{
- return readCallbackAnswer();
+ cout << file << " is unsigned, continue? [y/n]: " << endl;
+ return readBoolAnswer();
}
- virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+
+ virtual bool askUserToImportKey( const PublicKey &key )
{
- return readCallbackAnswer();
+ cout << "Import key " << key.id() << " in trusted keyring? [y/n]: " << endl;
+ return readBoolAnswer();
+ }
+
+ virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id )
+ {
+ cout << file << " is signed with an unknown key id: " << id << ", continue? [y/n]: " << endl;
+ return readBoolAnswer();
}
- virtual bool askUserToTrustKey( const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+ virtual bool askUserToTrustKey( const PublicKey &key )
{
- return readCallbackAnswer();
+ cout << "Do you want to trust key id " << key.id() << " " << key.name() << " fingerprint:" << key.fingerprint() << " ? [y/n]: " << endl;
+ return readBoolAnswer();
}
- virtual bool askUserToAcceptVerificationFailed( const std::string &file, const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+ virtual bool askUserToAcceptVerificationFailed( const std::string &file,const PublicKey &key )
{
- return readCallbackAnswer();
+ cout << file << "Signature verification for " << file << " with public key id " << key.id() << " " << key.name() << " fingerprint:" << key.fingerprint() << " failed, THIS IS RISKY!. continue? [y/n]: " << endl;
+ return readBoolAnswer();
}
};
{
virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
{
- return readCallbackAnswer();
+ return readBoolAnswer();
}
virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
{
- return readCallbackAnswer();
+ return readBoolAnswer();
}
virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
{
- return readCallbackAnswer();
+ return readBoolAnswer();
}
};
if (vm.count("sources"))
{
- vector<string> sources = vm["input-file"].as< vector<string> >();
+ vector<string> sources = vm["sources"].as< vector<string> >();
//MIL << "Additional sources are: " << sources << "\n";
for ( vector<string>::const_iterator it = sources.begin(); it != sources.end(); ++it )
{
bool KeyRingReport::askUserToAcceptUnsignedFile( const std::string &file )
{ return _keyRingDefaultAccept; }
- bool KeyRingReport::askUserToAcceptUnknownKey( const std::string &file, const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+ bool KeyRingReport::askUserToAcceptUnknownKey( const std::string &file, const std::string &id )
{ return _keyRingDefaultAccept; }
- bool KeyRingReport::askUserToTrustKey( const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+ bool KeyRingReport::askUserToTrustKey( const PublicKey &key )
{ return _keyRingDefaultAccept; }
- bool KeyRingReport::askUserToAcceptVerificationFailed( const std::string &file, const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+ bool KeyRingReport::askUserToImportKey( const PublicKey &key)
{ return _keyRingDefaultAccept; }
-
+
+ bool KeyRingReport::askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key )
+ { return _keyRingDefaultAccept; }
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : KeyRing::Impl
struct KeyRing::Impl
{
Impl(const Pathname &baseTmpDir)
- : _trusted_tmp_dir(baseTmpDir)
- , _general_tmp_dir(baseTmpDir)
+ : _trusted_tmp_dir(baseTmpDir, "zypp-trusted-kr")
+ , _general_tmp_dir(baseTmpDir, "zypp-general-kr")
+ , _base_dir( baseTmpDir )
{
- _base_dir = baseTmpDir;
}
/*
}
*/
- void importKey( const Pathname &keyfile, bool trusted = false);
- PublicKey readPublicKey( const Pathname &keyfile );
- std::string readSignatureKeyId( const Pathname &signature );
-
+ void importKey( const PublicKey &key, bool trusted = false);
void deleteKey( const std::string &id, bool trusted );
+
+ std::string readSignatureKeyId( const Pathname &signature );
+
std::list<PublicKey> trustedPublicKeys();
std::list<PublicKey> publicKeys();
//mutable std::map<Locale, std::string> translations;
bool verifyFile( const Pathname &file, const Pathname &signature, const Pathname &keyring);
void importKey( const Pathname &keyfile, const Pathname &keyring);
-
- void exportKey( std::string id, const Pathname &keyfile, bool trusted);
-
+ 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);
return _trusted_tmp_dir.path();
}
- void KeyRing::Impl::importKey( const Pathname &keyfile, bool trusted)
+ void KeyRing::Impl::importKey( const PublicKey &key, bool trusted)
{
- importKey( keyfile, trusted ? trustedKeyRing() : generalKeyRing() );
+ importKey( key.path(), trusted ? trustedKeyRing() : generalKeyRing() );
}
void KeyRing::Impl::deleteKey( const std::string &id, bool trusted)
std::list<PublicKey> keys = publicKeys(keyring);
for (std::list<PublicKey>::const_iterator it = keys.begin(); it != keys.end(); it++)
{
- if ( id == (*it).id )
+ if ( id == (*it).id() )
return true;
}
return false;
}
-
- void KeyRing::Impl::exportKey( std::string id, const Pathname &keyfile, bool trusted)
+
+ 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, trusted, os );
+ dumpPublicKey( id, keyring, os );
os.close();
+ PublicKey key(keyfile);
+ return key;
+ }
+ catch (BadKeyException &e)
+ {
+ ERR << "Cannot create public key " << id << " from " << keyring << " keyring to file " << e.keyFile() << std::endl;
+ ZYPP_THROW(Exception("Cannot create public key " + id + " from " + keyring.asString() + " keyring to file " + e.keyFile().asString() ) );
}
catch (std::exception &e)
{
- ERR << "Cannot export key " << id << " from " << (trusted ? "trusted" : "untrusted ") << " keyring to file " << keyfile << std::endl;
+ ERR << "Cannot export key " << id << " from " << keyring << " keyring to file " << keyfile << std::endl;
}
+ return PublicKey();
}
void KeyRing::Impl::dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream )
{
- Pathname keyring = trusted ? trustedKeyRing() : generalKeyRing();
+ dumpPublicKey( id, ( trusted ? trustedKeyRing() : generalKeyRing() ), stream );
+ }
+
+ void KeyRing::Impl::dumpPublicKey( const std::string &id, const Pathname &keyring, std::ostream &stream )
+ {
const char* argv[] =
{
"gpg",
// if signature does not exists, ask user if he wants to accept unsigned file.
if( signature.empty() || (!PathInfo(signature).isExist()) )
{
- bool res = report->askUserToAcceptUnsignedFile( filedesc );
- MIL << "User decision on unsigned file: " << res << endl;
- return res;
+ bool res = report->askUserToAcceptUnsignedFile( filedesc );
+ MIL << "User decision on unsigned file: " << res << endl;
+ return res;
}
// get the id of the signature
// doeskey exists in trusted keyring
if ( publicKeyExists( id, trustedKeyRing() ) )
{
- TmpFile trustedKey(_base_dir);
- exportKey( id, trustedKey.path(), true);
- PublicKey key = readPublicKey(trustedKey.path());
- MIL << "Key " << id << " " << key.name << " is trusted" << std::endl;
+ PublicKey key = exportKey( id, trustedKeyRing() );
+
+ MIL << "Key " << id << " " << key.name() << " is trusted" << std::endl;
// it exists, is trusted, does it validates?
if ( verifyFile( file, signature, trustedKeyRing() ) )
return true;
else
- return report->askUserToAcceptVerificationFailed( filedesc, key.id, key.name, key.fingerprint );
+ return report->askUserToAcceptVerificationFailed( filedesc, key );
}
else
{
if ( publicKeyExists( id, generalKeyRing() ) )
{
- TmpFile unKey(_base_dir);
- exportKey( id, unKey.path(), false);
- MIL << "Exported key " << id << " to " << unKey << std::endl;
-
- PublicKey key = readPublicKey(unKey.path());
- MIL << "Key " << id << " " << key.name << " is not trusted" << std::endl;
+ PublicKey key = exportKey( id, generalKeyRing());
+ MIL << "Exported key " << id << " to " << key.path() << std::endl;
+ MIL << "Key " << id << " " << key.name() << " is not trusted" << std::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.id, key.name, key.fingerprint) )
+ #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() << std::endl;
//dumpFile(unKey.path());
- importKey( unKey.path(), trustedKeyRing() );
- emitSignal->trustedKeyAdded( (const KeyRing &)(*this), id, key.name, key.fingerprint );
+ Pathname which_keyring;
+ if ( report->askUserToImportKey( key ) )
+ {
+ MIL << "User wants to import key " << id << " " << key.name() << std::endl;
+ importKey( key.path(), trustedKeyRing() );
+ emitSignal->trustedKeyAdded( (const KeyRing &)(*this), key );
+ which_keyring = trustedKeyRing();
+ }
+ else
+ {
+ which_keyring = generalKeyRing();
+ }
// emit key added
- if ( verifyFile( file, signature, trustedKeyRing() ) )
+ if ( verifyFile( file, signature, which_keyring ) )
{
MIL << "File signature is verified" << std::endl;
return true;
else
{
MIL << "File signature check fails" << std::endl;
- if ( report->askUserToAcceptVerificationFailed( filedesc, key.id, key.name, key.fingerprint ) )
+ if ( report->askUserToAcceptVerificationFailed( filedesc, key ) )
{
MIL << "User continues anyway." << std::endl;
return true;
}
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() << std::endl;
return false;
}
}
{
// unknown key...
MIL << "File [" << file << "] ( " << filedesc << " ) signed with unknown key [" << id << "]" << std::endl;
- if ( report->askUserToAcceptUnknownKey( filedesc, id, "", "" ) )
+ if ( report->askUserToAcceptUnknownKey( filedesc, id ) )
{
MIL << "User wants to accept unknown key " << id << std::endl;
return true;
return false;
}
-
- PublicKey KeyRing::Impl::readPublicKey( const Pathname &keyfile )
- {
- TmpDir dir(_base_dir);
-
- const char* argv[] =
- {
- "gpg",
- "--no-default-keyring",
- "--homedir",
- dir.path().asString().c_str(),
- "--with-fingerprint",
- "--with-colons",
- "--quiet",
- "--no-tty",
- "--no-greeting",
- "--batch",
- "--status-fd",
- "1",
- keyfile.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 <build@suse.de>:
-
- PublicKey key;
- for(line = prog.receiveLine(), count=0; !line.empty(); line = prog.receiveLine(), count++ )
- {
- //MIL << "[" << line << "]" << std::endl;
- str::smatch what;
- if(str::regex_match(line, what, rxColons, str::match_extra))
- {
- if ( what[1] == "pub" )
- {
- key.id = what[5];
- key.name = what[10];
- //return key;
- }
- else if ( what[1] == "fpr" )
- {
- key.fingerprint = what[10];
- }
- //dumpRegexpResults(what);
- }
- }
- prog.close();
- return key;
- }
-
std::list<PublicKey> KeyRing::Impl::publicKeys(const Pathname &keyring)
{
const char* argv[] =
str::smatch what;
if(str::regex_match(line, what, rxColons, str::match_extra))
{
- PublicKey key;
+ string id;
if ( what[1] == "pub" )
{
- key.id = what[5];
- key.name = what[10];
-
+ id = what[5];
+
std::string line2;
for(line2 = prog.receiveLine(); !line2.empty(); line2 = prog.receiveLine(), count++ )
{
{
if ( (what2[1] == "fpr") && (what2[1] != "pub") && (what2[1] !="sub"))
{
- key.fingerprint = what2[10];
+ //key.fingerprint = what2[10];
break;
}
}
}
+ PublicKey key(exportKey( id, keyring ));
keys.push_back(key);
- MIL << "Found key " << "[" << key.id << "]" << " [" << key.name << "]" << " [" << key.fingerprint << "]" << std::endl;
+ MIL << "Found key " << "[" << key.id() << "]" << " [" << key.name() << "]" << " [" << key.fingerprint() << "]" << std::endl;
}
//dumpRegexpResults(what);
}
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",
{
MIL << "Deetermining key id if signature " << signature << std::endl;
// HACK create a tmp keyring with no keys
- TmpDir dir(_base_dir);
- TmpFile fakeData(_base_dir);
+ TmpDir dir(_base_dir, "fake-keyring");
+ TmpFile fakeData(_base_dir, "fake-data");
const char* argv[] =
{
//
///////////////////////////////////////////////////////////////////
- void KeyRing::importKey( const Pathname &keyfile, bool trusted)
+
+ void KeyRing::importKey( const PublicKey &key, bool trusted )
{
- _pimpl->importKey(keyfile, trusted);
+ _pimpl->importKey( key.path(), trusted );
}
-
- PublicKey KeyRing::readPublicKey( const Pathname &keyfile )
- {
- return _pimpl->readPublicKey(keyfile);
- }
-
+
std::string KeyRing::readSignatureKeyId( const Pathname &signature )
{
return _pimpl->readSignatureKeyId(signature);
#include "zypp/Callback.h"
#include "zypp/base/PtrTypes.h"
#include "zypp/Locale.h"
+#include "zypp/PublicKey.h"
///////////////////////////////////////////////////////////////////
namespace zypp
struct KeyRingReport : public callback::ReportBase
{
virtual bool askUserToAcceptUnsignedFile( const std::string &file );
- virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &keyid, const std::string &keyname, const std::string &fingerprint );
- virtual bool askUserToTrustKey( const std::string &keyid, const std::string &keyname, const std::string &fingerprint);
- virtual bool askUserToAcceptVerificationFailed( const std::string &file, const std::string &keyid, const std::string &keyname, const std::string &fingerprint );
+ virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id );
+ virtual bool askUserToTrustKey( const PublicKey &key);
+ virtual bool askUserToImportKey( const PublicKey &key);
+ virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key );
};
struct KeyRingSignals : public callback::ReportBase
{
- virtual void trustedKeyAdded( const KeyRing &keyring, const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+ virtual void trustedKeyAdded( const KeyRing &keyring, const PublicKey &key )
{}
- virtual void trustedKeyRemoved( const KeyRing &keyring, const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+ virtual void trustedKeyRemoved( const KeyRing &keyring, const PublicKey &key )
{}
};
-
- struct PublicKey
- {
- bool operator==(PublicKey b)
- { return (b.id == id) && (b.fingerprint == fingerprint); }
-
- bool operator==(std::string sid)
- { return sid == id; }
-
- std::string id;
- std::string name;
- std::string fingerprint;
- };
+ class KeyRingException : public Exception
+ {
+ public:
+ /** Ctor taking message.
+ * Use \ref ZYPP_THROW to throw exceptions.
+ */
+ KeyRingException()
+ : Exception( "Bad Key Exception" )
+ {}
+ /** Ctor taking message.
+ * Use \ref ZYPP_THROW to throw exceptions.
+ */
+ KeyRingException( const std::string & msg_r )
+ : Exception( msg_r )
+ {}
+ /** Dtor. */
+ virtual ~KeyRingException() throw() {};
+ };
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : KeyRing
* imports a key from a file.
* throw if key was not imported
*/
- void importKey( const Pathname &keyfile, bool trusted = false);
- PublicKey readPublicKey( const Pathname &keyfile );
+ void importKey( const PublicKey &key, bool trusted = false);
void dumpTrustedPublicKey( const std::string &id, std::ostream &stream )
{ dumpPublicKey(id, true, stream); }
* The boolr eturned depends on user desicion to trust or not.
*/
bool verifyFileSignatureWorkflow( const Pathname &file, const std::string filedesc, const Pathname &signature);
-
bool verifyFileSignature( const Pathname &file, const Pathname &signature);
bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature);
///////////////////////////////////////////////////////////////////
namespace zypp
-{ /////////////////////////////////////////////////////////////////
-namespace devel
-{
- ///////////////////////////////////////////////////////////////////
+{ /////////////////////////////////////////////////////////////////
//
// CLASS NAME : PublicKey::Impl
//
std::string asString() const
{
- return "GPG KEY";
+ return "[" + id() + "] [" + name() + "] [" + fingerprint() + "]";
}
std::string armoredData() const
std::string fingerprint() const
{ return _fingerprint; }
+ Pathname path() const
+ {
+ return _data_file.path();
+ //return _data_file;
+ }
+
protected:
void readFromFile( const Pathname &keyfile)
{
- if ( !PathInfo(keyfile).isExist() )
+ PathInfo info(keyfile);
+ 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[] =
"--batch",
"--status-fd",
"1",
- keyfile.asString().c_str(),
+ _data_file.path().asString().c_str(),
NULL
};
prog.close();
if (_id.size() == 0 )
- ZYPP_THROW(Exception("Can't read public key from " + keyfile.asString()));
+ ZYPP_THROW(BadKeyException("File " + keyfile.asString() + " doesn't contain public key data" , keyfile));
}
private:
std::string _name;
std::string _fingerprint;
std::string _data;
+ filesystem::TmpFile _data_file;
+ //Pathname _data_file;
private:
friend Impl * rwcowClone<Impl>( const Impl * rhs );
/** clone for RWCOW_pointer */
: _pimpl( Impl::nullimpl() )
{}
- PublicKey::PublicKey( const Pathname &file )
+ PublicKey::PublicKey( const Pathname &file )
: _pimpl( new Impl(file) )
{}
///////////////////////////////////////////////////////////////////
std::string PublicKey::fingerprint() const
{ return _pimpl->fingerprint(); }
-
-// std::string PublicKey::text( const Locale &lang ) const
-// { return _pimpl->text( lang ); }
+
+ Pathname PublicKey::path() const
+ { return _pimpl->path(); }
/////////////////////////////////////////////////////////////////
} // namespace zypp
-///////////////////////////////////////////////////////////////////
-}
\ No newline at end of file
+///////////////////////////////////////////////////////////////////
\ No newline at end of file
#include <string>
#include "zypp/base/PtrTypes.h"
+#include "zypp/base/Exception.h"
#include "zypp/Pathname.h"
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
-namespace devel
-{
+
+
+ class BadKeyException : public Exception
+ {
+ public:
+ /** Ctor taking message.
+ * Use \ref ZYPP_THROW to throw exceptions.
+ */
+ BadKeyException()
+ : Exception( "Bad Key Exception" )
+ {}
+
+ Pathname keyFile() const
+ { return _keyfile; }
+
+ /** Ctor taking message.
+ * Use \ref ZYPP_THROW to throw exceptions.
+ */
+ BadKeyException( const std::string & msg_r, const Pathname &keyfile = Pathname() )
+ : Exception( msg_r ), _keyfile(keyfile)
+ {}
+ /** Dtor. */
+ virtual ~BadKeyException() throw() {};
+ private:
+ Pathname _keyfile;
+ };
+
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : PublicKey
* \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(); }
private:
/** Pointer to implementation */
/////////////////////////////////////////////////////////////////
} // namespace zypp
-}
///////////////////////////////////////////////////////////////////
#endif // ZYPP_PUBLICKEY_H
ZYPP_THROW(Exception("Unable to copy " + filename + " to " + (local_dir + "/DATA").asString()));
if ( filename == "content.key" )
- z->keyRing()->importKey(contentFileKey(), false);
+ z->keyRing()->importKey(local_dir + "DATA/content.key", false);
MIL << "cached " << filename << std::endl;
}
copy_result = filesystem::copy( remote_repomd_key, local_dir + "/repodata/repomd.xml.key");
if ( copy_result != 0 )
ZYPP_THROW(Exception("Can't copy " + remote_repomd_key.asString() + " to " + local_dir.asString() + "/repodata/repomd.xml.key"));
+
getZYpp()->keyRing()->importKey(local_dir + "/repodata/repomd.xml.key" , false);
}
#include "zypp/Date.h"
#include "zypp/Pathname.h"
#include "zypp/PathInfo.h"
+#include "zypp/PublicKey.h"
#include "zypp/target/rpm/RpmDb.h"
#include "zypp/target/rpm/RpmCallbacks.h"
disconnect();
}
- virtual void trustedKeyAdded( const KeyRing &keyring, const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+ virtual void trustedKeyAdded( const KeyRing &keyring, const PublicKey &key )
{
MIL << "trusted key added to zypp Keyring. Syncronizing keys with rpm keyring" << std::endl;
_rpmdb.importZyppKeyRingTrustedKeys();
_rpmdb.exportTrustedKeysInZyppKeyRing();
}
- virtual void trustedKeyRemoved( const KeyRing &keyring, const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+ virtual void trustedKeyRemoved( const KeyRing &keyring, const PublicKey &key )
{
}
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;
+ MIL << "Key " << (*it).id() << " (" << (*it).name() << ") is already in rpm database." << std::endl;
}
else
{
- // key does not exists, we need to import it into rpm
- // create a temporary file
- TmpFile file(getZYpp()->tmpPath());
- // open the file for writing
- std::ofstream os;
- try
- {
- os.open(file.path().asString().c_str());
- // dump zypp key into the tmp file
- getZYpp()->keyRing()->dumpTrustedPublicKey( (*it).id, os );
- os.close();
- }
- catch (std::exception &e)
- {
- ERR << "Could not dump key " << (*it).id << " (" << (*it).name << ") in tmp file " << file.path() << std::endl;
- // just ignore the key
- }
-
// now import the key in rpm
try
{
- importPubkey(file.path());
- MIL << "Trusted key " << (*it).id << " (" << (*it).name << ") imported in rpm database." << std::endl;
+ importPubkey((*it).path());
+ MIL << "Trusted key " << (*it).id() << " (" << (*it).name() << ") imported in rpm database." << std::endl;
}
catch (RpmException &e)
{
- ERR << "Could not dump key " << (*it).id << " (" << (*it).name << ") in tmp file " << file.path() << std::endl;
+ ERR << "Could not import key " << (*it).id() << " (" << (*it).name() << " from " << (*it).path() << " in rpm database" << std::endl;
}
}
}
//MIL << "-----------------------------------------------" << std::endl;
os.close();
// read the public key from the dumped file
- PublicKey key = getZYpp()->keyRing()->readPublicKey(file.path());
+ PublicKey key(file.path());
ret.push_back(key);
}
catch (std::exception &e)