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.

415 lines
20 KiB

  1. /* NO_MAPI - defined for lhutil to get some apis that
  2. * do not use mapi -scousens
  3. */
  4. #ifndef __AWSEC_H__
  5. #define __AWSEC_H__
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #ifndef __FAXOPT_H__
  10. /* **** Special return values for functions below **** */
  11. #define KEY_ADD 1
  12. #define KEY_DEL 2
  13. #define KEY_LOC 3
  14. #define KEY_FND 4
  15. /* The following are return codes from functions which say they return SIG_* as
  16. return values */
  17. #define SIG_SUCCESS 0 /* Operation succeeded */
  18. #define SIG_BADINFILE 1 /* Bad input file */
  19. #define SIG_BADOUTFILE 2 /* Bad output file */
  20. #define SIG_FORGED 3 /* Signature does not match keyset */
  21. #define SIG_AUTHENTIC 4 /* Signature matches keyset */
  22. #define SIG_NOTVERIFIED 5 /* No key found, so can not verify signature */
  23. #define SIG_BADPASS 6 /* Bad password or incorrect session handle */
  24. #define SIG_NOMEM 7 /* Out of memory error */
  25. #define SIG_ABORT 8 /* Callback caused abort */
  26. #define SIG_BUSY 9 /* Concurrent job already running */
  27. /* The following are return codes from functions which say they return SEC_* as
  28. return values */
  29. #define SEC_SUCCESS 0 /* Operation succeeded */
  30. #define SEC_BADFILE 1 /* File cannot be opened */
  31. #define SEC_KEYTOOSMALL 2 /* Keybuffer too small */
  32. #define SEC_NOMATCH 3 /* No key of requested type found for
  33. specified keyholder */
  34. #define SEC_FILECORRUPT 4 /* File integrity check failed */
  35. #define SEC_NOMEMORY 5 /* Aborted due to low memory conditions */
  36. #define SEC_BADPTR 6 /* An invalid pointer was passed in */
  37. #define SEC_USERABORT 7 /* User aborted operation */
  38. #define SEC_BADPASS 8 /* Invalid password */
  39. #define SEC_ABORT 9 /* Callback caused abort */
  40. #define SEC_BUSY 10 /* Concurrent job already running */
  41. #define SEC_WRONGKEY 11 /* Wrong key used in decryption */
  42. #define SEC_NEWERVERSION 12 /* File generated by newer version of software,
  43. and we cannot decrypt it */
  44. #define SEC_NODISKSPACE 13 /* Cannot allocate neccessary disk space for
  45. main or temporary file */
  46. #define SEC_ALREADYLOGGED 14 /* User is already logged in, so certain
  47. account changes cannot be made */
  48. #define SEC_UNDERPRIV 15 /* User does not have sufficient priviledge */
  49. #define SEC_INITFAIL 16 /* Can't init the security system */
  50. #define SEC_ALREADYTHERE 17 /* Key already exists on add or rename */
  51. #endif
  52. /* **** Callback parameter definitions for functions below **** */
  53. /* return values: 0 = success, 1 = End of Job, 2 = failure */
  54. /* A function of type ReadCB allocates a buffer (of arbitrary size), and then
  55. fills it from handle hf (passed in when the callback was set up) */
  56. typedef WORD CALLBACK ReadCB(DWORD hf, LPBUFFER FAR *buf);
  57. /* return values: 0 = success, 2 = failure */
  58. /* A function of type WriteCB writes the buffer passed in (arbitrary size) out
  59. to handle hf, and then frees the buffer */
  60. typedef WORD CALLBACK WriteCB(DWORD hf, LPBUFFER buf);
  61. /* return values: 0 = continue, 1 = abort */
  62. /* A function of type SigCB is called with information about a signature on a
  63. file. Each time it is called, it is passed the handle it gave when the
  64. callback was set up (hf), a username (username), and a result (result).
  65. The result can be SIG_FORGED (key found, but signature does not match key),
  66. SIG_AUTHENTIC (key found, and signature matches key), or SIG_NOTVERIFIED
  67. (key not found, and therefore cannot be authenticated) */
  68. typedef WORD CALLBACK SigCB(DWORD hf, LPSTR username, WORD result);
  69. /* return 0 for continue, 1 for abort. */
  70. /* A function of type listcallback is called with information about a key. For
  71. each key, a pointer to the key is returned (key), along with its size
  72. (keysize), and the userid for whom the key is for. Also, a handle is passed
  73. back which was passed in when the callback was set up originally */
  74. typedef WORD (CALLBACK *listcallback)(BYTE FAR *key, WORD keysize, LPSTR userid,
  75. DWORD handle);
  76. /* **** Special Purpose API's **** */
  77. /* To be called by UISHELL whenever the machine phone number has changed */
  78. void WINAPI SecNewPhoneNumber(void);
  79. #ifndef __AWGLOBAL_H__
  80. /* **** Linearize/Delinarize API's **** */
  81. /* Calls to encrypt and decrypt messages - for the linearizer only */
  82. #ifndef NO_MAPI
  83. /* Initializes key encryption. Takes userid and mapi session handle of user
  84. to encrypt for. Also takes userid of destination user. Returns instance,
  85. which should be used on calls to EncryptData, as well as fills in buf with
  86. header information. EncryptInit should be called with buf NULL first, and
  87. it will return the minimum needed size for the buffer. Buf should then be
  88. allocated to be at least this size. Returns value of type SEC_* if buf is
  89. not NULL. */
  90. WORD WINAPI EncryptInit(LPSTR userid, LPSOSSESSION lpSess, LPSTR destuser,
  91. LPDWORD instance, LPBUFFER buf);
  92. /* Takes current lpSess and inst from an EncryptInit call. Fills in a pointer
  93. (buf) and a length (len) of an IFMemAlloc'ed block of memory. This
  94. memory can be cached and restored via EncryptRestore for delayed encryption
  95. where the user can log out. The header from EncryptInit should be stored,
  96. along with the Mapi session handle and the buffer returned. Returns value
  97. of type SEC_* */
  98. WORD WINAPI EncryptSave(LPSOSSESSION lpSess, DWORD inst, LPBYTE FAR *buf,
  99. LPWORD len);
  100. /* Takes a pointer to a buffer and the buffer's length, as returned from
  101. EncryptSave, along with a (now possibly expired/invalid) lpSess. Returns
  102. an inst suitable for passing to EncryptData. Returns value of type SEC_* */
  103. WORD WINAPI EncryptRestore(LPDWORD inst, LPSOSSESSION lpSess, LPBYTE buf,
  104. WORD len);
  105. /* Encrypts data using key encryption. Takes a mapi session handle of user to
  106. encrypt for, as well as instance (inst) returned by EncryptInit. Converts
  107. buf in place from plaintext to encrypted text. After the final packet, a
  108. buffer of metatype END_OF_JOB should be passed in. Returns value of type
  109. SEC_* */
  110. WORD WINAPI EncryptData(LPSOSSESSION lpSess, DWORD inst, LPBUFFER buf);
  111. /* Initializes key decryption. Takes userid and mapi session handle of user
  112. to decrypt for. Also takes userid of source user. Returns instance,
  113. which should be used on calls to DecryptData. Takes a buffer which should
  114. be at least 8K (from message to decrypt), or the whole message if it is less
  115. than 8K, and returns a smaller buffer (of size >= 0, since header is
  116. stripped off). Note that the buffer is the same, but the valid data area
  117. will be smaller. Returns value of type SEC_* */
  118. WORD WINAPI DecryptInit(LPSTR userid, LPSOSSESSION lpSess, LPSTR srcuser,
  119. LPDWORD instance, LPBUFFER buf);
  120. /* Decrypts data using key encryption. Takes a mapi session handle of user to
  121. decrypt for, as well as instance (inst) returned by DecryptInit. Converts
  122. buf in place from encrypted to plaintext. After the final packet, a
  123. buffer of metatype END_OF_JOB should be passed in. Returns value of type
  124. SEC_*. */
  125. WORD WINAPI DecryptData(LPSOSSESSION lpSess, DWORD inst, LPBUFFER buf);
  126. #endif /* NO_MAPI */
  127. /* Initializes password encryption. Takes pwd as the password to encrypt with.
  128. Returns instance, which should be used on calls to SimpleEncryptData, as
  129. well as fills in buf with header information. SimpleEncryptInit should be
  130. called with buf NULL first, and it will return the minimum needed size for
  131. the buffer. Buf should then be allocated to be at least this size. Returns
  132. value of type SEC_* if buf is not NULL. */
  133. WORD WINAPI SimpleEncryptInit(LPSTR pwd, LPDWORD instance, LPBUFFER buf);
  134. /* Takes inst from a SimpleEncryptInit call. Fills in a pointer (buf) and a
  135. length (len) of an IFMemAlloc'ed block of memory. This memory can be
  136. cached and restored via SimpleEncryptRestore for delayed encryption where
  137. the user can log out. The header from EncryptInit should be stored, along
  138. with the returned buffer. Returns value of type SEC_* */
  139. WORD WINAPI SimpleEncryptSave(DWORD inst, LPBYTE FAR *buf, LPWORD len);
  140. /* Takes a pointer to a buffer and the buffer's length, as returned from
  141. SimpleEncryptSave, along with a (now possibly expired/invalid) lpSess.
  142. Returns an inst suitable for passing to SimpleEncryptData. Returns value
  143. of type SEC_* */
  144. WORD WINAPI SimpleEncryptRestore(LPDWORD inst, LPBYTE buf, WORD len);
  145. /* Encrypts data using password encryption. Takes an instance (inst) returned
  146. by EncryptInit. Converts buf in place from plaintext to encrypted text.
  147. After the final packet, a buffer of metatype END_OF_JOB should be passed
  148. in. Returns a value of type SEC_*. */
  149. WORD WINAPI SimpleEncryptData(DWORD inst, LPBUFFER buf);
  150. /* Initializes password decryption. Takes password to use for decryption.
  151. Returns instance, which should be used on calls to SimpleDecryptData. Takes
  152. a buffer which should be used on calls to DecryptData. Takes a buffer which
  153. should be at least 8K (from message to decrypt), or the whole message if it
  154. is less than 8K, and returns a smaller buffer (of size >= 0, since header is
  155. stripped off). Note that the buffer is the same, but the valid data area
  156. will be smaller. Returns value of type SEC_* */
  157. WORD WINAPI SimpleDecryptInit(LPSTR pwd, LPDWORD instance, LPBUFFER buf);
  158. /* Decrypts data using password decryption. Takes an instance (inst) returned
  159. by SimpleDecryptInit. Converts buf in place from encrypted to plaintext.
  160. After the final packet, a buffer of metatype END_OF_JOB should be passed in.
  161. Returns value of type SEC_*. */
  162. WORD WINAPI SimpleDecryptData(DWORD inst, LPBUFFER buf);
  163. /* Call to start hashing bft header. Returns 0 for failure, or non-zero
  164. context for passing to SendBFTHash and DoneBFTHash */
  165. DWORD WINAPI StartBFTHash(void);
  166. /* Pass in context from StartBFTHash, and buffer with length */
  167. void WINAPI SendBFTHash(DWORD Context, LPBYTE buf, WORD len);
  168. /* Pass in context after done calling SendBFTHash. If salt points to 3 bytes
  169. which are 0, a salt is generated and returned, else the salt is used.
  170. Key must be 5 bytes, from which the actual key is derived. Res must be 16
  171. bytes long to receive hashed encrypted result. */
  172. void WINAPI DoneBFTHash(DWORD Context, LPBYTE salt, LPBYTE res);
  173. /* **** Signature API's **** */
  174. #ifndef NO_MAPI
  175. /* Takes a read and write callback, and handles to pass them. If the file is
  176. already signed (YOU MUST CHECK THE EXTENSION), you must pass the size of the
  177. header (from SignFileHeaderSize) in the HeaderSize field. This value will
  178. currently always be changed to 0 upon return. The new header will be
  179. written out to the callback. To make the signed file, you prepend the data
  180. written to the callback to the original file, unless it was already signed,
  181. in which case you prepend it to the file inside the signed file (based on
  182. SignFileHeaderSize). Also takes a session handle for the user who is
  183. signing the file, along with the username. Returns SIG_*. */
  184. WORD WINAPI SignFile(ReadCB *readCB, DWORD readHand, WriteCB *writeCB,
  185. DWORD writeHand, LPSTR userid, LPSOSSESSION lpSess,
  186. LPSTR filename, LPWORD HeaderSize);
  187. /* Extracts file from signed file. Takes a read and write callback and handles
  188. for them. Reads the file from the read callback, and writes it out to the
  189. write callback. Returns SIG_*. */
  190. WORD WINAPI UnSignFile(ReadCB *readCB, DWORD readHand, WriteCB *writeCB,
  191. DWORD writeHand);
  192. /* Obtains the headersize and filename of a signed file. Sets headersize to be
  193. the size of the header of signed file, and fills filename with 8.3 filename
  194. from a signed file obtained by reading from the callback. Returns 0 for
  195. success, 1 for failure, 2 for not a signed file. */
  196. WORD WINAPI SignFileHeaderSize(ReadCB *readCB, DWORD readHand,
  197. LPWORD headersize, LPSTR filename);
  198. /* Calls signature callback for each signature in the file obtained by the
  199. read callback. Reads file from the read callback (SEE NOTE), and then calls the
  200. sig callback once for each signature (or until the callback signals to stop
  201. through its return value. If filename is non-null, also returns the 8.3
  202. filename in the buffer pointed to by filename. Returns SIG_*. */
  203. /* NOTE: Unlike the usual semantics, the read callback should not simply return 1
  204. to indicate EOF. Instead, it should allocate an empty buffer and return 0, then
  205. return 1 on the next call. -RajeevD */
  206. WORD WINAPI GetSignatures(LPSTR userid, LPSOSSESSION lpSess, ReadCB *readCB,
  207. DWORD readHand, SigCB *sigCB, DWORD sigHand,
  208. LPSTR filename);
  209. /* **** Public key API's **** */
  210. /* Lists all public keys in an exported file, given that the read callback
  211. returns data from the unsigned portion of a signed key file, or from an
  212. unsigned key file. Calls the read callback to read the file, and then
  213. calls the listcallback to enumerate the keys, passing it the listhandle with
  214. each key. Returns SEC_*. */
  215. WORD WINAPI ListKeysInFile(ReadCB FAR *readCB, DWORD readHand,
  216. listcallback lcb, DWORD listhandle);
  217. /* Lists all keys in user database for having mapi session lpSess for user
  218. userid. Calls the listcallback to enumerate the keys, also passing the
  219. listhandle with each key. Passing in a NULL for lpSess returns keys in the
  220. global key list (userid is ignored). Returns SEC_*. */
  221. WORD WINAPI ListKeys(LPSTR userid, LPSOSSESSION lpSess, listcallback lcb,
  222. DWORD listhandle);
  223. /* Creates a file header for an unsigned key file of numkeys public keys.
  224. Writes the header appropriate for a keyfile of numkeys keys out to the
  225. write callback, passing it writeHand as well. Should be called in order
  226. to create a key file, before using AddPubKeyToFile to actually add the
  227. keys. Returns SEC_*. */
  228. WORD WINAPI CreatePubKeyFile(WriteCB FAR *writeCB, DWORD writeHand,
  229. WORD numkeys);
  230. /* Appends a key to keyfile created with KeyFileHeader. Must be called exactly
  231. the number of times specified by the numkeys parameter to CreatePubKeyFile.
  232. Takes a key and a keysize, as well as the userid of the user corresponding
  233. to the key. Calls the writecallback to write to append to a file that key.
  234. After all keys are written to the file, it can be closed and is now a valid
  235. public key file. This file can be signed to create a signed key file.
  236. Returns SEC_*. */
  237. WORD WINAPI AddPubKeyToFile(WriteCB FAR *writeCB, DWORD writeHand,
  238. BYTE FAR *key, WORD keysize, LPSTR userid);
  239. /* Retrieves public key from a unsigned key file. Returns key and size of key
  240. for user corresponding to userid, if it can be found. Reads through read
  241. callback. Key must point to at least 1024 bytes of memory. If file is
  242. signed, callback should return bytes starting from offset in file after
  243. signed header size (from SignFileHeaderSize). Returns SEC_*. */
  244. WORD WINAPI GetPubKeyFromFile(ReadCB *readCB, DWORD readHand,
  245. BYTE FAR *key, WORD FAR *keysize,
  246. LPSTR userid);
  247. /* Adds key for targetuserid into registry of userid with session handle
  248. lpSess. Key should point to a key of size keysize, for user specified by
  249. userid. Returns SEC_*. */
  250. WORD WINAPI AddPubKey(LPSTR userid, LPSOSSESSION lpSess, BYTE FAR *key,
  251. WORD keysize, LPSTR targetuserid);
  252. /* Adds key for targetuserid into global key list. lpSess must be the session
  253. handle for superuser userid. Key should point to a key of size keysize,
  254. for user specified by targetuserid. Returns SEC_*. */
  255. WORD WINAPI AddGlobalPubKey(LPSTR userid, LPSOSSESSION lpSess,
  256. BYTE FAR *key, WORD keysize,
  257. LPSTR targetuserid);
  258. /* Retrieves key for searchuserid from registry of userid with session handle
  259. lpSess. Key must point to at least 1024 bytes of memory. Actual size is
  260. returned in keysize. If lpSess is NULL, reads from the global key list
  261. (userid is ignored). Returns SEC_*. */
  262. WORD WINAPI GetPubKey(LPSTR userid, LPSOSSESSION lpSess, BYTE FAR *key,
  263. WORD FAR *keysize, LPSTR searchuserid);
  264. /* Deletes key of targetuserid from registry of userid with session handle
  265. lpSess. Returns SEC_*. */
  266. WORD WINAPI DelPubKey(LPSTR userid, LPSOSSESSION lpSess,
  267. LPSTR targetuserid);
  268. /* Deletes key of targetuseri from global key list. Userid must be a superuser
  269. with session handle lpSess. Returns SEC_*. */
  270. WORD WINAPI DelGlobalPubKey(LPSTR userid, LPSOSSESSION lpSess,
  271. LPSTR targetuserid);
  272. /* Returns 1 if a public key exists for 'name' in key registry belonging to
  273. user 'userid' with session handle 'lpSess', or 0 otherwise. If NULL is
  274. passed in for lpSess, checks the global key list (and userid is ignored). */
  275. BOOL WINAPI ExistsPubKey(LPSTR userid, LPSOSSESSION lpSess, LPSTR name);
  276. /* Returns 1 if a public key can be found using fuzzy matching as used in
  277. decrypt and encrypt for 'name' in key registry belonging to user 'userid'
  278. with session handle 'lpSess', or 0 otherwise. If NULL is passed in for
  279. lpSess, checks the global key list (and userid is ignored). */
  280. BOOL WINAPI ExistsFuzzyPubKey(LPSTR userid, LPSOSSESSION lpSess, LPSTR name);
  281. /* Creates new key set (public and private) for userid logged in with 'lpSess'.
  282. Returns SEC_*. */
  283. WORD WINAPI MakeNewKeySet(LPSTR userid, LPSOSSESSION lpSess);
  284. /* For use when a user forgets his password. Takes lpSess of userid who is a
  285. superuser, and the username of the user who has forgotten his password
  286. (targetuser). Sets their password to be newuserpwd, and gives them a new
  287. set of keys. targetuser should not be logged in. Returns SEC_*. */
  288. WORD WINAPI ReinitKeyAndPassword(LPSTR userid, LPSOSSESSION lpSess,
  289. LPSTR targetuser, LPSTR newuserpwd);
  290. /* For use when a user wants to change his password. Takes lpSess of userid
  291. who wants to change his password, along with old and new password. Returns
  292. SEC_*. */
  293. WORD WINAPI ChangePassword(LPSTR userid, LPSOSSESSION lpSess, LPSTR oldpass,
  294. LPSTR newpass);
  295. /* Exports private key set (password encrypted) through callbacks. Writes out
  296. encrypted (with login password) file through write callback, which contains
  297. the user's private and public keys. This file can be read back with
  298. ImportPrivateKeys. Returns SEC_*. */
  299. WORD WINAPI ExportPrivateKeys(LPSTR userid, LPSOSSESSION lpSess,
  300. WriteCB FAR *writeCB, DWORD writeHand);
  301. /* Attemps to import private and public key for userid with session lpSess,
  302. using password passed in to decrypt, reading file through read callback.
  303. Returns SEC_*. */
  304. WORD WINAPI ImportPrivateKeys(LPSTR userid, LPSOSSESSION lpSess,
  305. ReadCB FAR *readCB, DWORD readHand,
  306. LPSTR password);
  307. /* Removes keyset for a user */
  308. WORD WINAPI DeleteKeySet(LPSTR userid, LPSOSSESSION lpSess);
  309. /* Returns 1 if a user has a key set, else returns 0 */
  310. WORD WINAPI HasPrivateKey(LPSTR userid, LPSOSSESSION lpSess);
  311. /* Places 154 bytes into screendata array for displaying key passed in.
  312. screendata should be displayed as 14 groups of 11 characters. Only
  313. alphanumerical characters will be returned in screendata. It is not
  314. null-terminated, or delimited in any way - just 154 characters. Returns 0
  315. on success, or 1 if the key is invalid. */
  316. WORD WINAPI GetDisplayableKey(BYTE FAR *key, BYTE FAR *screendata);
  317. /* Converts keyinput into key for userid. Keyinput is 154 bytes (only valid
  318. characters are 2..9, A..H, J..N, P..Z). Returns 0 for success, or group
  319. which is invalid if the key is not valid (ie: 1 for 1st 11 characters,
  320. etc...). If 15 is returned, there is an error, but the box number cannot
  321. be determined (should never happen, barring a malicious user trying to make
  322. it happen). If 0 is returned, fills in key and keysize. Key must point to
  323. at least 1024 bytes of memory. */
  324. WORD WINAPI BuildKey(BYTE FAR *keyinput, BYTE FAR *key,WORD FAR *keysize);
  325. /* **** Generic API's **** */
  326. /* Returns a random DWORD */
  327. DWORD WINAPI RandDWord(void);
  328. /* **** Mapi API's **** */
  329. HRESULTSOS WINAPI ValidateUserLogin(LPSTR lpszname, LPSTR lpszPassword,
  330. DWORD FAR *lpdwSecurityHandle);
  331. HRESULTSOS WINAPI UnvalidateUserLogin(LPSOSSESSION lpSess);
  332. HRESULTSOS WINAPI CreateSecureUser(LPSTR lpszName, LPSTR lpszPassword);
  333. HRESULTSOS WINAPI DeleteSecureUser(LPSTR lpszName);
  334. #endif /* NO_MAPI */
  335. #endif
  336. #ifdef __cplusplus
  337. } /* extern "C" */
  338. #endif
  339. #endif /* __AWSEC_H__ */