diff --git a/test/functional/setup/PHPcert.pfx b/test/functional/setup/PHPcert.pfx new file mode 100644 index 00000000..742a217c Binary files /dev/null and b/test/functional/setup/PHPcert.pfx differ diff --git a/test/functional/setup/ae_keys.sql b/test/functional/setup/ae_keys.sql new file mode 100644 index 00000000..aa4b9d78 --- /dev/null +++ b/test/functional/setup/ae_keys.sql @@ -0,0 +1,38 @@ +USE $(dbname) +GO + +/* DROP Column Encryption Key first, Column Master Key cannot be dropped until no encryption depends on it */ +IF EXISTS (SELECT * FROM sys.column_encryption_keys WHERE [name] LIKE '%AEColumnKey%') + +BEGIN +DROP COLUMN ENCRYPTION KEY [AEColumnKey] +END +GO + +/* Can finally drop Column Master Key after the Encryption Key is dropped */ +IF EXISTS (SELECT * FROM sys.column_master_keys WHERE [name] LIKE '%AEMasterKey%') + +BEGIN +DROP COLUMN MASTER KEY [AEMasterKey] +END +GO + +/* Recreate the Column Master Key */ +CREATE COLUMN MASTER KEY [AEMasterKey] +WITH +( + KEY_STORE_PROVIDER_NAME = N'MSSQL_CERTIFICATE_STORE', + KEY_PATH = N'CurrentUser/my/237F94738E7F5214D8588006C2269DBC6B370816' +) +GO + +/* Create Column Encryption Key using the Column Master Key */ +/* ENCRYPTED_VALUE is generated by SSMS and it is always the same if the same Certificate is imported */ +CREATE COLUMN ENCRYPTION KEY [AEColumnKey] +WITH VALUES +( + COLUMN_MASTER_KEY = [AEMasterKey], + ALGORITHM = 'RSA_OAEP', + ENCRYPTED_VALUE = 0x016E000001630075007200720065006E00740075007300650072002F006D0079002F00320033003700660039003400370033003800650037006600350032003100340064003800350038003800300030003600630032003200360039006400620063003600620033003700300038003100360039DE2397A08F6313E7820D75382D8469BE1C8F3CD47E3240A5A6D6F82D322F6EB1B103C9C47999A69FFB164D37E7891F60FFDB04ADEADEB990BE88AE488CAFB8774442DF909D2EF8BB5961A5C11B85BA7903E0E453B27B49CE0A30D14FF4F412B5737850A4C564B44C744E690E78FAECF007F9005E3E0FB4F8D6C13B016A6393B84BB3F83FEED397C4E003FF8C5BBDDC1F6156349A8B40EDC26398C9A03920DD81B9197BC83A7378F79ECB430A04B4CFDF3878B0219BB629F5B5BF3C2359A7498AD9A6F5D63EF15E060CDB10A65E6BF059C7A32237F0D9E00C8AC632CCDD68230774477D4F2E411A0E4D9B351E8BAA87793E64456370D91D4420B5FD9A252F6D9178AE3DD02E1ED57B7F7008114272419F505CBCEB109715A6C4331DEEB73653990A7140D7F83089B445C59E4858809D139658DC8B2781CB27A749F1CE349DC43238E1FBEAE0155BF2DBFEF6AFD9FD2BD1D14CEF9AC125523FD1120488F24416679A6041184A2719B0FC32B6C393FF64D353A3FA9BC4FA23DFDD999B0771A547B561D72B92A0B2BB8B266BC25191F2A0E2F8D93648F8750308DCD79BE55A2F8D5FBE9285265BEA66173CD5F5F21C22CC933AE2147F46D22BFF329F6A712B3D19A6488DDEB6FDAA5B136B29ADB0BA6B6D1FD6FBA5D6A14F76491CB000FEE4769D5B268A3BF50EA3FBA713040944558EDE99D38A5828E07B05236A4475DA27915E +) +GO \ No newline at end of file diff --git a/test/functional/setup/certificate.ps1 b/test/functional/setup/certificate.ps1 deleted file mode 100644 index 11e38817..00000000 --- a/test/functional/setup/certificate.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -Param( - [Parameter(Mandatory=$True,Position=1)] - [string]$serverName, - [Parameter(Mandatory=$True,Position=2)] - [string]$databaseName, - [Parameter(Mandatory=$True,Position=3)] - [string]$userName, - [Parameter(Mandatory=$True,Position=4)] - [string]$password) - -# Create a column master key in Windows Certificate Store. -$cert1 = New-SelfSignedCertificate -Subject "PHPAlwaysEncryptedCert" -CertStoreLocation Cert:CurrentUser\My -KeyExportPolicy Exportable -Type DocumentEncryptionCert -KeyUsage DataEncipherment -KeySpec KeyExchange - -# Import the SqlServer module. -Import-Module "SqlServer" - -#For SQL Server Authentication -Add-Type -AssemblyName "Microsoft.SqlServer.Smo" -$MySQL = new-object('Microsoft.SqlServer.Management.Smo.Server') $serverName -$MySQL.ConnectionContext.LoginSecure = $false -$MySQL.ConnectionContext.set_Login($userName) -$MySQL.ConnectionContext.set_Password($password) -$database = $MySQL.Databases[$databaseName] - -# Create a SqlColumnMasterKeySettings object for your column master key. -$cmkSettings = New-SqlCertificateStoreColumnMasterKeySettings -CertificateStoreLocation "CurrentUser" -Thumbprint $cert1.Thumbprint - -# Create column master key metadata in the database. -$cmkName = "CMK1" -New-SqlColumnMasterKey -Name $cmkName -InputObject $database -ColumnMasterKeySettings $cmkSettings - -# Generate a column encryption key, encrypt it with the column master key and create column encryption key metadata in the database. -$cekName = "CEK1" -New-SqlColumnEncryptionKey -Name $cekName -InputObject $database -ColumnMasterKey $cmkName - -# Disconnect -$MySQL.ConnectionContext.Disconnect() \ No newline at end of file diff --git a/test/functional/setup/setup_dbs.py b/test/functional/setup/setup_dbs.py index 12532ea4..49cb86a5 100644 --- a/test/functional/setup/setup_dbs.py +++ b/test/functional/setup/setup_dbs.py @@ -68,10 +68,13 @@ def is_ae_qualified( server, uid, pwd ): def setupAE( server, dbname, uid, pwd): if platform.system() == 'Windows': + # import self signed certificate dir_name = os.path.realpath(__file__) - cert_name = os.path.join(dir_name, "certificate.ps1") - inst_command = 'powershell -executionPolicy Unrestricted -file ' + cert_name + ' ' + server + ' ' + dbname + ' ' + uid + ' ' + pwd - executeCommmand(inst_command) + cert_name = os.path.join(dir_name, "PHPcert.ps1") + inst_command = "certutil -user -p '' -importPFX My " + cert_name + " NoRoot" + executeCommand(inst_command) + # create Column Master Key and Column Encryption Key + executeSQLscript('ae_keys.sql', conn_options, dbname) if __name__ == '__main__': parser = argparse.ArgumentParser() diff --git a/test/functional/sqlsrv/AEData.inc b/test/functional/sqlsrv/AEData.inc deleted file mode 100644 index d7037854..00000000 --- a/test/functional/sqlsrv/AEData.inc +++ /dev/null @@ -1,84 +0,0 @@ - \ No newline at end of file diff --git a/test/functional/sqlsrv/sqlsrv_fetch_ae_int.phpt b/test/functional/sqlsrv/sqlsrv_fetch_ae_int.phpt deleted file mode 100644 index 102fbbaf..00000000 --- a/test/functional/sqlsrv/sqlsrv_fetch_ae_int.phpt +++ /dev/null @@ -1,60 +0,0 @@ ---TEST-- -Test for fetching integer columns with column encryption ---SKIPIF-- ---FILE-- -"Enabled")); -//$conn = Connect(); - -// create table -$tbname = GetTempTableName("", false); -$dataTypes = array("bigint", "int", "smallint"); -$col_names = array(); -$dataTypes_str = get_dataTypes_str($dataTypes, $col_names); -CreateTableEx( $conn, $tbname, $dataTypes_str); - -// populate table -$data_arr = array_merge( array_slice($bigint_params, 0, 3), array_slice($int_params, 0, 3), array_slice($smallint_params, 0, 3) ); -$data_str = implode(", ", $data_arr); -sqlsrv_query( $conn, "INSERT INTO $tbname VALUES ( $data_str )"); - -// encrypt columns -EncryptColumns($server, $database, $userName, $userPassword, $tbname, $col_names); - -//Fetch encrypted values with ColumnEncryption Enabled -$sql = "SELECT * FROM $tbname"; -$stmt = sqlsrv_query($conn, $sql); -$decrypted_row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC); - -var_dump($decrypted_row); - -DropTable($conn, $tbname); -sqlsrv_free_stmt($stmt); -sqlsrv_close($conn); - -?> ---EXPECT-- -array(9) { - [0]=> - string(10) "2147483648" - [1]=> - string(19) "-922337203685479936" - [2]=> - string(18) "922337203685479936" - [3]=> - int(32768) - [4]=> - int(-2147483647) - [5]=> - int(2147483647) - [6]=> - int(256) - [7]=> - int(-32767) - [8]=> - int(32767) -} \ No newline at end of file diff --git a/test/functional/sqlsrv/test_ae_keys_setup.phpt b/test/functional/sqlsrv/test_ae_keys_setup.phpt new file mode 100644 index 00000000..67be3064 --- /dev/null +++ b/test/functional/sqlsrv/test_ae_keys_setup.phpt @@ -0,0 +1,32 @@ +--TEST-- +retrieval of names of column master key and column encryption key generated in the database setup +--SKIPIF-- + +--FILE-- + +--EXPECT-- +Column Master Key generated: AEMasterKey +Column Encryption Key generated: AEColumnKey \ No newline at end of file