diff --git a/db/db.go b/db/db.go index fefec5a..fb5e8ca 100644 --- a/db/db.go +++ b/db/db.go @@ -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) diff --git a/internalapi/createboltcard.go b/internalapi/createboltcard.go index 45389a5..ec4834a 100644 --- a/internalapi/createboltcard.go +++ b/internalapi/createboltcard.go @@ -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{ diff --git a/lnurlw/lnurlw_request.go b/lnurlw/lnurlw_request.go index c3a25e2..fe1a93d 100644 --- a/lnurlw/lnurlw_request.go +++ b/lnurlw/lnurlw_request.go @@ -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) }