📄 xpt-auth.c
字号:
CString_t rc = ""; HttpDigestPtr_t dig; /**************************/ /* check entry conditions */ /**************************/ if ((dest != AUTH_NONE) && (auth != NULL) && ((dig = getDigest (auth, dest)) != NULL) ) rc = dig->achDigest; return rc; }Bool_t authCalcDigest (HttpAuthenticationPtr_t auth, HttpAuthenticationDest_t dest, CString_t szURI, CString_t szMode) { Bool_t rc = true; HttpDigestPtr_t dig; HASHHEX ha1, ha2 = ""; char szSeparator [2] = { ':', 0 }; BufferSize_t cbDigestSize = MAX_DIGEST_SIZE; BufferSize_t cbLength; BufferSize_t cbOffset = 0; // <<<<< ???? char abSave [4]; int cbCopied = 0; /**************************/ /* check entry conditions */ /**************************/ if ((dest != AUTH_NONE) && (auth != NULL) && (szURI != NULL) && (szMode != NULL) && ((dig = getDigest (auth, dest)) != NULL) ) { switch (dig->fType) { case AUTH_DIGEST: /*******************************************/ /* Digest authentication: */ /* compute the digest according to RFC2617 */ /*******************************************/ DigestCalcHA1 ("md5", dig->achUser, dig->achRealm, dig->achPassword, dig->achNonce, dig->achCNonce, ha1); DigestCalcResponse (ha1, dig->achNonce, dig->achNC, dig->achCNonce, dig->achQOp, (char *)szMode, (char *) szURI, ha2, dig->achDigest); rc = true; break; case AUTH_BASIC: /**************************************/ /* Basic authentication: */ /* calculate a base64-encoding of the */ /* string <user>:<password> */ /**************************************/ abSave [0] = abSave [1] = abSave [2] = abSave [3] = '\0'; cbLength = (unsigned long) xppStrlen (dig->achUser); cbCopied += base64Encode ((DataBuffer_t) dig->achDigest, cbDigestSize, (DataBuffer_t) dig->achUser, &cbLength, &cbOffset, 0, (unsigned char *)abSave); cbLength = 1; cbCopied += base64Encode ((DataBuffer_t) dig->achDigest+cbCopied, cbDigestSize-cbCopied, (DataBuffer_t) szSeparator, &cbLength, &cbOffset, 0, (unsigned char *)abSave); cbLength = (unsigned long) xppStrlen (dig->achPassword); cbCopied += base64Encode ((DataBuffer_t) dig->achDigest+cbCopied, cbDigestSize-cbCopied, (DataBuffer_t) dig->achPassword, &cbLength, &cbOffset, 1, (unsigned char *)abSave); dig->achDigest [cbCopied] = '\0'; rc = true; break; default: rc = false; } } else rc = false; return rc; }Bool_t authSetAuthenticationInfo (HttpAuthenticationPtr_t auth, HttpAuthenticationDest_t dest, HttpAuthenticationInfoPtr_t pAuthInfo) { Bool_t rc = true; HttpDigestPtr_t dig; /**************************/ /* check entry conditions */ /**************************/ if ((dest != AUTH_NONE) && (auth != NULL) && (pAuthInfo != NULL) && (pAuthInfo->cbSize == sizeof (HttpAuthenticationInfo_t)) && ((dig = getDigest (auth, dest)) != NULL) ) { if (pAuthInfo->szNonce != NULL) { if (xppStrlen(pAuthInfo->szNonce) < MAX_NONCE_SIZE) xppStrcpy (dig->achNonce, pAuthInfo->szNonce); else rc = false; } if (pAuthInfo->szNC != NULL) { if (xppStrlen(pAuthInfo->szNC) < MAX_NC_SIZE) xppStrcpy (dig->achNC, pAuthInfo->szNC); else rc = false; } if (pAuthInfo->szQop != NULL) { if (xppStrlen(pAuthInfo->szQop) < MAX_QOP_SIZE) xppStrcpy (dig->achQOp, pAuthInfo->szQop); else rc = false; } } else rc = false; return rc; }Bool_t authSetAuthenticationData (HttpAuthenticationPtr_t auth, HttpAuthenticationDest_t dest, HttpAuthenticationDataPtr_t pAuthData) { Bool_t rc = true; HttpDigestPtr_t dig; /**************************/ /* check entry conditions */ /**************************/ if ((dest != AUTH_NONE) && (auth != NULL) && (pAuthData != NULL) && (pAuthData->cbSize == sizeof (HttpAuthenticationData_t)) && ((dig = getDigest (auth, dest)) != NULL) ) { dig->achRealm [0] = '\0'; dig->achNonce [0] = '\0'; dig->achOpaque [0] = '\0'; dig->achDomain [0] = '\0'; dig->achQOp [0] = '\0'; dig->bStale = pAuthData->bStale; if (pAuthData->szRealm != NULL) { /****************************************************/ /* If a Realm value has been preset by the user, */ /* check if it is correct. Return an error, if not. */ /****************************************************/ if (dig->achRealm [0] != '\0') { if (xppStricmp (dig->achRealm, pAuthData->szRealm)) rc = false; } else { /****************************************************/ /* The user did not set a realm value: */ /* It is assumed that the server realm value is OK. */ /****************************************************/ if (xppStrlen(pAuthData->szRealm) < MAX_REALM_SIZE) xppStrcpy (dig->achRealm, pAuthData->szRealm); else rc = false; } } if (pAuthData->szNonce != NULL) { if (xppStrlen(pAuthData->szNonce) < MAX_NONCE_SIZE) xppStrcpy (dig->achNonce, pAuthData->szNonce); else rc = false; } if (pAuthData->szOpaque != NULL) { if (xppStrlen(pAuthData->szOpaque) < MAX_OPAQUE_SIZE) xppStrcpy (dig->achOpaque, pAuthData->szOpaque); else rc = false; } if (pAuthData->szDomain != NULL) { if (xppStrlen(pAuthData->szDomain) < MAX_DOMAIN_SIZE) xppStrcpy (dig->achDomain, pAuthData->szDomain); else rc = false; } if (pAuthData->szQop != NULL) { if (xppStrlen(pAuthData->szQop) < MAX_QOP_SIZE) xppStrcpy (dig->achQOp, pAuthData->szQop); else rc = false; } } return false; }Bool_t authGetUserData (HttpAuthenticationPtr_t auth, HttpAuthenticationDest_t dest, HttpAuthenticationUserDataPtr_t pUserData) { Bool_t rc = false; HttpDigestPtr_t dig; /**************************/ /* check entry conditions */ /**************************/ if ((dest != AUTH_NONE) && (auth != NULL) && (pUserData != NULL) && (pUserData->cbSize == sizeof (HttpAuthenticationUserData_t)) && ((dig = getDigest (auth, dest)) != NULL) ) { rc = true; pUserData->szUser = dig->achUser; pUserData->szPassword = dig->achPassword; pUserData->szRealm = dig->achRealm; pUserData->szCNonce = dig->achCNonce; pUserData->szNC = dig->achNC; } return rc; }Bool_t authGetAuthenticationData (HttpAuthenticationPtr_t auth, HttpAuthenticationDest_t dest, HttpAuthenticationDataPtr_t pAuthData) { Bool_t rc = false; HttpDigestPtr_t dig; /**************************/ /* check entry conditions */ /**************************/ if ((dest != AUTH_NONE) && (auth != NULL) && (pAuthData != NULL) && (pAuthData->cbSize == sizeof (HttpAuthenticationData_t)) && ((dig = getDigest (auth, dest)) != NULL) ) { rc = true; pAuthData->szRealm = dig->achRealm; pAuthData->szNonce = dig->achNonce; pAuthData->szOpaque = dig->achOpaque; pAuthData->szDomain = dig->achDomain; pAuthData->szQop = dig->achQOp; pAuthData->bStale = dig->bStale; } return rc; }/* eof */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -