mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-15 11:43:14 +08:00
get cose public key and fix some printing
This commit is contained in:
parent
0a2f874ac3
commit
065773377d
2 changed files with 45 additions and 8 deletions
|
@ -720,22 +720,27 @@ int MakeCredentionalParseRes(json_t *root, uint8_t *data, size_t dataLen, bool v
|
||||||
|
|
||||||
// Credential ID
|
// Credential ID
|
||||||
uint8_t cridlen = (uint16_t)bytes_to_num(&ubuf[53], 2);
|
uint8_t cridlen = (uint16_t)bytes_to_num(&ubuf[53], 2);
|
||||||
PrintAndLog("Credential id[%d]: %s", cridlen, sprint_hex(&ubuf[55], cridlen));
|
PrintAndLog("Credential id[%d]: %s", cridlen, sprint_hex_inrow(&ubuf[55], cridlen));
|
||||||
JsonSaveBufAsHexCompact(root, "$.AppData.CredentialId", &ubuf[55], cridlen);
|
JsonSaveBufAsHexCompact(root, "$.AppData.CredentialId", &ubuf[55], cridlen);
|
||||||
|
|
||||||
//Credentional public key (COSE_KEY)
|
//Credentional public key (COSE_KEY)
|
||||||
uint8_t coseKey[65] = {0};
|
uint8_t coseKey[65] = {0};
|
||||||
uint16_t cplen = n - 55 - cridlen;
|
uint16_t cplen = n - 55 - cridlen;
|
||||||
PrintAndLog("Credentional public key (COSE_KEY)[%d]: %s", cplen, sprint_hex(&ubuf[55 + cridlen], cplen));
|
PrintAndLog("Credentional public key (COSE_KEY)[%d]: %s", cplen, sprint_hex_inrow(&ubuf[55 + cridlen], cplen));
|
||||||
JsonSaveBufAsHexCompact(root, "$.AppData.COSE_KEY", &ubuf[55 + cridlen], cplen);
|
JsonSaveBufAsHexCompact(root, "$.AppData.COSE_KEY", &ubuf[55 + cridlen], cplen);
|
||||||
if (showCBOR) {
|
if (showCBOR) {
|
||||||
|
PrintAndLog("COSE structure:");
|
||||||
|
PrintAndLog("---------------- CBOR ------------------");
|
||||||
TinyCborPrintFIDOPackage(fido2COSEKey, true, &ubuf[55 + cridlen], cplen);
|
TinyCborPrintFIDOPackage(fido2COSEKey, true, &ubuf[55 + cridlen], cplen);
|
||||||
|
PrintAndLog("---------------- CBOR ------------------");
|
||||||
}
|
}
|
||||||
res = COSEGetECDSAKey(&ubuf[55 + cridlen], cplen, verbose, coseKey);
|
res = COSEGetECDSAKey(&ubuf[55 + cridlen], cplen, verbose, coseKey);
|
||||||
if (res)
|
if (res) {
|
||||||
PrintAndLog("ERROR: Can't get COSE_KEY.");
|
PrintAndLog("ERROR: Can't get COSE_KEY.");
|
||||||
else
|
} else {
|
||||||
|
PrintAndLog("COSE public key: %s", sprint_hex_inrow(coseKey, sizeof(coseKey)));
|
||||||
JsonSaveBufAsHexCompact(root, "$.AppData.COSEPublicKey", coseKey, sizeof(coseKey));
|
JsonSaveBufAsHexCompact(root, "$.AppData.COSEPublicKey", coseKey, sizeof(coseKey));
|
||||||
|
}
|
||||||
|
|
||||||
free(ubuf);
|
free(ubuf);
|
||||||
|
|
||||||
|
@ -767,13 +772,13 @@ int MakeCredentionalParseRes(json_t *root, uint8_t *data, size_t dataLen, bool v
|
||||||
if (!strcmp(key, "sig")) {
|
if (!strcmp(key, "sig")) {
|
||||||
res = CborGetBinStringValue(&mapsmt, sign, sizeof(sign), &signLen);
|
res = CborGetBinStringValue(&mapsmt, sign, sizeof(sign), &signLen);
|
||||||
cbor_check(res);
|
cbor_check(res);
|
||||||
PrintAndLog("signature [%d]: %s", signLen, sprint_hex(sign, signLen));
|
PrintAndLog("signature [%d]: %s", signLen, sprint_hex_inrow(sign, signLen));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(key, "x5c")) {
|
if (!strcmp(key, "x5c")) {
|
||||||
res = CborGetArrayBinStringValue(&mapsmt, der, sizeof(der), &derLen);
|
res = CborGetArrayBinStringValue(&mapsmt, der, sizeof(der), &derLen);
|
||||||
cbor_check(res);
|
cbor_check(res);
|
||||||
PrintAndLog("DER [%d]: %s", derLen, sprint_hex(der, derLen));
|
PrintAndLog("DER [%d]: %s", derLen, sprint_hex_inrow(der, derLen));
|
||||||
JsonSaveBufAsHexCompact(root, "$.AppData.DER", der, derLen);
|
JsonSaveBufAsHexCompact(root, "$.AppData.DER", der, derLen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -816,7 +821,7 @@ int MakeCredentionalParseRes(json_t *root, uint8_t *data, size_t dataLen, bool v
|
||||||
clientDataHash, 32, // Hash of the serialized client data. "$.ClientDataHash" from json
|
clientDataHash, 32, // Hash of the serialized client data. "$.ClientDataHash" from json
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
PrintAndLog("--xbuf(%d)[%d]: %s", res, xbuflen, sprint_hex(xbuf, xbuflen));
|
PrintAndLog("--xbuf(%d)[%d]: %s", res, xbuflen, sprint_hex(xbuf, xbuflen));
|
||||||
res = ecdsa_signature_verify(public_key, xbuf, xbuflen, sign, signLen);
|
res = ecdsa_signature_verify(coseKey, xbuf, xbuflen, sign, signLen);
|
||||||
if (res) {
|
if (res) {
|
||||||
if (res == -0x4e00) {
|
if (res == -0x4e00) {
|
||||||
PrintAndLog("Signature is NOT VALID.");
|
PrintAndLog("Signature is NOT VALID.");
|
||||||
|
@ -880,7 +885,9 @@ int CmdHFFido2MakeCredential(const char *cmd) {
|
||||||
|
|
||||||
if (showCBOR) {
|
if (showCBOR) {
|
||||||
PrintAndLog("CBOR make credentional request:");
|
PrintAndLog("CBOR make credentional request:");
|
||||||
|
PrintAndLog("---------------- CBOR ------------------");
|
||||||
TinyCborPrintFIDOPackage(fido2CmdMakeCredential, false, data, datalen);
|
TinyCborPrintFIDOPackage(fido2CmdMakeCredential, false, data, datalen);
|
||||||
|
PrintAndLog("---------------- CBOR ------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
res = FIDO2MakeCredential(data, datalen, buf, sizeof(buf), &len, &sw);
|
res = FIDO2MakeCredential(data, datalen, buf, sizeof(buf), &len, &sw);
|
||||||
|
@ -903,7 +910,9 @@ int CmdHFFido2MakeCredential(const char *cmd) {
|
||||||
PrintAndLog("MakeCredential result (%d b) OK.", len);
|
PrintAndLog("MakeCredential result (%d b) OK.", len);
|
||||||
if (showCBOR) {
|
if (showCBOR) {
|
||||||
PrintAndLog("CBOR make credentional response:");
|
PrintAndLog("CBOR make credentional response:");
|
||||||
|
PrintAndLog("---------------- CBOR ------------------");
|
||||||
TinyCborPrintFIDOPackage(fido2CmdMakeCredential, true, &buf[1], len - 1);
|
TinyCborPrintFIDOPackage(fido2CmdMakeCredential, true, &buf[1], len - 1);
|
||||||
|
PrintAndLog("---------------- CBOR ------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse returned cbor
|
// parse returned cbor
|
||||||
|
|
|
@ -71,7 +71,7 @@ COSEValueTypeNameDesc_t *GetCOSECurveElm(int id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *GetCOSECurveDescription(int id) {
|
const char *GetCOSECurveDescription(int id) {
|
||||||
COSEValueNameDesc_t *elm = GetCOSECurveElm(id);
|
COSEValueTypeNameDesc_t *elm = GetCOSECurveElm(id);
|
||||||
if (elm)
|
if (elm)
|
||||||
return elm->Description;
|
return elm->Description;
|
||||||
return COSEEmptyStr;
|
return COSEEmptyStr;
|
||||||
|
@ -160,6 +160,7 @@ int COSEGetECDSAKey(uint8_t *data, size_t datalen, bool verbose, uint8_t *public
|
||||||
CborParser parser;
|
CborParser parser;
|
||||||
CborValue map;
|
CborValue map;
|
||||||
int64_t i64;
|
int64_t i64;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
if(verbose)
|
if(verbose)
|
||||||
PrintAndLog("----------- CBOR decode ----------------");
|
PrintAndLog("----------- CBOR decode ----------------");
|
||||||
|
@ -191,6 +192,33 @@ int COSEGetECDSAKey(uint8_t *data, size_t datalen, bool verbose, uint8_t *public
|
||||||
// plain key
|
// plain key
|
||||||
public_key[0] = 0x04;
|
public_key[0] = 0x04;
|
||||||
|
|
||||||
|
// x - coordinate
|
||||||
|
res = CborMapGetKeyById(&parser, &map, data, datalen, -2);
|
||||||
|
if(!res) {
|
||||||
|
res = CborGetBinStringValue(&map, &public_key[1], 32, &len);
|
||||||
|
cbor_check(res);
|
||||||
|
if(verbose)
|
||||||
|
PrintAndLog("x - coordinate [%d]: %s", len, sprint_hex(&public_key[1], 32));
|
||||||
|
}
|
||||||
|
|
||||||
|
// y - coordinate
|
||||||
|
res = CborMapGetKeyById(&parser, &map, data, datalen, -3);
|
||||||
|
if(!res) {
|
||||||
|
res = CborGetBinStringValue(&map, &public_key[33], 32, &len);
|
||||||
|
cbor_check(res);
|
||||||
|
if(verbose)
|
||||||
|
PrintAndLog("y - coordinate [%d]: %s", len, sprint_hex(&public_key[33], 32));
|
||||||
|
}
|
||||||
|
|
||||||
|
// d - private key
|
||||||
|
uint8_t private_key[128] = {0};
|
||||||
|
res = CborMapGetKeyById(&parser, &map, data, datalen, -4);
|
||||||
|
if(!res) {
|
||||||
|
res = CborGetBinStringValue(&map, private_key, sizeof(private_key), &len);
|
||||||
|
cbor_check(res);
|
||||||
|
if(verbose)
|
||||||
|
PrintAndLog("d - private key [%d]: %s", len, sprint_hex(private_key, len));
|
||||||
|
}
|
||||||
|
|
||||||
if(verbose)
|
if(verbose)
|
||||||
PrintAndLog("----------- CBOR decode ----------------");
|
PrintAndLog("----------- CBOR decode ----------------");
|
||||||
|
|
Loading…
Reference in a new issue