Developer World
Spresense Arduino Library v3.2.0-77d75a4
LTETLSClient.h
Go to the documentation of this file.
1/*
2 * LTETLSClient.h - LTETLSClient include file for Spresense Arduino
3 * Copyright 2019 Sony Semiconductor Solutions Corporation
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
32#ifndef _LTE_TLS_CLIENT_H_
33#define _LTE_TLS_CLIENT_H_
34
35#ifdef SUBCORE
36#error "LTETLSClient library is NOT supported by SubCore."
37#endif
38
46/****************************************************************************
47 * Included Files
48 ****************************************************************************/
49
50#include <Client.h>
51#include <TLSClient.h>
52#include <File.h>
53
54/****************************************************************************
55 * class declaration
56 ****************************************************************************/
57
65class LTETLSClient : public Client
66{
67public:
72
77
94 int connect(IPAddress ip, uint16_t port);
95
112 int connect(const char *host, uint16_t port);
113
128 size_t write(uint8_t val);
129
146 size_t write(const uint8_t *buf, size_t size);
147
160
172 int read();
173
190 int read(uint8_t *buf, size_t size);
191
203 int peek();
204
212 void flush();
213
221 void stop();
222
234 uint8_t connected();
235
247 operator bool()
248 {
249 return connected();
250 };
251
262 void setCACert(const char *rootCA);
263
276 void setCACert(const unsigned char *rootCA, size_t size);
277
290 void setCACert(File& f, size_t size);
291
304 void setCACert(Stream& stream, size_t size);
305
316 void setCertificate(const char *clientCA);
317
330 void setCertificate(const unsigned char *clientCA, size_t size);
331
344 void setCertificate(File& f, size_t size);
345
358 void setCertificate(Stream& stream, size_t size);
359
370 void setPrivateKey(const char *privateKey);
371
384 void setPrivateKey(const unsigned char *privateKey, size_t size);
385
398 void setPrivateKey(File& f, size_t size);
399
412 void setPrivateKey(Stream& stream, size_t size);
413
425 int setTimeout(uint32_t milliseconds);
426
438 int setSendTimeout(uint32_t milliseconds);
439
440private:
441 int _peekVal;
442 char *_rootCA;
443 size_t _rootCASize;
444 char *_clientCA;
445 size_t _clientCASize;
446 char *_privateKey;
447 size_t _privateKeySize;
448 tlsClientContext_t *_tlsContext;
449 uint8_t _connected;
450 uint32_t _timeout;
451 uint32_t _writeTimeout;
452};
453
457#endif
SPRESENSE Arduino File library.
The File class allows for reading from and writing to individual files on the File System.
Definition: File.h:55
[en] Create a secure client that can connect to a specific Internet IP address and port....
Definition: LTETLSClient.h:66
void setCACert(const unsigned char *rootCA, size_t size)
Set the root certificate authority certificate on the client.
int setTimeout(uint32_t milliseconds)
Set the timeout when the client receive (including TLS handshake).
int available()
Returns the number of bytes available for reading.
int connect(IPAddress ip, uint16_t port)
Connects to a specified IP address and port.
void setPrivateKey(Stream &stream, size_t size)
Read the private key from the file or other stream and set it on the client.
void setCACert(File &f, size_t size)
Read the root certificate authority certificate from the file and set it on the client.
void setPrivateKey(const char *privateKey)
Set the private key on the client.
void setCertificate(File &f, size_t size)
Read the certificate from the file and set it on the client.
void setCertificate(const unsigned char *clientCA, size_t size)
Set the certificate on the client.
void stop()
Disconnect from the server.
int connect(const char *host, uint16_t port)
Connects to a specified host name and port.
size_t write(const uint8_t *buf, size_t size)
Send series of bytes data to the server the client is connected to.
void setCertificate(const char *clientCA)
Set the certificate on the client.
uint8_t connected()
Whether or not the client is connected.
void setPrivateKey(const unsigned char *privateKey, size_t size)
Set the private key on the client.
int setSendTimeout(uint32_t milliseconds)
Set the timeout when the client send.
void setCACert(const char *rootCA)
Set the root certificate authority certificate on the client.
void setCertificate(Stream &stream, size_t size)
Read the certificate from the file or other stream and set it on the client.
int read()
Read the next byte received from the server the client is connected to.
~LTETLSClient()
Destruct LTETLSClient instance.
void flush()
Discards any bytes that have been written to the client.
int peek()
Returns the next byte received from the server without removing it from the buffer.
void setPrivateKey(File &f, size_t size)
Read the private key from the file and set it on the client.
size_t write(uint8_t val)
Send one byte data to the server the client is connected to.
LTETLSClient()
Construct LTETLSClient instance.
int read(uint8_t *buf, size_t size)
Read series of bytes received from the server the client is connected to.
void setCACert(Stream &stream, size_t size)
Read the root certificate authority certificate from the file or other stream and set it on the clien...
Definition: TLSClient.h:39