2018-02-14 15:26:05 +01:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
2018-02-14 15:26:05 +01:00
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-06-27 14:02:16 +02:00
|
|
|
|
using System;
|
2020-07-31 19:57:08 +02:00
|
|
|
|
using System.Collections.Generic;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Communication.Contracts;
|
|
|
|
|
using SafeExamBrowser.Communication.Contracts.Data;
|
|
|
|
|
using SafeExamBrowser.Communication.Contracts.Proxies;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2018-02-14 15:26:05 +01:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Communication.Proxies
|
2018-02-14 15:26:05 +01:00
|
|
|
|
{
|
2018-03-06 14:35:10 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Default implementation of the <see cref="IClientProxy"/>, to be used for communication with the client application component.
|
|
|
|
|
/// </summary>
|
2018-02-14 15:26:05 +01:00
|
|
|
|
public class ClientProxy : BaseProxy, IClientProxy
|
|
|
|
|
{
|
2019-06-18 10:18:56 +02:00
|
|
|
|
public ClientProxy(string address, IProxyObjectFactory factory, ILogger logger, Interlocutor owner) : base(address, factory, logger, owner)
|
2018-02-14 15:26:05 +01:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 16:47:50 +01:00
|
|
|
|
public CommunicationResult InformReconfigurationAborted()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(new SimpleMessage(SimpleMessagePurport.ReconfigurationAborted));
|
|
|
|
|
var success = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Client acknowledged reconfiguration abortion.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Client did not acknowledge reconfiguration abortion! Received: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Failed to perform '{nameof(InformReconfigurationAborted)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
public CommunicationResult InformReconfigurationDenied(string filePath)
|
2018-07-04 09:53:33 +02:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(new ReconfigurationDeniedMessage(filePath));
|
|
|
|
|
var success = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Client acknowledged reconfiguration denial.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Client did not acknowledge reconfiguration denial! Received: {ToString(response)}.");
|
|
|
|
|
}
|
2018-07-04 09:53:33 +02:00
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2018-07-04 09:53:33 +02:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
Logger.Error($"Failed to perform '{nameof(InformReconfigurationDenied)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
2018-07-04 09:53:33 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
public CommunicationResult InitiateShutdown()
|
2018-02-20 15:15:26 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(SimpleMessagePurport.Shutdown);
|
|
|
|
|
var success = IsAcknowledged(response);
|
2018-02-20 15:15:26 +01:00
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Client acknowledged shutdown request.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Client did not acknowledge shutdown request! Received: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2018-02-20 15:15:26 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
Logger.Error($"Failed to perform '{nameof(InitiateShutdown)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
2018-02-20 15:15:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
public CommunicationResult<AuthenticationResponse> RequestAuthentication()
|
2018-02-14 15:26:05 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
try
|
2018-02-27 15:28:54 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
var response = Send(SimpleMessagePurport.Authenticate);
|
|
|
|
|
var success = response is AuthenticationResponse;
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Received authentication response.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Did not receive authentication response! Received: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult<AuthenticationResponse>(success, response as AuthenticationResponse);
|
2018-02-27 15:28:54 +01:00
|
|
|
|
}
|
2018-08-10 13:23:24 +02:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Failed to perform '{nameof(RequestAuthentication)}'", e);
|
2018-02-27 15:28:54 +01:00
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
return new CommunicationResult<AuthenticationResponse>(false, default(AuthenticationResponse));
|
|
|
|
|
}
|
2018-02-14 15:26:05 +01:00
|
|
|
|
}
|
2018-06-27 14:02:16 +02:00
|
|
|
|
|
2020-07-31 19:57:08 +02:00
|
|
|
|
public CommunicationResult RequestExamSelection(IEnumerable<(string id, string lms, string name, string url)> exams, Guid requestId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(new ExamSelectionRequestMessage(exams, requestId));
|
|
|
|
|
var success = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Client acknowledged server exam selection request.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Client did not acknowledge server exam selection request! Received: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Failed to perform '{nameof(RequestExamSelection)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
public CommunicationResult RequestPassword(PasswordRequestPurpose purpose, Guid requestId)
|
2018-06-27 14:02:16 +02:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(new PasswordRequestMessage(purpose, requestId));
|
|
|
|
|
var success = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Client acknowledged password request.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Client did not acknowledge password request! Received: {ToString(response)}.");
|
|
|
|
|
}
|
2018-07-04 09:53:33 +02:00
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2018-07-04 09:53:33 +02:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
Logger.Error($"Failed to perform '{nameof(RequestPassword)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
2018-07-04 09:53:33 +02:00
|
|
|
|
}
|
2018-06-27 14:02:16 +02:00
|
|
|
|
}
|
2018-12-14 12:31:31 +01:00
|
|
|
|
|
2020-07-31 20:35:18 +02:00
|
|
|
|
public CommunicationResult RequestServerFailureAction(string message, bool showFallback, Guid requestId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(new ServerFailureActionRequestMessage(message, showFallback, requestId));
|
|
|
|
|
var success = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Client acknowledged server failure action request.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Client did not acknowledge server failure action request! Received: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Failed to perform '{nameof(RequestServerFailureAction)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 14:02:36 +02:00
|
|
|
|
public CommunicationResult ShowMessage(string message, string title, int action, int icon, Guid requestId)
|
2018-12-14 12:31:31 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-08-30 14:02:36 +02:00
|
|
|
|
var response = Send(new MessageBoxRequestMessage(action, icon, message, requestId, title));
|
2018-12-14 12:31:31 +01:00
|
|
|
|
var success = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Client acknowledged message box request.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Client did not acknowledge message box request! Received: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Failed to perform '{nameof(ShowMessage)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-14 15:26:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|