AUC: use osmo_hexparse() when reading key material from db
The database stores the key material as hex-ascii, we thus need to go
through osmo_hexparse() when reading. We could also store the material
as BLOB in the database. That would however complicate matters, as it
would basically mean using the sqlite3 command to manually
inspect/modify data from the console would no longer be easily possible.
Using this commit I have 2G authentication working against osmo-sgsn
with GSUP and 'auth policy remote'.
diff --git a/src/db_auc.c b/src/db_auc.c
index 439018e..9196922 100644
--- a/src/db_auc.c
+++ b/src/db_auc.c
@@ -125,7 +125,7 @@
goto end_2g;
}
#endif
- memcpy(&aud2g->u.gsm.ki, ki, sizeof(aud2g->u.gsm.ki));
+ osmo_hexparse(ki, &aud2g->u.gsm.ki, sizeof(aud2g->u.gsm.ki));
aud2g->type = OSMO_AUTH_TYPE_GSM;
} else
LOGAUC(imsi, LOGL_DEBUG, "No 2G Auth Data\n");
@@ -140,7 +140,7 @@
LOGAUC(imsi, LOGL_ERROR, "Error reading K: %d\n", rc);
goto out;
}
- memcpy(&aud3g->u.umts.k, k, sizeof(aud3g->u.umts.k));
+ osmo_hexparse(k, &aud3g->u.umts.k, sizeof(aud3g->u.umts.k));
/* UMTS Subscribers can have either OP or OPC */
op = sqlite3_column_text(stmt, 5);
if (!op) {
@@ -149,10 +149,12 @@
LOGAUC(imsi, LOGL_ERROR, "Error reading OPC: %d\n", rc);
goto out;
}
- memcpy(&aud3g->u.umts.opc, opc, sizeof(aud3g->u.umts.opc));
+ osmo_hexparse(opc, &aud3g->u.umts.opc,
+ sizeof(aud3g->u.umts.opc));
aud3g->u.umts.opc_is_op = 0;
} else {
- memcpy(&aud3g->u.umts.opc, op, sizeof(aud3g->u.umts.opc));
+ osmo_hexparse(op, &aud3g->u.umts.opc,
+ sizeof(aud3g->u.umts.opc));
aud3g->u.umts.opc_is_op = 1;
}
aud3g->u.umts.sqn = sqlite3_column_int64(stmt, 7);