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-2019 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 1.9.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 context size
39 #if (HTTP_CLIENT_SHA512_256_SUPPORT == ENABLED)
40  #define HTTP_CLIENT_MAX_HASH_CONTEXT_SIZE sizeof(Sha512_256Context)
41 #elif (HTTP_CLIENT_SHA256_SUPPORT == ENABLED)
42  #define HTTP_CLIENT_MAX_HASH_CONTEXT_SIZE sizeof(Sha256Context)
43 #else
44  #define HTTP_CLIENT_MAX_HASH_CONTEXT_SIZE sizeof(Md5Context)
45 #endif
46 
47 //Maximum digest size
48 #if (HTTP_CLIENT_SHA512_256_SUPPORT == ENABLED)
49  #define HTTP_CLIENT_MAX_HASH_DIGEST_SIZE 32
50 #elif (HTTP_CLIENT_SHA256_SUPPORT == ENABLED)
51  #define HTTP_CLIENT_MAX_HASH_DIGEST_SIZE 32
52 #else
53  #define HTTP_CLIENT_MAX_HASH_DIGEST_SIZE 16
54 #endif
55 
56 //Maximum response length
57 #if (HTTP_CLIENT_SHA512_256_SUPPORT == ENABLED)
58  #define HTTP_CLIENT_MAX_RESPONSE_LEN 64
59 #elif (HTTP_CLIENT_SHA256_SUPPORT == ENABLED)
60  #define HTTP_CLIENT_MAX_RESPONSE_LEN 64
61 #else
62  #define HTTP_CLIENT_MAX_RESPONSE_LEN 32
63 #endif
64 
65 //C++ guard
66 #ifdef __cplusplus
67  extern "C" {
68 #endif
69 
70 
71 /**
72  * @brief WWW-Authenticate header field
73  **/
74 
75 typedef struct
76 {
77  HttpAuthMode mode; ///<Authentication scheme
78  const char_t *realm; ///<Realm
79  size_t realmLen; ///<Length of the realm
80 #if (HTTP_CLIENT_DIGEST_AUTH_SUPPORT == ENABLED)
81  HttpAuthQop qop; ///<Quality of protection
82  const HashAlgo *algorithm; ///<Digest algorithm
83  const char_t *nonce; ///<Nonce value
84  size_t nonceLen; ///<Length of the nonce value
85  const char_t *opaque; ///<Opaque parameter
86  size_t opaqueLen; ///<Length of the opaque parameter
87  bool_t stale; ///<Stale flag
88 #endif
90 
91 
92 //HTTP client related functions
94 
96 
98  const char_t *value);
99 
100 void httpClientParseQopParam(const HttpParam *param,
101  HttpWwwAuthenticateHeader *authHeader);
102 
103 void httpClientParseAlgorithmParam(const HttpParam *param,
104  HttpWwwAuthenticateHeader *authHeader);
105 
107  const char_t *method, size_t methodLen, const char_t *uri,
108  size_t uriLen, char_t *response);
109 
110 //C++ guard
111 #ifdef __cplusplus
112  }
113 #endif
114 
115 #endif
char char_t
Definition: compiler_port.h:43
const HashAlgo * algorithm
Digest algorithm.
HTTP authentication parameters.
Definition: http_client.h:250
TCP/IP stack core.
#define HttpClientContext
Definition: http_client.h:205
bool_t stale
Stale flag.
HttpAuthQop qop
Quality of protection.
void httpClientParseQopParam(const HttpParam *param, HttpWwwAuthenticateHeader *authHeader)
Parse qop parameter.
const char_t * nonce
Nonce value.
error_t httpClientComputeDigest(HttpClientAuthParams *authParams, const char_t *method, size_t methodLen, const char_t *uri, size_t uriLen, char_t *response)
Digest operation.
HttpAuthMode
HTTP authentication schemes.
Definition: http_common.h:71
error_t httpClientParseWwwAuthenticateField(HttpClientContext *context, const char_t *value)
Parse WWW-Authenticate header field.
HttpAuthQop
Quality of protection (digest authentication)
Definition: http_common.h:83
size_t nonceLen
Length of the nonce value.
Attribute-value pair.
Definition: http_common.h:154
void httpClientInitAuthParams(HttpClientAuthParams *authParams)
Initialize HTTP authentication parameters.
const char_t * opaque
Opaque parameter.
error_t httpClientFormatAuthorizationField(HttpClientContext *context)
Format Authorization header field.
error_t
Error codes.
Definition: error.h:42
HttpAuthMode mode
Authentication scheme.
uint8_t value[]
Definition: dtls_misc.h:143
WWW-Authenticate header field.
size_t opaqueLen
Length of the opaque parameter.
Common interface for hash algorithms.
Definition: crypto.h:1070
const char_t * realm
Realm.
HTTP client (HyperText Transfer Protocol)
size_t realmLen
Length of the realm.
void httpClientParseAlgorithmParam(const HttpParam *param, HttpWwwAuthenticateHeader *authHeader)
Parse algorithm parameter.
int bool_t
Definition: compiler_port.h:49