コード例 #1
0
ファイル: utils.c プロジェクト: biddyweb/libdmclient
SmlPcdataPtr_t create_chal_meta(dmclt_authType_t type,
                                buffer_t * nonceP)
{
    SmlMetInfMetInfPtr_t metInfP;
    SmlPcdataPtr_t metaP;

    metInfP = smlAllocMetInfMetInf();
    if (!metInfP) return NULL;

    metInfP->type = smlString2Pcdata(auth_type_as_string(type));
    metInfP->format = smlString2Pcdata("b64");
    if (nonceP)
    {
        char * tmp = encode_b64(*nonceP);
        metInfP->nextnonce = smlString2Pcdata(tmp);
        free(tmp);
    }

    metaP = smlAllocPcdata();
    if (!metaP)
    {
        smlFreeMetinfMetinf(metInfP);
        return NULL;
    }
    metaP->contentType = SML_PCDATA_EXTENSION;
    metaP->extension = SML_EXT_METINF;
    metaP->length = 0;
    metaP->content = metInfP;

    return metaP;
 }
コード例 #2
0
ファイル: credentials.c プロジェクト: pysjp/libdmclient
SmlChalPtr_t get_challenge(authDesc_t * authP)
{
    SmlPcdataPtr_t metaP;
    SmlChalPtr_t chalP;

    switch (authP->type)
    {
    case AUTH_TYPE_BASIC:
        metaP = create_chal_meta(authP->type, NULL);
        break;
    case AUTH_TYPE_DIGEST:
        {
            int nonce;
            
            srand(time(0));
            nonce = rand();
            if (authP->data.buffer) free(authP->data.buffer);
            authP->data.buffer = (uint8_t *)&nonce;
            authP->data.len = 8;
            authP->data.buffer = (uint8_t *)encode_b64(authP->data);
            authP->data.len = strlen((const char *)(authP->data.buffer));
            metaP = create_chal_meta(authP->type, &(authP->data));
        }
        break;
    default:
        metaP = NULL;
        break;
    }

    if (metaP)
    {
        chalP = (SmlChalPtr_t)malloc(sizeof(SmlChal_t));
        if(chalP)
        {
            chalP->meta = metaP;
        }
        else
        {
            smlFreePcdata(metaP);
        }
    }
    else
    {
        chalP = NULL;
    }

    return chalP;
}