Esempio n. 1
0
int main()
{
	OpenSSL_add_all_algorithms();

	int port = 24950; // "av" = 0x6176 = 24950
	// 开启 av协议处理

	boost::shared_ptr<BIO> keyfile(BIO_new_file("route.key","r"), BIO_free);
	if(!keyfile)
	{
		std::cerr << "can not open route.key" << std::endl;
		exit(1);
	}

	RSA * rsa_key = PEM_read_bio_RSAPrivateKey(keyfile.get(), 0, (pem_password_cb*) pass_cb, (void*)"route");

	boost::shared_ptr<BIO> certfile(BIO_new_file("route.crt", "r"), BIO_free);
	if(!certfile)
	{
		std::cerr << "can not open route.crt" << std::endl;
		exit(1);
	}
	X509 * x509_cert = PEM_read_bio_X509(certfile.get(), 0, 0, 0);

	certfile.reset();
	keyfile.reset();

	boost::asio::spawn(io_service, boost::bind(&async_acceptor, _1, port, rsa_key, x509_cert));

	// 无限睡眠,客户端的话就开始写客户端的逻辑吧
	io_service.run();
}
void QMyServer::_startServerEncryption ()
{
    if (QSslSocket::supportsSsl())
        qDebug()<< "Supporto SSL attivo....";
    else
        qDebug()<< "Supporto SSL non attivo.... Controlla l'include della libreria libssl .... ";

    QFile cert(":/files/resources/mycertcert.pem");
    if (!cert.open(QIODevice::ReadOnly | QIODevice::Text))
        return;

    QByteArray certba = cert.readAll();

    QFile keyfile(":/files/resources/mycertkey.pem");
    if (!keyfile.open(QIODevice::ReadOnly | QIODevice::Text))
        return;

    QByteArray keyba = keyfile.readAll();

    QSslKey keyKey(keyba, QSsl::Rsa);

    if (keyKey.isNull()) {
        qWarning("Key is null");
        socket->disconnectFromHost();
        return;
    }

    socket->setLocalCertificate( QSslCertificate( certba ) );
    socket->setPrivateKey(keyKey);
    socket->startServerEncryption();

}
Esempio n. 3
0
QString AuthorizationManager::GenerateEncString_bridge(QString str){
  //Get the private key
  QFile keyfile("/usr/local/etc/sysadm/ws_bridge.key");
    keyfile.open(QIODevice::ReadOnly);
  QSslKey key(&keyfile, QSsl::Rsa);
  QByteArray privkey = key.toPem();
  keyfile.close();

  //Now use this private key to encode the given string
  unsigned char encode[4098] = {};
  RSA *rsa= NULL;
  BIO *keybio = NULL;
  keybio = BIO_new_mem_buf(privkey.data(), -1);
  if(keybio==NULL){ return ""; }
  rsa = PEM_read_bio_RSAPrivateKey(keybio, &rsa,NULL, NULL);
  if(rsa==NULL){ return ""; }
  int len = RSA_private_encrypt(str.length(), (unsigned char*)(str.toLatin1().data()), encode, rsa, RSA_PKCS1_PADDING);
  if(len <0){ return ""; }
  else{ 
    //Now return this as a base64 encoded string
    QByteArray str_encode( (char*)(encode), len);
    /*qDebug() << "Encoded String Info";
    qDebug() << " - Raw string:" << str << "Length:" << str.length();
    qDebug() << " - Encoded string:" << str_encode << "Length:" << str_encode.length();*/
    str_encode = str_encode.toBase64();
    /*qDebug() << " - Enc string (base64):" << str_encode << "Length:" << str_encode.length();
    qDebug() << " - Enc string (QString):" << QString(str_encode);*/
    return QString( str_encode ); 
  }

}
Esempio n. 4
0
int main( int argc,char * argv[] )
{
	QApplication a( argc,argv ) ;

	MainWindow w ;

	w.setToken( QString( argv[ 3 ] ) ) ;
	w.setApplicationName( QString( "luks" ) ) ;
	w.setkeyLabel( QObject::tr( " enter luks key below" ) ) ;
	w.setkeyFileLabel( QObject::tr( "enter a path to a luks header below" ) ) ;

	auto e = []( const QVector<QString>& exe,const QString& keyFile,const QString& password ){
		Q_UNUSED( exe ) ;
		/*
		 * we are sending a 4 component structure.
		 * first  component at offset 0 is a u_int32_t structure holding the size of the passphrase
		 * Second component at offset 4 is a u_int32_t structure holding the size of the contents of luks header
		 * third  component at offset 8 is the passphrase to unlock the LUKS volume.
		 * last   component is at offset that marks the end of the third component.Where this offset will be depends on the length of the passphrase
		 */

		auto intToByteArray = []( quint32 s ){

			const char * e = reinterpret_cast< const char * >( &s ) ;
			return QByteArray( e,sizeof( quint32 ) ) ;
		} ;

		QFile keyfile( keyFile ) ;

		QByteArray keyFileSize  = intToByteArray( keyfile.size() ) ;
		QByteArray passWordSize = intToByteArray( password.size() ) ;

		keyfile.open( QIODevice::ReadOnly ) ;

		return passWordSize + keyFileSize + password.toLatin1() + keyfile.readAll() ;
	} ;

	w.setKeyFunction( e ) ;
	w.Show() ;

	return a.exec() ;
}
Esempio n. 5
0
int main( int argc, char *[] )
{
    if( argc < 2 || argc > 3 ) {
        HCWarning( USAGE );
        return( -1 );
    }

    // Parse the command line.
    char    cmdline[80];
    char    *pfilename, *temp;
    int     quiet = 0;

    getcmd( cmdline );
    temp = cmdline;
    pfilename = NULL;
    while( *temp != '\0' && isspace( *temp ) ) {
        temp++;
    }
    if( *temp == '-' || *temp == '/' ) {
        temp++;
        if( (*temp != 'q' && *temp != 'Q') || !isspace( *(temp+1) ) ) {
            HCWarning( USAGE );
            return( -1 );
        } else {
            quiet = 1;
            temp++;
            while( *temp != '\0' && isspace( *temp ) ) {
                temp++;
            }
            if( *temp == '\0' ) {
                HCWarning( USAGE );
                return( -1 );
            } else {
                pfilename = temp;
            }
        }
    } else if( *temp != '\0' ) {
        pfilename = temp++;
        while( *temp != '\0' && *temp != '/' && *temp != '-' ) {
            temp++;
        }
        if( *temp != '\0' ) {
            *temp = '\0';
            temp++;
            if( *temp != 'q' && *temp != 'Q' ) {
                HCWarning( USAGE );
                return( -1 );
            } else {
                temp++;
                while( *temp != '\0' && isspace( *temp ) ) {
                    temp++;
                }
                if( *temp != '\0' ){
                    HCWarning( USAGE );
                    return( -1 );
                } else {
                    quiet = 1;
                }
            }
        }
    }

    SetQuiet( quiet );


    //  Parse the given filename.

    char    path[_MAX_PATH];
    char    drive[_MAX_DRIVE];
    char    dir[_MAX_DIR];
    char    fname[_MAX_FNAME];
    char    ext[_MAX_EXT];

    _fullpath( path, pfilename, _MAX_PATH );
    _splitpath( path, drive, dir, fname, ext );

    if( stricmp( ext, PhExt ) == 0 || stricmp( ext, HlpExt ) == 0 ) {
        HCWarning( BAD_EXT );
        return( -1 );
    }
    if( ext[0] == '\0' ){
        _makepath( path, drive, dir, fname, HpjExt );
    }

    char    destpath[_MAX_PATH];
    _makepath( destpath, drive, dir, fname, HlpExt );

    InFile  input( path );
    if( input.bad() ) {
        HCWarning( FILE_ERR, pfilename );
        return( -1 );
    }


    //  Set up and start the help compiler.

    try {
        HFSDirectory    helpfile( destpath );
        HFFont          fontfile( &helpfile );
        HFContext       contfile( &helpfile );
        HFSystem        sysfile( &helpfile, &contfile );
        HFCtxomap       ctxfile( &helpfile, &contfile );
        HFTtlbtree      ttlfile( &helpfile );
        HFKwbtree       keyfile( &helpfile );
        HFBitmaps       bitfiles( &helpfile );

        Pointers        my_files = {
                            NULL,
                            NULL,
                            &sysfile,
                            &fontfile,
                            &contfile,
                            &ctxfile,
                            &keyfile,
                            &ttlfile,
                            &bitfiles,
        };

        if( stricmp( ext, RtfExt ) == 0 ) {
            my_files._topFile = new HFTopic( &helpfile );
            RTFparser   rtfhandler( &my_files, &input );
            rtfhandler.Go();
        } else {
            HPJReader   projfile( &helpfile, &my_files, &input );
            projfile.parseFile();
        }

        helpfile.dump();
        if( my_files._topFile != NULL ) {
            delete my_files._topFile;
        }
        if( my_files._phrFile != NULL ) {
            delete my_files._phrFile;
        }
    }
    catch( HCException ) {
        HCWarning( PROGRAM_STOPPED );
        return( -1 );
    }
    return( 0 );
}