Commit Graph

5071 Commits

Author SHA1 Message Date
Holger Hans Peter Freyther 58ec15c4ed configure: No need to check for crypt here
We just link to libosmovty and if it requires crypt internally it
needs to link to that (and not us). This looks like a left-over
from when we moved the VTY code out of OpenBSC
2015-07-02 09:40:03 +02:00
Holger Hans Peter Freyther 9f95ae8885 nat: Use RAND_bytes instead of /dev/urandom
We don't need to consume all the entropy of the kernel but can
use libcrypto (OpenSSL) to generate random data. It is not clear
if we need to call RAND_load_file but I think we can assume that
our Unices have a /dev/urandom.

This takes less CPU time, provides good enough entropy (in theory)
and leaves some in the kernel entropy pool.
2015-07-01 08:34:16 +02:00
Holger Hans Peter Freyther 8ee53ed9ec Merge branch 'zecke/features/auth'
Introduce another authentication scheme using MILENAGE. In the
future reading from /dev/urandom will be replaced with libcrypto.
2015-07-01 08:19:51 +02:00
Holger Hans Peter Freyther 694d98042f nat: After we identified the bsc check the key
We are using the token to find the right bsc_config and
then we can use the last_rand of the bsc_connection to
calculate the expected result and try to compare it with
a time constant(???) memcmp.
2015-07-01 08:16:41 +02:00
Holger Hans Peter Freyther e2ac6b77fe bsc: Check for the rand and then generate a res
Check if the NAT has sent 16 bytes of RAND and if a key
has been configured in the system and then generate a
result using milenage. The milenage res will be sent and
noth the four byte GSM SRES derivation.
2015-07-01 08:16:41 +02:00
Holger Hans Peter Freyther 9705671025 nat: Send 16 bytes of rand to the BSC and remember it
Generate 16 byte of random data to be used for A3A8 by
the BSC in the response. We can't know which BSC it is
at this point and I don't want to send another message
once the token has been received so always send the data
with an undefined code. The old BSCs don't parse the
message and will happily ignore the RAND.

/dev/urandom can give short reads on Linux so loop
around it until the bytes have been read from the kernel.
2015-07-01 08:16:40 +02:00
Holger Hans Peter Freyther fce6971fe3 nat: Provide access to /dev/urandom for the code
Instead of doing open/read/close all the time, open the
FD in the beginning and keep it open. To scare me even
more I have seen /dev/urandom actually providing a short
read and then blocking but it seems to be the best way
to get the random byes we need for authentication.

So one should/could run the cheap random generator on
the system (e.g. haveged) or deal with the NAT process
to block.
2015-07-01 08:16:40 +02:00
Holger Hans Peter Freyther 8a8df80772 bsc/nat: Fix the structure of the identity request message
Unfortunately the basic structure of the response is broken.
There is a two byte length followed by data. The concept of
a 'tag' happens to be the first byte of the data.

This means we want to write strlen of the token, then we
want to write the NUL and then we need to account for the
tag in front.

Introduce a flag if the new or old format should be used.
This will allow to have new BSCs talk to old NATs without
an additional change. In the long run we can clean that up.
2015-07-01 08:16:40 +02:00
Holger Hans Peter Freyther 0363d1bb97 nat: Close the connection after we couldn't find the user
In case the token was not correct, just close the connection.
It is not clear that forcing a new TCP connection is going to
give us any extra security here. But with the upcoming auth
handling it does make sense to have both case look similar.
2015-07-01 08:16:40 +02:00
Holger Hans Peter Freyther aa0cecd9b7 nat: Factor out the config by token search
In the upcoming authentication improvements it is nice to
separate the finding of the config from the post-allow
handling of it.
2015-07-01 08:16:40 +02:00
Holger Hans Peter Freyther 2dd18bdd87 nat: Add size check for the payload
The msgb will always have these bytes but it is better practice
to verify that the message really has space for the two bytes.
2015-07-01 08:16:40 +02:00
Holger Hans Peter Freyther 57ee780789 bts: Arfcn can never be smaller than 0
Remove the condition because it can never be true.

Fixes: Coverity CID#1307793
2015-06-20 18:45:35 +02:00
Andreas Rottmann 797eb7b592 build: avoid spurious hard dependency on libosmo-sccp
In the libfilter source code, which is built regardless of --enable-nat,
headers from libosmo-sccp were used, thus causing a build failure (see
below) when building without --enable-nat, and libosmo-sccp not being
installed (or being installed in a prefix not otherwise included in the
build).

The build fails like this:

In file included from ../../../src/libfilter/bsc_msg_filter.c:27:0:
../../../include/openbsc/bsc_nat_sccp.h:27:37: fatal error: osmocom/sccp/sccp_types.h: No such file or directory

As the includes seem not to be actually needed, this change fixes the
issue by just omitting them.
2015-06-19 20:58:35 +02:00
Andreas Rottmann 4bb3fccb75 Fix "make distcheck"
Running "make distcheck" failed trying to generate ".version" into the
read-only unpacked source directory. Actually shipping ".version" in the
tarball fixes that.
2015-06-19 20:57:48 +02:00
Andreas Rottmann b25c8342cc Fix build wrt. missing CFLAGS constituents
When libosmo-netif and/or libosmo-abis are installed in distinct
prefixes, the build failed with non-found headers.
2015-06-19 20:56:53 +02:00
Michael McTernan c58a1e573b Fix GSM900 ARFCN range check
Allow ARFCN 0 to be used in GSM900 band.
2015-06-19 20:51:43 +02:00
Holger Hans Peter Freyther ce97a06fa3 bsc: Attempt to fix crash when sending a SCCP CREF message
There was no context for the SCCP CREF message and this means
that the msc_con was a plain NULL pointer that was dereferenced
and the application would crash.

Use the new API to pass the incoming MSC Connection which sould
be used for the SCCP CREF message as context. The code has not
been fed with an actual SCCP CR message.
2015-06-15 09:47:45 +02:00
Holger Hans Peter Freyther 0958938d4e sgsn: Simplify finding/using the first address of the result
The loop was used to print all returned addresses but we can
simply pick the first one. This is fixing a coverity issue that
the loop will be executed eaxactly once (and that was on
purpose).

Simplify the code and just take the first element (which might
be NULL).

Fixes: Coverity CID#1302852
2015-06-02 09:51:32 +02:00
Holger Hans Peter Freyther f2e114ac85 sgsn: seleted_apn_str might be NULL do not strcpy
The subscriber might simply not be allowed to use the APN
that was specified. So selected_apn_str might very well be
NULL.

Fixes: Coverity CID#1302853
2015-06-02 09:46:32 +02:00
Holger Hans Peter Freyther 65b0efe56e sgsn: Check the return value of osmo_fd_register
We can't do much in case the fd is failing to be registered.
There should be a timeout that is catching this and it might
be able to repair it self.

Fixes: Coverity CID#1302854
2015-06-02 09:46:11 +02:00
Alexander Chemeris c36a13b073 libbsc: Move SIs update/generation for a BTS into a separate function.
The code to do that doesn't belong to the control interface, so
abstract it out to a separate function gsm_bts_set_system_infos().

[hfreyther: Fix the coding style...]
2015-06-02 08:43:29 +02:00
Holger Hans Peter Freyther 9cb249bf84 sgsn: Do not search the name with the "domain" name attached to it
In case the query for "hostname" will fail c-ares will append the
domain name of /etc/resolv.conf and query again. We don't want that
so claim we provide a list of domain names and then don't provide
any.

I didn't intend to have pushed the c-ares code to master yet.
2015-06-01 18:46:12 +02:00
Ivan Kluchnikov 5fd0c64e0a gsm_04_08: Use osmo_assert for transt->conn and conn only in case of paging succeeded
setup_trig_pag_evt function can receive parameter conn = NULL, if T3113 expires.
2015-05-29 15:14:23 +02:00
Holger Hans Peter Freyther b7ae0b34f9 ggsn: The id is a uint32_t don't print it as signed
This was noticed as I started to use UINT32_MAX for
dynamically created GGSNs.
2015-05-29 15:11:55 +02:00
Holger Hans Peter Freyther a5a6da46a0 sgsn: Allow to specify the DNS servers that should be used
If no server is specified the default list will be used. This
allows to separate the servers for the local network and GRX
from each other.
2015-05-25 15:58:02 +08:00
Holger Hans Peter Freyther 39c430ee29 sgsn: Allow to resolve the IPv4 address of a GGSN through DNS
For real networks we need to check if the requested APN string
is allowed and then resolve the GGSN address through DNS. There
are countries with two or three digit MNCs and one could either
try to keep a list of countries that have two/three digits or
just try both of them. I have opted for the later for the ease
of the implementation.

C-Ares doesn't allow to cancel a request so we will need to
have the MMCTX and the Lookup have different lifetimes. We simply
set ->mmctx to NULL in case the MMCTX dies more early.

The selected and verified apn_str will be copied into the out
parameter. In case no static APN/GGSN config is present and the
dynamic mode is enabled a request will be made.
2015-05-25 15:57:57 +08:00
Holger Hans Peter Freyther 66e7106d39 sgsn: Integrate c-ares with the osmocom event loop
c-ares is an asynchronous DNS resolver and we need it to
resolve the GGSN address. This is integrating the library
into our infrastructure. We will create and maintain a list
of registered FDs (c-ares is currently only using one of
them) and (re-)schedule the timer after events occurred.
2015-05-25 15:39:59 +08:00
Holger Hans Peter Freyther ccd2312d10 sgsn: Create a copy of the msgb for later usage
When needing to do an asynchronous DNS query we need
to keep the TLV data around. So create a wrapper that
takes a copy of it and frees it after the call. I can
change the code to add an out parameter to decide if
the msgb should be freed or not.

Pick network failure in case the msgb could not be
cloned in the hope the MS will retry then.
2015-05-25 15:39:59 +08:00
Holger Hans Peter Freyther 7605bdc02c sgsn: Re-factor the activate PDP code for future changes
A real SGSN will dynamically resolve the APN name into the
GGSN IP Address. This means that after we have collected all
information we need to start to resolve the GGSN and then
can continue.
2015-05-25 14:38:02 +08:00
Holger Hans Peter Freyther 08bb84b04e sgsn: Deal with no static ggsn being configured at all
In case no static ggsn is configured the code would crash
with the assumption that there is always such a GGSN.
2015-05-25 14:38:01 +08:00
Holger Hans Peter Freyther 9270d99f3d sgsn: If there is a subscr don't allow an empty list
This is a left-over from the initial system where no PDP
was provided by the system. For now if there is a subscr
attached and no PDP context provisioned. He is not allowed
to have a data connection.

Update the testcase to create the pdp list entry more
early with a wildcard and then change it to a specific
match.
2015-05-25 14:38:01 +08:00
Holger Hans Peter Freyther 5e4b88cbb2 Merge branch 'zecke/features/sgsn-hlr-number'
Store the hlr-Number for purgeMS and CDR handling
2015-05-24 12:32:36 +08:00
Holger Hans Peter Freyther 8ee13e2937 sgsn: Extract the hlr Number into the mm context
Include the hlr-Number of the subscriber in the CDR. This is useful
for debugging and understanding which equipment was used during the
test. In contrast to the MSISDN the '+' is emitted as the number
must be in international format already.
2015-05-24 12:32:23 +08:00
Holger Hans Peter Freyther 10c0f56a0e gsup: Copy the hlr-Number and use it during purge
Copy the hlr-Number into the sgsn_data and use it during
the purgeMS. There is no unit test that looks at the data
we send so I manually verified this by looking at the output.
Below is the output of the test that purges the subscriber.

<000f> gprs_subscriber.c:170 SUBSCR(123456789012345) Sending GSUP, will send: 0c 01 08 21 43 65 87 09 21 43 f5 09 07 91 83 61 26 31 23 f3
2015-05-24 12:32:23 +08:00
Holger Hans Peter Freyther 0bb5674cde gsup: Decode/Encode the hlr-Number in the GSUP message
Implement it similar to the msisdn_enc/msisdn_enc_len and
extend the testcase to include it as well.
2015-05-24 12:32:23 +08:00
Holger Hans Peter Freyther e54a24d4e6 gsup: Add the HLR-Number as type and use it for UpdateLocation Res
The HLR-Number can be passed from the MAP Proxy to the SGSN and
can then be used for the CDR module or passed during the purgeMS
operation.
2015-05-24 12:32:22 +08:00
Holger Hans Peter Freyther 0f7a279a06 sgsn: Change the selection mode to verified
We have verified/selected the APN. Either based on the subscriber
data, a global APN match. But at least this SGSN has looked at
what the MS has asked for and then selected a matching GGSN.
2015-05-22 10:05:56 +08:00
Holger Hans Peter Freyther c1c6a28c8d sgsn: Reserved bits should be set to 1
Bits 3 to 8 are spare bits and should be set to 1 in etsi
specifications. Do that.
2015-05-22 10:05:49 +08:00
Max 4c6e667968 Replace ad-hoc function with generic one from libosmocore
Signed-off-by: Max <max.suraev@fairwaves.co>
2015-05-17 19:09:32 +02:00
Holger Hans Peter Freyther 072bee5c85 sgsn: Clear LAC/RAC value for the routing area identity
Clear LAC/RAC with pre-defined value in the RAI.

3GPP 29.060 v7.17.0 section 7.3.1 page 23:

"The SGSN may include the Routeing Area Identity (RAI) of the
SGSN where the MS is registered. The MCC and MNC components shall
be populated with the MCC and MNC, respectively, of the SGSN
where the MS is registered. The LAC and RAC components shall be
populated by the SGSN with the value of 'FFFE' and 'FF',
respectively.”
2015-05-17 17:36:23 +02:00
Holger Hans Peter Freyther 267fd0c7f7 Merge branch 'zecke/features/sgsn-gtp-cdr'
Extend GTP and CDR support in the SGSN.
2015-05-17 17:24:09 +02:00
Holger Hans Peter Freyther d6900dfba4 sgsn: Give the IMEI to the GGSN for analysis
Most SGSNs pass the IMEI(SV). We currently only enquire about
the IMEI and then pad the 'SV' with 1111b (thanks to the encoding
routine). Sadly it insists on always writing the length which
means we have to memmove the data around by a single octet.

Manually verified using the pcu-emu and looking at the trace
using wireshark.
2015-05-17 17:23:57 +02:00
Holger Hans Peter Freyther 6ddb6ac028 sgsn: Encode the ULI for the PDP context creation ack
Give the GGSN another opportunity to determine which tarif
to apply for the SGSN/subscriber. This code assumes tha the
RAN is a GERAN system but the assumption has been made in
other places as well.
2015-05-17 17:23:57 +02:00
Holger Hans Peter Freyther 22093ef964 sgsn: Always include the routing area identity
For PDP context creation we always want to include the RAI
for the current mmctx. This might help commercial GGSNs to
determine which charging to apply.
2015-05-17 17:23:57 +02:00
Holger Hans Peter Freyther 77ff1c40e2 cdr: Remember the charging id supplied by the GGSN
The charging_id is provided by the GGSN. Copy it into the CDR
part of the data structure so it will remain present until after
the pdp context has been deleted.
2015-05-17 17:23:57 +02:00
Holger Hans Peter Freyther 446f8403d1 debian: Fix dependencies pointed out by lintian
E: openbsc source: missing-separator-between-items in osmocom-nitb depends field between '${misc:Depends}' and 'libdbd-sqlite3'
2015-05-17 17:23:36 +02:00
Holger Hans Peter Freyther 7882d2751f Merge branch 'zecke/features/cdr'
Add an optional CDR module. This will create a rotatable log
file, detect rotation and try to write as many information as
possible.
2015-05-12 20:06:47 +02:00
Holger Hans Peter Freyther c15c61c401 sgsn: Add VTY configuration for the CDR module
Make it possible to set a filename to use for the CDR. By
default no CDR will be generated. Forbid to set the interval
of 0 seconds as this will cause a lot of work. Add a very
basic VTY test.
2015-05-06 17:46:08 +02:00
Holger Hans Peter Freyther 4f5b8237ec sgsn: Create an initial and limited CDR module
This is consuming the new signals and allows to install several
different CDR/observing/event/audit modules in the future. For
getting the bytes in/out the code would have had to undo what the
rate counter is doing and at the same time adding a "total" to
the ratecounter didn't look like a good idea, the same went for
making it a plain counter.

Begin writing the values one by one and open/closing a new FILE
for every log messages. This is not efficient but easily deals
with external truncation/rotation of the file (no fstat for and
checking the links and size). As usual we will wait and see if
this is an issue.

Add some new members to our PDP context structure to see what it
is about.
2015-05-06 17:43:15 +02:00
Holger Hans Peter Freyther b100895557 sgsn: Add various signals consumed by CDR or other client code 2015-05-06 17:14:51 +02:00