working
This commit is contained in:
parent
62c0db37d5
commit
c5f70a2866
3 changed files with 9 additions and 19 deletions
2
db/db.go
2
db/db.go
|
|
@ -248,7 +248,7 @@ func Get_cards_blank_uid() ([]Card, error) {
|
||||||
|
|
||||||
// query the database
|
// 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)
|
rows, err := db.Query(sqlStatement)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,21 +83,6 @@ func Createboltcard(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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 the request
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
|
|
|
||||||
|
|
@ -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
|
// check card records for a matching cmac
|
||||||
|
|
||||||
for i, card := range cards {
|
for _, card := range cards {
|
||||||
|
|
||||||
// check the cmac
|
// check the cmac
|
||||||
|
|
||||||
k2_cmac_key, err := hex.DecodeString(card.K2_cmac_key)
|
k2_cmac_key, err := hex.DecodeString(card.K2_cmac_key)
|
||||||
|
|
||||||
if err != nil {
|
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)
|
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 {
|
if cmac_valid == true {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"i": i,
|
|
||||||
"card.card_id": card.Card_id,
|
"card.card_id": card.Card_id,
|
||||||
"card.k2_cmac_key": card.K2_cmac_key,
|
"card.k2_cmac_key": card.K2_cmac_key,
|
||||||
}).Info("cmac match found")
|
}).Info("cmac match found")
|
||||||
|
|
@ -189,6 +193,7 @@ func parse_request(req *http.Request) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if card_count == 0 {
|
if card_count == 0 {
|
||||||
|
log.Info("check CMACs and set UID")
|
||||||
setup_card_record(uid_str, ctr_int, uid, ctr, ba_c)
|
setup_card_record(uid_str, ctr_int, uid, ctr, ba_c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue