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.

206 lines
8.1 KiB

  1. //-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1997
  6. //
  7. // File: tdecode.h
  8. //
  9. // Contents: The header of tdecode.cpp. The API testing of CryptEncodeObject/CryptDecodeObject.
  10. //
  11. // History: 22-January-97 xiaohs created
  12. //
  13. //--------------------------------------------------------------------------
  14. #ifndef __TDECODE_H__
  15. #define __TDECODE_H__
  16. #include <windows.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <tchar.h>
  20. #include <assert.h>
  21. #include "wincrypt.h"
  22. #include "asn1code.h"
  23. //--------------------------------------------------------------------------
  24. // Contant Defines
  25. //--------------------------------------------------------------------------
  26. #define CRYPT_DECODE_COPY_FLAG 0
  27. #define MSG_ENCODING_TYPE PKCS_7_ASN_ENCODING|CRYPT_ASN_ENCODING
  28. #define CRYPT_ENCODE_TYPE X509_ASN_ENCODING
  29. #define LENGTH_LESS 1
  30. #define LENGTH_MORE 100
  31. #define INVALID_LPSZSTRUCTTYPE ((LPCSTR) 5000)
  32. #define CERT_CRL_FILE 0x1
  33. #define CERT_REQUEST_FILE 0x2
  34. #define SIGNED_MSG_FILE 0x4
  35. #define CERT_INFO_STRUCT 0x1
  36. #define CRL_INFO_STRUCT 0x2
  37. #define CERT_REQUEST_INFO_STRUCT 0x4
  38. #define CROW 16
  39. char szSubsystemProtocol[] = "MY";
  40. char szEncodedSizeInconsistent[] = "The two encoded BLOBs have different size!\n";
  41. char szEncodedContentInconsistent[] = "The two encoded BLOBs have different content!\n";
  42. //--------------------------------------------------------------------------
  43. // Macros
  44. //--------------------------------------------------------------------------
  45. //Macros for memory management
  46. #define SAFE_FREE(p1) {if(p1) {free(p1);p1=NULL;}}
  47. #define SAFE_ALLOC(p1) malloc(p1)
  48. #define CHECK_POINTER(pv) { if(!pv) goto TCLEANUP;}
  49. //Macros for error checking
  50. #define TESTC(rev,exp) {if(!TCHECK(rev,exp)) goto TCLEANUP; }
  51. #define TCHECK(rev,exp) (Validate(GetLastError(), (rev)==(exp), (char *)(__FILE__), __LINE__))
  52. #define TCHECKALL(rev, exp1, exp2) (Validate((DWORD) (rev), ((rev)==(exp1)||(rev)==(exp2)), (char *)(__FILE__), __LINE__))
  53. #define PROCESS_ERR(ErrMsg) {printf(ErrMsg);g_dwErrCnt++;}
  54. #define PROCESS_ERR_GOTO(ErrMsg) {PROCESS_ERR(ErrMsg); goto TCLEANUP;}
  55. //--------------------------------------------------------------------------
  56. // Inline Function
  57. //--------------------------------------------------------------------------
  58. //--------------------------------------------------------------------------
  59. // Function Prototype
  60. //--------------------------------------------------------------------------
  61. /////////////////////////////////////////////////////////////////////////////////
  62. //Error Manipulations
  63. void DisplayTestResult(DWORD dwErrCnt);
  64. BOOL Validate(DWORD dwErr, BOOL fSame, char *szFile, DWORD dwLine);
  65. static void Usage(void);
  66. void OutputError(LPCSTR lpszStructType, DWORD cbSecondEncoded, DWORD cbEncoded,
  67. BYTE *pbSecondEncoded, BYTE *pbEncoded);
  68. void PrintBytes(LPCSTR pszHdr, BYTE *pb, DWORD cbSize);
  69. ///////////////////////////////////////////////////////////////////////////////
  70. //Certificate Manipulations
  71. BOOL DecodeCertFile(LPSTR pszFileName,BOOL fStructLengthCheck,
  72. BOOL fBLOBLengthCheck);
  73. BOOL DecodeCertReqFile(LPSTR pszFileName,BOOL fStructLengthCheck,
  74. BOOL fBLOBLengthCheck);
  75. BOOL DecodeSignedMsgFile(LPSTR pszFileName, BOOL fStructLengthCheck,
  76. BOOL fBLOBLengthCheck);
  77. BOOL DecodeBLOB(LPCSTR lpszStructType,DWORD cbEncoded, BYTE *pbEncoded,
  78. DWORD dwDecodeFlags, DWORD *pcbStructInfo, void **ppvStructInfo,
  79. BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  80. BOOL EncodeStruct(LPCSTR lpszStructType, void *pStructInfo,DWORD *pcbEncoded,
  81. BYTE **ppbEncoded);
  82. BOOL EncodeAndVerify(LPCSTR lpszStructType, void *pvStructInfo, DWORD cbEncoded,
  83. BYTE *pbEncoded);
  84. BOOL DecodeX509_CERT(DWORD dwCertType,DWORD cbEncoded, BYTE *pbEncoded, DWORD dwDecodeFlags,
  85. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck,
  86. void *pInfoStruct);
  87. BOOL DecodeX509_CERT_TO_BE_SIGNED(DWORD cbEncoded, BYTE *pbEncoded, DWORD dwDecodeFlags,
  88. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck,
  89. BOOL cbExpectedEncoded, BYTE *pbExpectedEncoded);
  90. BOOL DecodeX509_CERT_REQUEST_TO_BE_SIGNED(DWORD cbEncoded, BYTE *pbEncoded, DWORD dwDecodeFlags,
  91. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck,
  92. BOOL cbExpectedEncoded, BYTE *pbExpectedEncoded);
  93. BOOL DecodeX509_CERT_CRL_TO_BE_SIGNED(DWORD cbEncoded, BYTE *pbEncoded, DWORD dwDecodeFlags,
  94. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck,
  95. BOOL cbExpectedEncoded, BYTE *pbExpectedEncoded);
  96. BOOL DecodeRSA_CSP_PUBLICKEYBLOB(DWORD cbEncoded, BYTE *pbEncoded, DWORD dwDecodeFlags,
  97. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  98. BOOL DecodePKCS_TIME_REQUEST(DWORD cbEncoded, BYTE *pbEncoded, DWORD dwDecodeFlags,
  99. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  100. BOOL DecodeX509_NAME(DWORD cbEncoded, BYTE *pbEncoded, DWORD dwDecodeFlags,
  101. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  102. BOOL DecodePKCS7_SIGNER_INFO(DWORD cbEncoded, BYTE *pbEncoded, DWORD dwDecodeFlags,
  103. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  104. BOOL DecodeX509_UNICODE_NAME(DWORD cbEncoded, BYTE *pbEncoded, DWORD dwDecodeFlags,
  105. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  106. BOOL DecodeX509_EXTENSIONS(DWORD cbEncoded, BYTE *pbEncoded, DWORD dwDecodeFlags,
  107. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  108. BOOL DecodeCertExtensions(DWORD cExtension, PCERT_EXTENSION rgExtension, DWORD dwDecodeFlags,
  109. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  110. BOOL DecodeCryptAttribute(PCRYPT_ATTRIBUTE pCryptAttribute,DWORD dwDecodeFlags,
  111. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  112. BOOL DecodeCRLEntry(PCRL_ENTRY pCrlEntry, DWORD dwDecodeFlags,
  113. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  114. BOOL DecodeBasedOnObjID(LPSTR szObjId, DWORD cbData, BYTE *pbData,
  115. DWORD dwDecodeFlags, BOOL fEncode,
  116. BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  117. BOOL DecodeCertAltNameEntry(PCERT_ALT_NAME_ENTRY pCertAltNameEntry,
  118. DWORD dwDecodeFlags, BOOL fEncode,
  119. BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  120. BOOL DecodeGenericBLOB(LPCSTR lpszStructInfo, DWORD cbEncoded, BYTE *pbEncoded, DWORD dwDecodeFlags,
  121. BOOL fEncode,BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  122. ///////////////////////////////////////////////////////////////////////////////
  123. //General Parameter Testing routines
  124. BOOL ParameterTest(LPCSTR lpszStructType, DWORD cbEncoded, BYTE *pbEncoded);
  125. BOOL MismatchTest(LPCSTR lpszStructType, DWORD cbEncoded, BYTE *pbEncoded,
  126. DWORD cbStructInfo);
  127. ///////////////////////////////////////////////////////////////////////////////
  128. //General Decode/Encode Testing routines
  129. BOOL RetrieveBLOBfromFile(LPSTR pszFileName,DWORD *pcbEncoded,BYTE **ppbEncoded);
  130. BOOL EncodeSignerInfoWAttr(PCMSG_SIGNER_INFO pSignerInfo,DWORD *pbSignerEncoded,
  131. BYTE **ppbSignerEncoded);
  132. BOOL CompareTimeStampRequest(CRYPT_TIME_STAMP_REQUEST_INFO *pReqNew,
  133. CRYPT_TIME_STAMP_REQUEST_INFO *pReqOld);
  134. BOOL VerifyAlgorithParam(PCRYPT_ALGORITHM_IDENTIFIER pAlgorithm);
  135. BOOL VerifyPKCS_UTC_TIME(BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  136. BOOL VerifyPKCS_TIME_REQUEST(BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  137. BOOL VerifyAttributes(DWORD cAttr, PCRYPT_ATTRIBUTE rgAttr,
  138. DWORD dwDecodeFlags, BOOL fEncode, BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  139. BOOL VerifyPublicKeyInfo(PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  140. DWORD dwDecodeFlags, BOOL fEncode,
  141. BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  142. BOOL VerifyCertExtensions(DWORD cExtension, PCERT_EXTENSION rgExtension,
  143. DWORD dwDecodeFlags, BOOL fEncode,
  144. BOOL fStructLengthCheck, BOOL fBLOBLengthCheck);
  145. LPCSTR MapObjID2StructType(LPSTR szObjectID);
  146. #endif // __TDECODE_H__