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
12 changes: 5 additions & 7 deletions src/Infrastructure/Helpers/ConnectionStringHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static string BuildFor(IPEndPoint endPoint)
{ ApplicationNameKey, AppEnvironment.ApplicationInstanceUniqueName }
};

return builder.ConnectionString.ToProtectedString();
return builder.ConnectionString;
}

public static string BuildFor(PBIDesktopReport report)
Expand All @@ -63,7 +63,7 @@ public static string BuildFor(PBIDesktopReport report)
{ ApplicationNameKey, AppEnvironment.ApplicationInstanceUniqueName }
};

return builder.ConnectionString.ToProtectedString();
return builder.ConnectionString;
}

public static string BuildFor(PBICloudDataset dataset, string accessToken)
Expand Down Expand Up @@ -102,15 +102,14 @@ public static string BuildFor(PBICloudDataset dataset, string accessToken)
};
var serverName = serverNameBuilder.Uri.AbsoluteUri;
var databaseName = dataset.ExternalDatabaseName;
var connectionString = Build(serverName, databaseName, accessToken, dataset.IdentityProvider);

return connectionString.ToProtectedString();
return Build(serverName, databaseName, accessToken, dataset.IdentityProvider);
}
else if (dataset.IsOnPremModel == true)
{
BravoUnexpectedException.ThrowIfNull(dataset.OnPremModelConnectionString);

return dataset.OnPremModelConnectionString.ToProtectedString();
return dataset.OnPremModelConnectionString;
}
else
{
Expand All @@ -121,9 +120,8 @@ public static string BuildFor(PBICloudDataset dataset, string accessToken)

var serverName = dataset.ExternalServerName;
var databaseName = dataset.ExternalDatabaseName;
var connectionString = Build(serverName, databaseName, accessToken, dataset.IdentityProvider);

return connectionString.ToProtectedString();
return Build(serverName, databaseName, accessToken, dataset.IdentityProvider);
}

static string Build(string serverName, string databaseName, string accessToken, string identityProvider)
Expand Down
18 changes: 0 additions & 18 deletions src/Infrastructure/Security/Cryptography.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,6 @@ internal static class CriptographyExtensions
{
public static string? ToSHA256Hash(this string value) => Cryptography.SHA256Hash(value);

public static string ToProtectedString(this string unprotectedString)
{
var unprotectedBytes = Encoding.Unicode.GetBytes(unprotectedString);
var protectedBytes = Cryptography.Protect(unprotectedBytes);
var protectedString = Convert.ToBase64String(protectedBytes);

return protectedString;
}

public static string ToUnprotectedString(this string protectedString)
{
var protectedBytes = Convert.FromBase64String(protectedString);
var unprotectedBytes = Cryptography.Unprotect(protectedBytes);
var unprotectedString = Encoding.Unicode.GetString(unprotectedBytes);

return unprotectedString;
}

public static string ToProtectedString(this SecureString secureString)
{
var unsecuredChars = new char[secureString.Length];
Expand Down
6 changes: 3 additions & 3 deletions src/Infrastructure/Services/ConnectionWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private TabularConnectionWrapper(string connectionString, string databaseIdOrNam
_connectionString = connectionString;

Server = new TOM.Server();
ProcessHelper.RunOnUISynchronizationContext(() => Server.Connect(connectionString.ToUnprotectedString()));
ProcessHelper.RunOnUISynchronizationContext(() => Server.Connect(connectionString));
Database = findById ? Server.Databases.Find(databaseIdOrName) : Server.Databases.FindByName(databaseIdOrName);

if (Database is null)
Expand Down Expand Up @@ -49,7 +49,7 @@ private TabularConnectionWrapper(string connectionString, string databaseIdOrNam

public AdomdConnection CreateAdomdConnection(bool open = true)
{
var connection = new AdomdConnection(_connectionString.ToUnprotectedString());
var connection = new AdomdConnection(_connectionString);

if (open)
{
Expand Down Expand Up @@ -91,7 +91,7 @@ internal class AdomdConnectionWrapper : IDisposable
{
private AdomdConnectionWrapper(string connectionString, string databaseName)
{
Connection = new AdomdConnection(connectionString.ToUnprotectedString());
Connection = new AdomdConnection(connectionString);
ProcessHelper.RunOnUISynchronizationContext(() => Connection.Open());
Connection.ChangeDatabase(databaseName);

Expand Down
2 changes: 1 addition & 1 deletion src/Models/PBIDesktopReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void GetConnectionMode(out string? serverName, out string? databaseName, out SSA
var connectionString = ConnectionStringHelper.BuildFor(ssasConnection.EndPoint);
try
{
server.Connect(connectionString.ToUnprotectedString());
server.Connect(connectionString);
compatibilityMode = server.CompatibilityMode;
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[InlineData("1234567890??=", "cb0f4399a2850ee589414b82de85b736ced269035c48e4275be850a3162ba284")]
[InlineData("abcdefghiABCDEFGHI??=", "1bca6736f96f84e35fa921938f45ba981a6e3f6aa02bcf46763009d3614cf89d")]
[InlineData("", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")]
[InlineData(null, null)]

Check warning on line 14 in test/Bravo.Tests/Infrastructure/Security/CryptographyExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Null should not be used for type parameter 'expected' of type 'string'. Use a non-null value, or convert the parameter to a nullable type. (https://xunit.net/xunit.analyzers/rules/xUnit1012)

Check warning on line 14 in test/Bravo.Tests/Infrastructure/Security/CryptographyExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Null should not be used for type parameter 'value' of type 'string'. Use a non-null value, or convert the parameter to a nullable type. (https://xunit.net/xunit.analyzers/rules/xUnit1012)

Check warning on line 14 in test/Bravo.Tests/Infrastructure/Security/CryptographyExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Null should not be used for type parameter 'expected' of type 'string'. Use a non-null value, or convert the parameter to a nullable type. (https://xunit.net/xunit.analyzers/rules/xUnit1012)

Check warning on line 14 in test/Bravo.Tests/Infrastructure/Security/CryptographyExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Null should not be used for type parameter 'value' of type 'string'. Use a non-null value, or convert the parameter to a nullable type. (https://xunit.net/xunit.analyzers/rules/xUnit1012)
public void ToSHA256Hash_SimpleTest(string value, string expected)
{
var actual = value.ToSHA256Hash();
Expand All @@ -32,18 +32,5 @@

Assert.Equal(expected, actual);
}

[Theory]
[InlineData("MySecret^ìfd56486-+{6 ♠ ⌂¿EFE==")]
[InlineData("AsDfJkIl123456")]
[InlineData("123==")]
[InlineData("")]
public void ToProtectedStringToUnprotectedString_SimpleTest(string expected)
{
var protectedString = expected.ToProtectedString();
var actual = protectedString.ToUnprotectedString();

Assert.Equal(expected, actual);
}
}
}
Loading