Changeset 6118
- Timestamp:
- Dec 16, 2019 12:37:57 PM (5 years ago)
- Location:
- pjproject/trunk/pjmedia
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/errno.h
r5845 r6118 657 657 #define PJMEDIA_SRTP_DTLS_ENOFPRINT (PJMEDIA_ERRNO_START+243) /* 220243 */ 658 658 659 /** 660 * @hideinitializer 661 * No valid SRTP protection profile for DTLS. 662 */ 663 #define PJMEDIA_SRTP_DTLS_ENOPROFILE (PJMEDIA_ERRNO_START+244) /* 220244 */ 664 659 665 #endif /* PJMEDIA_HAS_SRTP */ 660 666 -
pjproject/trunk/pjmedia/src/pjmedia/errno.c
r5845 r6118 171 171 PJ_BUILD_ERR( PJMEDIA_SRTP_DTLS_EPEERNOCERT,"No certificate supplied by peer in DTLS nego" ), 172 172 PJ_BUILD_ERR( PJMEDIA_SRTP_DTLS_EFPNOTMATCH,"Fingerprint from signalling not match to actual fingerprint" ), 173 PJ_BUILD_ERR( PJMEDIA_SRTP_DTLS_ENOFPRINT, "Fingerprint not found" ) 173 PJ_BUILD_ERR( PJMEDIA_SRTP_DTLS_ENOFPRINT, "Fingerprint not found" ), 174 PJ_BUILD_ERR( PJMEDIA_SRTP_DTLS_ENOPROFILE, "No valid SRTP protection profile found" ) 174 175 #endif 175 176 -
pjproject/trunk/pjmedia/src/pjmedia/transport_srtp_dtls.c
r6017 r6118 136 136 static const pj_str_t ID_FINGERPRINT = { "fingerprint", 11 }; 137 137 138 /* Map of OpenSSL-pjmedia SRTP cryptos. Currently OpenSSL seems to 139 * support few cryptos only (based on ssl/d1_srtp.c of OpenSSL 1.1.0c). 140 */ 141 #define OPENSSL_PROFILE_NUM 4 142 143 static char* ossl_profiles[OPENSSL_PROFILE_NUM] = 144 { 145 "SRTP_AES128_CM_SHA1_80", 146 "SRTP_AES128_CM_SHA1_32", 147 "SRTP_AEAD_AES_256_GCM", 148 "SRTP_AEAD_AES_128_GCM" 149 }; 150 static char* pj_profiles[OPENSSL_PROFILE_NUM] = 151 { 152 "AES_CM_128_HMAC_SHA1_80", 153 "AES_CM_128_HMAC_SHA1_32", 154 "AEAD_AES_256_GCM", 155 "AEAD_AES_128_GCM" 156 }; 157 158 /* This will store the valid OpenSSL profiles which is mapped from 159 * OpenSSL-pjmedia SRTP cryptos. 160 */ 161 static char *valid_pj_profiles_list[OPENSSL_PROFILE_NUM]; 162 static char *valid_ossl_profiles_list[OPENSSL_PROFILE_NUM]; 163 static unsigned valid_profiles_cnt; 164 138 165 139 166 /* Certificate & private key */ … … 162 189 } 163 190 191 if (valid_profiles_cnt == 0) { 192 unsigned n, j; 193 int rc; 194 char *p, *end, buf[OPENSSL_PROFILE_NUM*25]; 195 196 /* Create DTLS context */ 197 SSL_CTX *ctx = SSL_CTX_new(DTLS_method()); 198 if (ctx == NULL) { 199 return PJ_ENOMEM; 200 } 201 202 p = buf; 203 end = buf + sizeof(buf); 204 for (j=0; j<PJ_ARRAY_SIZE(ossl_profiles); ++j) { 205 rc = SSL_CTX_set_tlsext_use_srtp(ctx, ossl_profiles[j]); 206 if (rc == 0) { 207 valid_pj_profiles_list[valid_profiles_cnt] = 208 pj_profiles[j]; 209 valid_ossl_profiles_list[valid_profiles_cnt++] = 210 ossl_profiles[j]; 211 212 n = pj_ansi_snprintf(p, end - p, ":%s", pj_profiles[j]); 213 p += n; 214 } 215 } 216 SSL_CTX_free(ctx); 217 218 if (valid_profiles_cnt > 0) { 219 PJ_LOG(4,("DTLS-SRTP", "%s profile is supported", buf)); 220 } else { 221 PJ_PERROR(4, ("DTLS-SRTP", PJMEDIA_SRTP_DTLS_ENOPROFILE, 222 "Error getting SRTP profile")); 223 224 return PJMEDIA_SRTP_DTLS_ENOPROFILE; 225 } 226 } 227 164 228 return PJ_SUCCESS; 165 229 } … … 174 238 dtls_priv_key = NULL; 175 239 } 240 241 valid_profiles_cnt = 0; 176 242 } 177 243 … … 352 418 } 353 419 354 355 /* Map of OpenSSL-pjmedia SRTP cryptos. Currently OpenSSL seems to356 * support few cryptos only (based on ssl/d1_srtp.c of OpenSSL 1.1.0c).357 */358 static char* ossl_profiles[] =359 {360 "SRTP_AES128_CM_SHA1_80",361 "SRTP_AES128_CM_SHA1_32",362 "SRTP_AEAD_AES_256_GCM",363 "SRTP_AEAD_AES_128_GCM"364 };365 static char* pj_profiles[] =366 {367 "AES_CM_128_HMAC_SHA1_80",368 "AES_CM_128_HMAC_SHA1_32",369 "AEAD_AES_256_GCM",370 "AEAD_AES_128_GCM"371 };372 373 374 420 /* Create and initialize new SSL context and instance */ 375 421 static pj_status_t ssl_create(dtls_srtp *ds) … … 387 433 if (ctx == NULL) { 388 434 return GET_SSL_STATUS(ds); 435 } 436 437 if (valid_profiles_cnt == 0) { 438 return PJMEDIA_SRTP_DTLS_ENOPROFILE; 389 439 } 390 440 … … 399 449 pjmedia_srtp_crypto *crypto = &ds->srtp->setting.crypto[i]; 400 450 unsigned j; 401 for (j=0; j<PJ_ARRAY_SIZE(pj_profiles); ++j) { 402 if (!pj_ansi_strcmp(crypto->name.ptr, pj_profiles[j])) { 403 n = pj_ansi_snprintf(p, end-p, ":%s", ossl_profiles[j]); 451 for (j=0; j < valid_profiles_cnt; ++j) { 452 if (!pj_ansi_strcmp(crypto->name.ptr, 453 valid_pj_profiles_list[j])) 454 { 455 n = pj_ansi_snprintf(p, end-p, ":%s", 456 valid_ossl_profiles_list[j]); 404 457 p += n; 405 458 break; … … 410 463 rc = SSL_CTX_set_tlsext_use_srtp(ctx, buf+1); 411 464 PJ_LOG(4,(ds->base.name, "Setting crypto [%s], errcode=%d", buf, rc)); 412 pj_assert(rc == 0); 465 if (rc != 0) { 466 SSL_CTX_free(ctx); 467 return GET_SSL_STATUS(ds); 468 } 413 469 } 414 470
Note: See TracChangeset
for help on using the changeset viewer.