Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
5.4 KiB

  1. // mismtchd.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "keyring.h"
  5. #define SECURITY_WIN32
  6. extern "C"
  7. {
  8. #include <wincrypt.h>
  9. }
  10. #include "mismtchd.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. enum {
  17. COL_IDENTIFIER = 0,
  18. COL_CONTENT
  19. };
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CMismatchedCertDlg dialog
  22. CMismatchedCertDlg::CMismatchedCertDlg(
  23. PCERT_NAME_BLOB pRequestNameBlob,
  24. PCERT_NAME_BLOB pCertNameBlob,
  25. CWnd* pParent)
  26. : CDialog(CMismatchedCertDlg::IDD, pParent),
  27. m_pRequestNameBlob( pRequestNameBlob ),
  28. m_pCertNameBlob( pCertNameBlob )
  29. {
  30. //{{AFX_DATA_INIT(CMismatchedCertDlg)
  31. //}}AFX_DATA_INIT
  32. }
  33. void CMismatchedCertDlg::DoDataExchange(CDataExchange* pDX)
  34. {
  35. CDialog::DoDataExchange(pDX);
  36. //{{AFX_DATA_MAP(CMismatchedCertDlg)
  37. DDX_Control(pDX, IDC_LIST_REQUEST, m_clist_request);
  38. DDX_Control(pDX, IDC_LIST_CERTIFICATE, m_clist_certificate);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CMismatchedCertDlg, CDialog)
  42. //{{AFX_MSG_MAP(CMismatchedCertDlg)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CMismatchedCertDlg message handlers
  47. //----------------------------------------------------------------
  48. // override virtual oninitdialog
  49. BOOL CMismatchedCertDlg::OnInitDialog( )
  50. {
  51. // call the base oninit
  52. CDialog::OnInitDialog();
  53. // initialize the lists
  54. InitCrackerList( &m_clist_request );
  55. InitCrackerList( &m_clist_certificate );
  56. // fill in the request list
  57. FillInCrackerList( m_pRequestNameBlob, &m_clist_request );
  58. // fill in the certificate list
  59. FillInCrackerList( m_pCertNameBlob, &m_clist_certificate );
  60. // return 0 to say we set the default item
  61. // return 1 to just select the default default item
  62. return 1;
  63. }
  64. //----------------------------------------------------------------
  65. // fill in one of the info cracker lists
  66. void CMismatchedCertDlg::FillInCrackerList( PCERT_NAME_BLOB pNameBlob, CListCtrl* pList)
  67. {
  68. DWORD cch;
  69. CString szCrackedInfo;
  70. int iSemicolon;
  71. // first, use CAPI to get the required size of the string to hold the cracked info
  72. cch = CertNameToStr( X509_ASN_ENCODING, // type of encoding in the blob
  73. pNameBlob, // the name blob
  74. CERT_X500_NAME_STR|
  75. CERT_NAME_STR_SEMICOLON_FLAG|
  76. CERT_NAME_STR_NO_QUOTING_FLAG, // tell it we want the "OU" type labels
  77. NULL, // NULL because we want the size
  78. 0) + 1; // add a character for the null term
  79. // if we didn't get anything, fail
  80. if ( cch == 0 ) return;
  81. // do it again, with the right size stuff
  82. cch = CertNameToStr( X509_ASN_ENCODING, // type of encoding in the blob
  83. pNameBlob, // the name blob
  84. CERT_X500_NAME_STR|
  85. CERT_NAME_STR_SEMICOLON_FLAG|
  86. CERT_NAME_STR_NO_QUOTING_FLAG, // tell it we want the "OU" type labels
  87. szCrackedInfo.GetBuffer(cch*2), // buffer - account for DBCS
  88. cch); // size from above
  89. // let go of the name buffer
  90. szCrackedInfo.ReleaseBuffer();
  91. // if we didn't get anything, fail
  92. if ( cch == 0 ) return;
  93. // parse the name string we got back and use it to fill in the list
  94. // loop the items in the list
  95. do {
  96. // get the location of the last ";"
  97. iSemicolon = szCrackedInfo.ReverseFind( _T(';') );
  98. // if there is a semicolon, then add the string to the left of it
  99. if ( iSemicolon >= 0 )
  100. {
  101. AddOneCrackerItem( szCrackedInfo.Right(szCrackedInfo.GetLength() - (iSemicolon+1)), pList);
  102. // remove it from the list
  103. szCrackedInfo = szCrackedInfo.Left( iSemicolon );
  104. }
  105. // if there is no semicolon, then add the string
  106. else
  107. {
  108. AddOneCrackerItem( szCrackedInfo, pList);
  109. }
  110. // loop back
  111. }while ( iSemicolon >= 0);
  112. }
  113. //----------------------------------------------------------------
  114. void CMismatchedCertDlg::AddOneCrackerItem( CString& szItem, CListCtrl* pList)
  115. {
  116. // remove any fluff spaces
  117. szItem.TrimLeft();
  118. szItem.TrimRight();
  119. // get the position of the '=' character
  120. int iEqual = szItem.Find( _T('=') );
  121. // if it isn't there, fail
  122. if ( iEqual < 0 ) return;
  123. // get the identifier and content strings
  124. CString szIdent = szItem.Left( iEqual );
  125. CString szContent = szItem.Right( szItem.GetLength() - (iEqual+1) );
  126. // add the strings to the list
  127. DWORD i = pList->InsertItem( 0, szIdent );
  128. pList->SetItemText( i, COL_CONTENT, szContent );
  129. }
  130. //----------------------------------------------------------------
  131. void CMismatchedCertDlg::InitCrackerList( CListCtrl* pList)
  132. {
  133. CString sz;
  134. // prepare the list for use
  135. sz.LoadString( IDS_APP_EXTENSION );
  136. DWORD i = pList->InsertColumn( COL_IDENTIFIER, sz, LVCFMT_LEFT, 45 );
  137. sz.LoadString( IDS_APP_EXE_PATH );
  138. i = pList->InsertColumn( COL_CONTENT, sz, LVCFMT_LEFT, 176 );
  139. }