SPProtoDecoder.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * @file SPProtoDecoder.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * Object which decodes packets according to SPProto.
  25. */
  26. #ifndef BADVPN_FLOW_SPPROTODECODER_H
  27. #define BADVPN_FLOW_SPPROTODECODER_H
  28. #include <stdint.h>
  29. #include <misc/debug.h>
  30. #include <system/DebugObject.h>
  31. #include <protocol/spproto.h>
  32. #include <security/BEncryption.h>
  33. #include <security/OTPChecker.h>
  34. #include <flow/PacketPassInterface.h>
  35. /**
  36. * Object which decodes packets according to SPProto.
  37. * Input is with {@link PacketPassInterface}.
  38. * Output is with {@link PacketPassInterface}.
  39. */
  40. typedef struct {
  41. DebugObject d_obj;
  42. dead_t dead;
  43. PacketPassInterface *output;
  44. int output_mtu;
  45. struct spproto_security_params sp_params;
  46. int hash_size;
  47. int enc_block_size;
  48. int enc_key_size;
  49. int input_mtu;
  50. uint8_t *buf;
  51. PacketPassInterface input;
  52. OTPChecker otpchecker;
  53. int have_encryption_key;
  54. BEncryption encryptor;
  55. } SPProtoDecoder;
  56. /**
  57. * Initializes the object.
  58. *
  59. * @param o the object
  60. * @param output output interface
  61. * @param sp_params CCProto parameters. Must be valid.
  62. * @param encryption_key if using encryption, the encryption key
  63. * @param num_otp_seeds if using OTPs, how many OTP seeds to keep for checking
  64. * receiving packets. Must be >=2 if using OTPs.
  65. * @return 1 on success, 0 on failure
  66. */
  67. int SPProtoDecoder_Init (SPProtoDecoder *o, PacketPassInterface *output, struct spproto_security_params sp_params, int num_otp_seeds) WARN_UNUSED;
  68. /**
  69. * Frees the object.
  70. *
  71. * @param o the object
  72. */
  73. void SPProtoDecoder_Free (SPProtoDecoder *o);
  74. /**
  75. * Returns the input interface.
  76. * The MTU of the input interface will depend on the output MTU and security parameters,
  77. * that is spproto_carrier_mtu_for_payload_mtu(sp_params, output MTU).
  78. *
  79. * @param o the object
  80. * @return input interface
  81. */
  82. PacketPassInterface * SPProtoDecoder_GetInput (SPProtoDecoder *o);
  83. /**
  84. * Sets an encryption key for decrypting packets.
  85. * Encryption must be enabled.
  86. *
  87. * @param o the object
  88. * @param encryption_key key to use
  89. */
  90. void SPProtoDecoder_SetEncryptionKey (SPProtoDecoder *o, uint8_t *encryption_key);
  91. /**
  92. * Removes an encryption key if one is configured.
  93. * Encryption must be enabled.
  94. *
  95. * @param o the object
  96. */
  97. void SPProtoDecoder_RemoveEncryptionKey (SPProtoDecoder *o);
  98. /**
  99. * Adds a new OTP seed to check received packets against.
  100. * OTPs must be enabled.
  101. *
  102. * @param o the object
  103. * @param seed_id seed identifier
  104. * @param key OTP encryption key
  105. * @param iv OTP initialization vector
  106. */
  107. void SPProtoDecoder_AddOTPSeed (SPProtoDecoder *o, uint16_t seed_id, uint8_t *key, uint8_t *iv);
  108. /**
  109. * Removes all OTP seeds for checking received packets against.
  110. * OTPs must be enabled.
  111. *
  112. * @param o the object
  113. */
  114. void SPProtoDecoder_RemoveOTPSeeds (SPProtoDecoder *o);
  115. #endif