Beispiel #1
0
static void
skey_challenge_response_cb (GtkWidget *dialog,
                            int response_id,
                            SkeyData *data)
{  
  if (response_id == GTK_RESPONSE_OK)
    {
      GtkWidget *entry;
      const char *password;
      char *response;

      entry = g_object_get_data (G_OBJECT (dialog), "skey-entry");
      password = gtk_entry_get_text (GTK_ENTRY (entry));

      /* FIXME: fix skey to use g_malloc */
      response = skey (data->hash, data->seq, data->seed, password);
      if (response)
	{
          VteTerminal *vte_terminal = VTE_TERMINAL (data->screen);
          static const char newline[2] = "\n";

	  vte_terminal_feed_child (vte_terminal, response, strlen (response));
          vte_terminal_feed_child (vte_terminal, newline, strlen (newline));
	  free (response);
	}
    }

  gtk_widget_destroy (dialog);
}
Beispiel #2
0
  QByteArray CppRsaPublicKeyImpl::Encrypt(const QByteArray &data) const
  {
    if(!IsValid()) {
      return QByteArray();
    }

    RSAES<OAEP<SHA> >::Encryptor encryptor(*m_public_key);
    int clength = ((data.size() / AES::BLOCKSIZE) + 1) * AES::BLOCKSIZE;
    int data_start = encryptor.FixedCiphertextLength() + AES::BLOCKSIZE;
    QByteArray ciphertext(data_start + clength, 0);

    CryptoRandom rand;
    QByteArray skey(AES::BLOCKSIZE, 0);
    rand.GenerateBlock(skey);

    QByteArray iv(AES::BLOCKSIZE, 0);
    rand.GenerateBlock(iv);
    ciphertext.replace(encryptor.FixedCiphertextLength(), iv.size(), iv);

    CBC_Mode<AES>::Encryption enc;
    enc.SetKeyWithIV(reinterpret_cast<byte *>(skey.data()), skey.size(),
        reinterpret_cast<byte *>(iv.data()));

    StringSource(reinterpret_cast<const byte *>(data.data()), data.size(), true,
        new StreamTransformationFilter(enc,
          new ArraySink(reinterpret_cast<byte *>(ciphertext.data() + data_start), clength)));

    encryptor.Encrypt(GetCppRandom(rand),
        reinterpret_cast<const byte *>(skey.data()),
        skey.size(), reinterpret_cast<byte *>(ciphertext.data()));

    return ciphertext;
  }
Beispiel #3
0
void IniSetting::ParserCallback::onPopEntry(
    const std::string &key,
    const std::string &value,
    const std::string &offset,
    void *arg) {
  Variant *arr = (Variant*)arg;
  forceToArray(*arr);

  bool oEmpty = offset.empty();
  // Substitution copy or symlink
  // Offset come in like: hhvm.a.b\0c\0@
  // Check for `\0` because it is possible, although unlikely, to have
  // something like hhvm.a.b[c@]. Thus we wouldn't want to make a substitution.
  if (!oEmpty && (offset.size() == 1 || offset[offset.size() - 2] == '\0') &&
      (offset.back() == '@' || offset.back() == ':')) {
    makeSettingSub(key, offset, value, *arr);
  } else {                                 // Normal array value
    String skey(key);
    auto& hash = arr->toArrRef().lvalAt(skey);
    forceToArray(hash);
    if (!oEmpty) {                         // a[b]
      makeArray(hash, offset, value);
    } else {                               // a[]
      hash.toArrRef().append(value);
    }
  }
}
logical pc_ADKC_Bitmap_ :: DefineFromList (srt *srtptr, char *sysvar, char *filext )
{
  char              *name;
  char              *pkt;
  char               string[1000];
  int32              indx0 = 0;
  logical            term  = NO;
  while ( name = (char *)srtptr->srtigt(++indx0) )
  {
    if ( pkt = strchr(name,'.') )
      *pkt = 0;
    PropertyHandle  skey(strcat(strcat(strcpy(string,sysvar),"_"),name));
    if ( pkt )
      *pkt = '.';
      
    if ( !Get(skey) )
    {
      Add(skey);
      *GPH("inaktiv_bitmap.path") = strcat(strcat(strcat(strcpy(string,"%"),sysvar),"%"),name);
    }

  }

  return(term);
}
Beispiel #5
0
common::Error LmdbRaw::keys(const std::string &key_start, const std::string &key_end, uint64_t limit,
                   std::vector<std::string> *ret) {
  MDB_cursor *cursor;
  MDB_txn *txn = NULL;
  int rc = mdb_txn_begin(lmdb_->env, NULL, MDB_RDONLY, &txn);
  if (rc == LMDB_OK) {
    rc = mdb_cursor_open(txn, lmdb_->dbir, &cursor);
  }

  if (rc != LMDB_OK) {
    mdb_txn_abort(txn);
    char buff[1024] = {0};
    common::SNPrintf(buff, sizeof(buff), "Keys function error: %s", mdb_strerror(rc));
    return common::make_error_value(buff, common::ErrorValue::E_ERROR);
  }

  MDB_val key;
  MDB_val data;
  while ((mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == LMDB_OK) && limit > ret->size()) {
    std::string skey((const char*)key.mv_data, key.mv_size);
    if (key_start < skey && key_end > skey) {
      ret->push_back(skey);
    }
  }
  mdb_cursor_close(cursor);
  mdb_txn_abort(txn);

  return common::Error();
}
Beispiel #6
0
void IniSetting::ParserCallback::onEntry(
    const std::string &key, const std::string &value, void *arg) {
  Variant *arr = (Variant*)arg;
  String skey(key);
  Variant sval(value);
  forceToArray(*arr).set(skey, sval);
}
Beispiel #7
0
static void
skey_test (gconstpointer data)
{
	const TestEntry *test = (const TestEntry *) data;
	char *key;

	key = skey (test->algorithm,
	            test->count,
	            test->seed,
	            test->passphrase);
	g_assert (key != NULL);
	g_assert (strcmp (key, test->btoe) == 0);
	free (key);
}
        void rrdb_service_impl::on_get(const ::dsn::blob& key, ::dsn::service::rpc_replier<read_response>& reply)
        {
            read_response resp;

            if (_is_open)
            {
                rocksdb::Slice skey(key.data(), key.length());
                rocksdb::Status status = _db->Get(_rd_opts, skey, &resp.value);
                resp.error = status.code();
            }
            else
            {
                resp.error = ERR_SERVICE_NOT_ACTIVE;
            }
            reply(resp);
        }
        void rrdb_service_impl::on_remove(const ::dsn::blob& key, ::dsn::service::rpc_replier<int>& reply)
        {
            if (_is_open)
            {
                rocksdb::WriteOptions opts = _wt_opts;
                opts.given_sequence_number = static_cast<rocksdb::SequenceNumber>(_last_committed_decree + 1);

                rocksdb::Slice skey(key.data(), key.length());
                rocksdb::Status status = _db->Delete(opts, skey);
                reply(status.code());
            }
            else
            {
                reply(ERR_SERVICE_NOT_ACTIVE);
            }
        }
        void rrdb_service_impl::on_merge(const update_request& update, ::dsn::service::rpc_replier<int>& reply)
        {
            if (_is_open)
            {
                rocksdb::WriteOptions opts = _wt_opts;
                opts.given_sequence_number = static_cast<rocksdb::SequenceNumber>(_last_committed_decree + 1);

                rocksdb::Slice skey(update.key.data(), update.key.length());
                rocksdb::Slice svalue(update.value.data(), update.value.length());
                rocksdb::Status status = _db->Merge(opts, skey, svalue);
                reply(status.code());
            }
            else
            {
                reply(ERR_SERVICE_NOT_ACTIVE);
            }
        }
Beispiel #11
0
  QVariant LRSAuthenticate::PrepareForChallenge()
  {
    Library *lib = CryptoFactory::GetInstance().GetLibrary();
    QSharedPointer<AsymmetricKey> skey(lib->CreatePrivateKey());
    QSharedPointer<AsymmetricKey> dkey(lib->CreatePrivateKey());
    QSharedPointer<DiffieHellman> dh(lib->CreateDiffieHellman());
    _ident = PrivateIdentity(_ori_ident.GetLocalId(), skey, dkey, dh,
        _ori_ident.GetSuperPeer());
    _pub_ident = GetPublicIdentity(_ident);

    QByteArray bident;
    QDataStream stream(&bident, QIODevice::WriteOnly);
    stream << _pub_ident;

    QVariantList list;
    list.append(bident);
    list.append(_lrs->Sign(bident));
    return list;
  }
Beispiel #12
0
	//not modify
	bool PrivateKey::From(const std::string &encode_private_key) {
		valid_ = false;
		std::string tmp;

		do {
			PrivateKeyPrefix prefix;
			std::string raw_pubkey;
			valid_ = GetKeyElement(encode_private_key, prefix, type_, raw_priv_key_);
			if (!valid_) {
				return false;
			}

			if (prefix != PRIVATEKEY_PREFIX) {
				valid_ = false;
				return false;
			}

			if (type_ == SIGNTYPE_ED25519) {
				tmp.resize(32);
				ed25519_publickey((const unsigned char*)raw_priv_key_.c_str(), (unsigned char*)tmp.c_str());
			}
			else if (type_ == SIGNTYPE_CFCASM2) {
				utils::EccSm2 skey(utils::EccSm2::GetCFCAGroup());
				skey.From(raw_priv_key_);
				tmp = skey.GetPublicKey();
			}
			else{
				LOG_ERROR("Unknown signature type(%d)", type_);
			}
			//ToBase58();
			pub_key_.type_ = type_;
			pub_key_.Init(tmp);
			pub_key_.valid_ = true;
			valid_ = true;

		} while (false);
		return valid_;
	}
Beispiel #13
0
void SimTK_about_SimTKcommon(const char* key, int maxlen, char* value) {
    if (maxlen <= 0 || value==0) return;
    value[0] = '\0'; // in case we don't find a match
    if (key==0) return;

    // downshift the key
    std::string skey(key);
    for (int i=0; i<(int)skey.size(); ++i)
        skey[i] = (char)std::tolower((unsigned char)skey[i]);

    const char* v = 0;
    if      (skey == "version")   v = GET_VERSION_STRING;
    else if (skey == "library")   v = GET_LIBRARY_STRING;
    else if (skey == "type")      v = GET_TYPE_STRING;
    else if (skey == "copyright") v = GET_COPYRIGHT_STRING;
    else if (skey == "authors")   v = GET_AUTHORS_STRING;
    else if (skey == "debug")     v = GET_DEBUG_STRING;

    if (v) {
        std::strncpy(value,v,maxlen-1);
        value[maxlen-1] = '\0'; // in case we ran out of room
    }
}
Beispiel #14
0
ConfigUtil::ConfigUtil(const char *path)
{
	int i;
	for (i = 0; i < sizeof(DEFAULT_SETTING) / sizeof(DEFAULT_SETTING[0]); i++)
	{
        string key(DEFAULT_SETTING[i].key);
        string val(DEFAULT_SETTING[i].val);
        items.insert(pair<string, string>(key, val));
	}
	
	ifstream ifs(path);
	if (ifs.good())
	{
		char line[1024];
		char key[1024];
		char val[1024];
		while (!ifs.eof())
		{
			ifs.getline(line, sizeof(line));
			if (line[0] == '[')
			{
				continue;
			}
			for (i = 0; line[i]; i++)
			{
				if (line[i] == ';' || line[i] == '#')
				{
					line[i] = 0;
					break;
				}
			}
			for (i--; i >= 0; i--)
			{
				if (line[i] == ' ' || line[i] == '\t')
				{
					line[i] = 0;
				}
				else
				{
					break;
				}
			}
			if (!line[0])
			{
				continue;
			}

			string sline(line);
			istringstream issline(sline);
			
			issline.getline(key, sizeof(key), ':');
			string skey(key);
			if (skey.length() == 0)
			{
				continue;
			}
			
			issline.getline(val, sizeof(val), ':');
			string sval(val);
			if (sval.length() == 0)
			{
				//continue;
			}
			
			items.erase(skey);
			items.insert(pair<string, string>(skey, sval));
		}
	}
	ifs.close();
}
static const std::string valid_key_to_string(KEY key)
{
	std::string skey(1,(char)key);
	std::string strkey = LLKeyboard::stringFromKey(key);
	return ((skey == strkey && key >= ' ' && key <= '~') || (skey != strkey) ) ? strkey : "";
}
Beispiel #16
0
static int _buildHeader(const char* infile, FPTREE * fpt, HashTable * item_dict, char sep){
    FILE * fp = NULL;
    if ((fp = fopen(infile,"r")) == NULL){
        fprintf(stderr,"open input file failed\n");
        return -1;
    }
    char buffer[LINE_LEN];
    char ** str_array = NULL;
    int count = 0, item_count = 0;
    int line = 0;
    HashTable * tmp_dict = create_hashtable(5000000,char*,int);
    while (NULL != fgets(buffer,LINE_LEN,fp)){
        str_array = split(trim(buffer,3), sep ,&count);
        if (count < 3){
            goto str_free;
        }
        int t_count = atoi(str_array[count-1]);
        for (int i = 0; i< count - 1; i++){
            if (strlen(str_array[i]) < 6)
                continue;
            if (NOTEXISTS == hash_exists(tmp_dict,str_array[i])){
                hash_add(tmp_dict,str_array[i],t_count);
            }
            else{
                hash_find(tmp_dict,str_array[i],&item_count);
                item_count += t_count;
                hash_add(tmp_dict,str_array[i],item_count);
            }
        }
str_free:
        free(str_array[0]);
        free(str_array);
        if (++line % 1000000 == 0){
            fprintf(stderr,"load lines %d\n", line);
        }
    }
    fclose(fp);

    fprintf(stderr,"totle words %d\n", hash_num_elements(tmp_dict));

    for (reset(tmp_dict); isnotend(tmp_dict); next(tmp_dict)){
        char * key = skey(tmp_dict);
        int  item_sup = *((int*)value(tmp_dict));
        if (item_sup >= fpt->minsup){
            hash_add(item_dict,key,item_sup);
        }
    }


    hash_free(tmp_dict); tmp_dict = NULL;

    int item_size = 0;
    fpt->headsize = item_size = hash_num_elements(item_dict);
    fpt->header = (FPTLIST *)malloc(sizeof(FPTLIST) * item_size);
    ItemCount * ic = (ItemCount*)malloc(sizeof(ItemCount) * item_size);

    int i = 0;
    for (reset(item_dict); isnotend(item_dict); next(item_dict)){
        char * key = skey(item_dict);
        int item_sup = *((int*)value(item_dict));
        strncpy(ic[i].key,key,KEY_SIZE-1); ic[i].key[KEY_SIZE-1] = '\0';
        ic[i].count = item_sup;
        i += 1;
    }
    reset(item_dict);

    qsort(ic,item_size,sizeof(ItemCount),itemcompare);

    for (int i = 0; i< item_size; i++){
        strncpy(fpt->header[i].itemname,ic[i].key,KEY_SIZE-1);
        fpt->header[i].itemname[KEY_SIZE-1] = '\0';
        fpt->header[i].supp = ic[i].count;
        fpt->header[i].itemlink = 0;
        hash_add(item_dict,ic[i].key,i);
    }
    free(ic);ic = NULL;

    return 0;
}