// NetSecurityDlg.cpp : implementation file // #include "stdafx.h" #include "netapp.h" #include "NetKeyAdd.h" #include "NetKeyEdit.h" #include "NetSecurityDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif IMPLEMENT_DYNCREATE(CNetISCLInfo, CPropertyPage) IMPLEMENT_DYNCREATE(CNetISCLAuth, CPropertyPage) IMPLEMENT_DYNCREATE(CNetISCLEncr, CPropertyPage) IMPLEMENT_DYNCREATE(CNetTLSInit, CPropertyPage) ///////////////////////////////////////////////////////////////////////////// // CNetSecurityDlg dialog CNetSecurityDlg::CNetSecurityDlg(CWnd* pParent /*=NULL*/) : CDialog(CNetSecurityDlg::IDD, pParent) { //{{AFX_DATA_INIT(CNetSecurityDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CNetSecurityDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CNetSecurityDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CNetSecurityDlg, CDialog) //{{AFX_MSG_MAP(CNetSecurityDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CNetSecurityDlg message handlers BOOL CNetSecurityDlg::OnInitDialog() { CDialog::OnInitDialog(); m_Sheet.AddPage(&m_ISCLInfo); m_ISCLAuth.m_pOwner = this; m_Sheet.AddPage(&m_ISCLAuth); m_ISCLEnc.m_pOwner = this; m_Sheet.AddPage(&m_ISCLEnc); m_TLSInit.m_pOwner = this; m_Sheet.AddPage(&m_TLSInit); m_Sheet.Create(this, WS_CHILD | WS_VISIBLE, 0); m_Sheet.ModifyStyleEx (0, WS_EX_CONTROLPARENT); m_Sheet.ModifyStyle(0, WS_TABSTOP); m_Sheet.SetWindowPos( NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE ); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } CNetISCLInfo::CNetISCLInfo() : CPropertyPage(CNetISCLInfo::IDD) { //{{AFX_DATA_INIT(CNetISCLInfo) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } CNetISCLInfo::~CNetISCLInfo() { } void CNetISCLInfo::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CNetISCLInfo) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CNetISCLInfo, CPropertyPage) //{{AFX_MSG_MAP(CNetISCLInfo) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CNetISCLInfo message handlers CNetISCLEncr::CNetISCLEncr() : CPropertyPage(CNetISCLEncr::IDD) { //{{AFX_DATA_INIT(CNetISCLEncr) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } CNetISCLEncr::~CNetISCLEncr() { } void CNetISCLEncr::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CNetISCLEncr) DDX_Control(pDX, IDC_ENC_SIGN, m_Sign); DDX_Control(pDX, IDC_ENC_KEYS, m_Keys); DDX_Control(pDX, IDC_ENC_ALG, m_Alg); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CNetISCLEncr, CPropertyPage) //{{AFX_MSG_MAP(CNetISCLEncr) ON_BN_CLICKED(IDC_ENC_GENERATE, OnEncGenerate) ON_BN_CLICKED(IDC_ENC_ADD, OnEncAdd) ON_BN_CLICKED(IDC_ENC_EDIT, OnEncEdit) ON_NOTIFY(NM_DBLCLK, IDC_ENC_KEYS, OnDblclkEncKeys) ON_WM_CLOSE() //}}AFX_MSG_MAP END_MESSAGE_MAP() BOOL CNetISCLEncr::OnInitDialog() { CPropertyPage::OnInitDialog(); // m_Keys.SetExtendedStyle(LVS_EX_FULLROWSELECT); ListView_SetExtendedListViewStyle(m_Keys.m_hWnd, LVS_EX_FULLROWSELECT); m_Alg.AddString("ISCL_ENCRYPT_NONE"); m_Alg.AddString("ISCL_ENCRYPT_DESCBC"); m_Sign.AddString("ISCL_MAC_NONE"); m_Sign.AddString("ISCL_MAC_MD5"); m_Sign.AddString("ISCL_MAC_DESMAC"); m_Keys.InsertColumn(0, "Index", LVCFMT_LEFT, 50, 0); m_Keys.InsertColumn(1, "Value", LVCFMT_LEFT, 130, 1); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CNetISCLEncr::OnEncGenerate() { L_UINT i; LV_ITEM lvi; CString szKey; CString szIndex; char szRnd[64]; m_Keys.DeleteAllItems(); for (i=0; i<8; i++) { lvi.mask = LVIF_TEXT; lvi.iItem = i; lvi.iSubItem = 0; szIndex.Format("%d", i); lvi.pszText = szIndex.GetBuffer(szIndex.GetLength()); m_Keys.InsertItem(&lvi); lvi.iSubItem = 1; _i64toa(GetRandom(), szRnd, 10); szKey = szRnd; lvi.pszText = szKey.GetBuffer(szKey.GetLength()); m_Keys.SetItem(&lvi); } } L_UINT64 CNetISCLEncr::GetRandom() { L_UINT64 nRet; nRet = ((L_UINT64)(rand())<<48) + ((L_UINT64)(rand())<<32) + (rand()<<16) + (rand()<<8) + rand(); return nRet; } void CNetISCLEncr::OnEncAdd() { LV_ITEM lvi; CString szKey; CString szIndex; CNetKeyAdd dlgAdd; if (m_Keys.GetItemCount() < 8) { dlgAdd.m_szKey = ""; if (dlgAdd.DoModal() == IDOK) { lvi.mask = LVIF_TEXT; lvi.iItem = m_Keys.GetItemCount(); lvi.iSubItem = 0; szIndex.Format("%d", m_Keys.GetItemCount()); lvi.pszText = szIndex.GetBuffer(szIndex.GetLength()); m_Keys.InsertItem(&lvi); lvi.iSubItem = 1; szKey = dlgAdd.m_szKey; lvi.pszText = szKey.GetBuffer(szKey.GetLength()); m_Keys.SetItem(&lvi); } } } void CNetISCLEncr::OnEncEdit() { CNetKeyEdit dlgEdit; L_UINT nItem; nItem = m_Keys.GetNextItem(0, LVNI_SELECTED); if (nItem != -1) { dlgEdit.m_szKey = m_Keys.GetItemText(nItem, 1); if (dlgEdit.DoModal() == IDOK) { m_Keys.SetItemText(nItem, 1, dlgEdit.m_szKey); } } } void CNetISCLEncr::OnDblclkEncKeys(NMHDR* pNMHDR, LRESULT* pResult) { CNetKeyEdit dlgEdit; L_UINT nItem; nItem = m_Keys.GetNextItem(0, LVNI_SELECTED); if (nItem != -1) { dlgEdit.m_szKey = m_Keys.GetItemText(nItem, 1); if (dlgEdit.DoModal() == IDOK) { m_Keys.SetItemText(nItem, 1, dlgEdit.m_szKey); } } *pResult = 0; } ///////////////////////////////////////////////////////////////////////////// // CNetISCLEncr message handlers CNetISCLAuth::CNetISCLAuth() : CPropertyPage(CNetISCLAuth::IDD) { //{{AFX_DATA_INIT(CNetISCLAuth) //}}AFX_DATA_INIT } CNetISCLAuth::~CNetISCLAuth() { } void CNetISCLAuth::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CNetISCLAuth) DDX_Control(pDX, IDC_AUTH_KEYS, m_Keys); DDX_Control(pDX, IDC_AUTH_ALG, m_Alg); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CNetISCLAuth, CPropertyPage) //{{AFX_MSG_MAP(CNetISCLAuth) ON_BN_CLICKED(IDC_AUTH_GEN, OnAuthGen) ON_BN_CLICKED(IDC_AUTH_ADD, OnAuthAdd) ON_BN_CLICKED(IDC_AUTH_EDIT, OnAuthEdit) ON_BN_CLICKED(IDC_AUTH_REMOVE, OnAuthRemove) ON_NOTIFY(NM_DBLCLK, IDC_AUTH_KEYS, OnDblclkAuthKeys) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CNetISCLAuth message handlers BOOL CNetISCLAuth::OnSetActive() { L_UINT i; LV_ITEM lvi; CString szKey; CString szIndex; char szRnd[64]; m_Alg.SelectString(-1, "MUTUAL_AUTH_3P4W"); m_Keys.DeleteAllItems(); for (i=0; i<8; i++) { if (m_pOwner->m_ISCLAuthKeys[i] != 0) { lvi.mask = LVIF_TEXT; lvi.iItem = i; lvi.iSubItem = 0; szIndex.Format("%d", i); lvi.pszText = szIndex.GetBuffer(szIndex.GetLength()); m_Keys.InsertItem(&lvi); lvi.iSubItem = 1; _i64toa(m_pOwner->m_ISCLAuthKeys[i], szRnd, 10); szKey = szRnd; lvi.pszText = szKey.GetBuffer(szKey.GetLength()); m_Keys.SetItem(&lvi); } } m_Keys.SetItemState(m_pOwner->m_ISCLAuthCurrentKey, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); return CPropertyPage::OnSetActive(); } BOOL CNetISCLAuth::OnInitDialog() { CPropertyPage::OnInitDialog(); // m_Keys.SetExtendedStyle(LVS_EX_FULLROWSELECT); ListView_SetExtendedListViewStyle(m_Keys.m_hWnd, LVS_EX_FULLROWSELECT); m_Alg.AddString("MUTUAL_AUTH_3P4W"); m_Keys.InsertColumn(0, "Index", LVCFMT_LEFT, 50, 0); m_Keys.InsertColumn(1, "Value", LVCFMT_LEFT, 130, 1); //m_Keys.SetItemState(m_pOwner->m_ISCLAuthCurrentKey, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CNetISCLAuth::OnAuthGen() { L_UINT i; LV_ITEM lvi; CString szKey; CString szIndex; char szRnd[64]; m_Keys.DeleteAllItems(); for (i=0; i<8; i++) { lvi.mask = LVIF_TEXT; lvi.iItem = i; lvi.iSubItem = 0; szIndex.Format("%d", i); lvi.pszText = szIndex.GetBuffer(szIndex.GetLength()); m_Keys.InsertItem(&lvi); lvi.iSubItem = 1; _i64toa(GetRandom(), szRnd, 10); szKey = szRnd; lvi.pszText = szKey.GetBuffer(szKey.GetLength()); m_Keys.SetItem(&lvi); } } L_UINT64 CNetISCLAuth::GetRandom() { L_UINT64 nRet; nRet = ((L_UINT64)(rand())<<48) + ((L_UINT64)(rand())<<32) + (rand()<<16) + (rand()<<8) + rand(); return nRet; } BOOL CNetISCLAuth::OnKillActive() { L_UINT i; CString szKey; for (i=0; i<8; i++) { szKey = m_Keys.GetItemText(i, 1); m_pOwner->m_ISCLAuthKeys[i] = _atoi64(szKey); } m_pOwner->m_ISCLAuthCurrentKey = m_Keys.GetNextItem(-1, LVNI_SELECTED); m_pOwner->m_ISCLAuthAlg = DICOM_ISCL_MUTUAL_AUTH_3P4W; return CPropertyPage::OnKillActive(); } void CNetISCLAuth::OnAuthAdd() { LV_ITEM lvi; CString szKey; CString szIndex; CNetKeyAdd dlgAdd; if (m_Keys.GetItemCount() < 8) { dlgAdd.m_szKey = ""; if (dlgAdd.DoModal() == IDOK) { lvi.mask = LVIF_TEXT; lvi.iItem = m_Keys.GetItemCount(); lvi.iSubItem = 0; szIndex.Format("%d", m_Keys.GetItemCount()); lvi.pszText = szIndex.GetBuffer(szIndex.GetLength()); m_Keys.InsertItem(&lvi); lvi.iSubItem = 1; szKey = dlgAdd.m_szKey; lvi.pszText = szKey.GetBuffer(szKey.GetLength()); m_Keys.SetItem(&lvi); } } } void CNetISCLAuth::OnAuthEdit() { CNetKeyEdit dlgEdit; L_UINT nItem; nItem = m_Keys.GetNextItem(-1, LVNI_SELECTED); if (nItem != -1) { dlgEdit.m_szKey = m_Keys.GetItemText(nItem, 1); if (dlgEdit.DoModal() == IDOK) { m_Keys.SetItemText(nItem, 1, dlgEdit.m_szKey); } } } void CNetISCLAuth::OnAuthRemove() { L_UINT nItem; nItem = m_Keys.GetNextItem(0, LVNI_SELECTED); if (nItem != -1) { } } void CNetISCLAuth::OnDblclkAuthKeys(NMHDR* pNMHDR, LRESULT* pResult) { CNetKeyEdit dlgEdit; L_UINT nItem; nItem = m_Keys.GetNextItem(-1, LVNI_SELECTED); if (nItem != -1) { dlgEdit.m_szKey = m_Keys.GetItemText(nItem, 1); if (dlgEdit.DoModal() == IDOK) { m_Keys.SetItemText(nItem, 1, dlgEdit.m_szKey); } } *pResult = 0; } CNetTLSInit::CNetTLSInit() : CPropertyPage(CNetTLSInit::IDD) { //{{AFX_DATA_INIT(CNetTLSInit) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } CNetTLSInit::~CNetTLSInit() { } void CNetTLSInit::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CNetTLSInit) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CNetTLSInit, CPropertyPage) //{{AFX_MSG_MAP(CNetTLSInit) // NOTE: the ClassWizard will add message map macros here //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CNetTLSInit message handlers void CNetSecurityDlg::OnOK() { m_Sheet.PressButton(PSBTN_OK); m_Sheet.EndDialog(IDOK); m_Sheet.DestroyWindow(); CDialog::OnOK(); } BOOL CNetISCLEncr::OnSetActive() { L_UINT i; LV_ITEM lvi; CString szKey; CString szIndex; char szRnd[64]; m_Keys.DeleteAllItems(); for (i=0; i<8; i++) { if (m_pOwner->m_ISCLEncKeys[i] != 0) { lvi.mask = LVIF_TEXT; lvi.iItem = i; lvi.iSubItem = 0; szIndex.Format("%d", i); lvi.pszText = szIndex.GetBuffer(szIndex.GetLength()); m_Keys.InsertItem(&lvi); lvi.iSubItem = 1; _i64toa(m_pOwner->m_ISCLEncKeys[i], szRnd, 10); szKey = szRnd; lvi.pszText = szKey.GetBuffer(szKey.GetLength()); m_Keys.SetItem(&lvi); } } m_Keys.SetItemState(m_pOwner->m_ISCLEncCurrentKey, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); switch (m_pOwner->m_ISCLEncAlg) { case DICOM_ISCL_ENCRYPT_NONE: { m_Alg.SelectString(-1, "ISCL_ENCRYPT_NONE"); break; } case DICOM_ISCL_ENCRYPT_DESCBC: { m_Alg.SelectString(-1, "ISCL_ENCRYPT_DESCBC"); break; } } switch (m_pOwner->m_ISCLEncSign) { case DICOM_ISCL_MAC_NONE: { m_Sign.SelectString(-1, "ISCL_MAC_NONE"); break; } case DICOM_ISCL_MAC_MD5: { m_Sign.SelectString(-1, "ISCL_MAC_MD5"); break; } case DICOM_ISCL_MAC_DESMAC: { m_Sign.SelectString(-1, "ISCL_MAC_DESMAC"); break; } } return CPropertyPage::OnSetActive(); } BOOL CNetISCLEncr::OnKillActive() { L_UINT i; CString szKey; CString szAlg; for (i=0; i<8; i++) { szKey = m_Keys.GetItemText(i, 1); m_pOwner->m_ISCLEncKeys[i] = _atoi64(szKey); } m_pOwner->m_ISCLEncCurrentKey = m_Keys.GetNextItem(-1, LVNI_SELECTED); GetDlgItemText(IDC_ENC_ALG, szAlg); if (szAlg == "ISCL_ENCRYPT_NONE") { m_pOwner->m_ISCLEncAlg = DICOM_ISCL_ENCRYPT_NONE; } if (szAlg == "ISCL_ENCRYPT_DESCBC") { m_pOwner->m_ISCLEncAlg = DICOM_ISCL_ENCRYPT_DESCBC; } GetDlgItemText(IDC_ENC_SIGN, szAlg); if (szAlg == "ISCL_MAC_NONE") { m_pOwner->m_ISCLEncSign = DICOM_ISCL_MAC_NONE; } if (szAlg == "ISCL_MAC_MD5") { m_pOwner->m_ISCLEncSign = DICOM_ISCL_MAC_MD5; } if (szAlg == "ISCL_MAC_DESMAC") { m_pOwner->m_ISCLEncSign = DICOM_ISCL_MAC_DESMAC; } return CPropertyPage::OnKillActive(); } void CNetISCLEncr::OnClose() { } BOOL CNetISCLInfo::OnInitDialog() { CPropertyPage::OnInitDialog(); CWnd *pCtrl; m_Font1.CreateFont(-18, 0, 0, 0, FW_BOLD, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Times New Roman"); m_Font2.CreateFont(-11, 0, 0, 0, FW_BOLD, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "MS Sans Serif"); pCtrl = GetDlgItem(IDC_INFO_TITLE); if (pCtrl != NULL) { pCtrl->SetFont(&m_Font1, FALSE); } pCtrl = GetDlgItem(IDC_INFO_TEXT1); if (pCtrl != NULL) { pCtrl->SetFont(&m_Font2, FALSE); } pCtrl = GetDlgItem(IDC_INFO_TEXT2); if (pCtrl != NULL) { pCtrl->SetFont(&m_Font2, FALSE); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CNetSecurityDlg::OnCancel() { /*m_Sheet.RemovePage(&m_ISCLInfo); m_Sheet.RemovePage(&m_ISCLAuth); m_Sheet.RemovePage(&m_ISCLEnc); m_Sheet.RemovePage(&m_TLSInit);*/ CDialog::OnCancel(); }