Example #1
0
int pubnub_encrypt_buffered(char const *cipher_key, pubnub_bymebl_t msg, char *base64_str, size_t *n, pubnub_bymebl_t buffer)
{
    uint8_t const iv[] = "0123456789012345";
    uint8_t key[33];

    cipher_hash(cipher_key, key);
    if (-1 == pbaes256_encrypt(msg, key, iv, &buffer)) {
        return -1;
    }
    return pbbase64_encode_std(buffer, base64_str, n);
}
Example #2
0
int pubnub_encrypt(char const *cipher_key, pubnub_bymebl_t msg, char *base64_str, size_t *n)
{
    pubnub_bymebl_t encrypted;
    uint8_t const iv[] = "0123456789012345";
    uint8_t key[33];
    int result;

    cipher_hash(cipher_key, key);
    encrypted = pbaes256_encrypt_alloc(msg, key, iv);
    if (NULL == encrypted.ptr) {
        return -1;
    }
    result = pbbase64_encode_std(encrypted, base64_str, n);
    free(encrypted.ptr);

    return result;
}
Example #3
0
int pbproxy_http_header_to_send(pubnub_t *p, char* header, size_t n)
{
    PUBNUB_ASSERT_OPT(p != NULL);
    PUBNUB_ASSERT_OPT(header != NULL);

    switch (p->proxy_auth_scheme) {
    case pbhtauBasic:
    {
        int i;
        char prefix[] = "Proxy-Authorization: Basic ";
        char response[128];
        pubnub_bymebl_t data = { (uint8_t*)response, 0 };

        PUBNUB_ASSERT_OPT(n > sizeof prefix);
        memcpy(header, prefix, sizeof prefix);
        n -= sizeof prefix;
        data.size = snprintf(response, sizeof response, "%s:%s", figure_out_username(p), figure_out_password(p));

        PUBNUB_LOG_TRACE("pbproxy_http_header_to_send(): Basic header (before Base64): '%s'\n", response);

        i = pbbase64_encode_std(data, header + sizeof prefix - 1, &n);
        if (0 == i) {
            PUBNUB_LOG_TRACE("pbproxy_http_header_to_send(): Basic header (after Base64): '%s'\n", header);
            p->proxy_authorization_sent = true;
        }
        else {
            PUBNUB_LOG_ERROR("pbproxy_http_header_to_send(): Basic Failed Base64 encoding of header\n");
        }
        return i;
    }
    case pbhtauNTLM:
    {
        char prefix[] = "Proxy-Authorization: NTLM ";
        uint8_t response[PUBNUB_NTLM_MAX_TOKEN];
        pubnub_bymebl_t data = { response, sizeof response };
        int i = pbntlm_core_prep_msg_to_send(p, &data);

        if (i != 0) {
            PUBNUB_LOG_ERROR("pbproxy_http_header_to_send(): NTLM failed preparing message to send'\n");
            return -1;
        }
        if (0 == data.size) {
            return -1;
        }

        PUBNUB_ASSERT_OPT(n > sizeof prefix);
        memcpy(header, prefix, sizeof prefix);
        n -= sizeof prefix;

        i = pbbase64_encode_std(data, header + sizeof prefix - 1, &n);
        if (0 == i) {
            PUBNUB_LOG_TRACE("pbproxy_http_header_to_send(): NTLM header (after Base64): '%s'\n", header);
        }
        else {
            PUBNUB_LOG_ERROR("pbproxy_http_header_to_send(): NTLM Failed Base64 encoding of header\n");
        }

        return i;
    }
    case pbhtauNone:
        return -1;
    default:
        PUBNUB_LOG_ERROR("pbproxy_http_header_to_send(): Proxy auth scheme %d not supported\n", p->proxy_auth_scheme);
        return -1;
    }
}