rtsp_rsa.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. /**
  5. * AirPlay v1 RSA operations using the well-known AirPlay private key.
  6. * Uses mbedtls for RSA (libsodium does not support RSA).
  7. *
  8. * Two operations:
  9. * 1. Apple-Challenge: sign with RSA PKCS1 v1.5 (private encrypt)
  10. * 2. AES key decrypt: RSA OAEP-SHA1 (private decrypt of rsaaeskey)
  11. */
  12. /**
  13. * Build the Apple-Challenge response.
  14. *
  15. * Decodes the base64 challenge, appends our IP + MAC, pads to 32 bytes,
  16. * signs with RSA PKCS1 v1.5, and returns the base64-encoded response
  17. * (no trailing '=' padding).
  18. *
  19. * @param challenge_b64 Base64-encoded Apple-Challenge header value
  20. * @param ip_addr Our IPv4 address in network byte order
  21. * @param mac Our 6-byte MAC address
  22. * @param out_b64 Output buffer for base64-encoded response
  23. * @param out_b64_size Size of output buffer (256 bytes is sufficient)
  24. * @return 0 on success, -1 on failure
  25. */
  26. int rsa_apple_challenge_response(const char *challenge_b64, uint32_t ip_addr,
  27. const uint8_t mac[6], char *out_b64,
  28. size_t out_b64_size);
  29. /**
  30. * Decrypt an RSA-encrypted AES key from ANNOUNCE SDP.
  31. *
  32. * The key is base64-encoded, RSA OAEP-SHA1 encrypted with the
  33. * well-known AirPlay public key. We decrypt with the private key.
  34. *
  35. * @param encrypted_b64 Base64-encoded RSA-encrypted AES key
  36. * @param out_key Output buffer for decrypted AES key (16 bytes)
  37. * @param out_key_size Size of output buffer
  38. * @param out_key_len Actual decrypted key length
  39. * @return 0 on success, -1 on failure
  40. */
  41. int rsa_decrypt_aes_key(const char *encrypted_b64, uint8_t *out_key,
  42. size_t out_key_size, size_t *out_key_len);