├── _config.yml
├── settings.gradle
├── doc
├── assets
│ ├── Demo.png
│ ├── logogeneve.png
│ └── indiv-verif-sample.png
├── sequence
│ ├── Mixing.png
│ ├── Voting.png
│ ├── Tallying.png
│ ├── CodeSheets.png
│ ├── Decryption.png
│ ├── Initialization.png
│ ├── Tallying.puml
│ ├── style.puml
│ ├── Decryption.puml
│ ├── Mixing.puml
│ ├── CodeSheets.puml
│ ├── Initialization.puml
│ └── Voting.puml
└── Implementation.md
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── PITCHME.yaml
├── src
├── main
│ ├── resources
│ │ ├── db
│ │ │ └── local_db.mv.db
│ │ ├── application.properties
│ │ ├── import.sql
│ │ └── logback.xml
│ └── java
│ │ └── ch
│ │ └── ge
│ │ └── ve
│ │ └── protopoc
│ │ ├── model
│ │ ├── entity
│ │ │ ├── AuthorityName.java
│ │ │ └── Authority.java
│ │ └── repository
│ │ │ └── AccountRepository.java
│ │ ├── service
│ │ ├── support
│ │ │ ├── MoreMath.java
│ │ │ └── BigIntegers.java
│ │ ├── exception
│ │ │ ├── VoteCastingException.java
│ │ │ ├── InvalidDecryptionProofException.java
│ │ │ ├── TallyingRuntimeException.java
│ │ │ ├── VoteConfirmationException.java
│ │ │ ├── IncorrectBallotRuntimeException.java
│ │ │ ├── InvalidShuffleProofRuntimeException.java
│ │ │ ├── NotEnoughPrimesInGroupException.java
│ │ │ ├── IncorrectConfirmationRuntimeException.java
│ │ │ ├── BallotNotFoundRuntimeException.java
│ │ │ ├── InvalidObliviousTransferResponseException.java
│ │ │ ├── DigestInitialisationRuntimeException.java
│ │ │ └── IncompatibleParametersRuntimeException.java
│ │ ├── simulation
│ │ │ ├── VoteProcessException.java
│ │ │ ├── FinalizationCodeNotMatchingException.java
│ │ │ └── VerificationCodesNotMatchingException.java
│ │ ├── protocol
│ │ │ ├── IncorrectBallotOrQueryException.java
│ │ │ ├── VotingClientService.java
│ │ │ ├── AuthorityService.java
│ │ │ └── BulletinBoardService.java
│ │ └── model
│ │ │ ├── PrimeField.java
│ │ │ ├── Voter.java
│ │ │ ├── BallotQueryAndRand.java
│ │ │ ├── ObliviousTransferQuery.java
│ │ │ ├── VotingPageData.java
│ │ │ ├── DomainOfInfluence.java
│ │ │ ├── Candidate.java
│ │ │ ├── Election.java
│ │ │ ├── BallotAndQuery.java
│ │ │ ├── ShufflesAndProofs.java
│ │ │ ├── IdentificationGroup.java
│ │ │ ├── DecryptionProof.java
│ │ │ ├── ConfirmationEntry.java
│ │ │ ├── EncryptionPublicKey.java
│ │ │ ├── EncryptionPrivateKey.java
│ │ │ ├── Confirmation.java
│ │ │ ├── FinalizationCodePart.java
│ │ │ ├── CommitmentChain.java
│ │ │ ├── PermutationCommitment.java
│ │ │ ├── ElectorateData.java
│ │ │ ├── polynomial
│ │ │ ├── PointsAndZeroImages.java
│ │ │ └── Point.java
│ │ │ ├── NonInteractiveZKP.java
│ │ │ ├── SecurityParameters.java
│ │ │ ├── ReEncryption.java
│ │ │ ├── BallotEntry.java
│ │ │ ├── ObliviousTransferResponseAndRand.java
│ │ │ ├── ElectionSet.java
│ │ │ ├── Shuffle.java
│ │ │ └── Encryption.java
│ │ ├── controller
│ │ ├── api
│ │ │ ├── HomeInterface.java
│ │ │ └── AuthenticationInterface.java
│ │ └── impl
│ │ │ └── HomeController.java
│ │ ├── jwt
│ │ ├── JwtAuthenticationResponse.java
│ │ ├── JwtAuthenticationRequest.java
│ │ ├── JwtUserFactory.java
│ │ ├── JwtAuthenticationEntryPoint.java
│ │ └── JwtUserDetailsServiceImpl.java
│ │ └── ProtocolPocApplication.java
└── test
│ ├── resources
│ └── test_db.h2.mv.db
│ ├── java
│ └── ch
│ │ └── ge
│ │ └── ve
│ │ └── protopoc
│ │ └── ProtocolPocApplicationTests.java
│ └── groovy
│ └── ch
│ └── ge
│ └── ve
│ └── protopoc
│ └── service
│ ├── support
│ ├── ByteArrayUtilsTest.groovy
│ └── JacobiSymbolTest.groovy
│ └── algorithm
│ ├── VoteConfirmationVoterAlgorithmsTest.groovy
│ └── KeyEstablishmentAlgorithmsTest.groovy
├── circle.yml
├── .gitignore
├── .travis.yml
└── gradlew.bat
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-midnight
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'chvote-protocol-poc'
--------------------------------------------------------------------------------
/doc/assets/Demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/republique-et-canton-de-geneve/chvote-protocol-poc/HEAD/doc/assets/Demo.png
--------------------------------------------------------------------------------
/doc/sequence/Mixing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/republique-et-canton-de-geneve/chvote-protocol-poc/HEAD/doc/sequence/Mixing.png
--------------------------------------------------------------------------------
/doc/sequence/Voting.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/republique-et-canton-de-geneve/chvote-protocol-poc/HEAD/doc/sequence/Voting.png
--------------------------------------------------------------------------------
/doc/assets/logogeneve.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/republique-et-canton-de-geneve/chvote-protocol-poc/HEAD/doc/assets/logogeneve.png
--------------------------------------------------------------------------------
/doc/sequence/Tallying.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/republique-et-canton-de-geneve/chvote-protocol-poc/HEAD/doc/sequence/Tallying.png
--------------------------------------------------------------------------------
/doc/sequence/CodeSheets.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/republique-et-canton-de-geneve/chvote-protocol-poc/HEAD/doc/sequence/CodeSheets.png
--------------------------------------------------------------------------------
/doc/sequence/Decryption.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/republique-et-canton-de-geneve/chvote-protocol-poc/HEAD/doc/sequence/Decryption.png
--------------------------------------------------------------------------------
/doc/sequence/Initialization.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/republique-et-canton-de-geneve/chvote-protocol-poc/HEAD/doc/sequence/Initialization.png
--------------------------------------------------------------------------------
/doc/assets/indiv-verif-sample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/republique-et-canton-de-geneve/chvote-protocol-poc/HEAD/doc/assets/indiv-verif-sample.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/republique-et-canton-de-geneve/chvote-protocol-poc/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/PITCHME.yaml:
--------------------------------------------------------------------------------
1 | theme : moon
2 | mousewheel : true
3 | logo : doc/assets/logogeneve.png
4 | highlight : solarized-dark
5 | mathjax : TeX-AMS_HTML-full
6 |
7 |
--------------------------------------------------------------------------------
/src/main/resources/db/local_db.mv.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/republique-et-canton-de-geneve/chvote-protocol-poc/HEAD/src/main/resources/db/local_db.mv.db
--------------------------------------------------------------------------------
/src/test/resources/test_db.h2.mv.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/republique-et-canton-de-geneve/chvote-protocol-poc/HEAD/src/test/resources/test_db.h2.mv.db
--------------------------------------------------------------------------------
/circle.yml:
--------------------------------------------------------------------------------
1 | machine:
2 | java:
3 | version: oraclejdk8
4 |
5 | dependencies:
6 | override:
7 | - chmod +x gradlew
8 |
9 | test:
10 | post:
11 | - ./gradlew simulation -DsecLevel=2 -DvotersCount=10
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Oct 03 13:04:28 CEST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip
7 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | jwt.header=Authorization
2 | jwt.secret=POC-use-only!Please-change
3 | jwt.expiration=604800
4 |
5 | spring.jpa.hibernate.ddl-auto=update
6 |
7 | spring.data.rest.basePath=/api
8 |
9 | logging.level.org.springframework.web=INFO
10 | logging.level.org.hibernate=INFO
11 | server.port=9000
--------------------------------------------------------------------------------
/doc/sequence/Tallying.puml:
--------------------------------------------------------------------------------
1 | @startuml
2 | !include style.puml
3 | hide footbox
4 | participant "Election Officer / \nSimulation" as eo
5 | participant "Bulletin Board" as bb
6 |
7 | activate eo
8 | eo -> bb : getTallyData
9 | activate bb
10 | bb --> eo : partial decryptions and proofs
11 | deactivate bb
12 |
13 | eo -> eo : check decryption proofs
14 |
15 | eo -> bb : publishTally
16 | deactivate eo
17 |
18 | @enduml
--------------------------------------------------------------------------------
/doc/sequence/style.puml:
--------------------------------------------------------------------------------
1 | @startuml
2 | skinparam roundcorner 20
3 |
4 | skinparam sequence {
5 | ArrowColor #193A72
6 | ArrowFontColor #3F6AB2
7 | LifeLineBorderColor #26529C
8 | LifeLineBackgroundColor #89ABE6
9 |
10 | ParticipantBorderColor #26529C
11 | ParticipantBackgroundColor #89ABE6
12 | ParticipantFontName Trebuchet
13 | ParticipantFontSize 15
14 | ParticipantFontStyle bold
15 | ParticipantFontColor #193A72
16 |
17 | GroupingFontColor #3F6AB2
18 | GroupingHeaderFontColor #3F6AB2
19 | DividerFontColor #3F6AB2
20 | }
21 | @enduml
--------------------------------------------------------------------------------
/doc/sequence/Decryption.puml:
--------------------------------------------------------------------------------
1 | @startuml
2 | !include style.puml
3 | hide footbox
4 | participant "Election Officer / \nSimulation" as eo
5 | participant "Authority [1-s]" as auth
6 | participant "Bulletin Board" as bb
7 |
8 | activate eo
9 | loop for each authority
10 | eo -> auth : startPartialDecryption
11 | activate auth
12 | auth -> bb : getShufflesAndProofs
13 | bb --> auth : shufflesAndProofs
14 | auth -> auth : check shuffle proofs
15 | auth -> bb : publishPartialDecryptionsAndProofs
16 | auth --> eo : done
17 | deactivate auth
18 | end
19 | deactivate eo
20 |
21 | @enduml
--------------------------------------------------------------------------------
/src/main/resources/import.sql:
--------------------------------------------------------------------------------
1 | INSERT INTO ACCOUNT (ID, USERNAME, PASSWORD) VALUES (1, 'admin', '$2a$08$lDnHPz7eUkSi6ao14Twuau08mzhWrL4kyZGGU5xfiGALO/Vxd5DOi');
2 | INSERT INTO ACCOUNT (ID, USERNAME, PASSWORD) VALUES (2, 'user', '$2a$08$UkVvwpULis18S19S5pZFn.YHPZt3oaqHZnDwqbCW9pft6uFtkXKDC');
3 |
4 | INSERT INTO AUTHORITIES (ID, NAME) VALUES (1, "ROLE_USER");
5 | INSERT INTO AUTHORITIES (ID, NAME) VALUES (2, "ROLE_ADMIN");
6 |
7 | INSERT INTO ACCOUNT_AUTHORITIES (ACCOUNT_ID, AUTHORITY_ID) VALUES (1, 1);
8 | INSERT INTO ACCOUNT_AUTHORITIES (ACCOUNT_ID, AUTHORITY_ID) VALUES (1, 2);
9 | INSERT INTO ACCOUNT_AUTHORITIES (ACCOUNT_ID, AUTHORITY_ID) VALUES (2, 1);
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Added by hand
2 | ### Exclude logs
3 | logs/
4 |
5 | # Created by .ignore support plugin (hsz.mobi)
6 | ### Gradle template
7 | .gradle
8 | build/
9 |
10 | # Ignore Gradle GUI config
11 | gradle-app.setting
12 |
13 | # Cache of project
14 | .gradletasknamecache
15 |
16 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
17 | # gradle/wrapper/gradle-wrapper.properties
18 | ### Java template
19 | *.class
20 |
21 | # Mobile Tools for Java (J2ME)
22 | .mtj.tmp/
23 |
24 | # Package Files #
25 | *.jar
26 | *.war
27 | *.ear
28 |
29 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
30 | hs_err_pid*
31 |
32 | # IntelliJ
33 | .idea
34 |
35 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
36 | !gradle-wrapper.jar
37 |
--------------------------------------------------------------------------------
/doc/sequence/Mixing.puml:
--------------------------------------------------------------------------------
1 | @startuml
2 | !include style.puml
3 | hide footbox
4 | participant "Election Officer / \nSimulation" as eo
5 | participant "Authority 1" as auth1
6 | participant "Authority [2-s]" as auth2
7 | participant "Bulletin Board" as bb
8 |
9 | activate eo
10 | eo -> auth1 : startMixing
11 | activate auth1
12 | auth1 -> auth1 : shuffle
13 | auth1 -> bb : publishShuffleAndProof
14 | auth1 --> eo : done
15 | deactivate auth1
16 |
17 | loop for j in 2, ..., s
18 | eo -> auth2 : mixAgain
19 | activate auth2
20 | auth2 -> bb : getPreviousShuffle
21 | activate bb
22 | bb --> auth2 : result of previous shuffle
23 | deactivate bb
24 | auth2 -> auth2 : shuffle
25 | auth2 -> bb : publishShuffleAndProof
26 | auth2 --> eo : done
27 | deactivate auth2
28 | end
29 | deactivate eo
30 | @enduml
--------------------------------------------------------------------------------
/doc/sequence/CodeSheets.puml:
--------------------------------------------------------------------------------
1 | @startuml
2 | !include style.puml
3 | participant "Election Officer / \nSimulation" as eo
4 | participant "Authority [1-s]" as auth
5 | participant "Bulletin Board" as bb
6 | participant "Printing authority" as print
7 | participant "Voter" as voter
8 | activate eo
9 | eo -> print : print
10 | activate print
11 | == Configuration ==
12 | print -> bb : getPublicParameters
13 | activate bb
14 | bb --> print : public parameters
15 | deactivate bb
16 | print -> bb : getElectionSet
17 | activate bb
18 | bb --> print : election set
19 |
20 | == Retrieve credentials ==
21 | loop for each authority
22 | deactivate bb
23 | print -> auth : getPrivateCredentials
24 | activate auth
25 | auth --> print : private voter credentials
26 | deactivate auth
27 | end
28 |
29 | print -> print : combine credential parts
30 |
31 | == Send code sheets ==
32 | print -> voter : sendCodeSheet
33 | print --> eo : done
34 | deactivate print
35 | deactivate eo
36 | @enduml
--------------------------------------------------------------------------------
/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 | logs/simulation.log
11 |
12 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
13 |
14 |
15 |
16 | logs/simulation-performances.log
17 |
18 | %msg%n
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - oraclejdk8
4 |
5 | dist: trusty
6 | sudo: true
7 |
8 | addons:
9 | apt:
10 | packages:
11 | - oracle-java8-installer
12 | sonarqube:
13 | token:
14 | secure: "XuRMS2r+5cY3w2/SQwuxa0EEGbdgEJIyfV1QwS1kaLz6c5kX4xVhTsAqMfSd85GrKIdHPjvyq8J6bLxa3iVeuNUXG/S01XfJmoSujnP06sCCqay/+VwytzhVV4CN3bzFlibaHu7dPqbScbvXRP5Sm0wc4KEsrwM5+Oi2ZnFVwllFfgvJUuO+3kaLdIjUIqbtNttpA17oShFRjhznVO/Yk9JKPyxgRdt4Fzyiu39uJQ4hsBZ0J/9xXVFL0cL+WOvAeSklAJrRKVmiR2f/1gv1cgmsQ9uSOUqRbzDNbtG5xymBkXxYz4nj8RImGtmMgx0VBCI6pJWOOGdjpEtY3c0Qun+XxcH8mRphe0IsLYeZDazYLi/c1ILShNvbQDTuMXmNjDwdx89SaTeELITuT6JJcP5GOxtL/2Kw8X19ED5Yc8R+tMjz+qAPkpuBACrPtRLDqflXbDFOHt5dKYQXfLD1UeECMMQfrTAjNZ2sjf17YjBpSh1sqMogK/kuYJbvG7O7W6/LL87XnLhqG9tFE5mn1V7qOpqJPFQUITsdd7GV/Kbn1OkEQ6avZBQWaMRDzFkZyK4jeca2UrItV473yU9pRpJIsKR09z39iNgGRfq1x8/Vn0mv8wZ/z+MjtDOwVZzTbfZ3Sw73VI+Bh2fkSp/Az5J1LukN4lcKEU52xoeP0Sg="
15 | branches:
16 | - master
17 | - development
18 |
19 | before_install:
20 | - "curl -L --cookie 'oraclelicense=accept-securebackup-cookie;' http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip -o /tmp/policy.zip && sudo unzip -j -o /tmp/policy.zip *.jar -d `jdk_switcher home oraclejdk8`/jre/lib/security && rm /tmp/policy.zip"
21 | - "chmod +x ./gradlew"
22 |
23 | script:
24 | - ./gradlew simulation -DsecLevel=2 -DvotersCount=10
25 |
26 | cache:
27 | directories:
28 | - '$HOME/.m2/repository'
29 | - '$HOME/.sonar/cache'
--------------------------------------------------------------------------------
/doc/sequence/Initialization.puml:
--------------------------------------------------------------------------------
1 | @startuml
2 | !include style.puml
3 | participant "Election Officer / \nSimulation" as eo
4 | participant "Authority [1-s]" as auth
5 | participant "Bulletin Board" as bb
6 |
7 | activate eo
8 | eo -> bb : publishPublicParameters
9 |
10 | == Key generation ==
11 | loop for each authority
12 | eo -> auth : generateKeys
13 | activate auth
14 | auth -> bb : getPublicParameters
15 | bb --> auth : public parameters
16 | auth -> bb : publishPublicKeyPart
17 | auth --> eo : done
18 | deactivate auth
19 | end
20 |
21 | loop for each authority
22 | eo -> auth : buildPublicKey
23 | activate auth
24 | auth -> bb : getPublicKeyParts
25 | bb --> auth : public key parts
26 | auth -> auth : buildPublicKey
27 | auth --> eo : done
28 | deactivate auth
29 | end
30 |
31 | == Election configuration ==
32 |
33 | eo -> bb : publishElectionSet
34 |
35 | == Credentials generation ==
36 | loop for each authority
37 | eo -> auth : generateElectorateData
38 | activate auth
39 | auth -> bb : getElectionSet
40 | bb --> auth : election set
41 | auth -> bb : publishPublicCredentials
42 | auth --> eo : done
43 | deactivate auth
44 | end
45 |
46 | loop for each authority
47 | eo -> auth : buildPublicCredentials
48 | activate auth
49 | auth -> bb : getPublicCredentialsParts
50 | bb --> auth : public credential parts
51 | auth -> auth : combine public credentials
52 | auth --> eo : done
53 | deactivate auth
54 | deactivate eo
55 | end
56 | @enduml
--------------------------------------------------------------------------------
/doc/sequence/Voting.puml:
--------------------------------------------------------------------------------
1 | @startuml
2 | !include style.puml
3 | participant "Election Officer / \nSimulation" as eo
4 | participant "Authority [1-s]" as auth
5 | participant "Bulletin Board" as bb
6 | participant "Voting Client" as client
7 | participant "Voter Simulator" as voter
8 |
9 | activate eo
10 | eo -> voter : vote
11 | activate voter
12 |
13 | == Build voting page ==
14 | voter -> client : startVoteSession
15 | client -> bb : getPublicParameters
16 | client -> bb : getElectionSet
17 | client --> voter : votingPage
18 |
19 | == Submit vote and OT query ==
20 | voter -> client : submitVote
21 | activate client
22 | client -> bb : getPublicKeyParts
23 | activate bb
24 | bb --> client : public key parts
25 | deactivate bb
26 | client -> client : build public key
27 | client -> bb : publishBallotAndQuery
28 | activate bb
29 | loop for each authority
30 | bb -> auth : handleBallot
31 | activate auth
32 | auth --> bb : response
33 | deactivate auth
34 | end
35 | bb --> client : responses
36 | deactivate bb
37 | client --> voter : verification codes
38 | deactivate client
39 |
40 | == Confirm vote ==
41 | voter -> client : confirmVote
42 | activate client
43 | client -> bb : publishConfirmation
44 | activate bb
45 | loop for each authority
46 | bb -> auth : handleConfirmation
47 | activate auth
48 | auth --> bb : finalization
49 | deactivate auth
50 | end
51 | bb --> client : finalization
52 | deactivate bb
53 | client --> voter : finalization code
54 | deactivate client
55 |
56 | voter --> eo : done
57 | deactivate voter
58 | deactivate eo
59 |
60 | @enduml
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/model/entity/AuthorityName.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.model.entity;
23 |
24 | /**
25 | * Enumeration of the known authorities
26 | */
27 | public enum AuthorityName {
28 | ROLE_USER, ROLE_ADMIN
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/support/MoreMath.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.support;
23 |
24 | /**
25 | * Additional math primitives missing from {@link Math}
26 | */
27 | public class MoreMath {
28 | public static double log2(double value) {
29 | return Math.log(value) / Math.log(2);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/exception/VoteCastingException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.exception;
23 |
24 | /**
25 | * Exception thrown when an error occurs during the vote casting process
26 | */
27 | public class VoteCastingException extends Exception {
28 | public VoteCastingException(Exception cause) {
29 | super(cause);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/exception/InvalidDecryptionProofException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.exception;
23 |
24 | /**
25 | * Exception thrown during tallying if an invalid decryption proof is found
26 | */
27 | public class InvalidDecryptionProofException extends Exception {
28 | public InvalidDecryptionProofException(String message) {
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/simulation/VoteProcessException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.simulation;
23 |
24 | /**
25 | * Exception thrown when an error occurs during the vote simulation process
26 | */
27 | public class VoteProcessException extends RuntimeException {
28 | public VoteProcessException(Throwable cause) {
29 | super(cause);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/exception/TallyingRuntimeException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.exception;
23 |
24 | /**
25 | * Exception thrown if a fatal error occurs during the tallying phase
26 | */
27 | public class TallyingRuntimeException extends RuntimeException {
28 | public TallyingRuntimeException(Exception cause) {
29 | super(cause);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/exception/VoteConfirmationException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.exception;
23 |
24 | /**
25 | * Exception thrown when an error occurs while the voting client is trying to confirm a vote
26 | */
27 | public class VoteConfirmationException extends Exception {
28 | public VoteConfirmationException(Exception cause) {
29 | super(cause);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/protocol/IncorrectBallotOrQueryException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.protocol;
23 |
24 | /**
25 | * Exception thrown when an incorrect ballot or an invalid query is submitted
26 | */
27 | public class IncorrectBallotOrQueryException extends Exception {
28 | public IncorrectBallotOrQueryException(Exception cause) {
29 | super(cause);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/exception/IncorrectBallotRuntimeException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.exception;
23 |
24 | /**
25 | * Exception thrown when an authority deems that a ballot was invalid.
26 | */
27 | public class IncorrectBallotRuntimeException extends RuntimeException {
28 | public IncorrectBallotRuntimeException(String message) {
29 | super(message);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/exception/InvalidShuffleProofRuntimeException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.exception;
23 |
24 | /**
25 | * Exception thrown by an authority if it detects an invalid shuffle proof
26 | */
27 | public class InvalidShuffleProofRuntimeException extends RuntimeException {
28 | public InvalidShuffleProofRuntimeException(String message) {
29 | super(message);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/simulation/FinalizationCodeNotMatchingException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.simulation;
23 |
24 | /**
25 | * Exception thrown by the voter simulator when the finalization code does not match
26 | */
27 | public class FinalizationCodeNotMatchingException extends Exception {
28 | public FinalizationCodeNotMatchingException(String message) {
29 | super(message);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/exception/NotEnoughPrimesInGroupException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.exception;
23 |
24 | /**
25 | * This exception is thrown when an attempt is made to generate more primes than are available in a group
26 | */
27 | public class NotEnoughPrimesInGroupException extends Exception {
28 | public NotEnoughPrimesInGroupException(String message) {
29 | super(message);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/simulation/VerificationCodesNotMatchingException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.simulation;
23 |
24 | /**
25 | * Exception thrown by the voter simulator when the verification codes do not match
26 | */
27 | public class VerificationCodesNotMatchingException extends Exception {
28 | public VerificationCodesNotMatchingException(String message) {
29 | super(message);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/exception/IncorrectConfirmationRuntimeException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.exception;
23 |
24 | /**
25 | * Exception thrown when an authority receives a confirmation that it deems incorrect
26 | */
27 | public class IncorrectConfirmationRuntimeException extends RuntimeException {
28 | public IncorrectConfirmationRuntimeException(String message) {
29 | super(message);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/exception/BallotNotFoundRuntimeException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.exception;
23 |
24 | /**
25 | * Exception thrown when a confirmation is submitted for a voter for which the system has no trace of a ballot being
26 | * submitted
27 | */
28 | public class BallotNotFoundRuntimeException extends RuntimeException {
29 | public BallotNotFoundRuntimeException(String msg) {
30 | super(msg);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/test/java/ch/ge/ve/protopoc/ProtocolPocApplicationTests.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc;
23 |
24 | import org.junit.Test;
25 | import org.junit.runner.RunWith;
26 | import org.springframework.boot.test.context.SpringBootTest;
27 | import org.springframework.test.context.junit4.SpringRunner;
28 |
29 | @RunWith(SpringRunner.class)
30 | @SpringBootTest
31 | public class ProtocolPocApplicationTests {
32 |
33 | @Test
34 | public void contextLoads() {
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/PrimeField.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import java.math.BigInteger;
25 |
26 | /**
27 | * The model class representing the prime field
28 | */
29 | public final class PrimeField {
30 | private final BigInteger p_prime;
31 |
32 | public PrimeField(BigInteger p_prime) {
33 | this.p_prime = p_prime;
34 | }
35 |
36 | public BigInteger getP_prime() {
37 | return p_prime;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/exception/InvalidObliviousTransferResponseException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.exception;
23 |
24 | /**
25 | * Exception thrown on the voting client when an invalid oblivious transfer response is detected.
26 | * (or a computation error occurred...)
27 | */
28 | public class InvalidObliviousTransferResponseException extends Exception {
29 | public InvalidObliviousTransferResponseException(String s) {
30 | super(s);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/exception/DigestInitialisationRuntimeException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.exception;
23 |
24 | /**
25 | * This is the exception thrown when an unexpected (and non recoverable) exception is encountered upon
26 | * initialising the required digests
27 | */
28 | public class DigestInitialisationRuntimeException extends RuntimeException {
29 | public DigestInitialisationRuntimeException(Throwable cause) {
30 | super(cause);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/controller/api/HomeInterface.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.controller.api;
23 |
24 | import org.springframework.security.access.prepost.PreAuthorize;
25 | import org.springframework.web.bind.annotation.RequestMapping;
26 |
27 | /**
28 | * This sample interface serves as example of the routing and access restriction mechanisms
29 | */
30 | public interface HomeInterface {
31 | @RequestMapping("/")
32 | @PreAuthorize("authenticated")
33 | String index();
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/jwt/JwtAuthenticationResponse.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.jwt;
23 |
24 | import java.io.Serializable;
25 |
26 | /**
27 | *
28 | */
29 | public class JwtAuthenticationResponse implements Serializable {
30 |
31 | private static final long serialVersionUID = 1250166508152483573L;
32 |
33 | private final String token;
34 |
35 | public JwtAuthenticationResponse(String token) {
36 | this.token = token;
37 | }
38 |
39 | public String getToken() {
40 | return this.token;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/model/repository/AccountRepository.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.model.repository;
23 |
24 | import ch.ge.ve.protopoc.model.entity.Account;
25 | import org.springframework.data.jpa.repository.JpaRepository;
26 | import org.springframework.data.querydsl.QueryDslPredicateExecutor;
27 |
28 | /**
29 | * Simple repository for the {@link Account} entities
30 | */
31 | public interface AccountRepository extends JpaRepository, QueryDslPredicateExecutor {
32 | Account findByUsername(String username);
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/exception/IncompatibleParametersRuntimeException.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.exception;
23 |
24 | /**
25 | * Exception thrown when applying the protocol results in an error situation due to parameters being incompatible.
26 | */
27 | public class IncompatibleParametersRuntimeException extends RuntimeException {
28 | public IncompatibleParametersRuntimeException(String s) {
29 | super(s);
30 | }
31 |
32 | public IncompatibleParametersRuntimeException(Throwable cause) {
33 | super(cause);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/controller/impl/HomeController.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.controller.impl;
23 |
24 | import ch.ge.ve.protopoc.controller.api.HomeInterface;
25 | import org.springframework.web.bind.annotation.RestController;
26 |
27 | /**
28 | * This sample controller shows an example of a simple REST method.
29 | *
30 | * Security is handled at the interface level
31 | */
32 | @RestController
33 | public class HomeController implements HomeInterface {
34 |
35 | @Override
36 | public String index() {
37 | return "Greetings from Spring Boot!";
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/protocol/VotingClientService.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.protocol;
23 |
24 | import ch.ge.ve.protopoc.service.exception.VoteCastingException;
25 | import ch.ge.ve.protopoc.service.exception.VoteConfirmationException;
26 | import ch.ge.ve.protopoc.service.model.VotingPageData;
27 |
28 | import java.util.List;
29 |
30 | /**
31 | * This interface defines the contract for the voting client
32 | */
33 | public interface VotingClientService {
34 | VotingPageData startVoteSession(Integer voterIndex);
35 |
36 | List sumbitVote(String identificationCredentials, List selections) throws VoteCastingException;
37 |
38 | String confirmVote(String confirmationCredentials) throws VoteConfirmationException;
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/Voter.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.util.ArrayList;
27 | import java.util.Arrays;
28 | import java.util.Collection;
29 |
30 | /**
31 | * Model class for the voter
32 | */
33 | public final class Voter {
34 | private Collection allowedDomainsOfInfluence = new ArrayList<>();
35 |
36 | public void addDomainsOfInfluence(DomainOfInfluence... domainsOfInfluence) {
37 | allowedDomainsOfInfluence.addAll(Arrays.asList(domainsOfInfluence));
38 | }
39 |
40 | public Collection getAllowedDomainsOfInfluence() {
41 | return ImmutableList.copyOf(allowedDomainsOfInfluence);
42 | }
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/ProtocolPocApplication.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc;
23 |
24 | import ch.ge.ve.protopoc.model.entity.Account;
25 | import ch.ge.ve.protopoc.model.repository.AccountRepository;
26 | import org.springframework.boot.CommandLineRunner;
27 | import org.springframework.boot.SpringApplication;
28 | import org.springframework.boot.autoconfigure.SpringBootApplication;
29 | import org.springframework.context.annotation.Bean;
30 |
31 | @SpringBootApplication
32 | public class ProtocolPocApplication {
33 |
34 | public static void main(String[] args) {
35 | SpringApplication.run(ProtocolPocApplication.class, args);
36 | }
37 |
38 | @Bean
39 | public CommandLineRunner demo(AccountRepository accountRepository) {
40 | return args -> accountRepository.save(new Account("user", "password"));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/protocol/AuthorityService.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.protocol;
23 |
24 | import ch.ge.ve.protopoc.service.model.*;
25 |
26 | import java.util.List;
27 |
28 | /**
29 | * This interface defines the contract for an authority
30 | */
31 | public interface AuthorityService {
32 | void generateKeys();
33 |
34 | void buildPublicKey();
35 |
36 | void generateElectorateData();
37 |
38 | List getPrivateCredentials();
39 |
40 | void buildPublicCredentials();
41 |
42 | ObliviousTransferResponse handleBallot(Integer voterIndex, BallotAndQuery ballotAndQuery);
43 |
44 | FinalizationCodePart handleConfirmation(Integer voterIndex, Confirmation confirmation);
45 |
46 | void startMixing();
47 |
48 | void mixAgain();
49 |
50 | void startPartialDecryption();
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/BallotQueryAndRand.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.math.BigInteger;
27 | import java.util.List;
28 |
29 | /**
30 | * Model class combining a ballot, the corresponding OT query and the vector of random elements used
31 | */
32 | public final class BallotQueryAndRand {
33 | private final BallotAndQuery alpha;
34 | private final List bold_r;
35 |
36 | public BallotQueryAndRand(BallotAndQuery alpha, List bold_r) {
37 | this.alpha = alpha;
38 | this.bold_r = ImmutableList.copyOf(bold_r);
39 | }
40 |
41 | public BallotAndQuery getAlpha() {
42 | return alpha;
43 | }
44 |
45 | public List getBold_r() {
46 | return ImmutableList.copyOf(bold_r);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/ObliviousTransferQuery.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.math.BigInteger;
27 | import java.util.List;
28 |
29 | /**
30 | * Model class for an Oblivious Transfer query
31 | */
32 | public final class ObliviousTransferQuery {
33 | private final List bold_a;
34 | private final List bold_r;
35 |
36 | public ObliviousTransferQuery(List bold_a, List bold_r) {
37 | this.bold_a = ImmutableList.copyOf(bold_a);
38 | this.bold_r = ImmutableList.copyOf(bold_r);
39 | }
40 |
41 | public List getBold_a() {
42 | return ImmutableList.copyOf(bold_a);
43 | }
44 |
45 | public List getBold_r() {
46 | return ImmutableList.copyOf(bold_r);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/doc/Implementation.md:
--------------------------------------------------------------------------------
1 | # Implementation
2 |
3 | ## Implementation status
4 |
5 | The table below contains information on the progress of the project for the _backend_.
6 |
7 | | Step | Status |
8 | | --------------------------------------- | -------------------- |
9 | | **_Implementation of the protocol_** | **_done_** |
10 | | - Initialization | done |
11 | | - Key generation | done |
12 | | - Electoral data | done |
13 | | - Code sheet printing | done |
14 | | - Vote casting | done |
15 | | - Mixing | done |
16 | | - Decryption | done |
17 | | - Tallying | done |
18 | | **_Simulation program_** | **_done_** |
19 | | - Initialization | done |
20 | | - Key generation | done |
21 | | - Electoral data | done |
22 | | - Code sheet printing | done |
23 | | - Vote casting | done |
24 | | - Mixing | done |
25 | | - Decryption | done |
26 | | - Tallying | done |
27 | | - performance measurements | done |
28 | | **_Rest services_** | **_todo_** |
29 | | - Scaffolding | done |
30 | | - Initialization | todo |
31 | | - Election administration | todo |
32 | | - Code sheet display | todo |
33 | | - Vote casting | todo |
34 | | - Decryption | todo |
35 | | - Tallying | todo |
36 |
37 | # Code structure
38 |
39 | ## Protocol
40 |
41 | All the elements required by the protocol can be found in the [service](src/main/java/ch/ge/ve/protopoc/service)
42 | package.
43 | - The [algorithm](../src/main/java/ch/ge/ve/protopoc/service/algorithm) package covers the algorithms defined in section 5
44 | of the specification
45 | - The [support](../src/main/java/ch/ge/ve/protopoc/service/support) package covers the prerequisites discussed in section 2
46 | - The [service/model](../src/main/java/ch/ge/ve/protopoc/service/model) package holds the model classes used to represent
47 | the tuples and values returned by the algorithms
48 |
49 | ## Simulation
50 |
51 | The simulation can be run by executing the
52 | [Simulation](../src/main/java/ch/ge/ve/protopoc/service/simulation/Simulation.java) class.
53 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/VotingPageData.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.util.List;
27 |
28 | /**
29 | * Model class containing the data necessary for presenting the voting page to the voter
30 | */
31 | public final class VotingPageData {
32 | private final List selectionCounts;
33 | private final List candidateCounts;
34 |
35 | public VotingPageData(List selectionCounts, List candidateCounts) {
36 | this.selectionCounts = ImmutableList.copyOf(selectionCounts);
37 | this.candidateCounts = ImmutableList.copyOf(candidateCounts);
38 | }
39 |
40 | public List getSelectionCounts() {
41 | return ImmutableList.copyOf(selectionCounts);
42 | }
43 |
44 | public List getCandidateCounts() {
45 | return ImmutableList.copyOf(candidateCounts);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/DomainOfInfluence.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import java.util.Objects;
25 |
26 | /**
27 | * Model class for the domain of influence (as per eCH-0155)
28 | */
29 | public final class DomainOfInfluence {
30 | private final String identifier;
31 |
32 | public DomainOfInfluence(String identifier) {
33 | this.identifier = identifier;
34 | }
35 |
36 | @Override
37 | public boolean equals(Object o) {
38 | if (this == o) return true;
39 | if (o == null || getClass() != o.getClass()) return false;
40 | DomainOfInfluence that = (DomainOfInfluence) o;
41 | return Objects.equals(identifier, that.identifier);
42 | }
43 |
44 | @Override
45 | public int hashCode() {
46 | return Objects.hash(identifier);
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return String.format("DomainOfInfluence{identifier='%s'}", identifier);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/Candidate.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import java.util.Objects;
25 |
26 | /**
27 | * This model class represents a candidate, along with their description
28 | */
29 | public final class Candidate {
30 | private final String candidateDescription;
31 |
32 | public Candidate(String candidateDescription) {
33 | this.candidateDescription = candidateDescription;
34 | }
35 |
36 | public String getCandidateDescription() {
37 | return candidateDescription;
38 | }
39 |
40 | @Override
41 | public boolean equals(Object o) {
42 | if (this == o) return true;
43 | if (o == null || getClass() != o.getClass()) return false;
44 | Candidate candidate = (Candidate) o;
45 | return Objects.equals(candidateDescription, candidate.candidateDescription);
46 | }
47 |
48 | @Override
49 | public int hashCode() {
50 | return Objects.hash(candidateDescription);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/jwt/JwtAuthenticationRequest.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.jwt;
23 |
24 | import java.io.Serializable;
25 |
26 | /**
27 | *
28 | */
29 | public class JwtAuthenticationRequest implements Serializable {
30 |
31 | private static final long serialVersionUID = -8445943548965154778L;
32 |
33 | private String username;
34 | private String password;
35 |
36 | public JwtAuthenticationRequest() {
37 | super();
38 | }
39 |
40 | public JwtAuthenticationRequest(String username, String password) {
41 | this.setUsername(username);
42 | this.setPassword(password);
43 | }
44 |
45 | public String getUsername() {
46 | return this.username;
47 | }
48 |
49 | public void setUsername(String username) {
50 | this.username = username;
51 | }
52 |
53 | public String getPassword() {
54 | return this.password;
55 | }
56 |
57 | public void setPassword(String password) {
58 | this.password = password;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/jwt/JwtUserFactory.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.jwt;
23 |
24 | import ch.ge.ve.protopoc.model.entity.Account;
25 | import ch.ge.ve.protopoc.model.entity.Authority;
26 | import org.springframework.security.core.GrantedAuthority;
27 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
28 |
29 | import java.util.List;
30 | import java.util.stream.Collectors;
31 |
32 | final class JwtUserFactory {
33 |
34 | private JwtUserFactory() {
35 | }
36 |
37 | static JwtUser create(Account account) {
38 | return new JwtUser(
39 | account.getId(),
40 | account.getUsername(),
41 | account.getPassword(),
42 | mapToGrantedAuthorities(account.getAuthorities())
43 | );
44 | }
45 |
46 | private static List mapToGrantedAuthorities(List authorities) {
47 | return authorities.stream()
48 | .map(authority -> new SimpleGrantedAuthority(authority.getName().name()))
49 | .collect(Collectors.toList());
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/Election.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | /**
25 | * An election has a number of candidates and a number of allowed selections.
26 | * It is applicable to a domain of influence.
27 | */
28 | public final class Election {
29 | private final int numberOfCandidates;
30 | private final int numberOfSelections;
31 | private final DomainOfInfluence applicableDomainofInfluence;
32 |
33 | public Election(int numberOfCandidates, int numberOfSelections, DomainOfInfluence applicableDomainofInfluence) {
34 | this.numberOfCandidates = numberOfCandidates;
35 | this.numberOfSelections = numberOfSelections;
36 | this.applicableDomainofInfluence = applicableDomainofInfluence;
37 | }
38 |
39 | public int getNumberOfCandidates() {
40 | return numberOfCandidates;
41 | }
42 |
43 | public int getNumberOfSelections() {
44 | return numberOfSelections;
45 | }
46 |
47 | public DomainOfInfluence getApplicableDomainofInfluence() {
48 | return applicableDomainofInfluence;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/model/entity/Authority.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.model.entity;
23 |
24 | import javax.persistence.*;
25 | import java.util.List;
26 |
27 | /**
28 | * Simple entity for holding authorities (currently only used for testing JWT)
29 | */
30 | @Entity
31 | public class Authority {
32 | @Id
33 | @GeneratedValue(strategy = GenerationType.IDENTITY)
34 | private Long id;
35 |
36 | @Enumerated(EnumType.STRING)
37 | private AuthorityName name;
38 |
39 | @ManyToMany(mappedBy = "authorities")
40 | private List accounts;
41 |
42 | public Long getId() {
43 | return id;
44 | }
45 |
46 | public void setId(Long id) {
47 | this.id = id;
48 | }
49 |
50 | public AuthorityName getName() {
51 | return name;
52 | }
53 |
54 | public void setName(AuthorityName name) {
55 | this.name = name;
56 | }
57 |
58 | public List getAccounts() {
59 | return accounts;
60 | }
61 |
62 | public void setAccounts(List accounts) {
63 | this.accounts = accounts;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/BallotAndQuery.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.math.BigInteger;
27 | import java.util.List;
28 |
29 | /**
30 | * Model class combining a ballot and a OT query
31 | */
32 | public final class BallotAndQuery {
33 |
34 | private final BigInteger x_hat;
35 | private final List bold_a;
36 | private final BigInteger b;
37 | private final NonInteractiveZKP pi;
38 |
39 | public BallotAndQuery(BigInteger x_hat, List bold_a, BigInteger b, NonInteractiveZKP pi) {
40 | this.x_hat = x_hat;
41 | this.bold_a = ImmutableList.copyOf(bold_a);
42 | this.b = b;
43 | this.pi = pi;
44 | }
45 |
46 | public BigInteger getX_hat() {
47 | return x_hat;
48 | }
49 |
50 | public List getBold_a() {
51 | return bold_a;
52 | }
53 |
54 | public BigInteger getB() {
55 | return b;
56 | }
57 |
58 | public NonInteractiveZKP getPi() {
59 | return pi;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/ShufflesAndProofs.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.util.List;
27 | import java.util.stream.Collectors;
28 |
29 | /**
30 | * Model class containing the shuffles (re-encrypted, shuffled ballots) and the shuffle proofs
31 | */
32 | public final class ShufflesAndProofs {
33 | private final List> shuffles;
34 | private final List shuffleProofs;
35 |
36 |
37 | public ShufflesAndProofs(List> shuffles, List shuffleProofs) {
38 | this.shuffles = shuffles.parallelStream().map(ImmutableList::copyOf).collect(Collectors.toList());
39 | this.shuffleProofs = ImmutableList.copyOf(shuffleProofs);
40 | }
41 |
42 | public List> getShuffles() {
43 | return shuffles.parallelStream().map(ImmutableList::copyOf).collect(Collectors.toList());
44 | }
45 |
46 | public List getShuffleProofs() {
47 | return ImmutableList.copyOf(shuffleProofs);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/support/BigIntegers.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.support;
23 |
24 | import java.math.BigInteger;
25 | import java.util.function.BinaryOperator;
26 |
27 | /**
28 | * Commonly used BigInteger values.
29 | */
30 | public interface BigIntegers {
31 | BigInteger TWO = BigInteger.valueOf(2L);
32 | BigInteger THREE = BigInteger.valueOf(3L);
33 | BigInteger FOUR = BigInteger.valueOf(4L);
34 | BigInteger FIVE = BigInteger.valueOf(5L);
35 | BigInteger SIX = BigInteger.valueOf(6L);
36 | BigInteger SEVEN = BigInteger.valueOf(7L);
37 | BigInteger EIGHT = BigInteger.valueOf(8L);
38 | BigInteger NINE = BigInteger.valueOf(9L);
39 | BigInteger ELEVEN = BigInteger.valueOf(11L);
40 |
41 | /**
42 | * Get the operator for multiplying two BigIntegers modulo a fixed one
43 | *
44 | * @param m the modulus
45 | * @return an operator on two BigIntegers, multiplying them modulo m
46 | */
47 | static BinaryOperator multiplyMod(BigInteger m) {
48 | return (a, b) -> a.multiply(b).mod(m);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/controller/api/AuthenticationInterface.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.controller.api;
23 |
24 | import ch.ge.ve.protopoc.jwt.JwtAuthenticationRequest;
25 | import org.springframework.http.ResponseEntity;
26 | import org.springframework.security.access.prepost.PreAuthorize;
27 | import org.springframework.web.bind.annotation.RequestBody;
28 | import org.springframework.web.bind.annotation.RequestMapping;
29 | import org.springframework.web.bind.annotation.RequestMethod;
30 |
31 | import javax.servlet.http.HttpServletRequest;
32 |
33 | /**
34 | * This interface defines the contracts for an {@link ch.ge.ve.protopoc.controller.impl.AuthenticationController}
35 | */
36 | public interface AuthenticationInterface {
37 | @RequestMapping(value = "/auth/login", method = RequestMethod.POST)
38 | ResponseEntity> createAuthenticationToken(@RequestBody JwtAuthenticationRequest authenticationRequest);
39 |
40 | @RequestMapping(value = "/auth/renew", method = RequestMethod.GET)
41 | @PreAuthorize(value = "authenticated")
42 | ResponseEntity> renewAuthenticationToken(HttpServletRequest request);
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/IdentificationGroup.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.base.Preconditions;
25 |
26 | import java.math.BigInteger;
27 |
28 | /**
29 | * The model class representing the identification group
30 | */
31 | public final class IdentificationGroup {
32 | private final BigInteger p_hat;
33 | private final BigInteger q_hat;
34 | private final BigInteger g_hat;
35 |
36 | public IdentificationGroup(BigInteger p_hat, BigInteger q_hat, BigInteger g_hat) {
37 | Preconditions.checkArgument(q_hat.bitLength() <= p_hat.bitLength());
38 | Preconditions.checkArgument(g_hat.compareTo(BigInteger.ONE) != 0);
39 | Preconditions.checkArgument(p_hat.subtract(BigInteger.ONE).mod(q_hat)
40 | .compareTo(BigInteger.ZERO) == 0);
41 | this.p_hat = p_hat;
42 | this.q_hat = q_hat;
43 | this.g_hat = g_hat;
44 | }
45 |
46 | public BigInteger getP_hat() {
47 | return p_hat;
48 | }
49 |
50 | public BigInteger getQ_hat() {
51 | return q_hat;
52 | }
53 |
54 | public BigInteger getG_hat() {
55 | return g_hat;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/jwt/JwtAuthenticationEntryPoint.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.jwt;
23 |
24 | import org.springframework.security.core.AuthenticationException;
25 | import org.springframework.security.web.AuthenticationEntryPoint;
26 | import org.springframework.stereotype.Component;
27 |
28 | import javax.servlet.http.HttpServletRequest;
29 | import javax.servlet.http.HttpServletResponse;
30 | import java.io.IOException;
31 | import java.io.Serializable;
32 |
33 | @Component
34 | public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable {
35 |
36 | private static final long serialVersionUID = -8970718410437077606L;
37 |
38 | @Override
39 | public void commence(HttpServletRequest request,
40 | HttpServletResponse response,
41 | AuthenticationException authException) throws IOException {
42 | // This is invoked when user tries to access a secured REST resource without supplying any credentials
43 | // We should just send a 401 Unauthorized response because there is no 'login page' to redirect to
44 | response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
45 | }
46 | }
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/jwt/JwtUserDetailsServiceImpl.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.jwt;
23 |
24 | import ch.ge.ve.protopoc.model.entity.Account;
25 | import ch.ge.ve.protopoc.model.repository.AccountRepository;
26 | import org.springframework.beans.factory.annotation.Autowired;
27 | import org.springframework.security.core.userdetails.UserDetails;
28 | import org.springframework.security.core.userdetails.UserDetailsService;
29 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
30 | import org.springframework.stereotype.Service;
31 |
32 | /**
33 | *
34 | */
35 | @Service
36 | public class JwtUserDetailsServiceImpl implements UserDetailsService {
37 |
38 | @Autowired
39 | private AccountRepository accountRepository;
40 |
41 | @Override
42 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
43 | Account account = accountRepository.findByUsername(username);
44 |
45 | if (account == null) {
46 | throw new UsernameNotFoundException(String.format("No user found with username '%s'.", username));
47 | } else {
48 | return JwtUserFactory.create(account);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/DecryptionProof.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.math.BigInteger;
27 | import java.util.List;
28 | import java.util.Objects;
29 |
30 | /**
31 | * Model class for a decryption proof such as those generated by algorithm 5.50
32 | */
33 | public final class DecryptionProof {
34 | private final List t;
35 | private final BigInteger s;
36 |
37 | public DecryptionProof(List t, BigInteger s) {
38 | this.t = ImmutableList.copyOf(t);
39 | this.s = s;
40 | }
41 |
42 | public List getT() {
43 | return ImmutableList.copyOf(t);
44 | }
45 |
46 | public BigInteger getS() {
47 | return s;
48 | }
49 |
50 | @Override
51 | public boolean equals(Object o) {
52 | if (this == o) return true;
53 | if (o == null || getClass() != o.getClass()) return false;
54 | DecryptionProof that = (DecryptionProof) o;
55 | return Objects.equals(t, that.t) &&
56 | Objects.equals(s, that.s);
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | return Objects.hash(t, s);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/ConfirmationEntry.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import java.util.Objects;
25 |
26 | /**
27 | * Model class for the entries of the confirmation list held by each authority
28 | */
29 | public final class ConfirmationEntry {
30 | private final Integer i;
31 | private final Confirmation gamma;
32 |
33 | public ConfirmationEntry(Integer i, Confirmation gamma) {
34 | this.i = i;
35 | this.gamma = gamma;
36 | }
37 |
38 | public Integer getI() {
39 | return i;
40 | }
41 |
42 | public Confirmation getGamma() {
43 | return gamma;
44 | }
45 |
46 | @Override
47 | public boolean equals(Object o) {
48 | if (this == o) return true;
49 | if (o == null || getClass() != o.getClass()) return false;
50 | ConfirmationEntry that = (ConfirmationEntry) o;
51 | return Objects.equals(i, that.i) &&
52 | Objects.equals(gamma, that.gamma);
53 | }
54 |
55 | @Override
56 | public int hashCode() {
57 | return Objects.hash(i, gamma);
58 | }
59 |
60 | @Override
61 | public String toString() {
62 | return String.format("ConfirmationEntry{i=%d, gamma=%s}", i, gamma);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/EncryptionPublicKey.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import ch.ge.ve.protopoc.service.support.Conversion;
25 |
26 | import java.math.BigInteger;
27 | import java.security.PublicKey;
28 |
29 | /**
30 | * This model class holds the value of an encryption public key
31 | */
32 | public final class EncryptionPublicKey implements PublicKey {
33 | private final BigInteger publicKey;
34 | private final EncryptionGroup encryptionGroup;
35 | private final transient Conversion conversion = new Conversion();
36 |
37 | public EncryptionPublicKey(BigInteger publicKey, EncryptionGroup encryptionGroup) {
38 | this.publicKey = publicKey;
39 | this.encryptionGroup = encryptionGroup;
40 | }
41 |
42 |
43 | @Override
44 | public String getAlgorithm() {
45 | return null;
46 | }
47 |
48 | @Override
49 | public String getFormat() {
50 | return null;
51 | }
52 |
53 | @Override
54 | public byte[] getEncoded() {
55 | return conversion.toByteArray(publicKey);
56 | }
57 |
58 | public BigInteger getPublicKey() {
59 | return publicKey;
60 | }
61 |
62 | public EncryptionGroup getEncryptionGroup() {
63 | return encryptionGroup;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/EncryptionPrivateKey.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import ch.ge.ve.protopoc.service.support.Conversion;
25 |
26 | import java.math.BigInteger;
27 | import java.security.PrivateKey;
28 |
29 | /**
30 | * This model class holds the value of an encryption private key
31 | */
32 | public final class EncryptionPrivateKey implements PrivateKey {
33 | private final BigInteger privateKey;
34 | private final EncryptionGroup encryptionGroup;
35 | private final transient Conversion conversion = new Conversion();
36 |
37 | public EncryptionPrivateKey(BigInteger privateKey, EncryptionGroup encryptionGroup) {
38 | this.privateKey = privateKey;
39 | this.encryptionGroup = encryptionGroup;
40 | }
41 |
42 | @Override
43 | public String getAlgorithm() {
44 | return null;
45 | }
46 |
47 | @Override
48 | public String getFormat() {
49 | return null;
50 | }
51 |
52 | @Override
53 | public byte[] getEncoded() {
54 | return conversion.toByteArray(privateKey);
55 | }
56 |
57 | public BigInteger getPrivateKey() {
58 | return privateKey;
59 | }
60 |
61 | public EncryptionGroup getEncryptionGroup() {
62 | return encryptionGroup;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/Confirmation.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import java.math.BigInteger;
25 | import java.util.Objects;
26 |
27 | /**
28 | * Model class containing the necessary information for confirmation of the vote
29 | */
30 | public final class Confirmation {
31 | private final BigInteger y_hat;
32 | private final NonInteractiveZKP pi;
33 |
34 | public Confirmation(BigInteger y_hat, NonInteractiveZKP pi) {
35 | this.y_hat = y_hat;
36 | this.pi = pi;
37 | }
38 |
39 | public BigInteger getY_hat() {
40 | return y_hat;
41 | }
42 |
43 | public NonInteractiveZKP getPi() {
44 | return pi;
45 | }
46 |
47 | @Override
48 | public boolean equals(Object o) {
49 | if (this == o) return true;
50 | if (o == null || getClass() != o.getClass()) return false;
51 | Confirmation that = (Confirmation) o;
52 | return Objects.equals(y_hat, that.y_hat) &&
53 | Objects.equals(pi, that.pi);
54 | }
55 |
56 | @Override
57 | public int hashCode() {
58 | return Objects.hash(y_hat, pi);
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | return String.format("Confirmation{y_hat=%s, pi=%s}", y_hat, pi);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/FinalizationCodePart.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.math.BigInteger;
27 | import java.util.Arrays;
28 | import java.util.List;
29 | import java.util.Objects;
30 |
31 | /**
32 | * Part of the finalization code generated by one authority
33 | */
34 | public final class FinalizationCodePart {
35 | private final byte[] F;
36 | private final List bold_r;
37 |
38 | public FinalizationCodePart(byte[] f, List bold_r) {
39 | F = f;
40 | this.bold_r = ImmutableList.copyOf(bold_r);
41 | }
42 |
43 | public byte[] getF() {
44 | return F;
45 | }
46 |
47 | public List getBold_r() {
48 | return ImmutableList.copyOf(bold_r);
49 | }
50 |
51 | @Override
52 | public boolean equals(Object o) {
53 | if (this == o) return true;
54 | if (o == null || getClass() != o.getClass()) return false;
55 | FinalizationCodePart that = (FinalizationCodePart) o;
56 | return Arrays.equals(F, that.F) &&
57 | Objects.equals(bold_r, that.bold_r);
58 | }
59 |
60 | @Override
61 | public int hashCode() {
62 | return Objects.hash(F, bold_r);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/groovy/ch/ge/ve/protopoc/service/support/ByteArrayUtilsTest.groovy:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.support
23 |
24 | import spock.lang.Specification
25 |
26 | /**
27 | * This test class holds the tests for the utility methods defined in ByteArrayUtils
28 | */
29 | class ByteArrayUtilsTest extends Specification {
30 |
31 | def "markByteArray should watermark the target array according to spec"() {
32 | expect:
33 | ByteArrayUtils.markByteArray(upper_b as byte[], m, m_max) == (result as byte[])
34 |
35 | where:
36 | upper_b | m | m_max || result
37 | [0x00] | 0 | 3 || [0x00] // (0x00 & 0xFE) & 0xEF
38 | [0x00] | 1 | 3 || [0x01] // (0x00 | 0x01) & 0xEF
39 | [0x00] | 2 | 3 || [0x10] // (0x00 & 0xFE) | 0x10
40 | [0x00] | 3 | 3 || [0x11] // (0x00 | 0x01) | 0x10
41 | [0xFF, 0xFF, 0xFF, 0xFF] | 0 | 3 || [0xFE, 0xFF, 0xFE, 0xFF]
42 | [0xC1, 0xD2] | 0 | 3 || [0xC0, 0xD2]
43 | [0xC1, 0xD2] | 1 | 3 || [0xC1, 0xD2]
44 | [0xC1, 0xD2] | 0 | 15 || [0xC0, 0xC2]
45 | [0xCC, 0xDD] | 0 | 15 || [0xCC, 0xCC]
46 | [0xE3, 0xF4] | 1 | 3 || [0xE3, 0xF4]
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/groovy/ch/ge/ve/protopoc/service/support/JacobiSymbolTest.groovy:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.support
23 |
24 | import spock.lang.Specification
25 |
26 | /**
27 | * This test class holds the tests for the algorithm defined in {@link JacobiSymbol}
28 | */
29 | class JacobiSymbolTest extends Specification {
30 | JacobiSymbol jacobiSymbol
31 |
32 | void setup() {
33 | jacobiSymbol = new JacobiSymbol()
34 | }
35 |
36 | /**
37 | * Sample values taken from Wikipedia's table of values
38 | * @return
39 | */
40 | def "getJacobiSymbol"() {
41 | expect:
42 | jacobiSymbol.computeJacobiSymbol(a, n) == i
43 |
44 | where:
45 | a | n | i
46 | BigInteger.ONE | BigInteger.ONE | 1
47 | BigIntegers.THREE | BigIntegers.THREE | 0
48 | BigInteger.TEN | BigInteger.valueOf(11L) | -1
49 | BigInteger.valueOf(14L) | BigInteger.valueOf(51L) | 1
50 | BigInteger.valueOf(15L) | BigInteger.valueOf(51L) | 0
51 | BigInteger.valueOf(14L) | BigInteger.valueOf(59L) | -1
52 | BigInteger.valueOf(15L) | BigInteger.valueOf(59L) | 1
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/CommitmentChain.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.math.BigInteger;
27 | import java.util.List;
28 | import java.util.Objects;
29 |
30 | /**
31 | * Model class representing a commitment chain, as returned by algorithm 5.47
32 | */
33 | public final class CommitmentChain {
34 | private final List bold_c;
35 | private final List bold_r;
36 |
37 | public CommitmentChain(List bold_c, List bold_r) {
38 | this.bold_c = ImmutableList.copyOf(bold_c);
39 | this.bold_r = ImmutableList.copyOf(bold_r);
40 | }
41 |
42 | public List getBold_c() {
43 | return ImmutableList.copyOf(bold_c);
44 | }
45 |
46 | public List getBold_r() {
47 | return ImmutableList.copyOf(bold_r);
48 | }
49 |
50 | @Override
51 | public boolean equals(Object o) {
52 | if (this == o) return true;
53 | if (o == null || getClass() != o.getClass()) return false;
54 | CommitmentChain that = (CommitmentChain) o;
55 | return Objects.equals(bold_c, that.bold_c) &&
56 | Objects.equals(bold_r, that.bold_r);
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | return Objects.hash(bold_c, bold_r);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/PermutationCommitment.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.math.BigInteger;
27 | import java.util.List;
28 | import java.util.Objects;
29 |
30 | /**
31 | * Model class representing a permutation commitment
32 | */
33 | public final class PermutationCommitment {
34 | private final List bold_c;
35 | private final List bold_r;
36 |
37 | public PermutationCommitment(List bold_c, List bold_r) {
38 | this.bold_c = ImmutableList.copyOf(bold_c);
39 | this.bold_r = ImmutableList.copyOf(bold_r);
40 | }
41 |
42 | public List getBold_c() {
43 | return ImmutableList.copyOf(bold_c);
44 | }
45 |
46 | public List getBold_r() {
47 | return ImmutableList.copyOf(bold_r);
48 | }
49 |
50 | @Override
51 | public boolean equals(Object o) {
52 | if (this == o) return true;
53 | if (o == null || getClass() != o.getClass()) return false;
54 | PermutationCommitment that = (PermutationCommitment) o;
55 | return Objects.equals(bold_c, that.bold_c) &&
56 | Objects.equals(bold_r, that.bold_r);
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | return Objects.hash(bold_c, bold_r);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/ElectorateData.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import ch.ge.ve.protopoc.service.model.polynomial.Point;
25 | import com.google.common.collect.ImmutableList;
26 |
27 | import java.util.List;
28 |
29 | /**
30 | * Model class holding data for the whole electorate
31 | */
32 | public final class ElectorateData {
33 | private final List d;
34 | private final List d_hat;
35 | private final List> P;
36 | private final List> K;
37 |
38 | public ElectorateData(List secretVoterDataList, List publicVoterDataList, List> randomPoints, List> allowedSelections) {
39 | this.d = ImmutableList.copyOf(secretVoterDataList);
40 | this.d_hat = ImmutableList.copyOf(publicVoterDataList);
41 | this.P = ImmutableList.copyOf(randomPoints);
42 | this.K = ImmutableList.copyOf(allowedSelections);
43 | }
44 |
45 | public List getD() {
46 | return ImmutableList.copyOf(d);
47 | }
48 |
49 | public List getD_hat() {
50 | return ImmutableList.copyOf(d_hat);
51 | }
52 |
53 | public List> getP() {
54 | return ImmutableList.copyOf(P);
55 | }
56 |
57 | public List> getK() {
58 | return ImmutableList.copyOf(K);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/polynomial/PointsAndZeroImages.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model.polynomial;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.math.BigInteger;
27 | import java.util.List;
28 | import java.util.Objects;
29 |
30 | /**
31 | * Model class combining a list of points and y-images of 0 for a set of polynomials
32 | */
33 | public final class PointsAndZeroImages {
34 | private final List points;
35 | private final List y0s;
36 |
37 | public PointsAndZeroImages(List points, List y0s) {
38 | this.points = ImmutableList.copyOf(points);
39 | this.y0s = ImmutableList.copyOf(y0s);
40 | }
41 |
42 | public List getPoints() {
43 | return ImmutableList.copyOf(points);
44 | }
45 |
46 | public List getY0s() {
47 | return ImmutableList.copyOf(y0s);
48 | }
49 |
50 | @Override
51 | public boolean equals(Object o) {
52 | if (this == o) return true;
53 | if (o == null || getClass() != o.getClass()) return false;
54 | PointsAndZeroImages that = (PointsAndZeroImages) o;
55 | return Objects.equals(points, that.points) &&
56 | Objects.equals(y0s, that.y0s);
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | return Objects.hash(points, y0s);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/NonInteractiveZKP.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.math.BigInteger;
27 | import java.util.List;
28 | import java.util.Objects;
29 |
30 | /**
31 | * A non-interactive ZKP
32 | */
33 | public final class NonInteractiveZKP {
34 | private final List t;
35 | private final List s;
36 |
37 | public NonInteractiveZKP(List t, List s) {
38 | this.t = ImmutableList.copyOf(t);
39 | this.s = ImmutableList.copyOf(s);
40 | }
41 |
42 | public List getT() {
43 | return ImmutableList.copyOf(t);
44 | }
45 |
46 | public List getS() {
47 | return ImmutableList.copyOf(s);
48 | }
49 |
50 | @Override
51 | public boolean equals(Object o) {
52 | if (this == o) return true;
53 | if (o == null || getClass() != o.getClass()) return false;
54 | NonInteractiveZKP that = (NonInteractiveZKP) o;
55 | return Objects.equals(t, that.t) &&
56 | Objects.equals(s, that.s);
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | return Objects.hash(t, s);
62 | }
63 |
64 | @Override
65 | public String toString() {
66 | return String.format("NonInteractiveZKP{t=%s, s=%s}", t, s);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/SecurityParameters.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.base.Preconditions;
25 |
26 | /**
27 | * This class defines the security parameters to be used
28 | */
29 | public final class SecurityParameters {
30 | /**
31 | * Minimal privacy security level σ
32 | */
33 | private final int sigma;
34 |
35 | /**
36 | * Minimal integrity security level τ
37 | */
38 | private final int tau;
39 |
40 | /**
41 | * Output length of collision-resistant hash-function upper_l (in bytes)
42 | */
43 | private final int upper_l;
44 |
45 | /**
46 | * Deterrence factor ε (with 0 < ε ≤ 1)
47 | */
48 | private final double epsilon;
49 |
50 | public SecurityParameters(int sigma, int tau, int upper_l, double epsilon) {
51 | Preconditions.checkArgument(upper_l >= Math.max(sigma, tau) / 4.0);
52 | Preconditions.checkArgument(0.0 < epsilon && epsilon <= 1.0);
53 | this.sigma = sigma;
54 | this.tau = tau;
55 | this.upper_l = upper_l;
56 | this.epsilon = epsilon;
57 | }
58 |
59 | public int getSigma() {
60 | return sigma;
61 | }
62 |
63 | public int getTau() {
64 | return tau;
65 | }
66 |
67 | public int getUpper_l() {
68 | return upper_l;
69 | }
70 |
71 | public double getEpsilon() {
72 | return epsilon;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/polynomial/Point.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model.polynomial;
23 |
24 | import ch.ge.ve.protopoc.service.support.Hash;
25 | import com.google.common.base.MoreObjects;
26 |
27 | import java.math.BigInteger;
28 | import java.util.Objects;
29 |
30 | /**
31 | * Model class for a geometric point
32 | */
33 | public final class Point implements Hash.Hashable {
34 | public final BigInteger x;
35 | public final BigInteger y;
36 |
37 | public Point(BigInteger x, BigInteger y) {
38 | this.x = x;
39 | this.y = y;
40 | }
41 |
42 | @Override
43 | public Object[] elementsToHash() {
44 | BigInteger[] elementsToHash = new BigInteger[2];
45 | elementsToHash[0] = x;
46 | elementsToHash[1] = y;
47 | return elementsToHash;
48 | }
49 |
50 | @Override
51 | public boolean equals(Object o) {
52 | if (this == o) return true;
53 | if (o == null || getClass() != o.getClass()) return false;
54 | Point point = (Point) o;
55 | return Objects.equals(x, point.x) &&
56 | Objects.equals(y, point.y);
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | return Objects.hash(x, y);
62 | }
63 |
64 | @Override
65 | public String toString() {
66 | return MoreObjects.toStringHelper(this)
67 | .add("x", x)
68 | .add("y", y)
69 | .toString();
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/ReEncryption.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import java.math.BigInteger;
25 | import java.util.Objects;
26 |
27 | /**
28 | * Model class used to represent a "re-encryption", i.e. the resulting encryption and the randomness used
29 | */
30 | public final class ReEncryption {
31 | private final Encryption encryption;
32 | private final BigInteger randomness;
33 |
34 | public ReEncryption(Encryption encryption, BigInteger randomness) {
35 | this.encryption = encryption;
36 | this.randomness = randomness;
37 | }
38 |
39 | public Encryption getEncryption() {
40 | return encryption;
41 | }
42 |
43 | public BigInteger getRandomness() {
44 | return randomness;
45 | }
46 |
47 | @Override
48 | public boolean equals(Object o) {
49 | if (this == o) return true;
50 | if (o == null || getClass() != o.getClass()) return false;
51 | ReEncryption that = (ReEncryption) o;
52 | return Objects.equals(encryption, that.encryption) &&
53 | Objects.equals(randomness, that.randomness);
54 | }
55 |
56 | @Override
57 | public int hashCode() {
58 | return Objects.hash(encryption, randomness);
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | return "ReEncryption{" +
64 | "encryption=" + encryption +
65 | ", randomness=" + randomness +
66 | '}';
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/BallotEntry.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.math.BigInteger;
27 | import java.util.List;
28 | import java.util.Objects;
29 |
30 | /**
31 | * This model class holds the necessary data an entry in the ballot list held by the authorities
32 | */
33 | public final class BallotEntry {
34 | private final Integer i;
35 | private final BallotAndQuery alpha;
36 | private final List bold_r;
37 |
38 | public BallotEntry(Integer i, BallotAndQuery alpha, List bold_r) {
39 | this.i = i;
40 | this.alpha = alpha;
41 | this.bold_r = ImmutableList.copyOf(bold_r);
42 | }
43 |
44 | public Integer getI() {
45 | return i;
46 | }
47 |
48 | public BallotAndQuery getAlpha() {
49 | return alpha;
50 | }
51 |
52 | public List getBold_r() {
53 | return ImmutableList.copyOf(bold_r);
54 | }
55 |
56 | @Override
57 | public boolean equals(Object o) {
58 | if (this == o) return true;
59 | if (o == null || getClass() != o.getClass()) return false;
60 | BallotEntry that = (BallotEntry) o;
61 | return Objects.equals(i, that.i) &&
62 | Objects.equals(alpha, that.alpha) &&
63 | Objects.equals(bold_r, that.bold_r);
64 | }
65 |
66 | @Override
67 | public int hashCode() {
68 | return Objects.hash(i, alpha, bold_r);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/test/groovy/ch/ge/ve/protopoc/service/algorithm/VoteConfirmationVoterAlgorithmsTest.groovy:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.algorithm
23 |
24 | import spock.lang.Specification
25 |
26 | /**
27 | * Tests on the vote confirmation algorithms performed by the voter
28 | */
29 | class VoteConfirmationVoterAlgorithmsTest extends Specification {
30 | VoteConfirmationVoterAlgorithms voteConfirmationVoter
31 |
32 | void setup() {
33 | voteConfirmationVoter = new VoteConfirmationVoterAlgorithms()
34 | }
35 |
36 | def "checkReturnCodes should verify verification codes"() {
37 | expect:
38 | result == voteConfirmationVoter.checkReturnCodes(bold_rc, bold_rc_prime, bold_s)
39 |
40 | where:
41 | bold_rc | bold_rc_prime | bold_s || result
42 | ["a", "b", "c", "d"] | ["c"] | [3] || true
43 | ["a", "b", "c", "d"] | ["b", "d"] | [2, 4] || true
44 | ["ab", "cd"] | ["ab"] | [1] || true
45 | ["a", "b", "c", "d"] | ["d"] | [3] || false
46 | ["a", "b", "c", "d"] | ["b", "c"] | [2, 4] || false
47 | ["ab", "cd"] | ["cd"] | [1] || false
48 | }
49 |
50 | def "checkFinalizationCode should verify the finalization code"() {
51 | expect:
52 | result == voteConfirmationVoter.checkFinalizationCode(F, F_prime)
53 |
54 | where:
55 | F | F_prime || result
56 | "a" | "a" || true
57 | "ab" | "ab" || true
58 | "a" | "ab" || false
59 | "ab" | "a" || false
60 | "ab" | "AB" || false
61 | "Ab" | "ab" || false
62 |
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/ObliviousTransferResponseAndRand.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.math.BigInteger;
27 | import java.util.List;
28 | import java.util.Objects;
29 |
30 | /**
31 | * Model class representing the tuple <beta, bold_r>, returned by Algorithm 5.28
32 | */
33 | public final class ObliviousTransferResponseAndRand {
34 | private final ObliviousTransferResponse beta;
35 | private final List bold_r;
36 |
37 | public ObliviousTransferResponseAndRand(ObliviousTransferResponse beta, List bold_r) {
38 | this.beta = beta;
39 | this.bold_r = ImmutableList.copyOf(bold_r);
40 | }
41 |
42 | public ObliviousTransferResponse getBeta() {
43 | return beta;
44 | }
45 |
46 | public List getBold_r() {
47 | return ImmutableList.copyOf(bold_r);
48 | }
49 |
50 | @Override
51 | public boolean equals(Object o) {
52 | if (this == o) return true;
53 | if (o == null || getClass() != o.getClass()) return false;
54 | ObliviousTransferResponseAndRand that = (ObliviousTransferResponseAndRand) o;
55 | return Objects.equals(beta, that.beta) &&
56 | Objects.equals(bold_r, that.bold_r);
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | return Objects.hash(beta, bold_r);
62 | }
63 |
64 | @Override
65 | public String toString() {
66 | return "ObliviousTransferResponseAndRand{" + "beta=" + beta +
67 | ", bold_r=" + bold_r +
68 | '}';
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/ElectionSet.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.base.Preconditions;
25 | import com.google.common.collect.ImmutableList;
26 |
27 | import java.util.List;
28 | import java.util.stream.Collectors;
29 |
30 | /**
31 | * Model class containing the definition of a set of elections
32 | */
33 | public final class ElectionSet {
34 | private final List voters;
35 | private final List candidates;
36 | private final List elections;
37 |
38 | public ElectionSet(List voters, List candidates, List elections) {
39 | Preconditions.checkArgument(candidates.size() ==
40 | elections.stream().map(Election::getNumberOfCandidates).reduce((a, b) -> a + b).orElse(0));
41 | this.voters = ImmutableList.copyOf(voters);
42 | this.candidates = ImmutableList.copyOf(candidates);
43 | this.elections = ImmutableList.copyOf(elections);
44 | }
45 |
46 | public boolean isEligible(Voter voter, Election election) {
47 | return voter.getAllowedDomainsOfInfluence().contains(election.getApplicableDomainofInfluence());
48 | }
49 |
50 | public List getBold_n() {
51 | return elections.stream().map(Election::getNumberOfCandidates).collect(Collectors.toList());
52 | }
53 |
54 | public List getVoters() {
55 | return ImmutableList.copyOf(voters);
56 | }
57 |
58 | public List getCandidates() {
59 | return ImmutableList.copyOf(candidates);
60 | }
61 |
62 | public List getElections() {
63 | return ImmutableList.copyOf(elections);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/Shuffle.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import com.google.common.collect.ImmutableList;
25 |
26 | import java.math.BigInteger;
27 | import java.util.List;
28 | import java.util.Objects;
29 |
30 | /**
31 | * Model class representing the result of a shuffle
32 | */
33 | public final class Shuffle {
34 | private final List bold_e_prime;
35 | private final List bold_r_prime;
36 | private final List psy;
37 |
38 | public Shuffle(List bold_e_prime, List bold_r_prime, List psy) {
39 | this.bold_e_prime = ImmutableList.copyOf(bold_e_prime);
40 | this.bold_r_prime = ImmutableList.copyOf(bold_r_prime);
41 | this.psy = ImmutableList.copyOf(psy);
42 | }
43 |
44 | public List getBold_e_prime() {
45 | return ImmutableList.copyOf(bold_e_prime);
46 | }
47 |
48 | public List getBold_r_prime() {
49 | return ImmutableList.copyOf(bold_r_prime);
50 | }
51 |
52 | public List getPsy() {
53 | return ImmutableList.copyOf(psy);
54 | }
55 |
56 | @Override
57 | public boolean equals(Object o) {
58 | if (this == o) return true;
59 | if (o == null || getClass() != o.getClass()) return false;
60 | Shuffle shuffle = (Shuffle) o;
61 | return Objects.equals(bold_e_prime, shuffle.bold_e_prime) &&
62 | Objects.equals(bold_r_prime, shuffle.bold_r_prime) &&
63 | Objects.equals(psy, shuffle.psy);
64 | }
65 |
66 | @Override
67 | public int hashCode() {
68 | return Objects.hash(bold_e_prime, bold_r_prime, psy);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/protocol/BulletinBoardService.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.protocol;
23 |
24 | import ch.ge.ve.protopoc.service.exception.IncorrectConfirmationRuntimeException;
25 | import ch.ge.ve.protopoc.service.model.*;
26 | import ch.ge.ve.protopoc.service.model.polynomial.Point;
27 |
28 | import java.math.BigInteger;
29 | import java.util.List;
30 |
31 | /**
32 | * This interface defines the contract for the ballot board
33 | */
34 | public interface BulletinBoardService {
35 | void publishPublicParameters(PublicParameters publicParameters);
36 |
37 | PublicParameters getPublicParameters();
38 |
39 | void publishKeyPart(int j, EncryptionPublicKey publicKey);
40 |
41 | List getPublicKeyParts();
42 |
43 | void publishElectionSet(ElectionSet electionSet);
44 |
45 | ElectionSet getElectionSet();
46 |
47 | void publishPublicCredentials(int j, List publicCredentials);
48 |
49 | List> getPublicCredentialsParts();
50 |
51 | List publishBallot(Integer voterIndex, BallotAndQuery ballotAndQuery) throws IncorrectBallotOrQueryException;
52 |
53 | List publishConfirmation(Integer voterIndex, Confirmation confirmation) throws IncorrectConfirmationRuntimeException;
54 |
55 | void publishShuffleAndProof(int j, List shuffle, ShuffleProof proof);
56 |
57 | List getPreviousShuffle(int j);
58 |
59 | ShufflesAndProofs getShufflesAndProofs();
60 |
61 | void publishPartialDecryptionAndProof(int j, List partialDecryption, DecryptionProof proof);
62 |
63 | TallyData getTallyData();
64 |
65 | void publishTally(List tally);
66 | }
67 |
--------------------------------------------------------------------------------
/src/test/groovy/ch/ge/ve/protopoc/service/algorithm/KeyEstablishmentAlgorithmsTest.groovy:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.algorithm
23 |
24 | import ch.ge.ve.protopoc.service.model.EncryptionGroup
25 | import ch.ge.ve.protopoc.service.model.EncryptionPrivateKey
26 | import ch.ge.ve.protopoc.service.model.EncryptionPublicKey
27 | import ch.ge.ve.protopoc.service.support.RandomGenerator
28 | import spock.lang.Specification
29 |
30 | import static ch.ge.ve.protopoc.service.support.BigIntegers.*
31 |
32 | /**
33 | * Tests on the algorithms used during key establishment
34 | */
35 | class KeyEstablishmentAlgorithmsTest extends Specification {
36 | RandomGenerator randomGenerator = Mock()
37 | EncryptionGroup encryptionGroup = new EncryptionGroup(ELEVEN, FIVE, THREE, FOUR)
38 |
39 | KeyEstablishmentAlgorithms keyEstablishment
40 |
41 | void setup() {
42 | keyEstablishment = new KeyEstablishmentAlgorithms(randomGenerator)
43 | }
44 |
45 | def "generateKeyPair"() {
46 | when:
47 | def keyPair = keyEstablishment.generateKeyPair(encryptionGroup)
48 |
49 | then:
50 | 1 * randomGenerator.randomInZq(_) >> THREE
51 |
52 | (keyPair.private as EncryptionPrivateKey).privateKey == THREE
53 | (keyPair.public as EncryptionPublicKey).publicKey == FIVE // 3 ^ 3 mod 11
54 | }
55 |
56 | def "getPublicKey"() {
57 | def pubKeys = [new EncryptionPublicKey(FIVE, encryptionGroup), new EncryptionPublicKey(THREE, encryptionGroup)]
58 |
59 | when:
60 | def publicKey = keyEstablishment.getPublicKey(pubKeys)
61 |
62 | then:
63 | publicKey.encryptionGroup == encryptionGroup
64 | publicKey.publicKey == FOUR // 5 * 3 mod 11
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/ch/ge/ve/protopoc/service/model/Encryption.java:
--------------------------------------------------------------------------------
1 | /*-------------------------------------------------------------------------------------------------
2 | - #%L -
3 | - chvote-protocol-poc -
4 | - %% -
5 | - Copyright (C) 2016 - 2017 République et Canton de Genève -
6 | - %% -
7 | - This program is free software: you can redistribute it and/or modify -
8 | - it under the terms of the GNU Affero General Public License as published by -
9 | - the Free Software Foundation, either version 3 of the License, or -
10 | - (at your option) any later version. -
11 | - -
12 | - This program is distributed in the hope that it will be useful, -
13 | - but WITHOUT ANY WARRANTY; without even the implied warranty of -
14 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -
15 | - GNU General Public License for more details. -
16 | - -
17 | - You should have received a copy of the GNU Affero General Public License -
18 | - along with this program. If not, see . -
19 | - #L% -
20 | -------------------------------------------------------------------------------------------------*/
21 |
22 | package ch.ge.ve.protopoc.service.model;
23 |
24 | import ch.ge.ve.protopoc.service.support.Hash;
25 | import com.google.common.collect.ComparisonChain;
26 |
27 | import java.math.BigInteger;
28 | import java.util.Objects;
29 |
30 | /**
31 | * Model class containing one encryption of one ballot
32 | */
33 | public final class Encryption implements Hash.Hashable, Comparable {
34 | private final BigInteger a;
35 | private final BigInteger b;
36 |
37 | public Encryption(BigInteger a, BigInteger b) {
38 | this.a = a;
39 | this.b = b;
40 | }
41 |
42 | public BigInteger getA() {
43 | return a;
44 | }
45 |
46 | public BigInteger getB() {
47 | return b;
48 | }
49 |
50 | @Override
51 | public boolean equals(Object o) {
52 | if (this == o) return true;
53 | if (o == null || getClass() != o.getClass()) return false;
54 | Encryption that = (Encryption) o;
55 | return Objects.equals(a, that.a) &&
56 | Objects.equals(b, that.b);
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | return Objects.hash(a, b);
62 | }
63 |
64 | @Override
65 | public String toString() {
66 | return "Encryption{" +
67 | "a=" + a +
68 | ", b=" + b +
69 | '}';
70 | }
71 |
72 | @Override
73 | public Object[] elementsToHash() {
74 | return new BigInteger[]{a, b};
75 | }
76 |
77 | @Override
78 | public int compareTo(Encryption o) {
79 | return ComparisonChain.start()
80 | .compare(this.a, o.a)
81 | .compare(this.b, o.b)
82 | .result();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------