@@ -25,7 +25,7 @@ Dim strBuiltinDom, strClusterName, strCmd, strCmdSQL, strDirSystemDataBackup
25
25
Dim strGroupDBA, strGroupDBANonSA, strGroupMSA, strHKLM, strHKU, strIsInstallDBA, strKeyPassword, strLocalAdmin
26
26
Dim strNTAuth, strOSVersion, strPath, strProfDir, strProgCacls, strProgReg
27
27
Dim strServer, strSIDDistComUsers, strSSLCert, strSSLCertFile, strSSLCertThumb, strSystemDataSharedPrimary
28
- Dim strTDECert, strUser, strUserAccount, strUserDNSDomain, strWaitShort
28
+ Dim strTDECert, strUser, strUserAccount, strUserDNSDomain, strWaitMed, strWaitShort
29
29
30
30
31
31
Private Sub Class_Initialize
@@ -66,6 +66,7 @@ Private Sub Class_Initialize
66
66
strTDECert = GetBuildfileValue( "TDECert" )
67
67
strUserAccount = GetBuildfileValue( "UserAccount" )
68
68
strUserDNSDomain = GetBuildfileValue( "UserDNSDomain" )
69
+ strWaitMed = GetBuildfileValue( "WaitMed" )
69
70
strWaitShort = GetBuildfileValue( "WaitShort" )
70
71
71
72
Set arrProfFolders = objFSO.GetFolder(strProfDir).SubFolders
@@ -297,7 +298,8 @@ Function GetCertAttr(strCertName, strCertAttr)
297
298
Call DebugLog( "GetCertAttr: " & strCertName & ", " & strCertAttr)
298
299
Dim strAttrValue
299
300
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
301
303
strAttrValue = GetPSData(strCmd)
302
304
303
305
Select Case True
@@ -449,6 +451,24 @@ Private Function HexStrToSIDStr(strValue)
449
451
End Function
450
452
451
453
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
+
452
472
Sub ProcessUser(strLabel, strDescription, strProcess)
453
473
Call SetProcessId(strLabel, strDescription)
454
474
@@ -597,7 +617,8 @@ Sub SetCertAuth(strCertThumb, strAccount)
597
617
' Code based on https://stackoverflow.com/questions/40046916/how-to-grant-permission-to-user-on-certificate-private-key-using-powershell
598
618
Dim strPKFile
599
619
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"
601
622
strPKFile = GetPSData(strCmd)
602
623
603
624
strPath = GetBuildfileValue( "VolSys" ) & ":\ProgramData\Microsoft\Crypto\RSA\MachineKeys\" & strPKFile
@@ -968,16 +989,24 @@ Sub SetSSLCert()
968
989
strSSLFile = FormatFolder(GetBuildfileValue( "PathAddComp" )) & strSSLCertFile
969
990
970
991
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' "
973
996
Call Util_RunExec(strCmd, "" , "" , - 1 ) ' Attributes: RSA, 2048 bit; Defaults: Client Authentication, Server Authentication; Usable for: Digital Signature, Key Encipherment
974
997
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 ;"
976
1003
Call Util_RunExec(strCmd, "" , "" , - 1 )
1004
+ ' Call SetBuildMessage(strMsgError, "/SSLCertFile: processing is not yet supported in SQL FineBuild")
977
1005
Case Else
978
1006
Call SetBuildMessage(strMsgError, "Unable to find /SSLCertFile:" & strSSLCertFile)
979
1007
End Select
980
1008
1009
+ WScript.Sleep strWaitMed
981
1010
strSSLCertThumb = GetCertAttr(strSSLCert, "Thumbprint" )
982
1011
Call SetBuildfileValue( "SSLCertThumb" , strSSLCertThumb)
983
1012
@@ -1004,9 +1033,10 @@ End Sub
1004
1033
Sub SetWinRMSSL()
1005
1034
Call DebugLog( "SetWinRMSSL:" )
1006
1035
1007
- strCmd = "POWERSHELL Set-WSManInstance -ResourceURI winrm/config/Listener "
1036
+ strCmd = "POWERSHELL $SSLCertThumb = '" & strSSLCertThumb & "' ;"
1037
+ strCmd = strCmd & "Set-WSManInstance -ResourceURI winrm/config/Listener "
1008
1038
strCmd = strCmd & "-SelectorSet @{Address='*';Transport='HTTPS'} "
1009
- strCmd = strCmd & "-ValueSet @{CertificateThumbprint='" & strSSLCertThumb & "' } "
1039
+ strCmd = strCmd & "-ValueSet @{CertificateThumbprint=$SSLCertThumb } "
1010
1040
Call Util_RunExec(strCmd, "" , "" , - 1 )
1011
1041
1012
1042
End Sub
@@ -1047,6 +1077,10 @@ Function GetOUAttr(strOUPath, strUserDNSDomain, strOUAttr)
1047
1077
GetOUAttr = FBManageSecurity.GetOUAttr(strOUPath, strUserDNSDomain, strOUAttr)
1048
1078
End Function
1049
1079
1080
+ Function GetCredential(strPassword, strAccount)
1081
+ GetCredential = FBManageSecurity.GetCredential(strPassword, strAccount)
1082
+ End Function
1083
+
1050
1084
Sub ProcessUser(strLabel, strDescription, strProcess)
1051
1085
Call FBManageSecurity.ProcessUser(strLabel, strDescription, strProcess)
1052
1086
End Sub
0 commit comments