Module: kamailio
Branch: master
Commit: e5a723dfb0f38b0871d4fe624d57dbaa90e3b3bb
URL: https://github.com/kamailio/kamailio/commit/e5a723dfb0f38b0871d4fe624d57dba…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-11-10T12:36:23+01:00
core: added --cfg-print to help message
---
Modified: src/main.c
---
Diff: https://github.com/kamailio/kamailio/commit/e5a723dfb0f38b0871d4fe624d57dba…
Patch: https://github.com/kamailio/kamailio/commit/e5a723dfb0f38b0871d4fe624d57dba…
---
diff --git a/src/main.c b/src/main.c
index 722ad6c33b..0917561a4a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -169,6 +169,7 @@ Options:\n\
-b nr Maximum receive buffer size which will not be exceeded by\n\
auto-probing procedure even if OS allows\n\
-c Check configuration file for syntax errors\n\
+ --cfg-print Print configuration file evaluating includes and ifdefs\n\
-d Debugging level control (multiple -d to increase the level from 0)\n\
--debug=val Debugging level value\n\
-D Control how daemonize is done:\n\
<!--
Kamailio Project uses GitHub Issues only for bugs in the code or feature requests. Please use this template only for bug reports.
If you have questions about using Kamailio or related to its configuration file, ask on sr-users mailing list:
* http://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
If you have questions about developing extensions to Kamailio or its existing C code, ask on sr-dev mailing list:
* http://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Please try to fill this template as much as possible for any issue. It helps the developers to troubleshoot the issue.
If there is no content to be filled in a section, the entire section can be removed.
You can delete the comments from the template sections when filling.
You can delete next line and everything above before submitting (it is a comment).
-->
### Description
I've been trying to setup kamailio with the latest freeradius-client. I've been using the docker image `kamailio/kamailio:5.3.1-jessie` adding the freeradius-client (latest github pool).
However it seems that kamailio cannot create a proper radius request and fails with error `3(9) ERROR: auth_radius [sterman.c:264]: radius_authorize_sterman(): unable to add User-Name attribute`
### Troubleshooting
#### Reproduction
Install freeradius-client
```
git clone https://github.com/FreeRADIUS/freeradius-client.git \
&& cd freeradius-client/ \
&& ./configure \
&& make \
&& make install
```
Modify the `/usr/local/etc/radiusclient/dictionary` and append the following lines
```
$INCLUDE /etc/radiusclient/dictionary.sip
$INCLUDE /etc/radiusclient/dictionary.kamailio # https://github.com/kamailio/kamailio/blob/master/src/modules/auth_radius/cf…
```
Configure auth_radius
```
loadmodule "auth_radius.so"
loadmodule "misc_radius.so"
modparam("auth_radius|misc_radius", "radius_config", "/usr/local/etc/radiusclient/radiusclient.conf")
```
#### Debugging Data
I've went on the tried to debug the issue from the freeradius-client's point of view since it was easier to compile and iterate, and I've added various logs here and there to try and figure out what was wrong. From what I've seen, kamailio invokes `INIT_AV` to setup the `attrs` dictionary containing the dictionary attributes and matching values.
https://github.com/kamailio/kamailio/blob/360e012d9d93c80b62b6e75bfac6e3340…
I've traced the `rc_dict_findattr` and it seems that the library properly returns `User-Name` attribute with value `1`.
However in the `radius_authorize_sterman` function
https://github.com/kamailio/kamailio/blob/360e012d9d93c80b62b6e75bfac6e3340…
the application tries to add the AVPs by invoking `rc_avpair_add` and passing `attr[...].v` value. I've logged the `rc_avpair_add` parameters passed and it seems that `attr[...].v` is not 1 as expected but 0, thus failing since 0 is an invalid attribute code.
I modified freeradius-client to replace `attrid` with 1 if it were a 0 as a test, and it seems that all calls to `rc_avpair_add` by sterman.c are passing 0 as attribute value leading to a radius message like:
```
(0) User-Name = "test@localhost"
(0) User-Name = "test"
(0) User-Name = "localhost"
(0) User-Name = "X3q5AV96t9WlJ5ZnoFFQQq/ftg7u+Mx5KRxYYIA="
(0) User-Name = "sip:localhost"
(0) User-Name = "REGISTER"
(0) User-Name = "bc6c2152d2e068e16f76188d69e66340"
(0) User-Name = "\017"
(0) User-Name = "test"
(0) NAS-Port = 5060
(0) NAS-IP-Address = 10.10.10.4
```
(As you can see pretty much all attributes are replaced by User-Name)
It looks like `attrs` dictionary although initialized at `mod_init`, at a later stage is somehow corrupted or reset.
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
```
version: kamailio 5.3.1 (x86_64/linux)
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
compiled with gcc 4.9.2
```
* **Operating System**:
<!--
Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...;
Kernel details (output of `uname -a`)
-->
```
Linux bea2be591c38 4.19.76-linuxkit #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 GNU/Linux
```
This is tested on a docker installation using `kamailio/kamailio:5.3.1-jessie`
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2496
Module: kamailio
Branch: 5.4
Commit: 4b5f5636143037ff6620b88e03e57c05a91eabc4
URL: https://github.com/kamailio/kamailio/commit/4b5f5636143037ff6620b88e03e57c0…
Author: Henning Westerholt <hw(a)skalatan.de>
Committer: Henning Westerholt <hw(a)skalatan.de>
Date: 2020-11-09T12:53:36Z
crypto: properly initialize key and iv to 0, add comment regarding the size of IV
- properly initialize key and iv to 0, otherwise invalid data might be printed
- the initialization vector for AES will be always AES blocksize, e.g. 128 bits
(cherry picked from commit e9624bc4823cfba0bd9536a70b9eeadecb2a537e)
---
Modified: src/modules/crypto/crypto_aes.c
---
Diff: https://github.com/kamailio/kamailio/commit/4b5f5636143037ff6620b88e03e57c0…
Patch: https://github.com/kamailio/kamailio/commit/4b5f5636143037ff6620b88e03e57c0…
---
diff --git a/src/modules/crypto/crypto_aes.c b/src/modules/crypto/crypto_aes.c
index 8b80d62a29..f9aacf5410 100644
--- a/src/modules/crypto/crypto_aes.c
+++ b/src/modules/crypto/crypto_aes.c
@@ -76,7 +76,9 @@ int crypto_aes_init(unsigned char *key_data, int key_data_len,
{
int i, nrounds = 5;
int x;
- unsigned char key[32], iv[32];
+ unsigned char key[32], iv[32]; /* IV is only 16 bytes, but makes it easier */
+ memset(key, 0, sizeof(key));
+ memset(iv, 0, sizeof(iv));
/*
* Gen key & IV for AES 256 CBC mode. A SHA1 digest is used to hash
Module: kamailio
Branch: master
Commit: e9624bc4823cfba0bd9536a70b9eeadecb2a537e
URL: https://github.com/kamailio/kamailio/commit/e9624bc4823cfba0bd9536a70b9eead…
Author: Henning Westerholt <hw(a)skalatan.de>
Committer: Henning Westerholt <hw(a)skalatan.de>
Date: 2020-11-09T12:52:07Z
crypto: properly initialize key and iv to 0, add comment regarding the size of IV
- properly initialize key and iv to 0, otherwise invalid data might be printed
- the initialization vector for AES will be always AES blocksize, e.g. 128 bits
---
Modified: src/modules/crypto/crypto_aes.c
---
Diff: https://github.com/kamailio/kamailio/commit/e9624bc4823cfba0bd9536a70b9eead…
Patch: https://github.com/kamailio/kamailio/commit/e9624bc4823cfba0bd9536a70b9eead…
---
diff --git a/src/modules/crypto/crypto_aes.c b/src/modules/crypto/crypto_aes.c
index 8b80d62a29..f9aacf5410 100644
--- a/src/modules/crypto/crypto_aes.c
+++ b/src/modules/crypto/crypto_aes.c
@@ -76,7 +76,9 @@ int crypto_aes_init(unsigned char *key_data, int key_data_len,
{
int i, nrounds = 5;
int x;
- unsigned char key[32], iv[32];
+ unsigned char key[32], iv[32]; /* IV is only 16 bytes, but makes it easier */
+ memset(key, 0, sizeof(key));
+ memset(iv, 0, sizeof(iv));
/*
* Gen key & IV for AES 256 CBC mode. A SHA1 digest is used to hash