pageant.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * pageant.h: header for pageant.c.
  3. */
  4. #include <stdarg.h>
  5. /*
  6. * FIXME: it would be nice not to have this arbitrary limit. It's
  7. * currently needed because the Windows Pageant IPC system needs an
  8. * upper bound known to the client, but it's also reused as a basic
  9. * sanity check on incoming messages' length fields.
  10. */
  11. #define AGENT_MAX_MSGLEN 8192
  12. typedef void (*pageant_logfn_t)(void *logctx, const char *fmt, va_list ap);
  13. /*
  14. * Initial setup.
  15. */
  16. void pageant_init(void);
  17. /*
  18. * The main agent function that answers messages.
  19. *
  20. * Expects a message/length pair as input, minus its initial length
  21. * field but still with its type code on the front.
  22. *
  23. * Returns a fully formatted message as output, *with* its initial
  24. * length field, and sets *outlen to the full size of that message.
  25. */
  26. void *pageant_handle_msg(const void *msg, int msglen, int *outlen,
  27. void *logctx, pageant_logfn_t logfn);
  28. /*
  29. * Construct a failure response. Useful for agent front ends which
  30. * suffer a problem before they even get to pageant_handle_msg.
  31. */
  32. void *pageant_failure_msg(int *outlen);
  33. /*
  34. * Construct a list of public keys, just as the two LIST_IDENTITIES
  35. * requests would have returned them.
  36. */
  37. void *pageant_make_keylist1(int *length);
  38. void *pageant_make_keylist2(int *length);
  39. /*
  40. * Accessor functions for Pageant's internal key lists. Fetch the nth
  41. * key; count the keys; attempt to add a key (returning true on
  42. * success, in which case the ownership of the key structure has been
  43. * taken over by pageant.c); attempt to delete a key (returning true
  44. * on success, in which case the ownership of the key structure is
  45. * passed back to the client).
  46. */
  47. struct RSAKey *pageant_nth_ssh1_key(int i);
  48. struct ssh2_userkey *pageant_nth_ssh2_key(int i);
  49. int pageant_count_ssh1_keys(void);
  50. int pageant_count_ssh2_keys(void);
  51. int pageant_add_ssh1_key(struct RSAKey *rkey);
  52. int pageant_add_ssh2_key(struct ssh2_userkey *skey);
  53. int pageant_delete_ssh1_key(struct RSAKey *rkey);
  54. int pageant_delete_ssh2_key(struct ssh2_userkey *skey);
  55. /*
  56. * This callback must be provided by the Pageant front end code.
  57. * pageant_handle_msg calls it to indicate that the message it's just
  58. * handled has changed the list of keys held by the agent. Front ends
  59. * which expose that key list through dedicated UI may need to refresh
  60. * that UI's state in this function; other front ends can leave it
  61. * empty.
  62. */
  63. void keylist_update(void);
  64. /*
  65. * Functions to establish a listening socket speaking the SSH agent
  66. * protocol. Call pageant_listener_new() to set up a state; then
  67. * create a socket using the returned pointer as a Plug; then call
  68. * pageant_listener_got_socket() to give the listening state its own
  69. * socket pointer. Also, provide a logging function later if you want
  70. * to.
  71. */
  72. struct pageant_listen_state;
  73. struct pageant_listen_state *pageant_listener_new(void);
  74. void pageant_listener_got_socket(struct pageant_listen_state *pl, Socket sock);
  75. void pageant_listener_set_logfn(struct pageant_listen_state *pl,
  76. void *logctx, pageant_logfn_t logfn);
  77. void pageant_listener_free(struct pageant_listen_state *pl);
  78. /*
  79. * Functions to perform specific key actions, either as a client of an
  80. * ssh-agent running elsewhere, or directly on the agent state in this
  81. * process. (On at least one platform we want to do this in an
  82. * agnostic way between the two situations.)
  83. *
  84. * pageant_get_keylist{1,2} work just like pageant_make_keylist{1,2}
  85. * above, except that they can also cope if they have to contact an
  86. * external agent.
  87. *
  88. * pageant_add_keyfile() is used to load a private key from a file and
  89. * add it to the agent. Initially, you should call it with passphrase
  90. * NULL, and it will check if the key is already in the agent, and
  91. * whether a passphrase is required. Return values are given in the
  92. * enum below. On return, *retstr will either be NULL, or a
  93. * dynamically allocated string containing a key comment or an error
  94. * message.
  95. *
  96. * pageant_add_keyfile() also remembers passphrases with which it's
  97. * successfully decrypted keys (because if you try to add multiple
  98. * keys in one go, you might very well have used the same passphrase
  99. * for keys that have the same trust properties). Call
  100. * pageant_forget_passphrases() to get rid of them all.
  101. */
  102. void *pageant_get_keylist1(int *length);
  103. void *pageant_get_keylist2(int *length);
  104. enum {
  105. PAGEANT_ACTION_OK, /* success; no further action needed */
  106. PAGEANT_ACTION_FAILURE, /* failure; *retstr is error message */
  107. PAGEANT_ACTION_NEED_PP /* need passphrase: *retstr is key comment */
  108. };
  109. int pageant_add_keyfile(Filename *filename, const char *passphrase,
  110. char **retstr);
  111. void pageant_forget_passphrases(void);
  112. struct pageant_pubkey {
  113. /* Everything needed to identify a public key found by
  114. * pageant_enum_keys and pass it back to the agent or other code
  115. * later */
  116. void *blob;
  117. int bloblen;
  118. char *comment;
  119. int ssh_version;
  120. };
  121. struct pageant_pubkey *pageant_pubkey_copy(struct pageant_pubkey *key);
  122. void pageant_pubkey_free(struct pageant_pubkey *key);
  123. typedef void (*pageant_key_enum_fn_t)(void *ctx,
  124. const char *fingerprint,
  125. const char *comment,
  126. struct pageant_pubkey *key);
  127. int pageant_enum_keys(pageant_key_enum_fn_t callback, void *callback_ctx,
  128. char **retstr);
  129. int pageant_delete_key(struct pageant_pubkey *key, char **retstr);
  130. int pageant_delete_all_keys(char **retstr);