Skip to content

Commit

Permalink
Merge pull request #11 from SendSafely/v3.0.8
Browse files Browse the repository at this point in the history
v3.0.8
  • Loading branch information
jhemler authored Nov 28, 2023
2 parents a1ab3fc + 4ade922 commit c7309f3
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 215 deletions.
25 changes: 23 additions & 2 deletions SendsafelyAPI/ClientAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ namespace SendSafely
public class ClientAPI
{
private Connection connection = null;
private String locale = "en-US";

public ClientAPI() { }

public ClientAPI(string locale)
{
if (!String.IsNullOrEmpty(locale)) {
this.locale = locale;
}
}

/// <summary>
/// Initializes the API. This function must be called before the API can be used.
Expand All @@ -40,6 +50,7 @@ public void InitialSetup(string host, string apiKey, string apiSecret, WebProxy
{
StartupUtility su = new StartupUtility(host, apiSecret, apiKey, proxy);
this.connection = su.GetConnectionObject();
this.connection.setLocale(this.locale);
}

/// <summary>
Expand All @@ -51,6 +62,7 @@ public void InitialSetup(string host, string apiKey, string apiSecret, WebProxy
public void InitialSetup(string host, WebProxy proxy)
{
this.connection = new Connection(host, proxy);
this.connection.setLocale(this.locale);
}

/// <summary>
Expand Down Expand Up @@ -332,14 +344,15 @@ public void DeletePackage(String packageId)
}

/// <summary>
/// Deletes a temporary package, which is a package that has not yet been finalized.
/// (Deprecated) Deletes a temporary package, which is a package that has not yet been finalized.
/// </summary>
/// <param name="packageId"> The unique package id of the package to be deleted.</param>
/// <exception cref="APINotInitializedException">Thrown when the API has not been initialized.</exception>
/// <exception cref="InvalidCredentialsException">Thrown when the API credentials are incorrect.</exception>
/// <exception cref="ServerUnavailableException">Thrown when the API failed to connect to the server.</exception>
/// <exception cref="InvalidPackageException">Thrown when a non-existent or invalid package ID is used.</exception>
/// <exception cref="ActionFailedException">Will be thrown if the server returns an error message</exception>
[Obsolete("This version of DeleteTempPackage is deprecated. Instead please use DeletePackage.")]
public void DeleteTempPackage(String packageId)
{
EnforceInitialized();
Expand Down Expand Up @@ -713,7 +726,6 @@ public String FinalizePackage(String packageId, String keycode)
/// <returns>
/// A link to access the package. This link can be sent to the recipients.
/// </returns>
[Obsolete("This version of FinalizePackage is deprecated. Instead please use FinalizePackage which supports both allowReplyAll and notifyRecipients features.")]
public String FinalizePackage(String packageId, String keycode, bool allowReplyAll)
{
EnforceInitialized();
Expand Down Expand Up @@ -1598,6 +1610,15 @@ public void SetOutlookVersion(String version)
{
this.connection.OutlookVersion = version;
}

/// <summary>
/// This method is intended for use by the SendSafely Outlook Plugin. Sets the name of the client application that is making the API request.
/// </summary>
/// <param name="requestAPI">Name of client application making the API request.</param>
public void setRequestAPI(String requestAPI)
{
this.connection.RequestAPI = requestAPI;
}

/// <summary>
/// This method is intended for use by the SendSafely Outlook Plugin. Starts the registration process. If a valid email is provided, a validation code will be sent to the SendSafely servers.
Expand Down
7 changes: 7 additions & 0 deletions SendsafelyAPI/EnterpriseInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class EnterpriseInformation
private bool allowUndisclosedRecipients;
private bool outlookBeta;
private bool messageEncryption;
private bool allowI18nAll;

public String Host
{
Expand Down Expand Up @@ -43,5 +44,11 @@ public bool MessageEncryption
set { messageEncryption = value; }
}

public bool AllowI18nAll
{
get { return allowI18nAll; }
set { allowI18nAll = value; }
}

}
}
40 changes: 24 additions & 16 deletions SendsafelyAPI/Exceptions/TwoFactorAuthException.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace SendSafely.Exceptions
{
/// <summary>
/// Thrown when two factor authentication is required. The exception contains a ValidationToken parameter that must be used when validating the 2FA Code.
/// </summary>
[Serializable]
public class TwoFactorAuthException : BaseException
using System;
using System.Collections.Generic;
using System.Text;

namespace SendSafely.Exceptions
{
/// <summary>
/// Thrown when two factor authentication is required. The exception contains a ValidationToken parameter that must be used when validating the 2FA Code.
/// </summary>
[Serializable]
public class TwoFactorAuthException : BaseException
{

private String _validationToken;
private String _twoFaType;

public TwoFactorAuthException(String validationToken)
public TwoFactorAuthException(String validationToken, String twoFaType)
{
this._validationToken = validationToken;
this._validationToken = validationToken;
this._twoFaType = twoFaType;
}

public String ValidationToken
{
get { return _validationToken; }
set { _validationToken = value; }
}
}
}
}

public String TwoFaType
{
get { return _twoFaType; }
set { _twoFaType = value; }
}
}
}
22 changes: 22 additions & 0 deletions SendsafelyAPI/Objects/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ internal class Connection
private String apiKeyHeadervalue = "ss-api-key";
private String apiTimestampHeadervalue = "ss-request-timestamp";
private String apiSignatureHeadervalue = "ss-request-signature";
private String acceptLanguageHeaderValue = "Accept-Language";
private String apiIntegrationTypeHeadervalue = "ss-request-api";
private String outlookVersion = null;
private String requestAPI = null;
private String locale = "en-US";

#region Constructors

Expand Down Expand Up @@ -55,6 +59,12 @@ public String OutlookVersion
set { outlookVersion = value; }
}

public String RequestAPI
{
get { return requestAPI; }
set { requestAPI = value; }
}

public String ApiHost
{
get { return url; }
Expand Down Expand Up @@ -137,6 +147,7 @@ public HttpWebRequest GetRequestforFileUpload(Endpoint p, String boundary, Strin

wrReq.Headers.Add(apiSignatureHeadervalue, signature);
wrReq.Headers.Add(apiTimestampHeadervalue, dateStr);
wrReq.Headers.Add(acceptLanguageHeaderValue, locale);

wrReq.Method = p.Method.ToString();
wrReq.ContentType = p.ContentType + "; boundary=" + boundary;
Expand Down Expand Up @@ -182,6 +193,12 @@ public Stream CallServer(Endpoint p, Object request)
wrReq.Headers.Add(apiSignatureHeadervalue, signature);
}
wrReq.Headers.Add(apiTimestampHeadervalue, dateStr);
wrReq.Headers.Add(acceptLanguageHeaderValue, locale);

if (!String.IsNullOrEmpty(requestAPI))
{
wrReq.Headers.Add(apiIntegrationTypeHeadervalue, requestAPI);
}

if (proxy != null)
{
Expand All @@ -199,6 +216,11 @@ public Stream CallServer(Endpoint p, Object request)
return objStream;
}

public void setLocale(String locale)
{
this.locale = locale;
}

#endregion

#region Private Functions
Expand Down
8 changes: 8 additions & 0 deletions SendsafelyAPI/Objects/EnterpriseInformationResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class EnterpriseInformationResponse
private bool _allowUndisclosedRecipients;
private bool _outlookBeta;
private bool _messageEncryption;
private bool _allowI18nAll;

[JsonProperty(PropertyName = "host")]
public String Host
Expand Down Expand Up @@ -49,5 +50,12 @@ public bool MessageEncryption
get { return _messageEncryption; }
set { _messageEncryption = value; }
}

[JsonProperty(PropertyName = "allowI18nAll")]
public bool AllowI18nAll
{
get { return _allowI18nAll; }
set { _allowI18nAll = value; }
}
}
}
8 changes: 8 additions & 0 deletions SendsafelyAPI/Objects/GenerateAPIKeyResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class GenerateAPIKeyResponse
private String _email;
private String _apiKey;
private String _apiSecret;
private String _twoFaType;

[JsonProperty(PropertyName = "response")]
internal APIResponse Response
Expand Down Expand Up @@ -49,5 +50,12 @@ public String APISecret
get { return _apiSecret; }
set { _apiSecret = value; }
}

[JsonProperty(PropertyName = "twoFaType")]
public String TwoFaType
{
get { return _twoFaType; }
set { _twoFaType = value; }
}
}
}
6 changes: 3 additions & 3 deletions SendsafelyAPI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SendSafely Windows Client API")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,7 +32,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.0.7")]
[assembly: AssemblyFileVersion("3.0.7")]
[assembly: AssemblyVersion("3.0.8")]
[assembly: AssemblyFileVersion("3.0.8")]

[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("APITests")]
Loading

0 comments on commit c7309f3

Please sign in to comment.