use of co.krypt.krypton.protocol.SignRequest in project krypton-android by kryptco.
the class ClientAuthParsingTest method clientAuthParsingRSASHA1_works.
@Test
public void clientAuthParsingRSASHA1_works() throws Exception {
SignRequest signRequest = new SignRequest();
signRequest.data = Base64.decode("AAAAIFrZQlwF8k3UCrkwZ2E0U+qGx57wehv5ABkHJStoOCc3MgAAAANnaXQAAAAOc3NoLWNvbm5lY3Rpb24AAAAJcHVibGlja2V5AQAAAAdzc2gtcnNh");
Assert.assertTrue(signRequest.algo().equals("ssh-rsa"));
Assert.assertTrue(signRequest.user().equals("git"));
Assert.assertTrue(Arrays.equals(signRequest.sessionID(), Base64.decode("WtlCXAXyTdQKuTBnYTRT6obHnvB6G/kAGQclK2g4Jzc=")));
}
use of co.krypt.krypton.protocol.SignRequest in project krypton-android by kryptco.
the class ClientAuthParsingTest method clientAuthParsingRSASHA256_works.
@Test
public void clientAuthParsingRSASHA256_works() throws Exception {
SignRequest signRequest = new SignRequest();
signRequest.data = Base64.decode("AAAAIFFE46OxITOv4tIsO9u7Jq/W6vnf4diwbdSEoeGMDB9yMgAAAAh0ZXN0dXNlcgAAAA5zc2gtY29ubmVjdGlvbgAAAAlwdWJsaWNrZXkBAAAADHJzYS1zaGEyLTI1Ng==");
Assert.assertTrue(signRequest.algo().equals("rsa-sha2-256"));
Assert.assertTrue(signRequest.user().equals("testuser"));
Assert.assertTrue(Arrays.equals(signRequest.sessionID(), Base64.decode("UUTjo7EhM6/i0iw727smr9bq+d/h2LBt1ISh4YwMH3I=")));
}
use of co.krypt.krypton.protocol.SignRequest in project krypton-android by kryptco.
the class ClientAuthParsingTest method clientAuthParsingRSASHA512_works.
@Test
public void clientAuthParsingRSASHA512_works() throws Exception {
SignRequest signRequest = new SignRequest();
signRequest.data = Base64.decode("AAAAIJplnt2SRhPtYQqFfZcJwsSYrIIMaAjOxhTlrM/zNV6WMgAAAARyb290AAAADnNzaC1jb25uZWN0aW9uAAAACXB1YmxpY2tleQEAAAAMcnNhLXNoYTItNTEy");
Assert.assertTrue(signRequest.algo().equals("rsa-sha2-512"));
Assert.assertTrue(signRequest.user().equals("root"));
Assert.assertTrue(Arrays.equals(signRequest.sessionID(), Base64.decode("mmWe3ZJGE+1hCoV9lwnCxJisggxoCM7GFOWsz/M1XpY=")));
}
use of co.krypt.krypton.protocol.SignRequest in project krypton-android by kryptco.
the class JSONUnitTest method nestedRequestDeserialization_works.
@Test
public void nestedRequestDeserialization_works() throws Exception {
String json = "{\"request_id\":\"132\", \"unix_seconds\":0, \"sign_request\":{\"public_key_fingerprint\":\"aGkK\", \"data\": \"aGkK\"}, \"v\": \"1.0.0\"}";
Request request = JSON.fromJson(json, Request.class);
if (!(request.body instanceof SignRequest)) {
throw new JsonParseException("expected sign request");
}
}
use of co.krypt.krypton.protocol.SignRequest in project krypton-android by kryptco.
the class ApprovalDialog method showApprovalDialog.
public static void showApprovalDialog(final Activity activity, final String requestID) {
Pair<Pairing, Request> pendingRequestAndPairing = Policy.getPendingRequestAndPairing(requestID);
if (pendingRequestAndPairing == null) {
Log.e(TAG, "user clicked notification for unknown request");
return;
}
Pairing pairing = pendingRequestAndPairing.first;
Request request = pendingRequestAndPairing.second;
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setIcon(R.mipmap.ic_launcher);
// setPositiveButton: right button
// setNeutralButton: left button
// setNegativeButton: middle button
long temporaryApprovalSeconds = Policy.temporaryApprovalSeconds(activity, request);
boolean temporaryApprovalEnabled = temporaryApprovalSeconds > 0;
String temporaryApprovalDuration = Policy.temporaryApprovalDuration(activity, request);
request.body.visit(new RequestBody.Visitor<Void, RuntimeException>() {
@Override
public Void visit(MeRequest meRequest) throws RuntimeException {
return null;
}
@Override
public Void visit(SignRequest signRequest) throws RuntimeException {
builder.setPositiveButton("Once", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
if (temporaryApprovalEnabled) {
builder.setNeutralButton("All for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
if (signRequest.hostNameVerified) {
builder.setNegativeButton("This host for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_THIS_TEMPORARILY));
}
}
return null;
}
@Override
public Void visit(GitSignRequest gitSignRequest) throws RuntimeException {
builder.setPositiveButton("Once", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
if (temporaryApprovalEnabled) {
builder.setNeutralButton("All for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
}
return null;
}
@Override
public Void visit(UnpairRequest unpairRequest) throws RuntimeException {
return null;
}
@Override
public Void visit(HostsRequest hostsRequest) throws RuntimeException {
builder.setPositiveButton("Allow", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
if (temporaryApprovalEnabled) {
builder.setNeutralButton("All for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
}
return null;
}
@Override
public Void visit(ReadTeamRequest readTeamRequest) throws RuntimeException {
builder.setPositiveButton("Allow for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
return null;
}
@Override
public Void visit(LogDecryptionRequest logDecryptionRequest) throws RuntimeException {
builder.setPositiveButton("Allow for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
return null;
}
@Override
public Void visit(TeamOperationRequest teamOperationRequest) throws RuntimeException {
builder.setPositiveButton("Allow", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
return null;
}
});
builder.setOnDismissListener(dialogInterface -> {
Policy.onAction(activity.getApplicationContext(), requestID, Policy.REJECT);
});
View requestView = activity.getLayoutInflater().inflate(R.layout.request, null);
TextView workstationNameText = (TextView) requestView.findViewById(R.id.workstationName);
workstationNameText.setText(pairing.workstationName);
ConstraintLayout content = (ConstraintLayout) requestView.findViewById(R.id.content);
request.fillView(content);
builder.setView(requestView);
builder.create().show();
}
Aggregations