From 941d067b305461d47d52d85e5db6a35adee555a8 Mon Sep 17 00:00:00 2001 From: Brian Dickson Date: Tue, 7 Apr 2020 15:14:15 -0700 Subject: [PATCH 1/4] do-over of updates, on my own forked clone --- backend/backend.go | 56 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/backend/backend.go b/backend/backend.go index 4656f02..5314c96 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -28,11 +28,59 @@ type Backend struct { db *sql.DB } +// +// Brian Dickson's added comments for understanding the SQL elements used/required +// +// OLD DEFINITIONS, WRONG SIZE FOR cenKey +// +// CREATE TABLE `CENKeys` ( +// `cenKey` varchar(32) DEFAULT "", +// `reportID` varchar(64) DEFAULT "", +// `reportTS` int, +// PRIMARY KEY (`cenKey`, `reportID`), +// KEY (`reportID`), +// KEY (`reportTS`), +// KEY (`cenKey`) +// ); +// +// CREATE TABLE `CENReport` ( +// `reportID` varchar(64) DEFAULT "", +// `report` varchar(4000) DEFAULT "", +// `reportMimeType` varchar(64) DEFAULT "", +// `reportTS` int, +// PRIMARY KEY (`reportID`), +// KEY (`reportTS`) +// ); +// +// +// NEW DEFINITIONS, RIGHT SIZE FOR cenKey +// +// CREATE TABLE `CENKeys` ( +// `cenKey` varchar(64) DEFAULT "", +// `reportID` varchar(64) DEFAULT "", +// `reportTS` int, +// PRIMARY KEY (`cenKey`, `reportID`), +// KEY (`reportID`), +// KEY (`reportTS`), +// KEY (`cenKey`) +// ); +// +// CREATE TABLE `CENReport` ( +// `reportID` varchar(64) DEFAULT "", +// `report` varchar(4000) DEFAULT "", +// `reportMimeType` varchar(64) DEFAULT "", +// `reportTS` int, +// PRIMARY KEY (`reportID`), +// KEY (`reportTS`) +// ); +// +// + // CENReport payload is sent by client to /cenreport when user reports symptoms type CENReport struct { ReportID string `json:"reportID,omitempty"` Report []byte `json:"report,omitempty"` // this is expected to be a JSON blob but the server doesn't need to parse it - CENKeys string `json:"cenKeys,omitempty"` // comma separated list of base64 AES Keys + CENKeys string `json:"cenKeys,omitempty"` // comma separated list of hex AES-128 Keys (COMMENT WAS: base64 AES Keys) ReportMimeType string `json:"reportMimeType,omitempty"` ReportTimeStamp uint64 `json:"reportTimeStamp,omitempty"` } @@ -78,8 +126,8 @@ func (backend *Backend) ProcessCENReport(cenReport *CENReport) (err error) { // store the cenreportID in cenkeys table, one row per key for _, cenKey := range cenKeys { cenKey := strings.Trim(cenKey, " \n") - if len(cenKey) > 30 && len(cenKey) <= 32 { - _, err = stmtKeys.Exec(cenKey, reportID, curTS) + if len(cenKey) > 62 && len(cenKey) <= 64 { + _, err = stmtKeys.Exec(cenKey, reportID, cenReport.ReportTimestamp) if err != nil { return err } @@ -87,7 +135,7 @@ func (backend *Backend) ProcessCENReport(cenReport *CENReport) (err error) { } // store the cenreportID in cenReport table, one row per key - _, err = stmtReport.Exec(reportID, cenReport.Report, cenReport.ReportMimeType, curTS) + _, err = stmtReport.Exec(reportID, cenReport.Report, cenReport.ReportMimeType, cenReport.ReportTimeStamp) if err != nil { panic(5) return err From 3511f393b6648202d56f28189715123af0666e5e Mon Sep 17 00:00:00 2001 From: Brian Dickson Date: Tue, 7 Apr 2020 15:41:07 -0700 Subject: [PATCH 2/4] fix test case stuff to include current timestamp --- backend/backend.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/backend.go b/backend/backend.go index 5314c96..e6f0ea5 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -222,9 +222,11 @@ func GetSampleCENReportAndCENKeys(nKeys int) (cenReport *CENReport, cenKeys []st cenKeys[i] = makeCENKeyString() } CENKeys := fmt.Sprintf("%s,%s", cenKeys[0], cenKeys[1]) + curTS := uint64(time.Now().Unix()) cenReport = new(CENReport) cenReport.ReportID = "1" cenReport.Report = []byte("severe fever,coughing,hard to breathe") cenReport.CENKeys = CENKeys + cenReport.ReportTimeStamp = curTS return cenReport, cenKeys } From ccd24d5c388a9cf6eff4b2073fb07d8fe33de57a Mon Sep 17 00:00:00 2001 From: Brian Dickson Date: Tue, 7 Apr 2020 16:53:40 -0700 Subject: [PATCH 3/4] fix tyop --- backend/backend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/backend.go b/backend/backend.go index e6f0ea5..9c79910 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -127,7 +127,7 @@ func (backend *Backend) ProcessCENReport(cenReport *CENReport) (err error) { for _, cenKey := range cenKeys { cenKey := strings.Trim(cenKey, " \n") if len(cenKey) > 62 && len(cenKey) <= 64 { - _, err = stmtKeys.Exec(cenKey, reportID, cenReport.ReportTimestamp) + _, err = stmtKeys.Exec(cenKey, reportID, cenReport.ReportTimeStamp) if err != nil { return err } From 926220f4d5a7710767ed2f36373cabf0badd6ac7 Mon Sep 17 00:00:00 2001 From: Brian Dickson Date: Tue, 7 Apr 2020 20:58:39 -0700 Subject: [PATCH 4/4] fix test code in backend.go - wrong number of characters in cenKeys --- backend/backend.go | 5 ++--- backend/cen2.sql | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 backend/cen2.sql diff --git a/backend/backend.go b/backend/backend.go index 9c79910..282dc75 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -20,7 +20,7 @@ const ( TableCENReport = "CENReport" // Default Conn String - DefaultConnString = "[change this to your server]" + DefaultConnString = "root:2Nemesis234@/conn" ) // Backend holds a client to connect to the BigTable backend @@ -120,7 +120,6 @@ func (backend *Backend) ProcessCENReport(cenReport *CENReport) (err error) { return err } - curTS := uint64(time.Now().Unix()) reportID := fmt.Sprintf("%x", Computehash(reportData)) cenKeys := strings.Split(cenReport.CENKeys, ",") // store the cenreportID in cenkeys table, one row per key @@ -209,7 +208,7 @@ func Computehash(data ...[]byte) []byte { } func makeCENKeyString() string { - key := make([]byte, 16) + key := make([]byte, 32) rand.Read(key) encoded := fmt.Sprintf("%x", key) return encoded diff --git a/backend/cen2.sql b/backend/cen2.sql new file mode 100644 index 0000000..257bf6e --- /dev/null +++ b/backend/cen2.sql @@ -0,0 +1,23 @@ +DROP TABLE IF EXISTS CENKeys; +DROP TABLE IF EXISTS CENReport; + +CREATE TABLE `CENKeys` ( + `cenKey` varchar(64) DEFAULT "", + `reportID` varchar(64) DEFAULT "", + `reportTS` int, + PRIMARY KEY (`cenKey`, `reportID`), + KEY (`reportID`), + KEY (`reportTS`), + KEY (`cenKey`) +); + +CREATE TABLE `CENReport` ( + `reportID` varchar(64) DEFAULT "", + `report` varchar(4000) DEFAULT "", + `reportMimeType` varchar(64) DEFAULT "", + `reportTS` int, + PRIMARY KEY (`reportID`), + KEY (`reportTS`) +); + +