mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-14 00:53:12 +08:00
signatures v1 and v2
This commit is contained in:
parent
8dd19a00c5
commit
74243fcb03
1 changed files with 81 additions and 8 deletions
|
@ -160,14 +160,8 @@ static int ndefPrintHeader(NDEFHeader_t *header) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ndefDecodeSig(uint8_t *sig, size_t siglen) {
|
static int ndefDecodeSig1(uint8_t *sig, size_t siglen) {
|
||||||
size_t indx = 0;
|
size_t indx = 1;
|
||||||
PrintAndLogEx(NORMAL, "\tsignature version: 0x%02x", sig[0]);
|
|
||||||
if (sig[0] != 0x01 && sig[0] != 0x20) {
|
|
||||||
PrintAndLogEx(ERR, "signature version unknown.");
|
|
||||||
return PM3_ESOFT;
|
|
||||||
}
|
|
||||||
indx++;
|
|
||||||
|
|
||||||
uint8_t sigType = sig[indx] & 0x7f;
|
uint8_t sigType = sig[indx] & 0x7f;
|
||||||
bool sigURI = sig[indx] & 0x80;
|
bool sigURI = sig[indx] & 0x80;
|
||||||
|
@ -225,6 +219,85 @@ static int ndefDecodeSig(uint8_t *sig, size_t siglen) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// https://github.com/nfcpy/ndeflib/blob/master/src/ndef/signature.py#L292
|
||||||
|
static int ndefDecodeSig2(uint8_t *sig, size_t siglen) {
|
||||||
|
size_t indx = 1;
|
||||||
|
|
||||||
|
uint8_t sigType = sig[indx] & 0x7f;
|
||||||
|
bool sigURI = sig[indx] & 0x80;
|
||||||
|
indx++;
|
||||||
|
|
||||||
|
uint8_t hashType = sig[indx];
|
||||||
|
indx++;
|
||||||
|
|
||||||
|
PrintAndLogEx(NORMAL, "\tsignature type: %s", ((sigType < stNA) ? ndefSigType_s[sigType] : ndefSigType_s[stNA]));
|
||||||
|
PrintAndLogEx(NORMAL, "\tsignature uri: %s", (sigURI ? "present" : "not present"));
|
||||||
|
PrintAndLogEx(NORMAL, "\thash type: %s", ((hashType == 0x02) ? "SHA-256" : "unknown");
|
||||||
|
|
||||||
|
if (sigURI) {
|
||||||
|
size_t intsigurilen = (sig[indx] << 8) + sig[indx + 1];
|
||||||
|
indx += 2;
|
||||||
|
PrintAndLogEx(NORMAL, "\tsignature uri [%zu]: %.*s", intsigurilen, (int)intsigurilen, &sig[indx]);
|
||||||
|
indx += intsigurilen;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
/* if (sigType == stECDSA_P192 || sigType == stECDSA_P256) {
|
||||||
|
indx += 3;
|
||||||
|
PrintAndLogEx(NORMAL, "\tsignature [%zu]: %s", intsiglen, sprint_hex_inrow(&sig[indx], intsiglen));
|
||||||
|
|
||||||
|
uint8_t rval[300] = {0};
|
||||||
|
uint8_t sval[300] = {0};
|
||||||
|
int res = ecdsa_asn1_get_signature(&sig[indx], intsiglen, rval, sval);
|
||||||
|
if (!res) {
|
||||||
|
PrintAndLogEx(NORMAL, "\t\tr: %s", sprint_hex(rval, 32));
|
||||||
|
PrintAndLogEx(NORMAL, "\t\ts: %s", sprint_hex(sval, 32));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
indx += intsiglen;*/
|
||||||
|
|
||||||
|
uint8_t certFormat = (sig[indx] >> 4) & 0x07;
|
||||||
|
uint8_t certCount = sig[indx] & 0x0f;
|
||||||
|
bool certURI = sig[indx] & 0x80;
|
||||||
|
|
||||||
|
PrintAndLogEx(NORMAL, "\tcertificate format: %s", ((certFormat < sfNA) ? ndefCertificateFormat_s[certFormat] : ndefCertificateFormat_s[sfNA]));
|
||||||
|
PrintAndLogEx(NORMAL, "\tcertificates count: %d", certCount);
|
||||||
|
|
||||||
|
// print certificates
|
||||||
|
indx++;
|
||||||
|
for (int i = 0; i < certCount; i++) {
|
||||||
|
size_t intcertlen = (sig[indx + 1] << 8) + sig[indx + 2];
|
||||||
|
indx += 2;
|
||||||
|
|
||||||
|
PrintAndLogEx(NORMAL, "\tcertificate %d [%zu]: %s", i + 1, intcertlen, sprint_hex_inrow(&sig[indx], intcertlen));
|
||||||
|
indx += intcertlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
// have certificate uri
|
||||||
|
if ((indx <= siglen) && certURI) {
|
||||||
|
size_t inturilen = (sig[indx] << 8) + sig[indx + 1];
|
||||||
|
indx += 2;
|
||||||
|
PrintAndLogEx(NORMAL, "\tcertificate uri [%zu]: %.*s", inturilen, (int)inturilen, &sig[indx]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return PM3_SUCCESS;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int ndefDecodeSig(uint8_t *sig, size_t siglen) {
|
||||||
|
PrintAndLogEx(NORMAL, "\tsignature version: 0x%02x", sig[0]);
|
||||||
|
if (sig[0] != 0x01 && sig[0] != 0x20) {
|
||||||
|
PrintAndLogEx(ERR, "signature version unknown.");
|
||||||
|
return PM3_ESOFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sig[0] == 0x01)
|
||||||
|
return ndefDecodeSig1(sig, siglen);
|
||||||
|
|
||||||
|
if (sig[0] == 0x20)
|
||||||
|
return ndefDecodeSig2(sig, siglen);
|
||||||
|
|
||||||
|
return PM3_ESOFT;
|
||||||
|
}
|
||||||
|
|
||||||
static int ndefDecodePayload(NDEFHeader_t *ndef) {
|
static int ndefDecodePayload(NDEFHeader_t *ndef) {
|
||||||
|
|
||||||
switch (ndef->TypeNameFormat) {
|
switch (ndef->TypeNameFormat) {
|
||||||
|
|
Loading…
Reference in a new issue