Connection.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Connection.h
8  *
9  * @author: 2019 - Slavey Karadzhov <slav@attachix.com>
10  *
11  ****/
12 
13 #pragma once
14 
15 #include "SessionId.h"
16 #include "Certificate.h"
17 #include "InputBuffer.h"
18 #include "CipherSuite.h"
19 #include "Alert.h"
20 
21 namespace Ssl
22 {
23 class Context;
24 
35 class Connection : public Printable
36 {
37 public:
38  Connection(Context& context, tcp_pcb* tcp) : context(context), tcp(tcp)
39  {
40  assert(tcp != nullptr);
41  }
42 
43  virtual ~Connection()
44  {
45  }
46 
51  virtual bool isHandshakeDone() const = 0;
52 
63  virtual int read(InputBuffer& input, uint8_t*& output) = 0;
64 
72  virtual int write(const uint8_t* data, size_t length) = 0;
73 
78  virtual CipherSuite getCipherSuite() const = 0;
79 
85  virtual SessionId getSessionId() const = 0;
86 
94  virtual const Certificate* getCertificate() const = 0;
95 
96  virtual void freeCertificate() = 0;
97 
101  size_t printTo(Print& p) const override;
102 
103  int writeTcpData(uint8_t* data, size_t length);
104 
108  virtual String getErrorString(int error) const = 0;
109 
115  virtual Alert getAlert(int error) const = 0;
116 
118 
119 protected:
120  tcp_pcb* tcp;
121 };
122 
123 } // namespace Ssl
Wraps a pbuf for reading in chunks.
Definition: InputBuffer.h:20
Definition: Alert.h:15
virtual SessionId getSessionId() const =0
Gets the current session id object. Should be called after handshake.
Implemented by SSL adapter to handle a connection.
Definition: Connection.h:35
CipherSuite
Cipher suite identifier.
Definition: CipherSuite.h:154
Connection(Context &context, tcp_pcb *tcp)
Definition: Connection.h:38
virtual const Certificate * getCertificate() const =0
Gets the certificate object. That object MUST be owned by the Connection implementation and should no...
The String class.
Definition: WString.h:136
Implemented by SSL adapter to handle certificate operations.
Definition: Certificate.h:48
size_t printTo(Print &p) const override
For debugging.
Provides formatted output to stream.
Definition: Print.h:36
virtual bool isHandshakeDone() const =0
Checks if the handshake has finished.
tcp_pcb * tcp
Definition: Connection.h:120
virtual int write(const uint8_t *data, size_t length)=0
Converts and sends plaintext data.
virtual CipherSuite getCipherSuite() const =0
Gets the cipher suite that was used.
virtual ~Connection()
Definition: Connection.h:43
Definition: Printable.h:42
int writeTcpData(uint8_t *data, size_t length)
virtual void freeCertificate()=0
virtual int read(InputBuffer &input, uint8_t *&output)=0
Reads encrypted information and decrypts it.
virtual Alert getAlert(int error) const =0
Get alert code from error.
Context & context
Definition: Connection.h:117
Implemented by SSL adapter to create and manage SSL connections.
Definition: Context.h:28
Manages buffer to store SSL Session ID.
Definition: SessionId.h:21
Alert
Alert codes defined by the standard.
Definition: Alert.h:48
virtual String getErrorString(int error) const =0
Get string for error code.