Skip to content

Commit

Permalink
Commented Gossip PoM verification, uncommented Accusations
Browse files Browse the repository at this point in the history
  • Loading branch information
tfn18001 committed Apr 25, 2022
1 parent 86109d3 commit b40046e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 48 deletions.
71 changes: 34 additions & 37 deletions CTng/gossip/gossip_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,57 +53,54 @@ func unpack_object(obj []byte) (depacked Gossip_object) {
}

//verify gossip pom takes a gossip object as input
// Note: This function is not yet working.
func Verify_gossip_pom(g Gossip_object, c *crypto.CryptoConfig) error {
if g.Type == GOSSIP_POM {
// Assume true for now.
return nil
//gossip pom refers to Pom generated due to conflicting information
//From Finn's gossiper design, gossip poms are defaulted to have 2 non empty fields for signature and paypload
var err1, err2 error
if g.Signature[1] != "" && g.Payload[1] != "" {
if g.Signature[0] != g.Signature[1] {
//that means there are conflicting information
//the PoM is valid and the verification went through.
if g.Signature[0] != g.Signature[1] {
//that means there are conflicting information
//the PoM is valid and the verification went through.

// Next we need to figure out what type of signature is being used.
// First: try ThresholdSignature
thresSig1, sigerr1 := crypto.ThresholdSigFromString(g.Signature[0])
thresSig2, sigerr2 := crypto.ThresholdSigFromString(g.Signature[1])
// Verify the signatures were made successfully
if sigerr1 != nil || sigerr2 != nil && thresSig1.Sign != thresSig2.Sign {
err1 = c.ThresholdVerify(g.Payload[0], thresSig1)
err2 = c.ThresholdVerify(g.Payload[1], thresSig2)
// Next we need to figure out what type of signature is being used.
// First: try ThresholdSignature
thresSig1, sigerr1 := crypto.ThresholdSigFromString(g.Signature[0])
thresSig2, sigerr2 := crypto.ThresholdSigFromString(g.Signature[1])
// Verify the signatures were made successfully
if sigerr1 != nil || sigerr2 != nil && thresSig1.Sign != thresSig2.Sign {
err1 = c.ThresholdVerify(g.Payload[0], thresSig1)
err2 = c.ThresholdVerify(g.Payload[1], thresSig2)
} else {
// Second: try SigFragment
fragsig1, sigerr1 := crypto.SigFragmentFromString(g.Signature[0])
fragsig2, sigerr2 := crypto.SigFragmentFromString(g.Signature[1])
// Verify the signatures were made successfully
if sigerr1 != nil || sigerr2 != nil && !fragsig1.Sign.IsEqual(fragsig2.Sign) {
err1 = c.FragmentVerify(g.Payload[0], fragsig1)
err2 = c.FragmentVerify(g.Payload[1], fragsig2)
} else {
// Second: try SigFragment
fragsig1, sigerr1 := crypto.SigFragmentFromString(g.Signature[0])
fragsig2, sigerr2 := crypto.SigFragmentFromString(g.Signature[1])
// Try RSASig
rsaSig1, sigerr1 := crypto.RSASigFromString(g.Signature[0])
rsaSig2, sigerr2 := crypto.RSASigFromString(g.Signature[1])
// Verify the signatures were made successfully
if sigerr1 != nil || sigerr2 != nil && !fragsig1.Sign.IsEqual(fragsig2.Sign) {
err1 = c.FragmentVerify(g.Payload[0], fragsig1)
err2 = c.FragmentVerify(g.Payload[1], fragsig2)
} else {
// Try RSASig
rsaSig1, sigerr1 := crypto.RSASigFromString(g.Signature[0])
rsaSig2, sigerr2 := crypto.RSASigFromString(g.Signature[1])
// Verify the signatures were made successfully
if sigerr1 != nil || sigerr2 != nil {
err1 = c.Verify([]byte(g.Payload[0]), rsaSig1)
err2 = c.Verify([]byte(g.Payload[1]), rsaSig2)
}
if sigerr1 != nil || sigerr2 != nil {
err1 = c.Verify([]byte(g.Payload[0]), rsaSig1)
err2 = c.Verify([]byte(g.Payload[1]), rsaSig2)
}
}
if err1 == nil && err2 == nil {
return nil
} else {
return errors.New("Message Signature Mismatch" + fmt.Sprint(sigerr1) + fmt.Sprint(sigerr2))
}
}
if err1 == nil && err2 == nil {
return nil
} else {
//if signatures are the same, there are no conflicting information
return errors.New("This is not a valid gossip pom")
return errors.New("Message Signature Mismatch" + fmt.Sprint(sigerr1) + fmt.Sprint(sigerr2))
}
} else {
//type mislabeled
return errors.New("Gossip object label Mismatch")
//if signatures are the same, there are no conflicting information
return errors.New("This is not a valid gossip pom")
}

}
return errors.New("the input is not an gossip pom")
}
Expand Down
1 change: 0 additions & 1 deletion CTng/gossip/process_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func ProcessAccusation(c *GossiperContext, acc Gossip_object) {
fmt.Println(util.RED+"Generated POM for", acc.Payload[0], util.RESET)
c.StoreObject(*pom)
c.HasPom[acc.Payload[0]] = true
// We do not currently gossip PoMs.
SendToOwner(c, *pom)
}
}
6 changes: 3 additions & 3 deletions CTng/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func QueryLoggers(c *MonitorContext) {
sthResp, err := http.Get(PROTOCOL + logger + "/ctng/v2/get-sth/")
if err != nil {
log.Println(err)
// AccuseEntity(c, logger)
AccuseEntity(c, logger)
continue
}

Expand All @@ -35,13 +35,13 @@ func QueryLoggers(c *MonitorContext) {
err = json.Unmarshal(sthBody, &STH)
if err != nil {
log.Println(util.RED+err.Error(), util.RESET)
// AccuseEntity(c, logger)
AccuseEntity(c, logger)
continue
}
err = STH.Verify(c.Config.Crypto)
if err != nil {
log.Println(util.RED+"STH signature verification failed", err.Error(), util.RESET)
// AccuseEntity(c, logger)
AccuseEntity(c, logger)
} else {
Process_valid_object(c, STH)
}
Expand Down
6 changes: 4 additions & 2 deletions CTng/monitor/monitor_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ func Process_valid_object(c *MonitorContext, g gossip.Gossip_object) {
if IsLogger(c, g.Signer) && g.Type == gossip.STH {
Send_to_gossiper(c, g)
f := func() {
fmt.Println(util.BLUE, "Signing Revocation of", g.Signer, util.RESET)
sig_frag, err := c.Config.Crypto.ThresholdSign(g.Payload[0])
if err != nil {
fmt.Println(err.Error())
}
pom_err := Check_entity_pom(c, g.Signer)
//if there is no conflicting information/PoM send the Threshold signed version to the gossiper
if pom_err == false {
fmt.Println(util.BLUE, "Signing Revocation of", g.Signer, util.RESET)
g.Type = gossip.STH_FRAG
g.Signature[0] = sig_frag.String()
g.Signer = c.Config.Crypto.SelfID.String()
Send_to_gossiper(c, g)
} else {
fmt.Println(util.RED, "Conflicting information/PoM found, not sending STH_FRAG", util.RESET)
}

}
time.AfterFunc(time.Duration(c.Config.Public.Gossip_wait_time), f)
time.AfterFunc(time.Duration(c.Config.Public.Gossip_wait_time)*time.Second, f)
return
}
//if the object is from a CA, revocation information
Expand Down
3 changes: 2 additions & 1 deletion CTng/server/Monitor_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"CTng/gossip"
"CTng/monitor"
"CTng/util"
"encoding/json"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -143,7 +144,7 @@ func handle_gossip(c *monitor.MonitorContext, w http.ResponseWriter, r *http.Req
// Verify the object is valid.
err = gossip_obj.Verify(c.Config.Crypto)
if err != nil {
fmt.Println("Recieved invalid object from " + getSenderURL(r) + ".")
fmt.Println(util.RED+"Recieved invalid object from "+getSenderURL(r)+".", util.RESET)
monitor.AccuseEntity(c, gossip_obj.Signer)
http.Error(w, err.Error(), http.StatusOK)
return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Crypto_config_path": "testData/monitorNetworkTest/2/monitorCrypto.json",
"CA_URLs": ["localhost:9101", "localhost:9102"],
"CA_URLs": ["localhost:9102"],
"Logger_URLs": ["localhost:9001", "localhost:9002"],
"Gossiper_URL": "localhost:8081",
"Port": "8181"
Expand Down
4 changes: 2 additions & 2 deletions CTng/testData/monitorNetworkTest/3/monitor_priv_config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Crypto_config_path": "testData/monitorNetworkTest/3/monitorCrypto.json",
"CA_URLs": ["localhost:9102", "localhost:9103"],
"Logger_URLs": ["localhost:9002", "localhost:9003"],
"CA_URLs": ["localhost:9100", "localhost:9102"],
"Logger_URLs": ["localhost:9000", "localhost:9002"],
"Gossiper_URL": "localhost:8082",
"Port": "8182"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Crypto_config_path": "testData/monitorNetworkTest/4/monitorCrypto.json",
"CA_URLs": ["localhost:9100", "localhost:9101"],
"CA_URLs": ["localhost:9102", "localhost:9101"],
"Logger_URLs": ["localhost:9001"],
"Gossiper_URL": "localhost:8083",
"Port": "8183"
Expand Down

0 comments on commit b40046e

Please sign in to comment.