Beispiel #1
0
AJ_Status AJ_WSL_NET_SetPassphrase(const char* SSID, const char* passphrase, uint32_t passLen)
{
    AJ_Status status = AJ_OK;
    AJ_BufList* passphraseList;
    passphraseList = AJ_BufListCreate();
    uint8_t* hexPassphrase = NULL;

    if (passLen == 64) {
        hexPassphrase = (uint8_t*)AJ_WSL_Malloc(32);
        status = AJ_HexToRaw(passphrase, 64, hexPassphrase, 32);
        if (status == AJ_OK) {
            WSL_MarshalPacket(passphraseList, WMI_SET_PMK, 0, hexPassphrase, 32);
        }
    } else {
        WSL_MarshalPacket(passphraseList, WSL_SET_PASSPHRASE, 0, SSID, passphrase, strlen(SSID), passLen);
    }
    if (status == AJ_OK) {
        WMI_MarshalHeader(passphraseList, 1, 1);
        AJ_InfoPrintf(("AJ_WSL_NET_SetPassphrase(): SET_PASSPHRASE\n"));
        AJ_WSL_WMI_PadPayload(passphraseList);
        //AJ_BufListPrintDumpContinuous(passphraseList);
        status = AJ_WSL_WMI_QueueWorkItem(0, AJ_WSL_WORKITEM(AJ_WSL_WORKITEM_NETWORK, WSL_SET_PASSPHRASE), AJ_WSL_HTC_DATA_ENDPOINT1, passphraseList);
    }
    if (hexPassphrase != NULL) {
        AJ_MemZeroSecure(hexPassphrase, 32);
        AJ_WSL_Free(hexPassphrase);
    }
    return status;
}
/**
 * Finish the hash calculation and free resources.
 * @param context the hash context
 * @param digest - the buffer to hold the digest.
 *        Must be NULL or of size AJ_SHA256_DIGEST_LENGTH.
 *        If the value is NULL, resources are freed but the digest
 *        is not calculated.
 * @return AJ_OK if successful, otherwise error.
 */
AJ_Status AJ_SHA256_Final(AJ_SHA256_Context* context, uint8_t* digest)
{
    AJ_Status status = AJ_OK;

    if (!digest) {
        AJ_MemZeroSecure(context, sizeof(*context));
        AJ_Free(context);
    } else {
        status = getDigest(context, digest, 0);
    }
    return status;
}
/**
 * Retrieve the digest
 * @param context the hash context
 * @param digest the buffer to hold the digest.  Must be of size AJ_SHA256_DIGEST_LENGTH
 * @param keepAlive keep the digest process alive for continuing digest
 * @return AJ_OK if successful, otherwise error.
 */
static AJ_Status getDigest(AJ_SHA256_Context* context, uint8_t* digest,
                           const uint8_t keepAlive) {
    AJ_SHA256_Context tempCtx;
    AJ_SHA256_Context* finalCtx;

    if (keepAlive) {
        memcpy(&tempCtx, context, sizeof(AJ_SHA256_Context));
        finalCtx = &tempCtx;
    } else {
        finalCtx = context;
    }

    SHA256_Final(digest, &finalCtx->internal);
    AJ_MemZeroSecure(finalCtx, sizeof(*finalCtx));

    if (!keepAlive) {
        AJ_Free(context);
    }

    return AJ_OK;
}