Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfehr committed Aug 28, 2024
1 parent 67f2c7f commit f343957
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 3 deletions.
22 changes: 22 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class MIFARE_Ultralight_C {

public static final byte[] defaultAuthKey = hexStringToByteArray("49454D4B41455242214E4143554F5946"); // "IEMKAERB!NACUOYF" => "BREAKMEIFYOUCAN!", 16 bytes long
public static final byte[] customAuthKey = "1234567890123456".getBytes(StandardCharsets.UTF_8);

/**
* auth code taken from https://stackoverflow.com/a/44640515/8166854
* Note: this is a modified code without Apache Commons Lang.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.androidcrypto.mifare_ultralight_c_examples;

import static de.androidcrypto.mifare_ultralight_c_examples.MIFARE_Ultralight_C.authenticateUltralightC;
import static de.androidcrypto.mifare_ultralight_c_examples.MIFARE_Ultralight_C.convertPassword;
import static de.androidcrypto.mifare_ultralight_c_examples.MIFARE_Ultralight_C.customAuthKey;
import static de.androidcrypto.mifare_ultralight_c_examples.MIFARE_Ultralight_C.defaultAuthKey;
import static de.androidcrypto.mifare_ultralight_c_examples.MIFARE_Ultralight_C.getCounterValue;
Expand Down Expand Up @@ -256,6 +257,7 @@ public void onTagDiscovered(Tag tag) {
writeToUiAppend("authenticateUltralightC with defaultAuthKey success: " + authSuccess);
} else {
writeToUiAppend("Authentication with Custom Key requested");
//authSuccess = authenticateUltralightC(nfcA, convertPassword(customAuthKey));
authSuccess = authenticateUltralightC(nfcA, customAuthKey);
writeToUiAppend("authenticateUltralightC with customAuthKey success: " + authSuccess);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import static de.androidcrypto.mifare_ultralight_c_examples.MIFARE_Ultralight_C.authenticateUltralightC;
import static de.androidcrypto.mifare_ultralight_c_examples.MIFARE_Ultralight_C.customAuthKey;
import static de.androidcrypto.mifare_ultralight_c_examples.MIFARE_Ultralight_C.defaultAuthKey;
import static de.androidcrypto.mifare_ultralight_c_examples.MIFARE_Ultralight_C.doAuthenticateUltralightCDefault;
import static de.androidcrypto.mifare_ultralight_c_examples.MIFARE_Ultralight_C.writeAuth0UltralightC;
import static de.androidcrypto.mifare_ultralight_c_examples.MIFARE_Ultralight_C.writeAuth1UltralightC;
import static de.androidcrypto.mifare_ultralight_c_examples.MIFARE_Ultralight_C.writePasswordUltralightC;
import static de.androidcrypto.mifare_ultralight_c_examples.Utils.bytesToHexNpe;
import static de.androidcrypto.mifare_ultralight_c_examples.Utils.doVibrate;
import static de.androidcrypto.mifare_ultralight_c_examples.Utils.hexStringToByteArray;
Expand Down Expand Up @@ -74,6 +76,7 @@ public static WriteConfigurationFragment newInstance(String param1, String param
private TextView readResult;
private RadioButton rbNoAuth, rbDefaultAuth, rbCustomAuth;
private RadioButton rbMemoryWriteProtection, rbMemoryWriteReadProtection;
private RadioButton rbChangePasswordNone, rbChangePasswordDefault, rbChangePasswordCustom;
private AutoCompleteTextView authenticationRequiredPage;
private View loadingLayout;
private String outputString = ""; // used for the UI output
Expand All @@ -85,10 +88,10 @@ public static WriteConfigurationFragment newInstance(String param1, String param
String tagIdString = "";
String tagTypeString = "";
private static final int REQUEST_PERMISSION_WRITE_EXTERNAL_STORAGE = 100;
Context contextSave;
private Context contextSave;
private byte[][] pagesComplete;
private int pagesToRead;
byte[] versionData;
private byte[] versionData;
private boolean isUltralightC = false;
private boolean isUltralightEv1 = false;
private int counter0 = 0;
Expand All @@ -112,6 +115,9 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
rbCustomAuth = getView().findViewById(R.id.rbCustomAuth);
rbMemoryWriteProtection = getView().findViewById(R.id.rbMemoryWriteProtection);
rbMemoryWriteReadProtection = getView().findViewById(R.id.rbMemoryWriteReadProtection);
rbChangePasswordNone = getView().findViewById(R.id.rbChangePasswordNone);
rbChangePasswordDefault = getView().findViewById(R.id.rbChangePasswordDefault);
rbChangePasswordCustom = getView().findViewById(R.id.rbChangePasswordCustom);
loadingLayout = getView().findViewById(R.id.loading_layout);

// The minimum number of pages to write is 12 (= 48 bytes user memory)
Expand Down Expand Up @@ -235,7 +241,19 @@ public void onTagDiscovered(Tag tag) {
success = writeAuth1UltralightC(nfcA, defineWriteOnlyRestricted);
writeToUiAppend("Status of writeAuth1 command to WriteRestrictedOnly: " + success);


// change password - options are no change, change to default or change to custom
if (rbChangePasswordNone.isChecked()) {
// no password change
writeToUiAppend("No password change requested");
} else if (rbChangePasswordDefault.isChecked()) {
// change password to default
success = writePasswordUltralightC(nfcA, defaultAuthKey);
writeToUiAppend("Change the password to DEFAULT password: " + success);
} else {
// change password to custom
success = writePasswordUltralightC(nfcA, customAuthKey);
writeToUiAppend("Change the password to CUSTOM password: " + success);
}
}
} catch (Exception e) {
writeToUiAppend("Exception on connection: " + e.getMessage());
Expand Down
71 changes: 71 additions & 0 deletions app/src/main/res/layout/fragment_write_configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@

</RadioGroup>

<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:dividerInsetEnd="16dp"
app:dividerInsetStart="16dp"
app:dividerThickness="4dp" />

<TextView
android:id="@+id/tvInformationPage"
android:layout_width="match_parent"
Expand Down Expand Up @@ -139,6 +148,68 @@

</RadioGroup>

<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:dividerInsetEnd="16dp"
app:dividerInsetStart="16dp"
app:dividerThickness="4dp" />

<TextView
android:id="@+id/tvInformationChangePassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingEnd="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/description_change_password"
android:textAlignment="center"
android:textSize="16sp"
android:textStyle="bold" />

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:orientation="horizontal">

<RadioButton
android:id="@+id/rbChangePasswordNone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="No Change" />

<RadioButton
android:id="@+id/rbChangePasswordDefault"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Default" />

<RadioButton
android:id="@+id/rbChangePasswordCustom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Custom" />

</RadioGroup>

<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:dividerInsetEnd="16dp"
app:dividerInsetStart="16dp"
app:dividerThickness="4dp" />

<LinearLayout
android:id="@+id/loading_layout"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
<string name="description_write_page">Memory Protection: Select the page from where an authentication is required for writing or reading. Using \'48\' disables memory protection.</string>
<string name="description_memory_protection"><![CDATA[Select if the memory protection is for write access only or write & read access]]></string>
<string name="description_write_configuration">This example expects a MIFARE Ultralight C type tag. It writes a new memory protection configuration to the tag.\n\nWhen a tag is discovered the new data will be written without any confirmation.</string>
<string name="description_change_password">Change the password of the tag, select the Default or a Custom password</string>
</resources>

0 comments on commit f343957

Please sign in to comment.