Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpcs
dfss
Commits
04f4dc70
Commit
04f4dc70
authored
Apr 17, 2016
by
Loïck Bonniot
Browse files
[t] Improve code-style and fix linter
parent
72c5ddd3
Pipeline
#677
passed with stage
Changes
12
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
04f4dc70
...
...
@@ -36,8 +36,6 @@ Unit tests:
-
"
go
test
-coverprofile
dfssc_security.part
-v
dfss/dfssc/security"
-
"
go
test
-coverprofile
dfssc_user.part
-v
dfss/dfssc/user"
-
"
go
test
-coverprofile
dfssc_user.part
-v
dfss/dfssc/sign"
-
"
go
test
-coverprofile
dfsst_archivesManager.part
-v
dfss/dfsst/archivesManager"
-
"
go
test
-coverprofile
dfsst_checker.part
-v
dfss/dfsst/checker"
-
"
go
test
-coverprofile
dfsst_entities.part
-v
dfss/dfsst/entities"
-
"
go
test
-coverprofile
dfsst_resolve.part
-v
dfss/dfsst/resolve"
-
"
go
test
-coverprofile
dfsst_server.part
-v
dfss/dfsst/server"
...
...
dfsst/
archivesManager
/archivesManager.go
→
dfsst/
entities
/archivesManager.go
View file @
04f4dc70
package
archivesManager
package
entities
import
(
cAPI
"dfss/dfssc/api"
"dfss/dfsst/entities"
"dfss/mgdb"
"gopkg.in/mgo.v2/bson"
)
...
...
@@ -10,7 +9,7 @@ import (
// ArchivesManager : handles the structure of a SignatureArchives, with functions suited for the TTP resolve protocol.
type
ArchivesManager
struct
{
DB
*
mgdb
.
MongoManager
Archives
*
entities
.
SignatureArchives
Archives
*
SignatureArchives
}
// NewArchivesManager : create a new archivesManager, with the specified mgdb manager, but
...
...
@@ -24,11 +23,11 @@ func NewArchivesManager(db *mgdb.MongoManager) *ArchivesManager {
// InitializeArchives : if an entry in the database for this signature exists, retrieves it, otherwise creates it.
//
// This function should only be called after function IsRequestValid.
func
(
manager
*
ArchivesManager
)
InitializeArchives
(
promise
*
cAPI
.
Promise
,
signatureUUID
bson
.
ObjectId
,
signers
*
[]
entities
.
Signer
)
{
func
(
manager
*
ArchivesManager
)
InitializeArchives
(
promise
*
cAPI
.
Promise
,
signatureUUID
bson
.
ObjectId
,
signers
*
[]
Signer
)
{
present
,
archives
:=
manager
.
ContainsSignature
(
signatureUUID
)
if
!
present
{
archives
=
entities
.
NewSignatureArchives
(
signatureUUID
,
promise
.
Context
.
Sequence
,
*
signers
,
promise
.
Context
.
ContractDocumentHash
,
promise
.
Context
.
SignedHash
)
archives
=
NewSignatureArchives
(
signatureUUID
,
promise
.
Context
.
Sequence
,
*
signers
,
promise
.
Context
.
ContractDocumentHash
,
promise
.
Context
.
SignedHash
)
}
manager
.
Archives
=
archives
...
...
@@ -36,11 +35,11 @@ func (manager *ArchivesManager) InitializeArchives(promise *cAPI.Promise, signat
// ContainsSignature : checks if the specified signatureUUID matches a SignatureArchives in the database.
// If it exists, returns it.
func
(
manager
*
ArchivesManager
)
ContainsSignature
(
signatureUUID
bson
.
ObjectId
)
(
present
bool
,
archives
*
entities
.
SignatureArchives
)
{
err
:=
manager
.
DB
.
Get
(
"signatures"
)
.
FindByID
(
entities
.
SignatureArchives
{
ID
:
signatureUUID
},
&
archives
)
func
(
manager
*
ArchivesManager
)
ContainsSignature
(
signatureUUID
bson
.
ObjectId
)
(
present
bool
,
archives
*
SignatureArchives
)
{
err
:=
manager
.
DB
.
Get
(
"signatures"
)
.
FindByID
(
SignatureArchives
{
ID
:
signatureUUID
},
&
archives
)
if
err
!=
nil
{
present
=
false
archives
=
&
entities
.
SignatureArchives
{}
archives
=
&
SignatureArchives
{}
return
}
...
...
@@ -93,7 +92,7 @@ func (manager *ArchivesManager) AddToAbort(signerIndex uint32) {
// This requires the implementation of promises
var
abortIndex
uint32
abortIndex
=
0
abortedSigner
:=
entities
.
NewAbortedSigner
(
signerIndex
,
abortIndex
)
abortedSigner
:=
NewAbortedSigner
(
signerIndex
,
abortIndex
)
manager
.
Archives
.
AbortedSigners
=
append
(
manager
.
Archives
.
AbortedSigners
,
*
abortedSigner
)
}
...
...
@@ -111,9 +110,9 @@ func (manager *ArchivesManager) AddToDishonest(signerIndex uint32) {
}
// AddPromise : adds the specified promises to the list of received promises of the SignatureArchives.
func
(
manager
*
ArchivesManager
)
AddPromise
(
promise
*
entities
.
Promise
)
{
func
(
manager
*
ArchivesManager
)
AddPromise
(
promise
*
Promise
)
{
for
_
,
p
:=
range
manager
.
Archives
.
ReceivedPromises
{
if
entities
.
ArePromisesEqual
(
&
p
,
promise
)
{
if
ArePromisesEqual
(
&
p
,
promise
)
{
return
}
}
...
...
dfsst/
archivesManager
/archivesManager_test.go
→
dfsst/
entities
/archivesManager_test.go
View file @
04f4dc70
package
archivesManager
package
entities
import
(
"fmt"
"os"
"testing"
"crypto/sha512"
cAPI
"dfss/dfssc/api"
"dfss/dfsst/checker"
"dfss/dfsst/entities"
"dfss/mgdb"
"fmt"
"github.com/bmizerany/assert"
"gopkg.in/mgo.v2/bson"
"os"
"testing"
)
var
(
...
...
@@ -26,7 +25,7 @@ var (
signedHash
[]
byte
signersEntities
[]
entities
.
Signer
signersEntities
[]
Signer
err
error
)
...
...
@@ -51,9 +50,9 @@ func init() {
signedHash
=
[]
byte
{}
signersEntities
=
make
([]
entities
.
Signer
,
0
)
signersEntities
=
make
([]
Signer
,
0
)
for
_
,
s
:=
range
signers
{
signerEntity
:=
entities
.
NewSigner
(
s
)
signerEntity
:=
NewSigner
(
s
)
signersEntities
=
append
(
signersEntities
,
*
signerEntity
)
}
}
...
...
@@ -89,12 +88,12 @@ func TestInitializeArchives(t *testing.T) {
SignedHash
:
signedHash
,
},
}
archives
:=
entities
.
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
archives
:=
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
manager
:=
&
ArchivesManager
{
DB
:
dbManager
,
Archives
:
archives
,
}
arch
:=
entities
.
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
arch
:=
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
manager
.
InitializeArchives
(
promise
,
signatureUUIDBson
,
&
signersEntities
)
arch
.
Signers
=
manager
.
Archives
.
Signers
...
...
@@ -103,7 +102,7 @@ func TestInitializeArchives(t *testing.T) {
ok
,
err
:=
collection
.
Insert
(
manager
.
Archives
)
assert
.
Equal
(
t
,
ok
,
true
)
assert
.
Equal
(
t
,
err
,
nil
)
manager
.
Archives
=
&
entities
.
SignatureArchives
{}
manager
.
Archives
=
&
SignatureArchives
{}
manager
.
InitializeArchives
(
promise
,
signatureUUIDBson
,
&
signersEntities
)
assert
.
Equal
(
t
,
err
,
nil
)
...
...
@@ -115,7 +114,7 @@ func TestInitializeArchives(t *testing.T) {
}
func
TestContainsSignature
(
t
*
testing
.
T
)
{
archives
:=
entities
.
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
archives
:=
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
manager
:=
&
ArchivesManager
{
DB
:
dbManager
,
Archives
:
archives
,
...
...
@@ -123,7 +122,7 @@ func TestContainsSignature(t *testing.T) {
b
,
arch
:=
manager
.
ContainsSignature
(
signatureUUIDBson
)
assert
.
Equal
(
t
,
b
,
false
)
assert
.
Equal
(
t
,
arch
,
&
entities
.
SignatureArchives
{})
assert
.
Equal
(
t
,
arch
,
&
SignatureArchives
{})
ok
,
err
:=
collection
.
Insert
(
archives
)
assert
.
Equal
(
t
,
ok
,
true
)
...
...
@@ -139,14 +138,14 @@ func TestContainsSignature(t *testing.T) {
}
func
TestHasReceivedAbortToken
(
t
*
testing
.
T
)
{
archives
:=
entities
.
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
archives
:=
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
manager
:=
&
ArchivesManager
{
DB
:
dbManager
,
Archives
:
archives
,
}
signerIndex
:=
uint32
(
1
)
abortedSigner0
:=
entities
.
NewAbortedSigner
(
uint32
(
0
),
uint32
(
1
))
abortedSigner1
:=
entities
.
NewAbortedSigner
(
signerIndex
,
uint32
(
1
))
abortedSigner0
:=
NewAbortedSigner
(
uint32
(
0
),
uint32
(
1
))
abortedSigner1
:=
NewAbortedSigner
(
signerIndex
,
uint32
(
1
))
assert
.
Equal
(
t
,
len
(
archives
.
AbortedSigners
),
0
)
...
...
@@ -165,7 +164,7 @@ func TestHasReceivedAbortToken(t *testing.T) {
}
func
TestWasContractSigned
(
t
*
testing
.
T
)
{
archives
:=
entities
.
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
archives
:=
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
manager
:=
&
ArchivesManager
{
DB
:
dbManager
,
Archives
:
archives
,
...
...
@@ -183,7 +182,7 @@ func TestWasContractSigned(t *testing.T) {
}
func
TestHasSignerPromised
(
t
*
testing
.
T
)
{
archives
:=
entities
.
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
archives
:=
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
manager
:=
&
ArchivesManager
{
DB
:
dbManager
,
Archives
:
archives
,
...
...
@@ -192,7 +191,7 @@ func TestHasSignerPromised(t *testing.T) {
assert
.
Equal
(
t
,
len
(
archives
.
ReceivedPromises
),
0
)
assert
.
Equal
(
t
,
ok
,
false
)
promise0
:=
&
entities
.
Promise
{
promise0
:=
&
Promise
{
RecipientKeyIndex
:
1
,
SenderKeyIndex
:
0
,
}
...
...
@@ -202,7 +201,7 @@ func TestHasSignerPromised(t *testing.T) {
ok
=
manager
.
HasSignerPromised
(
1
)
assert
.
Equal
(
t
,
ok
,
false
)
promise1
:=
&
entities
.
Promise
{
promise1
:=
&
Promise
{
RecipientKeyIndex
:
1
,
SenderKeyIndex
:
1
,
}
...
...
@@ -212,7 +211,7 @@ func TestHasSignerPromised(t *testing.T) {
ok
=
manager
.
HasSignerPromised
(
1
)
assert
.
Equal
(
t
,
ok
,
false
)
promise2
:=
&
entities
.
Promise
{
promise2
:=
&
Promise
{
RecipientKeyIndex
:
0
,
SenderKeyIndex
:
1
,
}
...
...
@@ -227,7 +226,7 @@ func TestHasSignerPromised(t *testing.T) {
func
TestAddToAbort
(
t
*
testing
.
T
)
{
// TODO
// Test the abortedIndex field, when promises will be implemented
archives
:=
entities
.
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
archives
:=
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
manager
:=
&
ArchivesManager
{
DB
:
dbManager
,
Archives
:
archives
,
...
...
@@ -241,11 +240,11 @@ func TestAddToAbort(t *testing.T) {
assert
.
Equal
(
t
,
len
(
archives
.
AbortedSigners
),
0
)
sIndex
,
err
:=
checker
.
GetIndexOfSigner
(
promise
,
signers
[
1
])
sIndex
,
err
:=
GetIndexOfSigner
(
promise
,
signers
[
1
])
assert
.
Equal
(
t
,
err
.
Error
(),
"Signer's hash couldn't be matched"
)
promise
.
Context
.
Signers
=
signers
sIndex
,
err
=
checker
.
GetIndexOfSigner
(
promise
,
signers
[
1
])
sIndex
,
err
=
GetIndexOfSigner
(
promise
,
signers
[
1
])
assert
.
Equal
(
t
,
err
,
nil
)
assert
.
Equal
(
t
,
sIndex
,
uint32
(
1
))
...
...
@@ -259,7 +258,7 @@ func TestAddToAbort(t *testing.T) {
}
func
TestAddToDishonest
(
t
*
testing
.
T
)
{
archives
:=
entities
.
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
archives
:=
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
manager
:=
&
ArchivesManager
{
DB
:
dbManager
,
Archives
:
archives
,
...
...
@@ -273,11 +272,11 @@ func TestAddToDishonest(t *testing.T) {
assert
.
Equal
(
t
,
len
(
archives
.
DishonestSigners
),
0
)
sIndex
,
err
:=
checker
.
GetIndexOfSigner
(
promise
,
signers
[
1
])
sIndex
,
err
:=
GetIndexOfSigner
(
promise
,
signers
[
1
])
assert
.
Equal
(
t
,
err
.
Error
(),
"Signer's hash couldn't be matched"
)
promise
.
Context
.
Signers
=
signers
sIndex
,
err
=
checker
.
GetIndexOfSigner
(
promise
,
signers
[
1
])
sIndex
,
err
=
GetIndexOfSigner
(
promise
,
signers
[
1
])
assert
.
Equal
(
t
,
err
,
nil
)
assert
.
Equal
(
t
,
sIndex
,
uint32
(
1
))
...
...
@@ -291,19 +290,19 @@ func TestAddToDishonest(t *testing.T) {
}
func
TestAddPromise
(
t
*
testing
.
T
)
{
archives
:=
entities
.
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
archives
:=
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
manager
:=
&
ArchivesManager
{
DB
:
dbManager
,
Archives
:
archives
,
}
assert
.
Equal
(
t
,
len
(
archives
.
ReceivedPromises
),
0
)
promise0
:=
&
entities
.
Promise
{
promise0
:=
&
Promise
{
RecipientKeyIndex
:
1
,
SenderKeyIndex
:
0
,
SequenceIndex
:
0
,
}
promise1
:=
&
entities
.
Promise
{
promise1
:=
&
Promise
{
RecipientKeyIndex
:
0
,
SenderKeyIndex
:
1
,
SequenceIndex
:
1
,
...
...
dfsst/check
er/
promise.go
→
dfsst/
entities/
check
_
promise.go
View file @
04f4dc70
package
checker
package
entities
import
(
cAPI
"dfss/dfssc/api"
"dfss/dfsst/entities"
"errors"
cAPI
"dfss/dfssc/api"
)
// ArePromisesValid : determines if the specified promises contains coherent information wrt the ASSUMED TESTED platform signed information.
func
ArePromisesValid
(
promises
[]
*
cAPI
.
Promise
)
(
bool
,
[]
*
entities
.
Promise
)
{
var
tmpPromises
[]
*
entities
.
Promise
func
ArePromisesValid
(
promises
[]
*
cAPI
.
Promise
)
(
bool
,
[]
*
Promise
)
{
var
tmpPromises
[]
*
Promise
for
_
,
promise
:=
range
promises
{
valid
,
promiseEntity
:=
IsPromiseValid
(
promise
)
...
...
@@ -25,19 +25,19 @@ func ArePromisesValid(promises []*cAPI.Promise) (bool, []*entities.Promise) {
// ie: the sender and recipient's hashes are correct
// the index of the promise coresponds to an expected message from the sender in the signed sequence
// If true, returns a new promise entity
func
IsPromiseValid
(
promise
*
cAPI
.
Promise
)
(
bool
,
*
entities
.
Promise
)
{
func
IsPromiseValid
(
promise
*
cAPI
.
Promise
)
(
bool
,
*
Promise
)
{
valid
:=
IsPromiseFromAtoB
(
promise
)
if
!
valid
{
return
false
,
&
entities
.
Promise
{}
return
false
,
&
Promise
{}
}
// This checks if the index of the specified promise corresponds to an expected promise from the sender hash of the promise
sender
,
recipient
,
index
,
err
:=
GetPromiseProfile
(
promise
)
if
err
!=
nil
{
return
false
,
&
entities
.
Promise
{}
return
false
,
&
Promise
{}
}
entityPromise
:=
entities
.
NewPromise
(
sender
,
recipient
,
index
)
entityPromise
:=
NewPromise
(
sender
,
recipient
,
index
)
return
true
,
entityPromise
}
...
...
dfsst/check
er/
promise_test.go
→
dfsst/
entities/
check
_
promise_test.go
View file @
04f4dc70
package
checker
package
entities
import
(
"testing"
cAPI
"dfss/dfssc/api"
"dfss/dfsst/entities"
"github.com/bmizerany/assert"
"testing"
)
func
TestArePromisesValid
(
t
*
testing
.
T
)
{
...
...
@@ -31,14 +31,14 @@ func TestArePromisesValid(t *testing.T) {
promises
:=
[]
*
cAPI
.
Promise
{
promise0
,
promise1
}
valid
,
promiseEntities
:=
ArePromisesValid
(
promises
)
assert
.
Equal
(
t
,
valid
,
false
)
assert
.
Equal
(
t
,
promiseEntities
,
[]
*
entities
.
Promise
(
nil
))
assert
.
Equal
(
t
,
promiseEntities
,
[]
*
Promise
(
nil
))
promise0
.
Context
.
RecipientKeyHash
=
signers
[
2
]
promise0
.
Context
.
SenderKeyHash
=
signers
[
1
]
promise0
.
Index
=
1
valid
,
promiseEntities
=
ArePromisesValid
(
promises
)
assert
.
Equal
(
t
,
valid
,
false
)
assert
.
Equal
(
t
,
promiseEntities
,
[]
*
entities
.
Promise
(
nil
))
assert
.
Equal
(
t
,
promiseEntities
,
[]
*
Promise
(
nil
))
promise1
.
Context
.
RecipientKeyHash
=
signers
[
2
]
promise1
.
Context
.
SenderKeyHash
=
signers
[
0
]
...
...
@@ -68,7 +68,7 @@ func TestIsPromiseValid(t *testing.T) {
valid
,
promiseEntity
:=
IsPromiseValid
(
promise
)
assert
.
Equal
(
t
,
valid
,
false
)
assert
.
Equal
(
t
,
promiseEntity
,
&
entities
.
Promise
{})
assert
.
Equal
(
t
,
promiseEntity
,
&
Promise
{})
promise
.
Context
.
RecipientKeyHash
=
signers
[
2
]
promise
.
Context
.
SenderKeyHash
=
signers
[
1
]
...
...
dfsst/check
er/
request.go
→
dfsst/
entities/
check
_
request.go
View file @
04f4dc70
package
checker
package
entities
import
(
"bytes"
"errors"
"crypto/sha512"
"dfss/auth"
cAPI
"dfss/dfssc/api"
tAPI
"dfss/dfsst/api"
"dfss/dfsst/entities"
"dfss/net"
"errors"
"golang.org/x/net/context"
"gopkg.in/mgo.v2/bson"
)
...
...
@@ -16,7 +16,7 @@ import (
// IsRequestValid : determines if there are no errors in the received request.
// ie: the information signed by the platform in the received promises is valid and consistent
// the sender of the request is present amongst the signed signers of the promises
func
IsRequestValid
(
ctx
context
.
Context
,
request
*
tAPI
.
AlertRequest
)
(
valid
bool
,
signatureUUID
bson
.
ObjectId
,
signers
[]
entities
.
Signer
,
senderIndex
uint32
)
{
func
IsRequestValid
(
ctx
context
.
Context
,
request
*
tAPI
.
AlertRequest
)
(
valid
bool
,
signatureUUID
bson
.
ObjectId
,
signers
[]
Signer
,
senderIndex
uint32
)
{
// Due to specifications, there should be at least one promise (from the sender to himself)
if
len
(
request
.
Promises
)
==
0
{
valid
=
false
...
...
@@ -57,7 +57,7 @@ func IsRequestValid(ctx context.Context, request *tAPI.AlertRequest) (valid bool
// IsPromiseSignedByPlatform : determines if the specified promise contains valid information,
// correctly signed by the platform, and returns the signatureUUID if true.
func
IsPromiseSignedByPlatform
(
promise
*
cAPI
.
Promise
)
(
bool
,
bson
.
ObjectId
,
[]
entities
.
Signer
)
{
func
IsPromiseSignedByPlatform
(
promise
*
cAPI
.
Promise
)
(
bool
,
bson
.
ObjectId
,
[]
Signer
)
{
ok
,
signatureUUID
:=
IsSignatureUUIDValid
(
promise
)
if
!
ok
{
return
false
,
signatureUUID
,
nil
...
...
@@ -110,8 +110,8 @@ func IsSignatureUUIDValid(promise *cAPI.Promise) (bool, bson.ObjectId) {
// AreSignersHashesValid : verifies that all the specified hashes are valid (see function IsSignerHashValid).
// Returns a new array of Signers.
func
AreSignersHashesValid
(
promise
*
cAPI
.
Promise
)
(
bool
,
[]
entities
.
Signer
)
{
var
signers
[]
entities
.
Signer
func
AreSignersHashesValid
(
promise
*
cAPI
.
Promise
)
(
bool
,
[]
Signer
)
{
var
signers
[]
Signer
if
len
(
promise
.
Context
.
Signers
)
==
0
{
return
false
,
nil
}
...
...
@@ -129,12 +129,12 @@ func AreSignersHashesValid(promise *cAPI.Promise) (bool, []entities.Signer) {
// IsSignerHashValid : verifies that the specified array of bytes is a correct SHA-512 hash.
// Returns a new Signer with the specified hash.
func
IsSignerHashValid
(
hash
[]
byte
)
(
bool
,
*
entities
.
Signer
)
{
func
IsSignerHashValid
(
hash
[]
byte
)
(
bool
,
*
Signer
)
{
if
sha512
.
Size
!=
len
(
hash
)
{
return
false
,
nil
}
return
true
,
entities
.
NewSigner
(
hash
)
return
true
,
NewSigner
(
hash
)
}
// IsPlatformSignedHashValid : verifies that the specified promise contains the expected information signed by the platform.
...
...
dfsst/check
er/
request_test.go
→
dfsst/
entities/
check
_
request_test.go
View file @
04f4dc70
package
checker
package
entities
import
(
"bytes"
"crypto/sha512"
cAPI
"dfss/dfssc/api"
"github.com/bmizerany/assert"
"gopkg.in/mgo.v2/bson"
"testing"
)
var
(
sequence
[]
uint32
signers
[][]
byte
contractDocumentHash
[]
byte
signatureUUID
string
signatureUUIDBson
bson
.
ObjectId
signedHash
[]
byte
cAPI
"dfss/dfssc/api"
"github.com/bmizerany/assert"
)
func
init
()
{
sequence
=
[]
uint32
{
0
,
1
,
2
,
0
,
1
,
2
,
0
,
1
,
2
}
for
i
:=
0
;
i
<
3
;
i
++
{
h
:=
sha512
.
Sum512
([]
byte
{
byte
(
i
)})
signer
:=
h
[
:
]
signers
=
append
(
signers
,
signer
)
}
contractDocumentHash
=
[]
byte
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
}
signatureUUIDBson
=
bson
.
NewObjectId
()
signatureUUID
=
signatureUUIDBson
.
Hex
()
signedHash
=
[]
byte
{}
}
func
TestIsRequestValid
(
t
*
testing
.
T
)
{
// TODO
// This requires the use of a real Alert message
...
...
dfsst/entities/signatureArchives.go
View file @
04f4dc70
...
...
@@ -38,11 +38,6 @@ type SignatureArchives struct {
// NewSignatureArchives : creates a new SignatureArchives with the specified parameters
func
NewSignatureArchives
(
signatureUUID
bson
.
ObjectId
,
sequence
[]
uint32
,
signers
[]
Signer
,
textHash
,
signedHash
[]
byte
)
*
SignatureArchives
{
receivedPromises
:=
make
([]
Promise
,
0
)
abortedSigners
:=
make
([]
AbortedSigner
,
0
)
dishonestSigners
:=
make
([]
uint32
,
0
)
signedContract
:=
make
([]
byte
,
0
)
return
&
SignatureArchives
{
ID
:
signatureUUID
,
...
...
@@ -51,11 +46,11 @@ func NewSignatureArchives(signatureUUID bson.ObjectId, sequence []uint32, signer
TextHash
:
textHash
,
SignedHash
:
signedHash
,
ReceivedPromises
:
received
Promise
s
,
AbortedSigners
:
a
bortedSigner
s
,
DishonestSigners
:
dishonestSigners
,
ReceivedPromises
:
make
([]
Promise
,
0
)
,
AbortedSigners
:
make
([]
A
bortedSigner
,
0
)
,
DishonestSigners
:
make
([]
uint32
,
0
)
,
SignedContract
:
signedContract
,
SignedContract
:
make
([]
byte
,
0
)
,
}
}
...
...
@@ -64,9 +59,9 @@ type Promise struct {
ID
bson
.
ObjectId
`key:"_id" bson:"_id"`
// Internal id of a Promise
RecipientKeyIndex
uint32
`key:"recipientKeyIndex" bson:"recipientKeyIndex"`
// Index of the hash of the recipient's certificate in
// the `Signers` field of the enclosing SignatureArchives
SenderKeyIndex
uint32
`key:"senderKeyIndex" bson:"senderKeyIndex"`
// Index of the hash of the sender's certificate in
// the `Signers` field of the enclosing SignatureArchives
// the `Signers` field of the enclosing SignatureArchives
SenderKeyIndex
uint32
`key:"senderKeyIndex" bson:"senderKeyIndex"`
// Index of the hash of the sender's certificate in
// the `Signers` field of the enclosing SignatureArchives
SequenceIndex
uint32
`key:"sequenceIndex" bson:"sequenceIndex"`
// Sequence index of the promise
}
...
...
dfsst/resolve/resolve.go
View file @
04f4dc70
...
...
@@ -2,7 +2,6 @@ package resolve
import
(
cAPI
"dfss/dfssc/api"
"dfss/dfsst/archivesManager"
"dfss/dfsst/entities"
)
...
...
@@ -16,7 +15,7 @@ func ArePromisesComplete(promiseEntities []*entities.Promise, promise *cAPI.Prom
}
// Solve : tries to generate the signed contract from present evidence.
func
Solve
(
manager
*
archivesManager
.
ArchivesManager
)
(
bool
,
[]
byte
)
{
func
Solve
(
manager
*
entities
.
ArchivesManager
)
(
bool
,
[]
byte
)
{
// Test if we can generate the contract
for
i
:=
range
manager
.
Archives
.
Signers
{
ok
:=
manager
.
HasSignerPromised
(
uint32
(
i
))
...
...
dfsst/resolve/resolve_test.go
View file @
04f4dc70
package
resolve
import
(
"fmt"
"os"
"testing"
"crypto/sha512"
"dfss/dfsst/archivesManager"
"dfss/dfsst/entities"
"dfss/mgdb"
"fmt"
"github.com/bmizerany/assert"
"gopkg.in/mgo.v2/bson"
"os"
"testing"
)
var
(
...
...
@@ -79,7 +79,7 @@ func TestArePromisesComplete(t *testing.T) {
func
TestSolve
(
t
*
testing
.
T
)
{
archives
:=
entities
.
NewSignatureArchives
(
signatureUUIDBson
,
sequence
,
signersEntities
,
contractDocumentHash
,
signedHash
)
manager
:=
&
archivesManager
.
ArchivesManager
{
manager
:=
&
entities
.
ArchivesManager
{
DB
:
dbManager
,
Archives
:
archives
,
}
...
...
dfsst/server/server.go
View file @
04f4dc70
...
...
@@ -8,13 +8,10 @@ import (
cAPI
"dfss/dfssc/api"
"dfss/dfssc/security"
tAPI
"dfss/dfsst/api"
"dfss/dfsst/archivesManager"
"dfss/dfsst/checker"
"dfss/dfsst/entities"
"dfss/dfsst/resolve"
"dfss/mgdb"
"dfss/net"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
...
...
@@ -29,7 +26,7 @@ type ttpServer struct {
// Alert route for the TTP.
func
(
server
*
ttpServer
)
Alert
(
ctx
context
.
Context
,
in
*
tAPI
.
AlertRequest
)
(
*
tAPI
.
TTPResponse
,
error
)
{
valid
,
signatureUUID
,
signers
,
senderIndex
:=
checker
.
IsRequestValid
(
ctx
,
in
)
valid
,
signatureUUID
,
signers
,
senderIndex
:=
entities
.
IsRequestValid
(
ctx
,
in
)
if
!
valid
{
return
nil
,
errors
.
New
(
InternalError
)
}
...
...
@@ -37,7 +34,7 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
// with the same signatureUUID (thus signed information) for all promises, and sent by a valid signer
// wrt to the signed signers' hashes
manager
:=
archivesManager
.
NewArchivesManager
(
server
.
DB
)
manager
:=
entities
.
NewArchivesManager
(
server
.
DB
)
manager
.
InitializeArchives
(
in
.
Promises
[
0
],
signatureUUID
,
&
signers
)
// Now archives contains the new or already present SignatureArchives
...
...
@@ -82,7 +79,7 @@ func (server *ttpServer) Alert(ctx context.Context, in *tAPI.AlertRequest) (*tAP
//
// Updates the database with the new aborted signers.
// If an error occurs during this process, it is returned.
func
(
server
*
ttpServer
)
handleAbortedSender
(
manager
*
archivesManager
.
ArchivesManager
,
senderIndex
uint32
)
(
bool
,
*
tAPI
.
TTPResponse
,
error
)
{
func
(
server
*
ttpServer
)
handleAbortedSender
(
manager
*
entities
.
ArchivesManager
,
senderIndex
uint32
)
(
bool
,
*
tAPI
.
TTPResponse
,
error
)
{
if
manager
.
HasReceivedAbortToken
(
senderIndex
)
{
manager
.
AddToDishonest
(
senderIndex
)
...
...
@@ -111,8 +108,8 @@ func (server *ttpServer) handleAbortedSender(manager *archivesManager.ArchivesMa
//
// Updates the database with the new aborted signer.
// If an error occurs during this process, it is returned.
func
(
server
*
ttpServer
)
handleInvalidPromises
(
manager
*
archivesManager
.
ArchivesManager
,
promises
[]
*
cAPI
.
Promise
,
senderIndex
uint32
)
(
bool
,
*
tAPI
.
TTPResponse
,
[]
*
entities
.
Promise
,
error
)
{
valid
,
tmpPromises
:=
checker
.
ArePromisesValid
(
promises
)
func
(
server
*
ttpServer
)
handleInvalidPromises
(
manager
*
entities
.
ArchivesManager
,
promises
[]
*
cAPI
.
Promise
,
senderIndex
uint32
)
(
bool
,
*
tAPI
.
TTPResponse
,
[]
*
entities
.
Promise
,
error
)
{