CryptoAuth_pvt.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 <http://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_Auth {
  28. union CryptoHeader_Challenge challenge;
  29. uint8_t secret[32];
  30. String* user;
  31. uint8_t* restrictedToip6;
  32. };
  33. struct CryptoAuth_pvt
  34. {
  35. struct CryptoAuth pub;
  36. uint8_t privateKey[32];
  37. struct CryptoAuth_Auth* passwords;
  38. uint32_t passwordCount;
  39. uint32_t passwordCapacity;
  40. struct Log* logger;
  41. struct EventBase* eventBase;
  42. struct Allocator* allocator;
  43. struct Random* rand;
  44. Identity
  45. };
  46. struct CryptoAuth_Session_pvt
  47. {
  48. struct CryptoAuth_Session pub;
  49. struct Allocator* alloc;
  50. /** The shared secret. */
  51. uint8_t sharedSecret[32];
  52. uint8_t herTempPubKey[32];
  53. uint8_t ourTempPrivKey[32];
  54. uint8_t ourTempPubKey[32];
  55. /** A password to use for authing with the other party. */
  56. String* password;
  57. /** The next nonce to use. */
  58. uint32_t nextNonce;
  59. /** Used to reset the connection if it's in a bad state (no traffic coming in). */
  60. uint32_t timeOfLastPacket;
  61. /** The method to use for trying to auth with the server. */
  62. int authType : 8;
  63. /** True if this node began the conversation. */
  64. bool isInitiator : 1;
  65. /** If true and the other end is connecting, do not respond until a valid password is sent. */
  66. bool requireAuth : 1;
  67. bool established : 1;
  68. /** A pointer back to the main cryptoauth context. */
  69. struct CryptoAuth_pvt* context;
  70. /** A name for the session which will appear in logs. */
  71. char* name;
  72. Identity
  73. };
  74. //uint8_t CryptoAuth_receiveMessage(struct Message* received, struct Iface* interface);
  75. //uint8_t CryptoAuth_encryptHandshake(struct Message* message,
  76. // struct CryptoAuth_Wrapper* wrapper,
  77. // int setupMessage);
  78. int CryptoAuth_decryptRndNonce(uint8_t nonce[24], struct Message* msg, uint8_t secret[32]);
  79. void CryptoAuth_encryptRndNonce(uint8_t nonce[24], struct Message* msg, uint8_t secret[32]);
  80. #endif