Skip to content

Commit 7ff6c43

Browse files
InterLinked1gtjoseph
authored andcommitted
chan_iax2: Add encryption for RSA authentication
Adds support for encryption to RSA-authenticated calls. Also prevents crashes if an RSA IAX2 call is initiated to a switch requiring encryption but no secret is provided. ASTERISK-20219 Change-Id: I18f1f9d7c59b4f9cffa00f3b94a4c875846efd40
1 parent 5e9799a commit 7ff6c43

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

channels/chan_iax2.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -5125,7 +5125,7 @@ static int iax2_call(struct ast_channel *c, const char *dest, int timeout)
51255125
ast_channel_hangupcause_set(c, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
51265126
return -1;
51275127
}
5128-
if (((cai.authmethods & IAX_AUTH_MD5) || (cai.authmethods & IAX_AUTH_PLAINTEXT)) &&
5128+
if (((cai.authmethods & IAX_AUTH_RSA) || (cai.authmethods & IAX_AUTH_MD5) || (cai.authmethods & IAX_AUTH_PLAINTEXT)) &&
51295129
ast_strlen_zero(cai.secret) && ast_strlen_zero(pds.password)) {
51305130
ast_log(LOG_WARNING, "Call terminated. Encryption forced but no secret provided\n");
51315131
return -1;
@@ -8385,6 +8385,18 @@ static int authenticate(const char *challenge, const char *secret, const char *k
83858385
res = 0;
83868386
}
83878387
}
8388+
8389+
if (pvt && !ast_strlen_zero(secret)) {
8390+
struct MD5Context md5;
8391+
unsigned char digest[16];
8392+
8393+
MD5Init(&md5);
8394+
MD5Update(&md5, (unsigned char *) challenge, strlen(challenge));
8395+
MD5Update(&md5, (unsigned char *) secret, strlen(secret));
8396+
MD5Final(digest, &md5);
8397+
8398+
build_encryption_keys(digest, pvt);
8399+
}
83888400
}
83898401
}
83908402
/* Fall back */
@@ -8496,7 +8508,7 @@ static int authenticate_reply(struct chan_iax2_pvt *p, struct ast_sockaddr *addr
84968508

84978509
if (ies->encmethods) {
84988510
if (ast_strlen_zero(p->secret) &&
8499-
((ies->authmethods & IAX_AUTH_MD5) || (ies->authmethods & IAX_AUTH_PLAINTEXT))) {
8511+
((ies->authmethods & IAX_AUTH_RSA) || (ies->authmethods & IAX_AUTH_MD5) || (ies->authmethods & IAX_AUTH_PLAINTEXT))) {
85008512
ast_log(LOG_WARNING, "Call terminated. Encryption requested by peer but no secret available locally\n");
85018513
return -1;
85028514
}
@@ -10959,8 +10971,8 @@ static int socket_process_helper(struct iax2_thread *thread)
1095910971
}
1096010972
break;
1096110973
}
10962-
if (iaxs[fr->callno]->authmethods & IAX_AUTH_MD5)
10963-
merge_encryption(iaxs[fr->callno],ies.encmethods);
10974+
if (iaxs[fr->callno]->authmethods & (IAX_AUTH_MD5 | IAX_AUTH_RSA))
10975+
merge_encryption(iaxs[fr->callno], ies.encmethods);
1096410976
else
1096510977
iaxs[fr->callno]->encmethods = 0;
1096610978
if (!authenticate_request(fr->callno) && iaxs[fr->callno])

doc/UPGRADE-staging/chan_iax2_rsa.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Subject: chan_iax2
2+
3+
Encryption is now supported for RSA authentication.
4+
5+
Currently, these auth configurations will cause a crash:
6+
auth = md5,rsa
7+
auth = plaintext,md5,rsa
8+
9+
With a patched peer, the following will cause a crash:
10+
auth = rsa
11+
auth = md5,rsa
12+
auth = plaintext,md5,rsa
13+
14+
If both the peer and user are patches, no crash occurs.
15+
Existing good configurations should continue to work.

0 commit comments

Comments
 (0)