Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Student Project Spring '24: Access Control on the DELA Blockchain #394

Open
wants to merge 112 commits into
base: c4dt_student24spring_access_control
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
d6878b7
change some error checking method
MaximeZmt Feb 25, 2024
9f3cfab
add formAdmin struct
MaximeZmt Mar 25, 2024
96141d0
patch linting
MaximeZmt Mar 25, 2024
4e37d18
push working changes there
MaximeZmt Mar 27, 2024
e2fc059
Update .gitignore
MaximeZmt Mar 27, 2024
270fb52
change dela id
MaximeZmt Apr 3, 2024
10c8ed1
change comment formatting
MaximeZmt Mar 27, 2024
b5b6b92
make encode function logic simpler
MaximeZmt Mar 27, 2024
87a5320
update UserID to VoterID
MaximeZmt Apr 3, 2024
b26e8ed
happy linter
MaximeZmt Apr 3, 2024
ef75d56
happy linter bis
MaximeZmt Apr 3, 2024
0ef3367
change SciperID to UserID
MaximeZmt Apr 3, 2024
c15b3fc
address Carine review
MaximeZmt Apr 16, 2024
76ac17f
add remove and is admin
MaximeZmt Apr 18, 2024
71ff097
add ADD_ADMIN and REMOVE_ADMIN cmd
MaximeZmt Apr 18, 2024
6883598
patch current error
MaximeZmt Apr 18, 2024
c1dd917
create admin form test
MaximeZmt Apr 18, 2024
e0758f6
working on the testing part
MaximeZmt Apr 21, 2024
2422f26
patch test mistake
MaximeZmt Apr 22, 2024
402cd56
fully working adminForm test
MaximeZmt Apr 22, 2024
31e6719
clean test
MaximeZmt Apr 22, 2024
4966459
linter compliance
MaximeZmt Apr 22, 2024
0b49eab
linter compliance part 2
MaximeZmt Apr 22, 2024
ecfefae
remove double name var on my new code plus some other spotted places
MaximeZmt Apr 23, 2024
d143979
improve refactoring
MaximeZmt Apr 23, 2024
ef5f872
patch #1
MaximeZmt Apr 23, 2024
4907b05
remove old code
MaximeZmt Apr 23, 2024
f7630fd
revert to longer var name
MaximeZmt Apr 23, 2024
2d50300
attempt to simplify the code
MaximeZmt Apr 23, 2024
1d74ab4
address review
MaximeZmt Apr 25, 2024
faa2889
patch vet check
MaximeZmt Apr 25, 2024
5c8cc7a
final review
MaximeZmt Apr 25, 2024
51a20dc
modification of data struct + create form
MaximeZmt Apr 22, 2024
2bf8048
implement the basic logic for owners and voters
MaximeZmt Apr 22, 2024
8596d23
patch sciper type
MaximeZmt Apr 22, 2024
7b6b2bc
patch dummy userid to sciper format
MaximeZmt Apr 22, 2024
bd6ec9e
patch dummy userid to sciper format part 2
MaximeZmt Apr 22, 2024
eb062ce
improve code readability
MaximeZmt Apr 24, 2024
42eff89
add necessary command and data struct
MaximeZmt Apr 24, 2024
fe86e34
add template of owner and voter manager
MaximeZmt Apr 28, 2024
9a3c602
add logic for managers voters and owners
MaximeZmt Apr 28, 2024
7c2cb41
implem test
MaximeZmt Apr 29, 2024
6978b78
add test voters list
MaximeZmt Apr 29, 2024
cf55eef
clean + comment test
MaximeZmt Apr 29, 2024
cae4062
patch for vet
MaximeZmt Apr 29, 2024
770a404
merge manager voters and owners
MaximeZmt Apr 30, 2024
9686858
improve code
MaximeZmt Apr 30, 2024
1138f60
apply SciperToInt method to admin
MaximeZmt Apr 30, 2024
b51dd98
patch broken test
MaximeZmt Apr 30, 2024
d0b5f14
start implement is admin logic
MaximeZmt May 1, 2024
a4a9317
ongoing implem
MaximeZmt May 2, 2024
10f50fd
patch changes
MaximeZmt May 11, 2024
4745944
patch changes 2
MaximeZmt May 11, 2024
8d52899
Init AdminForm method
MaximeZmt May 11, 2024
1c5008b
now need an admin perm on blockchain to create form
MaximeZmt May 11, 2024
5c5f4e3
evening work refactor part 1
MaximeZmt May 14, 2024
b5f7fb2
add SciperToInt to AddVoter
MaximeZmt May 2, 2024
919a8e2
change error message to make them more clear
MaximeZmt May 2, 2024
1bf4860
change error message to make them more clear part 2
MaximeZmt May 2, 2024
75236cf
add an additional SciperToInt Method
MaximeZmt May 2, 2024
45a6f4d
patched unvalid userid in test
MaximeZmt May 2, 2024
a363b07
update a comment in the test
MaximeZmt May 2, 2024
42be1f3
update a comment in the test 2
MaximeZmt May 2, 2024
4d1c3cc
merge rebase
MaximeZmt May 14, 2024
0f30a61
patch one test
MaximeZmt May 14, 2024
48f1e0e
patch vet
MaximeZmt May 14, 2024
db4b2e4
patch even more adminform to adminlist
MaximeZmt May 15, 2024
2dee2d1
getting rid of adminform
MaximeZmt May 15, 2024
c647f17
add performing and target field
MaximeZmt May 16, 2024
223c1ac
patch error and test
MaximeZmt May 16, 2024
7c4b1be
some minor changes
MaximeZmt May 16, 2024
0bac02e
small code cleaning
MaximeZmt May 21, 2024
372262d
Update contracts/evoting/evoting.go
MaximeZmt May 23, 2024
80d2270
Update contracts/evoting/mod_test.go
MaximeZmt May 23, 2024
d0e8da5
Update contracts/evoting/types/admin.go
MaximeZmt May 23, 2024
4c60e70
Update contracts/evoting/types/admin.go
MaximeZmt May 23, 2024
abd024f
address partial review
MaximeZmt May 23, 2024
f155a43
isAdmin function
MaximeZmt May 23, 2024
1787874
patch updatemetadata review
MaximeZmt May 23, 2024
ad9babc
patch ownervoter test
MaximeZmt May 23, 2024
c2b0c0b
Update evoting.go
MaximeZmt May 23, 2024
9d68438
patch is admin error mgmt
MaximeZmt May 23, 2024
3887984
patch test
MaximeZmt May 23, 2024
cbb4563
patch isAdmin structure
MaximeZmt May 23, 2024
8259f04
Address review
MaximeZmt May 24, 2024
e079cb8
first version of ownersvoters logic
MaximeZmt May 27, 2024
6cfd91d
remove slices package and replace it by hand implemented method
MaximeZmt May 27, 2024
9e7d95d
patch integration test for createform and openform
MaximeZmt May 28, 2024
a68dfb7
patch shuffle intergration test
MaximeZmt May 28, 2024
7481a53
patch neff test
MaximeZmt May 28, 2024
b4986f5
patch neff test round 2
MaximeZmt May 28, 2024
97e1c88
patch weird neff test
MaximeZmt May 28, 2024
508e184
remove useless time.sleep
MaximeZmt May 28, 2024
6dc01f3
add explanation for voterid
MaximeZmt May 28, 2024
1677f59
vet reformat
MaximeZmt May 28, 2024
616805e
fix: do reinsert existing admin
MaximeZmt May 29, 2024
41a439a
feat: added new interface to the proxy (part 1)
MaximeZmt May 29, 2024
c60eddd
feat: AddToAdminList first implem
MaximeZmt May 29, 2024
ebe3c18
temp: add info
MaximeZmt May 29, 2024
929bb28
feat: update the signature verification on proxy
MaximeZmt Jun 3, 2024
56b0745
work: working on debugging the new features of the proxy
MaximeZmt Jun 3, 2024
2e2b413
work: proxy add/remove/get adminlist
MaximeZmt Jun 4, 2024
fc54d66
fix: for display
MaximeZmt Jun 4, 2024
3c0b64d
fix: fix bug on transaction result
MaximeZmt Jun 5, 2024
88558a8
fix: code cleaning + continue implem proxy
MaximeZmt Jun 12, 2024
4833881
fix: remove commented query for testing
MaximeZmt Jun 16, 2024
01d1409
fix: improve comments to make govet happy
MaximeZmt Jun 16, 2024
3bbba51
fix: clean the code
MaximeZmt Jun 16, 2024
3b002b6
fix: remove debug print
MaximeZmt Jun 20, 2024
be39b3e
fix: revert change
MaximeZmt Jun 20, 2024
a85dc7a
docs: update api.md
MaximeZmt Jun 26, 2024
4f74ed7
Update api.md
MaximeZmt Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions contracts/evoting/admin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package evoting

import (
"github.com/c4dt/d-voting/contracts/evoting/types"
"github.com/stretchr/testify/require"
"go.dedis.ch/dela/serde"
sjson "go.dedis.ch/dela/serde/json"
"testing"
)

var ctxAdminTest serde.Context

var formFacAdminTest serde.Factory
var transactionFacAdminTest serde.Factory

func init() {
ciphervoteFac := types.CiphervoteFactory{}
formFacAdminTest = types.NewFormFactory(ciphervoteFac, fakeAuthorityFactory{})
transactionFacAdminTest = types.NewTransactionFactory(ciphervoteFac)

ctxAdminTest = sjson.NewContext()
}

// This test create an Admin Form structure which is then serialized and
// deserialized to check whether these operations work as intended.
// Serialization/Deserialization of an AdminList should not change its values.
func TestAdmin_Serde(t *testing.T) {
initialAdminList := []int{111111, 222222, 333333, 123456}

adminList := types.AdminList{AdminList: initialAdminList}

value, err := adminList.Serialize(ctxAdminTest)

require.NoError(t, err)

// deserialization
deserializedAdminList := types.AdminList{}

msgs, err := deserializedAdminList.Deserialize(ctxAdminTest, value)

require.NoError(t, err)

updatedAdminList := msgs.(types.AdminList)

require.Equal(t, initialAdminList, updatedAdminList.AdminList)
}

func TestAdmin_AddAdminAndRemoveAdmin(t *testing.T) {
initialAdminList := []int{}

myTestID := "123456"

adminList := types.AdminList{AdminList: initialAdminList}

res, err := adminList.GetAdminIndex(myTestID)
require.Equal(t, -1, res)
require.NoError(t, err)

err = adminList.AddAdmin(myTestID)
require.NoError(t, err)
res, err = adminList.GetAdminIndex(myTestID)
require.Equal(t, 0, res)
require.NoError(t, err)

err = adminList.RemoveAdmin(myTestID)
require.ErrorContains(t, err, "cannot remove this Admin because it is the only one remaining")

err = adminList.AddAdmin("654321")
require.NoError(t, err)

err = adminList.RemoveAdmin(myTestID)
require.NoError(t, err)
res, err = adminList.GetAdminIndex(myTestID)
require.Equal(t, -1, res)
require.NoError(t, err)
}
33 changes: 22 additions & 11 deletions contracts/evoting/controller/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ const (
contentType = "application/json"
formPath = "/evoting/forms"
// FormPathSlash is the path to the form with a trailing slash
FormPathSlash = formPath + "/"
formIDPath = FormPathSlash + "{formID}"
transactionSlash = "/evoting/transactions/"
FormPathSlash = formPath + "/"
formIDPath = FormPathSlash + "{formID}"
transactionSlash = "/evoting/transactions/"

evotingPathSlash = "/evoting/"

transactionPath = transactionSlash + "{token}"
unexpectedStatus = "unexpected status: %s, body: %s"
failRetrieveDecryption = "failed to retrieve decryption key: %v"
Expand Down Expand Up @@ -169,12 +172,19 @@ func (a *RegisterAction) Execute(ctx node.Context) error {
return xerrors.Errorf("failed to unmarshal proxy key: %v", err)
}

transactionManager := txnmanager.NewTransactionManager(mngr, p, sjson.NewContext(), proxykey, blocks, signer)
transactionManager := txnmanager.NewTransactionManager(mngr, p, sjson.NewContext(), proxykey, blocks, signer, validation)

ep := eproxy.NewForm(ordering, p, sjson.NewContext(), formFac, proxykey, transactionManager)

router := mux.NewRouter()

router.HandleFunc(evotingPathSlash+"addadmin", ep.AddAdmin).Methods("POST")
router.HandleFunc(evotingPathSlash+"removeadmin", ep.RemoveAdmin).Methods("POST")
router.HandleFunc(evotingPathSlash+"adminlist", ep.AdminList).Methods("GET")
router.HandleFunc(formIDPath+"/addowner", ep.AddOwnerToForm).Methods("POST")
router.HandleFunc(formIDPath+"/removeowner", ep.RemoveOwnerToForm).Methods("POST")
router.HandleFunc(formIDPath+"/addvoter", ep.AddVoterToForm).Methods("POST")
router.HandleFunc(formIDPath+"/removevoter", ep.RemoveVoterToForm).Methods("POST")
router.HandleFunc(formPath, ep.NewForm).Methods("POST")
router.HandleFunc(formPath, ep.Forms).Methods("GET")
router.HandleFunc(formPath, eproxy.AllowCORS).Methods("OPTIONS")
Expand All @@ -188,6 +198,7 @@ func (a *RegisterAction) Execute(ctx node.Context) error {
router.NotFoundHandler = http.HandlerFunc(eproxy.NotFoundHandler)
router.MethodNotAllowedHandler = http.HandlerFunc(eproxy.NotAllowedHandler)

proxy.RegisterHandler(evotingPathSlash, router.ServeHTTP)
proxy.RegisterHandler(formPath, router.ServeHTTP)
proxy.RegisterHandler(FormPathSlash, router.ServeHTTP)
proxy.RegisterHandler(transactionSlash, router.ServeHTTP)
Expand Down Expand Up @@ -352,8 +363,8 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
}

castVoteRequest := ptypes.CastVoteRequest{
UserID: "user1",
Ballot: ballot1,
VoterID: "user1",
Ballot: ballot1,
}

signed, err := createSignedRequest(secret, castVoteRequest)
Expand All @@ -377,8 +388,8 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
}

castVoteRequest = ptypes.CastVoteRequest{
UserID: "user2",
Ballot: ballot2,
VoterID: "user2",
Ballot: ballot2,
}

signed, err = createSignedRequest(secret, castVoteRequest)
Expand All @@ -402,8 +413,8 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
}

castVoteRequest = ptypes.CastVoteRequest{
UserID: "user3",
Ballot: ballot3,
VoterID: "user3",
Ballot: ballot3,
}

signed, err = createSignedRequest(secret, castVoteRequest)
Expand Down Expand Up @@ -593,7 +604,7 @@ func setupSimpleForm(ctx node.Context, secret kyber.Scalar, proxyAddr1 string,

createSimpleFormRequest := ptypes.CreateFormRequest{
Configuration: configuration,
AdminID: "adminId",
UserID: "UserID",
}

signed, err := createSignedRequest(secret, createSimpleFormRequest)
Expand Down
Loading
Loading