/******************************************************************************
|
* FILE: MD5Calc.h
|
* Description:
|
* MD5 arithmetic calculation interface class.
|
*
|
* Modified Code History
|
* Mark Date By Modification Reason
|
*******************************************************************************
|
* 01 2007-6-6 Song-Xiaowen Initial creation.
|
******************************************************************************/
|
|
#if !defined(__MD5_CALC_H__)
|
#define __MD5_CALC_H__
|
|
#include "TypeDef.h"
|
//#include "osipparser2/osip_md5.h"
|
#include "osip_md5.h"
|
#include "str.h"
|
|
using namespace std;
|
|
#define DIGEST_MD5HEX_LEN 32
|
#define RANDOM_TAG_LEN 16
|
#define DIGEST_NONCE_LEN 64
|
#define MD5_SESSION_KEY_LEN 64
|
#define MD5_RESPONSE_LEN 64
|
#define DIGEST_HASH_LEN 16
|
#define SIP_PRIVATE_KEY "private key"
|
#define SIP_REGISTER_NONCE_EXPIRE 6 //6 minute
|
#define SIP_MAX_CHALLENGES 3 //if failed challenges > 3,means failure
|
#define SIP_MD5_URL_MAXLEN 128
|
|
|
/**
|
* Definition of the Authorization header.
|
* @struct osip_authorization
|
*/
|
struct rtsp_authorization_t
|
{
|
char auth_type[32]; /**< Authentication Type (Basic or Digest) */
|
char username[64]; /**< login */
|
char realm[128]; /**< realm (as a quoted-string) */
|
char nonce[64]; /**< nonce */
|
char uri[128]; /**< uri */
|
char response[64]; /**< response */
|
char digest[64]; /**< digest */
|
char algorithm[64]; /**< algorithm (optionnal) */
|
char cnonce[64]; /**< cnonce (optionnal) */
|
char opaque[64]; /**< opaque (optionnal) */
|
char message_qop[64]; /**< message_qop (optionnal) */
|
char nonce_count[64]; /**< nonce_count (optionnal) */
|
char auth_param[64]; /**< other parameters (optionnal) */
|
};
|
|
/* Class for MD5 calculation */
|
class CMD5Calc
|
{
|
public:
|
CMD5Calc();
|
~CMD5Calc();
|
|
inline bool MD5Encode(const char *pSource, char target[DIGEST_MD5HEX_LEN+1]);
|
void SIPGenerateNonce(char *pTarget, UINT32 timestamp, const char *pETag);
|
inline bool SIPCheckNonceExpire(const char *pszNonce, const char *pETag);
|
void DigestCalcHA1
|
(
|
char *pszAlg,
|
char *pszUserName,
|
char *pszRealm,
|
char *pszPassword,
|
char *pszNonce,
|
char *pszCNonce,
|
char SessionKey[DIGEST_MD5HEX_LEN+1]
|
);
|
void DigestCalcResponse
|
(
|
char HA1[DIGEST_MD5HEX_LEN+1], /* H(A1) */
|
char *pszNonce, /* nonce from server */
|
char *pszNonceCount, /* 8 hex digits */
|
char *pszCNonce, /* client nonce */
|
char *pszQop, /* qop-value: "", "auth", "auth-int" */
|
char *pszMethod, /* method from the request */
|
char *pszDigestUri, /* requested URL */
|
char HEntity[DIGEST_MD5HEX_LEN+1], /* H(entity body) if qop="auth-int" */
|
char Response[DIGEST_MD5HEX_LEN+1] /* request-digest or response-digest */
|
);
|
|
//Random character string operations
|
inline UINT32 GenerateRandom(UINT32 i1, UINT32 i2);
|
char *GenerateRandomTag(char *pStr);
|
|
char *unquote(char* s);
|
};
|
|
/* Reference md5 functions in libosip2 */
|
typedef osip_MD5_CTX MD5_CTX;
|
#define MD5Init osip_MD5Init
|
#define MD5Update osip_MD5Update
|
#define MD5Final osip_MD5Final
|
|
#endif //#if !defined(__MD5_CALC_H__)
|