Skip to content

Commit

Permalink
Merge pull request #56 from revtel/feat/ntag-sig-check
Browse files Browse the repository at this point in the history
feat: ntag 2xx signature verify
  • Loading branch information
whitedogg13 authored Apr 29, 2023
2 parents f4e0997 + 3a33371 commit 5073fa4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/NfcProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,29 @@ class NfcProxy {

return result;
});

readNxpSigNtag2xx = withAndroidPrompt(async () => {
let tag = null;

try {
await NfcManager.requestTechnology([NfcTech.NfcA]);

tag = await NfcManager.getTag();
tag.ndefStatus = await NfcManager.ndefHandler.getNdefStatus();
tag.nxpBytes = await NfcManager.nfcAHandler.transceive([0x3c, 0x00]);

if (Platform.OS === 'ios') {
await NfcManager.setAlertMessageIOS('Success');
}
} catch (ex) {
// for tag reading, we don't actually need to show any error
console.log(ex);
} finally {
NfcManager.cancelTechnologyRequest();
}

return tag;
});
}

// ------------------------
Expand Down
48 changes: 46 additions & 2 deletions src/Screens/TagKit/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as React from 'react';
import {ScrollView} from 'react-native';
import {ScrollView, Alert} from 'react-native';
import {List} from 'react-native-paper';
import * as NfcIcons from '../../Components/NfcIcons';
import * as Ntag424 from '../../data/ntag-424';
import * as Ntag213 from '../../data/ntag-213';
import * as Ntag215 from '../../data/ntag-215';
import * as Sic43NT from '../../data/sic-43nt';
import NfcProxy from '../../NfcProxy';

function TagKitScreen(props) {
const {navigation} = props;
Expand Down Expand Up @@ -78,7 +79,7 @@ function TagKitScreen(props) {
/>
<List.Item
title="Verify signature"
description="Verify signature"
description="Check if your tag is signed by NXP"
left={NfcIcons.TransceiveIcon}
onPress={() => {
navigation.navigate('CustomTransceive', {
Expand All @@ -89,6 +90,49 @@ function TagKitScreen(props) {
}}
/>

<List.Subheader>NXP NTAG 2XX</List.Subheader>
<List.Item
title="Verify signature"
description="Check if your tag is signed by NXP"
left={NfcIcons.TransceiveIcon}
onPress={async () => {
async function checkNxpSig({uid, sig}) {
const resp = await fetch(
`https://badge-api.revtel2.com/badge/v2/nxp-sig-check?uid=${uid}&sig=${sig}`,
);

if (resp.status !== 200) {
throw {
status: resp.status,
error: await resp.json(),
};
}

return resp.json();
}

const tag = await NfcProxy.readNxpSigNtag2xx();
const uid = tag.id;
const sig = tag.nxpBytes.reduce((acc, byte) => {
// eslint-disable-next-line no-bitwise
return acc + ('0' + (byte & 0xff).toString(16)).slice(-2);
}, '');

if (!sig) {
Alert.alert('Fail to obtain NXP Signature');
return;
}

try {
await checkNxpSig({uid, sig});
Alert.alert('Success', 'NXP signature is correct');
} catch (ex) {
Alert.alert('Failure', 'NXP signature is invalid');
console.warn(ex);
}
}}
/>

<List.Subheader>NXP NTAG 213</List.Subheader>
<List.Item
title="Enable password"
Expand Down

0 comments on commit 5073fa4

Please sign in to comment.