ZenLib
HTTPClientAuth.h
Go to the documentation of this file.
1
2#ifndef HTTP_CLIENT_AUTH_H
3#define HTTP_CLIENT_AUTH_H
4
5#include "HTTPClientWrapper.h" // Cross platform support
6
7
8#define HASHLEN 16
9#define HASHHEXLEN 32
10#define IN
11#define OUT
12
13typedef char HASH[HASHLEN];
14typedef char HASHHEX[HASHHEXLEN+1];
15typedef unsigned long uint32;
16
17// Base 64 Related
18#define DECODE64(c) (isascii(c) ? base64val[c] : BAD)
19#define BAD -1
20
21static const char base64digits[] =
22"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
23
24static const char base64val[] = {
27BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD, 62, BAD,BAD,BAD, 63,
2852, 53, 54, 55, 56, 57, 58, 59, 60, 61,BAD,BAD, BAD,BAD,BAD,BAD,
29BAD, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
3015, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,BAD, BAD,BAD,BAD,BAD,
31BAD, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
3241, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,BAD, BAD,BAD,BAD,BAD
33};
34
35void HTTPBase64Encoder(unsigned char *out, const unsigned char *in, int inlen);
36int HTTPBase64Decoder(char *out, const char *in);
37
38
39// Digest Related
40// Generates a 32 byte random hexadecimal string such as "4f6ba982..."
41void HTTPDigestGenerateCNonce(char *outbuff);
42
43// Calculate H(A1) as per HTTP Digest spec
45 IN int nAlg, /* 0 = MD5, 1 = MD5-Sess */
46 IN char * pszUserName,
47 IN char * pszRealm,
48 IN int nRealmLength,
49 IN char * pszPassword,
50 IN char * pszNonce,
51 IN int nNonceLength,
52 IN char * pszCNonce,
53 OUT HASHHEX SessionKey
54 );
55
56// Calculate request-digest/response-digest as per HTTP Digest spec
58 IN HASHHEX HA1, // H(A1)
59 IN char * pszNonce, // nonce from server
60 IN int nNonceLength, // Length of nonce
61 IN char * pszNonceCount, // 8 hex digits
62 IN char * pszCNonce, // client nonce
63 IN char * pszQop, // qop-value: "", "auth", "auth-int"
64 IN int nQopLength, // qop param length
65 IN char * pszMethod, // method from the request
66 IN char * pszDigestUri, // requested URL
67 IN int nDigestUriLebgth, // Uri Length
68 IN HASHHEX HEntity, // H(entity body) if qop="auth-int"
69 OUT HASHHEX Response // request-digest or response-digest
70 );
71
72// MD5 structures and functions
74{
77 unsigned char in[64];
78};
79
80void HTTPMD5Init (struct MD5Context *context);
81void HTTPMD5Update (struct MD5Context *context, unsigned char const *buf,unsigned len);
82void HTTPMD5Final (unsigned char digest[16], struct MD5Context *context);
83void HTTPMD5Transform (uint32 buf[4], uint32 const in[16]);
84
85
86// This is needed to make RSAREF happy on some MS-DOS compilers.
87typedef struct MD5Context MD5_CTX;
88
89#endif
#define HASHLEN
Definition: HTTPClientAuth.h:8
int HTTPBase64Decoder(char *out, const char *in)
void HTTPMD5Init(struct MD5Context *context)
void HTTPBase64Encoder(unsigned char *out, const unsigned char *in, int inlen)
unsigned long uint32
Definition: HTTPClientAuth.h:15
void HTTPMD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len)
void HTTPMD5Transform(uint32 buf[4], uint32 const in[16])
void HTTPDigestCalcHA1(IN int nAlg, IN char *pszUserName, IN char *pszRealm, IN int nRealmLength, IN char *pszPassword, IN char *pszNonce, IN int nNonceLength, IN char *pszCNonce, OUT HASHHEX SessionKey)
void HTTPDigestCalcResponse(IN HASHHEX HA1, IN char *pszNonce, IN int nNonceLength, IN char *pszNonceCount, IN char *pszCNonce, IN char *pszQop, IN int nQopLength, IN char *pszMethod, IN char *pszDigestUri, IN int nDigestUriLebgth, IN HASHHEX HEntity, OUT HASHHEX Response)
void HTTPDigestGenerateCNonce(char *outbuff)
#define HASHHEXLEN
Definition: HTTPClientAuth.h:9
char HASH[HASHLEN]
Definition: HTTPClientAuth.h:13
#define IN
Definition: HTTPClientAuth.h:10
char HASHHEX[HASHHEXLEN+1]
Definition: HTTPClientAuth.h:14
#define OUT
Definition: HTTPClientAuth.h:11
void HTTPMD5Final(unsigned char digest[16], struct MD5Context *context)
#define BAD
Definition: HTTPClientAuth.h:19
Definition: HTTPClientAuth.h:74
uint32 buf[4]
Definition: HTTPClientAuth.h:75
uint32 bits[2]
Definition: HTTPClientAuth.h:76
unsigned char in[64]
Definition: HTTPClientAuth.h:77