// Procedures for digital signature processing #include #include #ifndef WIN32 #include #include #include #include #include #include #include #include #include #else #include #include "getopt.h" #include "printf.h" #include "buildno.h" #endif #include "hdlcio.h" #include "ptable.h" #include "flasher.h" #include "util.h" #include "zlib.h" // table of key parameters -g struct { uint8_t type; uint32_t len; char* descr; } signbase[] = { {1,2958,"Basic Firmware"}, {1,2694,"E3372s-Stick Firmware"}, {2,1110,"Web-Interface + ISO for HiLink-Modem"}, {6,1110,"Web-Interface + ISO for HiLink-Modem"}, {2,846,"ISO (Dashboard) for Stick-Modem"}, {7,3750,"Firmware + ISO + Web-Interface"}, }; #define signbaselen 6 // table of signature types char* fwtypes[]={ "UNKNOWN", // 0 "ONLY_FW", // 1 "ONLY_ISO", // 2 "FW_ISO", // 3 "ONLY_WEBUI", // 4 "FW_WEBUI", // 5 "ISO_WEBUI", // 6 "FW_ISO_WEBUI" // 7 }; // result string ^signver-command uint8_t signver[200]; // digital type signature flag extern int gflag; // firmware type flag extern int dflag; // parameters of the current digital signature uint32_t signtype; // firmware type uint32_t signlen; // signature length int32_t serach_sign(); // public key hash for ^signver char signver_hash[100]="778A8D175E602B7B779D9E05C330B5279B0661BF2EED99A20445B366D63DD697"; //**************************************************** //* Receiving of firmware type description by code //**************************************************** char* fw_description(uint8_t code) { return fwtypes[code&0x7]; } //**************************************************** //* Receiving of firmware type list //**************************************************** void dlist() { int i; printf("\n # Description\n--------------------------------------"); for(i=1;i<8;i++) { printf("\n %i %s",i,fw_description(i)); } printf("\n\n"); exit(0); } //*************************************************** //* Processing of key parameters -d //*************************************************** void dparm(char* sparm) { if (dflag != 0) { printf("\n Duplicate option -d\n\n"); exit(-1); } if (sparm[0] == 'l') { dlist(); exit(0); } sscanf(sparm,"%x",&dload_id); if ((dload_id == 0) || (dload_id >7)) { printf("\n Incorrect value for option -d\n\n"); exit(-1); } dflag=1; } //**************************************************** //* Get a list of -g key parameters //**************************************************** void glist() { int i; printf("\n # Length Type Description \n--------------------------------------"); for (i=0; i= signbaselen) goto perror; signlen=signbase[index].len; signtype=signbase[index].type; } gflag=1; // printf("\nstr - %s",signver); return; perror: printf("\n Incorrect value in option -g\n"); exit(-1); } //*************************************************** //* Sending digital signature //*************************************************** void send_signver() { uint32_t res; // response to ^signver unsigned char SVrsp[]={0x0d, 0x0a, 0x30, 0x0d, 0x0a, 0x0d, 0x0a, 0x4f, 0x4b, 0x0d, 0x0a}; uint8_t replybuf[200]; if (gflag == 0) { // auto-detect digital signature signtype=dload_id&0x7; signlen=serach_sign(); if (signlen == -1) return; // no signature found in the file } printf("\n Digital Signature Type: %s (%i bytes)",fw_description(signtype),signlen); sprintf(signver,"^SIGNVER=%i,0,%s,%i",signtype,signver_hash,signlen); res=atcmd(signver,replybuf); if ( (res