module-raop-sink: Add Apple-Challenge only if RSA encrypted

Only add Apple-Challenge header once on ANNOUNCE,
and only if RSA encrypted.
This commit is contained in:
Christian Glombek 2023-09-23 16:29:57 +02:00
parent a8f5d20384
commit c4a18d6c5c

View file

@ -1367,10 +1367,17 @@ static int rtsp_do_announce(struct impl *impl)
break; break;
case CRYPTO_RSA: case CRYPTO_RSA:
if ((res = pw_getrandom(impl->aes_key, sizeof(impl->aes_key), 0)) < 0 || uint8_t rac[16];
char sac[16*4];
if ((res = pw_getrandom(rac, sizeof(rac), 0)) < 0 ||
(res = pw_getrandom(impl->aes_key, sizeof(impl->aes_key), 0)) < 0 ||
(res = pw_getrandom(impl->aes_iv, sizeof(impl->aes_iv), 0)) < 0) (res = pw_getrandom(impl->aes_iv, sizeof(impl->aes_iv), 0)) < 0)
return res; return res;
base64_encode(rac, sizeof(rac), sac, '\0');
pw_properties_set(impl->headers, "Apple-Challenge", sac);
rsa_len = rsa_encrypt(impl->aes_key, 16, rsakey); rsa_len = rsa_encrypt(impl->aes_key, 16, rsakey);
if (rsa_len < 0) if (rsa_len < 0)
return -rsa_len; return -rsa_len;
@ -1517,16 +1524,13 @@ static void rtsp_connected(void *data)
{ {
struct impl *impl = data; struct impl *impl = data;
uint32_t sci[2]; uint32_t sci[2];
uint8_t rac[16];
char sac[16*4];
int res; int res;
pw_log_info("connected"); pw_log_info("connected");
impl->connected = true; impl->connected = true;
if ((res = pw_getrandom(sci, sizeof(sci), 0)) < 0 || if ((res = pw_getrandom(sci, sizeof(sci), 0)) < 0) {
(res = pw_getrandom(rac, sizeof(rac), 0)) < 0) {
pw_log_error("error generating random data: %s", spa_strerror(res)); pw_log_error("error generating random data: %s", spa_strerror(res));
return; return;
} }
@ -1534,9 +1538,6 @@ static void rtsp_connected(void *data)
pw_properties_setf(impl->headers, "Client-Instance", pw_properties_setf(impl->headers, "Client-Instance",
"%08x%08x", sci[0], sci[1]); "%08x%08x", sci[0], sci[1]);
base64_encode(rac, sizeof(rac), sac, '\0');
pw_properties_set(impl->headers, "Apple-Challenge", sac);
pw_properties_set(impl->headers, "User-Agent", DEFAULT_USER_AGENT); pw_properties_set(impl->headers, "User-Agent", DEFAULT_USER_AGENT);
pw_rtsp_client_send(impl->rtsp, "OPTIONS", &impl->headers->dict, pw_rtsp_client_send(impl->rtsp, "OPTIONS", &impl->headers->dict,