PcapPlusPlus  20.08
SSLHandshake.h
Go to the documentation of this file.
1 #ifndef PACKETPP_SSL_HANDSHAKE_MESSAGE
2 #define PACKETPP_SSL_HANDSHAKE_MESSAGE
3 
4 #include "SSLCommon.h"
5 #include "PointerVector.h"
6 
16 namespace pcpp
17 {
18 
19 
30 {
31 public:
41  SSLCipherSuite(uint16_t id, SSLKeyExchangeAlgorithm keyExAlg,
44  SSLHashingAlgorithm MACAlg,
45  const char* name)
46  : m_Id(id), m_KeyExAlg(keyExAlg), m_AuthAlg(authAlg), m_SymKeyAlg(symKeyAlg), m_MACAlg(MACAlg), m_Name(name) {}
47 
51  uint16_t getID() const { return m_Id; }
52 
56  std::string asString() const { return m_Name; }
57 
61  SSLKeyExchangeAlgorithm getKeyExchangeAlg() const { return m_KeyExAlg; }
62 
66  SSLAuthenticationAlgorithm getAuthAlg() const { return m_AuthAlg; }
67 
71  SSLSymetricEncryptionAlgorithm getSymKeyAlg() const { return m_SymKeyAlg; }
72 
76  SSLHashingAlgorithm getMACAlg() const { return m_MACAlg; }
77 
83  static SSLCipherSuite* getCipherSuiteByID(uint16_t id);
84 
90  static SSLCipherSuite* getCipherSuiteByName(std::string name);
91 
92 private:
93  uint16_t m_Id;
94  SSLKeyExchangeAlgorithm m_KeyExAlg;
97  SSLHashingAlgorithm m_MACAlg;
98  std::string m_Name;
99 };
100 
101 
109 {
110 public:
115  SSLExtension(uint8_t* data);
116 
117  virtual ~SSLExtension() { }
118 
122  SSLExtensionType getType() const;
123 
127  uint16_t getTypeAsInt() const;
128 
132  uint16_t getLength() const;
133 
137  uint16_t getTotalLength() const;
138 
142  uint8_t* getData() const;
143 
144 protected:
145 
151  {
153  uint16_t extensionType;
157  uint8_t extensionData[];
158  };
159 
160  uint8_t* m_RawData;
161 
162  SSLExtensionStruct* getExtensionStruct() const { return (SSLExtensionStruct*)m_RawData; }
163 };
164 
165 
172 {
173 public:
179 
183  std::string getHostName() const;
184 };
185 
186 
194 {
195 public:
196 
205  SSLx509Certificate(uint8_t* data, size_t dataLen, bool allDataExists)
206  : m_Data(data), m_DataLen(dataLen), m_AllDataExists(allDataExists) {}
207 
211  uint8_t* getData() const { return m_Data; }
212 
216  size_t getDataLength() const { return m_DataLen; }
217 
223  bool allDataExists() const { return m_AllDataExists; }
224 
225 private:
226  uint8_t* m_Data;
227  size_t m_DataLen;
228  bool m_AllDataExists;
229 };
230 
231 
232 class SSLHandshakeLayer;
233 
234 
244 {
245 public:
246 
247  virtual ~SSLHandshakeMessage() {}
248 
256  static SSLHandshakeMessage* createHandhakeMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container);
257 
261  virtual SSLHandshakeType getHandshakeType() const;
262 
267  virtual size_t getMessageLength() const;
268 
275  virtual bool isMessageComplete() const;
276 
280  SSLHandshakeLayer* getContainingLayer() const { return m_Container; }
281 
285  virtual std::string toString() const = 0;
286 
287 protected:
288 
289  SSLHandshakeMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container);
290 
291  uint8_t* m_Data;
292  size_t m_DataLen;
293  SSLHandshakeLayer* m_Container;
294 
295 };
296 
297 
304 {
305 public:
306 
314  SSLClientHelloMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container);
315 
316  virtual ~SSLClientHelloMessage() {}
317 
323 
328  SSLVersion getHandshakeVersion() const;
329 
333  uint8_t getSessionIDLength() const;
334 
338  uint8_t* getSessionID() const;
339 
343  int getCipherSuiteCount() const;
344 
352  SSLCipherSuite* getCipherSuite(int index) const;
353 
357  uint8_t getCompressionMethodsValue() const;
358 
362  int getExtensionCount() const;
363 
367  uint16_t getExtensionsLenth() const;
368 
376  SSLExtension* getExtension(int index) const;
377 
385  SSLExtension* getExtensionOfType(uint16_t type) const;
386 
392  SSLExtension* getExtensionOfType(SSLExtensionType type) const;
393 
400  template<class TExtension>
401  TExtension* getExtensionOfType() const;
402 
403  // implement abstract methods
404 
405  std::string toString() const;
406 
407 private:
408  PointerVector<SSLExtension> m_ExtensionList;
409 
410 };
411 
412 
419 {
420 public:
421 
429  SSLServerHelloMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container);
430 
431  virtual ~SSLServerHelloMessage() {}
432 
438 
443  SSLVersion getHandshakeVersion() const;
444 
448  uint8_t getSessionIDLength() const;
449 
453  uint8_t* getSessionID() const;
454 
459  SSLCipherSuite* getCipherSuite() const;
460 
464  uint8_t getCompressionMethodsValue() const;
465 
469  int getExtensionCount() const;
470 
474  uint16_t getExtensionsLenth() const;
475 
483  SSLExtension* getExtension(int index) const;
484 
492  SSLExtension* getExtensionOfType(uint16_t type) const;
493 
499  SSLExtension* getExtensionOfType(SSLExtensionType type) const;
500 
507  template<class TExtension>
508  TExtension* getExtensionOfType() const;
509 
510  // implement abstract methods
511 
512  std::string toString() const;
513 
514 private:
515  PointerVector<SSLExtension> m_ExtensionList;
516 };
517 
518 
528 {
529 public:
530 
538  SSLCertificateMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container);
539 
540  virtual ~SSLCertificateMessage() {}
541 
549  int getNumOfCertificates() const;
550 
557  SSLx509Certificate* getCertificate(int index) const;
558 
559  // implement abstract methods
560 
561  std::string toString() const;
562 
563 private:
564  PointerVector<SSLx509Certificate> m_CertificateList;
565 };
566 
567 
574 {
575 public:
576 
584  SSLHelloRequestMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
585 
586  virtual ~SSLHelloRequestMessage() {}
587 
588  // implement abstract methods
589 
590  std::string toString() const;
591 };
592 
593 
601 {
602 public:
603 
611  SSLServerKeyExchangeMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
612 
614 
620  uint8_t* getServerKeyExchangeParams() const;
621 
628  size_t getServerKeyExchangeParamsLength() const;
629 
630  // implement abstract methods
631 
632  std::string toString() const;
633 };
634 
635 
643 {
644 public:
645 
653  SSLClientKeyExchangeMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
654 
656 
662  uint8_t* getClientKeyExchangeParams() const;
663 
670  size_t getClientKeyExchangeParamsLength() const;
671 
672  // implement abstract methods
673 
674  std::string toString() const;
675 };
676 
677 
684 {
685 public:
686 
694  SSLCertificateRequestMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container);
695 
697 
701  std::vector<SSLClientCertificateType>& getCertificateTypes();
702 
708  uint8_t* getCertificateAuthorityData() const;
709 
716  size_t getCertificateAuthorityLength() const;
717 
718  // implement abstract methods
719 
720  std::string toString() const;
721 
722 private:
723  std::vector<SSLClientCertificateType> m_ClientCertificateTypes;
724 };
725 
726 
733 {
734 public:
735 
743  SSLServerHelloDoneMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
744 
745  virtual ~SSLServerHelloDoneMessage() {}
746 
747  // implement abstract methods
748 
749  std::string toString() const;
750 };
751 
752 
760 {
761 public:
762 
770  SSLCertificateVerifyMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
771 
772  virtual ~SSLCertificateVerifyMessage() {}
773 
779  uint8_t* getSignedHash() const;
780 
787  size_t getSignedHashLength() const;
788 
789  // implement abstract methods
790 
791  std::string toString() const;
792 };
793 
794 
802 {
803 public:
804 
812  SSLFinishedMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
813 
814  virtual ~SSLFinishedMessage() {}
815 
821  uint8_t* getSignedHash() const;
822 
829  size_t getSignedHashLength() const;
830 
831  // implement abstract methods
832 
833  std::string toString() const;
834 };
835 
836 
843 {
844 public:
845 
853  SSLNewSessionTicketMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
854 
855  virtual ~SSLNewSessionTicketMessage() {}
856 
862  uint8_t* getSessionTicketData() const;
863 
870  size_t getSessionTicketDataLength() const;
871 
872  // implement abstract methods
873 
874  std::string toString() const;
875 };
876 
877 
885 {
886 public:
887 
895  SSLUnknownMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
896 
897  virtual ~SSLUnknownMessage() {}
898 
899  // implement virtual and abstract methods
900 
904  SSLHandshakeType getHandshakeType() const;
905 
911  size_t getMessageLength() const;
912 
913  std::string toString() const;
914 };
915 
916 template<class TExtension>
918 {
919  size_t vecSize = m_ExtensionList.size();
920  for (size_t i = 0; i < vecSize; i++)
921  {
922  SSLExtension* curElem = const_cast<SSLExtension*>(m_ExtensionList.at(i));
923  if (dynamic_cast<TExtension*>(curElem) != NULL)
924  return (TExtension*)curElem;
925  }
926 
927  return NULL;
928 }
929 
930 template<class TExtension>
932 {
933  size_t vecSize = m_ExtensionList.size();
934  for (size_t i = 0; i < vecSize; i++)
935  {
936  SSLExtension* curElem = const_cast<SSLExtension*>(m_ExtensionList.at(i));
937  if (dynamic_cast<TExtension*>(curElem) != NULL)
938  return (TExtension*)curElem;
939  }
940 
941  return NULL;
942 }
943 
944 } // namespace pcpp
945 
946 #endif /* PACKETPP_SSL_HANDSHAKE_MESSAGE */
The main namespace for the PcapPlusPlus lib.
static SSLCipherSuite * getCipherSuiteByID(uint16_t id)
Definition: SSLHandshake.h:193
bool allDataExists() const
Definition: SSLHandshake.h:223
uint16_t extensionDataLength
Definition: SSLHandshake.h:155
SSLSymetricEncryptionAlgorithm getSymKeyAlg() const
Definition: SSLHandshake.h:71
SSLHandshakeLayer * getContainingLayer() const
Definition: SSLHandshake.h:280
SSLVersion
Definition: SSLCommon.h:112
SSLKeyExchangeAlgorithm
Definition: SSLCommon.h:232
uint16_t getID() const
Definition: SSLHandshake.h:51
SSLUnknownMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:895
Definition: PointerVector.h:24
Definition: SSLLayer.h:308
Definition: SSLHandshake.h:171
Definition: SSLHandshake.h:732
SSLExtensionType
Definition: SSLCommon.h:404
SSLServerNameIndicationExtension(uint8_t *data)
Definition: SSLHandshake.h:178
SSLAuthenticationAlgorithm
Definition: SSLCommon.h:265
size_t getDataLength() const
Definition: SSLHandshake.h:216
SSLFinishedMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:812
Definition: SSLHandshake.h:108
Definition: SSLHandshake.h:801
SSLClientKeyExchangeMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:653
ssl_tls_client_server_hello * getClientHelloHeader() const
Definition: SSLHandshake.h:322
SSLHandshakeType
Definition: SSLCommon.h:129
Definition: SSLHandshake.h:527
Definition: SSLHandshake.h:759
Definition: SSLHandshake.h:600
Definition: SSLHandshake.h:418
SSLSymetricEncryptionAlgorithm
Definition: SSLCommon.h:298
TExtension * getExtensionOfType() const
Definition: SSLHandshake.h:917
static SSLCipherSuite * getCipherSuiteByName(std::string name)
Definition: SSLHandshake.h:573
SSLHelloRequestMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:584
SSLx509Certificate(uint8_t *data, size_t dataLen, bool allDataExists)
Definition: SSLHandshake.h:205
Definition: SSLHandshake.h:243
ssl_tls_client_server_hello * getServerHelloHeader() const
Definition: SSLHandshake.h:437
SSLNewSessionTicketMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:853
Definition: SSLHandshake.h:642
SSLHashingAlgorithm
Definition: SSLCommon.h:377
SSLHashingAlgorithm getMACAlg() const
Definition: SSLHandshake.h:76
SSLCipherSuite(uint16_t id, SSLKeyExchangeAlgorithm keyExAlg, SSLAuthenticationAlgorithm authAlg, SSLSymetricEncryptionAlgorithm symKeyAlg, SSLHashingAlgorithm MACAlg, const char *name)
Definition: SSLHandshake.h:41
SSLKeyExchangeAlgorithm getKeyExchangeAlg() const
Definition: SSLHandshake.h:61
Definition: SSLHandshake.h:884
Definition: SSLHandshake.h:150
uint8_t * getData() const
Definition: SSLHandshake.h:211
Definition: SSLCommon.h:56
SSLServerHelloDoneMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:743
SSLServerKeyExchangeMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:611
uint16_t extensionType
Definition: SSLHandshake.h:153
SSLCertificateVerifyMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:770
Definition: SSLHandshake.h:29
Definition: SSLHandshake.h:303
Definition: SSLHandshake.h:683
std::string asString() const
Definition: SSLHandshake.h:56
SSLAuthenticationAlgorithm getAuthAlg() const
Definition: SSLHandshake.h:66
TExtension * getExtensionOfType() const
Definition: SSLHandshake.h:931
Definition: SSLHandshake.h:842