@@ -25,7 +25,7 @@ Dim strBuiltinDom, strClusterName, strCmd, strCmdSQL, strDirSystemDataBackup
2525Dim strGroupDBA, strGroupDBANonSA, strGroupMSA, strHKLM, strHKU, strIsInstallDBA, strKeyPassword, strLocalAdmin
2626Dim strNTAuth, strOSVersion, strPath, strProfDir, strProgCacls, strProgReg
2727Dim strServer, strSIDDistComUsers, strSSLCert, strSSLCertFile, strSSLCertThumb, strSystemDataSharedPrimary
28- Dim strTDECert, strUser, strUserAccount, strUserDNSDomain, strWaitShort
28+ Dim strTDECert, strUser, strUserAccount, strUserDNSDomain, strWaitMed, strWaitShort
2929
3030
3131Private Sub Class_Initialize
@@ -66,6 +66,7 @@ Private Sub Class_Initialize
6666 strTDECert = GetBuildfileValue( "TDECert" )
6767 strUserAccount = GetBuildfileValue( "UserAccount" )
6868 strUserDNSDomain = GetBuildfileValue( "UserDNSDomain" )
69+ strWaitMed = GetBuildfileValue( "WaitMed" )
6970 strWaitShort = GetBuildfileValue( "WaitShort" )
7071
7172 Set arrProfFolders = objFSO.GetFolder(strProfDir).SubFolders
@@ -297,7 +298,8 @@ Function GetCertAttr(strCertName, strCertAttr)
297298 Call DebugLog( "GetCertAttr: " & strCertName & ", " & strCertAttr)
298299 Dim strAttrValue
299300
300- strCmd = "(Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object {$_.FriendlyName -match '" & strCertName & "'})." & strCertAttr
301+ strCmd = "$CertName = '" & strCertName & "' ;"
302+ strCmd = strCmd & "(Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object {$_.FriendlyName -like $CertName})." & strCertAttr
301303 strAttrValue = GetPSData(strCmd)
302304
303305 Select Case True
@@ -449,6 +451,24 @@ Private Function HexStrToSIDStr(strValue)
449451End Function
450452
451453
454+ Function GetCredential(strPassword, strAccount)
455+ Call DebugLog( "GetCredential: " & strPassword)
456+ Dim strAcctName
457+
458+ GetCredential = GetBuildfileValue(strPassword)
459+ Select Case True
460+ Case LCase(GetCredential) <> "encrypted"
461+ ' Nothing
462+ Case strAccount = ""
463+ ' Get credential from Password file
464+ Case Else
465+ strAcctName = GetBuildfileValue(strAccount)
466+ ' Get credential from Password file
467+ End Select
468+
469+ End Function
470+
471+
452472Sub ProcessUser(strLabel, strDescription, strProcess)
453473 Call SetProcessId(strLabel, strDescription)
454474
@@ -597,7 +617,8 @@ Sub SetCertAuth(strCertThumb, strAccount)
597617 ' Code based on https://stackoverflow.com/questions/40046916/how-to-grant-permission-to-user-on-certificate-private-key-using-powershell
598618 Dim strPKFile
599619
600- strCmd = "(Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object {$_.Thumbprint -match '" & strCertThumb & "'}).privatekey.cspkeycontainerinfo.uniquekeycontainername"
620+ strCmd = "$CertThumb = '" & strCertThumb & "' ;"
621+ strCmd = strCmd & "(Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object {$_.Thumbprint -like $CertThumb}).privatekey.cspkeycontainerinfo.uniquekeycontainername"
601622 strPKFile = GetPSData(strCmd)
602623
603624 strPath = GetBuildfileValue( "VolSys" ) & ":\ProgramData\Microsoft\Crypto\RSA\MachineKeys\" & strPKFile
@@ -968,16 +989,24 @@ Sub SetSSLCert()
968989 strSSLFile = FormatFolder(GetBuildfileValue( "PathAddComp" )) & strSSLCertFile
969990
970991 Select Case True
971- Case GetBuildfileValue( "SetSSLSelfCert" ) = "YES"
972- strCmd = "POWERSHELL New-SelfSignedCertificate -DNSName '*." & strUserDNSDomain & "' -FriendlyName '" & strSSLCert & "' -CertStoreLocation 'cert:\LocalMachine\My' -NotBefore '2001-01-01T00:00:00' -NotAfter '2999-12-31T23:59:59' "
992+ Case GetBuildfileValue( "SSLSelfCert" ) = "YES"
993+ strCmd = "POWERSHELL $UserDNSDomain = '*." & strUserDNSDomain & "' ;"
994+ strCmd = strCmd & "$SSLCert = '" & strSSLCert & "' ;"
995+ strCmd = strCmd & "New-SelfSignedCertificate -DNSName $UserDNSDomain -FriendlyName $SSLCert -CertStoreLocation 'cert:\LocalMachine\My' -NotBefore '2001-01-01T00:00:00' -NotAfter '2999-12-31T23:59:59' "
973996 Call Util_RunExec(strCmd, "" , "" , - 1 ) ' Attributes: RSA, 2048 bit; Defaults: Client Authentication, Server Authentication; Usable for: Digital Signature, Key Encipherment
974997 Case CheckFile(strSSLFile) = True
975- strCmd = "POWERSHELL $Cert = Import-PfxCertificate -FilePath '" & strSSLFile & "' -Password '" & strSSLCertPassword & "' -CertStoreLocation 'cert:\LocalMachine\My' | $Cert.FriendlyName = '" & strSSLCert & "' "
998+ strCmd = "$Password = '" & strSSLCertPassword & "' ;$SSLFile = '" & strSSLFile & "' ;"
999+ strCmd = strCmd & "(Import-PfxCertificate -FilePath $SSLFile -Password (ConvertTo-SecureString -String $Password -AsPlainText -Force) -CertStoreLocation 'cert:\LocalMachine\My').Thumbprint;"
1000+ strSSLCertThumb = GetPSData(strCmd)
1001+ strCmd = "POWERSHELL $SSLCertThumb = '" & LCase(strSSLCertThumb) & "' ;$SSLCert = '" & strSSLCert & "' ;"
1002+ strCmd = strCmd & "$Cert = (Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object {$_.Thumbprint -like $SSLCertThumb}) ;$Cert.FriendlyName = $SSLCert ;"
9761003 Call Util_RunExec(strCmd, "" , "" , - 1 )
1004+ ' Call SetBuildMessage(strMsgError, "/SSLCertFile: processing is not yet supported in SQL FineBuild")
9771005 Case Else
9781006 Call SetBuildMessage(strMsgError, "Unable to find /SSLCertFile:" & strSSLCertFile)
9791007 End Select
9801008
1009+ WScript.Sleep strWaitMed
9811010 strSSLCertThumb = GetCertAttr(strSSLCert, "Thumbprint" )
9821011 Call SetBuildfileValue( "SSLCertThumb" , strSSLCertThumb)
9831012
@@ -1004,9 +1033,10 @@ End Sub
10041033Sub SetWinRMSSL()
10051034 Call DebugLog( "SetWinRMSSL:" )
10061035
1007- strCmd = "POWERSHELL Set-WSManInstance -ResourceURI winrm/config/Listener "
1036+ strCmd = "POWERSHELL $SSLCertThumb = '" & strSSLCertThumb & "' ;"
1037+ strCmd = strCmd & "Set-WSManInstance -ResourceURI winrm/config/Listener "
10081038 strCmd = strCmd & "-SelectorSet @{Address='*';Transport='HTTPS'} "
1009- strCmd = strCmd & "-ValueSet @{CertificateThumbprint='" & strSSLCertThumb & "' } "
1039+ strCmd = strCmd & "-ValueSet @{CertificateThumbprint=$SSLCertThumb } "
10101040 Call Util_RunExec(strCmd, "" , "" , - 1 )
10111041
10121042End Sub
@@ -1047,6 +1077,10 @@ Function GetOUAttr(strOUPath, strUserDNSDomain, strOUAttr)
10471077 GetOUAttr = FBManageSecurity.GetOUAttr(strOUPath, strUserDNSDomain, strOUAttr)
10481078End Function
10491079
1080+ Function GetCredential(strPassword, strAccount)
1081+ GetCredential = FBManageSecurity.GetCredential(strPassword, strAccount)
1082+ End Function
1083+
10501084Sub ProcessUser(strLabel, strDescription, strProcess)
10511085 Call FBManageSecurity.ProcessUser(strLabel, strDescription, strProcess)
10521086End Sub
0 commit comments