1
0

CryptoAuth_pvt.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #ifndef CryptoAuth_pvt_H
  16. #define CryptoAuth_pvt_H
  17. #include "crypto/CryptoAuth.h"
  18. #include "crypto/ReplayProtector.h"
  19. #include "benc/Object.h"
  20. #include "util/log/Log.h"
  21. #include "memory/Allocator.h"
  22. #include "util/events/EventBase.h"
  23. #include "wire/CryptoHeader.h"
  24. #include "wire/Message.h"
  25. #include "util/Identity.h"
  26. #include <stdint.h>
  27. struct CryptoAuth_User;
  28. struct CryptoAuth_User {
  29. /** Double-hash of password for authType 1 */
  30. uint8_t passwordHash[CryptoHeader_Challenge_KEYSIZE];
  31. /** Hash of username for authType 2 */
  32. uint8_t userNameHash[CryptoHeader_Challenge_KEYSIZE];
  33. uint8_t secret[32];
  34. String* login;
  35. uint8_t restrictedToip6[16];
  36. struct CryptoAuth_User* next;
  37. struct Allocator* alloc;
  38. Identity
  39. };
  40. struct CryptoAuth_pvt
  41. {
  42. struct CryptoAuth pub;
  43. uint8_t pubKey[32];
  44. uint8_t privateKey[32];
  45. struct CryptoAuth_User* users;
  46. struct Log* logger;
  47. struct EventBase* eventBase;
  48. struct Allocator* allocator;
  49. struct Random* rand;
  50. Identity
  51. };
  52. struct CryptoAuth_Session_pvt
  53. {
  54. struct CryptoAuth_Session pub;
  55. uint8_t herPublicKey[32];
  56. String* displayName;
  57. struct ReplayProtector replayProtector;
  58. /**
  59. * Bind this CryptoAuth session to the other node's ip6 address,
  60. * any packet avertizing a key which doesn't hash to this will be dropped.
  61. */
  62. uint8_t herIp6[16];
  63. /**
  64. * After this number of seconds of inactivity,
  65. * a connection will be reset to prevent them hanging in a bad state.
  66. */
  67. uint32_t resetAfterInactivitySeconds;
  68. /** If a session is not completely setup, reset it after this many seconds of inactivity. */
  69. uint32_t setupResetAfterInactivitySeconds;
  70. struct Allocator* alloc;
  71. /** The shared secret. */
  72. uint8_t sharedSecret[32];
  73. uint8_t herTempPubKey[32];
  74. uint8_t ourTempPrivKey[32];
  75. uint8_t ourTempPubKey[32];
  76. /** A password to use for authing with the other party. */
  77. struct Allocator* passwdAlloc;
  78. String* password;
  79. /** The login name to auth with the other party. */
  80. struct Allocator* loginAlloc;
  81. String* login;
  82. /** The next nonce to use. */
  83. uint32_t nextNonce;
  84. /** Used to reset the connection if it's in a bad state (no traffic coming in). */
  85. uint32_t timeOfLastPacket;
  86. /** The method to use for trying to auth with the server. */
  87. int authType : 8;
  88. /** True if this node began the conversation. */
  89. bool isInitiator : 1;
  90. /** If true and the other end is connecting, do not respond until a valid password is sent. */
  91. bool requireAuth : 1;
  92. bool established : 1;
  93. /** A pointer back to the main cryptoauth context. */
  94. struct CryptoAuth_pvt* context;
  95. Identity
  96. };
  97. //uint8_t CryptoAuth_receiveMessage(struct Message* received, struct Iface* interface);
  98. //uint8_t CryptoAuth_encryptHandshake(struct Message* message,
  99. // struct CryptoAuth_Wrapper* wrapper,
  100. // int setupMessage);
  101. int CryptoAuth_decryptRndNonce(const uint8_t nonce[24], struct Message* msg, const uint8_t secret[32]);
  102. void CryptoAuth_encryptRndNonce(const uint8_t nonce[24], struct Message* msg, const uint8_t secret[32]);
  103. #endif