snmpv3_dummy.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * @file
  3. * Dummy SNMPv3 functions.
  4. */
  5. /*
  6. * Copyright (c) 2016 Elias Oenal.
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. The name of the author may not be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  21. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  23. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  25. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  28. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  29. * OF SUCH DAMAGE.
  30. *
  31. * Author: Elias Oenal <lwip@eliasoenal.com>
  32. * Dirk Ziegelmeier <dirk@ziegelmeier.net>
  33. */
  34. #include "lwip/apps/snmpv3.h"
  35. #include "snmpv3_priv.h"
  36. #include <string.h>
  37. #include "lwip/err.h"
  38. #if LWIP_SNMP && LWIP_SNMP_V3
  39. /**
  40. * @param username is a pointer to a string.
  41. * @param auth_algo is a pointer to u8_t. The implementation has to set this if user was found.
  42. * @param auth_key is a pointer to a pointer to a string. Implementation has to set this if user was found.
  43. * @param priv_algo is a pointer to u8_t. The implementation has to set this if user was found.
  44. * @param priv_key is a pointer to a pointer to a string. Implementation has to set this if user was found.
  45. */
  46. err_t
  47. snmpv3_get_user(const char* username, u8_t *auth_algo, u8_t *auth_key, u8_t *priv_algo, u8_t *priv_key)
  48. {
  49. const char* engine_id;
  50. u8_t engine_id_len;
  51. if(strlen(username) == 0) {
  52. return ERR_OK;
  53. }
  54. if(memcmp(username, "lwip", 4) != 0) {
  55. return ERR_VAL;
  56. }
  57. snmpv3_get_engine_id(&engine_id, &engine_id_len);
  58. if(auth_key != NULL) {
  59. snmpv3_password_to_key_sha((const u8_t*)"maplesyrup", 10,
  60. (const u8_t*)engine_id, engine_id_len,
  61. auth_key);
  62. *auth_algo = SNMP_V3_AUTH_ALGO_SHA;
  63. }
  64. if(priv_key != NULL) {
  65. snmpv3_password_to_key_sha((const u8_t*)"maplesyrup", 10,
  66. (const u8_t*)engine_id, engine_id_len,
  67. priv_key);
  68. *priv_algo = SNMP_V3_PRIV_ALGO_DES;
  69. }
  70. return ERR_OK;
  71. }
  72. /**
  73. * Get engine ID from persistence
  74. * @param id
  75. * @param len
  76. */
  77. void
  78. snmpv3_get_engine_id(const char **id, u8_t *len)
  79. {
  80. *id = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02";
  81. *len = 12;
  82. }
  83. /**
  84. * Store engine ID in persistence
  85. * @param id
  86. * @param len
  87. */
  88. err_t
  89. snmpv3_set_engine_id(const char *id, u8_t len)
  90. {
  91. LWIP_UNUSED_ARG(id);
  92. LWIP_UNUSED_ARG(len);
  93. return ERR_OK;
  94. }
  95. /**
  96. * Get engine boots from persistence. Must be increased on each boot.
  97. * @return
  98. */
  99. u32_t
  100. snmpv3_get_engine_boots(void)
  101. {
  102. return 0;
  103. }
  104. /**
  105. * Store engine boots in persistence
  106. * @param boots
  107. */
  108. void
  109. snmpv3_set_engine_boots(u32_t boots)
  110. {
  111. LWIP_UNUSED_ARG(boots);
  112. }
  113. /**
  114. * RFC3414 2.2.2.
  115. * Once the timer reaches 2147483647 it gets reset to zero and the
  116. * engine boot ups get incremented.
  117. */
  118. u32_t
  119. snmpv3_get_engine_time(void)
  120. {
  121. return 0;
  122. }
  123. /**
  124. * Reset current engine time to 0
  125. */
  126. void
  127. snmpv3_reset_engine_time(void)
  128. {
  129. }
  130. #endif /* LWIP_SNMP && LWIP_SNMP_V3 */