PcapPlusPlus  19.12
SSLLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_SSL_LAYER
2 #define PACKETPP_SSL_LAYER
3 
4 #include "PointerVector.h"
5 #include "Layer.h"
6 #include "SSLCommon.h"
7 #include "SSLHandshake.h"
8 
161 namespace pcpp
162 {
163 
171  class SSLLayer : public Layer
172  {
173  public:
174 
179  static bool isSSLPort(uint16_t port);
180 
200  static bool IsSSLMessage(uint16_t srcPort, uint16_t dstPort, uint8_t* data, size_t dataLen);
201 
213  static SSLLayer* createSSLMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
214 
220  static std::string sslVersionToString(SSLVersion ver);
221 
227 
232 
237 
238  // implement abstract methods
239 
243  size_t getHeaderLen() const;
244 
249  void parseNextLayer();
250 
252 
253  protected:
254  SSLLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = SSL; }
255 
256  };
257 
258 
306  {
307  public:
308 
316  SSLHandshakeLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
317 
321  size_t getHandshakeMessagesCount() const { return m_MessageList.size(); }
322 
330  SSLHandshakeMessage* getHandshakeMessageAt(int index) const;
331 
336  template<class THandshakeMessage>
337  THandshakeMessage* getHandshakeMessageOfType() const;
338 
348  template<class THandshakeMessage>
349  THandshakeMessage* getNextHandshakeMessageOfType(SSLHandshakeMessage* after) const;
350 
351  // implement abstract methods
352 
353  std::string toString() const;
354 
359 
360  private:
362  };
363 
364 
371  {
372  public:
373 
381  SSLChangeCipherSpecLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
382  : SSLLayer(data, dataLen, prevLayer, packet) {}
383 
385 
386  // implement abstract methods
387 
388  std::string toString() const;
389 
394  };
395 
396 
402  class SSLAlertLayer : public SSLLayer
403  {
404  public:
405 
413  SSLAlertLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
414  : SSLLayer(data, dataLen, prevLayer, packet) {}
415 
416  ~SSLAlertLayer() {}
417 
422 
427 
428  // implement abstract methods
429 
430  std::string toString() const;
431 
436  };
437 
438 
445  {
446  public:
447 
455  SSLApplicationDataLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
456  : SSLLayer(data, dataLen, prevLayer, packet) {}
457 
459 
464  uint8_t* getEncrpytedData() const;
465 
469  size_t getEncrpytedDataLen() const;
470 
471  // implement abstract methods
472 
473  std::string toString() const;
474 
479  };
480 
481  template<class THandshakeMessage>
483  {
484  size_t vecSize = m_MessageList.size();
485  for (size_t i = 0; i < vecSize; i++)
486  {
487  SSLHandshakeMessage* curElem = const_cast<SSLHandshakeMessage*>(m_MessageList.at(i));
488  if (dynamic_cast<THandshakeMessage*>(curElem) != NULL)
489  return (THandshakeMessage*)curElem;
490  }
491 
492  // element not found
493  return NULL;
494  }
495 
496  template<class THandshakeMessage>
498  {
499  size_t vecSize = m_MessageList.size();
500  size_t afterIndex;
501 
502  // find the index of "after"
503  for (afterIndex = 0; afterIndex < vecSize; afterIndex++)
504  {
505  SSLHandshakeMessage* curElem = const_cast<SSLHandshakeMessage*>(m_MessageList.at(afterIndex));
506  if (curElem == after)
507  break;
508  }
509 
510  // "after" not found
511  if (afterIndex == vecSize)
512  return NULL;
513 
514  for (size_t i = afterIndex+1; i < vecSize; i++)
515  {
516  SSLHandshakeMessage* curElem = const_cast<SSLHandshakeMessage*>(m_MessageList.at(i));
517  if (dynamic_cast<THandshakeMessage*>(curElem) != NULL)
518  return (THandshakeMessage*)curElem;
519  }
520 
521  // element not found
522  return NULL;
523  }
524 
525 } // namespace pcpp
526 
527 #endif /* PACKETPP_SSL_LAYER */
pcpp::SSLAlertLayer
Definition: SSLLayer.h:402
pcpp::SSLRecordType
SSLRecordType
Definition: SSLCommon.h:97
pcpp::SSLHandshakeMessage
Definition: SSLHandshake.h:243
pcpp::SSLAlertLayer::getAlertDescription
SSLAlertDescription getAlertDescription()
pcpp::OsiModelLayer
OsiModelLayer
Definition: ProtocolType.h:224
pcpp::SSLVersion
SSLVersion
Definition: SSLCommon.h:112
pcpp::Packet
Definition: Packet.h:26
pcpp::SSLLayer::sslVersionToString
static std::string sslVersionToString(SSLVersion ver)
pcpp::SSLApplicationDataLayer
Definition: SSLLayer.h:444
Layer.h
pcpp::SSLLayer::IsSSLMessage
static bool IsSSLMessage(uint16_t srcPort, uint16_t dstPort, uint8_t *data, size_t dataLen)
pcpp::SSLAlertLayer::getAlertLevel
SSLAlertLevel getAlertLevel() const
pcpp::SSLApplicationDataLayer::computeCalculateFields
void computeCalculateFields()
Definition: SSLLayer.h:478
pcpp::SSLHandshakeLayer::getHandshakeMessagesCount
size_t getHandshakeMessagesCount() const
Definition: SSLLayer.h:321
pcpp::SSLHandshakeLayer::getNextHandshakeMessageOfType
THandshakeMessage * getNextHandshakeMessageOfType(SSLHandshakeMessage *after) const
Definition: SSLLayer.h:497
pcpp::SSLChangeCipherSpecLayer::toString
std::string toString() const
SSLCommon.h
pcpp::SSLLayer
Definition: SSLLayer.h:171
pcpp::SSLHandshakeLayer::SSLHandshakeLayer
SSLHandshakeLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
pcpp::SSLAlertLayer::SSLAlertLayer
SSLAlertLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: SSLLayer.h:413
pcpp::SSLHandshakeLayer::computeCalculateFields
void computeCalculateFields()
Definition: SSLLayer.h:358
pcpp::SSLAlertLayer::computeCalculateFields
void computeCalculateFields()
Definition: SSLLayer.h:435
pcpp::SSLApplicationDataLayer::getEncrpytedData
uint8_t * getEncrpytedData() const
pcpp::SSLApplicationDataLayer::getEncrpytedDataLen
size_t getEncrpytedDataLen() const
pcpp::SSL
Definition: ProtocolType.h:131
PointerVector.h
pcpp::SSLHandshakeLayer::toString
std::string toString() const
pcpp::SSLLayer::isSSLPort
static bool isSSLPort(uint16_t port)
pcpp::SSLAlertDescription
SSLAlertDescription
Definition: SSLCommon.h:173
pcpp::SSLLayer::createSSLMessage
static SSLLayer * createSSLMessage(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
pcpp::ssl_tls_record_layer
Definition: SSLCommon.h:22
pcpp::SSLHandshakeLayer::getHandshakeMessageAt
SSLHandshakeMessage * getHandshakeMessageAt(int index) const
pcpp::SSLLayer::getOsiModelLayer
OsiModelLayer getOsiModelLayer() const
Definition: SSLLayer.h:251
pcpp::SSLLayer::getHeaderLen
size_t getHeaderLen() const
pcpp::SSLLayer::getRecordType
SSLRecordType getRecordType() const
pcpp::SSLChangeCipherSpecLayer::SSLChangeCipherSpecLayer
SSLChangeCipherSpecLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: SSLLayer.h:381
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::SSLAlertLevel
SSLAlertLevel
Definition: SSLCommon.h:160
pcpp::Layer
Definition: Layer.h:70
pcpp::SSLLayer::getRecordVersion
SSLVersion getRecordVersion() const
pcpp::SSLHandshakeLayer
Definition: SSLLayer.h:305
pcpp::SSLApplicationDataLayer::toString
std::string toString() const
pcpp::SSLApplicationDataLayer::SSLApplicationDataLayer
SSLApplicationDataLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: SSLLayer.h:455
pcpp::SSLLayer::getRecordLayer
ssl_tls_record_layer * getRecordLayer() const
Definition: SSLLayer.h:226
pcpp::SSLChangeCipherSpecLayer::computeCalculateFields
void computeCalculateFields()
Definition: SSLLayer.h:393
pcpp::SSLAlertLayer::toString
std::string toString() const
pcpp::OsiModelPresentationLayer
Definition: ProtocolType.h:237
pcpp::PointerVector
Definition: PointerVector.h:24
pcpp::SSLLayer::parseNextLayer
void parseNextLayer()
pcpp::SSLHandshakeLayer::getHandshakeMessageOfType
THandshakeMessage * getHandshakeMessageOfType() const
Definition: SSLLayer.h:482
pcpp::SSLChangeCipherSpecLayer
Definition: SSLLayer.h:370
SSLHandshake.h