Commit 7fda94e9 authored by Richer Maximilien's avatar Richer Maximilien Committed by Loïck Bonniot

[c] Implement evidences reception and emission

parent 525d85ce
......@@ -36,11 +36,16 @@ const _ = proto.ProtoPackageIsVersion1
// Promise message contains all the required information to verify
// the identity of the sender and reciever, and the actual promise
//
// * sequence is transmitted by platform and identical across clients
// * TODO implement an global signature for content
type Promise struct {
RecipientKeyHash []byte `protobuf:"bytes,1,opt,name=recipientKeyHash,proto3" json:"recipientKeyHash,omitempty"`
SenderKeyHash []byte `protobuf:"bytes,2,opt,name=senderKeyHash,proto3" json:"senderKeyHash,omitempty"`
SignatureUuid string `protobuf:"bytes,3,opt,name=signatureUuid" json:"signatureUuid,omitempty"`
ContractUuid string `protobuf:"bytes,4,opt,name=contractUuid" json:"contractUuid,omitempty"`
RecipientKeyHash []byte `protobuf:"bytes,1,opt,name=recipientKeyHash,proto3" json:"recipientKeyHash,omitempty"`
SenderKeyHash []byte `protobuf:"bytes,2,opt,name=senderKeyHash,proto3" json:"senderKeyHash,omitempty"`
Index uint32 `protobuf:"varint,3,opt,name=index" json:"index,omitempty"`
ContractDocumentHash string `protobuf:"bytes,4,opt,name=contractDocumentHash" json:"contractDocumentHash,omitempty"`
SignatureUuid string `protobuf:"bytes,5,opt,name=signatureUuid" json:"signatureUuid,omitempty"`
ContractUuid string `protobuf:"bytes,6,opt,name=contractUuid" json:"contractUuid,omitempty"`
}
func (m *Promise) Reset() { *m = Promise{} }
......@@ -63,7 +68,8 @@ func (m *Signature) String() string { return proto.CompactTextString(
func (*Signature) ProtoMessage() {}
func (*Signature) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
// Hello message is used when discovering peers. It contains the current version of the software.
// Hello message is used when discovering peers.
// It contains the current version of the software.
type Hello struct {
Version string `protobuf:"bytes,1,opt,name=version" json:"version,omitempty"`
}
......@@ -199,24 +205,24 @@ var _Client_serviceDesc = grpc.ServiceDesc{
}
var fileDescriptor0 = []byte{
// 302 bytes of a gzipped FileDescriptorProto
0x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11, 0x35, 0xae, 0x75, 0x2e, 0x93,
0x11, 0x5b, 0xc1, 0x82, 0xf4, 0x3f, 0xef, 0xda, 0x6b, 0x7a, 0x3c, 0xd0, 0x73, 0x01, 0xff, 0x37,
0xca, 0x08, 0xed, 0x42, 0x30, 0xa0, 0x2a, 0xe5, 0x8a, 0x7f, 0xdd, 0x93, 0xd1, 0xe3, 0x8c, 0xbe,
0xf2, 0xea, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x2d, 0x9f, 0xc1, 0xc3, 0x0d, 0x02, 0x00, 0x00,
}
......@@ -12,11 +12,17 @@ service Client {
// Promise message contains all the required information to verify
// the identity of the sender and reciever, and the actual promise
//
// * sequence is transmitted by platform and identical across clients
// * TODO implement an global signature for content
message Promise {
bytes recipientKeyHash = 1; // SHA-512
bytes senderKeyHash = 2; // SHA-512
string signatureUuid = 3;
string contractUuid = 4;
bytes recipientKeyHash = 1; // SHA-512
bytes senderKeyHash = 2; // SHA-512
uint32 index = 3; // The index of the sequence for this message
string contractDocumentHash = 4; // Hash of the contract to be signed
string signatureUuid = 5; // Avoid re-use of the promise in another ctx
string contractUuid = 6;
// TODO the crypto payload
}
// Signature message contains all the required information to verify
......@@ -29,7 +35,8 @@ message Signature {
string contractUuid = 5;
}
// Hello message is used when discovering peers. It contains the current version of the software.
// Hello message is used when discovering peers.
// It contains the current version of the software.
message Hello {
string version = 1;
}
package sign
import (
"errors"
"fmt"
"time"
cAPI "dfss/dfssc/api"
dAPI "dfss/dfssd/api"
pAPI "dfss/dfssp/api"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
// CreatePromise creates a promise from 'from' to 'to', in the context of the SignatureManager
// provided the specified sequence indexes are valid
func (m *SignatureManager) CreatePromise(from, to uint32) (*cAPI.Promise, error) {
if int(from) >= len(m.keyHash) || int(to) >= len(m.keyHash) {
return nil, errors.New("Invalid id for promise creation")
}
if m.currentIndex < 0 {
return nil, errors.New("Invalid currentIndex for promise creation")
}
promise := &cAPI.Promise{
RecipientKeyHash: m.keyHash[to],
SenderKeyHash: m.keyHash[from],
Index: uint32(m.currentIndex),
ContractDocumentHash: m.contract.File.Hash,
SignatureUuid: m.uuid,
ContractUuid: m.contract.UUID,
}
return promise, nil
}
// SendPromise sends the specified promise to the specified peer
func (m *SignatureManager) SendPromise(promise *cAPI.Promise, to uint32) (*pAPI.ErrorCode, error) {
connection, err := m.GetClient(to)
if err != nil {
return &pAPI.ErrorCode{}, err
}
// Handle the timeout
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
errCode, err := (*connection).TreatPromise(ctx, promise)
if err == grpc.ErrClientConnTimeout {
dAPI.DLog("Promise timeout for [" + fmt.Sprintf("%d", to) + "]")
return &pAPI.ErrorCode{Code: pAPI.ErrorCode_TIMEOUT, Message: "promise timeout"}, err
} else if err != nil {
return &pAPI.ErrorCode{Code: pAPI.ErrorCode_INTERR, Message: "internal server error"}, err
}
m.archives.sentPromises = append(m.archives.sentPromises, promise)
return errCode, nil
}
package sign
import (
"errors"
"fmt"
"time"
cAPI "dfss/dfssc/api"
"dfss/dfssc/common"
dAPI "dfss/dfssd/api"
pAPI "dfss/dfssp/api"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
// Sign makes the SignatureManager perform its specified signature
var (
hashToID map[string]uint32
incomingPromises chan *cAPI.Promise
incomingSignatures chan *cAPI.Signature
)
// Sign performe all the message exchange for the contract to be signed
//
// * Initialize the SignatureManager from starter.go
// * Compute the reversed map [mail -> ID] of signers
// * Make channels for handlers
// * Promises rounds
// * Signature round
func (m *SignatureManager) Sign() error {
myID, currentIndex, nextIndex, err := m.Initialize()
myID, nextIndex, err := m.Initialize()
if err != nil {
return err
}
hashToID = m.makeSignersHashToIDMap()
incomingPromises = make(chan *cAPI.Promise)
incomingSignatures = make(chan *cAPI.Signature)
// Promess rounds
for nextIndex != -1 {
pendingSet, err1 := common.GetPendingSet(m.sequence, myID, currentIndex)
// Follow the sequence until there is no next occurence of me
for nextIndex > 0 {
// Set of the promise we are waiting for
pendingSet, err1 := common.GetPendingSet(m.sequence, myID, m.currentIndex)
if err1 != nil {
return err1 // err is renamed to avoid shadowing err on linter check
}
sendSet, err1 := common.GetSendSet(m.sequence, myID, currentIndex)
// Set of the promises we must send
sendSet, err1 := common.GetSendSet(m.sequence, myID, m.currentIndex)
if err1 != nil {
return err1
}
// Reception of the due promesses
for len(pendingSet) != 0 {
i := 0
// TODO
// Improve, because potential memory leak
// see https://github.com/golang/go/wiki/SliceTricks
pendingSet = append(pendingSet[:i], pendingSet[i+1:]...)
}
c := make(chan int)
// Sending of the due promesses
/*
for _, id := range sendSet {
go func(id) {
promise, err := m.CreatePromise(id)
recpt := m.SendPromise(promise, id)
c <- id
}(id)
}
*/
// Verifying we sent all the due promesses
for _ = range sendSet {
<-c
}
// Exchange messages
m.promiseRound(pendingSet, sendSet, myID)
currentIndex = nextIndex
nextIndex, err1 = common.FindNextIndex(m.sequence, myID, currentIndex)
m.currentIndex = nextIndex
nextIndex, err1 = common.FindNextIndex(m.sequence, myID, m.currentIndex)
if err1 != nil {
return err1
}
......@@ -78,46 +71,6 @@ func (m *SignatureManager) Sign() error {
return nil
}
// CreatePromise creates a promise from 'from' to 'to', in the context of the SignatureManager
// provided the specified sequence indexes are valid
func (m *SignatureManager) CreatePromise(from, to uint32) (*cAPI.Promise, error) {
if int(from) >= len(m.keyHash) || int(to) >= len(m.keyHash) {
return &cAPI.Promise{}, errors.New("Invalid id for promise creation")
}
promise := &cAPI.Promise{
RecipientKeyHash: m.keyHash[to],
SenderKeyHash: m.keyHash[from],
SignatureUuid: m.uuid,
ContractUuid: m.contract.UUID,
}
return promise, nil
}
// SendPromise sends the specified promise to the specified peer
// TODO
func (m *SignatureManager) SendPromise(promise *cAPI.Promise, to uint32) (*pAPI.ErrorCode, error) {
connection, err := m.GetClient(to)
if err != nil {
return &pAPI.ErrorCode{}, err
}
// Handle the timeout
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
errCode, err := (*connection).TreatPromise(ctx, promise)
if err == grpc.ErrClientConnTimeout {
dAPI.DLog("Promise timeout for [" + fmt.Sprintf("%d", to) + "]")
return &pAPI.ErrorCode{Code: pAPI.ErrorCode_TIMEOUT, Message: "promise timeout"}, err
} else if err != nil {
return &pAPI.ErrorCode{Code: pAPI.ErrorCode_INTERR, Message: "internal server error"}, err
}
m.archives.sentPromises = append(m.archives.sentPromises, promise)
return errCode, nil
}
// GetClient retrieves the Client to the specified sequence id provided it exists
func (m *SignatureManager) GetClient(to uint32) (*cAPI.ClientClient, error) {
mailto := m.contract.Signers[to].Email
......@@ -129,75 +82,61 @@ func (m *SignatureManager) GetClient(to uint32) (*cAPI.ClientClient, error) {
return m.peers[mailto], nil
}
// SendAllSigns creates and sends signatures to all the signers of the contract
// TODO
// Use goroutines to send in parallel
func (m *SignatureManager) SendAllSigns() error {
myID, err := m.FindID()
if err != nil {
return err
}
// makeEMailMap build an association to reverse a hash to the sequence ID
func (m *SignatureManager) makeSignersHashToIDMap() map[string]uint32 {
sendSet := common.GetAllButOne(m.sequence, myID)
for _, id := range sendSet {
signature, err := m.CreateSignature(myID, id)
if err != nil {
return err
}
hashToID := make(map[string]uint32)
_, err = m.SendSignature(signature, id)
if err != nil {
return err
}
signers := m.contract.Signers
for id, signer := range signers {
hashToID[signer.Hash] = uint32(id)
}
return nil
return hashToID
}
// CreateSignature creates a signature from from to to, in the context of the SignatureManager
// provided the specified sequence indexes are valid
// TODO
// Implement a true cryptographic signature
func (m *SignatureManager) CreateSignature(from, to uint32) (*cAPI.Signature, error) {
if int(from) >= len(m.keyHash) || int(to) >= len(m.keyHash) {
return &cAPI.Signature{}, errors.New("Invalid id for signature creation")
}
signature := &cAPI.Signature{
RecipientKeyHash: m.keyHash[to],
SenderKeyHash: m.keyHash[from],
Signature: "Signature",
SignatureUuid: m.uuid,
ContractUuid: m.contract.UUID,
func (m *SignatureManager) promiseRound(pendingSet, sendSet []uint32, myID uint32) {
// Reception of the due promises
// TODO this ctx needs a timeout !
for len(pendingSet) > 0 {
promise := <-incomingPromises
senderID, exist := hashToID[string(promise.SenderKeyHash)]
if exist {
var err error
pendingSet, err = common.Remove(pendingSet, senderID)
if err != nil {
// Recieve unexpected promise, ignore ?
}
m.archives.recievedPromises = append(m.archives.recievedPromises, promise)
} else {
// Wrong sender keyHash
}
}
return signature, nil
}
// SendSignature sends the specified signature to the specified peer
// TODO
func (m *SignatureManager) SendSignature(signature *cAPI.Signature, to uint32) (*pAPI.ErrorCode, error) {
connection, err := m.GetClient(to)
if err != nil {
return &pAPI.ErrorCode{}, err
c := make(chan *cAPI.Promise)
// Sending of due promises
for _, id := range sendSet {
// The signature manager is read only - safe !
go func(id uint32, m *SignatureManager) {
promise, err := m.CreatePromise(myID, id)
if err != nil {
// Failed to create promise
}
_, err = m.SendPromise(promise, id)
if err != nil {
// We don't check if the promise has been recieved
}
c <- promise
}(id, m)
}
// TODO
// Handle the timeout
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
errCode, err := (*connection).TreatSignature(ctx, signature)
if err != nil {
return &pAPI.ErrorCode{}, err
// Verifying we sent all the due promesses
for _ = range sendSet {
promise := <-c
if promise != nil {
m.archives.sentPromises = append(m.archives.sentPromises, promise)
} else {
// something appened during the goroutine
}
}
m.archives.sentSignatures = append(m.archives.sentSignatures, signature)
return errCode, nil
}
// RecieveAllSigns is not done yet
// TODO
func (m *SignatureManager) RecieveAllSigns() error {
return nil
}
......@@ -15,7 +15,11 @@ type clientServer struct{}
//
// Handle incoming TreatPromise messages
func (s *clientServer) TreatPromise(ctx context.Context, in *cAPI.Promise) (*pAPI.ErrorCode, error) {
// TODO
// Pass the message to Sign()
if incomingPromises != nil {
incomingPromises <- in
}
return nil, nil
}
......
package sign
import (
"dfss/dfssc/common"
"errors"
"fmt"
"time"
cAPI "dfss/dfssc/api"
dAPI "dfss/dfssd/api"
pAPI "dfss/dfssp/api"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
// SendAllSigns creates and sends signatures to all the signers of the contract
// TODO Use goroutines to send in parallel
func (m *SignatureManager) SendAllSigns() error {
myID, err := m.FindID()
if err != nil {
return err
}
// compute a set of all signers exept me
sendSet := common.GetAllButOne(m.sequence, myID)
for _, id := range sendSet {
signature, err := m.CreateSignature(myID, id)
if err != nil {
return err
}
_, err = m.SendSignature(signature, id)
if err != nil {
return err
}
}
return nil
}
// CreateSignature creates a signature from a sequence ID to another
// provided the specified sequence indexes are valid
// TODO Implement a true cryptographic signature
func (m *SignatureManager) CreateSignature(from, to uint32) (*cAPI.Signature, error) {
if int(from) >= len(m.keyHash) || int(to) >= len(m.keyHash) {
return &cAPI.Signature{}, errors.New("Invalid id for signature creation")
}
signature := &cAPI.Signature{
RecipientKeyHash: m.keyHash[to],
SenderKeyHash: m.keyHash[from],
Signature: "Signature",
SignatureUuid: m.uuid,
ContractUuid: m.contract.UUID,
}
return signature, nil
}
// SendSignature sends the specified signature to the specified peer
func (m *SignatureManager) SendSignature(signature *cAPI.Signature, to uint32) (*pAPI.ErrorCode, error) {
connection, err := m.GetClient(to)
if err != nil {
return &pAPI.ErrorCode{}, err
}
// Handle the timeout
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
errCode, err := (*connection).TreatSignature(ctx, signature)
if err == grpc.ErrClientConnTimeout {
dAPI.DLog("Signature timeout for [" + fmt.Sprintf("%d", to) + "]")
return &pAPI.ErrorCode{Code: pAPI.ErrorCode_TIMEOUT, Message: "signature timeout"}, err
} else if err != nil {
return &pAPI.ErrorCode{Code: pAPI.ErrorCode_INTERR, Message: "internal server error"}, err
}
m.archives.sentSignatures = append(m.archives.sentSignatures, signature)
return errCode, nil
}
// RecieveAllSigns is not done yet
func (m *SignatureManager) RecieveAllSigns() error {
myID, err := m.FindID()
if err != nil {
return err
}
// compute a set of all signers exept me
pendingSet := common.GetAllButOne(m.sequence, myID)
// TODO this ctx needs a timeout !
for len(pendingSet) > 0 {
signature := <-incomingSignatures
senderID, exist := hashToID[string(signature.SenderKeyHash)]
if exist {
var err error
pendingSet, err = common.Remove(pendingSet, senderID)
if err != nil {
// Recieve unexpected signature, ignore ?
}
m.archives.recievedSignatures = append(m.archives.recievedSignatures, signature)
} else {
// Wrong sender keyHash
}
}
return nil
}
......@@ -20,18 +20,19 @@ import (
// SignatureManager handles the signature of a contract.
type SignatureManager struct {
auth *security.AuthContainer
localPort int
contract *contract.JSON
platform pAPI.PlatformClient
peers map[string]*cAPI.ClientClient
nbReady int
cServer *grpc.Server
sequence []uint32
uuid string
keyHash [][]byte
mail string
archives *Archives
auth *security.AuthContainer
localPort int
contract *contract.JSON // contains the contractUUID, the list of the signers' hashes, the hash of the contract
platform pAPI.PlatformClient
peers map[string]*cAPI.ClientClient
nbReady int
cServer *grpc.Server
sequence []uint32
currentIndex int
uuid string
keyHash [][]byte
mail string
archives *Archives
}
// Archives stores the recieved and sent messages, as evidence if needed
......@@ -197,23 +198,23 @@ func (m *SignatureManager) SendReadySign() (signatureUUID string, err error) {
}
// Initialize computes the values needed for the start of the signing
func (m *SignatureManager) Initialize() (uint32, int, int, error) {
func (m *SignatureManager) Initialize() (uint32, int, error) {
myID, err := m.FindID()
if err != nil {
return 0, 0, 0, err
return 0, 0, err
}
currentIndex, err := common.FindNextIndex(m.sequence, myID, -1)
m.currentIndex, err = common.FindNextIndex(m.sequence, myID, -1)
if err != nil {
return 0, 0, 0, err
return 0, 0, err
}
nextIndex, err := common.FindNextIndex(m.sequence, myID, currentIndex)
nextIndex, err := common.FindNextIndex(m.sequence, myID, m.currentIndex)
if err != nil {
return 0, 0, 0, err
return 0, 0, err
}
return myID, currentIndex, nextIndex, nil
return myID, nextIndex, nil
}
// FindID finds the sequence id for the user's email and the contract to sign
......
......@@ -132,16 +132,15 @@ var _Demonstrator_serviceDesc = grpc.ServiceDesc{
}
var fileDescriptor0 = []byte{
// 167 bytes of a gzipped FileDescriptorProto
// 159 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0x4c, 0x49, 0x2b, 0x2e,
0xd6, 0x07, 0x11, 0x29, 0xfa, 0x89, 0x05, 0x99, 0xfa, 0x29, 0xa9, 0xb9, 0xf9, 0x79, 0xc5, 0x25,
0x45, 0x89, 0x25, 0xf9, 0x45, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xcc, 0x40, 0x71, 0xa5,
0x50, 0x2e, 0x66, 0x9f, 0xfc, 0x74, 0x21, 0x19, 0x2e, 0xce, 0x92, 0xcc, 0xdc, 0xd4, 0xe2, 0x92,
0xc4, 0xdc, 0x02, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xe6, 0x20, 0x84, 0x80, 0x90, 0x1c, 0x17, 0x57,
0x66, 0x4a, 0x6a, 0x5e, 0x49, 0x66, 0x5a, 0x66, 0x6a, 0x91, 0x04, 0x13, 0x50, 0x9a, 0x33, 0x08,
0x49, 0x44, 0x48, 0x80, 0x8b, 0x39, 0x27, 0x3f, 0x5d, 0x82, 0x19, 0x2c, 0x01, 0x62, 0x2a, 0xb1,
0x72, 0x31, 0x3b, 0x26, 0x67, 0x1b, 0xe9, 0x73, 0xf1, 0xb8, 0x20, 0x59, 0x2c, 0x24, 0xcf, 0xc5,
0x1e, 0x9c, 0x9a, 0x97, 0x02, 0xb2, 0x91, 0x43, 0x0f, 0x68, 0xbd, 0x1e, 0x90, 0x25, 0x05, 0x61,
0x01, 0x95, 0x2b, 0x31, 0x24, 0xb1, 0x81, 0x9d, 0x66, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xc3,
0xc3, 0x86, 0x7b, 0xbf, 0x00, 0x00, 0x00,
0x45, 0x89, 0x25, 0xf9, 0x45, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xcc, 0x40, 0x71, 0x25,
0x4b, 0x2e, 0x66, 0x9f, 0xfc, 0x74, 0x21, 0x41, 0x2e, 0xce, 0x92, 0xcc, 0xdc, 0xd4, 0xe2, 0x92,
0xc4, 0xdc, 0x02, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x66, 0x21, 0x21, 0x2e, 0xae, 0xcc, 0x94, 0xd4,
0xbc, 0x92, 0xcc, 0xb4, 0xcc, 0xd4, 0x22, 0x09, 0x26, 0xa0, 0x18, 0xa7, 0x10, 0x37, 0x17, 0x73,
0x4e, 0x7e, 0xba, 0x04, 0x33, 0x88, 0xa3, 0xc4, 0xca, 0xc5, 0xec, 0x98, 0x9c, 0x6d, 0xa4, 0xcf,
0xc5, 0xe3, 0x82, 0x64, 0xb8, 0x90, 0x3c, 0x17, 0x7b, 0x70, 0x6a, 0x5e, 0x0a, 0xc8, 0x54, 0x0e,
0x3d, 0xa0, 0x15, 0x7a, 0x40, 0x96, 0x14, 0x84, 0x05, 0x54, 0xae, 0xc4, 0x90, 0xc4, 0x06, 0xb6,
0xde, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x16, 0xf4, 0xd0, 0x37, 0xa3, 0x00, 0x00, 0x00,
}
......@@ -56,6 +56,8 @@ const (
ErrorCode_WARNING ErrorCode_Code = 3
// INTERR is the error code for an internal server error
ErrorCode_INTERR ErrorCode_Code = -1
// TIMEOUT is the error code for a timeout or unreacheable target
ErrorCode_TIMEOUT ErrorCode_Code = -2
)
var ErrorCode_Code_name = map[int32]string{
......@@ -64,6 +66,7 @@ var ErrorCode_Code_name = map[int32]string{
2: "BADAUTH",
3: "WARNING",
-1: "INTERR",
-2: "TIMEOUT",
}
var ErrorCode_Code_value = map[string]int32{
"SUCCESS": 0,
......@@ -71,6 +74,7 @@ var ErrorCode_Code_value = map[string]int32{
"BADAUTH": 2,
"WARNING": 3,
"INTERR": -1,
"TIMEOUT": -2,
}
func (x ErrorCode_Code) String() string {
......@@ -90,8 +94,9 @@ func (m *RegisterRequest) String() string { return proto.CompactTextS
func (*RegisterRequest) ProtoMessage()