Skip to content

Commit df9aeea

Browse files
InterLinked1gtjoseph
authored andcommitted
chan_iax2: Allow both secret and outkey at dial time
Historically, the dial syntax for IAX2 has held that an outkey (used only for RSA authenticated calls) and a secret (used only for plain text and MD5 authenticated calls, historically) were mutually exclusive, and thus the same position in the dial string was used for both values. Now that encryption is possible with RSA authentication, this poses a limitation, since encryption requires a secret and RSA authentication requires an outkey. Thus, the dial syntax is extended so that both a secret and an outkey can be specified. The new extended syntax is backwards compatible with the old syntax. However, a secret can now be specified after the outkey, or the outkey can be specified after the secret. This makes it possible to spawn an encrypted RSA authenticated call without a corresponding peer being predefined in iax.conf. ASTERISK-29707 #close Change-Id: I1f8149313ed760169d604afbb07720a8b07dd00e
1 parent d116365 commit df9aeea

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

channels/chan_iax2.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5035,6 +5035,8 @@ static int handle_call_token(struct ast_iax2_full_hdr *fh, struct iax_ies *ies,
50355035
*/
50365036
static void parse_dial_string(char *data, struct parsed_dial_string *pds)
50375037
{
5038+
char *outkey = NULL;
5039+
50385040
if (ast_strlen_zero(data))
50395041
return;
50405042

@@ -5057,7 +5059,8 @@ static void parse_dial_string(char *data, struct parsed_dial_string *pds)
50575059
if (pds->username) {
50585060
data = pds->username;
50595061
pds->username = strsep(&data, ":");
5060-
pds->password = data;
5062+
pds->password = strsep(&data, ":");
5063+
outkey = data;
50615064
}
50625065

50635066
data = pds->peer;
@@ -5067,10 +5070,26 @@ static void parse_dial_string(char *data, struct parsed_dial_string *pds)
50675070
/*
50685071
* Check for a key name wrapped in [] in the password position.
50695072
* If found, move it to the key field instead.
5073+
* Also allow for both key and secret to be specified, now that
5074+
* encryption is possible with RSA authentication.
50705075
*/
5071-
if (pds->password && (pds->password[0] == '[')) {
5076+
5077+
if (pds->password && (pds->password[0] == '[')) { /* key (then maybe secret) */
50725078
pds->key = ast_strip_quoted(pds->password, "[", "]");
5073-
pds->password = NULL;
5079+
if (ast_strlen_zero(outkey)) {
5080+
pds->password = NULL;
5081+
ast_debug(1, "Outkey (%s), no secret\n", pds->key);
5082+
} else {
5083+
pds->password = outkey;
5084+
ast_debug(1, "Outkey (%s) and secret (%s)\n", pds->key, pds->password);
5085+
}
5086+
} else if (outkey && (outkey[0] == '[')) { /* secret, then key */
5087+
pds->key = ast_strip_quoted(outkey, "[", "]");
5088+
if (ast_strlen_zero(pds->password)) {
5089+
ast_debug(1, "Outkey (%s), no secret\n", pds->key);
5090+
} else {
5091+
ast_debug(1, "Outkey (%s) and secret (%s)\n", pds->key, pds->password);
5092+
}
50745093
}
50755094
}
50765095

@@ -6468,7 +6487,7 @@ static int decode_frame(ast_aes_decrypt_key *dcx, struct ast_iax2_full_hdr *fh,
64686487
} else {
64696488
struct ast_iax2_mini_enc_hdr *efh = (struct ast_iax2_mini_enc_hdr *)fh;
64706489
if (iaxdebug)
6471-
ast_debug(1, "Decoding mini with length %d\n", *datalen);
6490+
ast_debug(5, "Decoding mini with length %d\n", *datalen);
64726491
if (*datalen < 16 + sizeof(struct ast_iax2_mini_hdr))
64736492
return -1;
64746493
/* Decrypt */
@@ -6506,7 +6525,7 @@ static int encrypt_frame(ast_aes_encrypt_key *ecx, struct ast_iax2_full_hdr *fh,
65066525
} else {
65076526
struct ast_iax2_mini_enc_hdr *efh = (struct ast_iax2_mini_enc_hdr *)fh;
65086527
if (iaxdebug)
6509-
ast_debug(1, "Encoding mini frame with length %d\n", *datalen);
6528+
ast_debug(5, "Encoding mini frame with length %d\n", *datalen);
65106529
padding = 16 - ((*datalen - sizeof(struct ast_iax2_mini_enc_hdr)) % 16);
65116530
padding = 16 + (padding & 0xf);
65126531
memcpy(workspace, poo, padding);
@@ -11993,7 +12012,7 @@ static int socket_process_helper(struct iax2_thread *thread)
1199312012
iaxs[fr->callno]->last = fr->ts;
1199412013
#if 1
1199512014
if (iaxdebug)
11996-
ast_debug(1, "For call=%d, set last=%u\n", fr->callno, fr->ts);
12015+
ast_debug(3, "For call=%d, set last=%u\n", fr->callno, fr->ts);
1199712016
#endif
1199812017
}
1199912018

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Subject: chan_iax2
2+
3+
Both a secret and an outkey may be specified at dial time,
4+
since encryption is possible with RSA authentication.

0 commit comments

Comments
 (0)