Skip to content

fix(auth): correct OPc derivation per 3GPP#70

Open
abubakar508 wants to merge 1 commit intonutcas3:mainfrom
abubakar508:subscriber-x-auc-changes
Open

fix(auth): correct OPc derivation per 3GPP#70
abubakar508 wants to merge 1 commit intonutcas3:mainfrom
abubakar508:subscriber-x-auc-changes

Conversation

@abubakar508
Copy link
Copy Markdown

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.

  • 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.

  • 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).

  • 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

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

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
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.

1 participant