Changes due to continue development. Switched to using calls to a single Servlet and telling it what method to execute. The test application was also updated to be more flexible.

This commit is contained in:
Juan Carlos Luciani 2006-05-16 15:24:21 +00:00
parent a6321f6cf0
commit 0805107dd4
9 changed files with 529 additions and 344 deletions

View File

@ -99,6 +99,7 @@ BuildAuthenticateMsg(
* <?xml version="1.0" encoding="ISO-8859-1"?> * <?xml version="1.0" encoding="ISO-8859-1"?>
* <auth_req> * <auth_req>
* <realm>realm value</realm> * <realm>realm value</realm>
* <mechanism>mechanism id value</mechanism>
* <auth_mech_token>authentication mechanism token data</auth_mech_token> * <auth_mech_token>authentication mechanism token data</auth_mech_token>
* </auth_req> * </auth_req>
* *
@ -118,6 +119,13 @@ BuildAuthenticateMsg(
+ strlen(REALM_ELEMENT_NAME) + strlen(REALM_ELEMENT_NAME)
+ 3 // >crlf + 3 // >crlf
+ 1 // < + 1 // <
+ strlen(MECHANISM_ELEMENT_NAME)
+ 1 // >
+ strlen(pAuthContext->pMechanism)
+ 2 // </
+ strlen(MECHANISM_ELEMENT_NAME)
+ 3 // >crlf
+ 1 // <
+ strlen(AUTH_MECH_TOKEN_ELEMENT_NAME) + strlen(AUTH_MECH_TOKEN_ELEMENT_NAME)
+ 1 // > + 1 // >
+ strlen(pAuthMechToken) + strlen(pAuthMechToken)
@ -147,6 +155,13 @@ BuildAuthenticateMsg(
strcat(pMsg, REALM_ELEMENT_NAME); strcat(pMsg, REALM_ELEMENT_NAME);
strcat(pMsg, ">\r\n"); strcat(pMsg, ">\r\n");
strcat(pMsg, "<"); strcat(pMsg, "<");
strcat(pMsg, MECHANISM_ELEMENT_NAME);
strcat(pMsg, ">");
strcat(pMsg, pAuthContext->pMechanism);
strcat(pMsg, "</");
strcat(pMsg, MECHANISM_ELEMENT_NAME);
strcat(pMsg, ">\r\n");
strcat(pMsg, "<");
strcat(pMsg, AUTH_MECH_TOKEN_ELEMENT_NAME); strcat(pMsg, AUTH_MECH_TOKEN_ELEMENT_NAME);
strcat(pMsg, ">"); strcat(pMsg, ">");
strcat(pMsg, pAuthMechToken); strcat(pMsg, pAuthMechToken);
@ -422,6 +437,12 @@ AuthRespCharDataHandler(
CASA_FACILITY_AUTHTOKEN, CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_AUTHENTICATION_FAILURE); CASA_STATUS_AUTHENTICATION_FAILURE);
} }
else if (strncmp(HTTP_NOT_FOUND_STATUS_CODE, s, len) == 0)
{
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_CONFIGURATION_ERROR);
}
else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE, s, len) == 0) else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE, s, len) == 0)
{ {
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR, pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,

View File

@ -40,7 +40,13 @@
"Entry" "Entry"
{ {
"MsmKey" = "8:_71C343EBC4935F8914C3145115EDEC4A" "MsmKey" = "8:_71C343EBC4935F8914C3145115EDEC4A"
"OwnerKey" = "8:_A6E7F30D430741F79B780AA6B1B8D3D3" "OwnerKey" = "8:_7462FCD02DE146CFA809BCDC9FCFA3CC"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_7462FCD02DE146CFA809BCDC9FCFA3CC"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
} }
"Entry" "Entry"
@ -63,14 +69,14 @@
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_A6E7F30D430741F79B780AA6B1B8D3D3" "MsmKey" = "8:_AD11D4F6DDB74221806A3D1AB47BDC41"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
} }
"Entry" "Entry"
{ {
"MsmKey" = "8:_AD11D4F6DDB74221806A3D1AB47BDC41" "MsmKey" = "8:_FE85A5D48B5A23F3077871E9FD2378DE"
"OwnerKey" = "8:_UNDEFINED" "OwnerKey" = "8:_0C0B5ECE6E9C47F1A1F13B58141B5DC8"
"MsmSig" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED"
} }
} }
@ -198,7 +204,7 @@
"SharedLegacy" = "11:FALSE" "SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1" "PackageAs" = "3:1"
"Register" = "3:1" "Register" = "3:1"
"Exclude" = "11:TRUE" "Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE" "IsDependency" = "11:TRUE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
@ -262,6 +268,26 @@
"IsDependency" = "11:TRUE" "IsDependency" = "11:TRUE"
"IsolateTo" = "8:" "IsolateTo" = "8:"
} }
"{A582A373-4685-4296-BEFE-614B80A702C3}:_FE85A5D48B5A23F3077871E9FD2378DE"
{
"SourcePath" = "8:WINHTTP.dll"
"TargetName" = "8:WINHTTP.dll"
"Tag" = "8:"
"Folder" = "8:_01897726E7804A3B875B67A1C2692147"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:TRUE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
} }
"FileType" "FileType"
{ {
@ -393,7 +419,7 @@
{ {
"{8062640A-2EEE-46E9-AB67-688E9A886E9F}:_0C0B5ECE6E9C47F1A1F13B58141B5DC8" "{8062640A-2EEE-46E9-AB67-688E9A886E9F}:_0C0B5ECE6E9C47F1A1F13B58141B5DC8"
{ {
"SourcePath" = "8:..\\windows\\release\\authtoken.dll" "SourcePath" = "8:..\\windows\\Release\\authtoken.dll"
"TargetName" = "8:" "TargetName" = "8:"
"Tag" = "8:" "Tag" = "8:"
"Folder" = "8:_01897726E7804A3B875B67A1C2692147" "Folder" = "8:_01897726E7804A3B875B67A1C2692147"
@ -419,9 +445,9 @@
{ {
} }
} }
"{8062640A-2EEE-46E9-AB67-688E9A886E9F}:_A6E7F30D430741F79B780AA6B1B8D3D3" "{8062640A-2EEE-46E9-AB67-688E9A886E9F}:_7462FCD02DE146CFA809BCDC9FCFA3CC"
{ {
"SourcePath" = "8:..\\mechanisms\\pwd\\windows\\release\\pwmech.dll" "SourcePath" = "8:..\\mechanisms\\pwd\\windows\\Release\\pwmech.dll"
"TargetName" = "8:" "TargetName" = "8:"
"Tag" = "8:" "Tag" = "8:"
"Folder" = "8:_01897726E7804A3B875B67A1C2692147" "Folder" = "8:_01897726E7804A3B875B67A1C2692147"
@ -449,7 +475,7 @@
} }
"{8062640A-2EEE-46E9-AB67-688E9A886E9F}:_AD11D4F6DDB74221806A3D1AB47BDC41" "{8062640A-2EEE-46E9-AB67-688E9A886E9F}:_AD11D4F6DDB74221806A3D1AB47BDC41"
{ {
"SourcePath" = "8:..\\mechanisms\\krb5\\windows\\release\\krb5mech.dll" "SourcePath" = "8:..\\mechanisms\\krb5\\windows\\Release\\krb5mech.dll"
"TargetName" = "8:" "TargetName" = "8:"
"Tag" = "8:" "Tag" = "8:"
"Folder" = "8:_01897726E7804A3B875B67A1C2692147" "Folder" = "8:_01897726E7804A3B875B67A1C2692147"

View File

@ -38,7 +38,7 @@
// //
// Debug tracing level // Debug tracing level
// //
int DebugLevel = 0; int DebugLevel = 3;
// //
// Operating parameter // Operating parameter
@ -147,7 +147,7 @@ ObtainSessionToken(
{ {
// Issue rpc // Issue rpc
retStatus = Rpc(pRpcSession, retStatus = Rpc(pRpcSession,
pAuthContext->pMechanism, "Authenticate",
secureRpcSetting, secureRpcSetting,
pReqMsg, pReqMsg,
&pRespMsg, &pRespMsg,
@ -422,15 +422,21 @@ ObtainAuthTokenFromServer(
//++======================================================================= //++=======================================================================
CasaStatus SSCS_CALL CasaStatus SSCS_CALL
ObtainAuthToken( ObtainAuthToken(
IN const char *pServiceAtHostName, IN const char *pServiceName,
IN const char *pHostName,
INOUT char *pAuthTokenBuf, INOUT char *pAuthTokenBuf,
INOUT int *pAuthTokenBufLen) INOUT int *pAuthTokenBufLen)
// //
// Arguments: // Arguments:
// pServiceAtHostName - // pServiceName -
// Pointer to NULL terminated string that contains the // Pointer to NULL terminated string that contains the
// service@host name to which the client is trying to // name of the service to which the client is trying to
// authenticate. Note that the host portion of the name // authenticate.
//
// pHostName -
// Pointer to NULL terminated string that contains the
// name of the host where resides the service to which the
// client is trying to authenticate. Note that the name
// can either be a DNS name or a dotted IP address. // can either be a DNS name or a dotted IP address.
// //
// pAuthTokenBuf - // pAuthTokenBuf -
@ -458,13 +464,15 @@ ObtainAuthToken(
// L2 // L2
//=======================================================================-- //=======================================================================--
{ {
CasaStatus retStatus = CASA_STATUS_SUCCESS; CasaStatus retStatus = CASA_STATUS_SUCCESS;
char *pParseString; AuthCacheEntry *pCacheEntry;
char *pNormalizedHostName;
DbgTrace(1, "-ObtainAuthToken- Start\n", 0); DbgTrace(1, "-ObtainAuthToken- Start\n", 0);
// Verify the input parameters // Verify the input parameters
if (pServiceAtHostName == NULL if (pServiceName == NULL
|| pHostName == NULL
|| pAuthTokenBufLen == NULL || pAuthTokenBufLen == NULL
|| (*pAuthTokenBufLen != 0 && pAuthTokenBuf == NULL)) || (*pAuthTokenBufLen != 0 && pAuthTokenBuf == NULL))
{ {
@ -475,125 +483,93 @@ ObtainAuthToken(
goto exit; goto exit;
} }
// Allocate space to copy the service name string // Normalize the host name
pParseString = (char*) malloc(strlen(pServiceAtHostName) + 1); pNormalizedHostName = NormalizeHostName(pHostName);
if (pParseString) if (pNormalizedHostName)
{ {
char *pServiceName, *pHostName; // Start user process synchronization
AcquireUserMutex();
// Space allocated, now copy the string onto it // Try to find a cache entry for the service
// and parse it into its components. pCacheEntry = FindEntryInAuthCache(pServiceName, pNormalizedHostName);
strcpy(pParseString, pServiceAtHostName); if (pCacheEntry == NULL)
pServiceName = strtok(pParseString, "@");
pHostName = strtok(NULL, "@");
if (pHostName == NULL)
{ {
DbgTrace(0, "-ObtainAuthToken- Missing host name\n", 0); // No entry found in the cache, create one.
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, pCacheEntry = CreateAuthCacheEntry(pServiceName, pNormalizedHostName);
CASA_FACILITY_AUTHTOKEN, if (pCacheEntry)
CASA_STATUS_INVALID_PARAMETER);
}
else
{
AuthCacheEntry *pCacheEntry;
char *pNormalizedHostName;
// Normalize the host name
pNormalizedHostName = NormalizeHostName(pHostName);
if (pNormalizedHostName)
{ {
// Start user process synchronization int cacheEntryLifetime = retryLifetime; // Initialize to retry in case of failure
AcquireUserMutex();
// Try to find a cache entry for the service // Cache entry created, now try to obtain auth token from the CASA Server
pCacheEntry = FindEntryInAuthCache(pServiceName, pNormalizedHostName); retStatus = ObtainAuthTokenFromServer(pServiceName,
if (pCacheEntry == NULL) pNormalizedHostName,
&pCacheEntry->pToken,
&cacheEntryLifetime);
// Add the entry to the cache if successful or if the reason that we failed
// was because the server was un-available.
if (CASA_SUCCESS(retStatus)
|| CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE)
{ {
// No entry found in the cache, create one. pCacheEntry->status = retStatus;
pCacheEntry = CreateAuthCacheEntry(pServiceName, pNormalizedHostName); AddEntryToAuthCache(pCacheEntry, cacheEntryLifetime);
if (pCacheEntry)
{
int cacheEntryLifetime = retryLifetime; // Initialize to retry in case of failure
// Cache entry created, now try to obtain auth token from the CASA Server
retStatus = ObtainAuthTokenFromServer(pServiceName,
pNormalizedHostName,
&pCacheEntry->pToken,
&cacheEntryLifetime);
// Add the entry to the cache if successful or if the reason that we failed
// was because the server was un-available.
if (CASA_SUCCESS(retStatus)
|| CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE)
{
pCacheEntry->status = retStatus;
AddEntryToAuthCache(pCacheEntry, cacheEntryLifetime);
}
else
{
// Free the entry
FreeAuthCacheEntry(pCacheEntry);
}
}
else
{
DbgTrace(0, "-ObtainAuthToken- Cache entry creation failure\n", 0);
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_INSUFFICIENT_RESOURCES);
}
} }
else else
{ {
// Cache entry found, update the return status with the information saved in it. // Free the entry
retStatus = pCacheEntry->status; FreeAuthCacheEntry(pCacheEntry);
} }
// Try to return auth token if we have one to return
if (CASA_SUCCESS(retStatus))
{
int tokenLen = (int) strlen(pCacheEntry->pToken) + 1;
// We have an authentication token, try to return it to the caller
// after verifying that the supplied buffer is big enough.
if (*pAuthTokenBufLen >= tokenLen)
{
// Return the auth token to the caller
strcpy(pAuthTokenBuf, pCacheEntry->pToken);
}
else
{
DbgTrace(0, "-ObtainAuthToken- The supplied buffer is not large enough", 0);
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_BUFFER_OVERFLOW);
}
// Return the token length to the caller
*pAuthTokenBufLen = tokenLen;
}
// Stop user process synchronization
ReleaseUserMutex();
// Free the space allocated for the normalized host name
free(pNormalizedHostName);
} }
else else
{ {
DbgTrace(0, "-ObtainAuthToken- Host name normalization failed\n", 0); DbgTrace(0, "-ObtainAuthToken- Cache entry creation failure\n", 0);
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN, CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_UNSUCCESSFUL); CASA_STATUS_INSUFFICIENT_RESOURCES);
} }
} }
else
{
// Cache entry found, update the return status with the information saved in it.
retStatus = pCacheEntry->status;
}
// Free allocated space // Try to return auth token if we have one to return
free(pParseString); if (CASA_SUCCESS(retStatus))
{
int tokenLen = (int) strlen(pCacheEntry->pToken) + 1;
// We have an authentication token, try to return it to the caller
// after verifying that the supplied buffer is big enough.
if (*pAuthTokenBufLen >= tokenLen)
{
// Return the auth token to the caller
strcpy(pAuthTokenBuf, pCacheEntry->pToken);
}
else
{
DbgTrace(0, "-ObtainAuthToken- The supplied buffer is not large enough", 0);
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_BUFFER_OVERFLOW);
}
// Return the token length to the caller
*pAuthTokenBufLen = tokenLen;
}
// Stop user process synchronization
ReleaseUserMutex();
// Free the space allocated for the normalized host name
free(pNormalizedHostName);
} }
else else
{ {
DbgTrace(0, "-ObtainAuthToken- Buffer allocation error\n", 0); DbgTrace(0, "-ObtainAuthToken- Host name normalization failed\n", 0);
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_UNSUCCESSFUL);
} }
exit: exit:

View File

@ -400,21 +400,27 @@ GetAuthPolicyRespCharDataHandler(
else if (strncmp(HTTP_UNAUTHORIZED_STATUS_CODE, s, len) == 0) else if (strncmp(HTTP_UNAUTHORIZED_STATUS_CODE, s, len) == 0)
{ {
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR, pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN, CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_AUTHENTICATION_FAILURE); CASA_STATUS_AUTHENTICATION_FAILURE);
}
else if (strncmp(HTTP_NOT_FOUND_STATUS_CODE, s, len) == 0)
{
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_NOT_CONFIGURED);
} }
else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE, s, len) == 0) else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE, s, len) == 0)
{ {
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR, pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN, CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_SERVER_ERROR); CASA_STATUS_SERVER_ERROR);
} }
else else
{ {
DbgTrace(0, "-GetAuthPolicyRespCharDataHandler- Un-expected status\n", 0); DbgTrace(0, "-GetAuthPolicyRespCharDataHandler- Un-expected status\n", 0);
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR, pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN, CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_UNSUCCESSFUL); CASA_STATUS_UNSUCCESSFUL);
} }
// Advanced to the next state // Advanced to the next state

View File

@ -25,23 +25,139 @@
#include <windows.h> #include <windows.h>
#include "casa_c_authtoken.h" #include "casa_c_authtoken.h"
// Globals
char usageString[] = "usage: test -a serverAddress -p serverPort [-h]\n";
int main(int argc, char* argv[]) char *pServerAddress = NULL;
int serverPort = 0;
BOOLEAN execHttpTest = FALSE;
/***********************************************************************
*
* dtoul()
*
***********************************************************************/
int
dtoul(
IN char *cp,
IN int len)
{ {
int retStatus; int n = 0;
char authToken[4096]; int i;
int authTokenLen = sizeof(authToken);
// Now lets obtain a token for our service for (i = 0; i < len; i++, cp++)
retStatus = ObtainAuthToken("testService@137.65.132.44", authToken, &authTokenLen); {
if (retStatus) // Verify that we are dealing with a valid digit
printf("ObtainAuthToken failed with status %d\n", retStatus); if (*cp >= '0' && *cp <= '9')
{
n = 10 * n + (*cp - '0');
}
else
{
printf("-dtoul- Found invalid digit\n");
break;
}
}
return n;
}
/***********************************************************************
*
* EncodeData()
*
***********************************************************************/
int
EncodeData(
IN const void *pData,
IN const int32_t dataLen,
INOUT char **ppEncodedData,
INOUT int32_t *pEncodedDataLen)
{
int8_t base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int retStatus;
int encodedSize;
char *pTmp;
// Determine the encoded size and allocate a buffer to hold the encoded data
encodedSize = ((dataLen * 4 + 2) / 3) - (dataLen % 3 ) + 4;
pTmp = (char*) malloc(encodedSize);
*ppEncodedData = pTmp;
if (*ppEncodedData)
{
uint8_t *pOut, *pIn;
int i;
// Setup pointers to move through the buffers
pIn = (uint8_t*) pData;
pOut = (uint8_t*) *ppEncodedData;
// Perform the encoding
for (i = 0; i < dataLen - 2; i += 3)
{
*pOut++ = base64[(pIn[i] >> 2) & 0x3F];
*pOut++ = base64[((pIn[i] & 0x3) << 4) |
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
*pOut++ = base64[((pIn[i + 1] & 0xF) << 2) |
((int32_t)(pIn[i + 2] & 0xC0) >> 6)];
*pOut++ = base64[pIn[i + 2] & 0x3F];
}
if (i < dataLen)
{
*pOut++ = base64[(pIn[i] >> 2) & 0x3F];
if (i == (dataLen - 1))
{
*pOut++ = base64[((pIn[i] & 0x3) << 4)];
*pOut++ = '=';
}
else
{
*pOut++ = base64[((pIn[i] & 0x3) << 4) |
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
*pOut++ = base64[((pIn[i + 1] & 0xF) << 2)];
}
*pOut++ = '=';
}
*pOut++ = '\0';
// Return the encoded data length
*pEncodedDataLen = (int32_t)(pOut - (uint8_t*)*ppEncodedData);
// Success
retStatus = 0;
}
else
{
printf("-EncodeData- Buffer allocation failure\n");
retStatus = -1;
}
return retStatus;
}
/***********************************************************************
*
* NonHttpTest()
*
***********************************************************************/
void NonHttpTest(void)
{
CasaStatus retStatus;
char authToken[4096];
int authTokenLen = sizeof(authToken);
// Obtain an authentication token for the testService
retStatus = ObtainAuthToken("testService", pServerAddress, authToken, &authTokenLen);
if (!CASA_SUCCESS(retStatus))
{
printf("-NonHttpTest- ObtainAuthToken failed with status %d\n", retStatus);
}
else else
{ {
char serverAddr[] = "137.65.132.44";
char *pServerAddress = serverAddr;
// int serverPort = htons(4444);
int serverPort = 27008;
SOCKET sock; SOCKET sock;
struct sockaddr_in localAddr = {0}; struct sockaddr_in localAddr = {0};
struct sockaddr_in remoteAddr = {0}; struct sockaddr_in remoteAddr = {0};
@ -50,8 +166,7 @@ int main(int argc, char* argv[])
int winsockStartupResult; int winsockStartupResult;
WSADATA winsockData; WSADATA winsockData;
//printf("ObtainAuthToken succedded, token = %s\n", authToken); printf("-NonHttpTest- ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
printf("ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
// Send the token to the server // Send the token to the server
// //
@ -86,7 +201,6 @@ int main(int argc, char* argv[])
} }
//printf("Found %d addresses\n", numAddressesFound); //printf("Found %d addresses\n", numAddressesFound);
// Setup the remote address structure with the lookup results // Setup the remote address structure with the lookup results
remoteAddr.sin_family = AF_INET; remoteAddr.sin_family = AF_INET;
remoteAddr.sin_port = serverPort; remoteAddr.sin_port = serverPort;
@ -98,19 +212,13 @@ int main(int argc, char* argv[])
(struct sockaddr*) &remoteAddr, (struct sockaddr*) &remoteAddr,
sizeof(struct sockaddr_in)) == SOCKET_ERROR) sizeof(struct sockaddr_in)) == SOCKET_ERROR)
{ {
printf("main()- Connection creation failed, error = %d\n", WSAGetLastError()); printf("-NonHttpTest- Connection creation failed, error = %d\n", WSAGetLastError());
} }
else else
{ {
// Now the connection is setup, send the credentials to the server as one line. // Now the connection is setup, send the credentials to the server as one line.
// using our cheesy protocol followed by a hello string. // using our cheesy protocol followed by a hello string.
//
// Send the username to the server (including NULL terminator)
//send(sock, userName, userNameBufLen, 0);
// Send new line
//send(sock, "\n", 1, MSG_NOSIGNAL);
// Send the token to the server (including NULL terminator) // Send the token to the server (including NULL terminator)
send(sock, authToken, (int) strlen(authToken) + 1, 0); send(sock, authToken, (int) strlen(authToken) + 1, 0);
@ -129,17 +237,17 @@ int main(int argc, char* argv[])
} }
else else
{ {
printf("main()- Unsupported address type returned %08X\n", pLookupResult->h_addrtype); printf("-NonHttpTest- Unsupported address type returned %08X\n", pLookupResult->h_addrtype);
} }
} }
else else
{ {
printf("main()- Lookup for %s failed\n", pServerAddress); printf("-NonHttpTest- Lookup for %s failed\n", pServerAddress);
} }
} }
else else
{ {
printf("main()- Unable to bind socket, error = %d", errno); printf("-NonHttpTest- Unable to bind socket, error = %d", errno);
} }
// Close the socket // Close the socket
@ -148,7 +256,7 @@ int main(int argc, char* argv[])
} }
else else
{ {
printf("main()- Unable to open socket, error = %d\n", errno); printf("-NonHttpTest- Unable to open socket, error = %d\n", errno);
} }
// Close winsock // Close winsock
@ -156,104 +264,31 @@ int main(int argc, char* argv[])
} }
else else
{ {
printf("main()- WSAStartup failed, error = %d\n", winsockStartupResult); printf("-NonHttpTest- WSAStartup failed, error = %d\n", winsockStartupResult);
} }
} }
printf("Enter to exit application\n");
getchar();
return 0;
} }
/* /***********************************************************************
int *
EncodeData( * HttpTest()
IN const void *pData, *
IN const int32_t dataLen, ***********************************************************************/
INOUT char **ppEncodedData, void HttpTest(void)
INOUT int32_t *pEncodedDataLen)
{
int8_t g_Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int retStatus;
int encodedSize;
char *pTmp;
// Determine the encoded size and allocate a buffer to hold the encoded data
encodedSize = ((dataLen * 4 + 2) / 3) - (dataLen % 3 ) + 4;
pTmp = (char*) malloc(encodedSize);
*ppEncodedData = pTmp;
if (*ppEncodedData)
{
uint8_t *pOut, *pIn;
int i;
// Setup pointers to move through the buffers
pIn = (uint8_t*) pData;
pOut = (uint8_t*) *ppEncodedData;
// Perform the encoding
for (i = 0; i < dataLen - 2; i += 3)
{
*pOut++ = g_Base64[(pIn[i] >> 2) & 0x3F];
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4) |
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
*pOut++ = g_Base64[((pIn[i + 1] & 0xF) << 2) |
((int32_t)(pIn[i + 2] & 0xC0) >> 6)];
*pOut++ = g_Base64[pIn[i + 2] & 0x3F];
}
if (i < dataLen)
{
*pOut++ = g_Base64[(pIn[i] >> 2) & 0x3F];
if (i == (dataLen - 1))
{
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4)];
*pOut++ = '=';
}
else
{
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4) |
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
*pOut++ = g_Base64[((pIn[i + 1] & 0xF) << 2)];
}
*pOut++ = '=';
}
*pOut++ = '\0';
// Return the encoded data length
*pEncodedDataLen = (int32_t)(pOut - (uint8_t*)*ppEncodedData);
// Success
retStatus = 0;
}
else
{
printf("-EncodeData- Buffer allocation failure\n");
retStatus = -1;
}
return retStatus;
}
int main(int argc, char* argv[])
{ {
int retStatus; CasaStatus retStatus;
char authToken[4096]; char authToken[4096];
int authTokenLen = sizeof(authToken); int authTokenLen = sizeof(authToken);
// Now lets obtain a token for our service // Obtain an authentication token for the testService
retStatus = ObtainAuthToken("testService@137.65.132.44", authToken, &authTokenLen); retStatus = ObtainAuthToken("testService", pServerAddress, authToken, &authTokenLen);
if (retStatus) if (!CASA_SUCCESS(retStatus))
printf("ObtainAuthToken failed with status %d\n", retStatus); {
printf("-HttpTest- ObtainAuthToken failed with status %d\n", retStatus);
}
else else
{ {
char serverAddr[] = "137.65.132.44";
char *pServerAddress = serverAddr;
// int serverPort = htons(4444);
int serverPort = htons(4096);
SOCKET sock; SOCKET sock;
struct sockaddr_in localAddr = {0}; struct sockaddr_in localAddr = {0};
struct sockaddr_in remoteAddr = {0}; struct sockaddr_in remoteAddr = {0};
@ -263,7 +298,7 @@ int main(int argc, char* argv[])
WSADATA winsockData; WSADATA winsockData;
//printf("ObtainAuthToken succedded, token = %s\n", authToken); //printf("ObtainAuthToken succedded, token = %s\n", authToken);
printf("ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen); printf("-HttpTest- ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
// Send the token to the server // Send the token to the server
// //
@ -310,7 +345,7 @@ int main(int argc, char* argv[])
(struct sockaddr*) &remoteAddr, (struct sockaddr*) &remoteAddr,
sizeof(struct sockaddr_in)) == SOCKET_ERROR) sizeof(struct sockaddr_in)) == SOCKET_ERROR)
{ {
printf("main()- Connection creation failed, error = %d\n", WSAGetLastError()); printf("-HttpTest- Connection creation failed, error = %d\n", WSAGetLastError());
} }
else else
{ {
@ -346,7 +381,7 @@ int main(int argc, char* argv[])
} }
else else
{ {
printf("Error encoding credentials\n"); printf("-HttpTest- Error encoding credentials\n");
} }
// Free the buffer containing the basic credentials // Free the buffer containing the basic credentials
@ -354,7 +389,7 @@ int main(int argc, char* argv[])
} }
else else
{ {
printf("Buffer allocation failure\n"); printf("-HttpTest- Buffer allocation failure\n");
} }
// Shutdown the connection // Shutdown the connection
@ -363,17 +398,17 @@ int main(int argc, char* argv[])
} }
else else
{ {
printf("main()- Unsupported address type returned %08X\n", pLookupResult->h_addrtype); printf("-HttpTest- Unsupported address type returned %08X\n", pLookupResult->h_addrtype);
} }
} }
else else
{ {
printf("main()- Lookup for %s failed\n", pServerAddress); printf("-HttpTest- Lookup for %s failed\n", pServerAddress);
} }
} }
else else
{ {
printf("main()- Unable to bind socket, error = %d", errno); printf("-HttpTest- Unable to bind socket, error = %d", errno);
} }
// Close the socket // Close the socket
@ -382,7 +417,7 @@ int main(int argc, char* argv[])
} }
else else
{ {
printf("main()- Unable to open socket, error = %d\n", errno); printf("-HttpTest- Unable to open socket, error = %d\n", errno);
} }
// Close winsock // Close winsock
@ -390,12 +425,89 @@ int main(int argc, char* argv[])
} }
else else
{ {
printf("main()- WSAStartup failed, error = %d\n", winsockStartupResult); printf("-HttpTest- WSAStartup failed, error = %d\n", winsockStartupResult);
} }
} }
}
/***********************************************************************
*
* main()
*
***********************************************************************/
int main(int argc, char* argv[])
{
// Process input parameters
int i = 1;
while(argv[i] != NULL)
{
if (stricmp(argv[i], "-a") == 0)
{
// Server Address option, the next argument should
// contain the address.
i++;
if (argv[i] != NULL)
{
pServerAddress = argv[i];
}
else
{
printf(usageString);
return -1;
}
}
else if (stricmp(argv[i], "-p") == 0)
{
// Server port option, the next argument should
// contain the port.
i++;
if (argv[i] != NULL)
{
serverPort = htons(dtoul(argv[i], strlen(argv[i])));
}
else
{
printf(usageString);
return -1;
}
}
else if (stricmp(argv[i], "-h") == 0)
{
// Perform http test option
execHttpTest = TRUE;
}
// Advance to the next argument
i++;
}
// Verify that the server address and port were specified
if (pServerAddress && serverPort != 0)
{
// Repeat the test when indicated
printf("Press 'Enter' to run test or 'n + Enter' to stop.\n");
while(getchar() != 'n')
{
// Execute the appropriate test
if (execHttpTest)
{
HttpTest();
}
else
{
NonHttpTest();
}
printf("Press 'Enter' to run test or 'n + Enter' to stop.\n");
}
}
else
{
printf(usageString);
return -1;
}
printf("Enter to exit application\n");
getchar();
return 0; return 0;
} }
*/

View File

@ -35,7 +35,7 @@
AdditionalDependencies="authtoken.lib ws2_32.lib" AdditionalDependencies="authtoken.lib ws2_32.lib"
OutputFile="$(OutDir)/test.exe" OutputFile="$(OutDir)/test.exe"
LinkIncremental="2" LinkIncremental="2"
AdditionalLibraryDirectories="..\..\client\win32\Debug" AdditionalLibraryDirectories="&quot;C:\Program Files\novell\CASA\lib&quot;"
GenerateDebugInformation="TRUE" GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/test.pdb" ProgramDatabaseFile="$(OutDir)/test.pdb"
SubSystem="1" SubSystem="1"
@ -44,7 +44,7 @@
Name="VCMIDLTool"/> Name="VCMIDLTool"/>
<Tool <Tool
Name="VCPostBuildEventTool" Name="VCPostBuildEventTool"
CommandLine="copy ..\win32\debug\authtoken.dll debug\authtoken.dll"/> CommandLine="copy ..\windows\debug\authtoken.dll debug\authtoken.dll"/>
<Tool <Tool
Name="VCPreBuildEventTool"/> Name="VCPreBuildEventTool"/>
<Tool <Tool

View File

@ -35,6 +35,7 @@
#define CASA_AUTH_CACHE_REG_KEY "CASA_Auth_Cache" #define CASA_AUTH_CACHE_REG_KEY "CASA_Auth_Cache"
#define CREATION_TIME_REG_VALUE "CreationTime" #define CREATION_TIME_REG_VALUE "CreationTime"
#define EXPIRATION_TIME_REG_VALUE "ExpirationTime" #define EXPIRATION_TIME_REG_VALUE "ExpirationTime"
#define DOES_NOT_EXPIRE_REG_VALUE "DoesNotExpire"
#define STATUS_REG_VALUE "Status" #define STATUS_REG_VALUE "Status"
#define TOKEN_REG_VALUE "Token" #define TOKEN_REG_VALUE "Token"
@ -281,7 +282,8 @@ FindEntryInAuthCache(
{ {
// This entry is for the appropriate CacheKeyName, check if it // This entry is for the appropriate CacheKeyName, check if it
// has not expired. // has not expired.
if (CacheEntryLifetimeExpired(pWrkEntry->creationTime, pWrkEntry->expirationTime)) if (pWrkEntry->doesNotExpire == FALSE
&& CacheEntryLifetimeExpired(pWrkEntry->creationTime, pWrkEntry->expirationTime))
{ {
// The lifetime of the entry has expired, remove it from the in-memory cache // The lifetime of the entry has expired, remove it from the in-memory cache
// and free it. // and free it.
@ -342,6 +344,7 @@ FindEntryInAuthCache(
{ {
DWORD creationTime; DWORD creationTime;
DWORD expirationTime; DWORD expirationTime;
BOOL doesNotExpire;
BOOL deleteCacheKeyNameKey = TRUE; BOOL deleteCacheKeyNameKey = TRUE;
DWORD variableSz; DWORD variableSz;
@ -368,107 +371,124 @@ FindEntryInAuthCache(
&variableSz); &variableSz);
if (status == ERROR_SUCCESS) if (status == ERROR_SUCCESS)
{ {
// Check if the extry lifetime has been exceeded // Read the does not expire
if (CacheEntryLifetimeExpired(creationTime, expirationTime) == FALSE) variableSz = sizeof(doesNotExpire);
status = RegQueryValueExA(hCacheKeyNameRegKey,
EXPIRATION_TIME_REG_VALUE,
NULL,
NULL,
(LPBYTE) &doesNotExpire,
&variableSz);
if (status == ERROR_SUCCESS)
{ {
// Create a AuthCacheEntry // Check if the extry lifetime has been exceeded
pEntry = CreateAuthCacheEntry(pCacheKeyName, pHostName); if (doesNotExpire == TRUE
if (pEntry) || CacheEntryLifetimeExpired(creationTime, expirationTime) == FALSE)
{ {
BOOL entryInitialized = FALSE; // Create a AuthCacheEntry
pEntry = CreateAuthCacheEntry(pCacheKeyName, pHostName);
// Start setting up the AuthCacheEntry if (pEntry)
pEntry->creationTime = creationTime;
pEntry->expirationTime = expirationTime;
// Read the status
variableSz = sizeof(pEntry->status);
status = RegQueryValueExA(hCacheKeyNameRegKey,
STATUS_REG_VALUE,
NULL,
NULL,
(LPBYTE) &pEntry->status,
&variableSz);
if (status == ERROR_SUCCESS)
{ {
// Check if there is also an auth token associated with BOOL entryInitialized = FALSE;
// this entry.
if (pEntry->status == CASA_STATUS_SUCCESS)
{
DWORD tokenSz = 0;
// There should be an auth token associated with this CacheKeyName, // Start setting up the AuthCacheEntry
// first determine what size buffer to allocate for it. pEntry->creationTime = creationTime;
status = RegQueryValueExA(hCacheKeyNameRegKey, pEntry->expirationTime = expirationTime;
TOKEN_REG_VALUE, pEntry->doesNotExpire = doesNotExpire;
NULL,
NULL, // Read the status
(LPBYTE) pEntry->pToken, variableSz = sizeof(pEntry->status);
&tokenSz); status = RegQueryValueExA(hCacheKeyNameRegKey,
if (status == ERROR_SUCCESS STATUS_REG_VALUE,
|| status == ERROR_MORE_DATA) NULL,
NULL,
(LPBYTE) &pEntry->status,
&variableSz);
if (status == ERROR_SUCCESS)
{
// Check if there is also an auth token associated with
// this entry.
if (pEntry->status == CASA_STATUS_SUCCESS)
{ {
// Allocate buffer to hold the auth token DWORD tokenSz = 0;
pEntry->pToken = (char*) malloc(tokenSz);
if (pEntry->pToken) // There should be an auth token associated with this CacheKeyName,
// first determine what size buffer to allocate for it.
status = RegQueryValueExA(hCacheKeyNameRegKey,
TOKEN_REG_VALUE,
NULL,
NULL,
(LPBYTE) pEntry->pToken,
&tokenSz);
if (status == ERROR_SUCCESS
|| status == ERROR_MORE_DATA)
{ {
// Now read token into the allocated buffer // Allocate buffer to hold the auth token
status = RegQueryValueExA(hCacheKeyNameRegKey, pEntry->pToken = (char*) malloc(tokenSz);
TOKEN_REG_VALUE, if (pEntry->pToken)
NULL,
NULL,
(LPBYTE) pEntry->pToken,
&tokenSz);
if (status == ERROR_SUCCESS)
{ {
// The cache entry has been properly initialized, // Now read token into the allocated buffer
// add it to the in-memory cache. status = RegQueryValueExA(hCacheKeyNameRegKey,
entryInitialized = TRUE; TOKEN_REG_VALUE,
deleteCacheKeyNameKey = FALSE; NULL,
InsertHeadList(&g_authCacheListHead, &pEntry->listEntry); NULL,
(LPBYTE) pEntry->pToken,
&tokenSz);
if (status == ERROR_SUCCESS)
{
// The cache entry has been properly initialized,
// add it to the in-memory cache.
entryInitialized = TRUE;
deleteCacheKeyNameKey = FALSE;
InsertHeadList(&g_authCacheListHead, &pEntry->listEntry);
}
else
{
DbgTrace(0, "-FindEntryInAuthCache- Error reading token, status = %d\n", status);
}
} }
else else
{ {
DbgTrace(0, "-FindEntryInAuthCache- Error reading token, status = %d\n", status); DbgTrace(0, "-FindEntryInAuthCache- Unable to allocate buffer for token\n", 0);
} }
} }
else else
{ {
DbgTrace(0, "-FindEntryInAuthCache- Unable to allocate buffer for token\n", 0); DbgTrace(0, "-FindEntryInAuthCache- Error reading token2, status = %d\n", status);
} }
} }
else else
{ {
DbgTrace(0, "-FindEntryInAuthCache- Error reading token2, status = %d\n", status); // There is no auth token associated with this entry
//
// The cache entry has been properly initialized,
// add it to the in-memory cache.
entryInitialized = TRUE;
deleteCacheKeyNameKey = FALSE;
InsertHeadList(&g_authCacheListHead, &pEntry->listEntry);
} }
} }
else else
{ {
// There is no auth token associated with this entry DbgTrace(0, "-FindEntryInAuthCache- Error reading status, status = %d\n", status);
// }
// The cache entry has been properly initialized,
// add it to the in-memory cache. // Free the auth cache entry if it was not successfully initialized
entryInitialized = TRUE; if (entryInitialized == FALSE)
deleteCacheKeyNameKey = FALSE; {
InsertHeadList(&g_authCacheListHead, &pEntry->listEntry); FreeAuthCacheEntry(pEntry);
pEntry = NULL;
} }
} }
else else
{ {
DbgTrace(0, "-FindEntryInAuthCache- Error reading status, status = %d\n", status); DbgTrace(0, "-FindEntryInAuthCache- Error creating auth cache entry\n", 0);
}
// Free the auth cache entry if it was not successfully initialized
if (entryInitialized == FALSE)
{
FreeAuthCacheEntry(pEntry);
pEntry = NULL;
} }
} }
else }
{ else
DbgTrace(0, "-FindEntryInAuthCache- Error creating auth cache entry\n", 0); {
} DbgTrace(0, "-FindEntryInAuthCache- Error reading does not expire, status = %d\n", status);
} }
} }
else else
@ -514,7 +534,7 @@ FindEntryInAuthCache(
void void
AddEntryToAuthCache( AddEntryToAuthCache(
IN AuthCacheEntry *pEntry, IN AuthCacheEntry *pEntry,
IN int entryLifetime) // seconds IN int entryLifetime) // seconds (0 == Lives forever)
// //
// Arguments: // Arguments:
// //
@ -536,7 +556,17 @@ AddEntryToAuthCache(
pEntry->creationTime = GetTickCount(); pEntry->creationTime = GetTickCount();
// First determine the time when the entry is due to expire // First determine the time when the entry is due to expire
pEntry->expirationTime = pEntry->creationTime + (entryLifetime * 1000); if (entryLifetime != 0)
{
pEntry->expirationTime = pEntry->creationTime + (entryLifetime * 1000);
pEntry->doesNotExpire = FALSE;
}
else
{
// The entry does not expire
pEntry->expirationTime = 0;
pEntry->doesNotExpire = TRUE;
}
// Save the entry in our persistent cache (registry) // Save the entry in our persistent cache (registry)
// //
@ -594,32 +624,45 @@ AddEntryToAuthCache(
if (status == ERROR_SUCCESS) if (status == ERROR_SUCCESS)
{ {
status = RegSetValueExA(hCacheKeyNameRegKey, status = RegSetValueExA(hCacheKeyNameRegKey,
STATUS_REG_VALUE, DOES_NOT_EXPIRE_REG_VALUE,
0, 0,
REG_DWORD, REG_DWORD,
(LPBYTE) &pEntry->status, (LPBYTE) &pEntry->doesNotExpire,
sizeof(pEntry->status)); sizeof(pEntry->doesNotExpire));
if (status == ERROR_SUCCESS) if (status == ERROR_SUCCESS)
{ {
// Check if there is also an auth token associated with this entry status = RegSetValueExA(hCacheKeyNameRegKey,
// this entry. STATUS_REG_VALUE,
if (pEntry->status == CASA_STATUS_SUCCESS) 0,
REG_DWORD,
(LPBYTE) &pEntry->status,
sizeof(pEntry->status));
if (status == ERROR_SUCCESS)
{ {
status = RegSetValueExA(hCacheKeyNameRegKey, // Check if there is also an auth token associated with this entry
TOKEN_REG_VALUE, // this entry.
0, if (pEntry->status == CASA_STATUS_SUCCESS)
REG_SZ,
(LPBYTE) pEntry->pToken,
(DWORD) strlen(pEntry->pToken) + 1);
if (status != ERROR_SUCCESS)
{ {
DbgTrace(0, "-AddEntryToAuthCache- Error setting token, status = %d\n", status); status = RegSetValueExA(hCacheKeyNameRegKey,
TOKEN_REG_VALUE,
0,
REG_SZ,
(LPBYTE) pEntry->pToken,
(DWORD) strlen(pEntry->pToken) + 1);
if (status != ERROR_SUCCESS)
{
DbgTrace(0, "-AddEntryToAuthCache- Error setting token, status = %d\n", status);
}
} }
} }
else
{
DbgTrace(0, "-AddEntryToAuthCache- Error setting status, status = %d\n", status);
}
} }
else else
{ {
DbgTrace(0, "-AddEntryToAuthCache- Error setting status, status = %d\n", status); DbgTrace(0, "-AddEntryToAuthCache- Error setting does not expire, status = %d\n", status);
} }
} }
else else

View File

@ -77,6 +77,7 @@ typedef struct _AuthCacheEntry
LIST_ENTRY listEntry; LIST_ENTRY listEntry;
DWORD creationTime; DWORD creationTime;
DWORD expirationTime; DWORD expirationTime;
BOOL doesNotExpire;
char *pHostName; char *pHostName;
char *pCacheKeyName; char *pCacheKeyName;
char *pToken; char *pToken;

View File

@ -251,7 +251,7 @@ InternalRpc(
*ppResponseData = NULL; *ppResponseData = NULL;
// Create rpc target string and convert it to a wide string // Create rpc target string and convert it to a wide string
sprintf(rpcTarget, "CasaAuthTokenSvc/%s", pMethod); sprintf(rpcTarget, "CasaAuthTokenSvc/Rpc?method=%s", pMethod);
retStatus = CopyMultiToWideAlloc(rpcTarget, retStatus = CopyMultiToWideAlloc(rpcTarget,
(int) strlen(rpcTarget), (int) strlen(rpcTarget),
&pWideRpcTarget, &pWideRpcTarget,