PcapPlusPlus
SSLLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_SSL_LAYER
2 #define PACKETPP_SSL_LAYER
3 
4 #include <map>
5 #include <vector>
6 #include "PointerVector.h"
7 #include "Layer.h"
8 #include "SSLCommon.h"
9 #include "SSLHandshake.h"
10 
163 namespace pcpp
164 {
165 
173  class SSLLayer : public Layer
174  {
175  public:
176 
196  static bool IsSSLMessage(uint16_t srcPort, uint16_t dstPort, uint8_t* data, size_t dataLen);
197 
209  static SSLLayer* createSSLMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
210 
216  static std::string sslVersionToString(SSLVersion ver);
217 
221  static const std::map<uint16_t, bool>* getSSLPortMap();
222 
228 
233 
238 
239  // implement abstract methods
240 
244  size_t getHeaderLen();
245 
250  void parseNextLayer();
251 
253 
254  protected:
255  SSLLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = SSL; }
256 
257  };
258 
259 
307  {
308  public:
309 
317  SSLHandshakeLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
318 
322  size_t getHandshakeMessagesCount();
323 
332 
337  template<class THandshakeMessage>
338  THandshakeMessage* getHandshakeMessageOfType();
339 
349  template<class THandshakeMessage>
350  THandshakeMessage* getNextHandshakeMessageOfType(SSLHandshakeMessage* after);
351 
352  // implement abstract methods
353 
354  std::string toString();
355 
360 
361  private:
363  };
364 
365 
372  {
373  public:
374 
382  SSLChangeCipherSpecLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
383  : SSLLayer(data, dataLen, prevLayer, packet) {}
384 
386 
387  // implement abstract methods
388 
389  std::string toString();
390 
395  };
396 
397 
403  class SSLAlertLayer : public SSLLayer
404  {
405  public:
406 
414  SSLAlertLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
415  : SSLLayer(data, dataLen, prevLayer, packet) {}
416 
417  ~SSLAlertLayer() {}
418 
423 
428 
429  // implement abstract methods
430 
431  std::string toString();
432 
437  };
438 
439 
446  {
447  public:
448 
456  SSLApplicationDataLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
457  : SSLLayer(data, dataLen, prevLayer, packet) {}
458 
460 
465  uint8_t* getEncrpytedData();
466 
470  size_t getEncrpytedDataLen();
471 
472  // implement abstract methods
473 
474  std::string toString();
475 
480  };
481 
482  template<class THandshakeMessage>
484  {
485  size_t vecSize = m_MessageList.size();
486  for (size_t i = 0; i < vecSize; i++)
487  {
488  SSLHandshakeMessage* curElem = m_MessageList.at(i);
489  if (dynamic_cast<THandshakeMessage*>(curElem) != NULL)
490  return (THandshakeMessage*)curElem;
491  }
492 
493  // element not found
494  return NULL;
495  }
496 
497  template<class THandshakeMessage>
499  {
500  size_t vecSize = m_MessageList.size();
501  size_t afterIndex;
502 
503  // find the index of "after"
504  for (afterIndex = 0; afterIndex < vecSize; afterIndex++)
505  {
506  SSLHandshakeMessage* curElem = m_MessageList.at(afterIndex);
507  if (curElem == after)
508  break;
509  }
510 
511  // "after" not found
512  if (afterIndex == vecSize)
513  return NULL;
514 
515  for (size_t i = afterIndex+1; i < vecSize; i++)
516  {
517  SSLHandshakeMessage* curElem = m_MessageList.at(i);
518  if (dynamic_cast<THandshakeMessage*>(curElem) != NULL)
519  return (THandshakeMessage*)curElem;
520  }
521 
522  // element not found
523  return NULL;
524  }
525 
526 } // namespace pcpp
527 
528 #endif /* PACKETPP_SSL_LAYER */
void computeCalculateFields()
Definition: SSLLayer.h:436
static SSLLayer * createSSLMessage(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
void computeCalculateFields()
Definition: SSLLayer.h:394
SSLAlertLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: SSLLayer.h:414
SSLAlertDescription
Definition: SSLCommon.h:173
OsiModelLayer getOsiModelLayer()
Definition: SSLLayer.h:252
Definition: SSLLayer.h:173
SSLAlertDescription getAlertDescription()
Definition: PointerVector.h:24
Definition: SSLCommon.h:22
static std::string sslVersionToString(SSLVersion ver)
Definition: SSLLayer.h:371
static bool IsSSLMessage(uint16_t srcPort, uint16_t dstPort, uint8_t *data, size_t dataLen)
SSLVersion getRecordVersion()
SSLHandshakeMessage * getHandshakeMessageAt(int index)
Definition: ProtocolType.h:131
SSLRecordType getRecordType()
Definition: Layer.h:70
static const std::map< uint16_t, bool > * getSSLPortMap()
void parseNextLayer()
Definition: Packet.h:26
Definition: SSLHandshake.h:243
SSLAlertLevel
Definition: SSLCommon.h:160
void computeCalculateFields()
Definition: SSLLayer.h:359
std::string toString()
SSLRecordType
Definition: SSLCommon.h:97
OsiModelLayer
Definition: ProtocolType.h:213
SSLChangeCipherSpecLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: SSLLayer.h:382
Definition: SSLLayer.h:445
Definition: SSLLayer.h:306
size_t getHandshakeMessagesCount()
THandshakeMessage * getNextHandshakeMessageOfType(SSLHandshakeMessage *after)
Definition: SSLLayer.h:498
SSLApplicationDataLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: SSLLayer.h:456
Definition: SSLLayer.h:403
std::string toString()
size_t getHeaderLen()
THandshakeMessage * getHandshakeMessageOfType()
Definition: SSLLayer.h:483
Definition: ProtocolType.h:226
ssl_tls_record_layer * getRecordLayer()
Definition: SSLLayer.h:227
SSLHandshakeLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
SSLVersion
Definition: SSLCommon.h:112
The main namespace for the PcapPlusPlus lib.
SSLAlertLevel getAlertLevel()
void computeCalculateFields()
Definition: SSLLayer.h:479