Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,6 @@ modules.xml
*.log*
launchSettings.json
**/PublishProfiles/*

## Project specific
**/keys.bin
33 changes: 21 additions & 12 deletions ExchangeSharp/API/Common/BaseAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public async Task<object> GenerateNonceAsync()
{
await OnGetNonceOffset();
}

object nonce;

while (true)
Expand Down Expand Up @@ -430,17 +430,26 @@ public async Task<object> GenerateNonceAsync()
/// <param name="encryptedFile">Encrypted file to load keys from</param>
public void LoadAPIKeys(string encryptedFile)
{
SecureString[] strings = CryptoUtility.LoadProtectedStringsFromFile(encryptedFile);
if (strings.Length < 2)
{
throw new InvalidOperationException("Encrypted keys file should have at least a public and private key, and an optional pass phrase");
}
PublicApiKey = strings[0];
PrivateApiKey = strings[1];
if (strings.Length > 2)
{
Passphrase = strings[2];
}
if (string.IsNullOrWhiteSpace(encryptedFile))
throw new ArgumentNullException(nameof(encryptedFile));
if (!File.Exists(encryptedFile))
throw new ArgumentException("Invalid key file.", nameof(encryptedFile));

var strings = CryptoUtility.LoadProtectedStringsFromFile(encryptedFile);

if (strings.Length < 2)
{
throw new InvalidOperationException(
"Encrypted keys file should have at least a public and private key, and an optional pass phrase"
);
}

PublicApiKey = strings[0];
PrivateApiKey = strings[1];
if (strings.Length > 2)
{
Passphrase = strings[2];
}
}

/// <summary>
Expand Down
18 changes: 8 additions & 10 deletions ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,21 +289,19 @@ public static IExchangeAPI GetExchangeAPI(string exchangeName)
// find an API with the right name
foreach (Type type in typeof(ExchangeAPI).Assembly.GetTypes().Where(type => type.IsSubclassOf(typeof(ExchangeAPI)) && !type.IsAbstract))
{
api = Activator.CreateInstance(type) as IExchangeAPI;
if (api.Name == exchangeName)
api = (IExchangeAPI) Activator.CreateInstance(type);
if (api.Name.Equals(exchangeName, StringComparison.OrdinalIgnoreCase))
{
// found one with right name, add it to the API dictionary
apis[exchangeName] = api;

// break out, we are done
break;
}
else
{
// name didn't match, dispose immediately to stop timers and other nasties we don't want running, and null out api variable
api.Dispose();
api = null;
}

// name didn't match, dispose immediately to stop timers and other nasties we don't want running, and null out api variable
api.Dispose();
api = null;
}
}
return api;
Expand Down Expand Up @@ -788,7 +786,7 @@ public virtual async Task<ExchangeWithdrawalResponse> WithdrawAsync(ExchangeWith
withdrawalRequest.Currency = NormalizeMarketSymbol(withdrawalRequest.Currency);
return await OnWithdrawAsync(withdrawalRequest);
}

/// <summary>
/// Gets the withdraw history for a symbol
/// </summary>
Expand Down Expand Up @@ -832,7 +830,7 @@ public virtual async Task<ExchangeCloseMarginPositionResult> CloseMarginPosition
return await OnCloseMarginPositionAsync(NormalizeMarketSymbol(marketSymbol));
}



#endregion REST API

Expand Down
12 changes: 6 additions & 6 deletions ExchangeSharp/Utility/DataProtector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private static byte[] CryptOperationWindows(bool protect, byte[] data, byte[] op
#region Non-Windows

//
// ManagedProtection.cs -
// ManagedProtection.cs -
// Protect (encrypt) data without (user involved) key management
//
// Author:
Expand All @@ -166,10 +166,10 @@ private static byte[] CryptOperationWindows(bool protect, byte[] data, byte[] op
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand All @@ -189,7 +189,7 @@ internal static class ManagedProtection
{
private static readonly RSA user;
private static readonly RSA machine;

static ManagedProtection()
{
try
Expand Down Expand Up @@ -307,7 +307,7 @@ public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtec
return result;
}

// FIXME [KeyContainerPermission (SecurityAction.Assert, KeyContainerName = "DAPI",
//TODO: FIXME [KeyContainerPermission (SecurityAction.Assert, KeyContainerName = "DAPI",
// Flags = KeyContainerPermissionFlags.Open | KeyContainerPermissionFlags.Decrypt)]
public static byte[] Unprotect(byte[] encryptedData, byte[] optionalEntropy, DataProtectionScope scope)
{
Expand Down Expand Up @@ -529,7 +529,7 @@ public static byte[] Unprotect(byte[] data, byte[] optionalEntropy = null, DataP
else
{
return ManagedProtection.Unprotect(data, optionalEntropy, scope);
}
}
}
}

Expand Down
31 changes: 0 additions & 31 deletions ExchangeSharpConsole/Console/ExchangeSharpConsole_Convert.cs

This file was deleted.

Loading