tls_protection.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2010 Martin Willi
  3. * Copyright (C) 2010 revosec AG
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. */
  15. /**
  16. * @defgroup tls_protection tls_protection
  17. * @{ @ingroup libtls
  18. */
  19. #ifndef TLS_PROTECTION_H_
  20. #define TLS_PROTECTION_H_
  21. #include <library.h>
  22. typedef struct tls_protection_t tls_protection_t;
  23. #include "tls.h"
  24. #include "tls_aead.h"
  25. #include "tls_alert.h"
  26. #include "tls_compression.h"
  27. /**
  28. * TLS record protocol protection layer.
  29. */
  30. struct tls_protection_t {
  31. /**
  32. * Process a protected TLS record, pass it to upper layers.
  33. *
  34. * @param type type of the TLS record to process
  35. * @param data associated TLS record data
  36. * @return
  37. * - SUCCESS if TLS negotiation complete
  38. * - FAILED if TLS handshake failed
  39. * - NEED_MORE if more invocations to process/build needed
  40. */
  41. status_t (*process)(tls_protection_t *this,
  42. tls_content_type_t type, chunk_t data);
  43. /**
  44. * Query upper layer for TLS record, build protected record.
  45. *
  46. * @param type type of the built TLS record
  47. * @param data allocated data of the built TLS record
  48. * @return
  49. * - SUCCESS if TLS negotiation complete
  50. * - FAILED if TLS handshake failed
  51. * - NEED_MORE if upper layers have more records to send
  52. * - INVALID_STATE if more input records required
  53. */
  54. status_t (*build)(tls_protection_t *this,
  55. tls_content_type_t *type, chunk_t *data);
  56. /**
  57. * Set a new transforms to use at protection layer
  58. *
  59. * @param inbound TRUE to use cipher for inbound data, FALSE for outbound
  60. * @param aead new AEAD transform
  61. */
  62. void (*set_cipher)(tls_protection_t *this, bool inbound, tls_aead_t *aead);
  63. /**
  64. * Set the TLS version negotiated, used for MAC calculation.
  65. *
  66. * @param version TLS version negotiated
  67. */
  68. void (*set_version)(tls_protection_t *this, tls_version_t version);
  69. /**
  70. * Destroy a tls_protection_t.
  71. */
  72. void (*destroy)(tls_protection_t *this);
  73. };
  74. /**
  75. * Create a tls_protection instance.
  76. *
  77. * @param compression compression layer of TLS stack
  78. * @param alert TLS alert handler
  79. * @return TLS protection layer.
  80. */
  81. tls_protection_t *tls_protection_create(tls_compression_t *compression,
  82. tls_alert_t *alert);
  83. #endif /** TLS_PROTECTION_H_ @}*/