Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the security of SUCI to SUPI conversion #47

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

linouxis9
Copy link

@linouxis9 linouxis9 commented Feb 17, 2025

Hi!

This PR improves:

  • The security of SUCI parsing using regex
  • Use built-in function to compress/uncompress Profile-B keys instead of rolling out the crypto ourselves :-)
  • Use constant time equality
  • Add much needed returns on errors as well
  • Stop the usage of logf.Printf
  • Added some units tests about compressed and uncompressed Profile B Ephemeral and Home Keys (using test data from TS 33.501 C.4.4)
  • Use crypto/ecdh (introduced in Go 1.20) instead of rolling out crypto, and factor what's possible between Profile A and Profile B

This work is part of an going project I'm working on to considerably up the code quality and security of free5gc!
This work is sponsored by Free Mobile!

Hope you find it useful.

CC: @ianchen0119

Thanks and cheers,
Valentin

@linouxis9 linouxis9 changed the title Improve the security of SUCI parsing, and use built-in function to compress/uncompress Profile-B keys instead of rolling out the crypto ourselves Improve the security of SUCI to SUPI conversion Feb 17, 2025
@linouxis9
Copy link
Author

Will fix the checks, thanks!

@linouxis9 linouxis9 force-pushed the main branch 2 times, most recently from e5d2128 to a0b3133 Compare February 18, 2025 08:48
@linouxis9
Copy link
Author

For the following golangci-lint warnings:

Error: pkg/suci/suci.go:231:19: SA1019: elliptic.Marshal has been deprecated since Go 1.21: for ECDH, use the crypto/ecdh package. This function returns an encoding equivalent to that of PublicKey.Bytes in crypto/ecdh. (staticcheck)
  		pubKeyForECDH = elliptic.Marshal(elliptic.P256(), x, y)
  		                ^
Error: pkg/suci/suci.go:239:11: SA1019: elliptic.Unmarshal has been deprecated since Go 1.21: for ECDH, use the crypto/ecdh package. This function accepts an encoding equivalent to that of the NewPublicKey methods in crypto/ecdh. (staticcheck)
  		x, y := elliptic.Unmarshal(elliptic.P256(), transmittedPubKey)

Sadly, we don't have the choice to not use these deprecated functions. It's either we use these deprecated functions, or roll out our own functions, which should be avoided in crypto. This PR at least reduces the number of usage of deprecated unsafe functions such as elliptic.ScalarMult.

I had opened a Go issue about it yesterday: golang/go#71807

@linouxis9 linouxis9 changed the base branch from main to next February 27, 2025 16:25
@linouxis9
Copy link
Author

Hi!

As per new free5gc policy, I've rebased my code upon next branch.

Thanks and cheers,
Valentin

@ianchen0119
Copy link
Contributor

Hi @linouxis9

Thanks for your contribution.
I'm planning to release the v4.0.0 next week, So I'll review the PR after new version released.

@ianchen0119 ianchen0119 changed the base branch from next to main March 3, 2025 11:40
@ianchen0119 ianchen0119 self-requested a review March 3, 2025 11:40
@@ -393,24 +392,7 @@ func (p *Processor) GenerateAuthDataProcedure(
sqnStr = fmt.Sprintf("%x", bigSQN)
sqnStr = p.strictHex(sqnStr, 12)
} else {
logger.UeauLog.Errorln("Re-Sync MAC failed ", supiOrSuci)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @linouxis9

I have question about why this part is removed. I think this part can make log message be clear.

Copy link
Author

@linouxis9 linouxis9 Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Alonza0314!

I thought that if the SUCI was able to be resolved, it would be better to use it in the log.
If we had an invalid SUCI, it would already had been logged earlier.

But you are right, it's probably clearer for the log flow to show from which SUCI this SUPI is coming from if auth failed! I'll add it back alongside SUPI.

Thanks a ton,
Valentin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants