Secure random number generator for SRTP key when using PJ_SSL_SOCK_IMP_APPLE (#3860)

This commit is contained in:
Jannis Muething 2024-02-15 04:25:16 +01:00 committed by GitHub
parent beb06a57ca
commit fc3b03c937
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 0 deletions

View File

@ -34,6 +34,9 @@
# endif
#endif
#if (PJ_SSL_SOCK_IMP == PJ_SSL_SOCK_IMP_APPLE)
#include <Security/SecRandom.h>
#endif
#include <pj/rand.h>
@ -134,6 +137,16 @@ static pj_status_t generate_crypto_attr_value(pj_pool_t *pool,
"(native err=%d)", err));
return PJMEDIA_ERRNO_FROM_LIBSRTP(1);
}
#elif defined(PJ_HAS_SSL_SOCK) && (PJ_HAS_SSL_SOCK != 0) && \
(PJ_SSL_SOCK_IMP == PJ_SSL_SOCK_IMP_APPLE)
int err = SecRandomCopyBytes(kSecRandomDefault,
crypto_suites[cs_idx].cipher_key_len,
&key);
if (err != errSecSuccess) {
PJ_LOG(4,(THIS_FILE, "Failed generating random key "
"(native err=%d)", err));
return PJMEDIA_ERRNO_FROM_LIBSRTP(1);
}
#else
PJ_LOG(3,(THIS_FILE, "Warning: simple random generator is used "
"for generating SRTP key"));