Leaked source code of windows server 2003
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.

172 lines
3.9 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1992 - 1992
  6. //
  7. // File: secret.cxx
  8. //
  9. // Contents: test program to check the setup of a Cairo installation
  10. //
  11. //
  12. // History: 22-Dec-92 Created MikeSw
  13. //
  14. //------------------------------------------------------------------------
  15. extern "C"
  16. {
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <ntlsa.h>
  21. #include <stdio.h>
  22. #include <windef.h>
  23. #include <winbase.h>
  24. #include <winreg.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. }
  28. void _cdecl
  29. main(int argc, char *argv[])
  30. {
  31. LPSTR KeyName;
  32. LPSTR ValueName;
  33. FILE * File;
  34. DWORD RegStatus;
  35. HKEY Key = NULL;
  36. PBYTE Buffer = NULL;
  37. ULONG Size;
  38. ULONG Type;
  39. CHAR FileName[20];
  40. ULONG Index;
  41. ULONG CertCount;
  42. CHAR NameBuffer[10];
  43. ULONG NameBufferSize;
  44. BYTE VerisignCert[] = {
  45. 0x30, 0x82, 0x02, 0x79, 0x30, 0x82, 0x01, 0xE2,
  46. 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x35,
  47. 0x11, 0xA5, 0x52, 0x90, 0x6F, 0xE7, 0xD0, 0x29,
  48. 0xA4, 0x40, 0x19, 0xD4, 0x11, 0xFC, 0x3E, 0x30
  49. };
  50. //
  51. // Open the key with the list of certificates
  52. //
  53. RegStatus = RegOpenKeyExA(
  54. HKEY_CURRENT_USER,
  55. "Software\\Microsoft\\Cryptography\\PersonalCertificates\\ClientAuth\\Certificates",
  56. 0,
  57. KEY_QUERY_VALUE,
  58. &Key
  59. );
  60. if (RegStatus != ERROR_SUCCESS)
  61. {
  62. printf("No certificates found\n");
  63. return;
  64. }
  65. //
  66. // Enumerate throught the values
  67. //
  68. CertCount = 1;
  69. for (Index = 0; ; Index++ )
  70. {
  71. NameBufferSize = sizeof(NameBuffer);
  72. RegStatus = RegEnumValueA(
  73. Key,
  74. Index,
  75. NameBuffer,
  76. &NameBufferSize,
  77. 0,
  78. &Type,
  79. NULL,
  80. &Size );
  81. if ((RegStatus != STATUS_SUCCESS) &&
  82. (RegStatus != ERROR_MORE_DATA))
  83. {
  84. break;
  85. }
  86. //
  87. // We only want binary values
  88. //
  89. if (Type != REG_BINARY)
  90. {
  91. continue;
  92. }
  93. Buffer = (PBYTE) LocalAlloc(LMEM_ZEROINIT, Size);
  94. if (Buffer == NULL)
  95. {
  96. goto Cleanup;
  97. }
  98. NameBufferSize = sizeof(NameBuffer);
  99. RegStatus = RegEnumValueA(
  100. Key,
  101. Index,
  102. NameBuffer,
  103. &NameBufferSize,
  104. 0,
  105. &Type,
  106. Buffer,
  107. &Size );
  108. if (RegStatus != ERROR_SUCCESS)
  109. {
  110. goto Cleanup;
  111. }
  112. //
  113. // Skip the verisign certificate.
  114. //
  115. if (memcmp(Buffer,VerisignCert, sizeof(VerisignCert)) == 0)
  116. {
  117. LocalFree(Buffer);
  118. Buffer = NULL;
  119. continue;
  120. }
  121. if (CertCount == 1)
  122. {
  123. sprintf(FileName,"mycerts.cer");
  124. }
  125. else
  126. {
  127. sprintf(FileName,"mycerts%d.cer",CertCount);
  128. }
  129. File = fopen(FileName,"wb");
  130. if (File == NULL)
  131. {
  132. printf("Error opening file %s\n",FileName);
  133. goto Cleanup;
  134. }
  135. fwrite(Buffer, Size, 1, File);
  136. fclose(File);
  137. LocalFree(Buffer);
  138. Buffer = NULL;
  139. CertCount++;
  140. }
  141. Cleanup:
  142. if (Key != NULL)
  143. {
  144. RegCloseKey(Key);
  145. }
  146. if (Buffer != NULL)
  147. {
  148. LocalFree(Buffer);
  149. }
  150. return;
  151. }