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 
193 {
194 public:
199  SSLSupportedVersionsExtension(uint8_t* data) : SSLExtension(data) {}
200 
204  std::vector<SSLVersion> getSupportedVersions() const;
205 };
206 
207 
214 {
215  public:
220  TLSSupportedGroupsExtension(uint8_t* data) : SSLExtension(data) {}
221 
225  std::vector<uint16_t> getSupportedGroups() const;
226 };
227 
228 
235 {
236  public:
241  TLSECPointFormatExtension(uint8_t* data) : SSLExtension(data) {}
242 
246  std::vector<uint8_t> getECPointFormatList() const;
247 };
248 
249 
257 {
258 public:
259 
268  SSLx509Certificate(uint8_t* data, size_t dataLen, bool allDataExists)
269  : m_Data(data), m_DataLen(dataLen), m_AllDataExists(allDataExists) {}
270 
274  uint8_t* getData() const { return m_Data; }
275 
279  size_t getDataLength() const { return m_DataLen; }
280 
286  bool allDataExists() const { return m_AllDataExists; }
287 
288 private:
289  uint8_t* m_Data;
290  size_t m_DataLen;
291  bool m_AllDataExists;
292 };
293 
294 
295 class SSLHandshakeLayer;
296 
297 
307 {
308 public:
309 
310  virtual ~SSLHandshakeMessage() {}
311 
319  static SSLHandshakeMessage* createHandhakeMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container);
320 
324  virtual SSLHandshakeType getHandshakeType() const;
325 
330  virtual size_t getMessageLength() const;
331 
338  virtual bool isMessageComplete() const;
339 
343  SSLHandshakeLayer* getContainingLayer() const { return m_Container; }
344 
348  virtual std::string toString() const = 0;
349 
350 protected:
351 
352  SSLHandshakeMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container);
353 
354  uint8_t* m_Data;
355  size_t m_DataLen;
356  SSLHandshakeLayer* m_Container;
357 
358 };
359 
360 
367 {
368 public:
369 
377  SSLClientHelloMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container);
378 
379  virtual ~SSLClientHelloMessage() {}
380 
386 
391  SSLVersion getHandshakeVersion() const;
392 
396  uint8_t getSessionIDLength() const;
397 
401  uint8_t* getSessionID() const;
402 
406  int getCipherSuiteCount() const;
407 
415  SSLCipherSuite* getCipherSuite(int index) const;
416 
420  uint8_t getCompressionMethodsValue() const;
421 
425  int getExtensionCount() const;
426 
430  uint16_t getExtensionsLenth() const;
431 
439  SSLExtension* getExtension(int index) const;
440 
448  SSLExtension* getExtensionOfType(uint16_t type) const;
449 
455  SSLExtension* getExtensionOfType(SSLExtensionType type) const;
456 
463  template<class TExtension>
464  TExtension* getExtensionOfType() const;
465 
466  // implement abstract methods
467 
468  std::string toString() const;
469 
470 private:
471  PointerVector<SSLExtension> m_ExtensionList;
472 
473 };
474 
475 
482 {
483 public:
484 
492  SSLServerHelloMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container);
493 
494  virtual ~SSLServerHelloMessage() {}
495 
501 
510  SSLVersion getHandshakeVersion() const;
511 
515  uint8_t getSessionIDLength() const;
516 
520  uint8_t* getSessionID() const;
521 
526  SSLCipherSuite* getCipherSuite() const;
527 
531  uint8_t getCompressionMethodsValue() const;
532 
536  int getExtensionCount() const;
537 
541  uint16_t getExtensionsLenth() const;
542 
550  SSLExtension* getExtension(int index) const;
551 
559  SSLExtension* getExtensionOfType(uint16_t type) const;
560 
566  SSLExtension* getExtensionOfType(SSLExtensionType type) const;
567 
574  template<class TExtension>
575  TExtension* getExtensionOfType() const;
576 
577  // implement abstract methods
578 
579  std::string toString() const;
580 
581 private:
582  PointerVector<SSLExtension> m_ExtensionList;
583 };
584 
585 
595 {
596 public:
597 
605  SSLCertificateMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container);
606 
607  virtual ~SSLCertificateMessage() {}
608 
616  int getNumOfCertificates() const;
617 
624  SSLx509Certificate* getCertificate(int index) const;
625 
626  // implement abstract methods
627 
628  std::string toString() const;
629 
630 private:
631  PointerVector<SSLx509Certificate> m_CertificateList;
632 };
633 
634 
641 {
642 public:
643 
651  SSLHelloRequestMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
652 
653  virtual ~SSLHelloRequestMessage() {}
654 
655  // implement abstract methods
656 
657  std::string toString() const;
658 };
659 
660 
668 {
669 public:
670 
678  SSLServerKeyExchangeMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
679 
681 
687  uint8_t* getServerKeyExchangeParams() const;
688 
695  size_t getServerKeyExchangeParamsLength() const;
696 
697  // implement abstract methods
698 
699  std::string toString() const;
700 };
701 
702 
710 {
711 public:
712 
720  SSLClientKeyExchangeMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
721 
723 
729  uint8_t* getClientKeyExchangeParams() const;
730 
737  size_t getClientKeyExchangeParamsLength() const;
738 
739  // implement abstract methods
740 
741  std::string toString() const;
742 };
743 
744 
751 {
752 public:
753 
761  SSLCertificateRequestMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container);
762 
764 
768  std::vector<SSLClientCertificateType>& getCertificateTypes();
769 
775  uint8_t* getCertificateAuthorityData() const;
776 
783  size_t getCertificateAuthorityLength() const;
784 
785  // implement abstract methods
786 
787  std::string toString() const;
788 
789 private:
790  std::vector<SSLClientCertificateType> m_ClientCertificateTypes;
791 };
792 
793 
800 {
801 public:
802 
810  SSLServerHelloDoneMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
811 
812  virtual ~SSLServerHelloDoneMessage() {}
813 
814  // implement abstract methods
815 
816  std::string toString() const;
817 };
818 
819 
827 {
828 public:
829 
837  SSLCertificateVerifyMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
838 
839  virtual ~SSLCertificateVerifyMessage() {}
840 
846  uint8_t* getSignedHash() const;
847 
854  size_t getSignedHashLength() const;
855 
856  // implement abstract methods
857 
858  std::string toString() const;
859 };
860 
861 
869 {
870 public:
871 
879  SSLFinishedMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
880 
881  virtual ~SSLFinishedMessage() {}
882 
888  uint8_t* getSignedHash() const;
889 
896  size_t getSignedHashLength() const;
897 
898  // implement abstract methods
899 
900  std::string toString() const;
901 };
902 
903 
910 {
911 public:
912 
920  SSLNewSessionTicketMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
921 
922  virtual ~SSLNewSessionTicketMessage() {}
923 
929  uint8_t* getSessionTicketData() const;
930 
937  size_t getSessionTicketDataLength() const;
938 
939  // implement abstract methods
940 
941  std::string toString() const;
942 };
943 
944 
952 {
953 public:
954 
962  SSLUnknownMessage(uint8_t* data, size_t dataLen, SSLHandshakeLayer* container) : SSLHandshakeMessage(data, dataLen, container) {}
963 
964  virtual ~SSLUnknownMessage() {}
965 
966  // implement virtual and abstract methods
967 
971  SSLHandshakeType getHandshakeType() const;
972 
978  size_t getMessageLength() const;
979 
980  std::string toString() const;
981 };
982 
983 template<class TExtension>
985 {
986  size_t vecSize = m_ExtensionList.size();
987  for (size_t i = 0; i < vecSize; i++)
988  {
989  SSLExtension* curElem = const_cast<SSLExtension*>(m_ExtensionList.at(i));
990  if (dynamic_cast<TExtension*>(curElem) != NULL)
991  return (TExtension*)curElem;
992  }
993 
994  return NULL;
995 }
996 
997 template<class TExtension>
999 {
1000  size_t vecSize = m_ExtensionList.size();
1001  for (size_t i = 0; i < vecSize; i++)
1002  {
1003  SSLExtension* curElem = const_cast<SSLExtension*>(m_ExtensionList.at(i));
1004  if (dynamic_cast<TExtension*>(curElem) != NULL)
1005  return (TExtension*)curElem;
1006  }
1007 
1008  return NULL;
1009 }
1010 
1011 } // namespace pcpp
1012 
1013 #endif /* PACKETPP_SSL_HANDSHAKE_MESSAGE */
The main namespace for the PcapPlusPlus lib.
static SSLCipherSuite * getCipherSuiteByID(uint16_t id)
Definition: SSLHandshake.h:256
bool allDataExists() const
Definition: SSLHandshake.h:286
uint16_t extensionDataLength
Definition: SSLHandshake.h:155
SSLSymetricEncryptionAlgorithm getSymKeyAlg() const
Definition: SSLHandshake.h:71
SSLHandshakeLayer * getContainingLayer() const
Definition: SSLHandshake.h:343
SSLKeyExchangeAlgorithm
Definition: SSLCommon.h:325
uint16_t getID() const
Definition: SSLHandshake.h:51
SSLUnknownMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:962
Definition: PointerVector.h:24
Definition: SSLLayer.h:306
Definition: SSLHandshake.h:171
Definition: SSLHandshake.h:799
SSLExtensionType
Definition: SSLCommon.h:501
SSLServerNameIndicationExtension(uint8_t *data)
Definition: SSLHandshake.h:178
SSLAuthenticationAlgorithm
Definition: SSLCommon.h:358
size_t getDataLength() const
Definition: SSLHandshake.h:279
SSLFinishedMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:879
Definition: SSLHandshake.h:108
Definition: SSLHandshake.h:868
SSLClientKeyExchangeMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:720
ssl_tls_client_server_hello * getClientHelloHeader() const
Definition: SSLHandshake.h:385
SSLHandshakeType
Definition: SSLCommon.h:216
Definition: SSLHandshake.h:594
Definition: SSLHandshake.h:826
Definition: SSLHandshake.h:667
Definition: SSLHandshake.h:481
Definition: SSLHandshake.h:234
SSLSymetricEncryptionAlgorithm
Definition: SSLCommon.h:391
TLSECPointFormatExtension(uint8_t *data)
Definition: SSLHandshake.h:241
TExtension * getExtensionOfType() const
Definition: SSLHandshake.h:984
static SSLCipherSuite * getCipherSuiteByName(std::string name)
Definition: SSLHandshake.h:640
Definition: SSLHandshake.h:192
SSLHelloRequestMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:651
SSLx509Certificate(uint8_t *data, size_t dataLen, bool allDataExists)
Definition: SSLHandshake.h:268
Definition: SSLHandshake.h:306
ssl_tls_client_server_hello * getServerHelloHeader() const
Definition: SSLHandshake.h:500
SSLNewSessionTicketMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:920
Definition: SSLHandshake.h:709
SSLHashingAlgorithm
Definition: SSLCommon.h:474
SSLHashingAlgorithm getMACAlg() const
Definition: SSLHandshake.h:76
Definition: SSLCommon.h:118
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:951
Definition: SSLHandshake.h:150
uint8_t * getData() const
Definition: SSLHandshake.h:274
Definition: SSLCommon.h:58
SSLServerHelloDoneMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:810
SSLServerKeyExchangeMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:678
uint16_t extensionType
Definition: SSLHandshake.h:153
SSLCertificateVerifyMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:837
Definition: SSLHandshake.h:29
SSLSupportedVersionsExtension(uint8_t *data)
Definition: SSLHandshake.h:199
Definition: SSLHandshake.h:366
Definition: SSLHandshake.h:750
Definition: SSLHandshake.h:213
TLSSupportedGroupsExtension(uint8_t *data)
Definition: SSLHandshake.h:220
std::string asString() const
Definition: SSLHandshake.h:56
SSLAuthenticationAlgorithm getAuthAlg() const
Definition: SSLHandshake.h:66
TExtension * getExtensionOfType() const
Definition: SSLHandshake.h:998
Definition: SSLHandshake.h:909