commit to push, too long so forget
This commit is contained in:
parent
ce7a132ae2
commit
68cbe56e9d
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
<bytecodeTargetLevel target="17" />
|
||||
</component>
|
||||
</project>
|
@ -7,6 +7,7 @@
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="Embedded JDK" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
6
.idea/kotlinc.xml
Normal file
6
.idea/kotlinc.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.8.0" />
|
||||
</component>
|
||||
</project>
|
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
@ -19,6 +19,9 @@
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
|
||||
android:resource="@xml/tech_list" />
|
||||
</activity>
|
||||
</application>
|
||||
<uses-permission android:name="android.permission.NFC" />
|
||||
|
@ -794,6 +794,8 @@ void Connector::activeAuthentication(bytes m2) {
|
||||
|
||||
// 256 is hardcoded
|
||||
// MRTD returns signature of size [sigLength] or of arbitrarily size if [sigLength] is 256.
|
||||
|
||||
logBytes("Internal auth with %s", m2);
|
||||
auto response = internalAuthenticate(m2, 256);
|
||||
auto message = response.data;
|
||||
|
||||
@ -833,6 +835,7 @@ void Connector::activeAuthentication(bytes m2) {
|
||||
break;
|
||||
default:
|
||||
hashlen = 0;
|
||||
LOGI("cannot detect hash type, wrong !!!!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -863,8 +866,34 @@ void Connector::activeAuthentication(bytes m2) {
|
||||
bytes check_hash(160 / 8);
|
||||
SHA1(m1_m2.data(), m1_m2.size(), check_hash.data());
|
||||
bool verified = std::equal(hash.begin(), hash.end(), check_hash.begin());
|
||||
verified &= hash.size() == check_hash.size();
|
||||
|
||||
logBytes("hash %s", hash);
|
||||
logBytes("check hash %s", check_hash);
|
||||
LOGI("active authentication verified %d", verified);
|
||||
}
|
||||
|
||||
void Connector::selectSAM() {
|
||||
bytes command;
|
||||
bytes response;
|
||||
|
||||
// 00A404000C4D4B4D4F43436C69656E7431
|
||||
// command = {0, 164, 4, 0, 12, 77, 75, 77, 79, 67, 67, 108, 105, 101, 110, 116, 49};
|
||||
// response = transceive(command);
|
||||
// command = {0x80, 0x50, 0, 0, 0x20};
|
||||
// response = transceive(command);
|
||||
//
|
||||
// bytes random = response;
|
||||
// logBytes("random %s", random);
|
||||
|
||||
// 00A404000CA000000063504B43532D3135
|
||||
command = {0, 164, 4, 0, 12, 160, 0, 0, 0, 99, 80, 75, 67, 83, 45, 49, 53};
|
||||
response = transceive(command);
|
||||
logBytes("SAM selected %s", response);
|
||||
|
||||
// get pubkey
|
||||
// 00F1000100
|
||||
command = {00, 0xf1, 00, 01, 00};
|
||||
response = transceive(command);
|
||||
logBytes("pubkey %s", response);
|
||||
}
|
@ -298,6 +298,8 @@ public:
|
||||
void readEFSOD();
|
||||
|
||||
void activeAuthentication(bytes challenge);
|
||||
|
||||
void selectSAM();
|
||||
};
|
||||
|
||||
#endif //CCCC_API_H
|
||||
|
@ -232,12 +232,16 @@ uint64_t iso9797_mac(bytes data, uint64_t key1, uint64_t key2, uint64_t key3, bo
|
||||
bytes msg = data;
|
||||
if (pad) iso9797_pad(msg);
|
||||
|
||||
logBytes("eifd padded %s", msg);
|
||||
bytes mac = des_encrypt(msg, key1);
|
||||
mac.erase(mac.begin(), mac.end() - 8);
|
||||
|
||||
uint64_t mac_value = bytes2num(mac);
|
||||
LOGI("mac1 %llx", mac_value);
|
||||
mac_value = des(mac_value, key2, 'd');
|
||||
LOGI("mac2 %llx", mac_value);
|
||||
mac_value = des(mac_value, key3, 'e');
|
||||
LOGI("mac3 %llx", mac_value);
|
||||
return mac_value;
|
||||
}
|
||||
|
||||
|
@ -22,22 +22,24 @@ Java_com_bshield_cccc_MainActivity_initNFCScan(
|
||||
|
||||
// TODO: move to connector class
|
||||
|
||||
connector->selectDf1();
|
||||
connector->initBAC();
|
||||
connector->selectSAM();
|
||||
|
||||
connector->readEFCOM();
|
||||
connector->readEFDG1();
|
||||
connector->readEFDG2();
|
||||
connector->readEFDG13();
|
||||
connector->readEFDG14();
|
||||
connector->readEFDG15();
|
||||
|
||||
connector->readEFSOD();
|
||||
|
||||
bytes challenge = randomBytes(8);
|
||||
connector->activeAuthentication(challenge);
|
||||
|
||||
connector->ready = true;
|
||||
// connector->selectDf1();
|
||||
// connector->initBAC();
|
||||
//
|
||||
// connector->readEFCOM();
|
||||
// connector->readEFDG1();
|
||||
// connector->readEFDG2();
|
||||
// connector->readEFDG13();
|
||||
// connector->readEFDG14();
|
||||
// connector->readEFDG15();
|
||||
//
|
||||
// connector->readEFSOD();
|
||||
//
|
||||
// bytes challenge = randomBytes(8);
|
||||
// connector->activeAuthentication(challenge);
|
||||
//
|
||||
// connector->ready = true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,11 @@ import android.nfc.NfcAdapter
|
||||
import android.nfc.NfcAdapter.ACTION_ADAPTER_STATE_CHANGED
|
||||
import android.nfc.NfcAdapter.getDefaultAdapter
|
||||
import android.nfc.tech.IsoDep
|
||||
import android.nfc.tech.NfcA
|
||||
import android.nfc.tech.TagTechnology
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@ -107,14 +109,16 @@ class MainActivity : AppCompatActivity() {
|
||||
super.onResume();
|
||||
|
||||
nfcAdapter.enableReaderMode(this, {tag ->
|
||||
Log.d("BRUH", tag.techList.joinToString())
|
||||
if (tag.techList.contains(IsoDep::class.java.name)) {
|
||||
// type = "iso7816"
|
||||
// standard = "ISO 14443-4 (Type B)"
|
||||
val isoDep = IsoDep.get(tag)
|
||||
(isoDep as IsoDep).timeout = 5000;
|
||||
tagTechnology = isoDep
|
||||
PerfomNFCScanning();
|
||||
}
|
||||
}, (0x1 or 0x2), null);
|
||||
}, (0x1 or 0x2 or 0x4 or 0x8 or 16 or 256), null);
|
||||
|
||||
// Example of a call to a native method
|
||||
// binding.sampleText.text = "nfc enabled? ${nfcAdapter.isEnabled()}"
|
||||
@ -145,19 +149,19 @@ class MainActivity : AppCompatActivity() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (binding.idnumber.text.length != 12) {
|
||||
setError("ID number must be 12 digits");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!::birthday.isInitialized) {
|
||||
setError("Birthday is not entered");
|
||||
}
|
||||
if (!::expirydate.isInitialized) {
|
||||
setError("Birthday is not entered");
|
||||
}
|
||||
|
||||
val id = binding.idnumber.text.substring(3);
|
||||
// if (binding.idnumber.text.length != 12) {
|
||||
// setError("ID number must be 12 digits");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (!::birthday.isInitialized) {
|
||||
// setError("Birthday is not entered");
|
||||
// }
|
||||
// if (!::expirydate.isInitialized) {
|
||||
// setError("Birthday is not entered");
|
||||
// }
|
||||
//
|
||||
// val id = binding.idnumber.text.substring(3);
|
||||
|
||||
fun checkdigit(digits: String): String {
|
||||
fun mapValue(x: Char): Int {
|
||||
@ -173,7 +177,8 @@ class MainActivity : AppCompatActivity() {
|
||||
return (hash % 10).toString();
|
||||
}
|
||||
|
||||
val passcode = id + checkdigit(id) + birthday + checkdigit(birthday) + expirydate + checkdigit(expirydate);
|
||||
// val passcode = id + checkdigit(id) + birthday + checkdigit(birthday) + expirydate + checkdigit(expirydate);
|
||||
val passcode = "098002079798112232311229";
|
||||
|
||||
try {
|
||||
setError("Scanning the identity card");
|
||||
|
21
app/src/main/res/xml/tech_list.xml
Normal file
21
app/src/main/res/xml/tech_list.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<!-- capture anything using NfcF -->
|
||||
<tech-list>
|
||||
<tech>android.nfc.tech.NfcF</tech>
|
||||
</tech-list>
|
||||
|
||||
<!-- OR -->
|
||||
|
||||
<!-- capture all MIFARE Classics with NDEF payloads -->
|
||||
<tech-list>
|
||||
<tech>android.nfc.tech.NfcA</tech>
|
||||
<tech>android.nfc.tech.NfcB</tech>
|
||||
<tech>android.nfc.tech.NfcF</tech>
|
||||
<tech>android.nfc.tech.NfcV</tech>
|
||||
<tech>android.nfc.tech.IsoDep</tech>
|
||||
<tech>android.nfc.tech.Ndef</tech>
|
||||
<tech>android.nfc.tech.NdefFormatable</tech>
|
||||
<tech>android.nfc.tech.MifareClassic</tech>
|
||||
<tech>android.nfc.tech.MifareUltralight</tech>
|
||||
</tech-list>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user