Beispiel #1
0
int main(int argc, char **argv)
{
  QxtCommandOptions options;

  options.add(CL_HELP, "display this help message",
      QxtCommandOptions::NoValue);
  options.add(CL_NKEYS, "number of keys to generate",
      QxtCommandOptions::ValueRequired);
  options.add(CL_PUBDIR, "directory in which to put public keys (default=./keys/pub)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_PRIVDIR, "directory in which to put private keys (default=./keys/priv)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_KEYTYPE, "specify the key type (default=dsa, options=dsa|rsa)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_LIB, "specify the library (default=cryptopp, options=cryptopp)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_RAND, "specify the base properties for the key (default=NULL)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_DEBUG, "enable debugging",
      QxtCommandOptions::NoValue);

  options.parse(argc, argv);

  if(options.count(CL_HELP) || options.showUnrecognizedWarning()) {
    options.showUsage();
    return -1;
  }

  QMultiHash<QString, QVariant> params = options.parameters();

  int key_count = params.value(CL_NKEYS, 1).toInt();
  if(key_count < 1) {
    ExitWithWarning(options, "Invalid nkeys");
  }

  QString pubdir_path = params.value(CL_PUBDIR, DEFAULT_PUBDIR).toString();
  QDir pubdir(pubdir_path);
  if(!pubdir.exists()) {
    pubdir.mkpath(".");
  }

  if(!pubdir.exists()) {
    ExitWithWarning(options, "Unable to create pubdir");
  }

  QString privdir_path = params.value(CL_PRIVDIR, DEFAULT_PRIVDIR).toString();
  QDir privdir(privdir_path);
  if(!privdir.exists()) {
    privdir.mkpath(".");
  }

  if(!privdir.exists()) {
    ExitWithWarning(options, "Unable to create privdir");
  }

  if(params.contains(CL_DEBUG)) {
    Logging::UseStderr();
  }

  QString lib_name = params.value(CL_LIB, "cryptopp").toString();
  QString key = params.value(CL_KEYTYPE, "dsa").toString();

  CryptoFactory &cf = CryptoFactory::GetInstance();
  QSharedPointer<CreateKey> ck(new CreateKey());
  if(lib_name == "cryptopp") {
    if(key == "dsa") {
      cf.SetLibrary(CryptoFactory::CryptoPPDsa);
      if(params.contains(CL_RAND)) {
        ck = QSharedPointer<CreateKey>(
            new CreateSeededDsaKey(params.value(CL_RAND).toString()));
      }
    } else if (key == "rsa") {
      cf.SetLibrary(CryptoFactory::CryptoPP);
    } else {
      ExitWithWarning(options, "Invalid key type");
    }
  } else {
    ExitWithWarning(options, "Invalid library");
  }

  Library *lib = cf.GetLibrary();
  QSharedPointer<Hash> hash(lib->GetHashAlgorithm());

  int count = 0;
  while(count < key_count) {
    QSharedPointer<AsymmetricKey> key((*ck)());
    QSharedPointer<AsymmetricKey> pubkey(key->GetPublicKey());
    QByteArray hvalue = hash->ComputeHash(pubkey->GetByteArray());
    QString id = Integer(hvalue).ToString();

    if(!key->Save(privdir_path + QDir::separator() + id)) {
      qFatal("Could not save private key");
    }

    if(!pubkey->Save(pubdir_path + QDir::separator() + id + ".pub")) {
      qFatal("Could not save private key");
    }

    count++;
  }

  return 0;
}
Beispiel #2
0
RosterBox::RosterBox( QWidget* parent, const char* name )
	: QListView( parent, name ), QToolTip( viewport() )
{
	QSettings settings;
	settings.setPath( "qtlen.sf.net", "QTlen" );
	
	settings.beginGroup( "/look" );
	
	header()->hide();
	
	setResizeMode( QListView::AllColumns );
	addColumn( QString::null );
	setTreeStepSize( 5 );
	
	setPaletteBackgroundColor( (QColor)settings.readEntry( "/roster/background", "#eeeeee" ) );
	setPaletteForegroundColor( (QColor)settings.readEntry( "/roster/foreground", "#000000" ) );
	
	setSorting( -1 );
	
	connect( roster_manager, SIGNAL( refreshContext() ),
			this, SLOT( refreshContext() ) );
	
	connect( this, SIGNAL( clicked( QListViewItem * ) ),
			SLOT( clicked( QListViewItem * ) ) );
	connect( this, SIGNAL( doubleClicked( QListViewItem *, const QPoint &, int ) ),
			SLOT( doubleClicked( QListViewItem *, const QPoint &, int ) ) );
	connect( this, SIGNAL( contextMenuRequested( QListViewItem *, const QPoint &, int ) ),
			SLOT( contextMenuRequested( QListViewItem *, const QPoint &, int ) ) );
	
	connect( this, SIGNAL( itemRenamed(QListViewItem *, int, const QString &) ),
			SLOT( itemRenamed(QListViewItem *, int, const QString &) ) );
	
	menu = new QPopupMenu( this );
	menu->insertItem( QIconSet( takePixmap( "msg" ) ), tr( "New &message" ),  this, SLOT( newMessage() ), CTRL+Key_M );
	menu->insertItem( QIconSet( takePixmap( "msg-chat" ) ), tr( "New &chat" ),  this, SLOT( newChatMessage() ), CTRL+Key_C );
	menu->insertSeparator();
	menu->insertItem( QIconSet( takePixmap( "edit" ) ), tr( "Edit contact" ),  this, SLOT( edit() ) );
	menu->insertItem( QIconSet( takePixmap( "find" ) ), tr( "Check in pubdir" ),  this, SLOT( pubdir() ) );
	menu->insertSeparator();
	menu->insertItem( QIconSet( takePixmap( "rename" ) ), tr( "Rename contect" ),  this, SLOT( rename() ) );
	menu->insertItem( QIconSet( takePixmap( "delete" ) ), tr( "Remove contect" ),  this, SLOT( remove() ) );
	
	settings.endGroup();
	
	settings.beginGroup( "/roster" );
	
	setShowOffline( settings.readBoolEntry( "/showOffline", true ) );
	setShowAway( settings.readBoolEntry( "/showAway", true ) );
	
	settings.endGroup();
}