fix(auth): correct OPc derivation per 3GPP#70
Open
abubakar508 wants to merge 1 commit intonutcas3:mainfrom
Open
fix(auth): correct OPc derivation per 3GPP#70abubakar508 wants to merge 1 commit intonutcas3:mainfrom
abubakar508 wants to merge 1 commit intonutcas3:mainfrom
Conversation
OPc must be computed as AES-128(K, OP) XOR OP, not just AES-128(K, OP).
The missing XOR step produced incorrect OPc values incompatible with any
standard Milenage implementation.
- Add XOR of encrypted block with OP in generateOPc()
- Add Milenage f1–f5 helper functions (runMilenage, xorBytes,
rotateLeft)
feat(subscriber): add SQN field for 3GPP AKA replay protection
Sequence number (SQN) is required by the Milenage AKA protocol to
prevent replay attacks. It is incremented atomically on each auth
vector generation.
feat(handlers): expose AuC auth-vector endpoint
Adds POST /api/v1/auc/:imsi/auth-vector for HSS/MME to request
authentication vectors during subscriber attach procedures.
- AuCHandler struct with SubscriberService dependency
- Returns { rand, xres, ck, ik, autn } as hex strings
- Returns 404 if IMSI not found, 500 on crypto/DB failure
- Register route in router
feat(auc): implement Authentication Center with Milenage AKA
Adds GenerateAuthVector() which produces a full 3GPP AKA authentication
vector (RAND, XRES, CK, IK, AUTN) for a given IMSI using the Milenage
algorithm (3GPP TS 35.205/206).
- Load subscriber K and OPc from DB by IMSI
- Atomically increment SQN via UPDATE … RETURNING (no race condition)
- Generate 16-byte RAND via crypto/rand
- Run Milenage f1–f5 to derive XRES, CK, IK, AK, MAC-A
- Construct AUTN = (SQN XOR AK) || AMF || MAC-A
Files changed:
M apps/api-server/internal/services/subscriber_auth.go
A apps/api-server/internal/services/subscriber_auc.go
A apps/api-server/internal/handlers/auc_handler.go
M apps/api-server/internal/models/subscriber.go
A migrations/00019_add_subscriber_sqn.sql
add: new migration for teh sequencing number attached to the
Authentication Center (AuC)
- Add SQN int64 field to models.Subscriber (gorm:"default:0")
- Add migration 00019_add_subscriber_sqn.sql:
ALTER TABLE subscribers ADD COLUMN sqn BIGINT NOT NULL DEFAULT 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(auth): correct OPc derivation per 3GPP
OPc must be computed as AES-128(K, OP) XOR OP, not just AES-128(K, OP).
The missing XOR step produced incorrect OPc values incompatible with any
standard Milenage implementation.
feat(subscriber): add SQN field for 3GPP AKA replay protection
Sequence number (SQN) is required by the Milenage AKA protocol to
prevent replay attacks. It is incremented atomically on each auth
vector generation.
Add SQN int64 field to models.Subscriber (gorm:"default:0")
Add migration 00019_add_subscriber_sqn.sql:
ALTER TABLE subscribers ADD COLUMN sqn BIGINT NOT NULL DEFAULT 0
feat(auc): implement Authentication Center with Milenage AKA
Adds GenerateAuthVector() which produces a full 3GPP AKA authentication
vector (RAND, XRES, CK, IK, AUTN) for a given IMSI using the Milenage
algorithm (3GPP TS 35.205/206).
feat(handlers): expose AuC auth-vector endpoint
Adds POST /api/v1/auc/:imsi/auth-vector for HSS/MME to request
authentication vectors during subscriber attach procedures.