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 #include <lwip/tcp.h>
21 
22 namespace Ssl
23 {
24 class Context;
25 
36 class Connection : public Printable
37 {
38 public:
40  {
41  assert(tcp != nullptr);
42  }
43 
44  virtual ~Connection()
45  {
46  }
47 
52  virtual bool isHandshakeDone() const = 0;
53 
64  virtual int read(InputBuffer& input, uint8_t*& output) = 0;
65 
73  virtual int write(const uint8_t* data, size_t length) = 0;
74 
79  virtual CipherSuite getCipherSuite() const = 0;
80 
86  virtual SessionId getSessionId() const = 0;
87 
95  virtual const Certificate* getCertificate() const = 0;
96 
97  virtual void freeCertificate() = 0;
98 
102  size_t printTo(Print& p) const override;
103 
104  int writeTcpData(uint8_t* data, size_t length);
105 
109  virtual String getErrorString(int error) const = 0;
110 
116  virtual Alert getAlert(int error) const = 0;
117 
119 
120 protected:
121  tcp_pcb* tcp;
122 };
123 
124 } // namespace Ssl
Provides formatted output to stream.
Definition: Print.h:37
Definition: Printable.h:43
Implemented by SSL adapter to handle certificate operations.
Definition: Certificate.h:49
Implemented by SSL adapter to handle a connection.
Definition: Connection.h:37
virtual SessionId getSessionId() const =0
Gets the current session id object. Should be called after handshake.
virtual CipherSuite getCipherSuite() const =0
Gets the cipher suite that was used.
size_t printTo(Print &p) const override
For debugging.
Connection(Context &context, tcp_pcb *tcp)
Definition: Connection.h:39
int writeTcpData(uint8_t *data, size_t length)
virtual bool isHandshakeDone() const =0
Checks if the handshake has finished.
virtual ~Connection()
Definition: Connection.h:44
virtual Alert getAlert(int error) const =0
Get alert code from error.
virtual int read(InputBuffer &input, uint8_t *&output)=0
Reads encrypted information and decrypts it.
virtual const Certificate * getCertificate() const =0
Gets the certificate object. That object MUST be owned by the Connection implementation and should no...
Context & context
Definition: Connection.h:118
tcp_pcb * tcp
Definition: Connection.h:121
virtual String getErrorString(int error) const =0
Get string for error code.
virtual int write(const uint8_t *data, size_t length)=0
Converts and sends plaintext data.
virtual void freeCertificate()=0
Implemented by SSL adapter to create and manage SSL connections.
Definition: Components/ssl/include/Network/Ssl/Context.h:29
Wraps a pbuf for reading in chunks.
Definition: InputBuffer.h:23
Manages buffer to store SSL Session ID.
Definition: SessionId.h:22
The String class.
Definition: WString.h:137
Definition: Alert.h:16
Alert
Alert codes defined by the standard.
Definition: Alert.h:49
CipherSuite
Cipher suite identifier.
Definition: CipherSuite.h:154