CryptoAuth_pvt.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 privateKey[32];
  44. struct CryptoAuth_User* users;
  45. struct Log* logger;
  46. struct EventBase* eventBase;
  47. struct Allocator* allocator;
  48. struct Random* rand;
  49. Identity
  50. };
  51. struct CryptoAuth_Session_pvt
  52. {
  53. struct CryptoAuth_Session pub;
  54. struct Allocator* alloc;
  55. /** The shared secret. */
  56. uint8_t sharedSecret[32];
  57. uint8_t herTempPubKey[32];
  58. uint8_t ourTempPrivKey[32];
  59. uint8_t ourTempPubKey[32];
  60. /** A password to use for authing with the other party. */
  61. String* password;
  62. /** The login name to auth with the other party. */
  63. String* login;
  64. /** The next nonce to use. */
  65. uint32_t nextNonce;
  66. /** Used to reset the connection if it's in a bad state (no traffic coming in). */
  67. uint32_t timeOfLastPacket;
  68. /** The method to use for trying to auth with the server. */
  69. int authType : 8;
  70. /** True if this node began the conversation. */
  71. bool isInitiator : 1;
  72. /** If true and the other end is connecting, do not respond until a valid password is sent. */
  73. bool requireAuth : 1;
  74. bool established : 1;
  75. /** A pointer back to the main cryptoauth context. */
  76. struct CryptoAuth_pvt* context;
  77. Identity
  78. };
  79. //uint8_t CryptoAuth_receiveMessage(struct Message* received, struct Iface* interface);
  80. //uint8_t CryptoAuth_encryptHandshake(struct Message* message,
  81. // struct CryptoAuth_Wrapper* wrapper,
  82. // int setupMessage);
  83. int CryptoAuth_decryptRndNonce(uint8_t nonce[24], struct Message* msg, uint8_t secret[32]);
  84. void CryptoAuth_encryptRndNonce(uint8_t nonce[24], struct Message* msg, uint8_t secret[32]);
  85. #endif