📄 sslclientsocket.cpp
字号:
pList->SetItemText(0,3,buf);
ZeroMemory(buf,48);
strncpy(buf,(char *)pRa->SUBJECT.L,sizeof(pRa->SUBJECT.L));
pList->SetItemText(0,4,buf);
ZeroMemory(buf,48);
strncpy(buf,(char *)pRa->SUBJECT.O,sizeof(pRa->SUBJECT.O));
pList->SetItemText(0,5,buf);
ZeroMemory(buf,48);
strncpy(buf,(char *)pRa->SUBJECT.OU,sizeof(pRa->SUBJECT.OU));
pList->SetItemText(0,6,buf);
ZeroMemory(buf,48);
strncpy(buf,(char *)pRa->SUBJECT.MAIL,sizeof(pRa->SUBJECT.MAIL));
pList->SetItemText(0,7,buf);
ZeroMemory(buf,48);
strncpy(buf,(char *)pRa->SUBJECT.PMAIL,sizeof(pRa->SUBJECT.PMAIL));
pList->SetItemText(0,8,buf);
pList->SetItemText(0,9,pRa->Time);
}
void CSslClientSocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
if(!m_ifCert&&!m_ifCrl)
{
stuRA RA;//用于接受的结构
if(SSlReceive((char *)&RA,sizeof(stuRA))==0)//对方已经关闭
return;
else if(RA.Type==FInputD)//查询代审核证书
{
if(RA.State)
{
if(RA.KeyL==1) //总纪录,第一次发送总纪录
{
CString str;
str.Format("待审核证书记录条数%d",RA.CertL);//总纪录数RA.CertL
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(1,str);
m_MaxCount=RA.CertL;
((CMainFrame *)AfxGetMainWnd())->SetRange(0,m_MaxCount);
if(RA.CertL==0)//0条纪录
return;
}
else if((RA.KeyL==-1)&&(1==RA.CertL))//总共一条纪录
{
CString str;
str.Format("待审核证书记录条数%d",RA.CertL);//总纪录数RA.CertL
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(1,str);
m_MaxCount=RA.CertL;
((CMainFrame *)AfxGetMainWnd())->SetRange(0,m_MaxCount);
}
if(1==m_MaxCount)
((CMainFrame *)AfxGetMainWnd())->SetPos(1);
else if(RA.CertL!=m_MaxCount)//不是最大数目
((CMainFrame *)AfxGetMainWnd())->SetPos(RA.CertL+1);
if(RA.KeyL==-1)//最后一条
{
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(1,"查询待审核证书完成");
m_AuditList->SetRedraw();
((CMainFrame *)AfxGetMainWnd())->SetPos(m_MaxCount);
}
InsertList(m_AuditList,&RA);
}
else
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(1,"查询待审核证书失败",M_ERROR);
}
else if(RA.Type==FAuditD)//查询代制作证书
{
if(RA.State)
{
if(RA.KeyL==1) //总纪录,第一次发送总纪录
{
CString str;
str.Format("待制作证书记录条数%d",RA.CertL);//总纪录数RA.CertL
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,str);
m_MaxCount=RA.CertL;
((CMainFrame *)AfxGetMainWnd())->SetRange(0,m_MaxCount);
if(RA.CertL==0)//0条纪录
return;
}
else if((RA.KeyL==-1)&&(1==RA.CertL))//总共一条纪录
{
CString str;
str.Format("待制作证书记录条数%d",RA.CertL);//总纪录数RA.CertL
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,str);
m_MaxCount=RA.CertL;
((CMainFrame *)AfxGetMainWnd())->SetRange(0,m_MaxCount);
}
if(1==m_MaxCount)//一条纪录
((CMainFrame *)AfxGetMainWnd())->SetPos(1);
else if(RA.CertL!=m_MaxCount)//不是最大数目
((CMainFrame *)AfxGetMainWnd())->SetPos(RA.CertL+1);
if(RA.KeyL==-1)//最后一条
{
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,"查询待制作证书完成");
m_MadeList->SetRedraw();
((CMainFrame *)AfxGetMainWnd())->SetPos(m_MaxCount);
}
InsertList(m_MadeList,&RA);
}
else
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,"接收待制作证书信息失败",M_ERROR);
}
else if(RA.Type==FMadeD)//查询有效证书(已经制作,尚未作废)
{
if(RA.State)
{
if(RA.KeyL==1) //总纪录,第一次发送总纪录
{
CString str;
str.Format("有效证书记录条数%d",RA.CertL);//总纪录数RA.CertL
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,str);
m_MaxCount=RA.CertL;
((CMainFrame *)AfxGetMainWnd())->SetRange(0,m_MaxCount);
if(RA.CertL==0)//0条纪录
return;
}
else if((RA.KeyL==-1)&&(1==RA.CertL))//总共一条纪录
{
CString str;
str.Format("有效证书记录条数%d",RA.CertL);//总纪录数RA.CertL
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,str);
m_MaxCount=RA.CertL;
((CMainFrame *)AfxGetMainWnd())->SetRange(0,m_MaxCount);
}
if(1==m_MaxCount)
((CMainFrame *)AfxGetMainWnd())->SetPos(1);
else if(RA.CertL!=m_MaxCount)//不是最大数目
((CMainFrame *)AfxGetMainWnd())->SetPos(RA.CertL+1);
if(RA.KeyL==-1)//最后一条
{
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,"查询有效证书完成");
m_RevokeList->SetRedraw();
((CMainFrame *)AfxGetMainWnd())->SetPos(m_MaxCount);
}
InsertList(m_RevokeList,&RA);
}
else
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,"接收有效证书信息失败",M_ERROR);
}
else if(RA.Type==FRevokeD)//查询作废证书
{
if(RA.State)
{
if(RA.KeyL==1) //总纪录,第一次发送总纪录
{
CString str;
str.Format("作废证书记录条数%d",RA.CertL);//总纪录数RA.CertL
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,str);
m_MaxCount=RA.CertL;
((CMainFrame *)AfxGetMainWnd())->SetRange(0,m_MaxCount);
if(RA.CertL==0)//0条纪录
return;
}
else if((RA.KeyL==-1)&&(1==RA.CertL))//总共一条纪录
{
CString str;
str.Format("作废证书记录条数%d",RA.CertL);//总纪录数RA.CertL
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,str);
((CMainFrame *)AfxGetMainWnd())->SetRange(0,1);
}
if(1==m_MaxCount)
((CMainFrame *)AfxGetMainWnd())->SetPos(1);
else if(RA.CertL!=m_MaxCount)//不是最大数目
((CMainFrame *)AfxGetMainWnd())->SetPos(RA.CertL+1);
if(RA.KeyL==-1)//最后一条
{
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,"查询作废证书完成");
m_RevokeList->SetRedraw();
((CMainFrame *)AfxGetMainWnd())->SetPos(m_MaxCount);
}
InsertList(m_RevokeList,&RA);
}
else
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,"接收作废证书信息失败",M_ERROR);
}
if(RA.Type==Input)//申请操作结果
{
if(RA.State)
{
CString ID;
ID.Format("证书录入成功,证书序列号为%d",RA.ID);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(0,ID);;
}
else
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(0,"证书录入失败",M_ERROR);;
}
else if(RA.Type==Audit)//审核操作结果
{
if(RA.State)
{
CString item,Msg;
item.Format("%d",RA.ID);
LVFINDINFO Info;
Info.flags=LVFI_STRING;
Info.psz=item;
int index=m_AuditList->FindItem(&Info,-1);
m_AuditList->DeleteItem(index);
Msg.Format("证书审核操作完成,证书%d已经通过审核",RA.ID);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(1,Msg);
}
else
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(1,"证书审核操作失败",M_ERROR);;
}
else if(RA.Type==Made)//制作操作结果
{
if(RA.State)
{
CString id,msg;
id.Format("%d",RA.ID);
m_CertLen=RA.CertL;
m_KeyLen=RA.KeyL;
m_CertID=id;
m_pCertKey=new char[m_CertLen+m_KeyLen];//动态分配
m_ifCert=true;//下一个接受单元是证书
msg.Format("接收证书制作信息头成功,等待证书%d制作信息......",RA.ID);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,msg);;
}
else
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,"接收证书制作信息头失败",M_ERROR);;
}
else if(RA.Type==Revoke)//证书作废操作结果
{
if(RA.State)
{
CString item,msg;
item.Format("%d",RA.ID);
LVFINDINFO Info;
Info.flags=LVFI_STRING;
Info.psz=item;
int index=m_RevokeList->FindItem(&Info,-1);
m_RevokeList->DeleteItem(index);
msg.Format("证书作废操作完成,证书%d已经作废",RA.ID);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,msg);
// AsyncSelect(FD_CLOSE|FD_WRITE);
}
else
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,"证书作废操作失败",M_ERROR);;
}
else if(RA.Type==MadeCrl)//制作crl
{
if(RA.State)
{
m_CertLen=RA.CertL;
m_pCertKey=new char[m_CertLen];//动态分配
m_ifCrl=true;//下一个接受单元是证书
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,"接收CRL制作信息头成功,等待CRL制作信息......");;
}
else
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,"接收CRL制作信息失败",M_ERROR);;
}
}
else if(m_ifCert)//保存证书
{
SSlReceive(m_pCertKey,m_CertLen+m_KeyLen);
CString info;
info.Format("接收证书%s制作信息成功,保存证书......",m_CertID);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,info);
info.Format("%s\\%scert.pem",((CMainFrame *)AfxGetMainWnd())->m_PathCert,m_CertID);
FILE * cert=fopen(info,"w");
if(cert==NULL)
{
CString strerr;
strerr.Format("保存公钥%s错误",m_CertID);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,strerr);
return;
}
fwrite(m_pCertKey,sizeof(char),m_CertLen,cert);
fclose(cert);
cert=NULL;
info.Format("%s\\%skey.pem",((CMainFrame *)AfxGetMainWnd())->m_PathCert,m_CertID);
cert=fopen(info,"w");
if(cert==NULL)
{
CString strerr;
strerr.Format("保存私钥%s错误",m_CertID);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,strerr);
return;
}
fwrite(m_pCertKey+m_CertLen,sizeof(char),m_KeyLen,cert);
fclose(cert);
cert=NULL;
info.Format("保存证书%s成功",m_CertID);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,info);
m_ifCert=false;//下一单元不是证书
LVFINDINFO Info;
Info.flags=LVFI_STRING;
Info.psz=m_CertID;
int index=m_MadeList->FindItem(&Info,-1);
m_MadeList->DeleteItem(index);
delete [] m_pCertKey;
CString query;
query.Format("Select ID,CERTSTATE,MADETIME From CERTLIST Where ID=%s",m_CertID);
stuCA CA;
CA.Type=MadeOK;
strcpy(CA.SQL,query);
if(SSlSend((char *)&CA,sizeof(CA))>0)
{
info.Format("发送证书%s制作确认信息成功",m_CertID);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,info);
}
else
{
info.Format("发送证书%s制作确认信息失败",m_CertID);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,info,M_ERROR);
}
}
else//crl
{
memset(m_pCertKey,0,m_CertLen);
for(int offect=0,len=0;offect!=m_CertLen;offect+=len)//整个程序只有这里长度可能>16k
{
len=SSlReceive(m_pCertKey+offect,m_CertLen-offect);
}
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,"接收CRL制作信息成功,保存CRL......");;
CString path;
path.Format("%s\\hpxsCrl.crl",((CMainFrame *)AfxGetMainWnd())->m_PathCrl);
FILE * crl=fopen(path,"w");
if(crl==NULL)
{
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,"保存CRL失败");
return;
}
fwrite(m_pCertKey,sizeof(char),m_CertLen,crl);
fclose(crl);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,"保存CRL成功");
m_ifCrl=false;
delete [] m_pCertKey;
}
AsyncSelect(FD_READ|FD_CLOSE|FD_WRITE);//接收完毕,继续发送、接受
CAsyncSocket::OnReceive(nErrorCode);
}
void CSslClientSocket::OnClose(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CString serverIp,str;
unsigned int port;
GetPeerName(serverIp,port);//得到用户ip,port
str.Format("%d被服务器%s断开",m_hSocket,serverIp);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(0,str,M_ERROR);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(1,str,M_ERROR);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(2,str,M_ERROR);
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(3,str,M_ERROR);
SSlShouDown();
((CMainFrame *)AfxGetMainWnd())->SetStatusIcon(IDS_STRING_STATE,IDI_ICON2);
((CMainFrame *)AfxGetMainWnd())->ShowFind(0);
CAsyncSocket::OnClose(nErrorCode);
}
void CSslClientSocket::OnSend(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
if(m_ComList.IsEmpty())
return;
stuLIST * LIST=(stuLIST *)m_ComList.RemoveHead();
int window=0;
if(SSlSend((char *)(&LIST->CA),sizeof(stuCA))>0)//发送成功
{
CString str;
switch(LIST->CA.Type)
{
case FInputD://查询待审核
str.Format("发送待审核证书查询指令成功,等待服务器回应......");
window=1;
break;
case Audit://审核证书
str.Format("发送证书%d审核申请指令成功,等待服务器回应......",LIST->ID);
window=1;
break;
case FAuditD://查询待制作:
str.Format("发送待制作证书查询指令成功,等待服务器回应......");
window=2;
break;
case Made://制作:
str.Format("发送证书%d制作申请指令成功,等待服务器回应......",LIST->ID);
window=2;
break;
case FRevokeD://查询已作废
str.Format("发送已作废证书查询指令成功,等待服务器回应......");
window=3;
break;
case FMadeD://查询已制作
str.Format("发送已制作证书查询指令成功,等待服务器回应......");
window=3;
break;
case Revoke://作废
str.Format("发送证书%d作废申请指令成功,等待服务器回应......",LIST->ID);
window=3;
break;
case MadeCrl://制作黑名单
str.Format("发送黑名单制作指令成功,等待服务器回应......");
window=3;
break;
}
((CMainFrame *)AfxGetMainWnd())->AddDialogBarInfo(window,str,M_WARING);
delete LIST;
int pos=m_ComList.GetCount();
((CMainFrame *)AfxGetMainWnd())->SetPos(pos);//进度条
}
else//失败重新加入头部
{
m_ComList.AddHead(LIST);
}
CAsyncSocket::OnSend(nErrorCode);
}
void CSslClientSocket::AddCommand(stuLIST * LIST)
{
m_ComList.AddTail((stuLIST *)LIST);
int pos=m_ComList.GetCount();
((CMainFrame *)AfxGetMainWnd())->SetPos(pos);
}
BOOL CSslClientSocket::GetComCount()
{
return m_ComList.GetCount()==0?FALSE:TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -