Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to ssl-keystore parameter #824

Merged
merged 7 commits into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions lib/GLPI/Agent/HTTP/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,6 @@ sub _setSSLOptions {
sub _KeyChain_or_KeyStore_Export {
my ($self) = @_;

# Only MacOSX and MSWin32 are supported
return unless $OSNAME =~ /^darwin|MSWin32$/;

eduardomozart marked this conversation as resolved.
Show resolved Hide resolved
# But we don't need to extract anything if we still use an option to authenticate server certificate
return if $self->{ca_cert_file} || $self->{ca_cert_dir} || (ref($self->{ssl_fingerprint}) eq 'ARRAY' && @{$self->{ssl_fingerprint}});

Expand Down Expand Up @@ -603,11 +600,14 @@ sub _KeyChain_or_KeyStore_Export {
SUFFIX => ".pem",
);
my $file = $tmpfile->filename;
my $command = "security find-certificate -a -p";
$command .= " /System/Library/Keychains/SystemRootCertificates.keychain"
if $self->{ssl_keystore} =~ /^system-ssl-ca$/i;
getAllLines(
command => "security find-certificate -a -p > '$file'",
logger => $logger
command => "$command > '$file'",
logger => $logger
);
@certs = IO::Socket::SSL::Utils::PEM_file2certs($file)
push @certs, IO::Socket::SSL::Utils::PEM_file2certs($file)
if -s $file;
} else {
my @certCommands;
Expand Down Expand Up @@ -691,8 +691,15 @@ sub _KeyChain_or_KeyStore_Export {
}
}

# Always include default CA file from Mozilla::CA
if (Mozilla::CA->require()) {
# Like Mozilla::CA, but using certs from /etc/ssl/certs
if ($OSNAME !~ /^darwin|MSWin32$/) {
my $sslcacert = "/etc/ssl/certs/ca-certificates.crt";
push @certs, IO::Socket::SSL::Utils::PEM_file2certs($sslcacert)
if -e $sslcacert;
}

Comment on lines +694 to +700
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said on my first comment, this is not required as this is still the default.

Copy link
Contributor Author

@eduardomozart eduardomozart Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there should be cases where internal CA is used and some automation tool already added the self-signed certificate to system CA store and it's not a public certificate provided by Mozilla::CA. As this use case is supported on Windows and macOS (otherwise it wouldn't need to import the keystore/keychain from those systems), I don't see why don't include support for keystore of other systems too, only if the SSL library loads it by default?

# Include default CA file from Mozilla::CA if @certs is empty
if ((!@certs || $OSNAME eq 'darwin' && $self->{ssl_keystore} !~ /^system-ssl-ca$/i) && Mozilla::CA->require()) {
my $cacert = Mozilla::CA::SSL_ca_file();
push @certs, IO::Socket::SSL::Utils::PEM_file2certs($cacert)
if -e $cacert;
Expand Down
Loading