Example #1
0
void recursiveSolve(int depth) {
	if (depth == 0) {
		for (unsigned char i = 'a'; i <= 'z'; i++) {
			plaintext[depth] = (u08b_t)i;
			checkHash();
		}
		for (unsigned char i = '0'; i <= '9'; i++) {
			plaintext[depth] = (u08b_t)i;
			checkHash();
		}
		for (unsigned char i = 'A'; i <= 'Z'; i++) {
			plaintext[depth] = (u08b_t)i;
			checkHash();
		}
	} else {
		for (unsigned char i = 'a'; i <= 'z'; i++) {
			plaintext[depth] = (u08b_t)i;
			recursiveSolve(depth-1);
		}
		for (unsigned char i = '0'; i <= '9'; i++) {
			plaintext[depth] = (u08b_t)i;
			recursiveSolve(depth-1);
		}
		for (unsigned char i = 'A'; i <= 'Z'; i++) {
			plaintext[depth] = (u08b_t)i;
			recursiveSolve(depth-1);
		}
	}
}
Example #2
0
static void testCTLProperties(void)
{
    PCCTL_CONTEXT ctl;
    BOOL ret;
    DWORD propID, numProps, access, size;

    ctl = CertCreateCTLContext(X509_ASN_ENCODING,
     signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent));
    if (!ctl)
    {
        skip("CertCreateCTLContext failed: %08x\n", GetLastError());
        return;
    }

    /* No properties as yet */
    propID = 0;
    numProps = 0;
    do {
        propID = CertEnumCTLContextProperties(ctl, propID);
        if (propID)
            numProps++;
    } while (propID != 0);
    ok(numProps == 0, "Expected 0 properties, got %d\n", numProps);

    /* An implicit property */
    ret = CertGetCTLContextProperty(ctl, CERT_ACCESS_STATE_PROP_ID, NULL,
     &size);
    ok(ret || broken(GetLastError() == CRYPT_E_NOT_FOUND /* some win98 */),
     "CertGetCTLContextProperty failed: %08x\n", GetLastError());
    ret = CertGetCTLContextProperty(ctl, CERT_ACCESS_STATE_PROP_ID, &access,
     &size);
    ok(ret || broken(GetLastError() == CRYPT_E_NOT_FOUND /* some win98 */),
     "CertGetCTLContextProperty failed: %08x\n", GetLastError());
    if (ret)
        ok(!(access & CERT_ACCESS_STATE_WRITE_PERSIST_FLAG),
         "Didn't expect a persisted cert\n");

    checkHash(signedCTLWithCTLInnerContent,
     sizeof(signedCTLWithCTLInnerContent), CALG_SHA1, ctl, CERT_HASH_PROP_ID);

    /* Now that the hash property is set, we should get one property when
     * enumerating.
     */
    propID = 0;
    numProps = 0;
    do {
        propID = CertEnumCTLContextProperties(ctl, propID);
        if (propID)
            numProps++;
    } while (propID != 0);
    ok(numProps == 1, "Expected 1 properties, got %d\n", numProps);

    checkHash(signedCTLWithCTLInnerContent,
     sizeof(signedCTLWithCTLInnerContent), CALG_MD5, ctl,
     CERT_MD5_HASH_PROP_ID);

    CertFreeCTLContext(ctl);
}
Example #3
0
/**
 * @brief Parses in the block context for the given node
 * 
 * The block context parses comments and data identifiers, any other
 * data is invalid in this context.
 * 
 * The block context ends when a closing hash marker is found.
 */
void NepParser::genCtxBlock(Nepeta::Node &node)
{
	size_t stLine = getCurLine(), stCol = getCurCol();
	
	while( notEof() ) {
		char ch = getCurRaw();
		
		// Skip whitespace
		if( isWhite(ch) ) {
			iterCur();
		// Check for data block marker
		} else if( checkIdentifier(ch) || checkHash(ch) ) {
			// Parse the data block.
			// If an end marker is found, this returns false
			if(!genCtxData(node))
				return;
		// Check for comment marker
		} else if( checkComment(ch) ) {
			helpSkipComment();
		// Any other character is invalid, skip to the next line
		} else {
			mScript.addError( Nepeta::ErrIllegalCharacter, std::string(1,ch),
				getCurLine(), getCurCol()
			);
			helpSeekNewline(false);
		}
	}
	
	if(node.getParent()) {
		mScript.addError( Nepeta::ErrPrematureEnd, "",
		stLine, stCol, getCurLine(), getCurCol());
	}
}
Example #4
0
int XmlStnInterface::readFile(const QString &fileName)
{
	GEOLIB::GEOObjects* geoObjects = _project->getGEOObjects();
	QFile* file = new QFile(fileName);
	if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
	{
		std::cout << "XmlStnInterface::readFile() - Can't open xml-file." << "\n";
		delete file;
		return 0;
	}
	if (!checkHash(fileName))
	{
		delete file;
		return 0;
	}

	QDomDocument doc("OGS-STN-DOM");
	doc.setContent(file);
	QDomElement docElement = doc.documentElement(); //root element, used for identifying file-type
	if (docElement.nodeName().compare("OpenGeoSysSTN"))
	{
		std::cout << "XmlStnInterface::readFile() - Unexpected XML root." << "\n";
		delete file;
		return 0;
	}

	QDomNodeList lists = docElement.childNodes();
	for (int i = 0; i < lists.count(); i++)
	{
		// read all the station lists
		QDomNodeList stationList = lists.at(i).childNodes();
		std::vector<GEOLIB::Point*>* stations = new std::vector<GEOLIB::Point*>;
		std::string stnName("[NN]");

		for (int j = 0; j < stationList.count(); j++)
		{
			const QDomNode station_node(stationList.at(j));
			const QString station_type(station_node.nodeName());
			if (station_type.compare("name") == 0)
				stnName = station_node.toElement().text().toStdString();
			else if (station_type.compare("stations") == 0)
				this->readStations(station_node, stations, fileName.toStdString());
			else if (station_type.compare("boreholes") == 0)
				this->readStations(station_node, stations, fileName.toStdString());
		}

		if (!stations->empty())
			geoObjects->addStationVec(stations, stnName);
		else
			delete stations;
	}

	delete file;

	return 1;
}
Example #5
0
int XmlCndInterface::readFile(std::vector<FEMCondition*> &conditions, const QString &fileName)
{
	QFile* file = new QFile(fileName);
	if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
	{
		std::cout << "XMLInterface::readFEMCondFile() - Can't open xml-file." << std::endl;
		delete file;
		return 0;
	}
	if (!checkHash(fileName))
	{
		delete file;
		return 0;
	}

	QDomDocument doc("OGS-Cond-DOM");
	doc.setContent(file);
	QDomElement docElement = doc.documentElement(); //root element, used for identifying file-type
	if (docElement.nodeName().compare("OpenGeoSysCond"))
	{
		std::cout << "XMLInterface::readFEMCondFile() - Unexpected XML root." << std::endl;
		delete file;
		return 0;
	}

	//std::vector<FEMCondition*> conditions;
	QDomNodeList lists = docElement.childNodes();
	for (int i = 0; i < lists.count(); i++)
	{
		const QDomNode list_node (lists.at(i));
		if (list_node.nodeName().compare("BoundaryConditions") == 0)
			readConditions(list_node, conditions, FEMCondition::BOUNDARY_CONDITION);
		else if (list_node.nodeName().compare("InitialConditions") == 0)
			readConditions(list_node, conditions, FEMCondition::INITIAL_CONDITION);
		else if (list_node.nodeName().compare("SourceTerms") == 0)
			readConditions(list_node, conditions, FEMCondition::SOURCE_TERM);
	}
	if (!conditions.empty())
		return 1;             //do something like _geoObjects->addStationVec(stations, stnName, color);
	else
	{
		std::cout << "XMLInterface::readFEMCondFile() - No FEM Conditions found..." <<
		std::endl;
		return 0;
	}

	delete file;

	return 1;
}
Example #6
0
int XMLQtInterface::readFile(const QString &fileName)
{
	_fileName = fileName;
	QFile file(fileName);
	if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		ERR("XMLQtInterface::readFile(): Can't open xml-file %s.", fileName.toStdString().c_str());
		return 0;
	}
	_fileData = file.readAll();
	file.close();

	if (!checkHash())
		return 0;

	return 1;
}
Example #7
0
void ParamMap::add(const string &str) {

  int hash = checkHash(str);

  if (hash != 1)
  {
    Param p(str.substr(0, hash));             // cut the string until a hash appears, otherwise use the whole string (hash = str.length())

    if (!checkParam(p.getParamName()))        // if name not present -> create list with first Param entry
    {
      vector<Param> paramVec;
      paramVec.push_back(p);
      paraMap[p.getParamName()] = paramVec;
    }
    else                                      // if name already exits push_back Param to STL vector in map
    {
      vector<Param> *paramVec = getParamVector(p.getParamName());
      paramVec->push_back(p);
    }
  }
}
Example #8
0
bool CSPDirectiveList::allowStyleHash(const CSPHashValue& hashValue) const
{
    return checkHash(operativeDirective(m_styleSrc.get()), hashValue);
}
Example #9
0
/*	================== getOption =================
 This function reads in the user's desired chose
 of operation. Calls upon other functions to
 perform the procedure.
 Pre		pHeader - pointer to HEAD structure
 Post
 Return
 */
void getOption (HEAD* pHeader)
{
	//	Local Declarations
    char command;
    DATA target;
    DATA* airport = NULL;
	int i;
    
	//	Statements
    while ((command = menu()) != 'Q') {
        switch (command)
        {
            case 'A':
                if (addAirport(pHeader))
                {
                    while (checkHash(pHeader->pHash) == 1) {
                        pHeader->pHash = upsizeHash(pHeader->pHash);
                    }
					printf ("\n Succesfully added data.\n\n");
                }
                break;
            case 'D':
                printf("Enter the airport code: ");
                scanf(" %s", target.arpCode);
                
				if (deleteHash (pHeader, target))
                {
                    while (checkHash(pHeader->pHash) == -1) {
                        pHeader->pHash = downsizeHash(pHeader->pHash);
                    }
					printf ("\n Succesfully deleted data.\n\n");
                }
                
                break;
            case 'F':
                printf("Enter the airport code: ");
                scanf(" %s", target.arpCode);
				// fix sensitive input cases
				for (i = 0; i < strlen(target.arpCode); i++) {
					target.arpCode[i] = toupper(target.arpCode[i]);
				}
                airport = findHash(pHeader->pHash, &target);
                if (airport != NULL) {
                    processScreen(airport);
                }
                else printf("No airport exists\n");
                
                break;
            case 'L':
                printHash(pHeader->pHash);
                break;
            case 'K':
                BST_Traverse(pHeader->pTree, processScreen);
                break;
            case 'P':
                printTree(pHeader->pTree->root, 0);
				printf("\n");
                break;
            case 'W':
				outputFile (pHeader->pHash);
                break;
            case 'E':
				efficiency(pHeader->pHash);
                break;
			case 'H':
				pHeader->pHash = hashDemo(pHeader->pHash);
				break;
            default:
                printf("Invalid choice. Choose again\n");
                break;
        }
    }
    return;
}	// getOption
Example #10
0
void RetroShareLink::check()
{
    _valid = true;

    switch (_type) {
    case TYPE_UNKNOWN:
        _valid = false;
        break;
    case TYPE_FILE:
        if(_size > (((uint64_t)1)<<40))	// 1TB. Who has such large files?
            _valid = false;

        if(!checkName(_name))
            _valid = false;

        if(!checkHash(_hash))
            _valid = false;
        break;
    case TYPE_PERSON:
        if(_size != 0)
            _valid = false;

        if(_name.isEmpty())
            _valid = false;

        if(_hash.isEmpty())
            _valid = false;
        break;
    case TYPE_FORUM:
        if(_size != 0)
            _valid = false;

        if(_name.isEmpty())
            _valid = false;

        if(_hash.isEmpty())
            _valid = false;
        break;
    case TYPE_CHANNEL:
        if(_size != 0)
            _valid = false;

        if(_name.isEmpty())
            _valid = false;

        if(_hash.isEmpty())
            _valid = false;
        break;
    case TYPE_SEARCH:
        if(_size != 0)
            _valid = false;

        if(_name.isEmpty())
            _valid = false;

        if(!_hash.isEmpty())
            _valid = false;
        break;
    case TYPE_MESSAGE:
        if(_size != 0)
            _valid = false;

        if(_hash.isEmpty())
            _valid = false;
        break;
    case TYPE_CERTIFICATE:
        break;
    }

    if (!_valid) {
        clear();
    }
}
Example #11
0
int XmlGspInterface::readFile(const QString &fileName)
{
	QFile* file = new QFile(fileName);
	QFileInfo fi(fileName);
	QString path = (fi.path().length() > 3) ? QString(fi.path() + "/") : fi.path();

	QFileInfo si(QString::fromStdString(_schemaName));
	QString schemaPath(si.absolutePath() + "/");

	if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
	{
		std::cout << "XmlGspInterface::readFile() - Can't open xml-file " <<
		fileName.toStdString() << "." << std::endl;
		delete file;
		return 0;
	}
	if (!checkHash(fileName))
	{
		delete file;
		return 0;
	}

	QDomDocument doc("OGS-PROJECT-DOM");
	doc.setContent(file);
	QDomElement docElement = doc.documentElement(); //OpenGeoSysProject
	if (docElement.nodeName().compare("OpenGeoSysProject"))
	{
		std::cout << "XmlGspInterface::readFile() - Unexpected XML root." << std::endl;
		delete file;
		return 0;
	}

	QDomNodeList fileList = docElement.childNodes();

	for(int i = 0; i < fileList.count(); i++)
	{
		const QString file_node(fileList.at(i).nodeName());
		if (file_node.compare("geo") == 0)
		{
			XmlGmlInterface gml(_project, schemaPath.toStdString() + "OpenGeoSysGLI.xsd");
			const QDomNodeList childList = fileList.at(i).childNodes();
			for(int j = 0; j < childList.count(); j++)
			{
				const QDomNode child_node (childList.at(j));
				if (child_node.nodeName().compare("file") == 0)
				{
					std::cout << "path: " << path.toStdString() << "#" << std::endl;
					std::cout << "file name: " << (child_node.toElement().text()).toStdString() << "#" << std::endl;
					gml.readFile(QString(path + child_node.toElement().text()));
				}
			}
		}
		else if (file_node.compare("stn") == 0)
		{
			XmlStnInterface stn(_project, schemaPath.toStdString() + "OpenGeoSysSTN.xsd");
			const QDomNodeList childList = fileList.at(i).childNodes();
			for(int j = 0; j < childList.count(); j++)
				if (childList.at(j).nodeName().compare("file") == 0)
					stn.readFile(QString(path + childList.at(j).toElement().text()));
		}
		else if (file_node.compare("msh") == 0)
		{
			const std::string msh_name = path.toStdString() +
			                       fileList.at(i).toElement().text().toStdString();
			FileIO::MeshIO meshIO;
			MeshLib::Mesh* msh = meshIO.loadMeshFromFile(msh_name);
			_project->addMesh(msh);
		}
	}

	return 1;
}
Example #12
0
void LoadAndCheckHash::processFile(const QString &fileName)
{
    if(fileName.isEmpty() || fileName.isNull())
        return;
#ifdef MYPREFIX_DEBUG
    qDebug() << "LoadAndCheckHash::processFile:" << fileName;
#endif
    QFileInfo fInfo(fileName);
    QString hashStrFromFile,
            origFileName;
    if( fInfo.isFile() && fInfo.isReadable() )
    {

        QFile file(fileName);
        QString line;
        QByteArray bline;
        QStringList qsl;
        if (file.open(QFile::ReadOnly | QIODevice::Text)) {
            while (!file.atEnd())
            {
                bline = file.readLine();
                line = QString::fromUtf8(bline);

                qsl = line.split(" *");
                if(qsl.size() == 2)
                {
                    hashStrFromFile = qsl[0];
                    origFileName = qsl[1];
                    origFileName = QDir::toNativeSeparators(fInfo.path()) + QDir::separator() + origFileName;
                }
                else
                {
                    hashStrFromFile = line;
                    origFileName = QDir::toNativeSeparators(fInfo.path()) + QDir::separator() + fInfo.completeBaseName();
                }
            }
            file.close();
        }


#ifdef MYPREFIX_DEBUG
        qDebug() << "LoadAndCheckHash::processFile " << origFileName;
#endif
        if(QFileInfo(origFileName).exists())
        {
#ifdef MYPREFIX_DEBUG
        qDebug() << "LoadAndCheckHash::processFile File exists: " << origFileName;
#endif
            checkHash(origFileName, hashStrFromFile);
        }
        else
        {
#ifdef MYPREFIX_DEBUG
        qDebug() << "LoadAndCheckHash::processFile File non exists: " << origFileName;
#endif
            origFileName = QDir::toNativeSeparators(fInfo.path()) + QDir::separator() + fInfo.completeBaseName();
            if(QFileInfo(origFileName).exists())
            {
#ifdef MYPREFIX_DEBUG
        qDebug() << "LoadAndCheckHash::processFile File Exists: " << origFileName;
#endif
                checkHash(origFileName, hashStrFromFile);
            }
            else
            {
#ifdef MYPREFIX_DEBUG
        qDebug() << "LoadAndCheckHash::processFile File non exists: " << origFileName;
#endif
                HashFileInfoStruct strct;
                strct.hash = hashStrFromFile;
                strct.fileName = fileName;
                strct.checked = true;
                strct.size = 0;
                itemsList.data()->append(std::move(strct));
            }
        }
        ++processed_files;
        if(processed_files % SAY_PROGRESS_EVERY == 0)
            emit currentProcessedFiles(processed_files);
    }
}
Example #13
0
/*****************child process encrypt udp connection*******************/
void udp_vpn(int MODE, int Port, char *ip, int port, int pipefd) {

    struct sockaddr_in sin, sout;//standard in and out sockets address
    struct ifreq ifr;//virtual nic card
    socklen_t soutlen;
    int fd, s, l, i, ready = 0;
    int status;

    fd_set fdset;
    char buf[BUFSIZE], hash[HASHLEN], totalbuf[BUFSIZE];

    //set up virtual nic card
    if ((fd = open("/dev/net/tun", O_RDWR)) < 0) PERROR("open error!!!");
    memset(&ifr, 0, sizeof(ifr));
    ifr.ifr_flags = IFF_TUN;   
    strncpy(ifr.ifr_name, "toto%d", IFNAMSIZ);
    if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) PERROR("ioctl");
    printf("Allocated interface %s. Configure and use it\n", ifr.ifr_name);

    //create udp socket
    s = socket(PF_INET, SOCK_DGRAM, 0);
    sin.sin_family = AF_INET;
    sin.sin_addr.s_addr = htonl(INADDR_ANY);
    sin.sin_port = htons(Port);

    //bind step
    if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) PERROR("bind error!!!");

    soutlen = sizeof(sout);
    if (MODE == CLIENT) { 
   	 sout.sin_family = AF_INET;
   	 sout.sin_port = htons(port);
   	 inet_aton(ip, &sout.sin_addr);
    }

    while (1) {
	 //read the key
   	 l = read(pipefd, buf, sizeof(buf));
   	 if (l > 0) { 
		 if (buf[0] == 'a') {	//disconnect
		     exit(0);
		 }
   		 else if (buf[0]=='k') {	//getting key
			memcpy(key, buf + 1, KEYSIZE);
   			ready = 1;
   		 }
   	 }
   	 if (!ready) {
   		 sleep(1);
   		 continue;
   	 }
	 //fd from nic card, s from socket
   	 FD_ZERO(&fdset);
   	 FD_SET(fd, &fdset);
   	 FD_SET(s, &fdset);
   	 if (select(fd+s+1, &fdset,NULL,NULL,NULL) < 0) PERROR("select");//select which file descriptor is using
	 //virtual nic card
   	 if (FD_ISSET(fd, &fdset)) {	
   		 if (DEBUG) printf("SENT: ");
   		 l = read(fd, buf, BUFSIZE);
   		 if (l < 0) PERROR("read");
   		 if (DEBUG) {
   			 printf("\nplain payload: ");
   			 for(i = 0; i < l; i++) printf("%02x", *(buf+i));
   			 printf("\n");
   		 }
		 genIV(IV);

		 //encrypt, hash, append, and send to client
   		 if (do_crypt(key, IV, buf, &l, 1)) {
   			 if (DEBUG) {
   				 printf("\nencrypted payload: ");
   				 for(i = 0; i < l; i++) printf("%02x", *(buf+i));
   				 printf("\n");
   			 }
			 memcpy(totalbuf, IV, IVSIZE);
			 memcpy(totalbuf+IVSIZE, buf, BUFSIZE-IVSIZE);
			 l+=IVSIZE;
   			 appendHash(totalbuf, &l); 
   			 if (DEBUG) {
   				 printf("\nfinal payload: ");
   				 for(i = 0; i < l; i++) printf("%02x", *(buf+i));
   				 printf("\n");
   			 }
			 //send to client
   			 if (sendto(s, totalbuf, l, 0, (struct sockaddr *)&sout, soutlen) < 0) PERROR("sendto");
   		 }
   		 else {
   			 printf("encrypt error\n");
   		 }
   	 }
	 //socket
   	 else {
   		 if (DEBUG) printf("\n RECEIVED");
   		 l = recvfrom(s, buf, BUFSIZE, 0, (struct sockaddr *)&sout, &soutlen);
   		 if (DEBUG) {
   			 printf("\n(encrypted) payload: ");
   			 for(i = 0; i < l; i++) printf("%02x", *(buf+i));
   			 putchar(10); 
   		 }
		 //check reliability
   		 if (checkHash(buf, &l)) {
			   
   			 printf("HASH mismatch.\n");
   		 }
   		 else {
		 	memcpy(IV, buf, IVSIZE);
   			 if (DEBUG) {
   				 printf("\nhash checked payload: ");
   				 for(i = 0; i < l; i++) printf("%02x", *(buf+i));
   			 	 putchar(10); 
   			 }
			 l-=IVSIZE;
			 //decrypt and send to virtual nic card
   			 if (do_crypt(key, IV, buf+IVSIZE, &l, 0)) {
   				 if (DEBUG) {
   					 printf("\nfinal plain payload: ");
   					 for(i = 0; i < l; i++) printf("%02x", *(buf+i));
   					 putchar(10);
   				 }
   				 if (write(fd, buf+IVSIZE, l) < 0) PERROR("write");
   			 }
   			 else {
   				 printf("decrypt error\n");
   			 }
   		 }
	}
    }
}