|
@@ -406,71 +406,8 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
panic(err)
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
|
|
- //auditing starts here
|
|
|
|
-
|
|
|
|
- //generate seed
|
|
|
|
- var seed [16]byte
|
|
|
|
- _, err = rand.Read(seed[:])
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //send seed to client
|
|
|
|
- _, err = clientConnection.Write(seed[:])
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //send seed to follower
|
|
|
|
- _, err = followerConnection.Write(seed[:])
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //receive proofs
|
|
|
|
- auditLengthBytes := make([]byte, 4)
|
|
|
|
-
|
|
|
|
- _, err = clientConnection.Read(auditLengthBytes)
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- auditLength := byteToInt(auditLengthBytes)
|
|
|
|
-
|
|
|
|
- clientAuditA := make([]byte, auditLength)
|
|
|
|
- clientAuditB := make([]byte, auditLength)
|
|
|
|
-
|
|
|
|
- _, err = clientConnection.Read(clientAuditA)
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _, err = clientConnection.Read(clientAuditB)
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //send client audit to follower
|
|
|
|
- _, err = followerConnection.Write(auditLengthBytes)
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _, err = followerConnection.Write(clientAuditB)
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //decrypts the client audit
|
|
|
|
- var decryptNonce [24]byte
|
|
|
|
- copy(decryptNonce[:], clientAuditA[:24])
|
|
|
|
-
|
|
|
|
- clientAuditA, ok := box.Open(nil, clientAuditA[24:], &decryptNonce, clientPublicKey, leaderPrivateKey)
|
|
|
|
- if !ok {
|
|
|
|
- panic("clientAudit decryption not ok")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//decrypt dpfQueryA for sorting into db
|
|
//decrypt dpfQueryA for sorting into db
|
|
|
|
+ var decryptNonce [24]byte
|
|
copy(decryptNonce[:], dpfQueryAEncrypted[:24])
|
|
copy(decryptNonce[:], dpfQueryAEncrypted[:24])
|
|
dpfQueryA, ok := box.Open(nil, dpfQueryAEncrypted[24:], &decryptNonce, clientPublicKey, leaderPrivateKey)
|
|
dpfQueryA, ok := box.Open(nil, dpfQueryAEncrypted[24:], &decryptNonce, clientPublicKey, leaderPrivateKey)
|
|
if !ok {
|
|
if !ok {
|
|
@@ -491,69 +428,6 @@ func phase1(id int, phase []byte, followerConnection net.Conn, wg *sync.WaitGrou
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- //prepare for audit
|
|
|
|
- mVal := make([]byte, 16)
|
|
|
|
- cVal := make([]byte, 16)
|
|
|
|
- C.serverSetupProof(C.ctx[id], (*C.uchar)(&seed[0]), C.dbSize, (*C.uchar)(&vector[0]), (*C.uchar)(&mVal[0]), (*C.uchar)(&cVal[0]))
|
|
|
|
-
|
|
|
|
- //compute audit query
|
|
|
|
- auditResultA := make([]byte, 96)
|
|
|
|
- C.serverComputeQuery(C.ctx[id], (*C.uchar)(&seed[0]), (*C.uchar)(&mVal[0]), (*C.uchar)(&cVal[0]), (*C.uchar)(&clientAuditA[0]), (*C.uchar)(&auditResultA[0]))
|
|
|
|
-
|
|
|
|
- //encrypt leader audit result
|
|
|
|
- var nonce [24]byte
|
|
|
|
- //fill nonce with randomness
|
|
|
|
- _, err = rand.Read(nonce[:])
|
|
|
|
- if err != nil {
|
|
|
|
- panic("couldn't get randomness for nonce!")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- auditResultAEncrypted := box.Seal(nonce[:], auditResultA, &nonce, followerPublicKey, leaderPrivateKey)
|
|
|
|
-
|
|
|
|
- encryptedAuditResultALengthBytes := intToByte(len(auditResultAEncrypted))
|
|
|
|
-
|
|
|
|
- //send audit result to follower
|
|
|
|
- _, err = followerConnection.Write(encryptedAuditResultALengthBytes)
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _, err = followerConnection.Write(auditResultAEncrypted)
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //receive follower audit result
|
|
|
|
- auditResultBEncryptedLengthBytes := make([]byte, 4)
|
|
|
|
- _, err = followerConnection.Read(auditResultBEncryptedLengthBytes)
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
- auditResultBEncryptedLength := byteToInt(auditResultBEncryptedLengthBytes)
|
|
|
|
-
|
|
|
|
- auditResultBEncrypted := make([]byte, auditResultBEncryptedLength)
|
|
|
|
- _, err = followerConnection.Read(auditResultBEncrypted)
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //decrypts the audit result from follower
|
|
|
|
- copy(decryptNonce[:], auditResultBEncrypted[:24])
|
|
|
|
- auditResultB, ok := box.Open(nil, auditResultBEncrypted[24:], &decryptNonce, followerPublicKey, leaderPrivateKey)
|
|
|
|
- if !ok {
|
|
|
|
- panic("auditResultB decryption not ok")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //compute audit result
|
|
|
|
- auditResult := int(C.serverVerifyProof((*C.uchar)(&auditResultA[0]), (*C.uchar)(&auditResultB[0])))
|
|
|
|
-
|
|
|
|
- if byteToInt(auditResultB) == 0 || auditResult == 0 {
|
|
|
|
- //fmt.Println("audit failed")
|
|
|
|
- } /*else {
|
|
|
|
- fmt.Println("audit passed")
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
//xor the worker's DB into the main DB
|
|
//xor the worker's DB into the main DB
|
|
for i := 0; i < dbSize; i++ {
|
|
for i := 0; i < dbSize; i++ {
|
|
m.Lock()
|
|
m.Lock()
|