-
Notifications
You must be signed in to change notification settings - Fork 8
Protocol part of the federation authentication on FE2 #1838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
3c007df
Some messageData added
quadcopterman e61e5ea
Added more messageData
quadcopterman cfef266
Created ViewModel
quadcopterman 7e77e9b
Created repository and handler for challenge messages
quadcopterman dc0eb50
Send message correctly
quadcopterman a767529
Added qr scanner and other elements
quadcopterman f0df64b
Debugged scanner, added mechanisms to send federation expect and init
quadcopterman b8ecf95
QR code is now displayed correctly, corrected a few other errors
quadcopterman b44c5fa
Corrected the used channel
quadcopterman d01b559
Resolve merge conflicts
quadcopterman f1fd114
Some debugging, sending/receiving Challenge and displaying QR code wo…
quadcopterman 18aea21
Corrected init and expect messages, wrote some tests
quadcopterman 260f8ad
Delete fe2-android/app/src/main/java/com/github/dedis/popstellar/plac…
quadcopterman c6f7b63
Some more tests
quadcopterman 3b1308c
Merge remote-tracking branch 'origin/work-fe2-johan-federation' into …
quadcopterman 36bb77a
Tests for the repository
quadcopterman ec32968
Merge branch 'master' into work-fe2-johan-federation
Kaz-ookid bb35d98
merged master and adapted for new QR Scanning interface
Kaz-ookid be8e199
Subscribed to the federation channel, added tests
quadcopterman a82b258
Debugging and tests
quadcopterman 874e4d2
Added scanning tests
quadcopterman 17f251c
Added federation exchange qr code
quadcopterman 5c73373
Little enhancements
quadcopterman b21e409
This fix is not working
quadcopterman bc4e9df
Reverted last commit and some last little improvements
quadcopterman 9ae488c
Added more tests for federation home and invite fragments
quadcopterman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ava/com/github/dedis/popstellar/model/network/method/message/data/federation/Challenge.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.github.dedis.popstellar.model.network.method.message.data.federation | ||
|
||
import com.github.dedis.popstellar.model.network.method.message.data.Action | ||
import com.github.dedis.popstellar.model.network.method.message.data.Data | ||
import com.github.dedis.popstellar.model.network.method.message.data.Objects | ||
import com.google.gson.annotations.SerializedName | ||
|
||
/** Challenge sent by the server */ | ||
class Challenge : Data { | ||
val value: String | ||
@SerializedName("valid_until") val validUntil: Long | ||
|
||
/** | ||
* Constructor for a data Challenge | ||
* | ||
* @param value value of the Challenge (A 32 bytes array encoded in hexadecimal) | ||
* @param validUntil expiration time of the Challenge | ||
*/ | ||
constructor(value: String, validUntil: Long) { | ||
this.value = value | ||
if (validUntil < 0L) { | ||
this.validUntil = 0L | ||
} else { | ||
this.validUntil = validUntil | ||
} | ||
} | ||
matteosz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
override val `object`: String | ||
get() = Objects.FEDERATION.`object` | ||
|
||
override val action: String | ||
get() = Action.CHALLENGE.action | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) { | ||
return true | ||
} | ||
if (other == null || javaClass != other.javaClass) { | ||
return false | ||
} | ||
val that = other as Challenge | ||
return value == that.value && validUntil == that.validUntil | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return java.util.Objects.hash(value, validUntil) | ||
} | ||
|
||
override fun toString(): String { | ||
return "Challenge{value='$value', valid_until='$validUntil'}" | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
.../github/dedis/popstellar/model/network/method/message/data/federation/ChallengeRequest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.github.dedis.popstellar.model.network.method.message.data.federation | ||
|
||
import com.github.dedis.popstellar.model.Immutable | ||
import com.github.dedis.popstellar.model.network.method.message.data.Action | ||
import com.github.dedis.popstellar.model.network.method.message.data.Data | ||
import com.github.dedis.popstellar.model.network.method.message.data.Objects | ||
|
||
/** Data sent to get a challenge */ | ||
@Immutable | ||
class ChallengeRequest : Data { | ||
val timestamp: Long | ||
|
||
/** | ||
* Constructor for a data Challenge Request | ||
* | ||
* @param timestamp time of the Challenge Request | ||
*/ | ||
constructor(timestamp: Long) { | ||
this.timestamp = timestamp | ||
} | ||
matteosz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
override val `object`: String | ||
get() = Objects.FEDERATION.`object` | ||
|
||
override val action: String | ||
get() = Action.CHALLENGE_REQUEST.action | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) { | ||
return true | ||
} | ||
if (other == null || javaClass != other.javaClass) { | ||
return false | ||
} | ||
val that = other as ChallengeRequest | ||
return timestamp == that.timestamp | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return java.util.Objects.hash(timestamp) | ||
} | ||
|
||
override fun toString(): String { | ||
return "ChallengeRequest{timestamp='$timestamp'}" | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
.../github/dedis/popstellar/model/network/method/message/data/federation/FederationExpect.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.github.dedis.popstellar.model.network.method.message.data.federation | ||
|
||
import com.github.dedis.popstellar.model.network.method.message.MessageGeneral | ||
import com.github.dedis.popstellar.model.network.method.message.data.Action | ||
import com.github.dedis.popstellar.model.network.method.message.data.Data | ||
import com.github.dedis.popstellar.model.network.method.message.data.Objects | ||
import com.google.gson.annotations.SerializedName | ||
|
||
/** Federation Expect message */ | ||
class FederationExpect : Data { | ||
@SerializedName("lao_id") val laoId: String | ||
@SerializedName("server_address") val serverAddress: String | ||
@SerializedName("public_key") val publicKey: String | ||
val challenge: MessageGeneral | ||
|
||
/** | ||
* Constructor for a data Federation Expect | ||
* | ||
* @param laoId ID of the remote LAO | ||
* @param serverAddress public address of the remote organizer server | ||
* @param publicKey public key of the remote organizer | ||
* @param challenge challenge for the server | ||
*/ | ||
constructor(laoId: String, serverAddress: String, publicKey: String, challenge: MessageGeneral) { | ||
this.laoId = laoId | ||
this.serverAddress = serverAddress | ||
this.publicKey = publicKey | ||
this.challenge = challenge | ||
} | ||
matteosz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
override val `object`: String | ||
get() = Objects.FEDERATION.`object` | ||
|
||
override val action: String | ||
get() = Action.EXPECT.action | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) { | ||
return true | ||
} | ||
if (other == null || javaClass != other.javaClass) { | ||
return false | ||
} | ||
val that = other as FederationExpect | ||
return laoId == that.laoId && | ||
serverAddress == that.serverAddress && | ||
publicKey == that.publicKey && | ||
challenge == that.challenge | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return java.util.Objects.hash(laoId, serverAddress, publicKey, challenge) | ||
} | ||
|
||
override fun toString(): String { | ||
return "FederationExpect{lao_id='$laoId', server_address='$serverAddress'," + | ||
"public_key='$publicKey', challenge='$challenge'}" | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...om/github/dedis/popstellar/model/network/method/message/data/federation/FederationInit.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.github.dedis.popstellar.model.network.method.message.data.federation | ||
|
||
import com.github.dedis.popstellar.model.network.method.message.MessageGeneral | ||
import com.github.dedis.popstellar.model.network.method.message.data.Action | ||
import com.github.dedis.popstellar.model.network.method.message.data.Data | ||
import com.github.dedis.popstellar.model.network.method.message.data.Objects | ||
import com.google.gson.annotations.SerializedName | ||
|
||
/** Initiates a federation link */ | ||
class FederationInit : Data { | ||
@SerializedName("lao_id") val laoId: String | ||
@SerializedName("server_address") val serverAddress: String | ||
@SerializedName("public_key") val publicKey: String | ||
val challenge: MessageGeneral | ||
|
||
/** | ||
* Constructor for a data Federation Init | ||
* | ||
* @param laoId ID of the remote LAO | ||
* @param serverAddress public address of the remote organizer server | ||
* @param publicKey public key of the remote organizer | ||
* @param challenge challenge from the other server | ||
*/ | ||
constructor(laoId: String, serverAddress: String, publicKey: String, challenge: MessageGeneral) { | ||
this.laoId = laoId | ||
this.serverAddress = serverAddress | ||
this.publicKey = publicKey | ||
this.challenge = challenge | ||
} | ||
matteosz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
override val `object`: String | ||
get() = Objects.FEDERATION.`object` | ||
|
||
override val action: String | ||
get() = Action.INIT.action | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) { | ||
return true | ||
} | ||
if (other == null || javaClass != other.javaClass) { | ||
return false | ||
} | ||
val that = other as FederationInit | ||
return laoId == that.laoId && | ||
serverAddress == that.serverAddress && | ||
publicKey == that.publicKey && | ||
challenge == that.challenge | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return java.util.Objects.hash(laoId, serverAddress, publicKey, challenge) | ||
} | ||
|
||
override fun toString(): String { | ||
return "FederationInit{lao_id='$laoId', server_address='$serverAddress'," + | ||
"public_key='$publicKey', challenge='$challenge'}" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
fe2-android/app/src/main/java/com/github/dedis/popstellar/model/qrcode/FederationDetails.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.dedis.popstellar.model.qrcode | ||
|
||
import com.github.dedis.popstellar.model.Immutable | ||
import com.github.dedis.popstellar.model.network.method.message.data.federation.Challenge | ||
import com.github.dedis.popstellar.model.network.serializer.JsonUtils | ||
import com.google.gson.Gson | ||
import com.google.gson.annotations.SerializedName | ||
|
||
@Immutable | ||
class FederationDetails( | ||
@field:SerializedName("lao_id") val laoId: String, | ||
@field:SerializedName("server_address") val serverAddress: String, | ||
@field:SerializedName("public_key") val publicKey: String, | ||
val challenge: Challenge? = null | ||
) { | ||
|
||
companion object { | ||
/** | ||
* Extract data from the given json string | ||
* | ||
* @param gson is used to parse the json string into the object | ||
* @param json representation of the data | ||
* @return the extracted data | ||
* @throws com.google.gson.JsonParseException if the value cannot be parsed | ||
*/ | ||
@JvmStatic | ||
fun extractFrom(gson: Gson, json: String?): FederationDetails { | ||
JsonUtils.verifyJson(JsonUtils.FEDERATION_DETAILS, json) | ||
|
||
return gson.fromJson(json, FederationDetails::class.java) | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...app/src/main/java/com/github/dedis/popstellar/repository/LinkedOrganizationsRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.github.dedis.popstellar.repository | ||
|
||
import com.github.dedis.popstellar.model.network.method.message.data.federation.Challenge | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
/** | ||
* This class is the repository of federation | ||
* | ||
* Its main purpose is to store received messages | ||
*/ | ||
@Singleton | ||
class LinkedOrganizationsRepository @Inject constructor() { | ||
private var challenge: Challenge? = null | ||
matteosz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private var onChallengeUpdatedCallback: ((Challenge) -> Unit)? = null | ||
var otherLaoId: String? = null | ||
var otherServerAddr: String? = null | ||
var otherPublicKey: String? = null | ||
|
||
/** | ||
* Updates the challenge | ||
* | ||
* @param challenge the new Challenge | ||
*/ | ||
fun updateChallenge(challenge: Challenge) { | ||
this.challenge = challenge | ||
onChallengeUpdatedCallback?.invoke(challenge) | ||
} | ||
|
||
fun setOnChallengeUpdatedCallback(callback: (Challenge) -> Unit) { | ||
onChallengeUpdatedCallback = callback | ||
} | ||
|
||
fun getChallenge(): Challenge? { | ||
return challenge | ||
} | ||
|
||
fun flush() { | ||
otherLaoId = null | ||
otherServerAddr = null | ||
otherPublicKey = null | ||
challenge = null | ||
onChallengeUpdatedCallback = null | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.