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
8fa2ee5b
Commit
8fa2ee5b
authored
Feb 21, 2016
by
Loïck Bonniot
Browse files
[p][c] Use bytes instead of strings for hashes
parent
a163a1cb
Pipeline
#319
failed with stage
Changes
16
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
dfssc/sign/create.go
View file @
8fa2ee5b
...
...
@@ -2,7 +2,6 @@ package sign
import
(
"crypto/sha512"
"fmt"
"io/ioutil"
"path/filepath"
"time"
...
...
@@ -26,7 +25,7 @@ type CreateManager struct {
filepath
string
comment
string
signers
[]
string
hash
string
hash
[]
byte
filename
string
}
...
...
@@ -64,7 +63,7 @@ func (m *CreateManager) computeFile() error {
}
hash
:=
sha512
.
Sum512
(
data
)
m
.
hash
=
fmt
.
Sprintf
(
"%x"
,
hash
)
m
.
hash
=
hash
[
:
]
m
.
filename
=
filepath
.
Base
(
m
.
filepath
)
return
nil
...
...
dfssc/sign/create_test.go
View file @
8fa2ee5b
package
sign
import
(
"fmt"
"io/ioutil"
"os"
"path/filepath"
...
...
@@ -55,7 +56,7 @@ func TestComputeFile(t *testing.T) {
m
:=
&
CreateManager
{
filepath
:
fcontract
}
err
:=
m
.
computeFile
()
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
"37fd29decfb2d689439478b1f64b60441534c1e373a7023676c94ac6772639edab46f80139d167a2741f159e62b3064eca58bb331d32cd10770f29064af2a9de"
,
m
.
hash
)
assert
.
Equal
(
t
,
"37fd29decfb2d689439478b1f64b60441534c1e373a7023676c94ac6772639edab46f80139d167a2741f159e62b3064eca58bb331d32cd10770f29064af2a9de"
,
fmt
.
Sprintf
(
"%x"
,
m
.
hash
)
)
assert
.
Equal
(
t
,
"contract.txt"
,
m
.
filename
)
}
dfssp/api/gRPCServices.pb.go
View file @
8fa2ee5b
...
...
@@ -132,7 +132,7 @@ func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
// PostContractRequest message contains the contract as SHA-512 hash, its filename,
// the list of signers as an array of strings, and a comment
type
PostContractRequest
struct
{
Hash
string
`protobuf:"bytes,1,opt,name=hash" json:"hash,omitempty"`
Hash
[]
byte
`protobuf:"bytes,1,opt,name=hash
,proto3
" json:"hash,omitempty"`
Filename
string
`protobuf:"bytes,2,opt,name=filename" json:"filename,omitempty"`
Signer
[]
string
`protobuf:"bytes,3,rep,name=signer" json:"signer,omitempty"`
Comment
string
`protobuf:"bytes,4,opt,name=comment" json:"comment,omitempty"`
...
...
@@ -374,36 +374,36 @@ var _Platform_serviceDesc = grpc.ServiceDesc{
}
var
fileDescriptor0
=
[]
byte
{
// 4
8
9 bytes of a gzipped FileDescriptorProto
// 49
0
bytes of a gzipped FileDescriptorProto
0x1f
,
0x8b
,
0x08
,
0x00
,
0x00
,
0x09
,
0x6e
,
0x88
,
0x02
,
0xff
,
0x94
,
0x53
,
0x5d
,
0x8f
,
0xd2
,
0x40
,
0x14
,
0xdd
,
0x42
,
0x97
,
0x8f
,
0xbb
,
0x
bb
,
0x
d8
,
0x0
c
,
0x
68
,
0x
2
a
,
0x
0f
,
0x
66
,
0x
33
,
0x
2f
,
0x
1a
,
0x
1f
,
0x
d0
,
0x
a0
,
0x
31
,
0x
d1
,
0x
f8
,
0x
52
,
0x
2b
,
0x
59
,
0x
d7
,
0x
07
,
0x
42
,
0x
a6
,
0x5
b
,
0x
7d
,
0x
ae
,
0x
e5
,
0x
2e
,
0x
34
,
0x
d2
,
0x
0e
,
0x
4e
,
0x
07
,
0x
0d
,
0x7f
,
0xc6
,
0x3f
,
0xe4
,
0x8f
,
0xd2
,
0xce
,
0xb4
,
0x43
,
0xa8
,
0x36
,
0x26
,
0xcb
,
0x03
,
0xcc
,
0xb9
,
0x1f
,
0xe7
,
0xde
,
0x39
,
0x67
,
0x00
,
0xb2
,
0x6
2
,
0x
0
b
,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9
9
,
0x
d1
,
0x
40
,
0x
f
e
,
0x
06
,
0x
06
,
0x
c7
,
0x
f6
,
0x
10
,
0x
57
,
0x
57
,
0x
34
,
0x
38
,
0x
d6
,
0xd
0
,
0x
fb
,
0x
16
,
0x
ce
,
0x6
b
,
0x
0a
,
0x
93
,
0x
8
7
,
0x
ba
,
0xa
4
,
0x
49
,
0x
f5
,
0x
86
,
0x
ee
,
0x
97
,
0x
d
0
,
0x3
f
,
0x
e8
,
0x
49
,
0xe
e
,
0x
57
,
0x
3
7
,
0x
a9
,
0x
eb
,
0x
fb
,
0x
6
f
,
0xd
7
,
0x
97
,
0x
8e
,
0xfe
,
0xd
3
,
0x
be
,
0xf
8
,
0x
13
,
0x00
,
0x00
,
0xff
,
0x
ff
,
0x
35
,
0x
7d
,
0xdf
,
0x
dc
,
0xca
,
0x03
,
0x00
,
0x00
,
}
dfssp/api/gRPCServices.proto
View file @
8fa2ee5b
...
...
@@ -57,7 +57,7 @@ message Empty {
// PostContractRequest message contains the contract as SHA-512 hash, its filename,
// the list of signers as an array of strings, and a comment
message
PostContractRequest
{
string
hash
=
1
;
bytes
hash
=
1
;
string
filename
=
2
;
repeated
string
signer
=
3
;
string
comment
=
4
;
...
...
dfssp/contract/contract_test.go
View file @
8fa2ee5b
...
...
@@ -56,8 +56,8 @@ func TestAddSigner(t *testing.T) {
id
:=
bson
.
NewObjectId
()
c
.
AddSigner
(
nil
,
"mail1"
,
"hash1"
)
c
.
AddSigner
(
&
id
,
"mail2"
,
"hash2"
)
c
.
AddSigner
(
nil
,
"mail1"
,
[]
byte
{
0xaa
}
)
c
.
AddSigner
(
&
id
,
"mail2"
,
[]
byte
{}
)
signers
:=
c
.
Signers
...
...
@@ -66,10 +66,10 @@ func TestAddSigner(t *testing.T) {
}
assert
.
Equal
(
t
,
signers
[
0
]
.
Email
,
"mail1"
)
assert
.
Equal
(
t
,
signers
[
0
]
.
Hash
,
"hash1"
)
assert
.
Equal
(
t
,
signers
[
0
]
.
Hash
,
[]
byte
{
0xaa
}
)
assert
.
Equal
(
t
,
signers
[
0
]
.
UserID
.
Hex
(),
"000000000000000000000000"
)
assert
.
Equal
(
t
,
signers
[
1
]
.
Email
,
"mail2"
)
assert
.
Equal
(
t
,
signers
[
1
]
.
Hash
,
"hash2"
)
assert
.
Equal
(
t
,
signers
[
1
]
.
Hash
,
[]
byte
{}
)
assert
.
Equal
(
t
,
signers
[
1
]
.
UserID
.
Hex
(),
id
.
Hex
())
}
...
...
@@ -85,10 +85,10 @@ func assertContractEqual(t *testing.T, contract, fetched entities.Contract) {
func
TestInsertContract
(
t
*
testing
.
T
)
{
dropDataset
()
c
:=
entities
.
NewContract
()
c
.
AddSigner
(
nil
,
"mail1"
,
"hash1"
)
c
.
AddSigner
(
nil
,
"mail1"
,
"hash1"
)
c
.
AddSigner
(
nil
,
"mail1"
,
[]
byte
{
0xaa
}
)
c
.
AddSigner
(
nil
,
"mail1"
,
[]
byte
{
0xaa
}
)
c
.
File
.
Name
=
"file"
c
.
File
.
Hash
=
"hashFile"
c
.
File
.
Hash
=
[]
byte
{
0xff
}
c
.
File
.
Hosted
=
false
c
.
Comment
=
"comment"
c
.
Ready
=
true
...
...
@@ -118,17 +118,17 @@ func TestGetWaitingForUser(t *testing.T) {
dropDataset
()
c1
:=
entities
.
NewContract
()
c1
.
AddSigner
(
nil
,
"mail1"
,
""
)
c1
.
AddSigner
(
nil
,
"mail1"
,
[]
byte
{}
)
c1
.
Ready
=
false
c2
:=
entities
.
NewContract
()
c2
.
AddSigner
(
nil
,
"mail1"
,
""
)
c2
.
AddSigner
(
&
knownID
,
"mail2"
,
"hash"
)
c2
.
AddSigner
(
nil
,
"mail1"
,
[]
byte
{}
)
c2
.
AddSigner
(
&
knownID
,
"mail2"
,
[]
byte
{
0x12
}
)
c2
.
Ready
=
false
c3
:=
entities
.
NewContract
()
c3
.
AddSigner
(
nil
,
"mail2"
,
""
)
c3
.
AddSigner
(
&
knownID
,
"mail1"
,
"hash"
)
c3
.
AddSigner
(
nil
,
"mail2"
,
[]
byte
{}
)
c3
.
AddSigner
(
&
knownID
,
"mail1"
,
[]
byte
{
0xaa
}
)
c3
.
Ready
=
false
_
,
_
=
repository
.
Collection
.
Insert
(
c1
)
...
...
dfssp/contract/create.go
View file @
8fa2ee5b
...
...
@@ -70,7 +70,7 @@ func (c *Builder) checkInput() *api.ErrorCode {
return
&
api
.
ErrorCode
{
Code
:
api
.
ErrorCode_INVARG
,
Message
:
"Expecting a valid filename"
}
}
if
len
(
c
.
in
.
Hash
)
!=
sha512
.
Size
*
2
{
// *2 because string format doubles the length
if
len
(
c
.
in
.
Hash
)
!=
sha512
.
Size
{
return
&
api
.
ErrorCode
{
Code
:
api
.
ErrorCode_INVARG
,
Message
:
"Expecting a valid sha512 hash"
}
}
...
...
@@ -117,7 +117,7 @@ func (c *Builder) addContract() error {
contract
.
AddSigner
(
&
s
.
ID
,
s
.
Email
,
s
.
CertHash
)
}
for
_
,
s
:=
range
c
.
missingSigners
{
contract
.
AddSigner
(
nil
,
s
,
""
)
contract
.
AddSigner
(
nil
,
s
,
nil
)
}
contract
.
Comment
=
c
.
in
.
Comment
...
...
dfssp/contract/create_test.go
View file @
8fa2ee5b
...
...
@@ -2,7 +2,6 @@ package contract_test
import
(
"crypto/sha512"
"fmt"
"io/ioutil"
"path/filepath"
"testing"
...
...
@@ -18,7 +17,6 @@ import (
var
user1
,
user2
,
user3
*
entities
.
User
var
defaultHash
=
sha512
.
Sum512
([]
byte
{
0
})
var
defaultHashStr
=
fmt
.
Sprintf
(
"%x"
,
defaultHash
)
func
createDataset
()
{
...
...
@@ -29,17 +27,17 @@ func createDataset() {
user1
.
Email
=
"user1@example.com"
user1
.
Expiration
=
time
.
Now
()
.
AddDate
(
1
,
0
,
0
)
user1
.
Certificate
=
"Certificate1"
user1
.
CertHash
=
"Hash1"
user1
.
CertHash
=
[]
byte
{
0x01
}
user2
.
Email
=
"user2@example.com"
user2
.
Expiration
=
time
.
Now
()
.
AddDate
(
1
,
0
,
0
)
user2
.
Certificate
=
"Certificate2"
user2
.
CertHash
=
"Hash2"
user2
.
CertHash
=
[]
byte
{
0x02
}
user3
.
Email
=
"user3@example.com"
user3
.
Expiration
=
time
.
Now
()
.
AddDate
(
0
,
0
,
-
1
)
user3
.
Certificate
=
"Certificate3"
user3
.
CertHash
=
"Hash3"
user3
.
CertHash
=
[]
byte
{
0x03
}
_
,
_
=
manager
.
Get
(
"users"
)
.
Insert
(
user1
)
_
,
_
=
manager
.
Get
(
"users"
)
.
Insert
(
user2
)
...
...
@@ -91,7 +89,7 @@ func TestAddContract(t *testing.T) {
client
:=
clientTest
(
t
)
errorCode
,
err
:=
client
.
PostContract
(
context
.
Background
(),
&
api
.
PostContractRequest
{
Hash
:
defaultHash
Str
,
Hash
:
defaultHash
[
:
]
,
Filename
:
"ContractFilename"
,
Signer
:
[]
string
{
user1
.
Email
,
user2
.
Email
},
Comment
:
"ContractComment"
,
...
...
@@ -107,7 +105,7 @@ func TestAddContract(t *testing.T) {
}
assert
.
Equal
(
t
,
1
,
len
(
contracts
))
assert
.
Equal
(
t
,
defaultHash
Str
,
contracts
[
0
]
.
File
.
Hash
)
assert
.
Equal
(
t
,
defaultHash
[
:
]
,
contracts
[
0
]
.
File
.
Hash
)
assert
.
Equal
(
t
,
"ContractFilename"
,
contracts
[
0
]
.
File
.
Name
)
assert
.
Equal
(
t
,
"ContractComment"
,
contracts
[
0
]
.
Comment
)
assert
.
T
(
t
,
contracts
[
0
]
.
Ready
)
...
...
@@ -127,7 +125,7 @@ func TestAddContractMissingUser(t *testing.T) {
client
:=
clientTest
(
t
)
errorCode
,
err
:=
client
.
PostContract
(
context
.
Background
(),
&
api
.
PostContractRequest
{
Hash
:
defaultHash
Str
,
Hash
:
defaultHash
[
:
]
,
Filename
:
"ContractFilename"
,
Signer
:
[]
string
{
user1
.
Email
,
user3
.
Email
},
})
...
...
@@ -142,7 +140,7 @@ func TestAddContractMissingUser(t *testing.T) {
}
assert
.
Equal
(
t
,
1
,
len
(
contracts
))
assert
.
Equal
(
t
,
defaultHash
Str
,
contracts
[
0
]
.
File
.
Hash
)
assert
.
Equal
(
t
,
defaultHash
[
:
]
,
contracts
[
0
]
.
File
.
Hash
)
assert
.
Equal
(
t
,
"ContractFilename"
,
contracts
[
0
]
.
File
.
Name
)
assert
.
Equal
(
t
,
""
,
contracts
[
0
]
.
Comment
)
assert
.
T
(
t
,
!
contracts
[
0
]
.
Ready
)
...
...
@@ -152,7 +150,7 @@ func TestAddContractMissingUser(t *testing.T) {
assert
.
Equal
(
t
,
user1
.
CertHash
,
contracts
[
0
]
.
Signers
[
0
]
.
Hash
)
assert
.
Equal
(
t
,
user1
.
Email
,
contracts
[
0
]
.
Signers
[
0
]
.
Email
)
assert
.
Equal
(
t
,
"000000000000000000000000"
,
contracts
[
0
]
.
Signers
[
1
]
.
UserID
.
Hex
())
assert
.
Equal
(
t
,
""
,
contracts
[
0
]
.
Signers
[
1
]
.
Hash
)
assert
.
Equal
(
t
,
[]
byte
{}
,
contracts
[
0
]
.
Signers
[
1
]
.
Hash
)
assert
.
Equal
(
t
,
user3
.
Email
,
contracts
[
0
]
.
Signers
[
1
]
.
Email
)
}
...
...
@@ -162,7 +160,7 @@ func TestAddContractNoUser(t *testing.T) {
client
:=
clientTest
(
t
)
errorCode
,
err
:=
client
.
PostContract
(
context
.
Background
(),
&
api
.
PostContractRequest
{
Hash
:
defaultHash
Str
,
Hash
:
defaultHash
[
:
]
,
Filename
:
"ContractFilename"
,
Signer
:
[]
string
{},
})
...
...
@@ -185,7 +183,7 @@ func TestAddContractDuplicatedUser(t *testing.T) {
client
:=
clientTest
(
t
)
errorCode
,
err
:=
client
.
PostContract
(
context
.
Background
(),
&
api
.
PostContractRequest
{
Hash
:
defaultHash
Str
,
Hash
:
defaultHash
[
:
]
,
Filename
:
"ContractFilename"
,
Signer
:
[]
string
{
user1
.
Email
,
user1
.
Email
,
user2
.
Email
},
})
...
...
@@ -209,7 +207,7 @@ func TestAddContractNoFilename(t *testing.T) {
client
:=
clientTest
(
t
)
errorCode
,
err
:=
client
.
PostContract
(
context
.
Background
(),
&
api
.
PostContractRequest
{
Hash
:
defaultHash
Str
,
Hash
:
defaultHash
[
:
]
,
Signer
:
[]
string
{
user1
.
Email
},
})
assert
.
Equal
(
t
,
nil
,
err
)
...
...
@@ -231,7 +229,7 @@ func TestAddContractBadHash(t *testing.T) {
client
:=
clientTest
(
t
)
errorCode
,
err
:=
client
.
PostContract
(
context
.
Background
(),
&
api
.
PostContractRequest
{
Hash
:
"aVeryBadHash"
,
Hash
:
[]
byte
{
0xba
,
0xd
}
,
Filename
:
"ContractFilename"
,
Signer
:
[]
string
{
user1
.
Email
},
})
...
...
dfssp/contract/file.go
View file @
8fa2ee5b
...
...
@@ -2,6 +2,7 @@ package contract
import
(
"encoding/json"
"fmt"
"time"
"dfss/dfssp/entities"
...
...
@@ -46,7 +47,7 @@ func GetJSON(c *entities.Contract, ttp *TTPJSON) ([]byte, error) {
Comment
:
c
.
Comment
,
File
:
&
FileJSON
{
Name
:
c
.
File
.
Name
,
Hash
:
c
.
File
.
Hash
,
Hash
:
fmt
.
Sprintf
(
"%x"
,
c
.
File
.
Hash
)
,
Hosted
:
c
.
File
.
Hosted
,
},
Signers
:
make
([]
SignerJSON
,
len
(
c
.
Signers
)),
...
...
@@ -55,7 +56,7 @@ func GetJSON(c *entities.Contract, ttp *TTPJSON) ([]byte, error) {
for
i
,
s
:=
range
c
.
Signers
{
data
.
Signers
[
i
]
.
Email
=
s
.
Email
data
.
Signers
[
i
]
.
Hash
=
s
.
Hash
data
.
Signers
[
i
]
.
Hash
=
fmt
.
Sprintf
(
"%x"
,
s
.
Hash
)
}
return
json
.
MarshalIndent
(
data
,
""
,
" "
)
...
...
dfssp/contract/file_test.go
View file @
8fa2ee5b
...
...
@@ -20,12 +20,12 @@ func TestGetJSON(t *testing.T) {
allow multiline and accents: éÉ`
,
File
:
&
entities
.
File
{
Name
:
"filename.pdf"
,
Hash
:
"hash"
,
Hash
:
[]
byte
{
0x01
,
0x02
}
,
Hosted
:
false
,
},
Signers
:
[]
entities
.
Signer
{
entities
.
Signer
{
Email
:
"a"
,
Hash
:
"ha"
},
entities
.
Signer
{
Email
:
"b"
,
Hash
:
"hb"
},
entities
.
Signer
{
Email
:
"a"
,
Hash
:
[]
byte
{
0xaa
}
},
entities
.
Signer
{
Email
:
"b"
,
Hash
:
[]
byte
{
0xbb
}
},
},
}
...
...
@@ -35,17 +35,17 @@ allow multiline and accents: éÉ`,
"Comment": "A test comment\nallow multiline and accents: éÉ",
"File": {
"Name": "filename.pdf",
"Hash": "
hash
",
"Hash": "
0102
",
"Hosted": false
},
"Signers": [
{
"Email": "a",
"Hash": "
h
a"
"Hash": "
a
a"
},
{
"Email": "b",
"Hash": "
h
b"
"Hash": "
b
b"
}
],
"Sequence": null,
...
...
dfssp/entities/contract.go
View file @
8fa2ee5b
...
...
@@ -10,7 +10,7 @@ import (
// File : Represents a file structure
type
File
struct
{
Name
string
`key:"name" bson:"name"`
// Name of the File
Hash
string
`key:"hash" bson:"hash"`
// Hash of the File
Hash
[]
byte
`key:"hash" bson:"hash"`
// Hash of the File
Hosted
bool
`key:"hosted" bson:"hosted"`
// True if hosted on the platform, else false
}
...
...
@@ -18,7 +18,7 @@ type File struct {
type
Signer
struct
{
UserID
bson
.
ObjectId
`key:"userId" bson:"userId"`
Email
string
`key:"email" bson:"email"`
Hash
string
`key:"hash" bson:"hash"`
Hash
[]
byte
`key:"hash" bson:"hash"`
}
// Contract : Informations about a contract to be signed
...
...
@@ -44,7 +44,7 @@ func NewContract() *Contract {
}
// AddSigner : Add a signer to the contract
func
(
c
*
Contract
)
AddSigner
(
id
*
bson
.
ObjectId
,
email
,
hash
string
)
{
func
(
c
*
Contract
)
AddSigner
(
id
*
bson
.
ObjectId
,
email
string
,
hash
[]
byte
)
{
signer
:=
&
Signer
{}
signer
.
Email
=
email
...
...
@@ -78,7 +78,7 @@ func (r *ContractRepository) GetWaitingForUser(email string) ([]Contract, error)
"signers"
:
bson
.
M
{
"$elemMatch"
:
bson
.
M
{
"email"
:
email
,
"hash"
:
""
,
"hash"
:
[]
byte
{}
,
}},
},
&
res
)
return
res
,
err
...
...
dfssp/entities/user.go
View file @
8fa2ee5b
...
...
@@ -28,7 +28,7 @@ type User struct {
RegToken
string
`key:"regToken" bson:"regToken"`
// Token used for registering a User
Csr
string
`key:"csr" bson:"csr"`
// Certificate request at PEM format
Certificate
string
`key:"certificate" bson:"certificate"`
// Certificate of the User
CertHash
string
`key:"certHash" bson:"certHash"`
// Hash of the certificate
CertHash
[]
byte
`key:"certHash" bson:"certHash"`
// Hash of the certificate
ConnInfo
ConnectionInfo
`key:"connInfo" bson:"connInfo"`
// Information about the connection
}
...
...
@@ -54,7 +54,7 @@ func NewUserRepository(collection *mgdb.MongoCollection) *UserRepository {
}
// FetchByMailAndHash : Fetches a User from its email and certificate hash
func
(
repository
*
UserRepository
)
FetchByMailAndHash
(
email
,
hash
string
)
(
*
User
,
error
)
{
func
(
repository
*
UserRepository
)
FetchByMailAndHash
(
email
string
,
hash
[]
byte
)
(
*
User
,
error
)
{
var
users
[]
User
err
:=
repository
.
Collection
.
FindAll
(
bson
.
M
{
"email"
:
email
,
"certHash"
:
hash
},
&
users
)
if
err
!=
nil
||
len
(
users
)
==
0
{
...
...
dfssp/templates/contract.go
View file @
8fa2ee5b
...
...
@@ -13,6 +13,6 @@ const contractDetails = `Signers :
{{range .Signers}} - {{.Email}}
{{end}}
Contract name : {{.File.Name}}
SHA-512 hash : {{.File.Hash}}
SHA-512 hash : {{
printf "%x"
.File.Hash}}
Comment : {{.Comment}}
`
dfssp/templates/manager_test.go
View file @
8fa2ee5b
...
...
@@ -14,11 +14,11 @@ func TestInit(t *testing.T) {
func
TestGet
(
t
*
testing
.
T
)
{
contract
:=
entities
.
NewContract
()
contract
.
File
.
Hash
=
"hash"
contract
.
File
.
Hash
=
[]
byte
{
0x01
,
0x02
,
0x11
,
0xaa
}
contract
.
File
.
Name
=
"name.pdf"
contract
.
Comment
=
"comment"
contract
.
AddSigner
(
nil
,
"mail@example.com"
,
""
)
contract
.
AddSigner
(
nil
,
"mail2@example.com"
,
""
)
contract
.
AddSigner
(
nil
,
"mail@example.com"
,
nil
)
contract
.
AddSigner
(
nil
,
"mail2@example.com"
,
nil
)
s
,
err
:=
Get
(
"contract"
,
contract
)
...
...
@@ -32,7 +32,7 @@ Signers :
- mail2@example.com
Contract name : name.pdf
SHA-512 hash :
hash
SHA-512 hash :
010211aa
Comment : comment
Yours faithfully,
...
...
dfssp/user/create.go
View file @
8fa2ee5b
...
...
@@ -199,7 +199,7 @@ func Auth(pid *authority.PlatformID, manager *mgdb.MongoManager, certDuration in
}
// If the user already has a certificate and certificate hash in the database, does nothing
if
user
.
Certificate
!=
""
||
user
.
CertHash
!=
""
{
if
user
.
Certificate
!=
""
||
len
(
user
.
CertHash
)
!=
0
{
return
nil
,
errors
.
New
(
"User is already registered"
)
}
...
...
@@ -221,7 +221,7 @@ func Auth(pid *authority.PlatformID, manager *mgdb.MongoManager, certDuration in
}
user
.
Certificate
=
string
(
cert
)
user
.
CertHash
=
fmt
.
Sprintf
(
"%x"
,
certHash
)
user
.
CertHash
=
certHash
user
.
Expiration
=
time
.
Now
()
.
AddDate
(
0
,
0
,
certDuration
)
// Updating the database
...
...
dfssp/user/user_test.go
View file @
8fa2ee5b
...
...
@@ -75,11 +75,8 @@ func TestMain(m *testing.M) {
go
func
()
{
_
=
net
.
Listen
(
InvalidServ
,
srv2
)
}()
// Run
err
=
collection
.
Drop
()
code
:=
m
.
Run
()
// Teardown
// The collection is created automatically on
// first connection, that's why we do not recreate it manually
err
=
collection
.
Drop
()
if
err
!=
nil
{
...
...
@@ -91,7 +88,7 @@ func TestMain(m *testing.M) {
}
func
TestMongoFetchInexistantUser
(
t
*
testing
.
T
)
{
user
,
erro
:=
repository
.
FetchByMailAndHash
(
"dummyMail"
,
"dummyHash"
)
user
,
erro
:=
repository
.
FetchByMailAndHash
(
"dummyMail"
,
[]
byte
{
0x01
}
)
if
user
!=
nil
||
erro
!=
nil
{
t
.
Fatal
(
"User should not have been found and error should be nil"
)
}
...
...
@@ -100,7 +97,7 @@ func TestMongoFetchInexistantUser(t *testing.T) {
func
TestMongoInsertUser
(
t
*
testing
.
T
)
{
user
:=
entities
.
NewUser
()
user
.
Email
=
"dfss1@mpcs.tk"
user
.
CertHash
=
"dummy_hash"
user
.
CertHash
=
[]
byte
{
0x01
,
0x02
}
user
.
ConnInfo
.
IP
=
"127.0.0.1"
user
.
ConnInfo
.
Port
=
1111
user
.
Csr
=
"csr1"
...
...
@@ -117,7 +114,7 @@ func equalUsers(t *testing.T, user1, user2 *entities.User) {
t
.
Fatal
(
"ID doesn't match : received "
,
user1
.
ID
,
" and "
,
user2
.
ID
)
}
if
user1
.
CertHash
!=
user2
.
CertHash
{
if
string
(
user1
.
CertHash
)
!=
string
(
user2
.
CertHash
)
{
t
.
Fatal
(
"CertHash doesn't match : received "
,
user1
.
CertHash
,
" and "
,
user2
.
CertHash
)
}
...
...
@@ -153,7 +150,7 @@ func equalUsers(t *testing.T, user1, user2 *entities.User) {
func
TestMongoFetchUser
(
t
*
testing
.
T
)
{
user
:=
entities
.
NewUser
()
user
.
Email
=
"dfss2@mpcs.tk"
user
.
CertHash
=
"dummy_hash"
user
.
CertHash
=
nil
user
.
ConnInfo
.
IP
=
"127.0.0.2"
user
.
ConnInfo
.
Port
=
2222
user
.
Csr
=
"csr2"
...
...
@@ -240,7 +237,7 @@ func TestWrongAuthRequestContext(t *testing.T) {
}
assert
.
Equal
(
t
,
res
.
Certificate
,
""
)
assert
.
Equal
(
t
,
res
.
CertHash
,
""
)
assert
.
Equal
(
t
,
res
.
CertHash
,
[]
byte
{}
)
// Invalid certificate request (none here)
request
.
Token
=
token
...
...
@@ -255,7 +252,7 @@ func TestWrongAuthRequestContext(t *testing.T) {
t
.
Fatal
(
err
)
}
assert
.
Equal
(
t
,
res
.
Certificate
,
""
)
assert
.
Equal
(
t
,
res
.
CertHash
,
""
)
assert
.
Equal
(
t
,
res
.
CertHash
,
[]
byte
{}
)
}
func
ExampleAuth
()
{
...
...
@@ -305,7 +302,7 @@ func ExampleAuth() {
fmt
.
Println
(
err
)
}
if
res
.
Certificate
==
""
||
res
.
CertHash
==
""
{
if
res
.
Certificate
==
""
||
res
.
CertHash
==
nil
{
fmt
.
Println
(
"The database should have been updated"
)
}
...
...
@@ -347,7 +344,7 @@ func TestAuthTwice(t *testing.T) {
user
.
RegToken
=
token
user
.
Csr
=
string
(
csr
)
user
.
Certificate
=
"foo"
user
.
CertHash
=
"foo"
user
.
CertHash
=
[]
byte