common-runopts.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Dropbear - a SSH2 server
  3. *
  4. * Copyright (c) 2002,2003 Matt Johnston
  5. * All rights reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE. */
  24. #include "includes.h"
  25. #include "runopts.h"
  26. #include "signkey.h"
  27. #include "buffer.h"
  28. #include "dbutil.h"
  29. #include "auth.h"
  30. #include "algo.h"
  31. #include "dbrandom.h"
  32. runopts opts; /* GLOBAL */
  33. /* returns success or failure, and the keytype in *type. If we want
  34. * to restrict the type, type can contain a type to return */
  35. int readhostkey(const char * filename, sign_key * hostkey,
  36. enum signkey_type *type) {
  37. int ret = DROPBEAR_FAILURE;
  38. buffer *buf;
  39. buf = buf_new(MAX_PRIVKEY_SIZE);
  40. if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) {
  41. goto out;
  42. }
  43. buf_setpos(buf, 0);
  44. addrandom(buf_getptr(buf, buf->len), buf->len);
  45. if (buf_get_priv_key(buf, hostkey, type) == DROPBEAR_FAILURE) {
  46. goto out;
  47. }
  48. ret = DROPBEAR_SUCCESS;
  49. out:
  50. buf_burn(buf);
  51. buf_free(buf);
  52. return ret;
  53. }
  54. #ifdef ENABLE_USER_ALGO_LIST
  55. void
  56. parse_ciphers_macs()
  57. {
  58. if (opts.cipher_list)
  59. {
  60. if (strcmp(opts.cipher_list, "help") == 0)
  61. {
  62. char *ciphers = algolist_string(sshciphers);
  63. dropbear_log(LOG_INFO, "Available ciphers:\n%s\n", ciphers);
  64. m_free(ciphers);
  65. dropbear_exit(".");
  66. }
  67. if (strcmp(opts.cipher_list, "none") == 0)
  68. {
  69. /* Encryption is required during authentication */
  70. opts.cipher_list = "none,aes128-ctr";
  71. }
  72. if (check_user_algos(opts.cipher_list, sshciphers, "cipher") == 0)
  73. {
  74. dropbear_exit("No valid ciphers specified for '-c'");
  75. }
  76. }
  77. if (opts.mac_list)
  78. {
  79. if (strcmp(opts.mac_list, "help") == 0)
  80. {
  81. char *macs = algolist_string(sshhashes);
  82. dropbear_log(LOG_INFO, "Available MACs:\n%s\n", macs);
  83. m_free(macs);
  84. dropbear_exit(".");
  85. }
  86. if (check_user_algos(opts.mac_list, sshhashes, "MAC") == 0)
  87. {
  88. dropbear_exit("No valid MACs specified for '-m'");
  89. }
  90. }
  91. }
  92. #endif
  93. void print_version() {
  94. fprintf(stderr, "Dropbear v%s\n", DROPBEAR_VERSION);
  95. }