OpenDDS  Snapshot(2023/04/28-20:55)
Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
OpenDDS::STUN::Message Struct Reference

#include <Stun.h>

Collaboration diagram for OpenDDS::STUN::Message:
Collaboration graph
[legend]

Public Types

typedef std::vector< AttributeAttributesType
 
typedef AttributesType::const_iterator const_iterator
 

Public Member Functions

 Message ()
 
void generate_transaction_id ()
 
void clear_transaction_id ()
 
void append_attribute (const Attribute &attribute)
 
const_iterator begin () const
 
const_iterator end () const
 
ACE_UINT16 length () const
 
ACE_UINT16 length_for_message_integrity () const
 
std::vector< AttributeTypeunknown_comprehension_required_attributes () const
 
bool get_mapped_address (ACE_INET_Addr &address) const
 
bool get_priority (ACE_UINT32 &priority) const
 
bool get_username (std::string &username) const
 
bool has_message_integrity () const
 
bool verify_message_integrity (const std::string &password) const
 
void compute_message_integrity (const std::string &password, unsigned char message_integrity[20]) const
 
bool has_error_code () const
 
ACE_UINT16 get_error_code () const
 
std::string get_error_reason () const
 
bool has_unknown_attributes () const
 
std::vector< AttributeTypeget_unknown_attributes () const
 
bool has_fingerprint () const
 
ACE_UINT32 compute_fingerprint () const
 
bool has_ice_controlled () const
 
bool has_ice_controlling () const
 
bool has_use_candidate () const
 
bool get_guid_prefix (DCPS::GuidPrefix_t &guid_pefix) const
 

Public Attributes

Class class_
 
Method method
 
TransactionId transaction_id
 
ACE_Message_Blockblock
 
std::string password
 

Private Attributes

AttributesType attributes_
 
ACE_UINT16 length_
 
ACE_UINT16 length_for_message_integrity_
 

Detailed Description

Definition at line 180 of file Stun.h.

Member Typedef Documentation

◆ AttributesType

Definition at line 181 of file Stun.h.

◆ const_iterator

typedef AttributesType::const_iterator OpenDDS::STUN::Message::const_iterator

Definition at line 182 of file Stun.h.

Constructor & Destructor Documentation

◆ Message()

OpenDDS::STUN::Message::Message ( )
inline

Definition at line 188 of file Stun.h.

Member Function Documentation

◆ append_attribute()

void OpenDDS::STUN::Message::append_attribute ( const Attribute attribute)
inline

◆ begin()

const_iterator OpenDDS::STUN::Message::begin ( void  ) const
inline

Definition at line 205 of file Stun.h.

Referenced by OpenDDS::STUN::operator<<().

206  {
207  return attributes_.begin();
208  }
AttributesType attributes_
Definition: Stun.h:245

◆ clear_transaction_id()

void OpenDDS::STUN::Message::clear_transaction_id ( )

Definition at line 611 of file Stun.cpp.

References ACE_OS::memset().

Referenced by OpenDDS::ICE::EndpointManager::EndpointManager().

612 {
614 }
ACE_UINT8 data[12]
Definition: Stun.h:144
void * memset(void *s, int c, size_t len)
TransactionId transaction_id
Definition: Stun.h:186

◆ compute_fingerprint()

ACE_UINT32 OpenDDS::STUN::Message::compute_fingerprint ( ) const

Definition at line 808 of file Stun.cpp.

References ACE_Message_Block::base(), ACE::crc32(), ACE_Message_Block::duplicate(), OpenDDS::STUN::encoding(), OpenDDS::STUN::HEADER_SIZE, ACE_Message_Block::length(), OpenDDS::STUN::Attribute::length(), ACE_Message_Block::rd_ptr(), ACE_Message_Block::release(), and ACE_Message_Block::wr_ptr().

Referenced by OpenDDS::STUN::operator<<(), and OpenDDS::STUN::operator>>().

809 {
810  ACE_Message_Block* block = this->block->duplicate();
811  block->rd_ptr(block->base());
812  DCPS::Serializer serializer(block, encoding);
813 
814  // Resize for hashing.
815  block->wr_ptr(block->base() + HEADER_SIZE + length() - 8);
816 
817  // Compute the CRC-32
818  ACE_UINT32 crc = ACE::crc32(block->rd_ptr(), block->length());
819 
820  block->release();
821 
822  return crc ^ 0x5354554E;
823 }
size_t length(void) const
const size_t HEADER_SIZE
Definition: Stun.h:49
char * rd_ptr(void) const
virtual ACE_Message_Block * release(void)
ACE_Message_Block * block
Definition: Stun.h:241
virtual ACE_Message_Block * duplicate(void) const
char * wr_ptr(void) const
ACE_UINT32 crc32(const char *str)
ACE_UINT16 length() const
Definition: Stun.h:213
const DCPS::Encoding encoding(DCPS::Encoding::KIND_UNALIGNED_CDR, DCPS::ENDIAN_BIG)
char * base(void) const

◆ compute_message_integrity()

void OpenDDS::STUN::Message::compute_message_integrity ( const std::string &  password,
unsigned char  message_integrity[20] 
) const

Definition at line 719 of file Stun.cpp.

References ACE_Message_Block::base(), ACE_Message_Block::duplicate(), OpenDDS::STUN::encoding(), OpenDDS::STUN::HEADER_SIZE, ACE_Message_Block::length(), OpenDDS::STUN::Attribute::length(), ACE_Message_Block::rd_ptr(), ACE_Message_Block::release(), TheSecurityRegistry, and ACE_Message_Block::wr_ptr().

Referenced by OpenDDS::STUN::operator<<().

720 {
721  ACE_Message_Block* block = this->block->duplicate();
722  block->rd_ptr(block->base());
723  DCPS::Serializer serializer(block, encoding);
724 
725  // Write the length and resize for hashing.
726  block->wr_ptr(block->base() + 2);
727  ACE_UINT16 message_length = length_for_message_integrity();
728  serializer << message_length;
729  block->wr_ptr(block->base() + HEADER_SIZE + length_for_message_integrity() - 24);
730 
731  // Compute the SHA1.
732  TheSecurityRegistry->builtin_config()->get_utility()->hmac(message_integrity, block->rd_ptr(), block->length(), password);
733 
734  // Write the correct length.
735  block->wr_ptr(block->base() + 2);
736  message_length = length();
737  serializer << message_length;
738 
739  block->release();
740 }
size_t length(void) const
const size_t HEADER_SIZE
Definition: Stun.h:49
char * rd_ptr(void) const
ACE_UINT16 length_for_message_integrity() const
Definition: Stun.h:217
virtual ACE_Message_Block * release(void)
ACE_Message_Block * block
Definition: Stun.h:241
#define TheSecurityRegistry
virtual ACE_Message_Block * duplicate(void) const
char * wr_ptr(void) const
ACE_UINT16 length() const
Definition: Stun.h:213
std::string password
Definition: Stun.h:242
const DCPS::Encoding encoding(DCPS::Encoding::KIND_UNALIGNED_CDR, DCPS::ENDIAN_BIG)
char * base(void) const

◆ end()

const_iterator OpenDDS::STUN::Message::end ( void  ) const
inline

Definition at line 209 of file Stun.h.

Referenced by OpenDDS::STUN::operator<<().

210  {
211  return attributes_.end();
212  }
AttributesType attributes_
Definition: Stun.h:245

◆ generate_transaction_id()

void OpenDDS::STUN::Message::generate_transaction_id ( )

Definition at line 606 of file Stun.cpp.

References TheSecurityRegistry.

Referenced by OpenDDS::ICE::ConnectivityCheck::ConnectivityCheck(), OpenDDS::ICE::Checklist::execute(), and OpenDDS::ICE::EndpointManager::server_reflexive_task().

607 {
608  TheSecurityRegistry->builtin_config()->get_utility()->generate_random_bytes(transaction_id.data, sizeof(transaction_id.data));
609 }
ACE_UINT8 data[12]
Definition: Stun.h:144
#define TheSecurityRegistry
TransactionId transaction_id
Definition: Stun.h:186

◆ get_error_code()

ACE_UINT16 OpenDDS::STUN::Message::get_error_code ( ) const

Definition at line 753 of file Stun.cpp.

References OpenDDS::STUN::ERROR_CODE.

Referenced by OpenDDS::ICE::Checklist::error_response(), OpenDDS::ICE::EndpointManager::error_response(), and OpenDDS::ICE::ServerReflexiveStateMachine::error_response().

754 {
755  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
756  if (pos->type == STUN::ERROR_CODE) {
757  return pos->error.code;
758  }
759  }
760 
761  return 0;
762 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ get_error_reason()

std::string OpenDDS::STUN::Message::get_error_reason ( ) const

Definition at line 764 of file Stun.cpp.

References OpenDDS::STUN::ERROR_CODE.

Referenced by OpenDDS::ICE::Checklist::error_response(), OpenDDS::ICE::EndpointManager::error_response(), and OpenDDS::ICE::ServerReflexiveStateMachine::error_response().

765 {
766  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
767  if (pos->type == STUN::ERROR_CODE) {
768  return pos->error.reason;
769  }
770  }
771 
772  return std::string();
773 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ get_guid_prefix()

bool OpenDDS::STUN::Message::get_guid_prefix ( DCPS::GuidPrefix_t guid_pefix) const

Definition at line 858 of file Stun.cpp.

References OpenDDS::STUN::GUID_PREFIX.

859 {
860  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
861  if (pos->type == STUN::GUID_PREFIX) {
862  std::memcpy(guid_prefix, pos->guid_prefix, sizeof(guid_prefix));
863  return true;
864  }
865  }
866 
867  return false;
868 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ get_mapped_address()

bool OpenDDS::STUN::Message::get_mapped_address ( ACE_INET_Addr address) const

Definition at line 643 of file Stun.cpp.

References OpenDDS::STUN::MAPPED_ADDRESS, and OpenDDS::STUN::XOR_MAPPED_ADDRESS.

Referenced by OpenDDS::ICE::Checklist::success_response(), OpenDDS::ICE::EndpointManager::success_response(), and OpenDDS::ICE::ServerReflexiveStateMachine::success_response().

644 {
645  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
646  if (pos->type == STUN::XOR_MAPPED_ADDRESS) {
647  address = pos->mapped_address;
648  return true;
649  }
650  }
651 
652  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
653  if (pos->type == STUN::MAPPED_ADDRESS) {
654  address = pos->mapped_address;
655  return true;
656  }
657  }
658 
659  return false;
660 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ get_priority()

bool OpenDDS::STUN::Message::get_priority ( ACE_UINT32 &  priority) const

Definition at line 662 of file Stun.cpp.

References OpenDDS::STUN::PRIORITY.

Referenced by OpenDDS::ICE::EndpointManager::request().

663 {
664  bool flag = false;
665 
666  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
667  if (pos->type == STUN::PRIORITY) {
668  flag = true;
669  priority = pos->priority;
670  // Use the last.
671  }
672  }
673 
674  return flag;
675 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ get_unknown_attributes()

std::vector< AttributeType > OpenDDS::STUN::Message::get_unknown_attributes ( ) const

Definition at line 786 of file Stun.cpp.

References OpenDDS::STUN::UNKNOWN_ATTRIBUTES.

Referenced by OpenDDS::ICE::Checklist::error_response(), OpenDDS::ICE::EndpointManager::error_response(), and OpenDDS::ICE::ServerReflexiveStateMachine::error_response().

787 {
788  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
789  if (pos->type == STUN::UNKNOWN_ATTRIBUTES) {
790  return pos->unknown_attributes;
791  }
792  }
793 
794  return std::vector<AttributeType>();
795 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ get_username()

bool OpenDDS::STUN::Message::get_username ( std::string &  username) const

Definition at line 677 of file Stun.cpp.

References OpenDDS::STUN::USERNAME.

Referenced by OpenDDS::ICE::EndpointManager::indication(), and OpenDDS::ICE::EndpointManager::request().

678 {
679  bool flag = false;
680 
681  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
682  if (pos->type == STUN::USERNAME) {
683  flag = true;
684  username = pos->username;
685  // Use the last.
686  }
687  }
688 
689  return flag;
690 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ has_error_code()

bool OpenDDS::STUN::Message::has_error_code ( ) const

Definition at line 742 of file Stun.cpp.

References OpenDDS::STUN::ERROR_CODE.

Referenced by OpenDDS::ICE::Checklist::error_response(), OpenDDS::ICE::EndpointManager::error_response(), and OpenDDS::ICE::ServerReflexiveStateMachine::error_response().

743 {
744  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
745  if (pos->type == STUN::ERROR_CODE) {
746  return true;
747  }
748  }
749 
750  return false;
751 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ has_fingerprint()

bool OpenDDS::STUN::Message::has_fingerprint ( ) const

Definition at line 797 of file Stun.cpp.

References OpenDDS::STUN::FINGERPRINT.

Referenced by OpenDDS::ICE::Checklist::error_response(), OpenDDS::ICE::EndpointManager::indication(), OpenDDS::ICE::EndpointManager::request(), and OpenDDS::ICE::Checklist::success_response().

798 {
799  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
800  if (pos->type == STUN::FINGERPRINT) {
801  return true;
802  }
803  }
804 
805  return false;
806 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ has_ice_controlled()

bool OpenDDS::STUN::Message::has_ice_controlled ( ) const

Definition at line 825 of file Stun.cpp.

References OpenDDS::STUN::ICE_CONTROLLED.

Referenced by OpenDDS::ICE::EndpointManager::request().

826 {
827  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
828  if (pos->type == STUN::ICE_CONTROLLED) {
829  return true;
830  }
831  }
832 
833  return false;
834 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ has_ice_controlling()

bool OpenDDS::STUN::Message::has_ice_controlling ( ) const

Definition at line 836 of file Stun.cpp.

References OpenDDS::STUN::ICE_CONTROLLING.

Referenced by OpenDDS::ICE::EndpointManager::request().

837 {
838  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
839  if (pos->type == STUN::ICE_CONTROLLING) {
840  return true;
841  }
842  }
843 
844  return false;
845 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ has_message_integrity()

bool OpenDDS::STUN::Message::has_message_integrity ( ) const

Definition at line 692 of file Stun.cpp.

References OpenDDS::STUN::MESSAGE_INTEGRITY.

Referenced by OpenDDS::ICE::Checklist::error_response(), OpenDDS::ICE::EndpointManager::indication(), OpenDDS::ICE::EndpointManager::request(), and OpenDDS::ICE::Checklist::success_response().

693 {
694  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
695  if (pos->type == STUN::MESSAGE_INTEGRITY) {
696  return true;
697  }
698  }
699 
700  return false;
701 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ has_unknown_attributes()

bool OpenDDS::STUN::Message::has_unknown_attributes ( ) const

Definition at line 775 of file Stun.cpp.

References OpenDDS::STUN::UNKNOWN_ATTRIBUTES.

Referenced by OpenDDS::ICE::Checklist::error_response(), OpenDDS::ICE::EndpointManager::error_response(), and OpenDDS::ICE::ServerReflexiveStateMachine::error_response().

776 {
777  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
778  if (pos->type == STUN::UNKNOWN_ATTRIBUTES) {
779  return true;
780  }
781  }
782 
783  return false;
784 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ has_use_candidate()

bool OpenDDS::STUN::Message::has_use_candidate ( ) const

Definition at line 847 of file Stun.cpp.

References OpenDDS::STUN::USE_CANDIDATE.

Referenced by OpenDDS::ICE::EndpointManager::request().

848 {
849  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
850  if (pos->type == STUN::USE_CANDIDATE) {
851  return true;
852  }
853  }
854 
855  return false;
856 }
const_iterator begin() const
Definition: Stun.h:205
const_iterator end() const
Definition: Stun.h:209
AttributesType::const_iterator const_iterator
Definition: Stun.h:182

◆ length()

ACE_UINT16 OpenDDS::STUN::Message::length ( void  ) const
inline

Definition at line 213 of file Stun.h.

Referenced by OpenDDS::STUN::operator<<(), OpenDDS::STUN::operator>>(), and OpenDDS::DCPS::RtpsUdpTransport::IceEndpoint::send().

214  {
215  return length_;
216  }
ACE_UINT16 length_
Definition: Stun.h:246

◆ length_for_message_integrity()

ACE_UINT16 OpenDDS::STUN::Message::length_for_message_integrity ( ) const
inline

Definition at line 217 of file Stun.h.

218  {
220  }
ACE_UINT16 length_for_message_integrity_
Definition: Stun.h:247

◆ unknown_comprehension_required_attributes()

std::vector< AttributeType > OpenDDS::STUN::Message::unknown_comprehension_required_attributes ( ) const

Definition at line 616 of file Stun.cpp.

References OpenDDS::STUN::ERROR_CODE, OpenDDS::STUN::MAPPED_ADDRESS, OpenDDS::STUN::MESSAGE_INTEGRITY, OpenDDS::STUN::PRIORITY, OpenDDS::STUN::UNKNOWN_ATTRIBUTES, OpenDDS::STUN::USE_CANDIDATE, OpenDDS::STUN::USERNAME, and OpenDDS::STUN::XOR_MAPPED_ADDRESS.

Referenced by OpenDDS::ICE::Checklist::error_response(), OpenDDS::ICE::EndpointManager::indication(), OpenDDS::ICE::EndpointManager::request(), OpenDDS::ICE::Checklist::success_response(), OpenDDS::ICE::EndpointManager::success_response(), and OpenDDS::ICE::ServerReflexiveStateMachine::success_response().

617 {
618  std::vector<AttributeType> retval;
619 
620  for (AttributesType::const_iterator pos = attributes_.begin(), limit = attributes_.end(); pos != limit; ++pos) {
621  const AttributesType::value_type& attribute = *pos;
622  switch (attribute.type) {
623  case MAPPED_ADDRESS:
624  case USERNAME:
625  case MESSAGE_INTEGRITY:
626  case ERROR_CODE:
627  case UNKNOWN_ATTRIBUTES:
628  case XOR_MAPPED_ADDRESS:
629  case PRIORITY:
630  case USE_CANDIDATE:
631  break;
632 
633  default:
634  if (attribute.type < 0x8000) {
635  retval.push_back(attribute.type);
636  }
637  }
638  }
639 
640  return retval;
641 }
AttributesType attributes_
Definition: Stun.h:245

◆ verify_message_integrity()

bool OpenDDS::STUN::Message::verify_message_integrity ( const std::string &  password) const

Definition at line 703 of file Stun.cpp.

References memcmp(), and OpenDDS::STUN::MESSAGE_INTEGRITY.

Referenced by OpenDDS::ICE::Checklist::error_response(), OpenDDS::ICE::EndpointManager::indication(), OpenDDS::ICE::EndpointManager::request(), and OpenDDS::ICE::Checklist::success_response().

704 {
705  bool verified = false;
706 
707  for (STUN::Message::const_iterator pos = begin(), limit = end(); pos != limit; ++pos) {
708  if (pos->type == STUN::MESSAGE_INTEGRITY) {
709  unsigned char computed_message_integrity[20];
710  compute_message_integrity(password, computed_message_integrity);
711  verified = memcmp(computed_message_integrity, pos->message_integrity, 20) == 0;
712  // Use the last.
713  }
714  }
715 
716  return verified;
717 }
const_iterator begin() const
Definition: Stun.h:205
void compute_message_integrity(const std::string &password, unsigned char message_integrity[20]) const
Definition: Stun.cpp:719
const_iterator end() const
Definition: Stun.h:209
int memcmp(const void *t, const void *s, size_t len)
AttributesType::const_iterator const_iterator
Definition: Stun.h:182
std::string password
Definition: Stun.h:242

Member Data Documentation

◆ attributes_

AttributesType OpenDDS::STUN::Message::attributes_
private

Definition at line 245 of file Stun.h.

◆ block

ACE_Message_Block* OpenDDS::STUN::Message::block

◆ class_

Class OpenDDS::STUN::Message::class_

◆ length_

ACE_UINT16 OpenDDS::STUN::Message::length_
private

Definition at line 246 of file Stun.h.

◆ length_for_message_integrity_

ACE_UINT16 OpenDDS::STUN::Message::length_for_message_integrity_
private

Definition at line 247 of file Stun.h.

◆ method

Method OpenDDS::STUN::Message::method

◆ password

std::string OpenDDS::STUN::Message::password

◆ transaction_id

TransactionId OpenDDS::STUN::Message::transaction_id

The documentation for this struct was generated from the following files: