Skip to content

Commit d23ad9f

Browse files
committed
feat: Add ssl-keystore option support
1 parent a30890c commit d23ad9f

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

Changes

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Revision history for GLPI agent
44

55
core:
66
* Prevent certificates overwriting during export from Windows Keystore
7+
* Add new option to specify or disable Windows KeyStore support
78

89
inventory:
910
* fix #700: Add TacticalRMM Remote_Mgmt support for MacOSX

bin/glpi-agent

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ GetOptions(
7070
'scan-profiles',
7171
'server|s=s',
7272
'ssl-fingerprint=s',
73+
'ssl-keystore=s',
7374
'tag|t=s',
7475
'tasks=s',
7576
'timeout=i',

contrib/windows/glpi-agent-packaging.pl

+1
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ sub _tree2xml {
572572
$result .= $ident ." ". qq[ <RegistryValue Name="ca-cert-file" Type="string" Value="[CA_CERT_FILE]" />\n];
573573
$result .= $ident ." ". qq[ <RegistryValue Name="ssl-cert-file" Type="string" Value="[SSL_CERT_FILE]" />\n];
574574
$result .= $ident ." ". qq[ <RegistryValue Name="ssl-fingerprint" Type="string" Value="[SSL_FINGERPRINT]" />\n];
575+
$result .= $ident ." ". qq[ <RegistryValue Name="ssl-keystore" Type="string" Value="[SSL_KEYSTORE]" />\n];
575576
$result .= $ident ." ". qq[ <RegistryValue Name="vardir" Type="string" Value="[VARDIR]" />\n];
576577
$result .= $ident ." ". qq[ <RegistryValue Name="listen" Type="string" Value="[LISTEN]" />\n];
577578
$result .= $ident ." ". qq[ <RegistryValue Name="remote" Type="string" Value="[REMOTE]" />\n];

contrib/windows/packaging/MSI_main-v2.wxs.tt

+6
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@
251251
<SetProperty Id="CMDLINE_SSL_FINGERPRINT" Before="AppSearch" Value="[SSL_FINGERPRINT]" />
252252
<SetProperty Id="SSL_FINGERPRINT" After="AppSearch" Value="[CMDLINE_SSL_FINGERPRINT]"><![CDATA[CMDLINE_SSL_FINGERPRINT<>"" OR CMDLINE_CONFIG="reset"]]></SetProperty>
253253

254+
<Property Id="SSL_KEYSTORE" Secure="yes">
255+
<RegistrySearch Id="SSLKeyStore" Root="HKLM" Key="[%agent_regpath%]" Name="ssl-keystore" Type="raw"/>
256+
</Property>
257+
<SetProperty Id="CMDLINE_SSL_KEYSTORE" Before="AppSearch" Value="[SSL_KEYSTORE]" />
258+
<SetProperty Id="SSL_KEYSTORE" After="AppSearch" Value="[CMDLINE_SSL_KEYSTORE]"><![CDATA[CMDLINE_SSL_KEYSTORE<>"" OR CMDLINE_CONFIG="reset"]]></SetProperty>
259+
254260
<Property Id="SSL_CERT_FILE" Secure="yes">
255261
<RegistrySearch Id="SSLCertFile" Root="HKLM" Key="[%agent_regpath%]" Name="ssl-cert-file" Type="raw"/>
256262
</Property>

lib/GLPI/Agent/Config.pm

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ my $default = {
5353
'server' => undef,
5454
'ssl-cert-file' => undef,
5555
'ssl-fingerprint' => undef,
56+
'ssl-keystore' => undef,
5657
'tag' => undef,
5758
'tasks' => undef,
5859
'timeout' => 180,

lib/GLPI/Agent/HTTP/Client.pm

+34-10
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ sub new {
6161
ca_cert_file => $ca_cert_file,
6262
ssl_cert_file => $ssl_cert_file,
6363
ssl_fingerprint => $params{ssl_fingerprint} || $config->{'ssl-fingerprint'},
64+
ssl_keystore => $params{ssl_keystore} || $config->{'ssl-keystore'},
6465
_vardir => $config->{'vardir'},
6566
};
6667
bless $self, $class;
@@ -569,6 +570,9 @@ sub _KeyChain_or_KeyStore_Export {
569570
}
570571
}
571572

573+
# Support --ssl-keystore=none option
574+
return if $self->{ssl_keystore} && $self->{ssl_keystore} =~ /^none$/i;
575+
572576
# Read certificates are cached for one hour after the service is started
573577
return $_SSL_ca->{_certs}
574578
if $_SSL_ca->{_expiration} && time < $_SSL_ca->{_expiration};
@@ -606,6 +610,36 @@ sub _KeyChain_or_KeyStore_Export {
606610
@certs = IO::Socket::SSL::Utils::PEM_file2certs($file)
607611
if -s $file;
608612
} else {
613+
my @certCommands;
614+
if ($self->{ssl_keystore}) {
615+
foreach my $case (split(/,+/, $self->{ssl_keystore})) {
616+
$case = trimWhitespace($case);
617+
if ($case =~ /^(Store|Enterprise|GroupPolicy|User)?-?(CA|Root)$/) {
618+
my $store = $2 =~ /CA/i ? "CA" : "Root";
619+
my $option = $1 ? " -$1" : "";
620+
push @certCommands, "certutil -Silent -Split$option -Store $store";
621+
} else {
622+
$logger->debug("Unsupported ssl-keystore option definition: $case");
623+
}
624+
}
625+
} else {
626+
@certCommands = (
627+
"certutil -Silent -Split -Store CA",
628+
"certutil -Silent -Split -Store Root",
629+
"certutil -Silent -Split -Enterprise -Store CA",
630+
"certutil -Silent -Split -Enterprise -Store Root",
631+
"certutil -Silent -Split -GroupPolicy -Store CA",
632+
"certutil -Silent -Split -GroupPolicy -Store Root",
633+
"certutil -Silent -Split -User -Store CA",
634+
"certutil -Silent -Split -User -Store Root"
635+
);
636+
}
637+
638+
unless (@certCommands) {
639+
$logger->debug("No keystore to export server certificates from");
640+
return
641+
}
642+
609643
# Windows keystore support
610644
Cwd->require();
611645
my $cwd = Cwd::cwd();
@@ -619,16 +653,6 @@ sub _KeyChain_or_KeyStore_Export {
619653
my $certdir = $tmpdir->dirname;
620654
$certdir =~ s{\\}{/}g;
621655
if (-d $certdir) {
622-
my @certCommands = (
623-
"certutil -Silent -Split -Store CA",
624-
"certutil -Silent -Split -Store Root",
625-
"certutil -Silent -Split -Enterprise -Store CA",
626-
"certutil -Silent -Split -Enterprise -Store Root",
627-
"certutil -Silent -Split -GroupPolicy -Store CA",
628-
"certutil -Silent -Split -GroupPolicy -Store Root",
629-
"certutil -Silent -Split -User -Store CA",
630-
"certutil -Silent -Split -User -Store Root"
631-
);
632656
$logger->debug2("Changing to '$certdir' temporary folder");
633657
chdir $certdir;
634658

0 commit comments

Comments
 (0)