MIKEY.hh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**********
  2. This library is free software; you can redistribute it and/or modify it under
  3. the terms of the GNU Lesser General Public License as published by the
  4. Free Software Foundation; either version 3 of the License, or (at your
  5. option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
  6. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // "liveMedia"
  15. // Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved.
  16. // A data structure that implements a MIKEY message (RFC 3830)
  17. // C++ header
  18. #ifndef _MIKEY_HH
  19. #define _MIKEY_HH
  20. #ifndef _NET_COMMON_H
  21. #include "NetCommon.h"
  22. #endif
  23. #ifndef _BOOLEAN_HH
  24. #include "Boolean.hh"
  25. #endif
  26. class MIKEYState {
  27. public:
  28. MIKEYState(); // initialize with default parameters
  29. virtual ~MIKEYState();
  30. static MIKEYState* createNew(u_int8_t* messageToParse, unsigned messageSize);
  31. // (Attempts to) parse a binary MIKEY message, returning a new "MIKEYState" if successful
  32. // (or NULL if unsuccessful).
  33. // ("messageToParse" is assumed to have been dynamically allocated;
  34. // this function will delete[] it.)
  35. u_int8_t* generateMessage(unsigned& messageSize) const;
  36. // Returns a binary message representing the current MIKEY state, of size "messageSize" bytes.
  37. // This array is dynamically allocated by this routine, and must be delete[]d by the caller.
  38. // Accessors for the encryption/authentication parameters:
  39. Boolean encryptSRTP() const { return fEncryptSRTP; }
  40. Boolean encryptSRTCP() const { return fEncryptSRTCP; }
  41. u_int8_t const* keyData() const { return fKeyData; }
  42. u_int32_t MKI() const { return fMKI; }
  43. Boolean useAuthentication() const { return fUseAuthentication; }
  44. private:
  45. MIKEYState(u_int8_t const* messageToParse, unsigned messageSize, Boolean& parsedOK);
  46. // called only by "createNew()"
  47. void addNewPayload(class MIKEYPayload* newPayload);
  48. Boolean parseHDRPayload(u_int8_t const*& ptr, u_int8_t const* endPtr, u_int8_t& nextPayloadType);
  49. Boolean parseNonHDRPayload(u_int8_t const*& ptr, u_int8_t const* endPtr, u_int8_t& nextPayloadType);
  50. private:
  51. // Encryption/authentication parameters, either set by default
  52. // (if the first (parameterless) constructor is used), or set by parsing an input message
  53. // (if the second constructor is used):
  54. Boolean fEncryptSRTP;
  55. Boolean fEncryptSRTCP;
  56. u_int8_t fKeyData[16+14]; // encryption key + salt
  57. u_int32_t fMKI; // used only if encryption is used. (We assume a MKI length of 4.)
  58. Boolean fUseAuthentication;
  59. // Our internal binary representation of the MIKEY payloads:
  60. class MIKEYPayload* fHeaderPayload;
  61. class MIKEYPayload* fTailPayload;
  62. unsigned fTotalPayloadByteCount;
  63. };
  64. #endif