Skip to content

Commit

Permalink
Enable Always Encrypted enclave connection parameters (#919)
Browse files Browse the repository at this point in the history
* Enable the enclave connection parameters.

* Update the switch statement to use the enum constants for EnclaveAttestationProtocol

* Update verbiage for Always Encrypted connection options

* Update the argument exception to chose one specific to this connection option

* Add resource logic to resource files.

* Add error checking for when enclave parameters are added and Always Encrypted is set to disabled.

* Add/Update unit tests
  • Loading branch information
Xtrimmer committed Feb 18, 2020
1 parent 7b102df commit 927b0d7
Show file tree
Hide file tree
Showing 9 changed files with 1,911 additions and 1,703 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,36 @@ internal static ConnectionProviderOptions BuildConnectionProviderOptions()
new ConnectionOption
{
Name = "columnEncryptionSetting",
DisplayName = "Column encryption setting",
Description = "Default column encryption setting for all the commands on the connection",
DisplayName = "Always Encrypted",
Description = "Enables or disables Always Encrypted for the connection",
ValueType = ConnectionOption.ValueTypeCategory,
GroupName = "Security",
CategoryValues = new CategoryValue[] {
new CategoryValue { Name = "Disabled" },
new CategoryValue {Name = "Enabled" }
new CategoryValue { Name = "Enabled" }
}
},
new ConnectionOption
{
Name = "attestationProtocol",
DisplayName = "Attestation Protocol",
Description = "Specifies a protocol for attesting a server-side enclave used with Always Encrypted with secure enclaves",
ValueType = ConnectionOption.ValueTypeCategory,
GroupName = "Security",
CategoryValues = new CategoryValue[] {
new CategoryValue { DisplayName = "Host Guardian Service", Name = "HGS" },
new CategoryValue { DisplayName = "Azure Attestation", Name = "AAS" }
}
},
new ConnectionOption
{
Name = "enclaveAttestationUrl",
DisplayName = "Enclave Attestation URL",
Description = "Specifies an endpoint for attesting a server-side enclave used with Always Encrypted with secure enclaves",
ValueType = ConnectionOption.ValueTypeString,
GroupName = "Security"
},
new ConnectionOption
{
Name = "encrypt",
DisplayName = "Encrypt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,34 @@ public static SqlConnectionStringBuilder CreateConnectionStringBuilder(Connectio
throw new ArgumentException(SR.ConnectionServiceConnStringInvalidColumnEncryptionSetting(connectionDetails.ColumnEncryptionSetting));
}
}
if (!string.IsNullOrEmpty(connectionDetails.EnclaveAttestationProtocol))
{
if (string.IsNullOrEmpty(connectionDetails.ColumnEncryptionSetting) || connectionDetails.ColumnEncryptionSetting.ToUpper() == "DISABLED")
{
throw new ArgumentException(SR.ConnectionServiceConnStringInvalidAlwaysEncryptedOptionCombination());
}

switch (connectionDetails.EnclaveAttestationProtocol.ToUpper())
{
case "AAS":
connectionBuilder.AttestationProtocol = SqlConnectionAttestationProtocol.AAS;
break;
case "HGS":
connectionBuilder.AttestationProtocol = SqlConnectionAttestationProtocol.HGS;
break;
default:
throw new ArgumentException(SR.ConnectionServiceConnStringInvalidEnclaveAttestationProtocol(connectionDetails.EnclaveAttestationProtocol));
}
}
if (!string.IsNullOrEmpty(connectionDetails.EnclaveAttestationUrl))
{
if (string.IsNullOrEmpty(connectionDetails.ColumnEncryptionSetting) || connectionDetails.ColumnEncryptionSetting.ToUpper() == "DISABLED")
{
throw new ArgumentException(SR.ConnectionServiceConnStringInvalidAlwaysEncryptedOptionCombination());
}

connectionBuilder.EnclaveAttestationUrl = connectionDetails.EnclaveAttestationUrl;
}
if (connectionDetails.Encrypt.HasValue)
{
connectionBuilder.Encrypt = connectionDetails.Encrypt.Value;
Expand Down Expand Up @@ -1328,6 +1356,8 @@ public ConnectionDetails ParseConnectionString(string connectionString)
CurrentLanguage = builder.CurrentLanguage,
DatabaseName = builder.InitialCatalog,
ColumnEncryptionSetting = builder.ColumnEncryptionSetting.ToString(),
EnclaveAttestationProtocol = builder.AttestationProtocol.ToString(),
EnclaveAttestationUrl = builder.EnclaveAttestationUrl,
Encrypt = builder.Encrypt,
FailoverPartner = builder.FailoverPartner,
LoadBalanceTimeout = builder.LoadBalanceTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,38 @@ public string ColumnEncryptionSetting
}
}

/// <summary>
/// Gets or sets a value for Attestation Protocol.
/// </summary>
public string EnclaveAttestationProtocol
{
get
{
return GetOptionValue<string>("attestationProtocol");
}

set
{
SetOptionValue("attestationProtocol", value);
}
}

/// <summary>
/// Gets or sets the enclave attestation Url to be used with enclave based Always Encrypted.
/// </summary>
public string EnclaveAttestationUrl
{
get
{
return GetOptionValue<string>("enclaveAttestationUrl");
}

set
{
SetOptionValue("enclaveAttestationUrl", value);
}
}

/// <summary>
/// Gets or sets a Boolean value that indicates whether SQL Server uses SSL encryption for all data sent between the client and server if the server has a certificate installed.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static ConnectionDetails Clone(this ConnectionDetails details)
Password = details.Password,
AuthenticationType = details.AuthenticationType,
ColumnEncryptionSetting = details.ColumnEncryptionSetting,
EnclaveAttestationProtocol = details.EnclaveAttestationProtocol,
EnclaveAttestationUrl = details.EnclaveAttestationUrl,
Encrypt = details.Encrypt,
TrustServerCertificate = details.TrustServerCertificate,
PersistSecurityInfo = details.PersistSecurityInfo,
Expand Down
Loading

0 comments on commit 927b0d7

Please sign in to comment.