This commit is contained in:
Peter Rounce 2023-02-28 17:45:00 +00:00
parent 62c0db37d5
commit c5f70a2866
3 changed files with 9 additions and 19 deletions

View file

@ -248,7 +248,7 @@ func Get_cards_blank_uid() ([]Card, error) {
// query the database
sqlStatement := `select card_id, k2_cmac_key from cards where uid='' and last_counter_value=0;`
sqlStatement := `select card_id, k2_cmac_key from cards where uid='' and last_counter_value=0 and wiped='N';`
rows, err := db.Query(sqlStatement)

View file

@ -83,21 +83,6 @@ func Createboltcard(w http.ResponseWriter, r *http.Request) {
return
}
// check if card_name already exists
card_count, err := db.Get_card_name_count(card_name)
if err != nil {
log.Warn(err.Error())
return
}
if card_count > 0 {
msg := "createboltcard: the card name already exists in the database"
log.Warn(msg)
resp_err.Write_message(w, msg)
return
}
// log the request
log.WithFields(log.Fields{

View file

@ -85,13 +85,18 @@ func setup_card_record(uid string, ctr uint32, uid_bin []byte, ctr_bin []byte, c
// check card records for a matching cmac
for i, card := range cards {
for _, card := range cards {
// check the cmac
k2_cmac_key, err := hex.DecodeString(card.K2_cmac_key)
if err != nil {
return errors.New("card.k2_cmac_key decode failed")
log.WithFields(log.Fields{
"card.card_id": card.Card_id,
"card.k2_cmac_key": card.K2_cmac_key,
}).Warn("card.k2_cmac_key decode failed - remove the invalid record")
return err
}
cmac_valid, err := check_cmac(uid_bin, ctr_bin, k2_cmac_key, cmac)
@ -102,7 +107,6 @@ func setup_card_record(uid string, ctr uint32, uid_bin []byte, ctr_bin []byte, c
if cmac_valid == true {
log.WithFields(log.Fields{
"i": i,
"card.card_id": card.Card_id,
"card.k2_cmac_key": card.K2_cmac_key,
}).Info("cmac match found")
@ -189,6 +193,7 @@ func parse_request(req *http.Request) (int, error) {
}
if card_count == 0 {
log.Info("check CMACs and set UID")
setup_card_record(uid_str, ctr_int, uid, ctr, ba_c)
}