ssh_api.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* $OpenBSD: ssh_api.h,v 1.2 2018/04/10 00:10:49 djm Exp $ */
  2. /*
  3. * Copyright (c) 2012 Markus Friedl. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef API_H
  18. #define API_H
  19. #include <sys/types.h>
  20. #include <signal.h>
  21. #include "openbsd-compat/sys-queue.h"
  22. #include "cipher.h"
  23. #include "sshkey.h"
  24. #include "kex.h"
  25. #include "ssh.h"
  26. #include "ssh2.h"
  27. #include "packet.h"
  28. struct kex_params {
  29. char *proposal[PROPOSAL_MAX];
  30. };
  31. /* public SSH API functions */
  32. /*
  33. * ssh_init() create a ssh connection object with given (optional)
  34. * key exchange parameters.
  35. */
  36. int ssh_init(struct ssh **, int is_server, struct kex_params *kex_params);
  37. /*
  38. * release ssh connection state.
  39. */
  40. void ssh_free(struct ssh *);
  41. /*
  42. * attach application specific data to the connection state
  43. */
  44. void ssh_set_app_data(struct ssh *, void *);
  45. void *ssh_get_app_data(struct ssh *);
  46. /*
  47. * ssh_add_hostkey() registers a private/public hostkey for an ssh
  48. * connection.
  49. * ssh_add_hostkey() needs to be called before a key exchange is
  50. * initiated with ssh_packet_next().
  51. * private hostkeys are required if we need to act as a server.
  52. * public hostkeys are used to verify the servers hostkey.
  53. */
  54. int ssh_add_hostkey(struct ssh *ssh, struct sshkey *key);
  55. /*
  56. * ssh_set_verify_host_key_callback() registers a callback function
  57. * which should be called instead of the default verification. The
  58. * function given must return 0 if the hostkey is ok, -1 if the
  59. * verification has failed.
  60. */
  61. int ssh_set_verify_host_key_callback(struct ssh *ssh,
  62. int (*cb)(struct sshkey *, struct ssh *));
  63. /*
  64. * ssh_packet_next() advances to the next input packet and returns
  65. * the packet type in typep.
  66. * ssh_packet_next() works by processing an input byte-stream,
  67. * decrypting the received data and hiding the key-exchange from
  68. * the caller.
  69. * ssh_packet_next() sets typep if there is no new packet available.
  70. * in this case the caller must fill the input byte-stream by passing
  71. * the data received over network to ssh_input_append().
  72. * additionally, the caller needs to send the resulting output
  73. * byte-stream back over the network. otherwise the key exchange
  74. * would not proceed. the output byte-stream is accessed through
  75. * ssh_output_ptr().
  76. */
  77. int ssh_packet_next(struct ssh *ssh, u_char *typep);
  78. /*
  79. * ssh_packet_payload() returns a pointer to the raw payload data of
  80. * the current input packet and the length of this payload.
  81. * the payload is accessible until ssh_packet_next() is called again.
  82. */
  83. const u_char *ssh_packet_payload(struct ssh *ssh, size_t *lenp);
  84. /*
  85. * ssh_packet_put() creates an encrypted packet with the given type
  86. * and payload.
  87. * the encrypted packet is appended to the output byte-stream.
  88. */
  89. int ssh_packet_put(struct ssh *ssh, int type, const u_char *data,
  90. size_t len);
  91. /*
  92. * ssh_input_space() checks if 'len' bytes can be appended to the
  93. * input byte-stream.
  94. */
  95. int ssh_input_space(struct ssh *ssh, size_t len);
  96. /*
  97. * ssh_input_append() appends data to the input byte-stream.
  98. */
  99. int ssh_input_append(struct ssh *ssh, const u_char *data, size_t len);
  100. /*
  101. * ssh_output_space() checks if 'len' bytes can be appended to the
  102. * output byte-stream. XXX
  103. */
  104. int ssh_output_space(struct ssh *ssh, size_t len);
  105. /*
  106. * ssh_output_ptr() retrieves both a pointer and the length of the
  107. * current output byte-stream. the bytes need to be sent over the
  108. * network. the number of bytes that have been successfully sent can
  109. * be removed from the output byte-stream with ssh_output_consume().
  110. */
  111. const u_char *ssh_output_ptr(struct ssh *ssh, size_t *len);
  112. /*
  113. * ssh_output_consume() removes the given number of bytes from
  114. * the output byte-stream.
  115. */
  116. int ssh_output_consume(struct ssh *ssh, size_t len);
  117. #endif