void rfid::onRead_clicked() { get_encrypt_key(); ui->stackedWidget->setCurrentWidget(ui->Read); qDebug()<<"Reading form Block 1"; if(tag.read_data_block(0,1,new_key_A)) qDebug()<<"Read, Block 1: SUCCESS"; else qDebug()<<"Read, Block 1: FAIL"; qDebug()<<"Reading form Block 2"; if(tag.read_data_block(0,2,new_key_A)) qDebug()<<"Read, Block 2: SUCCESS"; else qDebug()<<"Read, Block 2: FAIL"; qDebug()<<"Reading form Block 3"; if(tag.read_data_block(0,3,new_key_A)) qDebug()<<"Read, Block 3: SUCCESS"; else qDebug()<<"Read, Block 3: FAIL"; qDebug()<<"Reading form Block 4"; if(tag.read_data_block(0,4,new_key_A)) qDebug()<<"Read, Block 4: SUCCESS"; else qDebug()<<"Read, Block 4: FAIL"; qDebug()<<"Reading form Block 5"; if(tag.read_data_block(0,5,new_key_A)) qDebug()<<"Read, Block 5: SUCCESS"; else qDebug()<<"Read, Block 5: FAIL"; qDebug()<<"Reading form Block 6"; if(tag.read_data_block(0,6,new_key_A)) qDebug()<<"Read, Block 6: SUCCESS"; else qDebug()<<"Read, Block 6: FAIL"; }
static int store_master_key(char *upasswd, unsigned char *master_key) { AES_KEY key; DATA_BLOB blob; // prepare the blob if (strlen(MASTER_KEY_TAG) >= USER_KEY_LEN) return -1; strlcpy(blob.keyname, MASTER_KEY_TAG, USER_KEY_LEN); blob.value_size = USER_KEY_LEN; if (USER_KEY_LEN > MAX_KEY_VALUE_LENGTH) { LOGE("master_key length is too long."); return -1; } memcpy((void*)blob.value, (const void*)master_key, USER_KEY_LEN); // generate the encryption key get_encrypt_key(upasswd, &key); return encrypt_n_save(&key, &blob, MASTER_KEY); }
void rfid::onInit_clicked() { ///////////////////////////////////// /* defining the sector trailer for sector 0,1,2,3.... new_key_A(a function of the serial number),access_conditions(transport),new_key_B(useless)*/ //////////////////////////////////// get_encrypt_key(); qDebug()<<"new key A: "<<new_key_A; // 0xe9, 0x08, 0x86, 0xae, 0x06, 0x6a (for the blue tag) byte new_key_B[]={0xff,0xff,0xff,0xff,0xff,0xff}; byte data_write_sectorTrailer[16]; for(int i=0;i<6;i++) data_write_sectorTrailer[i]=new_key_A[i]; data_write_sectorTrailer[6]=0xff; data_write_sectorTrailer[7]=0x07; data_write_sectorTrailer[8]=0x80; data_write_sectorTrailer[9]=0x29; for(int i=10;i<16;i++) data_write_sectorTrailer[i]=new_key_B[i-10]; qDebug()<<data_write_sectorTrailer; ui->textEdit->setText("writing data...\n"); qDebug()<<"writing to sector trailer 0"; if(tag.write_data_block(0,3,default_key_A,data_write_sectorTrailer)) { qDebug()<<"Write, sector trailer 0: SUCCESS"; ui->textEdit->append("Write, sector trailer 0: SUCCESS\n"); } else { qDebug()<<"Write, sector trailer 0: FAIL"; ui->textEdit->append("Write, sector trailer 0: FAIL\n"); } qDebug()<<"writing to sector trailer 1"; if(tag.write_data_block(0,7,default_key_A,data_write_sectorTrailer)) { qDebug()<<"Write, sector trailer 1: SUCCESS"; ui->textEdit->append("Write, sector trailer 1: SUCCESS\n"); } else { qDebug()<<"Write, sector trailer 1: FAIL"; ui->textEdit->append("Write, sector trailer 1: FAIL\n"); } qDebug()<<"writing to sector trailer 2"; if(tag.write_data_block(0,11,default_key_A,data_write_sectorTrailer)) { qDebug()<<"Write, sector trailer 2: SUCCESS"; ui->textEdit->append("Write, sector trailer 2: SUCCESS\n"); } else { qDebug()<<"Write, sector trailer 2: FAIL"; ui->textEdit->append("Write, sector trailer 2: FAIL\n"); } qDebug()<<"writing to sector trailer 3"; if(tag.write_data_block(0,15,default_key_A,data_write_sectorTrailer)) { qDebug()<<"Write, sector trailer 3: SUCCESS"; ui->textEdit->append("Write, sector trailer 3: SUCCESS\n"); } else { qDebug()<<"Write, sector trailer 3: FAIL"; ui->textEdit->append("Write, sector trailer 3: FAIL\n"); } qDebug()<<"writing to sector trailer 4"; if(tag.write_data_block(0,19,default_key_A,data_write_sectorTrailer)) { qDebug()<<"Write, sector trailer 4: SUCCESS"; ui->textEdit->append("Write, sector trailer 4: SUCCESS\n"); } else { qDebug()<<"Write, sector trailer 4: FAIL"; ui->textEdit->append("Write, sector trailer 4: FAIL\n"); } ////////////////////////////////////// /*Storing Flags in block 1..... init_flag, install_flag, use_flag,0x00,0x02,0x09,Grey orange...*/ ///////////////////////////////////// qDebug()<<"writing to Block 1"; byte data_write_block1[]={true,false,false,0x00,0x02,0x09,'g','r','e','y','o','r','a','n','g','e'}; if(tag.write_data_block(0,1,new_key_A,data_write_block1)) { qDebug()<<"Write, Block 1: SUCCESS"; ui->textEdit->append("Write, Block 1: SUCCESS\n"); } else { qDebug()<<"Write, Block 1: FAIL"; ui->textEdit->append("Write, Block 1: FAIL\n"); } ///////////////////////////////////// /*Storing serial key in block 2*/ //////////////////////////////////// qDebug()<<"writing to block 2"; byte *data_write_block2=serialNumber; if(tag.write_data_block(0,2,new_key_A,data_write_block2)) { qDebug()<<"Write, Block 2: SUCCESS"; ui->textEdit->append("Write, Block 2: SUCCESS\n"); } else { qDebug()<<"Write, Block 2: FAIL"; ui->textEdit->append("Write, Block 2: FAIL\n"); } }