⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 security.cpp

📁 vncviewer_source_1.0
💻 CPP
字号:
/* Copyright (C) 2006 Lucas Gomez  All Rights Reserved.
 * 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */

// INCLUDE FILES
#include <aknquerydialog.h>

#include "Security.h"

#include "VncViewer.rsg"
#include "connection.h"
#include "LogWriter.h"

#ifdef __WINSCW__
extern "C"
{
#endif
	#include "d3des.h"
#ifdef __WINSCW__
}
#endif

// CONSTANTS
_LIT(KSecTypeNoneDes,"No Encryption");
_LIT(KSecTypeVncAuthDes,"Vnc Authentication");

_LIT(KSecTypeNone,"None");
_LIT(KSecTypeVncAuth,"VncAuth");
_LIT(KSecTypeRA2,"RA2");
_LIT(KSecTypeRA2ne,"RA2ne");

// This an Interface

TInt SecurityNone::ProcessMsg(CConnection* /*aConn*/) 
{
    return 1;
}
    
TInt SecurityNone::GetType() 
{
	return ESecTypeNone;
}

const TDesC& SecurityNone::Description() 
{
	return KSecTypeNoneDes;
}

TInt SecurityVncAuth::ProcessMsg(CConnection* aConn) 
{
	InStream* is=aConn->GetInStream();
    OutStream* os=aConn->GetOutStream();

    RBuf8 challenge;
    challenge.CreateMaxL(VncAuth::KChallengeSize);
    is->ReadBytes(challenge,0,VncAuth::KChallengeSize);
    
    // The descriptor used for the editor
	TBuf<15> text;
	// create dialog instance 
	CAknTextQueryDialog* dlg=new (ELeave) CAknTextQueryDialog(text);
	// Prepares the dialog, constructing it from the specified resource
	dlg->PrepareLC(R_INPUT_SECRET_TEXT_QUERY);
	// Launch the dialog
	if (dlg->RunLD())
    {
   		// ok pressed,   text is the descriptor containing the entered text 
   		// in the editor. 
    }
    else
    {
      	CLogWriter::InstanceL()->LogTrace(_L("Getting password failed"));
      	return 0;
    }
    TBuf8<15> password;
    password.Copy(text);
    VncAuth::EncryptChallenge(challenge,password);
    os->WriteBytes(challenge,0,VncAuth::KChallengeSize);
    os->Flush();
    
    challenge.Close();
    return 1;
}
    
TInt SecurityVncAuth::GetType() 
{
	return ESecTypeVncAuth;
}

const TDesC& SecurityVncAuth::Description() 
{
	return KSecTypeVncAuthDes;
}

void VncAuth::EncryptChallenge(TDes8& aChallenge,TDesC8& aPassword)
{
	TUint8 key[8];
    for(TInt i=0;i<8 && i<aPassword.Length();i++) 
    {
      	key[i]=aPassword[i];
    }
    for(TInt i=aPassword.Length();i<8;i++)
    {
    	key[i]=0;
    }
    
    TUint8 challenge[VncAuth::KChallengeSize];
    for(TInt i=0;i<VncAuth::KChallengeSize;i++)
    {
    	challenge[i]=aChallenge[i];
    }

    deskey(key,EN0);

    for(TInt j=0;j<KChallengeSize;j+=8)
      	des(challenge+j,challenge+j);
      	
    aChallenge.Copy(challenge,VncAuth::KChallengeSize);
}

const TDesC& MSecurity::SecurityName(TInt aSecType)
{
	switch(aSecType)
	{
		case ESecTypeNone:       return KSecTypeNone;
    	case ESecTypeVncAuth:    return KSecTypeVncAuth;
    	case ESecTypeRA2:        return KSecTypeRA2;
    	case ESecTypeRA2ne:      return KSecTypeRA2ne;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -