added cbor print sketch

This commit is contained in:
merlokk 2018-11-16 18:33:10 +02:00
commit 2d17fb172a
4 changed files with 73 additions and 7 deletions

View file

@ -30,9 +30,9 @@ JANSSONLIB = $(JANSSONLIBPATH)/libjansson.a
MBEDTLSLIBPATH = ../common/mbedtls
MBEDTLSLIB = $(MBEDTLSLIBPATH)/libmbedtls.a
CBORLIBPATH = ./tinycbor
CBORLIB = $(MBEDTLSLIBPATH)/tinycbor.a
LIBS = -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH)
INCLUDES_CLIENT = -I. -I../include -I../common -I../common/polarssl -I../zlib -I../uart -I/opt/local/include -I../liblua $(LIBS)
CBORLIB = $(CBORLIBPATH)/tinycbor.a
LIBS = -I../zlib -I../uart -I../liblua -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH)
INCLUDES_CLIENT = -I. -I../include -I../common -I/opt/local/include $(LIBS)
LDFLAGS = $(ENV_LDFLAGS)
CFLAGS = $(ENV_CFLAGS) -std=c99 -D_ISOC99_SOURCE -DPRESETS $(INCLUDES_CLIENT) -Wall -g -O3
CXXFLAGS = -I../include -Wall -O3
@ -111,6 +111,7 @@ CMDSRCS = crapto1/crapto1.c \
mfkey.c \
tea.c \
fido/additional_ca.c \
fido/cbortools.c \
crypto/asn1dump.c \
crypto/libpcrypto.c\
crypto/asn1utils.c\
@ -269,7 +270,7 @@ all: lua_build jansson_build mbedtls_build cbor_build $(BINS)
all-static: LDLIBS:=-static $(LDLIBS)
all-static: proxmark3 flasher fpga_compress
proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(QTLDLIBS)
proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(QTLDLIBS)
proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(ZLIBOBJS) lualibs/usb_cmd.lua lualibs/mf_default_keys.lua
$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(ZLIBOBJS) $(LDLIBS) -o $@

View file

@ -28,6 +28,9 @@
#include <ctype.h>
#include <unistd.h>
#include <jansson.h>
#include <mbedtls/x509_crt.h>
#include <mbedtls/x509.h>
#include <mbedtls/pk.h>
#include "comms.h"
#include "cmdmain.h"
#include "util.h"
@ -42,9 +45,7 @@
#include "crypto/asn1utils.h"
#include "crypto/libpcrypto.h"
#include "fido/additional_ca.h"
#include "mbedtls/x509_crt.h"
#include "mbedtls/x509.h"
#include "mbedtls/pk.h"
#include "fido/cbortools.h"
static int CmdHelp(const char *Cmd);
@ -142,6 +143,7 @@ int CmdHFFidoInfo(const char *cmd) {
PrintAndLog("FIDO2 version: (%d)", len);
dump_buffer((const unsigned char *)buf, len, NULL, 0);
TinyCborPrintFIDOPackage(buf, len);
return 0;
}

41
client/fido/cbortools.c Normal file
View file

@ -0,0 +1,41 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2018 Merlok
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Tools for work with CBOR format http://cbor.io/spec.html
// via Intel tinycbor (https://github.com/intel/tinycbor) library
//-----------------------------------------------------------------------------
//
#include "cbortools.h"
#include "cbor.h"
int TinyCborParser(uint8_t *data, size_t length, CborValue *cb) {
CborParser parser;
CborError err = cbor_parser_init(data, length, 0, &parser, cb);
// if (!err)
// err = dumprecursive(cb, 0);
if (err) {
fprintf(stderr, "CBOR parsing failure at offset %d: %s\n",
cb->ptr - data, cbor_error_string(err));
return 1;
}
return 0;
}
int TinyCborPrintFIDOPackage(uint8_t *data, size_t length) {
CborValue cb;
int res;
res = TinyCborParser(data, length, &cb);
if (res)
return res;
return 0;
}

22
client/fido/cbortools.h Normal file
View file

@ -0,0 +1,22 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2018 Merlok
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Tools for work with CBOR format http://cbor.io/spec.html
// via Intel tinycbor (https://github.com/intel/tinycbor) library
//-----------------------------------------------------------------------------
//
#ifndef __CBORTOOLS_H__
#define __CBORTOOLS_H__
#include <stddef.h>
#include <stdint.h>
extern int TinyCborPrintFIDOPackage(uint8_t *data, size_t length);
#endif /* __CBORTOOLS_H__ */