int BnetSRP3::init( const char* username_, const char* password_, const byte * salt_ ) { if(!srp3_inited) { gmp_randinit_default(rand); gmp_randseed_ui(rand, (unsigned long)time(NULL)); mpz_init2(N, 256); mpz_import(N, 32, -1, 1, 0, 0, SRP3_N); mpz_init_set_ui(g, SRP3_g); srp3_inited = true; } uint i; const char* source; if (!username_) { return -1; } uint len = strlen(username_); username.resize(len); source = username_; for(i = 0; i < len; ++ i) { username[i] = toupper(*(source++)); } if (!((password_ == NULL) ^ (salt_ == NULL))) { return -1; } if (password_!=NULL) { len = strlen(password_); password.resize(len); source = password_; for(i = 0; i < len; ++ i) { password[i] = toupper(*(source++)); } mpz_init2(a, 256); mpz_init(b); mpz_urandomm(a, rand, N); /* generates the private key */ mpz_t s; mpz_init2(s, 256); mpz_urandomb(s, rand, 256); mpz_export(raw_salt, NULL, 1, 4, -1, 0, s); } else { password = ""; mpz_init(a); mpz_init2(b, 256); mpz_urandomm(b, rand, N); setSalt(salt_); } B_inited = false; return 0; }
void Ledger::accountSuccess(QNetworkReply& reply) { // lets set the appropriate stuff in the wallet now auto wallet = DependencyManager::get<Wallet>(); QByteArray response = reply.readAll(); QJsonObject data = QJsonDocument::fromJson(response).object()["data"].toObject(); auto salt = QByteArray::fromBase64(data["salt"].toString().toUtf8()); auto iv = QByteArray::fromBase64(data["iv"].toString().toUtf8()); auto ckey = QByteArray::fromBase64(data["ckey"].toString().toUtf8()); QString remotePublicKey = data["public_key"].toString(); bool isOverride = wallet->wasSoftReset(); wallet->setSalt(salt); wallet->setIv(iv); wallet->setCKey(ckey); QString keyStatus = "ok"; QStringList localPublicKeys = wallet->listPublicKeys(); if (remotePublicKey.isEmpty() || isOverride) { if (!localPublicKeys.isEmpty()) { QString key = localPublicKeys.first(); receiveAt(key, key); } } else { if (localPublicKeys.isEmpty()) { keyStatus = "preexisting"; } else if (localPublicKeys.first() != remotePublicKey) { keyStatus = "conflicting"; } } // none of the hfc account info should be emitted QJsonObject json; QJsonObject responseData{ { "status", "success"} }; json["keyStatus"] = keyStatus; responseData["data"] = json; emit accountResult(responseData); }
RTI2Reader::RTI2Reader( std::string filename ) { SubKeySpace subKeySpace; CharacterSet charSet; char *str; uint8 *indexTmp; uint32 a, b, count, sum = 0, subKeySpacesCount = 0, hybridSets = 0, passwordLength = 0; int ret; uint8 characterSetFlags; chainPosition = 0; // XXX for reading straight from data in memory //indexOffset = 0; fin.open( filename.c_str(), std::ios_base::binary | std::ios_base::in ); if( !fin.seekg( 0, std::ios_base::beg ).good() || !fin.read( (char*) (&header), sizeof(header) ).good() ) { std::cerr << "readHeader fin.read() error" << std::endl; exit( 1 ); // file error } if ( header.tag != 0x32495452 ) // RTI2 { std::cerr << "readHeader bad tag - this is not a RTI2 file" << std::endl; exit( 3 ); // bad tag } if ( header.minor != 0 ) { std::cerr << "readHeader bad minor version" << std::endl; exit( 4 ); // bad minor version } if ( header.startPointBits == 0 || header.startPointBits > 64 ) { std::cerr << "readHeader parsing error" << std::endl; std::cerr << "header.startPointBits: " << header.startPointBits << std::endl; exit( 2 ); // invalid header } if ( header.endPointBits == 0 || header.endPointBits > 64 ) { std::cerr << "readHeader parsing error" << std::endl; std::cerr << "header.endPointBits: " << header.endPointBits << std::endl; exit( 2 ); // invalid header } if ( header.checkPointBits > 64 ) { std::cerr << "readHeader parsing error" << std::endl; std::cerr << "header.checkPointBits: " << header.checkPointBits << std::endl; exit( 2 ); // invalid header } if ( header.startPointBits + header.checkPointBits + header.endPointBits > 64 ) { std::cerr << "readHeader parsing error" << std::endl; std::cerr << "header.startPointBits + header.checkPointBits + header.endPointBits > 64" << std::endl; std::cerr << "header.startPointBits: " << header.startPointBits << std::endl; std::cerr << "header.endPointBits: " << header.endPointBits << std::endl; std::cerr << "header.checkPointBits: " << header.checkPointBits << std::endl; exit( 2 ); // invalid header } if ( header.fileIndex > header.files ) { std::cerr << "readHeader parsing error" << std::endl; std::cerr << "fileIndex: " << header.fileIndex << std::endl; std::cerr << "files: " << header.files << std::endl; exit( 2 ); // invalid header } if ( header.algorithm > 19 ) { std::cerr << "readHeader parsing error" << std::endl; std::cerr << "undefined algorithm: " << header.algorithm << std::endl; exit( 2 ); // invalid header } if ( header.reductionFunction > 2 || (header.reductionFunction < 1 && header.tableIndex > 65535) || (header.reductionFunction == 1 && header.tableIndex > 255)) { std::cerr << "readHeader parsing error" << std::endl; std::cerr << "invalid reductionFunction parameters" << std::endl; std::cerr << "header.reductionFunction: " << header.reductionFunction << std::endl; std::cerr << "header.tableIndex: " << header.tableIndex << std::endl; exit( 2 ); // invalid header } if ( header.tableIndex != 0 && ((header.reductionFunction < 1 && header.chainLength - 2 > header.tableIndex << 16) || (header.reductionFunction == 2 && header.chainLength > header.tableIndex))) // I think this might be "header.chainLength - 2 > header.tableIndex" need to double check { // Sc00bz remarks "(these tables suck)" std::cerr << "WARNING: Table index is not large enough for this chain length" << std::endl; } str = new char[1024]; if ( header.algorithm == 0 ) { std::cerr << "readHeader fin.read() error, reserved algorithm" << std::endl; delete [] str; exit( 2 ); } // Salt setSalt( "" ); if ( header.algorithm == 0 || ( header.algorithm >= 15 && header.algorithm <= 19 )) { ret = readRTI2String( fin, str ); if ( ret < 0 ) { std::cerr << "readHeader fin.read() error, salt" << std::endl; delete [] str; exit( -ret ); } str[ret] = 0; setSalt( str ); } // Sub keyspaces subKeySpaces.clear(); subKeySpacesCount = 0; if ( !fin.read( (char*) (&subKeySpacesCount), 1 ).good() ) { std::cerr << "readHeader fin.read() error" << std::endl; delete [] str; exit( 1 ); // file error } if ( subKeySpacesCount == 0 ) { std::cerr << "readHeader fin.read() error" << std::endl; std::cerr << "subKeySpaces missing from header" << std::endl; delete [] str; exit( 2 ); // invalid header } for ( a = 0; a < subKeySpacesCount; a++ ) { subKeySpace.perPositionCharacterSets.clear(); subKeySpace.passwordLength.clear(); if ( !fin.read( (char*) (&hybridSets), 1 ).good() ) { std::cerr << "readHeader fin.read() error" << std::endl; delete [] str; exit( 1 ); // file error } if ( hybridSets == 0 ) { std::cerr << "readHeader fin.read() error, hybridSets is 0" << std::endl; delete [] str; exit( 2 ); // invalid header } subKeySpace.hybridSets = hybridSets; // Hybrid sets for ( b = 0; b < hybridSets; b++ ) { // Password length if ( !fin.read( (char*) (&passwordLength), 1 ).good() ) { std::cerr << "readHeader fin.read() error" << std::endl; delete [] str; exit( 1 ); // file error } if ( passwordLength == 0 ) { std::cerr << "readHeader fin.read() error, passwordLength is 0" << std::endl; delete [] str; exit( 2 ); //invalid header } subKeySpace.passwordLength.push_back( passwordLength ); // Character set flags if ( !fin.read( (char*) (&characterSetFlags), 1 ).good() ) { std::cerr << "readHeader fin.read() error" << std::endl; delete [] str; exit( 1 ); // file error } if ( characterSetFlags == 0 ) { std::cerr << "readHeader fin.read() error, characterSetFlags is 0" << std::endl; delete [] str; exit( 2 ); // invalid header } subKeySpace.charSetFlags.push_back( characterSetFlags ); // Character set charSet.characterSet1.clear(); charSet.characterSet2.clear(); charSet.characterSet3.clear(); charSet.characterSet4.clear(); if ( characterSetFlags & 1 ) { ret = readRTI2String( fin, str, 1 ); if ( ret < 0 ) { delete [] str; exit( -ret ); } charSet.characterSet1.assign((uint8*) str, ((uint8*) str) + ret ); } if ( characterSetFlags & 2 ) { ret = readRTI2String( fin, str, 2 ); if ( ret < 0 ) { delete [] str; exit( -ret ); } charSet.characterSet2.assign((uint16*) str, ((uint16*) str) + ret ); } if ( characterSetFlags & 4 ) { ret = readRTI2String( fin, str, 3 ); if ( ret < 0 ) { delete [] str; exit( -ret ); } charSet.characterSet3.assign((uint24*) str, ((uint24*) str) + ret ); } if ( characterSetFlags & 8 ) { ret = readRTI2String( fin, str, 4 ); if ( ret < 0 ) { delete [] str; exit( -ret ); } charSet.characterSet4.assign((uint32*) str, ((uint32*) str) + ret ); } subKeySpace.perPositionCharacterSets.push_back(charSet); } subKeySpaces.push_back(subKeySpace); } // Check point positions if ( !fin.read( str, 4 * header.checkPointBits ).good() ) { std::cerr << "readHeader fin.read() error" << std::endl; delete [] str; exit( 1 ); // file error } checkPointPositions.assign((uint32*) str, ((uint32*) str) + header.checkPointBits); delete [] str; // *** Index *** if ( !fin.read( (char*) (&index.firstPrefix), 8 ).good() ) { std::cerr << "readIndex fin.read() error" << std::endl; exit( 1 ); // file error } if ( !fin.read((char*) (&count), 4 ).good() ) { std::cerr << "readIndex fin.read() error" << std::endl; exit( 1 ); // file error } if ( count == 0 ) { std::cerr << "readIndex fin.read() error, prefixIndex count is 0" << std::endl; exit( 1 ); // file error } indexTmp = new uint8[count]; if ( !fin.read( (char*) indexTmp, count ).good() ) { std::cerr << "readIndex fin.read() error" << std::endl; delete [] indexTmp; exit( 1 ); // file error } index.prefixIndex.reserve(count + 1); index.prefixIndex.push_back(sum); for (a = 0; a < count; a++) { sum += indexTmp[a]; index.prefixIndex.push_back(sum); } delete [] indexTmp; // *** Data *** chainSizeBytes = (header.startPointBits + header.checkPointBits + header.endPointBits + 7) >> 3; chainCount = sum; /* * reads everything at once...doesn't work for memory constrained env data = new uint8[chainSizeBytes * sum + 8 - chainSizeBytes]; // (8 - chainSizeBytes) to avoid "reading past the end of the array" error if ( !fin.read( (char*) (data), chainSizeBytes * sum ).good() ) { std::cerr << "readData fin.read() error" << std::endl; delete [] data; data = NULL; exit( 1 ); // file error } */ }