PcapPlusPlus
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  inline uint16_t getID() { return m_Id; }
52 
56  inline std::string asString() { return m_Name; }
57 
61  inline SSLKeyExchangeAlgorithm getKeyExchangeAlg() { return m_KeyExAlg; }
62 
66  inline SSLAuthenticationAlgorithm getAuthAlg() { return m_AuthAlg; }
67 
71  inline SSLSymetricEncryptionAlgorithm getSymKeyAlg() { return m_SymKeyAlg; }
72 
76  inline SSLHashingAlgorithm getMACAlg() { 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 
123 
127  uint16_t getTypeAsInt();
128 
132  uint16_t getLength();
133 
137  uint16_t getTotalLength();
138 
142  uint8_t* getData();
143 
144 protected:
145 
151  {
153  uint16_t extensionType;
157  uint8_t extensionData[];
158  };
159 
160  uint8_t* m_RawData;
161 
162  inline SSLExtensionStruct* getExtensionStruct() { return (SSLExtensionStruct*)m_RawData; }
163 };
164 
165 
172 {
173 public:
179 
183  std::string getHostName();
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() { return m_Data; }
212 
216  size_t getDataLength() { return m_DataLen; }
217 
223  bool allDataExists() { 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 
262 
267  virtual size_t getMessageLength();
268 
275  virtual bool isMessageComplete();
276 
280  inline SSLHandshakeLayer* getContainingLayer() { return m_Container; }
281 
285  virtual std::string toString() = 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 
329 
333  uint8_t getSessionIDLength();
334 
338  uint8_t* getSessionID();
339 
343  int getCipherSuiteCount();
344 
352  SSLCipherSuite* getCipherSuite(int index);
353 
357  uint8_t getCompressionMethodsValue();
358 
362  int getExtensionCount();
363 
367  uint16_t getExtensionsLenth();
368 
376  SSLExtension* getExtension(int index);
377 
385  SSLExtension* getExtensionOfType(uint16_t type);
386 
393 
400  template<class TExtension>
401  TExtension* getExtensionOfType();
402 
403  // implement abstract methods
404 
405  std::string toString();
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 
444 
448  uint8_t getSessionIDLength();
449 
453  uint8_t* getSessionID();
454 
460 
464  uint8_t getCompressionMethodsValue();
465 
469  int getExtensionCount();
470 
474  uint16_t getExtensionsLenth();
475 
483  SSLExtension* getExtension(int index);
484 
492  SSLExtension* getExtensionOfType(uint16_t type);
493 
500 
507  template<class TExtension>
508  TExtension* getExtensionOfType();
509 
510  // implement abstract methods
511 
512  std::string toString();
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();
550 
558 
559  // implement abstract methods
560 
561  std::string toString();
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();
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();
621 
629 
630  // implement abstract methods
631 
632  std::string toString();
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();
663 
671 
672  // implement abstract methods
673 
674  std::string toString();
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();
709 
717 
718  // implement abstract methods
719 
720  std::string toString();
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();
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();
780 
787  size_t getSignedHashLength();
788 
789  // implement abstract methods
790 
791  std::string toString();
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();
822 
829  size_t getSignedHashLength();
830 
831  // implement abstract methods
832 
833  std::string toString();
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();
863 
871 
872  // implement abstract methods
873 
874  std::string toString();
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 
905 
911  size_t getMessageLength();
912 
913  std::string toString();
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 = 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 = 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 */
virtual SSLHandshakeType getHandshakeType()
static SSLHandshakeMessage * createHandhakeMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
SSLSymetricEncryptionAlgorithm
Definition: SSLCommon.h:298
ssl_tls_client_server_hello * getServerHelloHeader()
Definition: SSLHandshake.h:437
std::string toString()
Definition: SSLHandshake.h:732
SSLCipherSuite(uint16_t id, SSLKeyExchangeAlgorithm keyExAlg, SSLAuthenticationAlgorithm authAlg, SSLSymetricEncryptionAlgorithm symKeyAlg, SSLHashingAlgorithm MACAlg, const char *name)
Definition: SSLHandshake.h:41
SSLCertificateVerifyMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:770
std::string asString()
Definition: SSLHandshake.h:56
size_t getDataLength()
Definition: SSLHandshake.h:216
SSLUnknownMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:895
SSLFinishedMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:812
SSLHandshakeType
Definition: SSLCommon.h:129
bool allDataExists()
Definition: SSLHandshake.h:223
Definition: SSLHandshake.h:801
SSLCipherSuite * getCipherSuite(int index)
SSLAuthenticationAlgorithm getAuthAlg()
Definition: SSLHandshake.h:66
SSLClientHelloMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: PointerVector.h:24
virtual std::string toString()=0
uint8_t * getData()
Definition: SSLHandshake.h:211
TExtension * getExtensionOfType()
Definition: SSLHandshake.h:931
SSLHelloRequestMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:584
TExtension * getExtensionOfType()
Definition: SSLHandshake.h:917
Definition: SSLHandshake.h:171
SSLNewSessionTicketMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:853
Definition: SSLHandshake.h:29
SSLServerNameIndicationExtension(uint8_t *data)
Definition: SSLHandshake.h:178
SSLExtension * getExtension(int index)
static SSLCipherSuite * getCipherSuiteByName(std::string name)
std::vector< SSLClientCertificateType > & getCertificateTypes()
uint16_t getID()
Definition: SSLHandshake.h:51
SSLHandshakeLayer * getContainingLayer()
Definition: SSLHandshake.h:280
uint16_t getTypeAsInt()
Definition: SSLHandshake.h:527
SSLCertificateRequestMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
uint16_t extensionType
Definition: SSLHandshake.h:153
Definition: SSLHandshake.h:884
Definition: SSLHandshake.h:243
Definition: SSLHandshake.h:759
static SSLCipherSuite * getCipherSuiteByID(uint16_t id)
SSLSymetricEncryptionAlgorithm getSymKeyAlg()
Definition: SSLHandshake.h:71
Definition: SSLCommon.h:56
Definition: SSLHandshake.h:600
SSLHashingAlgorithm
Definition: SSLCommon.h:377
Definition: SSLLayer.h:306
SSLServerHelloDoneMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:743
Definition: SSLHandshake.h:842
SSLServerKeyExchangeMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:611
SSLClientKeyExchangeMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:653
SSLCertificateMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:150
SSLVersion getHandshakeVersion()
SSLVersion getHandshakeVersion()
virtual size_t getMessageLength()
ssl_tls_client_server_hello * getClientHelloHeader()
Definition: SSLHandshake.h:322
SSLExtensionType getType()
SSLCipherSuite * getCipherSuite()
uint8_t * getData()
Definition: SSLHandshake.h:418
Definition: SSLHandshake.h:193
uint16_t getLength()
SSLHashingAlgorithm getMACAlg()
Definition: SSLHandshake.h:76
Definition: SSLHandshake.h:108
SSLExtension * getExtension(int index)
SSLExtension(uint8_t *data)
SSLKeyExchangeAlgorithm getKeyExchangeAlg()
Definition: SSLHandshake.h:61
virtual bool isMessageComplete()
Definition: SSLHandshake.h:683
SSLVersion
Definition: SSLCommon.h:112
Definition: SSLHandshake.h:573
SSLServerHelloMessage(uint8_t *data, size_t dataLen, SSLHandshakeLayer *container)
Definition: SSLHandshake.h:303
SSLHandshakeType getHandshakeType()
uint16_t getTotalLength()
The main namespace for the PcapPlusPlus lib.
SSLAuthenticationAlgorithm
Definition: SSLCommon.h:265
uint8_t extensionData[]
Definition: SSLHandshake.h:157
SSLx509Certificate(uint8_t *data, size_t dataLen, bool allDataExists)
Definition: SSLHandshake.h:205
Definition: SSLHandshake.h:642
SSLx509Certificate * getCertificate(int index)
SSLExtensionType
Definition: SSLCommon.h:404
SSLKeyExchangeAlgorithm
Definition: SSLCommon.h:232
uint16_t extensionDataLength
Definition: SSLHandshake.h:155