Skip to content

Commit 31b6819

Browse files
Merge pull request #4 from SendSafely/v3.0.4
v3.0.4
2 parents e3a9b08 + e373a90 commit 31b6819

8 files changed

Lines changed: 44 additions & 10 deletions

File tree

SendsafelyAPI/Objects/Connection.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using System.Security.Cryptography;
1010
using SendSafely.Exceptions;
1111
using System.Threading;
12+
using System.Reflection;
13+
using System.Runtime.Versioning;
1214

1315
namespace SendSafely.Objects
1416
{
@@ -203,6 +205,7 @@ public Stream CallServer(Endpoint p, Object request)
203205

204206
private void Initialize(String host, String privateKey, String apiKey)
205207
{
208+
this.SetTlsProtocol();
206209
this.apiKey = apiKey;
207210
this.privateKey = privateKey;
208211

@@ -271,6 +274,32 @@ private void WriteOutput(WebRequest req, String requestString)
271274
dataStream.Write(reqData, 0, reqData.Length);
272275
}
273276

277+
private void SetTlsProtocol()
278+
{
279+
var assembly = Assembly.GetExecutingAssembly();
280+
var attributes = assembly.GetCustomAttributes(typeof(TargetFrameworkAttribute), false);
281+
var version = (TargetFrameworkAttribute)attributes[0];
282+
283+
SecurityProtocolType flag;
284+
285+
try
286+
{
287+
if (Enum.TryParse("Tls11", out flag))
288+
ServicePointManager.SecurityProtocol |= flag;
289+
if (Enum.TryParse("Tls12", out flag))
290+
ServicePointManager.SecurityProtocol |= flag;
291+
}
292+
catch (Exception e)
293+
{
294+
throw new Exception("Unable to set TLS protocol for " + version.FrameworkDisplayName + ", enabled protocols " + GetEnabledSecurityProtocols(), e);
295+
}
296+
}
297+
298+
private string GetEnabledSecurityProtocols()
299+
{
300+
return ServicePointManager.SecurityProtocol.ToString();
301+
}
302+
274303
#endregion
275304
}
276305
}

SendsafelyAPI/Objects/ConnectionStrings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal class ConnectionStrings
3232
{"deleteTempPackage", new Endpoint("/api/v2.0/package/{packageId}/temp/", HTTPMethod.DELETE, "application/json")},
3333
{"deletePackage", new Endpoint("/api/v2.0/package/{packageId}/", HTTPMethod.DELETE, "application/json")},
3434
{"packageInformation", new Endpoint("/api/v2.0/package/{packageId}/", HTTPMethod.GET, "application/json")},
35-
{"updatePackageDescriptor", new Endpoint("/api/v2.0/package/{packageId}/", HTTPMethod.POST, "application/json")},
35+
{"updatePackage", new Endpoint("/api/v2.0/package/{packageId}/", HTTPMethod.POST, "application/json")},
3636

3737
{"directoryInformation", new Endpoint("/api/v2.0/package/{packageId}/directory/{directoryId}", HTTPMethod.GET, "application/json")},
3838
{"createDirectory", new Endpoint("/api/v2.0/package/{packageId}/directory/{directoryId}/subdirectory/", HTTPMethod.PUT, "application/json")},

SendsafelyAPI/Objects/Enums.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum APIResponse
2727
INVALID_RECIPIENT,
2828
PASSWORD_COMPLEXITY,
2929
TWO_FA_REQUIRED,
30+
TWO_FA_ENFORCED,
3031
AUTH_FORBIDDEN,
3132
INVALID_TOKEN,
3233
PIN_RESEND,

SendsafelyAPI/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("")]
1212
[assembly: AssemblyProduct("SendSafely Windows Client API")]
13-
[assembly: AssemblyCopyright("Copyright © 2017")]
13+
[assembly: AssemblyCopyright("Copyright © 2019")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,7 +32,7 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.0.3")]
36-
[assembly: AssemblyFileVersion("1.1.0.3")]
35+
[assembly: AssemblyVersion("3.0.4")]
36+
[assembly: AssemblyFileVersion("3.0.4")]
3737

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

SendsafelyAPI/SendsafelyAPI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -10,7 +10,7 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>SendSafely</RootNamespace>
1212
<AssemblyName>SendsafelyAPI</AssemblyName>
13-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<TargetFrameworkProfile />
1616
</PropertyGroup>

SendsafelyAPI/Utilities/CryptUtility.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ public String DecryptMessage(String encryptedMessage, char[] passPhrase)
148148

149149
public String EncryptMessage(String unencryptedMessage, char[] passPhrase)
150150
{
151-
// Convert the input to a byte array. Since it's text we will interpret it as Ascii
152-
byte[] unencryptedByteArray = System.Text.Encoding.ASCII.GetBytes (unencryptedMessage);
151+
// Convert the input to a byte array. We expect the string to be UTF-8 encoded
152+
byte[] unencryptedByteArray = System.Text.Encoding.UTF8.GetBytes (unencryptedMessage);
153153

154154
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator();
155155

@@ -323,7 +323,7 @@ private Keypair Armor(AsymmetricCipherKeyPair keyPair, String email)
323323
privateKey,
324324
DateTime.Now,
325325
email,
326-
SymmetricKeyAlgorithmTag.Aes256,
326+
SymmetricKeyAlgorithmTag.Null,
327327
null,
328328
null,
329329
null,

SendsafelyAPI/Utilities/PackageUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public bool UpdatePackageLife(String packageId, int life)
221221

222222
public void UpdatePackageDescriptor(String packageId, String packageDescriptor)
223223
{
224-
Endpoint p = ConnectionStrings.Endpoints["updatePackageDescriptor"].Clone();
224+
Endpoint p = ConnectionStrings.Endpoints["updatePackage"].Clone();
225225
p.Path = p.Path.Replace("{packageId}", packageId);
226226

227227
UpdatePackageDescriptorRequest req = new UpdatePackageDescriptorRequest();

SendsafelyAPI/Utilities/RegistrationUtility.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public void StartPINRegistration(String email)
5656
{
5757
throw new RegistrationNotAllowedException(response.Message);
5858
}
59+
else if (response.Response == APIResponse.TWO_FA_ENFORCED)
60+
{
61+
throw new TwoFAEnforcedException(response.Message);
62+
}
5963
else if (response.Response != APIResponse.SUCCESS)
6064
{
6165
throw new ActionFailedException(response.Response.ToString(), response.Message);

0 commit comments

Comments
 (0)