-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUpdate-hMailServerCertificate v1.13.ps1
878 lines (724 loc) · 43.7 KB
/
Update-hMailServerCertificate v1.13.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
<#
.SYNOPSIS
Name: Update-hMailServerCertificate.ps1
The purpose of this script is to automate the process of updating hMailServer's certificate and port bindings.
.DESCRIPTION
ONCE INITIAL INTERACTIVE SETUP HAS BEEN COMPLETED, this script will:
1. Obtain the specified or latest SSL / TLS certificate installed in the local computer account's personal store.
2. Export the certificate to PFX, KEY, and CRT files.
3. For hMailServer:
3a. Authenticate.
3b. Add the SSL / TLS certificate and set the paths to the private and public key files.
3c. Update the SSL / TLS certificate for all TCP/IP ports.
The hMailServer administrator password is required to be:
1. Entered by the user because:
1a. The documentation says that the only API is a COM one which says "you must call Application.Authenticate with valid credentials" and there are no options for keys. Refer to https://www.hmailserver.com/documentation/latest/?page=overview
1b. The only alternative is directly modifying hMailServer's database (file "C:\Program Files (x86)\hMailServer\Database\hMailServer.sdf") but it's encrypted using a key derived from the administrator password so it'd still be needed anyway. Refer to https://www.hmailserver.com/documentation/v5.4/?page=howto_connect_to_mssql
2. Stored locally because it need to be periodically and automatically / programmatically used.
3. Encrypted and stored alongside the keyfile because the only real alternative is using the encryption offered by DPAPI (used in [Export|Import]-CliXml, etc) which was the first method we used but, as it uses keys derived from the users on the computer / system, we found that it's incompatible with the model of the script being setup by a user and executed as the system such as via a Windows service with Certify The Web.
.NOTES
Author: Ben Hooper at Astrix
Tested on: Certify the Web v4.0.8 to v4.1.6 (latest), OpenSSL v1.1.0h to v1.1.1c (latest), and hMailServer v5.6.7 (latest) on Windows Server 2016 and Windows Server 2019 v1809
Version: 1.13
Changes in v1.13 (2019/10/01): Added support for wildcard certificates (as requested / reported by @D4rkiii at https://github.com/astrixsystems/Update-hMailServerCertificate/issues/1)
Changes in v1.12 (2019/08/29): Changed OpenSSL prerequisite by (1) moving it to #1 as it's the one that the user is least likely to be prepared for, (2) offering sources to obtain OpenSSL, and (3) requiring that the EXE has content.
Changes in v1.11 (2019/08/27): Changed OpenSSL switch for exporting public certificate from "-clcerts" to "-chain", as reported by mflorezm and jljtgr at https://community.certifytheweb.com/t/powershell-script-for-hmailserver/585/5
Changes in v1.10 (2019/08/23): Added thumbprint validation, added option to auto-restart hMailServer, changed default preferences to "No" to fail safe, enhanced output of "Obtained matching certificate" by including what store it was obtained from, added additional validation check for the OpenSSL path requiring that it's an EXE file.
Changes in v1.9 (2019/08/22): Fixed problem where auto-elevation would lose parameters; added checking of write access to log file; fixed problem with write access to log file when starting new sessions; enhanced output by (1) changing output type from "performing action-action result" with just "action result" which makes it easier to read, (2) adding tags ("[Success]:", "[ERROR]:") for quick checking of results, and (3) using colours; and fixed issue where Read-Host output wasn't included in logs.
Changes in v1.8 (2019/08/20): Added checking of hMailServer credentials, added notification of storing sensitive data, enhanced port updating logic and output, added handling of empty paths, added status checks for most actions.
Changes in v1.7 (2019/08/19): Added option to specify thumbprint, added automatic administrator elevation option, added checking of whether the private key exists, added removal of credential variables from memory, fixed issue of log parameters not being preserved when auto-restarting, added trimming of the non-subject DN, rephrased output for prerequisite checks, added to description explaining reasons around admin password, and tidied up logic around handling of first run or not.
Changes in v1.6 (2019/08/13): Code-signed, renamed removing "SSL", and restructured "Changes in vX" to include dates.
Changes in v1.5 (2019/08/06 13:28): Added tweaks to make this more user-friendly (option to auto re-run after initial setup, auto strip out quotation marks from paths, etc).
Changes in v1.4 (2019/08/06 09:21): Added logging by default for auto mode.
Changes in v1.3 (2019/08/06 09:26): Added path validation.
Changes in v1.2 (2019/08/05): Added proper setup process for credentials, paths, etc.
Changes in v1.1 (2019/04/23): Formalised script with a proper structure.
Changes in v1.0 (2018/09/17): Created.
.PARAMETER Thumbprint
Uses the certificate that has the specified thumbprint / hash instead of the default which is the most recent one installed in the local computer account's personal store.
.PARAMETER LogOutput
Logs the output to the default file path "C:\<hostname>.Update-hMailServerCertificate.log".
.PARAMETER LogFile
When used in combination with -LogOutput, logs the output to the custom specified file path.
.EXAMPLE
Run with the default settings:
Update-hMailServerCertificate
.EXAMPLE
Run with specified certificate thumbprint:
Update-hMailServerCertificate -Thumbprint 0000000000000000000000000000000000000000
.EXAMPLE
Run with the default settings AND logging to the default path:
Update-hMailServerCertificate -LogOutput
.EXAMPLE
Run with the default settings AND logging to a custom local path:
Update-hMailServerCertificate -LogOutput -LogPath "C:\$env:computername.Update-hMailServerCertificate.log"
.EXAMPLE
Run with the default settings AND logging to a custom network path:
Update-hMailServerCertificate -LogOutput -LogPath "\\servername\filesharename\$env:computername.Update-hMailServerCertificate.log"
#>
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
Param(
[string]$Thumbprint,
[switch]$LogOutput,
[string]$LogPath
)
#----------------------------------------------------------[Declarations]----------------------------------------------------------
$RunAsAdministrator = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator);
$global:FirstRun = $null;
$global:Script_Root = $PSScriptRoot;
$global:Script_PS1File_Name = Split-Path $PSCommandPath -Leaf;
$global:Script_PS1File_FullPath = $PSCommandPath;
$global:Script_ConfigFile_Extension = "config";
$global:Script_ConfigFile_Name = $global:Script_PS1File_Name + "." + $global:Script_ConfigFile_Extension;
$global:Script_ConfigFile_FullPath = "$global:Script_Root\$global:Script_ConfigFile_Name";
$global:Script_KeyFile_Extension = "password.key";
$global:Script_KeyFile_Name = $global:Script_PS1File_Name + "." + $global:Script_KeyFile_Extension;
$global:Script_KeyFile_FullPath = "$global:Script_Root\$global:Script_KeyFile_Name";
$global:Script_PasswordFile_Extension = "password";
$global:Script_PasswordFile_Name = $global:Script_PS1File_Name + "." + $global:Script_PasswordFile_Extension;
$global:Script_PasswordFile_FullPath = "$global:Script_Root\$global:Script_PasswordFile_Name";
$global:hMailServer_Admin_Username = "Administrator";
$LogPath_Default = "$global:Script_Root\$env:computername`_$global:Script_PS1File_Name.log";
#-----------------------------------------------------------[Functions]------------------------------------------------------------
Function Run-FirstSetup {
Param()
Begin {
Write-Host "Configuration files not found. Starting initial setup...";
}
Process {
Try {
Write-Host "`tDue to technical restrictions, this script must store 1 password and 2 private keys in local files. Would you still like to proceed? (y/n)";
$Proceed_General = Read-Host "`t[Input]";
If (($Proceed_General -Like "y") -Or ($Proceed_General -Like "yes")){
Write-Host "`t'Yes' selected. Proceeding...";
Write-Host "";
} Else {
Write-Host "`t'No' selected. Exiting...";
Break;
}
Write-Host "`t(1/4) OpenSSL's EXE file is required to create certain certificate files. Please enter the path below:";
Write-Host "`tThe source can be obtained from https://github.com/openssl/openssl/releases and EXE files can be obtained from https://wiki.openssl.org/index.php/Binaries.";
$OpenSSL_FullPath_Validity = $False;
While ($OpenSSL_FullPath_Validity -Eq $False){
$OpenSSL_FullPath = Read-Host "`t`t[Input]";
# Remove quotation marks, if any
$OpenSSL_FullPath = $OpenSSL_FullPath -Replace '"','';
$OpenSSL_FullPath = $OpenSSL_FullPath -Replace "'","";
$OpenSSL_Extension = [IO.Path]::GetExtension($OpenSSL_FullPath);
If (($OpenSSL_FullPath) -And (Test-Path -Path $OpenSSL_FullPath -PathType Leaf) -And ($OpenSSL_Extension -Like ".exe") -And (Get-Content $OpenSSL_FullPath) -Ne $Null) {
Write-Host -ForegroundColor Green "`t`t[Success]: EXE file path validated.";
$OpenSSL_FullPath_Validity = $True;
} Else {
Write-Host -ForegroundColor Red "`t`t[ERROR]: EXE file path is invalid. Please ensure that the file and path are valid and accessible by this script.";
}
Write-Host "";
}
Write-Host "`t(2/4) hMailServer can only be modified using the administrator password. Please enter this in the popup window. This will be encrypted.";
$hMailServer_AdminPassword_Validity = $False;
While ($hMailServer_AdminPassword_Validity -Eq $False){
$hMailServer_AdminPassword_Secure = (Get-Credential -Credential "Administrator").Password;
$hMailServer_AdminPassword_BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($hMailServer_AdminPassword_Secure);
$hMailServer_AdminPassword_Plaintext = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($hMailServer_AdminPassword_BSTR);
$hMailServer = New-Object -ComObject hMailServer.Application;
$hMailServer_AuthResults = $hMailServer.Authenticate($global:hMailServer_Admin_Username, $hMailServer_AdminPassword_Plaintext);
If ($hMailServer_AuthResults -Eq $Null){
Write-Host -ForegroundColor Red "`t`t[ERROR]: Credentials are invalid. Please ensure that they are correct and try entering them again.";
} Else {
Write-Host -ForegroundColor Green "`t`t[Success]: Credentials validated.";
$hMailServer_AdminPassword_Validity = $True;
}
}
Write-Host "";
# "32" = 32 bytes = 256 bits
$AESKey = New-Object Byte[] 32;
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($AESKey);
If ($AESKey){
Write-Host -ForegroundColor Green "`t`t[Success]: Generated 256-bit AES key.";
Write-Host "";
} Else {
Write-Host -ForegroundColor Red "`t`t[ERROR]: Could not generate 256-bit AES key. Exiting...";
Break;
}
$AESKey | Out-File $global:Script_KeyFile_FullPath;
If ((Get-Content $global:Script_KeyFile_FullPath) -Eq $Null) {
Write-Host -ForegroundColor Red "`t`t[ERROR]: Could not store 256-bit AES key in file '$global:Script_KeyFile_FullPath'. Exiting...";
Break;
} Else {
Write-Host -ForegroundColor Green "`t`t[Success]: Stored 256-bit AES key in file.";
Write-Host "`t`tPath: '$global:Script_KeyFile_FullPath'";
Write-Host "";
}
$hMailServer_AdminPassword_Secure | ConvertFrom-SecureString -Key (Get-Content $global:Script_KeyFile_FullPath) | Set-Content $global:Script_PasswordFile_FullPath;
If ((Get-Content $global:Script_PasswordFile_FullPath) -Eq $Null) {
Write-Host -ForegroundColor Red "`t`t[ERROR]: Could not encrypt password using 256-bit AES key and store in file '$global:Script_PasswordFile_FullPath'. Exiting...";
Break;
} Else {
Write-Host -ForegroundColor Green "`t`t[Success]: Encrypted password using 256-bit AES key and stored in file.";
Write-Host "`t`tPath: '$global:Script_PasswordFile_FullPath'";
Write-Host "";
}
Write-Host "`t(3/4) A folder is required to store hMailServer's SSL / TLS certificates. Please enter the path below:";
$hMailServer_SSLCert_Path_Validity = $False;
While ($hMailServer_SSLCert_Path_Validity -Eq $False){
$hMailServer_SSLCert_Path = Read-Host "`t`t[Input]";
# Remove quotation marks, if any
$hMailServer_SSLCert_Path = $hMailServer_SSLCert_Path -Replace '"','';
$hMailServer_SSLCert_Path = $hMailServer_SSLCert_Path -Replace "'","";
If (($hMailServer_SSLCert_Path) -And (Test-Path -Path $hMailServer_SSLCert_Path -PathType Container)) {
Write-Host -ForegroundColor Green "`t`t[Success]: Folder path validated.";
$hMailServer_SSLCert_Path_Validity = $True;
} Else {
Write-Host -ForegroundColor Red "`t`t[ERROR]: Folder path is invalid. Please ensure that the path is valid and accessible by this script.";
}
Write-Host "";
}
Write-Host "`t(4/4) hMailServer must be restarted for certificate and port changes to take effect. Would you like this to be done automatically? (y/n)";
$Proceed_hMailServer_Restart = Read-Host "`t`t[Input]";
If (($Proceed_hMailServer_Restart -Like "y") -Or ($Proceed_hMailServer_Restart -Like "yes")){
Write-Host "`t`t'Yes' selected.";
$hMailServer_Restart = $True;
} Else {
Write-Host "`t`t'No' selected.";
$hMailServer_Restart = $False;
}
Write-Host "";
$global:Script_ConfigFile_Content = @"
<?xml version="1.0"?>
<ScriptSettings>
<hMailServerSettings>
<CertificateFolderPath>$hMailServer_SSLCert_Path</CertificateFolderPath>
<RestartServer>$hMailServer_Restart</RestartServer>
</hMailServerSettings>
<OpenSSLSettings>
<OpenSSLFullPath>$OpenSSL_FullPath</OpenSSLFullPath>
</OpenSSLSettings>
</ScriptSettings>
"@
# The above here-string terminator cannot be indented for some reason;
New-Item -Path $global:Script_ConfigFile_FullPath -ItemType File -Force | Out-Null;
Set-Content -Path $global:Script_ConfigFile_FullPath -Value $global:Script_ConfigFile_Content;
If ((Get-Content $global:Script_ConfigFile_FullPath) -Eq $Null) {
Write-Host -ForegroundColor Red "`t[ERROR]: Could not store generic configuration in file '$global:Script_ConfigFile_FullPath'. Exiting...";
Break;
} Else {
Write-Host -ForegroundColor Green "`t[Success]: Stored generic configuration in file.";
Write-Host "`tPath: '$global:Script_ConfigFile_FullPath'";
Write-Host "";
}
# Remove credentials from memory. https://get-powershellblog.blogspot.com/2017/06/how-safe-are-your-strings.html
$hMailServer_AdminPassword_Secure = $Null;
$hMailServer_AdminPassword_BSTR = $Null;
$hMailServer_AdminPassword_Plaintext = $Null;
$AESKey = $Null;
[System.GC]::Collect();
}
Catch {
Write-Host -ForegroundColor Red "[ERROR]: Initial setup failed.";
$_.Exception.Message;
$_.Exception.ItemName;
Break;
}
}
End {
If($?){
Write-Host -ForegroundColor Green "[Success]: Initial setup complete.";
}
}
}
Function Update-hMailServerCertificate {
Param()
Begin {
Write-Host "Updating hMailServer's SSL / TLS certificate...";
}
Process {
Try {
$hMailServer_AdminPassword_Secure = Get-Content $global:Script_PasswordFile_FullPath | ConvertTo-SecureString -Key (Get-Content $global:Script_KeyFile_FullPath);
$hMailServer_AdminPassword_BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($hMailServer_AdminPassword_Secure);
$hMailServer_AdminPassword_Plaintext = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($hMailServer_AdminPassword_BSTR);
[xml]$Script_ConfigFile_Content = Get-Content $global:Script_ConfigFile_FullPath;
$hMailServer_SSLCert_Path = $Script_ConfigFile_Content.ScriptSettings.hMailServerSettings.CertificateFolderPath;
$hMailServer_Restart = $Script_ConfigFile_Content.ScriptSettings.hMailServerSettings.RestartServer;
$OpenSSL_FullPath = $Script_ConfigFile_Content.ScriptSettings.OpenSSLSettings.OpenSSLFullPath;
If (($hMailServer_AdminPassword_Secure) -And ($Script_ConfigFile_Content) -And ($hMailServer_SSLCert_Path) -And ($OpenSSL_FullPath)) {
Write-Host -ForegroundColor Green "`t`t[Success]: Loaded existing settings.";
Write-Host "";
} Else {
Write-Host -ForegroundColor Red "`t`t[ERROR]: Could not load existing settings. Exiting...";
Break;
}
If ($Thumbprint){
Write-Host "`t`tThumbprint specified. Obtaining certificate...";
$Regex_SHA = "[0-9a-fA-F]{40}";
If ($Thumbprint -Match $Regex_SHA){
Write-Host -ForegroundColor Green "`t`t`t[Success]: Thumbprint validated.";
Write-Host "";
} Else {
Write-Host -ForegroundColor Red "`t`t`t[ERROR]: Thumbprint invalid. Exiting...";
Break;
}
$Windows_SSLCert = Get-ChildItem -Path "Cert:\" -Recurse | Where { $_.Thumbprint -Eq $Thumbprint };
} Else {
Write-Host "`t`tThumbprint not specified. Obtaining certificate...";
$Windows_SSLCert = Get-ChildItem -Path "Cert:\LocalMachine\My" | Sort-Object -Property NotAfter -Descending | Select-Object -First 1;
}
If ($Windows_SSLCert){
$Windows_SSLCert_IssuedDate = $Windows_SSLCert.NotBefore.ToString("yyyy-MM-dd");
$Windows_SSLCert_Subject = $Windows_SSLCert.Subject.Replace("CN=","").Split(",")[0];
$Windows_SSLCert_Thumbprint = $Windows_SSLCert.Thumbprint;
$Windows_SSLCert_Path = $Windows_SSLCert.PSParentPath.Split("::")[2];
$Windows_SSLCert_Name = "$Windows_SSLCert_IssuedDate - $Windows_SSLCert_Subject";
$Windows_SSLCert_File_Name = $Windows_SSLCert_Name.Replace("*","%WILDCARD%");
$Windows_SSLCert_File_PathAndName = "$hMailServer_SSLCert_Path\$Windows_SSLCert_File_Name";
$Windows_SSLCert_File_PFX = "$Windows_SSLCert_File_PathAndName.pfx";
$Windows_SSLCert_File_KEY_Private = "$Windows_SSLCert_File_PathAndName - private.key";
$Windows_SSLCert_File_CRT_Public = "$Windows_SSLCert_File_PathAndName - public.crt";
If ($Thumbprint){
Write-Host -ForegroundColor Green "`t`t`t[Success]: Obtained matching certificate.";
Write-Host "`t`t`tPath: '$Windows_SSLCert_Path'";
} Else {
Write-Host -ForegroundColor Green "`t`t`t[Success]: Obtained newest certificate from store Local Computer | Personal | Certificates.";
}
Write-Host "`t`t`tSubject: '$Windows_SSLCert_Subject'";
Write-Host "`t`t`tIssued date: $Windows_SSLCert_IssuedDate";
Write-Host "`t`t`tThumbprint: $Windows_SSLCert_Thumbprint";
Write-Host "";
} Else {
Write-Host -ForegroundColor Red "`t`t`t[ERROR]: A certificate could not be obtained. Exiting...";
Break;
}
If (($Windows_SSLCert.HasPrivateKey -Eq $True) -And ($Windows_SSLCert.PrivateKey)){
Write-Host -ForegroundColor Green "`t`t`t[Success]: Verified that the certificate has a corresponding private key.";
Write-Host "";
} Else {
Write-Host -ForegroundColor Red "`t`t`t[ERROR]: Could not verify that the certificate has a corresponding private key. Exiting...";
Break;
}
Write-Host "`t`tExporting files...";
# Generate a random, 30-character password required for the PFX file and store it in a variable to be reused in OpenSSL commands
Add-Type -AssemblyName System.Web;
$Windows_SSLCert_Password_Plaintext = [System.Web.Security.Membership]::GeneratePassword(30, 5);
# Convert the password to a format accepted by the export command
$Windows_SSLCert_Password_Secure = ConvertTo-SecureString -String $Windows_SSLCert_Password_Plaintext -Force -AsPlainText;
If (($Windows_SSLCert_Password_Plaintext) -And ($Windows_SSLCert_Password_Secure)){
Write-Host -ForegroundColor Green "`t`t`t[Success]: Generated random, 30-character password for the upcoming PFX file.";
Write-Host "";
} Else {
Write-Host -ForegroundColor Red "`t`t`t[ERROR]: Could not generate random, 30-character password for the upcoming PFX file. Exiting...";
Break;
}
Export-PfxCertificate -Cert $Windows_SSLCert -FilePath $Windows_SSLCert_File_PFX -Password $Windows_SSLCert_Password_Secure | Out-Null;
If ((Get-Content $Windows_SSLCert_File_PFX) -Eq $Null) {
Write-Host -ForegroundColor Red "`t`t`t[ERROR]: Could not export certificate with private key to password-protected file '$Windows_SSLCert_File_PFX'. Exiting...";
Break;
} Else {
Write-Host -ForegroundColor Green "`t`t`t[Success]: Exported certificate with private key to password-protected file.";
Write-Host "`t`t`tPath: '$Windows_SSLCert_File_PFX'";
Write-Host "";
}
& $OpenSSL_FullPath pkcs12 -in $Windows_SSLCert_File_PFX -passin pass:$Windows_SSLCert_Password_Plaintext -nocerts -nodes -out $Windows_SSLCert_File_KEY_Private;
If ((Get-Content $Windows_SSLCert_File_KEY_Private) -Eq $Null) {
Write-Host -ForegroundColor Red "`t`t`t[ERROR]: Could not extract private key to passwordless file '$Windows_SSLCert_File_KEY_Private'. Exiting...";
Break;
} Else {
Write-Host -ForegroundColor Green "`t`t`t[Success]: Extracted private key to passwordless file.";
Write-Host "`t`t`tPath: '$Windows_SSLCert_File_KEY_Private'";
Write-Host "";
}
& $OpenSSL_FullPath pkcs12 -in $Windows_SSLCert_File_PFX -passin pass:$Windows_SSLCert_Password_Plaintext -clcerts -nokeys -out $Windows_SSLCert_File_CRT_Public;
If ((Get-Content $Windows_SSLCert_File_CRT_Public) -Eq $Null) {
Write-Host -ForegroundColor Red "`t`t`t[ERROR]: Could not extract public key and certificate to file '$Windows_SSLCert_File_CRT_Public'. Exiting...";
Break;
} Else {
Write-Host -ForegroundColor Green "`t`t`t[Success]: Extracted public key and certificate to file.";
Write-Host "`t`t`tPath: '$Windows_SSLCert_File_CRT_Public'";
Write-Host "";
}
Write-Host "`t`tUpdating hMailServer...";
$hMailServer = New-Object -ComObject hMailServer.Application;
$hMailServer_AuthResults = $hMailServer.Authenticate($global:hMailServer_Admin_Username, $hMailServer_AdminPassword_Plaintext);
If ($hMailServer_AuthResults -Eq $Null){
Write-Host -ForegroundColor Red "`t`t`t[ERROR]: Could not connect and authenticate. Please delete file '$global:Script_PasswordFile_FullPath', re-run this script, and ensure that the submitted hMailServer administrator password is correct. Exiting...";
Break;
} Else {
Write-Host -ForegroundColor Green "`t`t`t[Success]: Connected and authenticated.";
Write-Host "";
}
$hMailServer_SSLCert_New = $hMailServer.Settings.SSLCertificates.Add();
$hMailServer_SSLCert_New.Name = $Windows_SSLCert_Name;
$hMailServer_SSLCert_New.PrivateKeyFile = $Windows_SSLCert_File_KEY_Private;
$hMailServer_SSLCert_New.CertificateFile = $Windows_SSLCert_File_CRT_Public;
$hMailServer_SSLCert_New.Save();
# Once certificate object has been created, obtain ID
$hMailServer_SSLCert_New_ID = $hMailServer_SSLCert_New.ID;
If ($hMailServer_SSLCert_New_ID) {
Write-Host -ForegroundColor Green "`t`t`t[Success]: Added certificate '$Windows_SSLCert_Name' and set paths.";
Write-Host "";
} Else {
Write-Host -ForegroundColor Red "`t`t`t[ERROR]: Could not add certificate '$Windows_SSLCert_Name' and set paths. Exiting...";
Break;
}
Write-Host "`t`t`tSetting new certificate for secure TCP/IP ports...";
$hMailServer_TCPIPPort_All = $hMailServer.Settings.TCPIPPorts;
For ($i = 0; $i -NE $hMailServer_TCPIPPort_All.Count; $i++){
$hMailServer_TCPIPPort_Current = $hMailServer_TCPIPPort_All.Item($i);
If ($hMailServer_TCPIPPort_Current.Protocol -Eq 1){
$hMailServer_TCPIPPort_Current_Protocol = "SMTP";
} ElseIf ($hMailServer_TCPIPPort_Current.Protocol -Eq 3){
$hMailServer_TCPIPPort_Current_Protocol = "POP3";
} ElseIf ($hMailServer_TCPIPPort_Current.Protocol -Eq 5){
$hMailServer_TCPIPPort_Current_Protocol = "IMAP";
}
$hMailServer_TCPIPPort_Current_Port = $hMailServer_TCPIPPort_Current.PortNumber;
If ($hMailServer_TCPIPPort_Current.ConnectionSecurity -Eq 0){
$hMailServer_TCPIPPort_Current_ConnectionSecurity = "None";
} ElseIf ($hMailServer_TCPIPPort_Current.ConnectionSecurity -Eq 1){
$hMailServer_TCPIPPort_Current_ConnectionSecurity = "SSL/TLS";
} ElseIf ($hMailServer_TCPIPPort_Current.ConnectionSecurity -Eq 2){
$hMailServer_TCPIPPort_Current_ConnectionSecurity = "STARTTLS (Optional)";
} ElseIf ($hMailServer_TCPIPPort_Current.ConnectionSecurity -Eq 3){
$hMailServer_TCPIPPort_Current_ConnectionSecurity = "STARTTLS (Required)";
}
If (($hMailServer_TCPIPPort_Current_ConnectionSecurity) -And ($hMailServer_TCPIPPort_Current_ConnectionSecurity -Ne "None")){
$hMailServer_TCPIPPort_Current.SSLCertificateID = $hMailServer_SSLCert_New_ID;
$hMailServer_TCPIPPort_Current.Save();
If ($hMailServer_TCPIPPort_Current.SSLCertificateID -Eq $hMailServer_SSLCert_New_ID) {
Write-Host -ForegroundColor Green "`t`t`t`t[Success]: Updated port with protocol $hMailServer_TCPIPPort_Current_Protocol, number $hMailServer_TCPIPPort_Current_Port, and connection security '$hMailServer_TCPIPPort_Current_ConnectionSecurity'.";
Write-Host "";
} Else {
Write-Host -ForegroundColor Red "`t`t`t`t[ERROR]: Could not update port with protocol $hMailServer_TCPIPPort_Current_Protocol, number $hMailServer_TCPIPPort_Current_Port, and connection security '$hMailServer_TCPIPPort_Current_ConnectionSecurity'.";
}
}
}
If ($hMailServer_Restart -Eq $True){
Write-Host "`t`t`thMailServer restart was opted into during initial setup.";
Restart-Service -Name hMailServer -Force -ErrorAction SilentlyContinue;
If ($? -Eq $True){
Write-Host -ForegroundColor Green "`t`t`t[Success]: Restarted Windows service 'hMailServer'.";
} Else {
Write-Host -ForegroundColor Red "`t`t`t[ERROR]: Could not restart Windows service 'hMailServer'.";
}
} Else {
Write-Host "`t`t`t[Notification]: Windows service 'hMailServer' needs restarting.";
}
Write-Host "";
# Remove credentials from memory. https://get-powershellblog.blogspot.com/2017/06/how-safe-are-your-strings.html
$Windows_SSLCert_Password_Plaintext = $Null;
$Windows_SSLCert_Password_Secure = $Null;
$hMailServer_AdminPassword_Secure = $Null;
$hMailServer_AdminPassword_BSTR = $Null;
$hMailServer_AdminPassword_Plaintext = $Null;
[System.GC]::Collect();
}
Catch {
Write-Host -ForegroundColor Red "[ERROR]: Could not update hMailServer's SSL / TLS certificate.";
$_.Exception.Message;
$_.Exception.ItemName;
Break;
}
}
End {
If($?){
Write-Host -ForegroundColor Green "[Success]: Updated hMailServer's SSL / TLS certificate.";
}
}
}
#-----------------------------------------------------------[Execution]------------------------------------------------------------
# Check whether initial setup has been completed
If ((Test-Path -Path $global:Script_ConfigFile_FullPath) -And (Test-Path -Path $global:Script_PasswordFile_FullPath) -And (Test-Path -Path $global:Script_KeyFile_FullPath)) {
$global:FirstRun = $False;
} Else {
$global:FirstRun = $True;
}
If (-Not $LogPath) {
$LogPath = $LogPath_Default;
}
# Check write access to log file
If ($LogOutput -Eq $True) {
Try {
[io.file]::OpenWrite($LogPath).Close();
}
Catch {
Write-Host -ForegroundColor Red "[ERROR]: Unable to log output to file '$LogPath' due to insufficient permissions.";
Write-Host "";
$LogOutput = $False;
}
}
# Set up logging
If ($LogOutput -Eq $True) {
Start-Transcript -Path $LogPath -Append | Out-Null;
If ($global:FirstRun -Eq $True){
Write-Host "Logging output to file.";
} ElseIf ($global:FirstRun -Eq $False){
Write-Host "Initial setup has already been completed so assuming automatic mode and logging output to file.";
}
Write-Host "Path: '$LogPath'"
Write-Host "";
Write-Host "----------------------------------------------------------------";
Write-Host "";
}
# Handle admin
If ($RunAsAdministrator -Eq $False) {
Write-Host "This script requires administrative permissions but was not run as administrator. Elevate now? (y/n)";
$Elevate = Read-Host "[Input]";
If (($Elevate -Like "y") -Or ($Elevate -Like "yes")){
Write-Host "'Yes' selected. Launching a new session in a new window and ending this session...";
# Preserve original parameters
$AllParameters_String = "";
ForEach ($Parameter in $PsBoundParameters.GetEnumerator()){
$Parameter_Key = $Parameter.Key;
$Parameter_Value = $Parameter.Value;
$Parameter_Value_Type = $Parameter_Value.GetType().Name;
If ($Parameter_Value_Type -Eq "SwitchParameter"){
$AllParameters_String += " -$Parameter_Key";
} Else {
$AllParameters_String += " -$Parameter_Key $Parameter_Value";
}
}
$Arguments = ' -NoExit -File "' + $global:Script_PS1File_FullPath + '"' + $AllParameters_String;
If ($LogOutput -Eq $True) {
Stop-Transcript | Out-Null;
}
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $Arguments;
# Stop-Process -Id $PID;
Break;
} Else {
Write-Host "'No' selected. Exiting...";
If ($LogOutput -Eq $True) {
Stop-Transcript | Out-Null;
}
Break;
}
}
# Execute main functions
If ($global:FirstRun -Eq $True) {
Run-FirstSetup;
Write-Host "";
Write-Host "Re-run this script to actually update hMailServer? (y/n)";
$ReRun = Read-Host "[Input]";
If (($ReRun -Like "y") -Or ($ReRun -Like "yes")){
Write-Host "";
Write-Host "----------------------------------------------------------------";
Write-Host "";
Write-Host " ...RESTARTING...";
Write-Host "";
Write-Host "----------------------------------------------------------------";
Write-Host "";
If ($LogOutput -Eq $True) {
Stop-Transcript | Out-Null;
}
& $global:Script_PS1File_FullPath -NoExit @PSBoundParameters;
Break;
}
} ElseIf ($global:FirstRun -Eq $False){
Update-hMailServerCertificate;
}
Write-Host "";
Write-Host "----------------------------------------------------------------";
Write-Host "";
Write-Host "Script complete.";
<#
If ($Host.Name -Eq "ConsoleHost"){
Write-Host "Script complete. Press any key to continue..."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null
}
#>
If ($LogOutput -Eq $True) {
Stop-Transcript | Out-Null;
}
# SIG # Begin signature block
# MIIkagYJKoZIhvcNAQcCoIIkWzCCJFcCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUr97ceZaFo8G0LbXFBb5JDPws
# Z16ggh92MIIEhDCCA2ygAwIBAgIQQhrylAmEGR9SCkvGJCanSzANBgkqhkiG9w0B
# AQUFADBvMQswCQYDVQQGEwJTRTEUMBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNV
# BAsTHUFkZFRydXN0IEV4dGVybmFsIFRUUCBOZXR3b3JrMSIwIAYDVQQDExlBZGRU
# cnVzdCBFeHRlcm5hbCBDQSBSb290MB4XDTA1MDYwNzA4MDkxMFoXDTIwMDUzMDEw
# NDgzOFowgZUxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJVVDEXMBUGA1UEBxMOU2Fs
# dCBMYWtlIENpdHkxHjAcBgNVBAoTFVRoZSBVU0VSVFJVU1QgTmV0d29yazEhMB8G
# A1UECxMYaHR0cDovL3d3dy51c2VydHJ1c3QuY29tMR0wGwYDVQQDExRVVE4tVVNF
# UkZpcnN0LU9iamVjdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM6q
# gT+jo2F4qjEAVZURnicPHxzfOpuCaDDASmEd8S8O+r5596Uj71VRloTN2+O5bj4x
# 2AogZ8f02b+U60cEPgLOKqJdhwQJ9jCdGIqXsqoc/EHSoTbL+z2RuufZcDX65OeQ
# w5ujm9M89RKZd7G3CeBo5hy485RjiGpq/gt2yb70IuRnuasaXnfBhQfdDWy/7gbH
# d2pBnqcP1/vulBe3/IW+pKvEHDHd17bR5PDv3xaPslKT16HUiaEHLr/hARJCHhrh
# 2JU022R5KP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