Exemplo n.º 1
0
void winpr_SHA1_Final(WINPR_SHA1_CTX* ctx, BYTE* output)
{
#if defined(WITH_OPENSSL)
	SHA1_Final(output, (SHA_CTX*) ctx);
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_SHA1_C)
	mbedtls_sha1_finish((mbedtls_sha1_context*) ctx, output);
	mbedtls_sha1_free((mbedtls_sha1_context*) ctx);
#endif
}
Exemplo n.º 2
0
static void sha1_ctx_free( void *ctx )
{
    mbedtls_sha1_free( (mbedtls_sha1_context *) ctx );
    mbedtls_free( ctx );
}
Exemplo n.º 3
0
static void call_action(void *arg)
{
    schedule_msg_t* schedule_msg = (schedule_msg_t*)arg;
    if (schedule_msg != NULL) {
        if (schedule_msg->type == ON_CONNECT) {
            char productKey[64] = {0};
            char deviceName[64] = {0};
            char deviceSecret[64] = {0};
            sscanf((char*)schedule_msg->msg, "%[^|]|%[^|]|%s", productKey, deviceName, deviceSecret);

            if (strlen(productKey) == 0
                || strlen(deviceName) == 0 || strlen(deviceSecret) == 0) {
                be_error(JS_ZIGBEE_TAG, "productKey or deviceName or deviceSecret not exist");
                return;
            }

            unsigned char content[256] = {0};
            sprintf((char*)content, "clientId%sdeviceName%sproductKey%s", deviceName, deviceName, productKey);

            mbedtls_sha1_context sha1_ctx;
            unsigned char k_ipad[64] = {0};
            unsigned char k_opad[64] = {0};
            unsigned char out[20];

            memcpy(k_ipad, deviceSecret, strlen(deviceSecret));
            memcpy(k_opad, deviceSecret, strlen(deviceSecret));

            for (int i = 0; i < sizeof(k_ipad); i++) {
                k_ipad[i] ^= 0x36;
                k_opad[i] ^= 0x5c;
            }

            mbedtls_sha1_init(&sha1_ctx);
            mbedtls_sha1_starts(&sha1_ctx);
            mbedtls_sha1_update(&sha1_ctx, k_ipad, sizeof(k_ipad));
            mbedtls_sha1_update(&sha1_ctx, content, strlen((char*)content));
            mbedtls_sha1_finish(&sha1_ctx, out);

            mbedtls_sha1_init(&sha1_ctx);
            mbedtls_sha1_starts(&sha1_ctx);
            mbedtls_sha1_update(&sha1_ctx, k_opad, sizeof(k_opad));
            mbedtls_sha1_update(&sha1_ctx, out, sizeof(out));
            mbedtls_sha1_finish(&sha1_ctx, out);
            mbedtls_sha1_free(&sha1_ctx);

            char sign[41] = {0};
            for (int i=0; i<sizeof(out); ++i) {
                unsigned char byte[2] = {0};
                byte[0] = out[i] / 16;
                byte[1] = out[i] % 16;

                for(int j=0; j<2; ++j) {
                    if(byte[j] >= 0 && byte[j] <= 9)
                        sign[2 * i + j] = '0' + byte[j];
                    else
                        sign[2 * i + j] = 'a' + byte[j] - 10;
                }
            }

            char json_str[256] = {0};
            sprintf(json_str, "{\"productKey\": \"%s\", \"deviceName\": \"%s\", \"deviceSecret\": \"%s\", \"sign\": \"%s\"}", productKey, deviceName, deviceSecret, sign);

            be_jse_symbol_t* argv[2];
            char addr_str[12] = {0};
            sprintf(addr_str, "%d", schedule_msg->addr);
            argv[0] = new_str_symbol(addr_str);
            argv[1] = new_json_symbol(json_str, strlen(json_str));
            //symbol_relock(argv[0]);
            //symbol_relock(argv[1]);
            be_jse_execute_func(bone_engine_get_executor(), on_connect_func, 2, argv);
            //symbol_unlock(argv[0]);
            //symbol_unlock(argv[1]);
        }  else if (schedule_msg->type == ON_MESSAGE) {
            be_jse_symbol_t* argv[2];
            char addr_str[12] = {0};
            sprintf(addr_str, "%d", schedule_msg->addr);
            argv[0] = new_str_symbol(addr_str);
            argv[1] = new_json_symbol((char*)schedule_msg->msg, schedule_msg->msg_size);
            //symbol_relock(argv[0]);
            //symbol_relock(argv[1]);
            be_jse_execute_func(bone_engine_get_executor(), on_message_func, 2, argv);
            //symbol_unlock(argv[0]);
            //symbol_unlock(argv[1]);
        } else if (schedule_msg->type == BZB_NOTIFY) {
            bone_zigbee_notify(&zigbee);
        } else if (schedule_msg->type == BZB_SEARCH) {
            bone_zigbee_search(&zigbee);
        }
        free(schedule_msg);
        schedule_msg = NULL;
    }
}
Exemplo n.º 4
0
void git_hash_ctx_cleanup(git_hash_ctx *ctx)
{
    assert(ctx);
    mbedtls_sha1_free(&ctx->c);
}