INT-6557: Allow wildcard pjproject TLS certs#11
Conversation
0465c8b to
83e5545
Compare
pjsip/src/pjsip/sip_transport_tls.c
Outdated
| if (cert_name->slen > 2 && cert_name->ptr[0] == '*' && cert_name->ptr[1] == '.') { | ||
| if (!wildcard_adjusted_remote_set) { | ||
| wildcard_adjusted_remote = *remote_name; | ||
| remove_first_subdomain(&wildcard_adjusted_remote); | ||
| wildcard_adjusted_remote_set = PJ_TRUE; | ||
| } | ||
| pj_str_t wildcard_adjusted_cert_name = *cert_name; | ||
| wildcard_adjusted_cert_name.ptr += 2; | ||
| wildcard_adjusted_cert_name.slen -= 2; | ||
|
|
||
| matched = !pj_stricmp(&wildcard_adjusted_remote, &wildcard_adjusted_cert_name); | ||
| } else { | ||
| matched = !pj_stricmp(remote_name, cert_name); | ||
| } | ||
| break; |
There was a problem hiding this comment.
If it starts with *., remove the first subdomain of the remote name. This *. can only match one subdomain. We also are only considering if the cert name and remote name are both longer than 2, so *. and * in the cert we are not considering as valid (neither should happen ever, technically not sure if they are considered valid by the spec but I imagine not).
pjsip/src/pjsip/sip_transport_tls.c
Outdated
| if (!wildcard_adjusted_remote_set) { | ||
| wildcard_adjusted_remote = *remote_name; | ||
| remove_first_subdomain(&wildcard_adjusted_remote); | ||
| wildcard_adjusted_remote_set = PJ_TRUE; | ||
| } |
There was a problem hiding this comment.
might as well optimize to only do this once.
pjsip/src/pjsip/sip_transport_tls.c
Outdated
| if (serv_cert->subject.cn.slen > 2 && serv_cert->subject.cn.ptr[0] == '*' && serv_cert->subject.cn.ptr[1] == '.') { | ||
| if (!wildcard_adjusted_remote_set) { | ||
| wildcard_adjusted_remote = *remote_name; | ||
| remove_first_subdomain(&wildcard_adjusted_remote); | ||
| wildcard_adjusted_remote_set = PJ_TRUE; | ||
| } | ||
| pj_str_t wildcard_adjusted_cn = serv_cert->subject.cn; | ||
| wildcard_adjusted_cn.ptr += 2; | ||
| wildcard_adjusted_cn.slen -= 2; | ||
|
|
||
| matched = !pj_stricmp(&wildcard_adjusted_remote, &wildcard_adjusted_cn); | ||
| } else { | ||
| matched = !pj_stricmp(remote_name, &serv_cert->subject.cn); | ||
| } |
There was a problem hiding this comment.
Repeat the same logic for the CN.
|
Semgrep found 1 Don't call |
8a4d796 to
6c6a889
Compare
6c6a889 to
5b3664f
Compare
Twilio uses a wildcard TLS cert. If we want to use TLS with them and properly verify their cert, we need to allow these certs, despite them technically not being allowed by the SIP RFC.
Regardless, its better than not verifying the cert as a whole, which is the other option since we are stuck with Twilio as a primary SIP provider.