Skip to content

Commit

Permalink
Just committing progress, not complete
Browse files Browse the repository at this point in the history
  • Loading branch information
ist17002 committed Apr 24, 2022
1 parent 760ce92 commit c59b43f
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CTng/GZip/GZipbyte.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package GZIP64
package GZip

import (
"bytes"
Expand Down
25 changes: 25 additions & 0 deletions CTng/testData/fakeCA/ca1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"Signer": "localhost:9100",
"Port": "9100",
"Private": {
"N": 21807808817028069521693981025854627766849100907464628031386389529795793140445452403979568400586301388102303005688782597096478795543494617476262626637251939091457219474844544584944694111795327351162485025615396615156332890111445956553729344912738727208120229178581403780883051005207097866108991379098981205093118647139047092214048380759204440914928346690315813577955415022365974040592290311683131513649330794291316838007320668201086717296546111828165980835726696797314928836964283576233301855572522559548630195787917554335560790396850488199331707061308922415163250057868060445529850753103153976841020361249662478352377,
"E": 65537,
"D": 16170594889486794733909710574674328867018614030229504918034896098233919212858190106715154889526403440136404120793629233692425401654510649417526871905395352733394190115500335515052143904310629536858448239998868027375942645038006434604651284699932117542850766088810014162012187720662284326432893557207288869534626592451474437771165267484769520422903629217740240579289273529676393859967869460269837388569687923984655516338040594606575276408080187910404331988648414199330170125400643171043528578702256302970980289260376708590091879360125326297961002223727536666096389652350869770760250561883782148367725025356634681017361,
"Primes": [
140463616384866553918595352312686786596314726395963083219530912014753294451728681148565987592561439612322447556885244594195339901973810432557191641179209965432538551166272379006812619836942931771899375484964986070979627247707320437916212519272441852549385801343414421542851358544842189104008307084551441077879,
155255925899524445855809459296477563268340548102866651520781646889169869510504407353556123334495145398757980576244822554724040783403660456351057991566765756454343543095279460032487003815055894798519954856057590264975197686460364452717860935640242796419957584244644538961183667457780248977122454469708800674063
],
"Precomputed": {
"Dp": 94235382840377384419378373292708128737457709235663897386153396393864120274861630113373351579561795274037465465021750069694687044112249524675749608303210457606204968455661137375399198452640597283166329574483734494542506535654599157945893648585848045728235880700478283815189717754850258182782813462525867240065,
"Dq": 5943774022031933635232402053418102846335145569527021814633583350548960169093116225186876320952260857309363768036349844970056888865217878221230823822283828721850984171171340849009107718875982117727185662051184734956173932211255541325802418290757422161796749605105713539734956156851406757764319975960135204407,
"Qinv": 117606986598227264217645620978351610344911734058605024661741419619675948441364368837781444262761974698255363090133986028132488840217620702351940326116721108816542662361368257279753290519174829343170106517463300473891031311618123799343542327698990108420159529104166928829857013602141869228032970252472551770948,
"CRTValues": []
}
},
"Public": {
"N": 21807808817028069521693981025854627766849100907464628031386389529795793140445452403979568400586301388102303005688782597096478795543494617476262626637251939091457219474844544584944694111795327351162485025615396615156332890111445956553729344912738727208120229178581403780883051005207097866108991379098981205093118647139047092214048380759204440914928346690315813577955415022365974040592290311683131513649330794291316838007320668201086717296546111828165980835726696797314928836964283576233301855572522559548630195787917554335560790396850488199331707061308922415163250057868060445529850753103153976841020361249662478352377,
"E": 65537
},
"MMD": 10,
"MisbehaviorInterval": 3
}
25 changes: 25 additions & 0 deletions CTng/testData/fakeCA/ca2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"Signer": "localhost:9101",
"Port": "9101",
"Private": {
"N": 23252973551340935183125964301239394441268751011208146732992808020417063643722798116442608594279677205628615159796637042351236895510183530067421586578520622761961327937601077936607208585910560962764238731254814969375357028226260361691859503574268216691949008213953884839053600853903979504862782260745247938279459295671742467758276923319951606178695777588680957056514003518072749213888863320971271934432550756175972781344678001820332694558433506149685765145751895391937311845198206021246778714450986559172352984358941313079975500433800828535054555138262203102926122738137575483960219776073243032678302367325287435201381,
"E": 65537,
"D": 9892723325121503193248365604882078761790367512924081773796564890447664197541527031793533619569189310577796479629061965223266050026930393294472567816383294991363744839650781314806631212786033244789851599933575704962444186657988485965064416721207049724658166333849004639859811999459095725385417321422997741964071169239116281796709312310722904232260541441925575594725203767780858601940864212603563066830244314664580640649923892322228114227691213682680669864798774651265456371775894511256143862363829207724103150866837145073236702916364633459286556572186821959319927812492821437036207460276415312536819291029941936323265,
"Primes": [
137056409386041802375726016857850369921167192030246751743169406906674437099007896355034758356182092414453973088798676832418564561314627364082939984122868240355876852806144943575933853994514467774370874834465170920507763190393459934332542491758024296743740878430318770053938130599515713462420488881276455774217,
169659876947783817211784746324263854479398271283934329177057505145913733988104549449473216860612202597591491482546632529630508946254555167431852457758526673854434983889199066904260673248299263530018972075229101894611780029800418488776561887182474812639949141561426482249946794166954837409500489869686874957693
],
"Precomputed": {
"Dp": 104311101267473016169474312142037606257501844321172432827220453287425641211245782722626588218075386232823439029802847272902415151041584117263423157423509543627428499032877666671101892112736120635943739656503780465141930820355453988808961150897943053500786598032040983437148176086382414083526428809820228841145,
"Dq": 128620188996653663950902747095148165859810850519111238091962175346286494033370255502199174611328816910428241494405402911365521865293060697601113226288579569766448689130582212186570750715908580026938410494616517364723616872920701164172523930036072426128801030705371215406661222231578866012384185096747222109617,
"Qinv": 112919998236801026917941512303801999286506004751424349437885524823620018722687772818940045965261568245515566545625852325865792072384891143066647831616219834597153870222306633808513632723980064591609812545951479361885781992841009599637478237579158391311252760737685253043948350622409150267441100098649125932732,
"CRTValues": []
}
},
"Public": {
"N": 23252973551340935183125964301239394441268751011208146732992808020417063643722798116442608594279677205628615159796637042351236895510183530067421586578520622761961327937601077936607208585910560962764238731254814969375357028226260361691859503574268216691949008213953884839053600853903979504862782260745247938279459295671742467758276923319951606178695777588680957056514003518072749213888863320971271934432550756175972781344678001820332694558433506149685765145751895391937311845198206021246778714450986559172352984358941313079975500433800828535054555138262203102926122738137575483960219776073243032678302367325287435201381,
"E": 65537
},
"MMD": 10,
"MisbehaviorInterval": 3
}
25 changes: 25 additions & 0 deletions CTng/testData/fakeCA/ca3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"Signer": "localhost:9102",
"Port": "9102",
"Private": {
"N": 20028649974874227033360914359590766678527711517531636997713603474008908788659881072754993703433185955779617335557947288171124892464864232545291605031424352674054323768598060610599281281539072954580390937994894319035538689968791373798820944766502542768153531189979514749140151783915919768722020901389133722554527607979186909863026840800319528623758670965878003072462079597023515002126915829370037330794543912057953039966473482799333260960689543682741483394536974500771002815055637466302437703527466497406576505348945381874007559705058294342241838471511807556669238624256963671945475465519079937531652829531772652319583,
"E": 65537,
"D": 2688130448128441963859233756610165001515628583978642278894194976233003672811576878953155082097110085402711660337941992260146399043608126546353738466155127731220254693815532311989124893608460651364711822185987921788250886018058332299837176406703943820874902121657381505614183973806009281561238626251107316837620504520183617306425404610171723821769097292826247252148291128539006510252193355004670188542042970811181218280127164420424333352889762625370967673391792407320408289084682833321927389606679069691537203721011613525651202856647907853632246718182289122454779060292890491955306569998584279339929136729788813241153,
"Primes": [
139882067456344148156549719699281689121690056576113505330676318855419705353893809602639533864540838819650851266937261192894180528286330653283144975690606821703592001059371946373839571438785300704850331784210047987717852666390883170238246817948002558289585684537147908774261136332919507609710214876526809568743,
143182398852697659936032106447411087970163119402643754939207315109788150070203021706794096784497141217794741857256324537163326118131228811752891805490535596466501532306536228498498617235006095476820111688434956938745041097769964946049003980813386374196063208658519245290936171160101094417061323857136536999881
],
"Precomputed": {
"Dp": 73781883635669995780637055565020819225148875836902690881041533640449644852120194857012731840478626063409839122869329461463997932493124159218330950755647902904462643890021963810532772410942372625620127090293619464415989913664037863020823595874491545767343606559350121465869035213030220166508425894560000506161,
"Dq": 347376312885529211435206141952459877431922974579555930777026154728722948275970527356764291754810953409972442365438692668400580630527265225272896181897175028429341343618707910512554437041151855910621446792821736626035087577176624295005746875037435852986466426243260448315590448364375452222603269806135608633,
"Qinv": 70312256718574409922678059910929589188720596724723275357114271158724815622907845009357333704801452151756703330916312692668867168599668758674852895599600933909851586517988833054147618873752175118630390874152098464609349217481720207223891577516784171347413546419722394082971817727692250087049413939107186749392,
"CRTValues": []
}
},
"Public": {
"N": 20028649974874227033360914359590766678527711517531636997713603474008908788659881072754993703433185955779617335557947288171124892464864232545291605031424352674054323768598060610599281281539072954580390937994894319035538689968791373798820944766502542768153531189979514749140151783915919768722020901389133722554527607979186909863026840800319528623758670965878003072462079597023515002126915829370037330794543912057953039966473482799333260960689543682741483394536974500771002815055637466302437703527466497406576505348945381874007559705058294342241838471511807556669238624256963671945475465519079937531652829531772652319583,
"E": 65537
},
"MMD": 10,
"MisbehaviorInterval": 3
}
127 changes: 127 additions & 0 deletions CTng/testData/fakeCA/fakeCA.go
Original file line number Diff line number Diff line change
@@ -1 +1,128 @@
package fakeCA

import (
"CTng/crypto"
"CTng/gossip"
"CTng/util"
"crypto/rsa"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/gorilla/mux"
)

type CAConfig struct {
Signer string
Port string
MRD int
Private rsa.PrivateKey
CRVs [][]byte //should be array of size 365??
Day int
}

type Revocation struct {
SRH string
delta_CRV []byte
Timestamp string
}

//Caution: this file is plagued with Global Variables for conciseness.
var config CAConfig
var SRHs []gossip.Gossip_object
var fakeSRHs []gossip.Gossip_object
var request_count int
var currentPeriod int

func generateCRVs(CA CAConfig) gossip.Gossip_object {
// Generate delta CRV and then compress it
first_arr := CA.CRVs[CA.Day-1] //this assumes we never have CRV of len 0 (fresh CA)
sec_arr := CA.CRVs[CA.Day]

var delta_crv [len(sec_arr)]byte
for i, e := range first_arr {
delta_crv[i] = e & sec_arr[i]
} //this is scuffed/slow for giant CRVs O(n), also I am assuming CRVs are same size, can modify for different sizes

delta_crv = GZip.compress(delta_crv) //should work...

REV := Revocation{
SRH: CA.Signer,
delta_CRV: delta_crv,
Timestamp: gossip.GetTimestamp(),
}

payload, _ := json.Marshal(REV)
signature, _ := crypto.RSASign([]byte(payload), &CA.Private, crypto.CTngID(CA.Signer))
gossipREV := gossip.Gossip_object{
Application: "CTng",
Type: gossip.REVOCATION,
Signer: CA.Signer,
Signature: [2]string{signature.String(), ""},
Timestamp: REV.Timestamp,
Payload: [2]string{string(payload), ""},
}
return gossipREV
}

func periodicTasks() {
// Generate CRV and SRH
fmt.Println("Running Tasks")
Rev1 := generateCRVs(config)
request_count++
fakeRev1 := generateCRVs(config)
SRHs = append(SRHs, Rev1)
fakeSRHs = append(fakeSRHs, fakeRev1)
currentPeriod++
// Queue the next tasks to occur at next MRD.
time.AfterFunc(time.Duration(config.MRD)*time.Second, periodicTasks)
}

//I'm up to here right now, messaged on discord just to make sure I'm on a good path
//ignore json files at the moment
func requestSTH(w http.ResponseWriter, r *http.Request) {
//Disconnecting logger:
request_count++
if loggerType == 3 && currentPeriod%config.MisbehaviorInterval == 0 {
// No response or any bad request response should trigger the accusation
return
}
// Split-World Logger
if loggerType == 2 && request_count%2 == 0 && currentPeriod%config.MisbehaviorInterval == 0 {
json.NewEncoder(w).Encode(fakeSRHs[currentPeriod-1])
return
}
json.NewEncoder(w).Encode(SRHs[currentPeriod-1])
}

// Runs a fake logger server with the ability to act roguely.
// Note that the monitor configurations must include the fakeLogger's Public key and ID as trusted, which
// Requires copying them from the fakelogger config file that is being used. (see testData/fakeLogger/logger1.json)
func RunCA(configFile string) {
// Global Variable initialization

currentPeriod = 0
request_count = 0
STHS = make([]gossip.Gossip_object, 0, 20)
fakeSTHs = make([]gossip.Gossip_object, 0, 20)
// Read the config file
config = LoggerConfig{}
configBytes, err := util.ReadByte(configFile)
if err != nil {
fmt.Println("Error reading config file: ", err)
return
}
err = json.Unmarshal(configBytes, &config)
if err != nil {
fmt.Println("Error reading config file: ", err)
}
getLoggerType()
// MUX which routes HTTP directories to functions.
gorillaRouter := mux.NewRouter().StrictSlash(true)
gorillaRouter.HandleFunc("/ctng/v2/get-sth", requestSTH).Methods("GET")
http.Handle("/", gorillaRouter)
fmt.Println("Listening on port", config.Port)
go periodicTasks()
http.ListenAndServe(":"+config.Port, nil)
}

0 comments on commit c59b43f

Please sign in to comment.