Esempio n. 1
0
	void Plugin::initPlugin (QObject *obj)
	{
		AzothProxy_ = qobject_cast<IProxyObject*> (obj);

		OtrHandler_ = new OtrHandler (CoreProxy_, AzothProxy_);

		FPManager_ = new FPManager (OtrHandler_->GetUserState (), AzothProxy_);
		connect (FPManager_,
				SIGNAL (fingerprintsChanged ()),
				OtrHandler_,
				SLOT (writeFingerprints ()));
		XSD_->SetDataSource ("KnownFPs", FPManager_->GetModel ());

		PKManager_ = new PrivKeyManager (OtrHandler_->GetUserState (), AzothProxy_);
		connect (PKManager_,
				SIGNAL (keysChanged ()),
				OtrHandler_,
				SLOT (writeKeys ()));
		connect (PKManager_,
				SIGNAL (keysGenerationRequested (QString, QString)),
				OtrHandler_,
				SLOT (generateKeys (QString, QString)));
		connect (OtrHandler_,
				SIGNAL (privKeysChanged ()),
				PKManager_,
				SLOT (reloadAll ()));
		XSD_->SetDataSource ("PrivKeys", PKManager_->GetModel ());
	}
Esempio n. 2
0
// Textures anim bin export
bool exportTexturesAnimBin(const char * filename, MTexturesAnim * anim)
{
	int version = 1;
	
	
	// create file
	MFile * file = M_fopen(filename, "wb");
	if(! file)
	{
		printf("Error : can't create file %s\n", filename);
		return false;
	}
	
	
	// header
	M_fwrite(M_TA_HEADER, sizeof(char), 8, file);
	
	// version
	M_fwrite(&version, sizeof(int), 1, file);
	
	
	// textures
	unsigned int t, texturesAnimNumber = anim->getTexturesAnimNumber();
	MTextureAnim * texturesAnim = anim->getTexturesAnim();
	
	M_fwrite(&texturesAnimNumber, sizeof(int), 1, file);
	for(t=0; t<texturesAnimNumber; t++)
	{
		MTextureAnim * texAnim = &(texturesAnim[t]);
		
		unsigned int translateKeysNumber = texAnim->getTranslateKeysNumber();
		unsigned int scaleKeysNumber = texAnim->getScaleKeysNumber();
		unsigned int rotationKeysNumber = texAnim->getRotationKeysNumber();
		
		MKey * translateKeys = texAnim->getTranslateKeys();
		MKey * scaleKeys = texAnim->getScaleKeys();
		MKey * rotationKeys = texAnim->getRotationKeys();
		
		writeKeys(file, translateKeys, M_VARIABLE_VEC2, translateKeysNumber);
		writeKeys(file, scaleKeys, M_VARIABLE_VEC2, scaleKeysNumber);
		writeKeys(file, rotationKeys, M_VARIABLE_FLOAT, rotationKeysNumber);
	}
	
	
	M_fclose(file);
	return true;	
}
Esempio n. 3
0
// Armature anim bin export
bool exportArmatureAnimBin(const char * filename, MArmatureAnim * anim)
{
	int version = 1;
	
	
	// create file
	MFile * file = M_fopen(filename, "wb");
	if(! file)
	{
		printf("Error : can't create file %s\n", filename);
		return false;
	}
	
	
	// header
	M_fwrite(M_AA_HEADER, sizeof(char), 8, file);
	
	// version
	M_fwrite(&version, sizeof(int), 1, file);
	
	
	// bones
	unsigned int b, bonesAnimNumber = anim->getBonesAnimNumber();
	MObject3dAnim * bonesAnim = anim->getBonesAnim();
	
	M_fwrite(&bonesAnimNumber, sizeof(int), 1, file);
	for(b=0; b<bonesAnimNumber; b++)
	{
		MObject3dAnim * objAnim = &(bonesAnim[b]);
	
		unsigned int positionKeysNumber = objAnim->getPositionKeysNumber();
		unsigned int scaleKeysNumber = objAnim->getScaleKeysNumber();
		unsigned int rotationKeysNumber = objAnim->getRotationKeysNumber();
		
		MKey * positionKeys = objAnim->getPositionKeys();
		MKey * scaleKeys = objAnim->getScaleKeys();
		MKey * rotationKeys = objAnim->getRotationKeys();
	
		writeKeys(file, positionKeys, M_VARIABLE_VEC3, positionKeysNumber);
		writeKeys(file, scaleKeys, M_VARIABLE_VEC3, scaleKeysNumber);
		writeKeys(file, rotationKeys, M_VARIABLE_QUAT, rotationKeysNumber);
	}
	
	
	M_fclose(file);
	return true;
}
Esempio n. 4
0
// Materials anim bin export
bool exportMaterialsAnimBin(const char * filename, MMaterialsAnim * anim)
{
	int version = 1;
	
	
	// create file
	MFile * file = M_fopen(filename, "wb");
	if(! file)
	{
		printf("Error : can't create file %s\n", filename);
		return false;
	}
	
	
	// header
	M_fwrite(M_MA_HEADER, sizeof(char), 8, file);
	
	// version
	M_fwrite(&version, sizeof(int), 1, file);
	
	
	// materials
	unsigned int m, materialsAnimNumber = anim->getMaterialsAnimNumber();
	MMaterialAnim * materialsAnim = anim->getMaterialsAnim();
	
	M_fwrite(&materialsAnimNumber, sizeof(int), 1, file);
	for(m=0; m<materialsAnimNumber; m++)
	{
		MMaterialAnim * matAnim = &(materialsAnim[m]);
		
		unsigned int opacityKeysNumber = matAnim->getOpacityKeysNumber();
		unsigned int shininessKeysNumber = matAnim->getShininessKeysNumber();
		unsigned int customValueKeysNumber = matAnim->getCustomValueKeysNumber();
		unsigned int diffuseKeysNumber = matAnim->getDiffuseKeysNumber();
		unsigned int specularKeysNumber = matAnim->getSpecularKeysNumber();
		unsigned int emitKeysNumber = matAnim->getEmitKeysNumber();
		unsigned int customColorKeysNumber = matAnim->getCustomColorKeysNumber();
		
		MKey * opacityKeys = matAnim->getOpacityKeys();
		MKey * shininessKeys = matAnim->getShininessKeys();
		MKey * customValueKeys = matAnim->getCustomValueKeys();
		MKey * diffuseKeys = matAnim->getDiffuseKeys();
		MKey * specularKeys = matAnim->getSpecularKeys();
		MKey * emitKeys = matAnim->getEmitKeys();
		MKey * customColorKeys = matAnim->getCustomColorKeys();
		
		writeKeys(file, opacityKeys, M_VARIABLE_FLOAT, opacityKeysNumber);
		writeKeys(file, shininessKeys, M_VARIABLE_FLOAT, shininessKeysNumber);
		writeKeys(file, customValueKeys, M_VARIABLE_FLOAT, customValueKeysNumber);
		writeKeys(file, diffuseKeys, M_VARIABLE_VEC3, diffuseKeysNumber);
		writeKeys(file, specularKeys, M_VARIABLE_VEC3, specularKeysNumber);
		writeKeys(file, emitKeys, M_VARIABLE_VEC3, emitKeysNumber);
		writeKeys(file, customColorKeys, M_VARIABLE_VEC3, customColorKeysNumber);
	}
	
	
	M_fclose(file);
	return true;	
}
Esempio n. 5
0
QPair<QByteArray*, QByteArray*> generateECKeypair() {

    EC_KEY* keyPair = EC_KEY_new_by_curve_name(NID_secp256k1);
    QPair<QByteArray*, QByteArray*> retval{};

    EC_KEY_set_asn1_flag(keyPair, OPENSSL_EC_NAMED_CURVE);
    if (!EC_KEY_generate_key(keyPair)) {
        qCDebug(commerce) << "Error generating EC Keypair -" << ERR_get_error();
        return retval;
    }

    // grab the public key and private key from the file
    unsigned char* publicKeyDER = NULL;
    int publicKeyLength = i2d_EC_PUBKEY(keyPair, &publicKeyDER);

    unsigned char* privateKeyDER = NULL;
    int privateKeyLength = i2d_ECPrivateKey(keyPair, &privateKeyDER);

    if (publicKeyLength <= 0 || privateKeyLength <= 0) {
        qCDebug(commerce) << "Error getting DER public or private key from EC struct -" << ERR_get_error();


        // cleanup the EC struct
        EC_KEY_free(keyPair);

        // cleanup the public and private key DER data, if required
        if (publicKeyLength > 0) {
            OPENSSL_free(publicKeyDER);
        }

        if (privateKeyLength > 0) {
            OPENSSL_free(privateKeyDER);
        }

        return retval;
    }


    if (!writeKeys(keyFilePath().toStdString().c_str(), keyPair)) {
        qCDebug(commerce) << "couldn't save keys!";
        return retval;
    }

    EC_KEY_free(keyPair);

    // prepare the return values.  TODO: Fix this - we probably don't really even want the
    // private key at all (better to read it when we need it?).  Or maybe we do, when we have
    // multiple keys?
    retval.first = new QByteArray(reinterpret_cast<char*>(publicKeyDER), publicKeyLength);
    retval.second = new QByteArray(reinterpret_cast<char*>(privateKeyDER), privateKeyLength);

    // cleanup the publicKeyDER and publicKeyDER data
    OPENSSL_free(publicKeyDER);
    OPENSSL_free(privateKeyDER);
    return retval;
}
void writeTrace(const char* traceFileName)
{
    FILE *fp = fopen(traceFileName, "w");
    if (fp == NULL) {
        perror(traceFileName);
        exit(1);
    }
    writeKeys(fp);
    writeDataHeader(fp);
    writeDataRecords(fp);
    fclose(fp);
}
Esempio n. 7
0
void genKey(){
	
	int p,q,i,j;
	long long n,tot,d,e;
	
	seedRandom();
	
	do{
		//value larger = slower, by ALOT, cause of multiplication
		p = prime(randomInt(KEYMIN,KEYMAX));
		q = prime(randomInt(KEYMIN,KEYMAX));
		printf("%lld\t%lld\n",p,q);
	}while(isPrime(p)!=0 && isPrime(q)!=0);
	
	printf("---------------\n");
	
	n = p*q;
	tot = (p-1)*(q-1);

	
	for(j=0; j <10; j++){
		i++;
		d = tot*i+1;
		e = d;
		
		int div=2;
		
		do{
			(e%div==0)? e /= div : div++;
			
		}while(isPrime(e)==1);
		
		if((e == d)) j--;
	}
	
	printf("\np: %lld\nq: %lld\nn: %lld\ntot: %lld\n",p,q,n,tot);
	
	Keys key;
	key.n = n;
	key.d=d/e;
	key.e=e;
	
	printf("\nn: %lld\nd: %lld\ne: %lld\n\n",key.n,key.d,key.e);

	writeKeys(key);
	Keys empty = {0};
	key = empty;
	menu();
	
}
Esempio n. 8
0
bool Wallet::writeWallet(const QString& newPassphrase) {
    EC_KEY* keys = readKeys(keyFilePath());
    auto ledger = DependencyManager::get<Ledger>();
    // Remove any existing locker, because it will be out of date.
    if (!_publicKeys.isEmpty() && !ledger->receiveAt(_publicKeys.first(), _publicKeys.first(), QByteArray())) {
        return false;  // FIXME: receiveAt could fail asynchronously.
    }
    if (keys) {
        // we read successfully, so now write to a new temp file
        QString tempFileName = QString("%1.%2").arg(keyFilePath(), QString("temp"));
        QString oldPassphrase = *_passphrase;
        if (!newPassphrase.isEmpty()) {
            setPassphrase(newPassphrase);
        }

        if (writeKeys(tempFileName, keys)) {
            if (writeSecurityImage(_securityImage, tempFileName)) {
                // ok, now move the temp file to the correct spot
                QFile(QString(keyFilePath())).remove();
                QFile(tempFileName).rename(QString(keyFilePath()));
                qCDebug(commerce) << "wallet written successfully";
                emit keyFilePathIfExistsResult(getKeyFilePath());
                if (!walletIsAuthenticatedWithPassphrase() || !ledger->receiveAt()) {
                    // FIXME: Should we fail the whole operation?
                    // Tricky, because we'll need the the key and file from the TEMP location...
                    qCWarning(commerce) << "Failed to update locker";
                }
                return true;
            } else {
                qCDebug(commerce) << "couldn't write security image to temp wallet";
            }
        } else {
            qCDebug(commerce) << "couldn't write keys to temp wallet";
        }
        // if we are here, we failed, so cleanup
        QFile(tempFileName).remove();
        if (!newPassphrase.isEmpty()) {
            setPassphrase(oldPassphrase);
        }

    } else {
        qCDebug(commerce) << "couldn't read wallet - bad passphrase?";
        // TODO: review this, but it seems best to reset the passphrase
        // since we couldn't decrypt the existing wallet (or is doesn't
        // exist perhaps).
        setPassphrase("");
    }
    return false;
}
Esempio n. 9
0
static void readfile(char *filename) {
  char buf[1024];
  FILE *fp = fopen(filename,"r");
  while (fgets(buf, sizeof(buf), fp) != NULL) {
    char *p;
    if((p = strtok(buf,"\"")) && strncmp(p,"#include",8) == 0) {
      p = strtok(NULL,"\"");
      char filename[512];
      sprintf(filename,"../%s",p);
      readfile(filename);
    } else if((p = strtok(buf," ")) && strncmp(p,"host",4) == 0) {
      char *p;
      p = strtok(NULL," ");
      p = strtok(p,"{");
      writeKeys(p);

    }
  }
  return;
}
Esempio n. 10
0
bool Wallet::writeWallet(const QString& newPassphrase) {
    EC_KEY* keys = readKeys(keyFilePath().toStdString().c_str());
    if (keys) {
        // we read successfully, so now write to a new temp file
        QString tempFileName = QString("%1.%2").arg(keyFilePath(), QString("temp"));
        QString oldPassphrase = *_passphrase;
        if (!newPassphrase.isEmpty()) {
            setPassphrase(newPassphrase);
        }
        if (writeKeys(tempFileName.toStdString().c_str(), keys)) {
            if (writeSecurityImage(_securityImage, tempFileName)) {
                // ok, now move the temp file to the correct spot
                QFile(QString(keyFilePath())).remove();
                QFile(tempFileName).rename(QString(keyFilePath()));
                qCDebug(commerce) << "wallet written successfully";
                emit keyFilePathIfExistsResult(getKeyFilePath());
                return true;
            } else {
                qCDebug(commerce) << "couldn't write security image to temp wallet";
            }
        } else {
            qCDebug(commerce) << "couldn't write keys to temp wallet";
        }
        // if we are here, we failed, so cleanup
        QFile(tempFileName).remove();
        if (!newPassphrase.isEmpty()) {
            setPassphrase(oldPassphrase);
        }

    } else {
        qCDebug(commerce) << "couldn't read wallet - bad passphrase?";
        // TODO: review this, but it seems best to reset the passphrase
        // since we couldn't decrypt the existing wallet (or is doesn't
        // exist perhaps).
        setPassphrase("");
    }
    return false;
}
Esempio n. 11
0
/**
   Write the content of the dictionary to the named file.  The existing
   content in the named file is overwritten.  The content of the dictionary
   file is laid out as follows.

   \li Signature "#IBIS Dictionary " and version number (currently
   0x020000). (20 bytes)

   \li N = Number of strings in the file. (4 bytes)

   \li uint64_t[N+1]: the starting positions of the strings in this file.

   \li uint32_t[N]: The integer code corresponding to each string value.

   \li the string values packed one after the other with their nil
   terminators.
*/
int ibis::dictionary::write(const char* name) const {
    std::string evt = "dictionary::write";
    if (name == 0 || *name == 0) {
        LOGGER(ibis::gVerbose > 1)
            << "Warning -- " << evt << " can not proceed with a "
            "null string as the file name";
        return -1;
    }
    if (ibis::gVerbose > 1) {
        evt += '(';
        evt += name;
        evt += ')';
    }
    if (key_.size() > raw_.size()) {
        LOGGER(ibis::gVerbose > 1)
            << "Warning -- " << evt
            << " can not write an inconsistent dictionary, key_.size("
            << key_.size() << "), raw_.size(" << raw_.size() << ")";
        return -2;
    }

    ibis::util::timer mytimer(evt.c_str(), 4);
    FILE* fptr = fopen(name, "wb");
    if (fptr == 0) {
        LOGGER(ibis::gVerbose > 1)
            << "Warning -- " << evt << " failed to open the file ... "
            << (errno ? strerror(errno) : "no free stdio stream");
        return -3;
    }

    IBIS_BLOCK_GUARD(fclose, fptr);
    int ierr = fwrite(_fastbit_dictionary_header, 1, 20, fptr);
    if (ierr != 20) {
        LOGGER(ibis::gVerbose > 1)
            << "Warning -- " << evt
            << " failed to write the header, fwrite returned " << ierr;
        return -4;
    }

    const uint32_t nkeys = key_.size();
    ierr = fwrite(&nkeys, sizeof(nkeys), 1, fptr);
    if (ierr != 1) {
        LOGGER(ibis::gVerbose > 1)
            << "Warning -- " << evt << " failed to write the size(" << nkeys
            << "), fwrite returned " << ierr;
        return -5;
    }
    if (nkeys == 0) // nothing else to write
        return 0;

    mergeBuffers();
    array_t<uint64_t> pos(nkeys+1);
    array_t<uint32_t> qos(nkeys);

    pos.clear();
    qos.clear();
    pos.push_back(0);
    if (buffer_.size() == 1) {
        for (uint32_t j = 0; j < raw_.size(); ++ j) {
            if (raw_[j] != 0) {
                pos.push_back(1U + strlen(raw_[j]));
                qos.push_back(j);
            }
        }
        ierr = writeBuffer(fptr, nkeys, pos, qos);
    }
    else {
        ierr = writeKeys(fptr, nkeys, pos, qos);
    }
    LOGGER(ibis::gVerbose > 1)
        << evt << " complete with ierr = " << ierr;
    return ierr;
} // ibis::dictionary::write