-
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 #1700 from dedis/work-fe2-matteo-popcha
Popcha on FE2
- Loading branch information
Showing
24 changed files
with
1,234 additions
and
40 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
136 changes: 136 additions & 0 deletions
136
...ithub/dedis/popstellar/model/network/method/message/data/popcha/PoPCHAAuthentication.java
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,136 @@ | ||
package com.github.dedis.popstellar.model.network.method.message.data.popcha; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import com.github.dedis.popstellar.model.Immutable; | ||
import com.github.dedis.popstellar.model.network.method.message.data.*; | ||
import com.github.dedis.popstellar.model.objects.security.Base64URLData; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** Data sent to authenticate to a PoPCHA server */ | ||
@Immutable | ||
public class PoPCHAAuthentication extends Data { | ||
|
||
@SerializedName("client_id") | ||
private final String clientId; | ||
|
||
private final String nonce; | ||
private final Base64URLData identifier; | ||
|
||
@SerializedName("identifier_proof") | ||
private final Base64URLData identifierProof; | ||
|
||
@Nullable private final String state; | ||
|
||
@Nullable | ||
@SerializedName("response_mode") | ||
private final String responseMode; | ||
|
||
@SerializedName("popcha_address") | ||
private final String popchaAddress; | ||
|
||
public PoPCHAAuthentication( | ||
String clientId, | ||
String nonce, | ||
Base64URLData identifier, | ||
Base64URLData identifierProof, | ||
String popchaAddress, | ||
@Nullable String state, | ||
@Nullable String responseMode) { | ||
this.clientId = clientId; | ||
this.nonce = nonce; | ||
this.identifier = identifier; | ||
this.identifierProof = identifierProof; | ||
this.state = state; | ||
this.responseMode = responseMode; | ||
this.popchaAddress = popchaAddress; | ||
} | ||
|
||
public String getClientId() { | ||
return clientId; | ||
} | ||
|
||
public String getNonce() { | ||
return nonce; | ||
} | ||
|
||
public Base64URLData getIdentifier() { | ||
return identifier; | ||
} | ||
|
||
public Base64URLData getIdentifierProof() { | ||
return identifierProof; | ||
} | ||
|
||
@Nullable | ||
public String getState() { | ||
return state; | ||
} | ||
|
||
@Nullable | ||
public String getResponseMode() { | ||
return responseMode; | ||
} | ||
|
||
public String getPopchaAddress() { | ||
return popchaAddress; | ||
} | ||
|
||
@Override | ||
public String getObject() { | ||
return Objects.POPCHA.getObject(); | ||
} | ||
|
||
@Override | ||
public String getAction() { | ||
return Action.AUTH.getAction(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
PoPCHAAuthentication that = (PoPCHAAuthentication) o; | ||
return clientId.equals(that.clientId) | ||
&& nonce.equals(that.nonce) | ||
&& identifier.equals(that.identifier) | ||
&& identifierProof.equals(that.identifierProof) | ||
&& java.util.Objects.equals(state, that.state) | ||
&& java.util.Objects.equals(responseMode, that.responseMode) | ||
&& popchaAddress.equals(that.popchaAddress); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return java.util.Objects.hash( | ||
clientId, nonce, identifier, identifierProof, state, responseMode, popchaAddress); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String toString() { | ||
return "PoPCHAAuthentication{" | ||
+ "clientId='" | ||
+ clientId | ||
+ '\'' | ||
+ ", nonce='" | ||
+ nonce | ||
+ '\'' | ||
+ ", identifier='" | ||
+ identifier | ||
+ '\'' | ||
+ ", identifierProof='" | ||
+ identifierProof | ||
+ '\'' | ||
+ ", state='" | ||
+ state | ||
+ '\'' | ||
+ ", responseMode='" | ||
+ responseMode | ||
+ '\'' | ||
+ ", popchaAddress='" | ||
+ popchaAddress | ||
+ '\'' | ||
+ '}'; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...droid/app/src/main/java/com/github/dedis/popstellar/model/objects/security/AuthToken.java
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,22 @@ | ||
package com.github.dedis.popstellar.model.objects.security; | ||
|
||
import com.github.dedis.popstellar.model.Immutable; | ||
import com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey; | ||
|
||
/** Represents a AuthToken key pair with its private and public keys */ | ||
@Immutable | ||
public class AuthToken extends KeyPair { | ||
|
||
public AuthToken(byte[] privateKey, byte[] publicKey) { | ||
super(new PlainPrivateKey(privateKey), new PublicKey(publicKey)); | ||
} | ||
|
||
public AuthToken(PoPToken otherToken) { | ||
super(otherToken.getPrivateKey(), otherToken.getPublicKey()); | ||
} | ||
|
||
@Override | ||
public PlainPrivateKey getPrivateKey() { | ||
return (PlainPrivateKey) super.getPrivateKey(); | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
fe2-android/app/src/main/java/com/github/dedis/popstellar/model/qrcode/PoPCHAQRCode.java
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,79 @@ | ||
package com.github.dedis.popstellar.model.qrcode; | ||
|
||
import android.net.Uri; | ||
import com.github.dedis.popstellar.model.Immutable; | ||
import com.github.dedis.popstellar.utility.MessageValidator; | ||
import java.util.Locale; | ||
|
||
@Immutable | ||
public class PoPCHAQRCode { | ||
|
||
public static final String FIELD_CLIENT_ID = "client_id"; | ||
public static final String FIELD_NONCE = "nonce"; | ||
public static final String FIELD_REDIRECT_URI = "redirect_uri"; | ||
public static final String FIELD_STATE = "state"; | ||
public static final String FIELD_RESPONSE_TYPE = "response_type"; | ||
public static final String FIELD_RESPONSE_MODE = "response_mode"; | ||
public static final String FIELD_LOGIN_HINT = "login_hint"; | ||
|
||
private final String clientId; | ||
private final String nonce; | ||
private final String state; | ||
private final String responseMode; | ||
private final String host; | ||
|
||
public PoPCHAQRCode(String data, String laoId) throws IllegalArgumentException { | ||
MessageValidator.verify().isValidPoPCHAUrl(data, laoId); | ||
|
||
Uri uri = Uri.parse(data); | ||
clientId = uri.getQueryParameter(FIELD_CLIENT_ID); | ||
nonce = uri.getQueryParameter(FIELD_NONCE); | ||
state = uri.getQueryParameter(FIELD_STATE); | ||
responseMode = uri.getQueryParameter(FIELD_RESPONSE_MODE); | ||
final int port = uri.getPort(); | ||
host = | ||
String.format( | ||
"%s%s", uri.getHost(), port == -1 ? "" : String.format(Locale.ENGLISH, ":%d", port)); | ||
} | ||
|
||
public String getClientId() { | ||
return clientId; | ||
} | ||
|
||
public String getNonce() { | ||
return nonce; | ||
} | ||
|
||
public String getState() { | ||
return state; | ||
} | ||
|
||
public String getResponseMode() { | ||
return responseMode; | ||
} | ||
|
||
public String getHost() { | ||
return host; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PoPCHAQRCode{" | ||
+ "clientId='" | ||
+ clientId | ||
+ '\'' | ||
+ ", nonce='" | ||
+ nonce | ||
+ '\'' | ||
+ ", state='" | ||
+ state | ||
+ '\'' | ||
+ ", responseMode='" | ||
+ responseMode | ||
+ '\'' | ||
+ ", host='" | ||
+ host | ||
+ '\'' | ||
+ '}'; | ||
} | ||
} |
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
Oops, something went wrong.