acme_dns_client.h
Go to the documentation of this file.
1 /**
2  * @file acme_dns_client.h
3  * @brief ACME-DNS client
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2019-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneACME Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _ACME_DNS_CLIENT_H
32 #define _ACME_DNS_CLIENT_H
33 
34 //Dependencies
35 #include "acme_config.h"
36 #include "core/net.h"
37 #include "http/http_client.h"
38 
39 //ACME-DNS client support
40 #ifndef ACME_DNS_CLIENT_SUPPORT
41  #define ACME_DNS_CLIENT_SUPPORT ENABLED
42 #elif (ACME_DNS_CLIENT_SUPPORT != ENABLED && ACME_DNS_CLIENT_SUPPORT != DISABLED)
43  #error ACME_DNS_CLIENT_SUPPORT parameter is not valid
44 #endif
45 
46 //ACME-DNS over TLS
47 #ifndef ACME_DNS_CLIENT_TLS_SUPPORT
48  #define ACME_DNS_CLIENT_TLS_SUPPORT DISABLED
49 #elif (ACME_DNS_CLIENT_TLS_SUPPORT != ENABLED && ACME_DNS_CLIENT_TLS_SUPPORT != DISABLED)
50  #error ACME_DNS_CLIENT_TLS_SUPPORT parameter is not valid
51 #endif
52 
53 //Default timeout
54 #ifndef ACME_DNS_CLIENT_DEFAULT_TIMEOUT
55  #define ACME_DNS_CLIENT_DEFAULT_TIMEOUT 20000
56 #elif (ACME_DNS_CLIENT_DEFAULT_TIMEOUT < 1000)
57  #error ACME_DNS_CLIENT_DEFAULT_TIMEOUT parameter is not valid
58 #endif
59 
60 //Size of the buffer for input/output operations
61 #ifndef ACME_DNS_CLIENT_BUFFER_SIZE
62  #define ACME_DNS_CLIENT_BUFFER_SIZE 512
63 #elif (ACME_DNS_CLIENT_BUFFER_SIZE < 128)
64  #error ACME_DNS_CLIENT_BUFFER_SIZE parameter is not valid
65 #endif
66 
67 //Maximum length of host name
68 #ifndef ACME_DNS_CLIENT_MAX_HOST_LEN
69  #define ACME_DNS_CLIENT_MAX_HOST_LEN 64
70 #elif (ACME_DNS_CLIENT_MAX_HOST_LEN < 1)
71  #error ACME_DNS_CLIENT_MAX_HOST_LEN parameter is not valid
72 #endif
73 
74 //Maximum length of user name
75 #ifndef ACME_DNS_CLIENT_MAX_USERNAME_LEN
76  #define ACME_DNS_CLIENT_MAX_USERNAME_LEN 64
77 #elif (ACME_DNS_CLIENT_MAX_USERNAME_LEN < 1)
78  #error ACME_DNS_CLIENT_MAX_USERNAME_LEN parameter is not valid
79 #endif
80 
81 //Maximum length of password
82 #ifndef ACME_DNS_CLIENT_MAX_PASSWORD_LEN
83  #define ACME_DNS_CLIENT_MAX_PASSWORD_LEN 64
84 #elif (ACME_DNS_CLIENT_MAX_PASSWORD_LEN < 1)
85  #error ACME_DNS_CLIENT_MAX_PASSWORD_LEN parameter is not valid
86 #endif
87 
88 //Maximum length of sub domain
89 #ifndef ACME_DNS_CLIENT_MAX_SUB_DOMAIN_LEN
90  #define ACME_DNS_CLIENT_MAX_SUB_DOMAIN_LEN 64
91 #elif (ACME_DNS_CLIENT_MAX_SUB_DOMAIN_LEN < 1)
92  #error ACME_DNS_CLIENT_MAX_SUB_DOMAIN_LEN parameter is not valid
93 #endif
94 
95 //Maximum length of full domain
96 #ifndef ACME_DNS_CLIENT_MAX_FULL_DOMAIN_LEN
97  #define ACME_DNS_CLIENT_MAX_FULL_DOMAIN_LEN 128
98 #elif (ACME_DNS_CLIENT_MAX_FULL_DOMAIN_LEN < 1)
99  #error ACME_DNS_CLIENT_MAX_FULL_DOMAIN_LEN parameter is not valid
100 #endif
101 
102 //TXT record length
103 #define ACME_DNS_TXT_RECORD_LEN 43
104 
105 //TLS supported?
106 #if (ACME_DNS_CLIENT_TLS_SUPPORT == ENABLED)
107  #include "core/crypto.h"
108  #include "tls.h"
109 #endif
110 
111 //Forward declaration of AcmeDnsClientContext structure
112 struct _AcmeDnsClientContext;
113 #define AcmeDnsClientContext struct _AcmeDnsClientContext
114 
115 //C++ guard
116 #ifdef __cplusplus
117 extern "C" {
118 #endif
119 
120 
121 /**
122  * @brief ACME-DNS client states
123  **/
124 
125 typedef enum
126 {
139 
140 
141 //TLS supported?
142 #if (ACME_DNS_CLIENT_TLS_SUPPORT == ENABLED)
143 
144 /**
145  * @brief TLS initialization callback function
146  **/
147 
149  TlsContext *tlsContext);
150 
151 #endif
152 
153 
154 /**
155  * @brief ACME-DNS client context
156  **/
157 
159 {
160  AcmeDnsClientState state; ///<ACME-DNS client state
161  NetInterface *interface; ///<Underlying network interface
162  systime_t timeout; ///<Timeout value
163  HttpClientContext httpClientContext; ///<HTTP client context
164 #if (ACME_DNS_CLIENT_TLS_SUPPORT == ENABLED)
165  AcmeDnsClientTlsInitCallback tlsInitCallback; ///<TLS initialization callback function
166 #endif
167  char_t serverName[ACME_DNS_CLIENT_MAX_HOST_LEN + 1]; ///<Host name of the ACME-DNS server
168  uint16_t serverPort; ///<TCP port number
173  char_t buffer[ACME_DNS_CLIENT_BUFFER_SIZE + 1]; ///<Memory buffer for input/output operations
174  size_t bufferLen; ///<Length of the buffer, in bytes
175  size_t bufferPos; ///<Current position in the buffer
176  uint_t statusCode; ///<HTTP status code
177 };
178 
179 
180 //ACME-DNS client related functions
182 
183 #if (ACME_DNS_CLIENT_TLS_SUPPORT == ENABLED)
184 
187 
188 #endif
189 
191  systime_t timeout);
192 
194  const char_t *host);
195 
197  const char_t *username);
198 
200  const char_t *password);
201 
203  const char_t *subDomain);
204 
209 
211  NetInterface *interface);
212 
214  const IpAddr *serverIpAddr, uint16_t serverPort);
215 
218 
221 
223 
224 //C++ guard
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 #endif
error_t acmeDnsClientUpdate(AcmeDnsClientContext *context, const char_t *txt)
Update endpoint.
#define ACME_DNS_CLIENT_MAX_HOST_LEN
error_t acmeDnsClientConnect(AcmeDnsClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort)
Establish a connection with the specified ACME-DNS server.
#define ACME_DNS_CLIENT_MAX_USERNAME_LEN
const char_t * acmeDnsClientGetSubDomain(AcmeDnsClientContext *context)
Get sub domain.
error_t acmeDnsClientDisconnect(AcmeDnsClientContext *context)
Gracefully disconnect from the ACME-DNS server.
#define AcmeDnsClientContext
error_t(* AcmeDnsClientTlsInitCallback)(HttpClientContext *context, TlsContext *tlsContext)
TLS initialization callback function.
#define ACME_DNS_CLIENT_MAX_SUB_DOMAIN_LEN
error_t acmeDnsClientSetUsername(AcmeDnsClientContext *context, const char_t *username)
Set user name.
AcmeDnsClientState
ACME-DNS client states.
@ ACME_DNS_CLIENT_STATE_RECEIVE_BODY
@ ACME_DNS_CLIENT_STATE_DISCONNECTED
@ ACME_DNS_CLIENT_STATE_CLOSE_BODY
@ ACME_DNS_CLIENT_STATE_PARSE_HEADER
@ ACME_DNS_CLIENT_STATE_DISCONNECTING
@ ACME_DNS_CLIENT_STATE_RECEIVE_HEADER
@ ACME_DNS_CLIENT_STATE_SEND_BODY
@ ACME_DNS_CLIENT_STATE_CONNECTING
@ ACME_DNS_CLIENT_STATE_SEND_HEADER
@ ACME_DNS_CLIENT_STATE_PARSE_BODY
@ ACME_DNS_CLIENT_STATE_CONNECTED
#define ACME_DNS_CLIENT_MAX_FULL_DOMAIN_LEN
error_t acmeDnsClientClose(AcmeDnsClientContext *context)
Close the connection with the ACME-DNS server.
const char_t * acmeDnsClientGetUsername(AcmeDnsClientContext *context)
Get user name.
error_t acmeDnsClientInit(AcmeDnsClientContext *context)
Initialize ACME-DNS client context.
error_t acmeDnsClientBindToInterface(AcmeDnsClientContext *context, NetInterface *interface)
Bind the ACME-DNS client to a particular network interface.
error_t acmeDnsClientSetTimeout(AcmeDnsClientContext *context, systime_t timeout)
Set communication timeout.
const char_t * acmeDnsClientGetPassword(AcmeDnsClientContext *context)
Get password.
const char_t * acmeDnsClientGetFullDomain(AcmeDnsClientContext *context)
Get full domain.
#define ACME_DNS_CLIENT_MAX_PASSWORD_LEN
void acmeDnsClientDeinit(AcmeDnsClientContext *context)
Release ACME-DNS client context.
error_t acmeDnsClientSetSubDomain(AcmeDnsClientContext *context, const char_t *subDomain)
Set sub domain.
#define ACME_DNS_CLIENT_BUFFER_SIZE
error_t acmeDnsClientSetPassword(AcmeDnsClientContext *context, const char_t *password)
Set password.
error_t acmeDnsClientSetHost(AcmeDnsClientContext *context, const char_t *host)
Set the domain name of the ACME-DNS server.
error_t acmeDnsClientRegister(AcmeDnsClientContext *context)
Register endpoint.
error_t acmeDnsClientRegisterTlsInitCallback(AcmeDnsClientContext *context, AcmeDnsClientTlsInitCallback callback)
Register TLS initialization callback function.
unsigned int uint_t
Definition: compiler_port.h:50
char char_t
Definition: compiler_port.h:48
General definitions for cryptographic algorithms.
error_t
Error codes.
Definition: error.h:43
HTTP client (HyperText Transfer Protocol)
#define HttpClientContext
Definition: http_client.h:198
TCP/IP stack core.
#define NetInterface
Definition: net.h:36
uint32_t systime_t
System time.
ACME-DNS client context.
HttpClientContext httpClientContext
HTTP client context.
char_t subDomain[ACME_DNS_CLIENT_MAX_SUB_DOMAIN_LEN+1]
Sub domain.
char_t password[ACME_DNS_CLIENT_MAX_PASSWORD_LEN+1]
Password.
size_t bufferPos
Current position in the buffer.
char_t buffer[ACME_DNS_CLIENT_BUFFER_SIZE+1]
Memory buffer for input/output operations.
char_t fullDomain[ACME_DNS_CLIENT_MAX_FULL_DOMAIN_LEN+1]
Full domain.
uint16_t serverPort
TCP port number.
size_t bufferLen
Length of the buffer, in bytes.
AcmeDnsClientState state
ACME-DNS client state.
systime_t timeout
Timeout value.
AcmeDnsClientTlsInitCallback tlsInitCallback
TLS initialization callback function.
char_t serverName[ACME_DNS_CLIENT_MAX_HOST_LEN+1]
Host name of the ACME-DNS server.
uint_t statusCode
HTTP status code.
char_t username[ACME_DNS_CLIENT_MAX_USERNAME_LEN+1]
User name.
NetInterface * interface
Underlying network interface.
IP network address.
Definition: ip.h:79
TLS (Transport Layer Security)
#define TlsContext
Definition: tls.h:36