home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / schnlsp.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  16KB  |  529 lines

  1. //+---------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright 1992 - 1998 Microsoft Corporation.
  5. //
  6. //  File:       schnlsp.h
  7. //
  8. //  Contents:   Public Definitions for SCHANNEL Security Provider
  9. //
  10. //  Classes:
  11. //
  12. //  Functions:
  13. //
  14. //  History:    6-8-96   Created
  15. //
  16. //----------------------------------------------------------------------------
  17.  
  18. #ifndef __SCHNLSP_H__
  19. #define __SCHNLSP_H__
  20.  
  21. #include <wincrypt.h>
  22.  
  23.  
  24. #define UNISP_NAME_A    "Microsoft Unified Security Protocol Provider"
  25. #define UNISP_NAME_W    L"Microsoft Unified Security Protocol Provider"
  26.  
  27. #define SSL2SP_NAME_A    "Microsoft SSL 2.0"
  28. #define SSL2SP_NAME_W    L"Microsoft SSL 2.0"
  29.  
  30. #define SSL3SP_NAME_A    "Microsoft SSL 3.0"
  31. #define SSL3SP_NAME_W    L"Microsoft SSL 3.0"
  32.  
  33. #define TLS1SP_NAME_A    "Microsoft TLS 1.0"
  34. #define TLS1SP_NAME_W    L"Microsoft TLS 1.0"
  35.  
  36. #define PCT1SP_NAME_A    "Microsoft PCT 1.0"
  37. #define PCT1SP_NAME_W    L"Microsoft PCT 1.0"
  38.  
  39.  
  40. #ifdef UNICODE
  41.  
  42. #define UNISP_NAME  UNISP_NAME_W
  43. #define PCT1SP_NAME  PCT1SP_NAME_W
  44. #define SSL2SP_NAME  SSL2SP_NAME_W
  45. #define SSL3SP_NAME  SSL3SP_NAME_W
  46. #define TLS1SP_NAME  TLS1SP_NAME_W
  47.  
  48. #else
  49.  
  50. #define UNISP_NAME  UNISP_NAME_A
  51. #define PCT1SP_NAME  PCT1SP_NAME_A
  52. #define SSL2SP_NAME  SSL2SP_NAME_A
  53. #define SSL3SP_NAME  SSL3SP_NAME_A
  54. #define TLS1SP_NAME  TLS1SP_NAME_A
  55.  
  56. #endif
  57.  
  58. #define SSL2SP_RPC_ID    12
  59. #define PCT1SP_RPC_ID    13
  60. #define SSL3SP_RPC_ID    14
  61. #define UNISP_RPC_ID     15
  62. #define TLS1SP_RPC_ID    16
  63.  
  64.  
  65.  
  66. #define SCH_CRED_V1              0x00000001
  67. #define SCH_CRED_V2              0x00000002  // for legacy code
  68. #define SCH_CRED_VERSION         0x00000002  // for legacy code
  69. #define SCHANNEL_CRED_VERSION    0x00000003
  70.  
  71.  
  72.  
  73.  
  74. //
  75. // QueryContextAttributes/QueryCredentialsAttribute extensions
  76. //
  77. #define SECPKG_ATTR_REMOTE_CERT_CONTEXT  0x53  // returns PCCERT_CONTEXT
  78. #define SECPKG_ATTR_LOCAL_CERT_CONTEXT   0x54  // returns PCCERT_CONTEXT
  79. #define SECPKG_ATTR_ROOT_STORE           0x55  // returns HCERTCONTEXT to the root store
  80. #define SECPKG_ATTR_SUPPORTED_ALGS       0x56  // returns SecPkgCred_SupportedAlgs
  81. #define SECPKG_ATTR_CIPHER_STRENGTHS     0x57  // returns SecPkgCred_CipherStrengths
  82. #define SECPKG_ATTR_SUPPORTED_PROTOCOLS  0x58  // returns SecPkgCred_SupportedProtocols
  83. #define SECPKG_ATTR_ISSUER_LIST_EX       0x59  // returns SecPkgContext_IssuerListInfoEx
  84. #define SECPKG_ATTR_CONNECTION_INFO      0x5a  // returns SecPkgContext_ConnectionInfo
  85.  
  86.  
  87.  
  88. typedef struct _SecPkgCred_SupportedAlgs
  89. {
  90.     DWORD        cSupportedAlgs;
  91.     ALG_ID        *palgSupportedAlgs;
  92. } SecPkgCred_SupportedAlgs, *PSecPkgCred_SupportedAlgs;
  93.  
  94. typedef struct _SecPkgCred_CipherStrengths
  95. {
  96.     DWORD       dwMinimumCipherStrength;
  97.     DWORD       dwMaximumCipherStrength;
  98. } SecPkgCred_CipherStrengths, *PSecPkgCred_CipherStrengths;
  99.  
  100. typedef struct _SecPkgCred_SupportedProtocols
  101. {
  102.     DWORD          grbitProtocol;
  103. } SecPkgCred_SupportedProtocols, *PSecPkgCred_SupportedProtocols;
  104.  
  105. typedef struct _SecPkgContext_IssuerListInfoEx
  106. {
  107.     PCERT_NAME_BLOB       aIssuers;
  108.     DWORD               cIssuers;
  109. } SecPkgContext_IssuerListInfoEx, *PSecPkgContext_IssuerListInfoEx;
  110.  
  111. typedef struct _SecPkgContext_ConnectionInfo
  112. {
  113.     DWORD    dwProtocol;
  114.     ALG_ID   aiCipher;
  115.     DWORD    dwCipherStrength;
  116.     ALG_ID   aiHash;
  117.     DWORD    dwHashStrength;
  118.     ALG_ID   aiExch;
  119.     DWORD    dwExchStrength;
  120. }SecPkgContext_ConnectionInfo, *PSecPkgContext_ConnectionInfo;
  121.  
  122.  
  123. //
  124. // SCHANNEL Credentials data structure
  125. //
  126. struct _HMAPPER;
  127.  
  128. typedef struct _SCHANNEL_CRED
  129. {
  130.     DWORD           dwVersion;
  131.     DWORD           cCreds;
  132.     PCCERT_CONTEXT  *paCred; 
  133.     HCERTSTORE      hRootStore;
  134.  
  135.     DWORD            cMappers;                
  136.     struct _HMAPPER  **aphMappers;     
  137.  
  138.     DWORD           cSupportedAlgs;
  139.     ALG_ID          *palgSupportedAlgs;
  140.  
  141.     DWORD           grbitEnabledProtocols;
  142.     DWORD           dwMinimumCipherStrength;
  143.     DWORD           dwMaximumCipherStrength;
  144.     DWORD           dwSessionLifespan;
  145.  
  146. } SCHANNEL_CRED, *PSCHANNEL_CRED;
  147.  
  148.  
  149. // 
  150. //
  151. // ApplyControlToken PkgParams types
  152. //
  153. // These identifiers are the DWORD types
  154. // to be passed into ApplyControlToken
  155. // through a PkgParams buffer.
  156.  
  157. //
  158. // SCHANNEL_RENEGOTIATE
  159. //
  160. // Cause SCHANNEL to renegotiate 
  161. // a connection.
  162. //
  163. #define SCHANNEL_RENEGOTIATE 0
  164.  
  165. //
  166. // SCHANNEL_SHUTDOWN
  167. //
  168. // Cause SCHANNEL to shutdown 
  169. // a connection.
  170. //
  171.  
  172. #define SCHANNEL_SHUTDOWN    1
  173.  
  174.  
  175. //
  176. //
  177. // ADDITIONAL SCHANNEL ERROR CODES
  178. //
  179. //
  180.  
  181.  
  182. //
  183. // MessageId: SEC_I_INCOMPLETE_CREDENTIALS
  184. //
  185. // MessageText:
  186. //
  187. //  If this is returned from InitializeSecurityContext, it indicates
  188. //  that the credentials supplied were incomplete, and client-auth was
  189. //  attempted.  On receipt, the client should call QueryContextAttributes
  190. //  with SECPKG_ATTR_LOCAL_CERT to get the cert that was negotiated,
  191. //  and the supply the private key with this cert to AcquireCredential
  192. //  to get a new credential.  The context should then be closed, 
  193. //  and renegotiation should be completed.
  194. //  
  195. //
  196. #define SEC_I_INCOMPLETE_CREDENTIALS      ((HRESULT)0x00090320L)
  197.  
  198. #define SEC_E_INCOMPLETE_CREDENTIALS      ((HRESULT)0x80090320L)
  199.  
  200.  
  201. //
  202. // MessageId: SEC_I_RENEGOTIATE
  203. //
  204. // MessageText:
  205. //
  206. // This is returned by UnsealMessage, and indicates that the app should
  207. // restart the renegotiation loop.  It should use the existing context, and
  208. // pass in no data in the input buffers for the first call to AcceptSecurityContext
  209. // or InitializeSecurityContext. 
  210. //
  211. #define SEC_I_RENEGOTIATE            ((HRESULT)0x00090321L)
  212.  
  213.  
  214.  
  215. //
  216. //
  217. // ADDITIONAL SCHANNEL CERTIFICATE PROPERTIES
  218. //
  219. //
  220.  
  221.  
  222. // This property specifies the DER private key data associated with this
  223. // certificate.  It is for use with legacy IIS style private keys.
  224. //
  225. // PBYTE
  226. //
  227. #define CERT_SCHANNEL_IIS_PRIVATE_KEY_PROP_ID  (CERT_FIRST_USER_PROP_ID + 0)
  228.  
  229. // The password used to crack the private key associated with the certificate.
  230. // It is for use with legacy IIS style private keys.
  231. //
  232. // PBYTE
  233. #define CERT_SCHANNEL_IIS_PASSWORD_PROP_ID  (CERT_FIRST_USER_PROP_ID + 1)
  234.  
  235. // This is the unique ID of a Server Gated Cryptography certificate associated
  236. // with this certificate.
  237. //
  238. // CRYPT_BIT_BLOB
  239. #define CERT_SCHANNEL_SGC_CERTIFICATE_PROP_ID  (CERT_FIRST_USER_PROP_ID + 2)
  240.  
  241.  
  242.  
  243. //
  244. // Flags for identifying the various different protocols.
  245. //
  246.  
  247. /* flag/identifiers for protocols we support */
  248. #define SP_PROT_PCT1_SERVER             0x00000001
  249. #define SP_PROT_PCT1_CLIENT             0x00000002
  250. #define SP_PROT_PCT1                    (SP_PROT_PCT1_SERVER | SP_PROT_PCT1_CLIENT)
  251.  
  252. #define SP_PROT_SSL2_SERVER             0x00000004
  253. #define SP_PROT_SSL2_CLIENT             0x00000008
  254. #define SP_PROT_SSL2                    (SP_PROT_SSL2_SERVER | SP_PROT_SSL2_CLIENT)
  255.  
  256. #define SP_PROT_SSL3_SERVER             0x00000010
  257. #define SP_PROT_SSL3_CLIENT             0x00000020
  258. #define SP_PROT_SSL3                    (SP_PROT_SSL3_SERVER | SP_PROT_SSL3_CLIENT)
  259.  
  260. #define SP_PROT_TLS1_SERVER             0x00000040
  261. #define SP_PROT_TLS1_CLIENT             0x00000080
  262. #define SP_PROT_TLS1                    (SP_PROT_TLS1_SERVER | SP_PROT_TLS1_CLIENT)
  263.  
  264. #define SP_PROT_SSL3TLS1_CLIENTS        (SP_PROT_TLS1_CLIENT | SP_PROT_SSL3_CLIENT)
  265. #define SP_PROT_SSL3TLS1_SERVERS        (SP_PROT_TLS1_SERVER | SP_PROT_SSL3_SERVER)
  266. #define SP_PROT_SSL3TLS1                (SP_PROT_SSL3 | SP_PROT_TLS1)
  267.  
  268. #define SP_PROT_UNI_SERVER              0x40000000
  269. #define SP_PROT_UNI_CLIENT              0x80000000
  270. #define SP_PROT_UNI                     (SP_PROT_UNI_SERVER | SP_PROT_UNI_CLIENT)
  271.  
  272. #define SP_PROT_ALL                     0xffffffff
  273. #define SP_PROT_ALL_NOT_TLS             (SP_PROT_PCT1 | SP_PROT_SSL2 | SP_PROT_SSL3)
  274. #define SP_PROT_NONE                    0
  275. #define SP_PROT_CLIENTS                 (SP_PROT_PCT1_CLIENT | SP_PROT_SSL2_CLIENT | SP_PROT_SSL3_CLIENT | SP_PROT_UNI_CLIENT | SP_PROT_TLS1_CLIENT)
  276. #define SP_PROT_SERVERS                 (SP_PROT_PCT1_SERVER | SP_PROT_SSL2_SERVER | SP_PROT_SSL3_SERVER | SP_PROT_UNI_SERVER | SP_PROT_TLS1_SERVER)
  277.  
  278.  
  279. // A call for IIS to empty the cache.
  280.  
  281. BOOL
  282. SslEmptyCache(VOID);
  283.  
  284. //
  285. //
  286. //  Support for legacy applications
  287. //  NOTE: Do not use the following 
  288. //  API's and structures for new code.
  289. //
  290.  
  291.  
  292. #define SSLOLD_NAME_A    "Microsoft SSL"
  293. #define SSLOLD_NAME_W    L"Microsoft SSL"
  294. #define PCTOLD_NAME_A    "Microsoft PCT"
  295. #define PCTOLD_NAME_W    L"Microsoft PCT"
  296.  
  297. #ifdef UNICODE
  298. #define SSLOLD_NAME SSLOLD_NAME_W
  299. #define PCTOLD_NAME PCTOLD_NAME_W
  300. #else
  301. #define SSLOLD_NAME SSLOLD_NAME_A
  302. #define PCTOLD_NAME PCTOLD_NAME_A
  303. #endif
  304.  
  305. #define NETWORK_DREP    0x00000000
  306.  
  307.  
  308.  
  309. // Structures for compatability with the
  310. // NT 4.0 SP2 / IE 3.0 schannel interface, do
  311. // not use.
  312.  
  313. typedef struct _SSL_CREDENTIAL_CERTIFICATE {
  314.     DWORD   cbPrivateKey;
  315.     PBYTE   pPrivateKey;
  316.     DWORD   cbCertificate;
  317.     PBYTE   pCertificate;
  318.     PSTR    pszPassword;
  319. } SSL_CREDENTIAL_CERTIFICATE, * PSSL_CREDENTIAL_CERTIFICATE;
  320.  
  321.  
  322.  
  323.  
  324. // Structures for use with the 
  325. // NT 4.0 SP3 Schannel interface, 
  326. // do not use.
  327. #define SCHANNEL_SECRET_TYPE_CAPI       0x00000001
  328. #define SCHANNEL_SECRET_PRIVKEY         0x00000002
  329. #define SCH_CRED_X509_CERTCHAIN   0x00000001
  330. #define SCH_CRED_X509_CAPI        0x00000002
  331. #define SCH_CRED_CERT_CONTEXT     0x00000003
  332.  
  333. struct _HMAPPER;
  334. typedef struct _SCH_CRED
  335. {
  336.     DWORD     dwVersion;                // always SCH_CRED_VERSION.
  337.     DWORD     cCreds;                   // Number of credentials.
  338.     PVOID     *paSecret;                // Array of SCH_CRED_SECRET_* pointers
  339.     PVOID     *paPublic;                // Array of SCH_CRED_PUBLIC_* pointers
  340.     DWORD     cMappers;                 // Number of credential mappers.
  341.     struct _HMAPPER   **aphMappers;     // pointer to an array of pointers to credential mappers 
  342. } SCH_CRED, * PSCH_CRED;
  343.  
  344. // Structures for use with the 
  345. // NT 4.0 SP3 Schannel interface, 
  346. // do not use.
  347. typedef struct _SCH_CRED_SECRET_CAPI
  348. {
  349.     DWORD           dwType;      // SCHANNEL_SECRET_TYPE_CAPI
  350.     HCRYPTPROV      hProv;       // credential secret information.
  351.  
  352. } SCH_CRED_SECRET_CAPI, * PSCH_CRED_SECRET_CAPI;
  353.  
  354.  
  355. // Structures for use with the 
  356. // NT 4.0 SP3 Schannel interface, 
  357. // do not use.
  358. typedef struct _SCH_CRED_SECRET_PRIVKEY
  359. {
  360.     DWORD           dwType;       // SCHANNEL_SECRET_PRIVKEY
  361.     PBYTE           pPrivateKey;   // Der encoded private key
  362.     DWORD           cbPrivateKey;
  363.     PSTR            pszPassword;  // Password to crack the private key.
  364.  
  365. } SCH_CRED_SECRET_PRIVKEY, * PSCH_CRED_SECRET_PRIVKEY;
  366.  
  367.  
  368. // Structures for use with the 
  369. // NT 4.0 SP3 Schannel interface, 
  370. // do not use.
  371. typedef struct _SCH_CRED_PUBLIC_CERTCHAIN
  372. {
  373.     DWORD       dwType;
  374.     DWORD       cbCertChain;
  375.     PBYTE       pCertChain;
  376. } SCH_CRED_PUBLIC_CERTCHAIN, *PSCH_CRED_PUBLIC_CERTCHAIN;
  377.  
  378. // Structures for use with the 
  379. // NT 4.0 SP3 Schannel interface, 
  380. // do not use.
  381. typedef struct _SCH_CRED_PUBLIC_CAPI
  382. {
  383.     DWORD           dwType;      // SCH_CRED_X509_CAPI
  384.     HCRYPTPROV      hProv;       // CryptoAPI handle (usually a token CSP)
  385.  
  386. } SCH_CRED_PUBLIC_CAPI, * PSCH_CRED_PUBLIC_CAPI;
  387.  
  388. // Attributes for getting NON CAPI2 
  389. // certificate blobs.  Use the CAPI2
  390. // attributes defined above instead.
  391. #define SECPKG_ATTR_ISSUER_LIST          0x50  // SecPkgContext_IssuerListInfo
  392. #define SECPKG_ATTR_REMOTE_CRED          0x51  // SecPkgContext_RemoteCredentialInfo
  393. #define SECPKG_ATTR_LOCAL_CRED           0x52  // SecPkgContext_LocalCredentialInfo
  394.  
  395. // Attributes for getting NON CAPI2 
  396. // certificate blobs.  Use the CAPI2
  397. // attributes defined above instead.
  398. typedef struct _SecPkgContext_IssuerListInfo
  399. {
  400.     DWORD   cbIssuerList;
  401.     PBYTE   pIssuerList;
  402. } SecPkgContext_IssuerListInfo, *PSecPkgContext_IssuerListInfo;
  403.  
  404. // Attributes for getting NON CAPI2 
  405. // certificate blobs.  Use the CAPI2
  406. // attributes defined above instead.
  407. typedef struct _SecPkgContext_RemoteCredentialInfo
  408. {
  409.     DWORD   cbCertificateChain;     // count of bytes in cert chain buffer.
  410.     PBYTE   pbCertificateChain;     // DER encoded chain of certificates, leaf cert first.
  411.     DWORD   cCertificates;
  412.     DWORD   fFlags;
  413.     DWORD   dwBits;                 // Number of bits in the remote credentials
  414. } SecPkgContext_RemoteCredentialInfo, *PSecPkgContext_RemoteCredentialInfo;
  415.  
  416. // Make the old spelling error compatable
  417. typedef SecPkgContext_RemoteCredentialInfo SecPkgContext_RemoteCredenitalInfo, *PSecPkgContext_RemoteCredenitalInfo;
  418.  
  419. // Attributes for getting NON CAPI2 
  420. // certificate blobs.  Use the CAPI2
  421. // attributes defined above instead.
  422. typedef struct _SecPkgContext_LocalCredentialInfo
  423. {
  424.     DWORD   cbCertificateChain;     // count of bytes in cert chain buffer.
  425.     PBYTE   pbCertificateChain;     // DER encoded chain of certificates, leaf cert first.
  426.     DWORD   cCertificates;
  427.     DWORD   fFlags;
  428.     DWORD   dwBits;                 // Number of bits in the remote credentials.
  429. } SecPkgContext_LocalCredentialInfo, *PSecPkgContext_LocalCredentialInfo;
  430.  
  431. // Make the old spelling error compatable.
  432. typedef SecPkgContext_LocalCredentialInfo SecPkgContext_LocalCredenitalInfo, *PSecPkgContext_LocalCredenitalInfo;
  433. #define RCRED_STATUS_NOCRED          0x00000000
  434. #define RCRED_CRED_EXISTS            0x00000001
  435. #define RCRED_STATUS_UNKNOWN_ISSUER  0x00000002    // The last cert in this chain has 
  436.                                                    // an issuer that is unknown to us.
  437. #define LCRED_STATUS_NOCRED          0x00000000
  438. #define LCRED_CRED_EXISTS            0x00000001
  439. #define LCRED_STATUS_UNKNOWN_ISSUER  0x00000002    // The last cert in this chain has 
  440.  
  441.  
  442. // Structures needed for Pre NT4.0 SP2 calls.
  443. typedef struct _PctPublicKey
  444. {
  445.     DWORD Type;
  446.     DWORD cbKey;
  447.     UCHAR pKey[1];
  448. } PctPublicKey;
  449.  
  450. typedef struct _X509Certificate {
  451.     DWORD           Version;
  452.     DWORD           SerialNumber[4];
  453.     ALG_ID          SignatureAlgorithm;
  454.     FILETIME        ValidFrom;
  455.     FILETIME        ValidUntil;
  456.     PSTR            pszIssuer;
  457.     PSTR            pszSubject;
  458.     PctPublicKey    *pPublicKey;
  459. } X509Certificate, * PX509Certificate;
  460.  
  461.  
  462.  
  463. // Pre NT4.0 SP2 calls.  Call CAPI1 or CAPI2
  464. // to get the same functionality instead.
  465. BOOL
  466. SslGenerateKeyPair(
  467.     PSSL_CREDENTIAL_CERTIFICATE pCerts,
  468.     PSTR pszDN,
  469.     PSTR pszPassword,
  470.     DWORD Bits );
  471.  
  472. // Pre NT4.0 SP2 calls.  Call CAPI1 or CAPI2
  473. // to get the same functionality instead.
  474. VOID
  475. SslGenerateRandomBits(
  476.     PUCHAR      pRandomData,
  477.     LONG        cRandomData
  478.     );
  479.  
  480. // Pre NT4.0 SP2 calls.  Call CAPI1 or CAPI2
  481. // to get the same functionality instead.
  482. BOOL
  483. SslCrackCertificate(
  484.     PUCHAR              pbCertificate,
  485.     DWORD               cbCertificate,
  486.     DWORD               dwFlags,
  487.     PX509Certificate *  ppCertificate
  488.     );
  489.  
  490. // Pre NT4.0 SP2 calls.  Call CAPI1 or CAPI2
  491. // to get the same functionality instead.
  492. VOID
  493. SslFreeCertificate(
  494.     PX509Certificate    pCertificate
  495.     );
  496.  
  497. // Call QueryCredentialsAttribute instead.
  498. BOOL
  499. SslGetDefaultIssuers(
  500.     PBYTE pbIssuers,
  501.     DWORD *pcbIssuers);
  502.  
  503.  
  504. #define SSL_CRACK_CERTIFICATE_NAME  TEXT("SslCrackCertificate")
  505. #define SSL_FREE_CERTIFICATE_NAME   TEXT("SslFreeCertificate")
  506.  
  507. // Pre NT4.0 SP2 calls.  Call CAPI1 or CAPI2
  508. // to get the same functionality instead.
  509. typedef BOOL
  510. (WINAPI * SSL_CRACK_CERTIFICATE_FN)
  511. (
  512.     PUCHAR              pbCertificate,
  513.     DWORD               cbCertificate,
  514.     BOOL                VerifySignature,
  515.     PX509Certificate *  ppCertificate
  516. );
  517.  
  518.  
  519. // Pre NT4.0 SP2 calls.  Call CAPI1 or CAPI2
  520. // to get the same functionality instead.
  521. typedef VOID
  522. (WINAPI * SSL_FREE_CERTIFICATE_FN)
  523. (
  524.     PX509Certificate    pCertificate
  525. );
  526.  
  527.  
  528. #endif //__SCHNLSP_H__
  529.