Merge pull request #616 from v-kaywon/fixPDOTests

define getKSPPath function and ksp related variabled in MsCommon_mid-refactor.inc
This commit is contained in:
Yuki Wong 2017-12-05 11:24:42 -08:00 committed by GitHub
commit 1349f6b0d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 30 deletions

View file

@ -13,6 +13,10 @@
// to be runnable from the MSSQL teams' internal proprietary test running system
//
const KSP_NAME = 'MyCustomKSPName';
const ENCRYPT_KEY = 'LPKCWVD07N3RG98J0MBLG4H2';
const KSP_TEST_TABLE = 'CustomKSPTestTable';
function isAEQualified($conn)
{
$msodbcsql_ver = $conn->getAttribute(PDO::ATTR_CLIENT_VERSION)["DriverVer"];
@ -81,9 +85,8 @@ function getDSN($sqlsrvserver, $database, $keywords = '', $disableCE = false)
$dsn .= "ColumnEncryption=Enabled;";
}
if ($keystore == "ksp" && !$disableCE) {
require_once('AE_Ksp.inc');
$ksp_path = getKSPPath();
$dsn .= "CEKeystoreProvider=$ksp_path;CEKeystoreName=$ksp_name;CEKeystoreEncryptKey=$encrypt_key;";
$dsn .= "CEKeystoreProvider=$ksp_path;CEKeystoreName=KSP_NAME;CEKeystoreEncryptKey=ENCRYPT_KEY;";
}
if ($keywords) {
$dsn .= $keywords;
@ -118,6 +121,27 @@ function getCekName()
return $cekName;
}
/**
* @return the path to the KSP dll/so file
*/
function getKSPpath()
{
$name = 'myKSP';
$dir_name = realpath(dirname(__FILE__));
$ksp = $dir_name . DIRECTORY_SEPARATOR . $name;
if ( strtoupper( substr( php_uname( 's' ), 0, 3 ) ) == 'WIN' ) {
$arch = 'x64';
if ( PHP_INT_SIZE == 4 ) // running 32 bit
$arch = '';
$ksp .= $arch . '.dll';
}
else
$ksp .= '.so';
return $ksp;
}
/**
* class for encapsulating column metadata needed for creating a table

View file

@ -4,19 +4,11 @@ Fetch data from a prepopulated test table given a custom keystore provider
<?php require('skipif_not_ksp.inc'); ?>
--FILE--
<?php
require( 'MsSetup.inc' );
require( 'AE_Ksp.inc' );
$ksp_path = getKSPpath();
$connectionInfo = "Database = $databaseName; ColumnEncryption = Enabled; ";
$connectionInfo .= "CEKeystoreProvider = $ksp_path; ";
$connectionInfo .= "CEKeystoreName = $ksp_name; ";
$connectionInfo .= "CEKeystoreEncryptKey = $encrypt_key; ";
require_once("MsCommon_mid-refactor.inc");
try
{
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
$conn = connect();
echo "Connected successfully with ColumnEncryption enabled and KSP specified.\n";
}
catch( PDOException $e )
@ -26,15 +18,16 @@ Fetch data from a prepopulated test table given a custom keystore provider
echo "\n";
}
$tsql = "SELECT * FROM CustomKSPTestTable";
$tbname = KSP_TEST_TABLE;
$tsql = "SELECT * FROM $tbname";
$stmt = $conn->query($tsql);
while ($row = $stmt->fetch(PDO::FETCH_NUM))
{
echo "c1=" . $row[0] . "\tc2=" . $row[1] . "\tc3=" . $row[2] . "\tc4=" . $row[3] . "\n";
}
$stmt = null;
$conn = null;
unset($stmt);
unset($conn);
echo "Done\n";

View file

@ -4,19 +4,11 @@ Fetch encrypted data from a prepopulated test table given a custom keystore prov
<?php require('skipif_not_ksp.inc'); ?>
--FILE--
<?php
require( 'MsSetup.inc' );
require( 'AE_Ksp.inc' );
$ksp_path = getKSPpath();
$connectionInfo = "Database = $databaseName; ";
$connectionInfo .= "CEKeystoreProvider = $ksp_path; ";
$connectionInfo .= "CEKeystoreName = $ksp_name; ";
$connectionInfo .= "CEKeystoreEncryptKey = $encrypt_key; ";
require_once("MsCommon_mid-refactor.inc");
try
{
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
$conn = connect();
echo "Connected successfully with ColumnEncryption disabled and KSP specified.\n";
}
catch( PDOException $e )
@ -26,7 +18,8 @@ Fetch encrypted data from a prepopulated test table given a custom keystore prov
echo "\n";
}
$tsql = "SELECT * FROM CustomKSPTestTable";
$tbname = KSP_TEST_TABLE;
$tsql = "SELECT * FROM $tbname";
$stmt = $conn->query($tsql);
while ($row = $stmt->fetch(PDO::FETCH_NUM))
{
@ -37,8 +30,8 @@ Fetch encrypted data from a prepopulated test table given a custom keystore prov
echo "\n" ;
}
$stmt = null;
$conn = null;
unset($stmt);
unset($conn);
echo "Done\n";

View file

@ -4,8 +4,8 @@ Connect using a custom keystore provider with some required inputs missing
<?php require('skipif_not_ksp.inc'); ?>
--FILE--
<?php
require( 'MsSetup.inc' );
require( 'AE_Ksp.inc' );
require("MsSetup.inc");
require_once("MsCommon_mid-refactor.inc");
function connect( $connectionInfo )
{
@ -25,6 +25,8 @@ Connect using a custom keystore provider with some required inputs missing
}
$ksp_path = getKSPpath();
$ksp_name = KSP_NAME;
$encrypt_key = ENCRYPT_KEY;
echo("Connecting... with column encryption\n");
$connectionInfo = "Database = $databaseName; ColumnEncryption = Enabled; ";