Commit Graph

26 Commits

Author SHA1 Message Date
Sukchan Lee 7c14073533 [UDM] Added validation for pubkey
a cryptographic vulnerability in the SUCI decryption routines
of Open5GS 5G—specifically Profile B, which uses P-256 (secp256r1)
for its elliptic curve routines.

If a mobile device user passes a public key within its SUCI
that does not correspond to a valid point on the P-256 elliptic curve,
the Open5GS UDM will not check the point
before running elliptic curve operations with it and returning a response
to the mobile device user.

If the public key is not checked to be a valid point, an attacker can leverage
this behavior to extract the Profile B private key from the UDM,
as has been done in other domains
(https://owasp.org/www-pdf-archive/Practical_Invalid_Curve_Attacks_on_TLS-ECDH_-_Juraj_Somorovsky.pdf).

Note that Profile A is not similarly vulnerable to this, as it is impossible
to construct an invalid point on a curve25519 elliptic curve.

There was some work that went into developing a practical proof of concept
of this kind of attack against free5gc last year; it can be found here:

https://www.gsma.com/security/wp-content/uploads/2023/10/0073-invalid_curve.pdf

And here is the free5gc security advisory:

https://github.com/advisories/GHSA-cqvv-r3g3-26rf

To mitigate this issue in Open5GS, the public key of the UE must be validated
by the UDM prior to use. Adding a validation function such as the following
should work:

I designed this code based on information from https://crypto.stackexchange.com/questions/90151/verify-that-a-point-belongs-to-secp256r1.
2024-03-24 14:09:10 +09:00
Sukchan Lee d1d3ec6fcb [SEC] Several vulnerabilities have been resolved.
1. Reachable assertion in ogs_nas_5gmm_decode

Location: lib/nas/5gs/decoder.c:4445

```c
int ogs_nas_5gmm_decode(ogs_nas_5gs_message_t *message, ogs_pkbuf_t *pkbuf)
{
    int size = 0;
    int decoded = 0;

    ogs_assert(pkbuf);
    ogs_assert(pkbuf->data);
    ogs_assert(pkbuf->len);
```

When a NAS payload is received over `src/amf/context.c:1675`NGAP that has no data, the ogs_assert(pkbuf->len) assertion will be triggered.

2.Reachable assertion in ogs_nas_emm_decode

```
int ogs_nas_emm_decode(ogs_nas_eps_message_t *message, ogs_pkbuf_t *pkbuf)
{
    int size = 0;
    int decoded = 0;

    ogs_assert(pkbuf);
    ogs_assert(pkbuf->data);
    ogs_assert(pkbuf->len);
```

Nearly identical to (1), but for LTE.

3. Reachable assertion in nas_eps_send_emm_to_esm

```
int nas_eps_send_emm_to_esm(mme_ue_t *mme_ue,
        ogs_nas_esm_message_container_t *esm_message_container)
{
    int rv;
    ogs_pkbuf_t *esmbuf = NULL;

    if (!mme_ue_cycle(mme_ue)) {
        ogs_error("UE(mme-ue) context has already been removed");
        return OGS_NOTFOUND;
    }

    ogs_assert(esm_message_container);
    ogs_assert(esm_message_container->length);
```

The ESM message payload may be 0-length, as the length is determined by a field in the NAS payload (which can be chosen arbitrarily by an attacker). This leads to the length assertion above being triggered.

5. Reachable assertion and incorrect hash calculation in ogs_kdf_hash_mme

```
void ogs_kdf_hash_mme(const uint8_t *message, uint8_t message_len, uint8_t *hash_mme)
{
    uint8_t key[32];
    uint8_t output[OGS_SHA256_DIGEST_SIZE];

    ogs_assert(message);
    ogs_assert(message_len);
    ogs_assert(hash_mme);

    memset(key, 0, 32);
    ogs_hmac_sha256(key, 32, message, message_len,
            output, OGS_SHA256_DIGEST_SIZE);

    memcpy(hash_mme, output+24, OGS_HASH_MME_LEN);
}
```

When handling NAS attach requests or TAU requests, the ogs_kdf_hash_mme function is passed the NAS payload. However, the length field is represented as an unsigned 8-bit integer, which the passed length of the packet may overflow. This leads to the passed value being truncated.

When the passed value is a multiple of 256, the above assertion (ogs_assert(message_len)) is triggered. Otherwise, the hash is computed on only the first n bits of the message (where n = actual_message_len % 256).
2024-02-03 10:41:12 +09:00
Pau Espin afa2c2c9e0 [CRYPT] Add ogs_kdf_kasme_idle_mobility()
This function is needed by a follow-up patch implementing initial
support for GERAN->EUTRAN idle mobility.
2024-01-16 06:36:44 +09:00
Pau Espin 3d693da73e [MME] Gn: Introduce initial support for 4G->2G cell reselection
In an Inter-RAT setup a UE could perform a RAU coming from a 4G network.
In that case the UE/MS is unknown to the SGSN and it should request the
SGSN context (MM, PDP) from the MME. This is done through the following
GTPv1C message exchange on the Gn interface of SGSN and MME:
SGSN -> MME: SGSN Context Request
SGSN <- MME: SGSN Context Response
SGSN -> MME: SGSN Context Acknowledge

This commit doesn't aim to be a complete implementation of the mentioned
procedure, since it's quite a complex one, with lots of fields and logic
required. This so far only implements in general the minimally
successful case by filling as much as possible the required set of
fields.
This will allow for a base onto which do incremental improvements and
fixes while testing against UEs and SGSNs (such as osmo-sgsn, which
doesn't yet support this procedure but will potentially earn it soon).

This commit doesn't implement the reverse direction, aka UE issuing cell
reselection 2G->4G. Initial support for this scenario will hopefully be
added soon as a follow-up patch, similar to this one.

Related: https://osmocom.org/issues/6294
2023-12-23 09:56:55 +09:00
Pau Espin 6a9c7f16c1 Revert "[MME] Gn: Introduce initial support for 4G->2G cell reselection"
This reverts commit 5a31af36e0.
2023-12-22 06:02:11 +09:00
Pau Espin 5a31af36e0 [MME] Gn: Introduce initial support for 4G->2G cell reselection
In an Inter-RAT setup a UE could perform a RAU coming from a 4G network.
In that case the UE/MS is unknown to the SGSN and it should request the
SGSN context (MM, PDP) from the MME. This is done through the following
GTPv1C message exchange on the Gn interface of SGSN and MME:
SGSN -> MME: SGSN Context Request
SGSN <- MME: SGSN Context Response
SGSN -> MME: SGSN Context Acknowledge

This commit doesn't aim to be a complete implementation of the mentioned
procedure, since it's quite a complex one, with lots of fields and logic
required. This so far only implements in general the minimally
successful case by filling as much as possible the required set of
fields.
This will allow for a base onto which do incremental improvements and
fixes while testing against UEs and SGSNs (such as osmo-sgsn, which
doesn't yet support this procedure but will potentially earn it soon).

This commit doesn't implement the reverse direction, aka UE issuing cell
reselection 2G->4G. Initial support for this scenario will hopefully be
added soon as a follow-up patch, similar to this one.

Related: https://osmocom.org/issues/6294
2023-12-21 22:11:49 +09:00
Pau Espin 7728172a83 [CRYPT] Constify several input parameters
This allows easily spotting input vs output parameters, as well as
make it easier for compiler to find out bugs and optimize code.
2023-12-20 20:04:23 +09:00
Sukchan Lee bfe8ae659e Fixed MacOSX compile error (Follow-up on #2581) 2023-09-14 07:04:27 +09:00
Sukchan Lee bd74c259ec [AMF/MME] Fix crash during snow-3g encrypt (#2581)
There was a memory problem in the encryption using snow_3g_f8,
so AMF/MME crashed.

To solve this problem, we used the snow-3g encryption library
created as below.

https://github.com/rcatolino/libressl-snow3g

However, it seems that this library cannot be used to create
integrity hash like snow_3g_f8.

So, we decided to keep both snow-3g libraries for the time being.

1. lib/crypt/snow3g* : for INTEGRITY (NIA1, EIA1)
2. lib/crypt/openssl/snow3g* : for ENCRYPTION (NEA1, EEA1)
2023-09-13 23:22:46 +09:00
Bostjan Meglic 5f9b941d25 Remove not valid UTF-8 characters
These UTF-8 characters are causing issues with static code analysis
tools.

Error: encoding error in ./lib/crypt/zuc.c
'utf-8' codec can't decode byte 0x97 in position 3948: invalid start byte
Python3 requires input character data to be perfectly encoded;
it also requires perfectly correct system encoding settings.
Unfortunately, your data and/or system settings are not.
2023-01-31 00:22:16 +09:00
Sukchan Lee 79d46be086 Introduced Subscription identifier de-concealing
o Generate the private key as below.
   $ openssl genpkey -algorithm X25519 -out /etc/open5gs/hnet/curve25519-1.key
   $ openssl ecparam -name prime256v1 -genkey -conv_form compressed -out /etc/open5gs/hnet/secp256r1-2.key

 o The private and public keys can be viewed with the command.
   The public key is used when creating the SIM.
   $ openssl pkey -in /etc/open5gs/hnet/curve25519-1.key -text
   $ openssl ec -in /etc/open5gs/hnet/secp256r1-2.key -conv_form compressed -text

In ausf/udm.yaml

 hnet:
    o Home network public key identifier(PKI) value : 1
      Protection scheme identifier : ECIES scheme profile A
    - id: 1
      scheme: 1
      key: /etc/open5gs/hnet/curve25519-1.key

    o Home network public key identifier(PKI) value : 2
      Protection scheme identifier : ECIES scheme profile B
    - id: 2
      scheme: 2
      key: /etc/open5gs/hnet/secp256r1-2.key

    o Home network public key identifier(PKI) value : 3
      Protection scheme identifier : ECIES scheme profile A
    - id: 3
      scheme: 1
      key: /etc/open5gs/hnet/curve25519-1.key

    o Home network public key identifier(PKI) value : 4
      Protection scheme identifier : ECIES scheme profile B
    - id: 4
      scheme: 2
      key: /etc/open5gs/hnet/secp256r1-2.key

Related to #1779
2022-12-24 20:22:45 +09:00
Sukchan Lee 9b10d70c77 [NRF] Fixed library load error 2022-08-26 10:57:11 +09:00
Sukchan Lee e6a14cb73d Move src/../nf-sm.[ch] to lib/sbi/nf-sm.[ch] 2022-08-12 14:03:53 +09:00
Bostjan Meglic ab11220dcc [ALL] Fix differences in function parameter names between definition and declaration 2022-07-01 21:38:47 +09:00
Sukchan Lee b988e7edce Use talloc for all memory pool (#1263) 2022-01-04 08:29:18 +09:00
Sukchan Lee 1354947164 Improve Milenage library for [R1-R5] (#1153) 2021-09-01 19:38:36 +09:00
Sukchan Lee 118d62d42d Add more memory log 2021-06-06 22:35:46 +09:00
Sukchan Lee d7c188dc00 License update 2020-11-12 20:58:08 -05:00
Sukchan Lee 3cbec5f2e6 License update 2020-10-26 22:43:47 -04:00
Sukchan Lee 8e048be082 Release v2.0.0 2020-08-21 23:33:45 -04:00
Sukchan Lee 3b0db8c384 Fix the bug for Release-16 2020-07-03 01:03:13 -04:00
Sukchan Lee 3c6711c9c8 If HSS/UDR gets MSISDN, AMF/MME -> SMF/SGW [#464] 2020-06-29 22:12:24 -04:00
Sukchan Lee b35c2277be simple 5GC registration is done 2020-06-21 23:10:54 -04:00
Sukchan Lee dbee687a75 Add only one 5GC scenario (call-flow) 2020-06-17 01:22:28 -04:00
Sukchan Lee 72370ff0b2 Add AUSF, UDM, and UDR 2020-06-04 14:12:05 -04:00
Sukchan Lee 142763c280 Rename Project to Open5GS
- Change BuildTool to Meson
 - Many BUGS Fixed
2019-10-27 17:41:14 +09:00