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

📄 mfcdlg.cpp

📁 source_code 实现无线局域网中的802.1x功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMfcDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMfcDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMfcDlg::OnOK() 
{
	// TODO: Add extra validation here
	//--------------------------------------------------------------------
// This program lists all of the certificates in a system certificate
// store and all of the property identifier numbers of those 
// certificates. It also demonstrates the use of two
// UI functions. One, CryptUIDlgSelectCertificateFromStore, 
// displays the certificates in a store
// and allows the user to select one of them, 
// The other, CryptUIDlgViewContext,
// displays the contents of a single certificate.

//--------------------------------------------------------------------
// Declare and initialize variables.
/*
char             pszNameString[256];
char             pszNameString1[256];
char             pszNameString2[256];
char			 pszStoreName[256] ="my";
DWORD            dwPropId = 0;
LPTSTR			 pszString = 0;
DWORD*			 pcchString = 0; 
            // Zero must be used on the first
            // call to the function. After that,
            // the last returned property identifier is passed.

//--------------------------------------------------------------------
//  Begin processing. Get the name of the system certificate store 
//  to be enumerated. Output here is to stderr so that the program can 
//  be run from the command line and stdout can be redirected to a 
//  file.

fprintf(stderr,"Please enter the store name:");
//scanf("%s",pszStoreName);
fprintf(stderr,"The store name is %s .\n",pszStoreName);

//--------------------------------------------------------------------
// Open a system certificate store.

if ( hCertStore = CertOpenSystemStore(
     NULL,
     pszStoreName))
{
     fprintf(stderr,"The %s store has been opened. \n", pszStoreName);
}
else
{
// If the store was not opened, exit to an error routine.
     MyHandleError("The store was not opened.");
}



//--------------------------------------------------------------------
//  Select an new certificate using UI.

if(!(pCertContext = CryptUIDlgSelectCertificateFromStore(
  hCertStore,
  NULL,
  NULL,
  NULL,
  CRYPTUI_SELECT_LOCATION_COLUMN,
  0,
  NULL)))
{
    MyHandleError("Select UI failed." );
}
//--------------------------------------------------------------------
//  Find and print the name of the subject of the certificate 
//  just retrieved.
	
if(CertGetNameString(   
   pCertContext,   
   CERT_NAME_SIMPLE_DISPLAY_TYPE,   
   0,
   NULL,   
   pszNameString,   
   128))
{
     text = pszNameString;
	 m_UN.SetWindowText(text);
}
else
{
     text = "CertGetName failed." ;
	 m_UN.SetWindowText(text);
}
	 name = pszNameString;
//------------------------------------------------
//	Get issuer name
	 CertGetNameString(   
		pCertContext,   
		CERT_NAME_SIMPLE_DISPLAY_TYPE,   
		CERT_NAME_ISSUER_FLAG,
		NULL,   
		pszNameString1,   
		128);
//	 iname = pszNameString1;
//--------------------------------------------------------------------
	 length = pCertContext->cbCertEncoded;
	 pb = pCertContext->pbCertEncoded;
//--------------------------------------------------------------------
// Open the certificate store to be searched.

if(hSystemStore = CertOpenStore(
     CERT_STORE_PROV_SYSTEM, 
     0,                      // Encoding type not needed with this PROV.
     NULL,                   // Accept the default HCRYPTPROV. 
     CERT_SYSTEM_STORE_CURRENT_USER,
                             // Set the system store location in the
                             // registry.
     L"ROOT"))                 // Could have used other predefined 
                             // system stores
                             // including Trust, CA, or Root.
{
   printf("Opened the ROOT system store. \n");
}
else
{
   printf( "Could not open the ROOT system store.\n");
   exit(1);
}
//-------------------------------------------------------------------
while ( pDesiredCert = CertEnumCertificatesInStore(hSystemStore,pDesiredCert) ) {
	if ( pDesiredCert ) {
		
		CertGetNameString(   
				pDesiredCert,   
				CERT_NAME_SIMPLE_DISPLAY_TYPE,   
				0,
				NULL,   
				pszNameString2,   
				128);

    }
//	iname2 = pszNameString2;
//  need compare all of string
		if(pszNameString1[1] == pszNameString2[1])
		break;
}
*/
}

void MyHandleError(char *s)
{
    fprintf(stderr,"An error occurred in running the program. \n");
    fprintf(stderr,"%s\n",s);
    fprintf(stderr, "Error number %x.\n", GetLastError());
    fprintf(stderr, "Program terminating. \n");
    exit(1);
} // End of MyHandleError.

void CMfcDlg::Onlogin() 
{
	// TODO: Add your control notification handler code here
	CEdit *pUsername;
	CEdit *pPassword;

		
	pUsername = (CEdit *) GetDlgItem (IDC_USERNAME_EDIT1);
	pUsername->GetWindowText(m_username);

	pPassword = (CEdit *) GetDlgItem (IDC_PASSWORD_EDIT2);
	pPassword->GetWindowText(m_password);
	

	
	char face[100], name[100], pw[100];
	initalize_user_conf();  // Set up our user information structure.
	strcpy(face,m_Temp);
	strcpy(name,m_username);
	strcpy(pw,m_password);
	

//1x.conf	
//----------------------------------------
//	set_client_cert("cert-clt.der");
//    set_key_file("cert-clt.pem");
	set_root_cert("root.pem");
//	set_root_dir("E:\\");
//    set_crl_dir("E:\\");
	set_password(pw);
	set_random_file("random");
//	set_preferred_auth("TTLS");
//	set_phase2auth("PAP");
	set_phase2id(name);
	set_username(name,0);
//----------------------------------------

	device=face;
	
	auth_addr = (u_char *)malloc(sizeof(u_char) * ETH_ADDR_LEN);
	memcpy(auth_addr,dstAddr,ETH_ADDR_LEN);
		  
	/**** Begin EAPOL Conversation ****/

	if ((ret = init_eapol(device, netid, auth_addr, config)) == -1) 
	{
		free(auth_addr);
		auth_addr = NULL;
		exit_cleanly(-1);
	}

	running = TRUE;                  //803
	AfxBeginThread(run, this);       //803
}

void CMfcDlg::Onlogoff() 
{
	// TODO: Add your control notification handler code here
	OnStop();
	if(eapol_get_current_state() == AUTHENTICATED)
    {
      set_userLogoff(1);
      eapol_pae_transition_state();
      eapol_pae_do_state();
      set_userLogoff(0);
    }
	// Clean up.

	CertFreeCertificateContext(pCertContext);
	CertCloseStore(hCertStore,0);
	if(pDesiredCert)
    CertFreeCertificateContext(pDesiredCert);
	if(hSystemStore)
    CertCloseStore(
        hSystemStore, 
        CERT_CLOSE_STORE_CHECK_FLAG);

	EndDialog(IDOK);

}

void CMfcDlg::OnSelchangeCombo1() 
{
	// TODO: Add your control notification handler code here
	int i,ifSelect;
	char tmp[100];

	m_IF.GetLBText(m_IF.GetCurSel(),tmp);//get string data variable
	ifSelect=m_IF.GetCurSel();
	ifSelect=tmp[0]-48;
	d=alldev;
	for(i=0; i< ifSelect;i++){
		if(!strcmp(tmp,d->description))
		break;
		d=d->next;
	}
	m_Temp=d->name;
}



⌨️ 快捷键说明

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