http_client_auth.h
Go to the documentation of this file.
1 /**
2  * @file http_client_auth.h
3  * @brief HTTP authentication
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP 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.4
29  **/
30 
31 #ifndef _HTTP_CLIENT_AUTH_H
32 #define _HTTP_CLIENT_AUTH_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "http/http_client.h"
37 
38 //Maximum digest size
39 #if (HTTP_CLIENT_SHA512_256_SUPPORT == ENABLED)
40  #define HTTP_CLIENT_MAX_HASH_DIGEST_SIZE 32
41 #elif (HTTP_CLIENT_SHA256_SUPPORT == ENABLED)
42  #define HTTP_CLIENT_MAX_HASH_DIGEST_SIZE 32
43 #else
44  #define HTTP_CLIENT_MAX_HASH_DIGEST_SIZE 16
45 #endif
46 
47 //Maximum response length
48 #if (HTTP_CLIENT_SHA512_256_SUPPORT == ENABLED)
49  #define HTTP_CLIENT_MAX_RESPONSE_LEN 64
50 #elif (HTTP_CLIENT_SHA256_SUPPORT == ENABLED)
51  #define HTTP_CLIENT_MAX_RESPONSE_LEN 64
52 #else
53  #define HTTP_CLIENT_MAX_RESPONSE_LEN 32
54 #endif
55 
56 //C++ guard
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 
62 /**
63  * @brief WWW-Authenticate header field
64  **/
65 
66 typedef struct
67 {
68  HttpAuthMode mode; ///<Authentication scheme
69  const char_t *realm; ///<Realm
70  size_t realmLen; ///<Length of the realm
71 #if (HTTP_CLIENT_DIGEST_AUTH_SUPPORT == ENABLED)
72  HttpAuthQop qop; ///<Quality of protection
73  const HashAlgo *algorithm; ///<Digest algorithm
74  const char_t *nonce; ///<Nonce value
75  size_t nonceLen; ///<Length of the nonce value
76  const char_t *opaque; ///<Opaque parameter
77  size_t opaqueLen; ///<Length of the opaque parameter
78  bool_t stale; ///<Stale flag
79 #endif
81 
82 
83 //HTTP client related functions
85 
87 
89  const char_t *value);
90 
91 void httpClientParseQopParam(const HttpParam *param,
92  HttpWwwAuthenticateHeader *authHeader);
93 
95  HttpWwwAuthenticateHeader *authHeader);
96 
98  const char_t *method, size_t methodLen, const char_t *uri,
99  size_t uriLen, char_t *response);
100 
101 //C++ guard
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #endif
int bool_t
Definition: compiler_port.h:53
void httpClientParseAlgorithmParam(const HttpParam *param, HttpWwwAuthenticateHeader *authHeader)
Parse algorithm parameter.
const char_t * nonce
Nonce value.
size_t nonceLen
Length of the nonce value.
size_t realmLen
Length of the realm.
const char_t * realm
Realm.
#define HttpClientContext
Definition: http_client.h:198
error_t
Error codes.
Definition: error.h:43
const char_t * opaque
Opaque parameter.
HttpAuthQop
Quality of protection (digest authentication)
Definition: http_common.h:84
WWW-Authenticate header field.
const HashAlgo * algorithm
Digest algorithm.
HTTP client (HyperText Transfer Protocol)
size_t opaqueLen
Length of the opaque parameter.
void httpClientInitAuthParams(HttpClientAuthParams *authParams)
Initialize HTTP authentication parameters.
Attribute-value pair.
Definition: http_common.h:157
char char_t
Definition: compiler_port.h:48
void httpClientParseQopParam(const HttpParam *param, HttpWwwAuthenticateHeader *authHeader)
Parse qop parameter.
error_t httpClientParseWwwAuthenticateField(HttpClientContext *context, const char_t *value)
Parse WWW-Authenticate header field.
HTTP authentication parameters.
Definition: http_client.h:244
error_t httpClientFormatAuthorizationField(HttpClientContext *context)
Format Authorization header field.
uint8_t value[]
Definition: tcp.h:369
Common interface for hash algorithms.
Definition: crypto.h:1046
TCP/IP stack core.
HttpAuthMode mode
Authentication scheme.
HttpAuthMode
HTTP authentication schemes.
Definition: http_common.h:72
HttpAuthQop qop
Quality of protection.
error_t httpClientComputeDigest(HttpClientAuthParams *authParams, const char_t *method, size_t methodLen, const char_t *uri, size_t uriLen, char_t *response)
Digest operation.