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.

1492 lines
57 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: signutil.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _SIGNUTIL_H
  11. #define _SIGNUTIL_H
  12. // OBSOLETE :- Was used for signcde.dll that is no longer required
  13. //---------------------------------------------------------------------
  14. //---------------------------------------------------------------------
  15. // SignCode.h : main header file for the SIGNCODE application
  16. //
  17. #include "wincrypt.h"
  18. #include "ossglobl.h"
  19. #include "sgnerror.h"
  20. #include "spcmem.h"
  21. #include "pvkhlpr.h"
  22. #include "spc.h"
  23. #include "wintrust.h"
  24. #include "sipbase.h"
  25. #include "mssip.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. //
  30. //+-------------------------------------------------------------------------
  31. // SPC_TIME_STAMP_REQUEST_STRUCT (placed in PKCS#7 Content for a time request)
  32. // pvStructInfo points to SPC_TIMESTAMP_REQ
  33. //
  34. typedef struct _SPC_ContentInfo {
  35. LPCSTR pszContentType;
  36. PBYTE pbContentValue;
  37. DWORD cbContentValue;
  38. } SPC_CONTENT_INFO, *PSPC_CONTENT_INFO;
  39. typedef struct _SPC_TimeStampRequest {
  40. LPCSTR pszTimeStampAlg;
  41. DWORD cAuthAttr;
  42. PCRYPT_ATTRIBUTE rgAuthAttr;
  43. SPC_CONTENT_INFO sContent;
  44. } SPC_TIMESTAMP_REQ, *PSPC_TIMESTAMP_REQ;
  45. //
  46. //+-------------------------------------------------------------------------
  47. //+------------------------------------------------------------------------------
  48. // Certificate List structures. Ordered list of Certificate contexts
  49. //
  50. typedef struct CERT_CONTEXTLIST {
  51. PCCERT_CONTEXT* psList; // List
  52. DWORD dwCount; // Number of entries in list
  53. DWORD dwList; // Max size of list
  54. } CERT_CONTEXTLIST, *PCERT_CONTEXTLIST;
  55. typedef const CERT_CONTEXTLIST *PCCERT_CONTEXTLIST;
  56. //+------------------------------------------------------------------------------
  57. // Crl List structures. Ordered list of Certificate contexts
  58. //
  59. typedef struct CRL_CONTEXTLIST {
  60. PCCRL_CONTEXT* psList; // List
  61. DWORD dwCount; // Number of entries in list
  62. DWORD dwList; // Max size of list
  63. } CRL_CONTEXTLIST, *PCRL_CONTEXTLIST;
  64. typedef const CRL_CONTEXTLIST *PCCRL_CONTEXTLIST;
  65. //+------------------------------------------------------------------------------
  66. // Capi Provider information structure (see SpcGetCapiProviders)
  67. //
  68. typedef struct CAPIPROV
  69. {
  70. TCHAR szProviderName[MAX_PATH];
  71. TCHAR szProviderDisplayName[MAX_PATH];
  72. DWORD dwProviderType;
  73. } CAPIPROV;
  74. //+-------------------------------------------------------------------------
  75. //+-------------------------------------------------------------------------
  76. // Spc utility functions
  77. //+-------------------------------------------------------------------------
  78. // Converts error (see GetLastError()) to an HRESULT
  79. //--------------------------------------------------------------------------
  80. HRESULT SpcError();
  81. //+-------------------------------------------------------------------------
  82. // SPC PKCS #7 Indirect Data Content
  83. //--------------------------------------------------------------------------
  84. BOOL
  85. WINAPI
  86. SpcGetSignedDataIndirect(
  87. IN HCRYPTPROV hCryptProv,
  88. IN DWORD dwMsgAndCertEncodingType,
  89. IN PBYTE pbSignedData,
  90. IN DWORD cbSignedData,
  91. OUT PSPC_INDIRECT_DATA_CONTENT pInfo,
  92. IN OUT DWORD *pcbInfo);
  93. //+=========================================================================
  94. //
  95. // SPC PKCS #7 Signed Message Authenticated Attributes
  96. //
  97. //-=========================================================================
  98. //+-------------------------------------------------------------------------
  99. // Create a SignedData message consisting of the certificates and
  100. // CRLs copied from the specified cert store and write to the specified file.
  101. //--------------------------------------------------------------------------
  102. BOOL
  103. WINAPI
  104. SpcWriteSpcFile(
  105. IN HANDLE hFile,
  106. IN HCERTSTORE hCertStore,
  107. IN DWORD dwMsgAndCertEncodingType,
  108. IN DWORD dwFlags);
  109. //+-------------------------------------------------------------------------
  110. // Read a SignedData message consisting of certificates and
  111. // CRLs from the specified file and copy to the specified cert store.
  112. //--------------------------------------------------------------------------
  113. BOOL
  114. WINAPI
  115. SpcReadSpcFile(
  116. IN HANDLE hFile,
  117. IN HCERTSTORE hCertStore,
  118. IN DWORD dwMsgAndCertEncodingType,
  119. IN DWORD dwFlags);
  120. //+-------------------------------------------------------------------------
  121. // Create a SignedData message consisting of the certificates and
  122. // CRLs copied from the specified cert store and write to memory
  123. //
  124. // If pbData == NULL || *pcbData == 0, calculates the length and doesn't
  125. // return an error.
  126. //
  127. // Except for the SPC being saved to memory, identical to SpcWriteSpcFile.
  128. //--------------------------------------------------------------------------
  129. BOOL
  130. WINAPI
  131. SpcWriteSpcToMemory(
  132. IN HANDLE hFile,
  133. IN HCERTSTORE hCertStore,
  134. IN DWORD dwMsgAndCertEncodingType,
  135. IN DWORD dwFlags,
  136. OUT BYTE *pbData,
  137. IN OUT DWORD *pcbData);
  138. //+-------------------------------------------------------------------------
  139. // Read a SignedData message consisting of certificates and
  140. // CRLs from memory and copy to the specified cert store.
  141. //
  142. // Except for the SPC being loaded from memory, identical to SpcReadSpcFile.
  143. //--------------------------------------------------------------------------
  144. BOOL
  145. WINAPI
  146. SpcReadSpcFromMemory(
  147. IN BYTE *pbData,
  148. IN DWORD cbData,
  149. IN HCERTSTORE hCertStore,
  150. IN DWORD dwMsgAndCertEncodingType,
  151. IN DWORD dwFlags);
  152. //+-------------------------------------------------------------------------
  153. // By default (according to the world of BOB) the SignedData doesn't have
  154. // the normal PKCS #7 ContentType at the beginning. Set the following
  155. // flag in the SpcSign* and SpcWriteSpcFile functions to include the
  156. // PKCS #7 ContentType.
  157. //
  158. // The SpcVerify* functions take SignedData with or without the PKCS #7
  159. // ContentType.
  160. //--------------------------------------------------------------------------
  161. #define SPC_PKCS_7_FLAG 0x00010000
  162. //+-------------------------------------------------------------------------
  163. // Sign Portable Executable (PE) image file where the signed data is stored
  164. // in the file.
  165. //
  166. // The signed data's IndirectDataContentAttr is updated with its type set to
  167. // SPC_PE_IMAGE_DATA_OBJID and its optional value is set to the
  168. // PeImageData parameter.
  169. //
  170. // The SPC_LENGTH_ONLY_FLAG or SPC_DISABLE_DIGEST_FILE_FLAG isn't allowed
  171. // and return an error.
  172. //--------------------------------------------------------------------------
  173. BOOL
  174. WINAPI
  175. SpcSignPeImageFile(IN PSPC_SIGN_PARA pSignPara,
  176. IN HANDLE hFile,
  177. IN OPTIONAL PSPC_PE_IMAGE_DATA pPeImageData,
  178. IN DWORD dwFlags,
  179. OUT PBYTE* pbEncoding,
  180. OUT DWORD* cbEncoding);
  181. //+-------------------------------------------------------------------------
  182. // Verify Portable Executable (PE) image file where the signed data is
  183. // extracted from the file.
  184. //
  185. // See SpcVerifyFile for details about the other parameters.
  186. //--------------------------------------------------------------------------
  187. BOOL
  188. WINAPI
  189. SpcVerifyPeImageFile(
  190. IN PSPC_VERIFY_PARA pVerifyPara,
  191. IN HANDLE hFile,
  192. IN DWORD dwFlags,
  193. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert);
  194. //+-------------------------------------------------------------------------
  195. // Sign Java class file where the signed data is stored in the file.
  196. //
  197. // The signed data's IndirectDataContentAttr is updated with its type set to
  198. // SPC_JAVA_CLASS_DATA_OBJID and its optional value is set to the
  199. // Link parameter.
  200. //
  201. // The SPC_LENGTH_ONLY_FLAG or SPC_DISABLE_DIGEST_FILE_FLAG isn't allowed
  202. // and return an error.
  203. //--------------------------------------------------------------------------
  204. BOOL
  205. WINAPI
  206. SpcSignJavaClassFile(IN PSPC_SIGN_PARA pSignPara,
  207. IN HANDLE hFile,
  208. IN OPTIONAL PSPC_LINK pLink,
  209. IN DWORD dwFlags,
  210. OUT PBYTE* pbEncoding,
  211. OUT DWORD* cbEncoding);
  212. //+-------------------------------------------------------------------------
  213. // Verify Java class file where the signed data is extracted from the file.
  214. //
  215. // See SpcVerifyFile for details about the other parameters.
  216. //--------------------------------------------------------------------------
  217. BOOL
  218. WINAPI
  219. SpcVerifyJavaClassFile(
  220. IN PSPC_VERIFY_PARA pVerifyPara,
  221. IN HANDLE hFile,
  222. IN DWORD dwFlags,
  223. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert);
  224. //+-------------------------------------------------------------------------
  225. // Sign Structured Storage file where the signed data is stored in the file.
  226. //
  227. // The signed data's IndirectDataContentAttr is updated with its type set to
  228. // SPC_STRUCTURED_STORAGE_DATA_OBJID and its optional value is set to the
  229. // Link parameter.
  230. //
  231. // The SPC_LENGTH_ONLY_FLAG or SPC_DISABLE_DIGEST_FILE_FLAG isn't allowed
  232. // and return an error.
  233. //--------------------------------------------------------------------------
  234. BOOL
  235. WINAPI
  236. SpcSignStructuredStorageFile(IN PSPC_SIGN_PARA pSignPara,
  237. IN IStorage *pStg,
  238. IN OPTIONAL PSPC_LINK pLink,
  239. IN DWORD dwFlags,
  240. OUT PBYTE* pbEncoding,
  241. OUT DWORD* cbEncoding);
  242. //+-------------------------------------------------------------------------
  243. // Verify Structured Storage file where the signed data is extracted
  244. // from the file.
  245. //
  246. // See SpcVerifyFile for details about the other parameters.
  247. //--------------------------------------------------------------------------
  248. BOOL
  249. WINAPI
  250. SpcVerifyStructuredStorageFile(
  251. IN PSPC_VERIFY_PARA pVerifyPara,
  252. IN IStorage *pStg,
  253. IN DWORD dwFlags,
  254. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  255. );
  256. //+-------------------------------------------------------------------------
  257. // Sign Raw file. The signed data is stored OUTSIDE of the file.
  258. //
  259. // The signed data's IndirectDataContentAttr is updated with its type set to
  260. // SPC_RAW_FILE_DATA_OBJID and its optional value is set to the
  261. // Link parameter.
  262. //
  263. // If pbSignedData == NULL or *pcbSignedData == 0, then, the
  264. // SPC_LENGTH_ONLY_FLAG and SPC_DISABLE_DIGEST_FILE_FLAG are implicitly set.
  265. //--------------------------------------------------------------------------
  266. BOOL
  267. WINAPI
  268. SpcSignRawFile(IN PSPC_SIGN_PARA pSignPara,
  269. IN HANDLE hFile,
  270. IN OPTIONAL PSPC_LINK pLink,
  271. IN DWORD dwFlags,
  272. OUT PBYTE *pbSignedData,
  273. IN OUT DWORD *pcbSignedData);
  274. //+-------------------------------------------------------------------------
  275. // Verify Raw file. The signed data is stored OUTSIDE of the file.
  276. //
  277. // See SpcVerifyFile for details about the other parameters.
  278. //--------------------------------------------------------------------------
  279. BOOL
  280. WINAPI
  281. SpcVerifyRawFile(
  282. IN PSPC_VERIFY_PARA pVerifyPara,
  283. IN HANDLE hFile,
  284. IN const BYTE *pbSignedData,
  285. IN DWORD cbSignedData,
  286. IN DWORD dwFlags,
  287. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  288. );
  289. //+-------------------------------------------------------------------------
  290. // Sign Diamond Cabinet (.cab) file where the signed data is stored in the
  291. // the file's cabinet header reserved data space.
  292. //
  293. // The signed data's IndirectDataContentAttr is updated with its type set to
  294. // SPC_CAB_DATA_OBJID and its optional value is set to the
  295. // Link parameter.
  296. //
  297. // The SPC_LENGTH_ONLY_FLAG or SPC_DISABLE_DIGEST_FILE_FLAG isn't allowed
  298. // and return an error.
  299. //--------------------------------------------------------------------------
  300. BOOL
  301. WINAPI
  302. SpcSignCabFile(IN PSPC_SIGN_PARA pSignPara,
  303. IN HANDLE hFile,
  304. IN OPTIONAL PSPC_LINK pLink,
  305. IN DWORD dwFlags,
  306. OUT PBYTE* pbEncoding,
  307. OUT DWORD* cbEncoding);
  308. //+-------------------------------------------------------------------------
  309. // Verify cabinet file where the signed data is extracted from the file.
  310. //
  311. // See SpcVerifyFile for details about the other parameters.
  312. //--------------------------------------------------------------------------
  313. BOOL
  314. WINAPI
  315. SpcVerifyCabFile(
  316. IN PSPC_VERIFY_PARA pVerifyPara,
  317. IN HANDLE hFile,
  318. IN DWORD dwFlags,
  319. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert);
  320. //+=========================================================================
  321. //
  322. // SPC Sign and Verify File APIs and Type Definitions
  323. //
  324. // Supports any file type via a table of functions for accessing the file.
  325. // The above file types have been implemented on top of these
  326. // sign and verify file APIs.
  327. //
  328. //-=========================================================================
  329. //+-------------------------------------------------------------------------
  330. // A convient way of setting up the SPC dll and loading the oid encode and decode
  331. // routines. Not a required call!
  332. //
  333. // Returns:
  334. // E_OUTOFMEMORY - unable to set up dll
  335. // S_OK
  336. HRESULT WINAPI
  337. SpcInitialize(DWORD dwEncodingType, // Defaults to X509_ASN_ENCODING | PKCS_7_ASN_ENCODING
  338. SpcAlloc*); // Defaults to no memory allocator
  339. HRESULT WINAPI
  340. SpcInitializeStd(DWORD dwEncodingType); // Defaults to X509_ASN_ENCODING | PKCS_7_ASN_ENCODING
  341. // Sets memory to LocalAlloc and LocalFree.
  342. ////////////////////////////////////
  343. // Helper functions
  344. /////////////////////////////////////////////////////////////////////////////
  345. // Time Stamping structures
  346. typedef struct _SPC_SignerInfo {
  347. DWORD dwVersion;
  348. CRYPT_INTEGER_BLOB sSerialNumber;
  349. CERT_NAME_BLOB sIssuer;
  350. PCRYPT_ALGORITHM_IDENTIFIER psDigestEncryptionAlgorithm;
  351. PCRYPT_ALGORITHM_IDENTIFIER psDigestAlgorithm;
  352. DWORD cAuthAttr;
  353. PCRYPT_ATTRIBUTE rgAuthAttr;
  354. DWORD cUnauthAttr;
  355. PCRYPT_ATTRIBUTE rgUnauthAttr;
  356. PBYTE pbEncryptedDigest;
  357. DWORD cbEncryptedDigest;
  358. } SPC_SIGNER_INFO, *PSPC_SIGNER_INFO;
  359. //+------------------------------------------------------------------------------
  360. // Checks if the certificate is self signed.
  361. // Returns: S_FALSE - certificate is not self signed
  362. // NTE_BAD_SIGNATURE - self signed certificate but signature is invalid
  363. // S_OK - certificate is self signed and signature is valid
  364. // CRYPT_E_NO_PRVOIDER - no provider supplied
  365. //
  366. HRESULT WINAPI
  367. SpcSelfSignedCert(IN HCRYPTPROV hCryptProv,
  368. IN PCCERT_CONTEXT pSubject);
  369. //+-----------------------------------------------------------------------------------
  370. // Checks if the certificate is the Microsoft real root or one of the test roots used
  371. // in IE30
  372. // Returns: S_OK - For the Microsoft root
  373. // S_FALSE - For the Microsoft test root
  374. // CRYPT_E_NOT_FOUND - When it is not a root certificate
  375. //
  376. HRESULT WINAPI
  377. SpcIsRootCert(PCCERT_CONTEXT pSubject);
  378. //+---------------------------------------------------------------------------
  379. // Checks if the certificate a glue certificate
  380. // in IE30
  381. // Returns: S_OK - Is a glue certificate
  382. // S_FALSE - Not a certificate
  383. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  384. HRESULT WINAPI
  385. SpcIsGlueCert(IN PCCERT_CONTEXT pCert);
  386. //+--------------------------------------------------------------------
  387. // Gets the list of providers, pass in the address to a CAPIPROV
  388. // structer and a long.
  389. // ppsList - Vector of CAPIPROV (free pointer using the SpcAllocator)
  390. // pdwEntries - number of entries in the vector.
  391. //----------------------------------------------------------------------
  392. HRESULT WINAPI
  393. SpcGetCapiProviders(CAPIPROV** ppsList,
  394. DWORD* pdwEntries);
  395. //+-------------------------------------------------------------------
  396. // Checks the certifcate chain based on trusted roots then on glue certs
  397. // Returns:
  398. // S_OK - Cert was found and was verified at the given time
  399. // S_FALSE - Cert was found and verified to a test root
  400. // CERT_E_CHAINING - Could not be verified using trusted roots
  401. // CERT_E_EXPIRED - An issuing certificate was found but it was not currently valid
  402. //
  403. // E_OUTOFMEMORY - Memory allocation error occured
  404. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  405. HRESULT WINAPI
  406. SpcCheckTrustStore(IN HCRYPTPROV hCryptProv,
  407. IN DWORD dwVerifyFlags,
  408. IN OPTIONAL FILETIME* pTimeStamp,
  409. IN HCERTSTORE hCertStore,
  410. IN PCCERT_CONTEXT pChild,
  411. IN OPTIONAL PCCERT_CONTEXTLIST,
  412. OUT PCCERT_CONTEXT* pRoot);
  413. //+---------------------------------------------------------------------------
  414. // Checks the certifcate by finding a glue certificate and walking that chain
  415. // Returns:
  416. // S_OK - Cert was found and was verified at the given time
  417. // S_FALSE - Cert was found and verified to a test root
  418. // CERT_E_CHAINING - Could not be verified using store
  419. // CERT_E_EXPIRED - An issuing certificate was found but it was not currently valid
  420. //
  421. // E_OUTOFMEMORY - Memory allocation error occured
  422. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  423. HRESULT WINAPI
  424. SpcCheckGlueChain(IN HCRYPTPROV hCryptProv,
  425. IN DWORD dwVerifyFlags,
  426. IN OPTIONAL FILETIME* pTimeStamp,
  427. IN HCERTSTORE hCertStore,
  428. IN OPTIONAL PCCERT_CONTEXTLIST pIssuers,
  429. IN PCCERT_CONTEXT pChild);
  430. //+-------------------------------------------------------------------
  431. // Checks the certifcate chain based on trusted roots then on glue certs
  432. // Returns:
  433. // S_OK - Cert was found and was verified at the given time
  434. // S_FALSE - Cert was found and verified to a test root
  435. // CERT_E_CHAINING - Could not be verified using trusted roots
  436. //
  437. // E_OUTOFMEMORY - Memory allocation error occured
  438. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  439. HRESULT WINAPI
  440. SpcCheckCertChain(IN HCRYPTPROV hCryptProv,
  441. IN DWORD dwVerifyFlags,
  442. IN OPTIONAL FILETIME* pTimeStamp,
  443. IN HCERTSTORE hTrustedRoots,
  444. IN HCERTSTORE hCertStore,
  445. IN PCCERT_CONTEXT pChild,
  446. IN OPTIONAL PCCERT_CONTEXTLIST hChainStore,
  447. OUT PCCERT_CONTEXT* pRoot);
  448. //+--------------------------------------------------------------------------
  449. // Sign a file, optional supply a timestamp.
  450. //
  451. // Returns:
  452. //
  453. // NOTE: By default this will use CoTaskMemAlloc. Use CryptSetMemoryAlloc() to
  454. // specify a different memory model.
  455. // NOTE: Time Stamp must be an encoded pkcs7 message.
  456. HRESULT WINAPI
  457. SpcSignCode(IN HWND hwnd,
  458. IN LPCWSTR pwszFilename, // file to sign
  459. IN LPCWSTR pwszCapiProvider, // NULL if to use non default CAPI provider
  460. IN DWORD dwProviderType, // Uses default if 0
  461. IN LPCWSTR pwszPrivKey, // private key file / CAPI key set name
  462. IN LPCWSTR pwszSpc, // the credentials to use in the signing
  463. IN LPCWSTR pwszOpusName, // the name of the program to appear in
  464. IN LPCWSTR pwszOpusInfo, // the unparsed name of a link to more
  465. IN BOOL fIncludeCerts, // add the certificates to the signature
  466. IN BOOL fCommercial, // commerical signing
  467. IN BOOL fIndividual, // individual signing
  468. IN ALG_ID algidHash, // Algorithm id used to create digest
  469. IN PBYTE pbTimeStamp, // Optional
  470. IN DWORD cbTimeStamp ); // Optional
  471. //+--------------------------------------------------------------------------
  472. // Create a time stamp request. It does not actually sign the file.
  473. //
  474. // Returns:
  475. //
  476. // NOTE: By default this will use CoTaskMemAlloc. Use CryptSetMemoryAlloc() to
  477. // specify a different memory model.
  478. HRESULT WINAPI
  479. SpcTimeStampCode(IN HWND hwnd,
  480. IN LPCWSTR pwszFilename, // file to sign
  481. IN LPCWSTR pwszCapiProvider, // NULL if to use non default CAPI provider
  482. IN DWORD dwProviderType,
  483. IN LPCWSTR pwszPrivKey, // private key file / CAPI key set name
  484. IN LPCWSTR pwszSpc, // the credentials to use in the signing
  485. IN LPCWSTR pwszOpusName, // the name of the program to appear in the UI
  486. IN LPCWSTR pwszOpusInfo, // the unparsed name of a link to more info...
  487. IN BOOL fIncludeCerts,
  488. IN BOOL fCommercial,
  489. IN BOOL fIndividual,
  490. IN ALG_ID algidHash,
  491. OUT PCRYPT_DATA_BLOB sTimeRequest); // Returns result in sTimeRequest
  492. //+-------------------------------------------------------------------------
  493. // Crack a PKCS7 message and builds an encoded response. Store should
  494. // contain all the required certificates to crack the incoming message
  495. // and build the out going message.
  496. // Input:
  497. // pbEncodedMsg - encoded time stamp request.
  498. // cbEncodedMsg - length of time stamp request.
  499. //
  500. // Parameter Returns:
  501. // pbResponse - allocated response message containing the time stamp
  502. // cbResponse - length of response
  503. // Returns:
  504. // S_OK - everything worked
  505. //
  506. // E_OUTOFMEMORY - Memory allocation error occured
  507. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  508. // CRYPT_E_NO_MATCH - could not locate certificate in store
  509. HRESULT WINAPI
  510. SpcCreateTimeStampResponse(IN DWORD dwCertEncodingType,
  511. IN HCRYPTPROV hSignProv,
  512. IN HCERTSTORE hCertStore,
  513. IN DWORD dwAlgId,
  514. IN OPTIONAL FILETIME* pFileTime,
  515. IN PBYTE pbEncodedMsg,
  516. IN DWORD cbEncodedMsg,
  517. OUT PBYTE* pbResponse,
  518. OUT DWORD* cbResponse);
  519. //+-------------------------------------------------------------------------
  520. // Creates PKCS7 message using the information supplied
  521. // Parameter Returns:
  522. // pbPkcs7 - allocated pkcs7 message containing the time stamp
  523. // cbPkcs7 - length of pkcs7
  524. // Returns:
  525. // S_OK - everything worked
  526. //
  527. // E_OUTOFMEMORY - Memory allocation error occured
  528. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  529. HRESULT WINAPI
  530. SpcCreatePkcs7(IN DWORD dwCertEncodingType,
  531. IN HCRYPTPROV hCryptProv, // if Null it will get provider from signing certificate
  532. IN DWORD dwKeySpec, // if 0 it will get signing key type from signing certificate
  533. IN PCCERT_CONTEXT pSigningCert,
  534. IN CRYPT_ALGORITHM_IDENTIFIER dwDigestAlgorithm,
  535. IN OPTIONAL PCCERT_CONTEXTLIST pCertList,
  536. IN OPTIONAL PCRL_CONTEXTLIST pCrlList,
  537. IN OPTIONAL PCRYPT_ATTRIBUTE rgAuthAttr,
  538. IN OPTIONAL DWORD cAuthAttr,
  539. IN OPTIONAL PCRYPT_ATTRIBUTE rgUnauthAttr,
  540. IN OPTIONAL DWORD cUnauthAttr,
  541. IN LPCSTR pszContentType,
  542. IN PBYTE pbSignerData,
  543. IN DWORD cbSignerData,
  544. OUT PBYTE* pbPkcs7,
  545. OUT DWORD* pcbPkcs7);
  546. //+--------------------------------------------------------------------------
  547. // Retrieve the signature from an encoded PKCS7 message.
  548. //
  549. // Returns:
  550. //
  551. // Note: Returns the signature of the first signer.
  552. HRESULT WINAPI
  553. SpcGetSignature(IN PBYTE pbMessage, // Pkcs7 Message
  554. IN DWORD cbMessage, // length of Message
  555. OUT PCRYPT_DATA_BLOB); // Signature returned.
  556. //+--------------------------------------------------------------------------
  557. // Returns the content value from within a timestamp request.
  558. //
  559. // Returns:
  560. // S_OK - Success
  561. //
  562. // Note: By default this will use CoTaskMemAlloc. Use CryptSetMemoryAlloc() to specify
  563. // a different allocation routine
  564. HRESULT WINAPI
  565. SpcGetTimeStampContent(IN PBYTE pbEncoding, // Pkcs7 Message
  566. IN DWORD cbEncoding, // length of Message
  567. OUT PCRYPT_DATA_BLOB pSig); // Time Stamped Data
  568. //+--------------------------------------------------------------------------
  569. // Returns: the type of file
  570. //
  571. // Note: See defines for the type returned
  572. DWORD WINAPI
  573. SpcGetFileType(LPCWSTR pszFile);
  574. #define SIGN_FILE_IMAGE 1
  575. #define SIGN_FILE_JAVACLASS 2
  576. #define SIGN_FILE_RAW 4
  577. #define SIGN_FILE_CAB 8
  578. //+---------------------------------------------------------------
  579. //+---------------------------------------------------------------
  580. // SignCode Internal OID's and structurs
  581. // Global values
  582. #define EMAIL_OID "1.2.840.113549.1.9.1"
  583. // Not implemented
  584. #define CONTENT_TYPE_OID "1.2.840.113549.1.9.3"
  585. // Uses a LPSTR
  586. #define MESSAGE_DIGEST_OID "1.2.840.113549.1.9.4"
  587. // Not implemented
  588. #define SIGNING_TIME_OID "1.2.840.113549.1.9.5"
  589. // Structure passed in and out is FILETIME
  590. #define COUNTER_SIGNATURE_OID "1.2.840.113549.1.9.6"
  591. // Not implemented
  592. #define DIRECTORY_STRING_OID "2.5.4.4"
  593. // Not implemented (see Printable and Wide versions below)
  594. // OID functions
  595. #define OID_BASE 101
  596. #define TIMESTAMP_REQUEST_SPCID 101
  597. // Uses TimeStampRequest structure
  598. #define WIDE_DIRECTORY_STRING_SPCID 102
  599. // Structure is LPWSTR
  600. #define PRINTABLE_DIRECTORY_STRING_SPCID 103
  601. // Structure is LPSTR
  602. #define IA5_STRING_SPCID 104
  603. // Structure is LPSTR
  604. #define OCTET_STRING_SPCID 105
  605. // Structure is CRYPT_DATA_BLOB
  606. #define CONTENT_INFO_SPCID 106
  607. // Structure is SPC_CONTENT_INFO
  608. #define SIGNING_TIME_SPCID 107
  609. // Structure is a SPC_SIGNER_INFO
  610. #define SIGNER_INFO_SPCID 108
  611. // Structure is a SPC_SIGNER_INFO
  612. #define ATTRIBUTES_SPCID 109
  613. // Structure is a CMSG_ATTR
  614. #define OBJECTID_SPCID 110
  615. // Structure is a LPTSTR
  616. #define CONTENT_TYPE_SPCID 111
  617. // Structure is a LPTSTR
  618. #define ATTRIBUTE_TYPE_SPCID 112
  619. // Structure is a CRYPT_ATTRIBUTE
  620. HRESULT WINAPI
  621. SpcEncodeOid(IN DWORD dwAlgorithm,
  622. IN const void *pStructure,
  623. OUT PBYTE* ppsEncoding,
  624. IN OUT DWORD* pdwEncoding);
  625. HRESULT WINAPI
  626. SpcDecodeOid(IN DWORD dwAlgorithm,
  627. IN const PBYTE psEncoding,
  628. IN DWORD dwEncoding,
  629. IN DWORD dwFlags,
  630. OUT LPVOID* ppStructure,
  631. IN OUT DWORD* pdwStructure);
  632. //+-------------------------------------------------------------------
  633. // Pushes a certificate on the list, ONLY use SpcDeleteCertChain to free
  634. // up certificate list.
  635. // Returns:
  636. // S_OK
  637. HRESULT WINAPI
  638. SpcPushCertChain(IN PCCERT_CONTEXT pCert,
  639. IN PCCERT_CONTEXTLIST pIssuer);
  640. //+-------------------------------------------------------------------
  641. // Frees up a list of cert contexts
  642. // Returns:
  643. // S_OK
  644. HRESULT WINAPI
  645. SpcDeleteCertChain(IN PCCERT_CONTEXTLIST sIssuer);
  646. //+--------------------------------------------------------------------------
  647. // Creates a list of glue certs that apply to the pSubject. If the crypt memory
  648. // allocator is set it will return a list that must be freed. (Returned memory
  649. // is a vector so free just the returned pointer) If there is no allocator then
  650. // use the two pass win32 style. (NOTE: PCCERT_CONTEXTLIST must be supplied)
  651. //
  652. // Parameter Returns:
  653. // pGlue - List of cert contexts that must be released.
  654. //
  655. // Returns:
  656. // S_OK - Created list
  657. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  658. // E_OUTOFMEMORY - Memory allocation error occured
  659. HRESULT WINAPI
  660. SpcFindGlueCerts(IN PCCERT_CONTEXT pSubject,
  661. IN HCERTSTORE hCertStore,
  662. IN OUT PCCERT_CONTEXTLIST pGlue);
  663. //+-------------------------------------------------------------------
  664. // Locate the issuers in the trusted list. (NOTE: PCCERT_CONTEXTLIST must be supplied)
  665. // Parameter Returns:
  666. // pIssuerChain - List of cert contexts that must be released.
  667. //
  668. // Returns:
  669. // S_OK - Created list
  670. // E_OUTOFMEMORY - Memory allocation error occured
  671. HRESULT WINAPI
  672. SpcLocateIssuers(IN DWORD dwVerifyFlags,
  673. IN HCERTSTORE hCertStore,
  674. IN PCCERT_CONTEXT item,
  675. IN OUT PCCERT_CONTEXTLIST pIssuerChain);
  676. //+-------------------------------------------------------------------------
  677. // Find the the cert from the hprov
  678. // Parameter Returns:
  679. // pReturnCert - context of the cert found (must pass in cert context);
  680. // Returns:
  681. // S_OK - everything worked
  682. // E_OUTOFMEMORY - memory failure
  683. // E_INVALIDARG - no pReturnCert supplied
  684. // CRYPT_E_NO_MATCH - could not locate certificate in store
  685. //
  686. HRESULT WINAPI
  687. SpcGetCertFromKey(IN DWORD dwCertEncodingType,
  688. IN HCERTSTORE hStore,
  689. IN HCRYPTPROV hProv,
  690. IN OUT PCCERT_CONTEXT* pReturnCert);
  691. /*
  692. //+-------------------------------------------------------------------------
  693. // Locates a certificate in the store that matches the public key
  694. // dictated by the HCRYPTPROV
  695. //-=========================================================================
  696. PCCERT_CONTEXT WINAPI
  697. SpcFindCert(IN HCERTSTORE hStore,
  698. IN HCRYPTPROV hProv);
  699. */
  700. //+-------------------------------------------------------------------
  701. // Retrieves the a cert context from the store based on the issuer
  702. // and serial number.
  703. // Returns:
  704. // Cert context - on success
  705. // NULL - if no certificate existed or on Error
  706. //
  707. /*
  708. PCCERT_CONTEXT WINAPI
  709. SpcFindCertWithIssuer(IN DWORD dwCertEncodingType,
  710. IN HCERTSTORE hCertStore,
  711. IN CERT_NAME_BLOB* psIssuer,
  712. IN CRYPT_INTEGER_BLOB* psSerial);
  713. */
  714. //+-------------------------------------------------------------------------
  715. // Given a signing cert, a store with the certs chain, hashing algorithm,
  716. // and a time request structure it will return an encoded time stamp request
  717. // message.
  718. // Parameter Returns:
  719. // pbEncoding - time stamp response (PKCS7 message)
  720. // cbEncoding - length of encoding
  721. // Returns:
  722. // S_OK - everything worked
  723. //
  724. // E_OUTOFMEMORY - Memory allocation error occured
  725. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  726. HRESULT WINAPI
  727. SpcBuildTimeStampResponse(IN HCRYPTPROV hCryptProv,
  728. IN HCERTSTORE hCertStore,
  729. IN PCCERT_CONTEXT pSigningCert,
  730. IN ALG_ID algidHash,
  731. IN OPTIONAL FILETIME* pFileTime,
  732. IN PSPC_TIMESTAMP_REQ psRequest,
  733. OUT PBYTE* pbEncoding,
  734. OUT DWORD* cbEncoding);
  735. //+-------------------------------------------------------------------------
  736. // Encodes the current time
  737. // Parameter Returns:
  738. // pbEncodedTime - encoded time (current UTC time)
  739. // cbEncodedTime - length of encoding
  740. // Returns:
  741. // S_OK - everything worked
  742. //
  743. // E_OUTOFMEMORY - Memory allocation error occured
  744. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  745. HRESULT WINAPI
  746. SpcEncodeCurrentTime(OUT PBYTE* pbEncodedTime,
  747. OUT DWORD* cbEncodedTime);
  748. //+-------------------------------------------------------------------------
  749. // Crack a PKCS7 message returns the content and content type. Data is verified
  750. //
  751. // Parameter Returns:
  752. // pSignerCert - Context that was used to sign the certificate
  753. // ppbContent - the content of the message
  754. // pcbContent - the length
  755. // pOid - the oid of the content (content type)
  756. // Returns:
  757. // S_OK - everything worked
  758. //
  759. // CERT_E_NOT_FOUND - Cannot load certificate from encoded pkcs7 message
  760. // E_OUTOFMEMORY - Memory allocation error occured
  761. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  762. HRESULT WINAPI
  763. SpcLoadData(IN HCRYPTPROV hCryptProv,
  764. IN PBYTE pbEncoding,
  765. IN DWORD cbEncoding,
  766. IN DWORD lSignerIndex,
  767. OUT PCCERT_CONTEXT& pSignerCert,
  768. OUT PBYTE& pbContent,
  769. OUT DWORD& cbContent,
  770. OUT LPSTR& pOid);
  771. //+-------------------------------------------------------------------------
  772. // Crack a PKCS7 message which contains a time request
  773. // Parameter Returns:
  774. // ppCertContext - returns contexts if pointer provided (optional)
  775. // ppbRequest - allocates a Time request structure (delete just the pointer)
  776. // Returns:
  777. // S_OK - everything worked
  778. //
  779. // CERT_E_NOT_FOUND - Cannot load certificate from encoded pkcs7 message
  780. // E_OUTOFMEMORY - Memory allocation error occured
  781. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  782. HRESULT WINAPI
  783. SpcLoadTimeStamp(IN HCRYPTPROV hCryptProv,
  784. IN PBYTE pbEncoding,
  785. IN DWORD cbEncoding,
  786. OUT PCCERT_CONTEXT* ppCertContext, // Optional
  787. OUT PSPC_TIMESTAMP_REQ* ppbRequest);
  788. //+-------------------------------------------------------------------
  789. // Verifies the certifcate chain based on glue certs
  790. // Return Parameters:
  791. // pRoot - Context to the root certificate of the chain
  792. // (must be freed)
  793. // pIssuers - Stores the chain in pIssuers if it is present
  794. // Returns:
  795. // S_OK - Cert was found and was verified at the given time
  796. // S_FALSE - Cert was found and verified to a test root
  797. // CERT_E_CHAINING - Could not be verified
  798. // CERT_E_EXPIRED - An issuing certificate was found but it was not currently valid
  799. //
  800. // E_OUTOFMEMORY - Memory allocation error occured
  801. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  802. HRESULT WINAPI
  803. SpcVerifyCertChain(IN HCRYPTPROV hCryptProv,
  804. IN DWORD dwVerifyFlags,
  805. IN FILETIME* pTimeStamp,
  806. IN HCERTSTORE hCertStore,
  807. IN PCCERT_CONTEXT pChild,
  808. IN OUT OPTIONAL PCCERT_CONTEXTLIST pIssuers,
  809. OUT PCCERT_CONTEXT* pRoot);
  810. //+-------------------------------------------------------------------
  811. // Checks the certifcate chain for a glue certificate
  812. // Returns:
  813. // S_OK - Cert was found and was verified at the given time
  814. // S_FALSE - Cert was found and verified to a test root
  815. // CERT_E_CHAINING - Could not be verified using
  816. // CERT_E_EXPIRED - An issuing certificate was found but it was not currently valid
  817. //
  818. // E_OUTOFMEMORY - Memory allocation error occured
  819. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  820. HRESULT WINAPI
  821. SpcVerifyGlueChain(IN DWORD dwVerifyFlags,
  822. IN HCRYPTPROV hCryptProv,
  823. IN OPTIONAL FILETIME* pTimeStamp,
  824. IN HCERTSTORE hCertStore,
  825. IN OPTIONAL PCCERT_CONTEXTLIST pIssuers,
  826. IN PCCERT_CONTEXT pChild);
  827. //-------------------------------------------------------------------
  828. // Retrieves the a cert context from the store based on the issuer
  829. // and serial number. psIssuer and psSerial can be obtained from
  830. // the SPC_CONTENT_INFO.
  831. //
  832. // Returns:
  833. // Cert context - on success
  834. // NULL - if no certificate existed or on Error (use SpcError() to retirieve HRESULT)
  835. //
  836. PCCERT_CONTEXT WINAPI
  837. SpcGetCertFromStore(IN DWORD dwCertEncodingType,
  838. IN HCERTSTORE hCertStore,
  839. IN CERT_NAME_BLOB* psIssuer,
  840. IN CRYPT_INTEGER_BLOB* psSerial);
  841. //+---------------------------------------------------------------------------
  842. // Verifies the signer at the specified time. The psSignerInfo can be
  843. // obtained be decoding and encoded signature using SIGNER_INFO_SPCID.
  844. // Verify flags can be CERT_STORE_SIGNATURE_FLAG and/or CERT_STORE_REVOCATION_FLAG.
  845. // If pTimeStamp is present the certificate must have been valid at that time
  846. // Returns:
  847. // S_OK - Time stamp was found and verified
  848. // S_FALSE - Time stamp was found and verified to a test root
  849. // CERT_E_CHAINING - Could not be verified using tursted roots or certificate store
  850. //
  851. // E_OUTOFMEMORY - Memory allocation error occured
  852. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  853. HRESULT WINAPI
  854. SpcVerifySignerInfo(IN DWORD dwCertEncodingType,
  855. IN HCRYPTPROV hCryptProv,
  856. IN DWORD dwVerifyFlags,
  857. IN HCERTSTORE hTrustedRoots,
  858. IN HCERTSTORE hCertStore,
  859. IN PSPC_SIGNER_INFO psSignerInfo,
  860. IN LPFILETIME pTimeStamp,
  861. IN PSPC_CONTENT_INFO psData);
  862. //+-------------------------------------------------------------------------------
  863. // Verifies the encoded signature if there is a time stamp present. If there is no
  864. // time stamp the CERT_E_NO_MATCH is returned. If there is a time stamp then the
  865. // certificate and ceritifcate chain is verfified at that time.
  866. //
  867. // Verify flags can be CERT_STORE_SIGNATURE_FLAG and/or CERT_STORE_REVOCATION_FLAG.
  868. //
  869. // Parameter Returns:
  870. // psTime - Filled in time, time is set to zero on error.
  871. //
  872. // Returns:
  873. // S_OK - Time stamp was found and verified
  874. // S_FALSE - Time stamp was found and verified to a test root
  875. // CERT_E_NO_MATCH - Unable to find time stamp in signer info
  876. // CERT_E_CHAINING - Could not be verified using trusted roots or certicate store
  877. //
  878. // E_OUTOFMEMORY - Memory allocation error occured
  879. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  880. HRESULT WINAPI
  881. SpcVerifyEncodedSigner(IN DWORD dwCertEncodingType,
  882. IN HCRYPTPROV hCryptProv,
  883. IN DWORD dwVerifyFlags,
  884. IN HCERTSTORE hTrustedRoots,
  885. IN HCERTSTORE hCertStore,
  886. IN PBYTE psEncodedSigner,
  887. IN DWORD dwEncodedSigner,
  888. IN PSPC_CONTENT_INFO psData,
  889. OUT FILETIME* pReturnTime);
  890. //+-------------------------------------------------------------------
  891. // Finds a counter signature attribute (OID: COUNTER_SIGNATURE_OID ==
  892. // "1.2.840.113549.1.9.6"). The counter signature is then verified.
  893. // (see CryptVerifySignerInfo)
  894. // Parameter Returns:
  895. // psTime - Filled in time, time is set to zero on error.
  896. //
  897. // Returns:
  898. // S_OK - Time stamp was found and verified
  899. // S_FALSE - Time stamp was found and verified to a test root
  900. // CRYPT_E_NO_MATCH - Time stamp attribute could not be found
  901. //
  902. // CERT_E_CHAINING - Could not be verified using trusted roots or certicate store
  903. // E_OUTOFMEMORY - Memory allocation error occured
  904. // CRYPT_E_OSS_ERROR + Oss error - Encode or Decode error.
  905. HRESULT WINAPI
  906. SpcVerifyTimeStampAttribute(IN DWORD dwCertEncodingType,
  907. IN HCRYPTPROV hCryptProv,
  908. IN DWORD dwVerifyFlags,
  909. IN HCERTSTORE hTrustedRoots,
  910. IN HCERTSTORE hCertStore,
  911. IN PCRYPT_ATTRIBUTE psAttributes,
  912. IN DWORD dwAttributes,
  913. IN PSPC_CONTENT_INFO psData,
  914. OUT FILETIME* pReturnTime);
  915. //+-------------------------------------------------------------------------
  916. // Cracks the SignerInfo out of the PKCS7 message and returns the encoded representation.
  917. // Parameter Returns:
  918. // pbSignerData - Encoded signer info from the message.
  919. // cbSignerData - Length of the message
  920. // Returns:
  921. // TRUE - Succeeded.
  922. // FALSE - Failed.
  923. //
  924. HRESULT WINAPI
  925. SpcGetEncodedSigner(IN DWORD dwMsgAndCertEncodingType,
  926. IN HCERTSTORE hMsgCertStore,
  927. IN PCCERT_CONTEXT pSignerCert,
  928. IN PBYTE pbEncoding,
  929. IN DWORD cbEncoding,
  930. OUT PBYTE* pbSignerData,
  931. OUT DWORD* cbSignerData);
  932. //+-------------------------------------------------------------------------
  933. // Gets (and will set) the CERT_KEY_PROV_INFO_PROP_ID property for a cert
  934. // context.
  935. //+--------------------------------------------------------------------------
  936. HRESULT WINAPI
  937. SpcGetCertKeyProv(IN PCCERT_CONTEXT pCert,
  938. OUT HCRYPTPROV *phCryptProv,
  939. OUT DWORD *pdwKeySpec,
  940. OUT BOOL *pfDidCryptAcquire);
  941. //+-------------------------------------------------------------------------
  942. // Returns TRUE if message is not wrapped in a
  943. // ContentInfo.
  944. //+--------------------------------------------------------------------------
  945. BOOL WINAPI
  946. SpcNoContentWrap(IN const BYTE *pbDER,
  947. IN DWORD cbDER);
  948. //+-------------------------------------------------------------------------
  949. // Retrieves the specified parameter from the Signature. The parameter is
  950. // allocated using the SPC allocation.
  951. //
  952. // Parameter Returns:
  953. // pbData: Allocated data
  954. // cbData: size of data allocated
  955. // Returns:
  956. // S_OK - Created parameter
  957. // E_OUTOFMEMORY - Memory Allocation error
  958. //
  959. //--------------------------------------------------------------------------
  960. HRESULT SpcGetParam(IN HCRYPTMSG hMsg,
  961. IN DWORD dwParamType,
  962. IN DWORD dwIndex,
  963. OUT PBYTE& pbData,
  964. OUT DWORD& cbData);
  965. //+-------------------------------------------------------------------------
  966. // Retrieves the Signer Id from the Signature. The parameter is
  967. // allocated using the SPC allocation.
  968. //
  969. // Returns:
  970. // S_OK - Created Signer id
  971. // E_OUTOFMEMORY - Memory Allocation error
  972. //
  973. //--------------------------------------------------------------------------
  974. HRESULT SpcGetCertIdFromMsg(IN HCRYPTMSG hMsg,
  975. IN DWORD dwIndex,
  976. OUT PCERT_INFO& pSignerId);
  977. //+-------------------------------------------------------------------------
  978. //+-------------------------------------------------------------------------
  979. //+-------------------------------------------------------------------------
  980. // Certificate and CRL encoding types
  981. //+--------------------------------------------------------------------------
  982. #define CERT_OSS_ERROR 0x80093000
  983. typedef HRESULT (*SpcEncodeFunction)(const SpcAlloc* pManager,
  984. const void* pStructure,
  985. PBYTE& psEncoding,
  986. DWORD& dwEncoding);
  987. typedef HRESULT (*SpcDecodeFunction)(const SpcAlloc* pManager,
  988. const PBYTE pEncoding,
  989. DWORD dwEncoding,
  990. DWORD dwFlags,
  991. LPVOID& pStructure,
  992. DWORD& dwStructure);
  993. typedef struct _SPC_OidFuncEntry {
  994. SpcEncodeFunction pfEncode;
  995. SpcDecodeFunction pfDecode;
  996. } SPC_OidFuncEntry;
  997. //
  998. // Decode routines
  999. // #define CRYPT_DECODE_NOCOPY_FLAG 0x1
  1000. HRESULT WINAPI
  1001. SpcEncodeOid32(IN DWORD dwAlgorithm,
  1002. IN const void *pStructure,
  1003. OUT PBYTE ppsEncoding,
  1004. IN OUT DWORD* pdwEncoding);
  1005. // Win32 version of above function
  1006. HRESULT WINAPI
  1007. SpcDecodeOid32(IN DWORD dwAlgorithm,
  1008. IN const PBYTE psEncoding,
  1009. IN DWORD dwEncoding,
  1010. IN DWORD dwFlags,
  1011. OUT LPVOID ppStructure,
  1012. IN OUT DWORD* pdwStructure);
  1013. // Win32 version of above function
  1014. //+-------------------------------------------------------------------
  1015. // Asn routines, Uses specified memory allocator or Win32 dual call
  1016. // if no allocator set.
  1017. typedef OssGlobal *POssGlobal;
  1018. HRESULT WINAPI
  1019. SpcASNEncode(IN const SpcAlloc* pManager,
  1020. IN POssGlobal pOssGlobal,
  1021. IN DWORD pdu,
  1022. IN const void* sOssStructure,
  1023. OUT PBYTE& psEncoding,
  1024. OUT DWORD& dwEncoding);
  1025. HRESULT WINAPI
  1026. SpcASNDecode(IN POssGlobal pOssGlobal,
  1027. IN DWORD pdu,
  1028. IN const PBYTE psEncoding,
  1029. IN DWORD dwEncoding,
  1030. IN DWORD dwFlags,
  1031. OUT LPVOID& psStructure);
  1032. //+-------------------------------------------------------------------
  1033. // Memory Functions
  1034. HRESULT WINAPI
  1035. SpcSetMemoryAlloc(SpcAlloc& pAlloc);
  1036. const SpcAlloc* WINAPI
  1037. SpcGetMemoryAlloc();
  1038. BOOL WINAPI
  1039. SpcGetMemorySet();
  1040. BOOL WINAPI
  1041. SpcSetMemoryAllocState(BOOL state);
  1042. HRESULT WINAPI
  1043. SpcSetEncodingType(DWORD type);
  1044. HRESULT WINAPI
  1045. SpcGetEncodingType(DWORD* type);
  1046. //+-------------------------------------------------------------------
  1047. // Time Stamp functions
  1048. HRESULT WINAPI
  1049. SpcCompareTimeStamps(IN PBYTE psTime1,
  1050. IN DWORD dwTime1,
  1051. IN PBYTE psTime2,
  1052. IN DWORD dwTime2);
  1053. HRESULT WINAPI
  1054. SpcCreateTimeStampHash(IN HCRYPTPROV hCryptProv,
  1055. IN DWORD dwAlgoCAPI,
  1056. IN PBYTE pbData,
  1057. IN DWORD cbData,
  1058. OUT HCRYPTHASH& hHash);
  1059. HRESULT WINAPI
  1060. SpcGetTimeStampHash(IN HCRYPTPROV hCryptProv,
  1061. IN DWORD dwAlgoCAPI,
  1062. IN PBYTE pbData,
  1063. IN DWORD cbData,
  1064. OUT PBYTE& pbHashValue,
  1065. IN OUT DWORD& cbHashValue);
  1066. HRESULT WINAPI
  1067. SpcTimeStampHashContent(IN HCRYPTPROV hCryptProv,
  1068. IN SPC_CONTENT_INFO& sContent,
  1069. IN SPC_SIGNER_INFO& sTimeStamp,
  1070. OUT PBYTE& pbHashValue,
  1071. IN OUT DWORD& cbHashValue);
  1072. HRESULT WINAPI
  1073. SpcVerifyTimeStampSignature(IN HCRYPTPROV hCryptProv,
  1074. IN CERT_INFO& sCertInfo,
  1075. IN SPC_SIGNER_INFO& sTimeStamp);
  1076. HRESULT WINAPI
  1077. SpcVerifyTimeStampDigest(IN HCRYPTPROV hCryptProv,
  1078. IN SPC_CONTENT_INFO& sContent,
  1079. IN SPC_SIGNER_INFO& sTimeStamp);
  1080. HRESULT WINAPI
  1081. SpcVerifyTimeStamp(IN HCRYPTPROV hCryptProv,
  1082. IN CERT_INFO& sCertInfo,
  1083. IN SPC_CONTENT_INFO& sContent,
  1084. IN SPC_SIGNER_INFO& sTimeStamp);
  1085. HRESULT SpcError();
  1086. //+-------------------------------------------------------------------
  1087. // String functions
  1088. HRESULT WINAPI
  1089. SpcCopyPrintableString(const SpcAlloc* pManager,
  1090. LPCSTR sz,
  1091. LPSTR& str,
  1092. DWORD& lgth);
  1093. BOOL WINAPI
  1094. SpcIsPrintableStringW(LPCWSTR wsz);
  1095. BOOL WINAPI
  1096. SpcIsPrintableString(LPCSTR sz);
  1097. HRESULT WINAPI
  1098. SpcWideToPrintableString(const SpcAlloc* psManager,
  1099. LPCWSTR wsz,
  1100. LPSTR& pString,
  1101. DWORD& dwString);
  1102. HRESULT WINAPI
  1103. SpcPrintableToWideString(const SpcAlloc* psManager,
  1104. LPCSTR sz,
  1105. LPWSTR& psString,
  1106. DWORD& dwString);
  1107. HRESULT WINAPI
  1108. SpcBMPToWideString(const SpcAlloc* psManager,
  1109. WORD* pbStr,
  1110. DWORD cbStr,
  1111. LPWSTR& psString,
  1112. DWORD& dwString);
  1113. HRESULT WINAPI
  1114. SpcBMPToPrintableString(const SpcAlloc* psManager,
  1115. WORD* pbStr,
  1116. DWORD cbStr,
  1117. LPSTR& psString,
  1118. DWORD& dwString);
  1119. HRESULT WINAPI
  1120. SpcUniversalToWideString(const SpcAlloc* psManager,
  1121. DWORD* pbStr,
  1122. USHORT cbStr,
  1123. LPWSTR& psString,
  1124. DWORD& dwString);
  1125. HRESULT WINAPI
  1126. SpcWideToUniversalString(const SpcAlloc* psManager,
  1127. LPWSTR pSource,
  1128. DWORD* pString,
  1129. DWORD& dwString);
  1130. HRESULT WINAPI
  1131. SpcPrintableToUniversalString(const SpcAlloc* psManager,
  1132. LPSTR pSource,
  1133. DWORD* pString,
  1134. DWORD& dwString);
  1135. HRESULT WINAPI
  1136. SpcUniversalToPrintableString(const SpcAlloc* psManager,
  1137. DWORD* pbStr,
  1138. USHORT cbStr,
  1139. LPSTR& psString,
  1140. DWORD& dwString);
  1141. //+-------------------------------------------------------------------
  1142. // Asn functions
  1143. HRESULT WINAPI
  1144. SpcASNEncodeTimeStamp(IN const SpcAlloc* pManager,
  1145. IN const void* pStructure,
  1146. OUT PBYTE& psEncoding,
  1147. IN OUT DWORD& dwEncoding);
  1148. HRESULT WINAPI
  1149. SpcASNDecodeTimeStamp(IN const SpcAlloc* pManager,
  1150. IN const PBYTE psEncoding,
  1151. IN DWORD dwEncoding,
  1152. IN DWORD dwFlags,
  1153. OUT LPVOID& psStructure,
  1154. IN OUT DWORD& dwStructure);
  1155. HRESULT WINAPI
  1156. SpcASNEncodeObjectId(IN const SpcAlloc* pManager,
  1157. IN const void* pStructure,
  1158. OUT PBYTE& psEncoding,
  1159. IN OUT DWORD& dwEncoding);
  1160. HRESULT
  1161. SpcASNDecodeObjectId(IN const SpcAlloc* pManager,
  1162. IN const PBYTE psEncoding,
  1163. IN DWORD dwEncoding,
  1164. IN DWORD dwFlags,
  1165. OUT LPVOID& psStructure,
  1166. IN OUT DWORD& dwStructure);
  1167. HRESULT WINAPI
  1168. SpcASNEncodeDirectoryString(IN const SpcAlloc* pManager,
  1169. const void* psData,
  1170. PBYTE& pEncoding,
  1171. DWORD& dwEncoding);
  1172. HRESULT WINAPI
  1173. SpcASNDecodeDirectoryString(IN const SpcAlloc* pManager,
  1174. IN const PBYTE psEncoding,
  1175. IN DWORD dwEncoding,
  1176. IN DWORD dwFlags,
  1177. OUT LPVOID& psString,
  1178. IN OUT DWORD& dwString);
  1179. HRESULT WINAPI
  1180. SpcASNEncodeDirectoryStringW(IN const SpcAlloc* pManager,
  1181. const void* psData,
  1182. PBYTE& pEncoding,
  1183. DWORD& dwEncoding);
  1184. HRESULT WINAPI
  1185. SpcASNDecodeDirectoryStringW(IN const SpcAlloc* pManager,
  1186. IN const PBYTE psEncoding,
  1187. IN DWORD dwEncoding,
  1188. IN DWORD dwFlags,
  1189. OUT LPVOID& psString,
  1190. IN OUT DWORD& dwString);
  1191. HRESULT WINAPI
  1192. SpcASNEncodeOctetString(IN const SpcAlloc* pManager,
  1193. IN const void* pStructure,
  1194. OUT PBYTE& psEncoding,
  1195. IN OUT DWORD& dwEncoding);
  1196. HRESULT WINAPI
  1197. SpcASNDecodeOctetString(IN const SpcAlloc* pManager,
  1198. IN const PBYTE psEncoding,
  1199. IN DWORD dwEncoding,
  1200. IN DWORD dwFlags,
  1201. OUT LPVOID& psStructure,
  1202. IN OUT DWORD& dwStructure);
  1203. HRESULT WINAPI
  1204. SpcASNEncodeAttributes(IN const SpcAlloc* pManager,
  1205. IN const void* pStructure,
  1206. OUT PBYTE& psEncoding,
  1207. IN OUT DWORD& dwEncoding);
  1208. HRESULT WINAPI
  1209. SpcASNDecodeAttributes(IN const SpcAlloc* pManager,
  1210. IN const PBYTE psEncoding,
  1211. IN DWORD dwEncoding,
  1212. IN DWORD dwFlags,
  1213. OUT LPVOID& psStructure,
  1214. IN OUT DWORD& dwStructure);
  1215. HRESULT WINAPI
  1216. SpcASNEncodeIA5String(IN const SpcAlloc* pManager,
  1217. IN const void* pStructure,
  1218. OUT PBYTE& psEncoding,
  1219. IN OUT DWORD& dwEncoding);
  1220. HRESULT WINAPI
  1221. SpcASNDecodeIA5String(IN const SpcAlloc* pManager,
  1222. IN const PBYTE psEncoding,
  1223. IN DWORD dwEncoding,
  1224. IN DWORD dwFlags,
  1225. OUT LPVOID& psStructure,
  1226. IN OUT DWORD& dwStructure);
  1227. HRESULT WINAPI
  1228. SpcASNEncodeTimeRequest(IN const SpcAlloc* pManager,
  1229. IN const void* pStructure,
  1230. OUT PBYTE& psEncoding,
  1231. IN OUT DWORD& dwEncoding);
  1232. HRESULT WINAPI
  1233. SpcASNDecodeTimeRequest(IN const SpcAlloc* pManager,
  1234. IN const PBYTE psEncoding,
  1235. IN DWORD dwEncoding,
  1236. IN DWORD dwFlags,
  1237. OUT LPVOID& psStructure,
  1238. IN OUT DWORD& dwStructure);
  1239. HRESULT WINAPI
  1240. SpcASNEncodeSignerInfo(IN const SpcAlloc* pManager,
  1241. IN const void* pStructure,
  1242. OUT PBYTE& psEncoding,
  1243. IN OUT DWORD& dwEncoding);
  1244. HRESULT WINAPI
  1245. SpcASNDecodeSignerInfo(IN const SpcAlloc* pManager,
  1246. IN const PBYTE psEncoding,
  1247. IN DWORD dwEncoding,
  1248. IN DWORD dwFlags,
  1249. OUT LPVOID& psStructure,
  1250. IN OUT DWORD& dwStructure);
  1251. HRESULT WINAPI
  1252. SpcASNEncodeContentInfo(IN const SpcAlloc* pManager,
  1253. IN const void* pStructure,
  1254. OUT PBYTE& psEncoding,
  1255. IN OUT DWORD& dwEncoding);
  1256. HRESULT WINAPI
  1257. SpcASNDecodeContentInfo(IN const SpcAlloc* pManager,
  1258. IN const PBYTE psEncoding,
  1259. IN DWORD dwEncoding,
  1260. IN DWORD dwFlags,
  1261. OUT LPVOID& psStructure,
  1262. IN OUT DWORD& dwStructure);
  1263. HRESULT WINAPI
  1264. SpcASNEncodeContentType(IN const SpcAlloc* pManager,
  1265. IN const void* pStructure,
  1266. OUT PBYTE& psEncoding,
  1267. IN OUT DWORD& dwEncoding);
  1268. HRESULT WINAPI
  1269. SpcASNDecodeContentType(IN const SpcAlloc* pManager,
  1270. IN const PBYTE psEncoding,
  1271. IN DWORD dwEncoding,
  1272. IN DWORD dwFlags,
  1273. OUT LPVOID& psStructure,
  1274. IN OUT DWORD& dwStructure);
  1275. HRESULT WINAPI
  1276. SpcASNEncodeAttribute(IN const SpcAlloc* pManager,
  1277. IN const void* pStructure,
  1278. OUT PBYTE& psEncoding,
  1279. IN OUT DWORD& dwEncoding);
  1280. HRESULT WINAPI
  1281. SpcASNDecodeAttribute(IN const SpcAlloc* pManager,
  1282. IN const PBYTE psEncoding,
  1283. IN DWORD dwEncoding,
  1284. IN DWORD dwFlags,
  1285. OUT LPVOID& psStructure,
  1286. IN OUT DWORD& dwStructure);
  1287. #ifdef __cplusplus
  1288. }
  1289. #endif
  1290. #endif