geom_gate userland utility improvements
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.
 
 
 
 

66 lines
2.1 KiB

  1. #include "session_fixture.h"
  2. #include <libssh2.h>
  3. #include <stdio.h>
  4. static const char *EXPECTED_RSA_HOSTKEY =
  5. "AAAAB3NzaC1yc2EAAAABIwAAAQEArrr/JuJmaZligyfS8vcNur+mWR2ddDQtVdhHzdKU"
  6. "UoR6/Om6cvxpe61H1YZO1xCpLUBXmkki4HoNtYOpPB2W4V+8U4BDeVBD5crypEOE1+7B"
  7. "Am99fnEDxYIOZq2/jTP0yQmzCpWYS3COyFmkOL7sfX1wQMeW5zQT2WKcxC6FSWbhDqrB"
  8. "eNEGi687hJJoJ7YXgY/IdiYW5NcOuqRSWljjGS3dAJsHHWk4nJbhjEDXbPaeduMAwQU9"
  9. "i6ELfP3r+q6wdu0P4jWaoo3De1aYxnToV/ldXykpipON4NPamsb6Ph2qlJQKypq7J4iQ"
  10. "gkIIbCU1A31+4ExvcIVoxLQw/aTSbw==";
  11. static const char *EXPECTED_ECDSA_HOSTKEY =
  12. "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBC+/syyeKJD9dC2ZH"
  13. "9Q7iJGReR4YM3rUCMsSynkyXojdfSClGCMY7JvWlt30ESjYvxoTfSRGx6WvaqYK/vPoYQ4=";
  14. int test(LIBSSH2_SESSION *session)
  15. {
  16. int rc;
  17. size_t len;
  18. int type;
  19. unsigned int expected_len = 0;
  20. char *expected_hostkey = NULL;
  21. const char *hostkey = libssh2_session_hostkey(session, &len, &type);
  22. if(hostkey == NULL) {
  23. print_last_session_error("libssh2_session_hostkey");
  24. return 1;
  25. }
  26. if(type == LIBSSH2_HOSTKEY_TYPE_ECDSA_256) {
  27. rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len,
  28. EXPECTED_ECDSA_HOSTKEY,
  29. strlen(EXPECTED_ECDSA_HOSTKEY));
  30. }
  31. else if(type == LIBSSH2_HOSTKEY_TYPE_RSA) {
  32. rc = libssh2_base64_decode(session, &expected_hostkey, &expected_len,
  33. EXPECTED_RSA_HOSTKEY,
  34. strlen(EXPECTED_RSA_HOSTKEY));
  35. }
  36. else {
  37. fprintf(stderr, "Unexpected type of hostkey: %i\n", type);
  38. return 1;
  39. }
  40. if(rc != 0) {
  41. print_last_session_error("libssh2_base64_decode");
  42. return 1;
  43. }
  44. if(len != expected_len) {
  45. fprintf(stderr, "Hostkey does not have the expected length %ld!=%d\n",
  46. (unsigned long)len, expected_len);
  47. return 1;
  48. }
  49. if(memcmp(hostkey, expected_hostkey, len) != 0) {
  50. fprintf(stderr, "Hostkeys do not match\n");
  51. return 1;
  52. }
  53. return 0;
  54. }