-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1838 from dedis/work-fe2-johan-federation
Protocol part of the federation authentication on FE2
- Loading branch information
Showing
34 changed files
with
1,530 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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 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 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
48 changes: 48 additions & 0 deletions
48
...ava/com/github/dedis/popstellar/model/network/method/message/data/federation/Challenge.kt
This file contains 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,48 @@ | ||
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 | ||
import kotlin.math.max | ||
|
||
/** Challenge sent by the server */ | ||
class Challenge | ||
/** | ||
* 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 | ||
*/ | ||
(val value: String, validUntil: Long) : Data { | ||
@SerializedName("valid_until") val validUntil: Long | ||
|
||
init { | ||
this.validUntil = max(0L, validUntil) | ||
} | ||
|
||
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'}" | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../github/dedis/popstellar/model/network/method/message/data/federation/ChallengeRequest.kt
This file contains 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,42 @@ | ||
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 | ||
/** | ||
* Constructor for a data Challenge Request | ||
* | ||
* @param timestamp time of the Challenge Request | ||
*/ | ||
(val timestamp: Long) : Data { | ||
|
||
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'}" | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
.../github/dedis/popstellar/model/network/method/message/data/federation/FederationExpect.kt
This file contains 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,54 @@ | ||
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 | ||
/** | ||
* 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 | ||
*/ | ||
( | ||
@SerializedName("lao_id") val laoId: String, | ||
@SerializedName("server_address") val serverAddress: String, | ||
@SerializedName("public_key") val publicKey: String, | ||
val challenge: MessageGeneral | ||
) : Data { | ||
|
||
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'}" | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...om/github/dedis/popstellar/model/network/method/message/data/federation/FederationInit.kt
This file contains 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,54 @@ | ||
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 | ||
/** | ||
* 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 | ||
*/ | ||
( | ||
@SerializedName("lao_id") val laoId: String, | ||
@SerializedName("server_address") val serverAddress: String, | ||
@SerializedName("public_key") val publicKey: String, | ||
val challenge: MessageGeneral | ||
) : Data { | ||
|
||
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 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 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 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 | ||
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 | ||
} | ||
} |
This file contains 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
Oops, something went wrong.