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:
39  Connection(Context& context, tcp_pcb* tcp) : context(context), tcp(tcp)
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 
118  Context& context;
119 
120 protected:
121  tcp_pcb* tcp;
122 };
123 
124 } // namespace Ssl
Alert
Alert codes defined by the standard.
Definition: Alert.h:57
Implemented by SSL adapter to handle certificate operations.
Definition: Certificate.h:58
The String class.
Definition: WString.h:136
virtual SessionId getSessionId() const =0
Gets the current session id object. Should be called after handshake.
Implemented by SSL adapter to create and manage SSL connections.
Definition: Components/ssl/include/Network/Ssl/Context.h:28
CipherSuite
Cipher suite identifier.
Definition: CipherSuite.h:162
virtual int write(const uint8_t *data, size_t length)=0
Converts and sends plaintext data.
Connection(Context &context, tcp_pcb *tcp)
Definition: Connection.h:49
size_t printTo(Print &p) const override
For debugging.
tcp_pcb * tcp
Definition: Connection.h:131
virtual const Certificate * getCertificate() const =0
Gets the certificate object. That object MUST be owned by the Connection implementation and should no...
virtual bool isHandshakeDone() const =0
Checks if the handshake has finished.
Definition: Printable.h:42
virtual void freeCertificate()=0
virtual ~Connection()
Definition: Connection.h:54
virtual int read(InputBuffer &input, uint8_t *&output)=0
Reads encrypted information and decrypts it.
virtual CipherSuite getCipherSuite() const =0
Gets the cipher suite that was used.
Provides formatted output to stream.
Definition: Print.h:36
virtual Alert getAlert(int error) const =0
Get alert code from error.
int writeTcpData(uint8_t *data, size_t length)
Context & context
Definition: Connection.h:128
Manages buffer to store SSL Session ID.
Definition: SessionId.h:29
virtual String getErrorString(int error) const =0
Get string for error code.
Wraps a pbuf for reading in chunks.
Definition: InputBuffer.h:30
Definition: Alert.h:15