示例#1
0
static void
MDString(char *string)
{
    MD5_CTX context;
    unsigned char digest[16];
    unsigned int len = strlen(string);
    xMD5Init(&context);
    xMD5Update(&context, string, len);
    xMD5Final(digest, &context);
    printf("MD5 (\"%s\") = ", string);
    MDPrint(digest);
    printf("\n");
}
示例#2
0
/*---------------------------------------------------------------------------
 *            OBEXH_VerifyAuthResponse
 *---------------------------------------------------------------------------
 *
 * Synopsis: This function is used by both client & servers to verify the
 *           received authentication response digest against the expected value.
 *
 * Return:   TRUE - The response is authenticated.
 */
BOOL OBEXH_VerifyAuthResponse(ObexAuthResponseVerify *Verify)
{
    xMD5Context     context;
    U8              digest[AUTH_NONCE_LEN];

#if XA_ERROR_CHECK == XA_ENABLED
    if (!Verify) {
        return FALSE;
    }
#endif /* XA_ERROR_CHECK == XA_ENABLED */
    ASSERT(Verify);
    
    xMD5Init(&context);
    xMD5Update(&context, Verify->nonce, AUTH_NONCE_LEN);
    xMD5Update(&context, (U8 *)":", 1);
    xMD5Update(&context, Verify->password, Verify->passwordLen);
    xMD5Final(digest, &context);

    return OS_MemCmp(digest, AUTH_NONCE_LEN, Verify->digest, AUTH_NONCE_LEN);
}
示例#3
0
/*---------------------------------------------------------------------------
 *            OBEXH_BuildAuthResponse
 *---------------------------------------------------------------------------
 *
 * Synopsis:  This function is used by applications to build an Authentication
 *            response to a received Challenge. The header is constructed from
 *            the fields in the ObexAuthResponse structure.
 *
 * Return:    TRUE if header was successfully built.
 *            FALSE if headers would exceed limits on buffer or transmit space.
 */
BOOL OBEXH_BuildAuthResponse(ObexAppHandle *AppHndl, ObexAuthResponse *Response, 
                             U8 *Nonce)
{
    U8          len;
    xMD5Context context;
//#if XA_DEBUG == XA_ENABLED
    U8 *orig;
//#endif /* XA_DEBUG == XA_ENABLED */

    OS_LockObex();
#if XA_ERROR_CHECK == XA_ENABLED
    if (!AppHndl || !Response || !Nonce) {
        OS_UnlockObex();
        return FALSE;
    }
#endif /* XA_ERROR_CHECK == XA_ENABLED */
    ASSERT(AppHndl && Response && Nonce);

    len = CALC_RESPONSE_LEN(Response);
//#if XA_DEBUG == XA_ENABLED
    orig = AppHndl->buffer + AppHndl->txLength;
//#endif /* XA_DEBUG == XA_ENABLED */

#if XA_ERROR_CHECK == XA_ENABLED
    if (!ObIsHeaderSpaceAvail(AppHndl, (U16)(len+3))) {
        OS_UnlockObex();
        return FALSE;
    }
#endif
    ASSERT(ObIsHeaderSpaceAvail(AppHndl, (U16)(len+3)));

    /* Build the OBEX Response Header Identifier */
    AppHndl->buffer[AppHndl->txLength++] = OBEXH_AUTH_RESP;
    AppHndl->buffer[AppHndl->txLength++] = (U8)((len+3) >> 8);
    AppHndl->buffer[AppHndl->txLength++] = (U8) (len+3);

    /* Build digest from nonce and password */
    AppHndl->buffer[AppHndl->txLength++] = 0;                /* Request Digest Code */
    AppHndl->buffer[AppHndl->txLength++] = AUTH_NONCE_LEN;   /* Digest Length (16 bytes) */
    xMD5Init(&context);
    xMD5Update(&context, Nonce, AUTH_NONCE_LEN);
    xMD5Update(&context, (U8 *)":", 1);
    xMD5Update(&context, Response->password, Response->passwordLen);
    xMD5Final(AppHndl->buffer+AppHndl->txLength, &context);
    AppHndl->txLength += AUTH_NONCE_LEN;

    /* Add UserId */
    if (Response->userIdLen) {
        AppHndl->buffer[AppHndl->txLength++] = 1;    /* UserId */
        AppHndl->buffer[AppHndl->txLength++] = Response->userIdLen; /* Realm Len */
        OS_MemCopy(AppHndl->buffer+AppHndl->txLength, Response->userId, Response->userIdLen);
        AppHndl->txLength += Response->userIdLen;
    }

    /* Add Nonce */
    AppHndl->buffer[AppHndl->txLength++] = 2;                /* Nonce */
    AppHndl->buffer[AppHndl->txLength++] = AUTH_NONCE_LEN;   /* (16 bytes) */
    OS_MemCopy(AppHndl->buffer+AppHndl->txLength, Nonce, AUTH_NONCE_LEN);
    AppHndl->txLength += AUTH_NONCE_LEN;

//#if XA_DEBUG == XA_ENABLED
    ASSERT((orig + len + 3) == (AppHndl->buffer + AppHndl->txLength));
//#endif
    OS_UnlockObex();
    return TRUE;
}