Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.
HttpAuth.h
00001 //***************************************************************************** 00002 // Copyright (C) 2014 Texas Instruments Incorporated 00003 // 00004 // All rights reserved. Property of Texas Instruments Incorporated. 00005 // Restricted rights to use, duplicate or disclose this code are 00006 // granted through contract. 00007 // The program may not be used without the written permission of 00008 // Texas Instruments Incorporated or against the terms and conditions 00009 // stipulated in the agreement under which this program has been supplied, 00010 // and under no circumstances can it be used with non-TI connectivity device. 00011 // 00012 //***************************************************************************** 00013 00014 /** 00015 * @defgroup HttpAuth 00016 * 00017 * @{ 00018 */ 00019 00020 #ifndef _HTTP_AUTH_H_ 00021 #define _HTTP_AUTH_H_ 00022 00023 #include "HttpConfig.h" 00024 #include "HttpString.h" 00025 #include "HttpRequest.h" 00026 #ifdef HTTP_CORE_ENABLE_AUTH 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif 00031 00032 /** 00033 * @defgroup HttpAuth HTTP Authentication 00034 * This module implements the HTTP digest access authentication routines. 00035 * Note this module is only compiled if HTTP_CORE_ENABLE_AUTH is defined in HttpConfig.h 00036 * 00037 * When a "not authorized" response is sent to the client, the WWW-Authenticate header is built using HttpAuth_ResponseAuthenticate() 00038 * This in turn generates new nonce and opaque values which will be used for authentication. 00039 * Note that since only a single nonce is kept, only one client may ever be authenticated simultaneously. 00040 * When another request with Authorization header is received, it is verified using HttpAuth_RequestAuthenticate() 00041 * If all authentication tests pass, then the appropriate flag is set in the request to indicate that. 00042 * 00043 * @{ 00044 */ 00045 00046 /** 00047 * Initialize the authentication module, so that it accepts the specified username and password 00048 * This function should be called during server initialization in order to set initial user credentials 00049 * This function may then be called at any time during the operation of the server in order to set different user credentials 00050 * @param username The authorized user's username 00051 * @param password The authorized user's password 00052 */ 00053 void HttpAuth_Init(struct HttpBlob username, struct HttpBlob password); 00054 00055 /** 00056 * Builds and returns the WWW-Authenticate response header. 00057 * This implies generating a new nonce, etc. 00058 * Notes about return value: 00059 * Upon entry, pWWWAuthenticate should point to the place in the packet-send buffer where the header needs to be generated, and also specify the maximum amount of bytes available for the header at that place 00060 * Upon return, pWWWAuthenticate points to the same location, but specifies the actual length of the header. 00061 * If the returned length is 0, this means that there was not enough room in the buffer for the header. 00062 * In such a case, the core may try again with a larger buffer 00063 * @param pRequest All data about the request 00064 * @param[in,out] pWWWAuthenticate On entry specifies the memory location to build the header at, and the maximum size. On return, specifies the same location and the actual size of the header line 00065 */ 00066 void HttpAuth_ResponseAuthenticate(struct HttpRequest* pRequest, struct HttpBlob* pWWWAuthenticate); 00067 00068 /** 00069 * Check the authentication header in a request, and either authorize the request or deny it 00070 * If the authorization succeeds, then HTTP_REQUEST_FLAG_AUTHENTICATED is added to the request flags 00071 * @param pRequest All data about the request to authorize 00072 * @param authorization The full string of the Authorization header 00073 */ 00074 void HttpAuth_RequestAuthenticate(struct HttpRequest* pRequest, struct HttpBlob authorization); 00075 00076 static UINT16 HttpAuth_VerifyHeaderNameValue(struct HttpBlob *location, char* nameToken, UINT8 tokenlenLen, char *value, UINT8 valuelen, char** outValue); 00077 static void AddStringToBlob(struct HttpBlob * trgt, char *str, UINT16 length); 00078 static void Generate32BytesRandomString(UINT8 *str); 00079 static void MD5_FinalToString(UINT8* str, MD5_CTX *md5stat); 00080 static UINT32 GetRandomUint(void); 00081 00082 00083 /// @} 00084 #ifdef __cplusplus 00085 } 00086 #endif /* __cplusplus */ 00087 00088 #endif // HTTP_CORE_ENABLE_AUTH 00089 00090 #endif // _HTTP_AUTH_H_ 00091
Generated on Tue Jul 12 2022 22:22:38 by 1.7.2