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

read OPENSSLDIR from registry #24450

Closed
wants to merge 37 commits into from

Conversation

nhorman
Copy link
Contributor

@nhorman nhorman commented May 21, 2024

The windows installer we have allows for targeting arbitrary locations when installing our software. But we have a build time defined default directory OPENSSLDIR which may not match that target, leading to missing configuration files/etc. Enhance openssl to query the registry for the key that our installer creates allowing for an installation to match the run time defaults. Back off to the build time directory only if the key is not defined

@nhorman nhorman self-assigned this May 21, 2024
@nhorman nhorman linked an issue May 21, 2024 that may be closed by this pull request
2 tasks
@mattcaswell mattcaswell added branch: master Merge to master branch approval: review pending This pull request needs review by a committer approval: otc review pending This pull request needs review by an OTC member triaged: feature The issue/pr requests/adds a feature hold: needs tests The PR needs tests to be added to it labels May 21, 2024
Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

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

We need a test for this.

What about MODULESDIR and ENGINESDIR?

Do we also need some documentation?

crypto/x509/x509_def.c Outdated Show resolved Hide resolved
crypto/x509/x509_def.c Outdated Show resolved Hide resolved
crypto/x509/x509_def.c Outdated Show resolved Hide resolved
crypto/x509/x509_def.c Outdated Show resolved Hide resolved
crypto/x509/x509_def.c Outdated Show resolved Hide resolved
@nhorman nhorman force-pushed the read-openssldir-from-registry branch from 995c03b to d125bc4 Compare May 23, 2024 19:51
@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label May 23, 2024
Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

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

Some documentation and a test would still be good.

crypto/defaults.c Outdated Show resolved Hide resolved
crypto/defaults.c Outdated Show resolved Hide resolved
crypto/defaults.c Outdated Show resolved Hide resolved
crypto/defaults.c Show resolved Hide resolved
crypto/defaults.c Outdated Show resolved Hide resolved
crypto/defaults.c Outdated Show resolved Hide resolved
crypto/defaults.c Outdated Show resolved Hide resolved
crypto/x509/x509_def.c Outdated Show resolved Hide resolved
crypto/x509/x509_def.c Show resolved Hide resolved
Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

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

Looks good. Just some minor nits. Still needs documentation/test

crypto/defaults.c Outdated Show resolved Hide resolved
crypto/defaults.c Outdated Show resolved Hide resolved
crypto/x509/x509_def.c Outdated Show resolved Hide resolved
NOTES-WINDOWS.md Outdated Show resolved Hide resolved
NOTES-WINDOWS.md Outdated Show resolved Hide resolved
doc/man7/fips_module.pod Outdated Show resolved Hide resolved
test/recipes/02-test_windows_registry.t Outdated Show resolved Hide resolved
test/recipes/02-test_windows_registry.t Outdated Show resolved Hide resolved
crypto/defaults.c Outdated Show resolved Hide resolved
@mattcaswell
Copy link
Member

Also this needs a rebase

@mattcaswell
Copy link
Member

I'm wondering whether the registry key look up should be a compile time option. Consider the example where someone installs OpenSSL on their machine using the installer. But they also have an application which has statically linked OpenSSL (or maybe just bundled its own version of OpenSSL). Suddenly that application will start getting its locations from the registry and maybe break.

@mattcaswell
Copy link
Member

I'm wondering whether the registry key look up should be a compile time option. Consider the example where someone installs OpenSSL on their machine using the installer. But they also have an application which has statically linked OpenSSL (or maybe just bundled its own version of OpenSSL). Suddenly that application will start getting its locations from the registry and maybe break.

Maybe the compile time option could be set by setting an installer "context" define "-DINSTALLCONTEXT=blah", which could be included in the registry key and stop different builds of OpenSSL (maybe produced by different people) from interfering with each other.

Copy link
Contributor

@FdaSilvaYY FdaSilvaYY left a comment

Choose a reason for hiding this comment

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

Few comments about Unicode possible issues.

crypto/defaults.c Outdated Show resolved Hide resolved
crypto/defaults.c Outdated Show resolved Hide resolved
crypto/defaults.c Outdated Show resolved Hide resolved
crypto/defaults.c Outdated Show resolved Hide resolved
crypto/defaults.c Outdated Show resolved Hide resolved
doc/man7/fips_module.pod Outdated Show resolved Hide resolved
@nhorman
Copy link
Contributor Author

nhorman commented May 29, 2024

@mattcaswell I think adding a version prefix to the key would be the less confusing way to go, then each installation would just use their respective key. Ostensibly if someone has release installed via the installer, then builds openssl manually the version string should have been bumped, and there will be no conflict. the corner case there is if someone builds from an old tag against an already installed version, but at that point they have the environment variables to allow redirection. Presumably, it also seems unlikely that someone interested in using the windows installer will also be building locally that often, given that the installer is being created so that users don't have to build openssl themselves

@mattcaswell
Copy link
Member

@mattcaswell I think adding a version prefix to the key would be the less confusing way to go, then each installation would just use their respective key. Ostensibly if someone has release installed via the installer, then builds openssl manually the version string should have been bumped, and there will be no conflict. the corner case there is if someone builds from an old tag against an already installed version, but at that point they have the environment variables to allow redirection. Presumably, it also seems unlikely that someone interested in using the windows installer will also be building locally that often, given that the installer is being created so that users don't have to build openssl themselves

I disagree. I think it is very likely that people will end up a directly installed version of OpenSSL and a version of OpenSSL coming from somewhere else - quite possible of the same version (e.g. the static linking case where OpenSSL is being used in an application and maybe the end user is not even aware of it - plus a directly installed version). I think there is potential for huge confusion here and opportunity for things to be messed up. This is why I think having the registry keys thing being a build time option (off by default) is going to be essential. Having an installer specific context as an element in the key name in addition to the version would be a good thing too IMO to further reduce the possibility of problems.

Copy link
Contributor

@FdaSilvaYY FdaSilvaYY left a comment

Choose a reason for hiding this comment

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

2 small comments

crypto/defaults.c Show resolved Hide resolved
crypto/x509/x509_def.c Outdated Show resolved Hide resolved
@nhorman nhorman force-pushed the read-openssldir-from-registry branch 5 times, most recently from 00241fa to 7ea9aba Compare June 3, 2024 20:39
@mattcaswell mattcaswell added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Jul 8, 2024
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Jul 9, 2024
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@nhorman
Copy link
Contributor Author

nhorman commented Jul 9, 2024

merged to master

@nhorman nhorman closed this Jul 9, 2024
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Build time defaults aren't great for windows, in which various macros
(like OPENSSLDIR) are selected at build time, but may be selected
differently at install time.  Add an internal defaults api to return the
build time constants on unix systems, but instead query registry keys
for the form:
HLKM\SOFTWARE\OpenSSL-{version}-{wininstallcontext}
Such that each built version of openssl may maintain its own set of
registry keys to identify these locations, and be set administratiely as
appropriate at install or run time

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Now that we can query for install time registry keys on windows, convert
users of these macros to use the api instead

Add a unit test to validate the functionality of our reg key lookups

Add a test to check to make sure our registry key lookups work.  note
this test only runs on windows (clearly), but also only if the registry
keys are set via an installer or some other manual process (to be done
in the CI workflow)

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Add a test to check to make sure our registry key lookups work.  note
this test only runs on windows (clearly), but also only if the registry
keys are set via an installer or some other manual process (to be done
in the CI workflow)

Also add workflow steps to set registry keys for testing

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
On windows ci we're using powershell operations, need to follow those
rules

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
to prevent security issues, don't fall back to build time default
locations, instead return the string "UNDEFINED"

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Make it more in line with other command line defines, and a bit shorter

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
We don't want to allow windows systems on new installs to use
OPENSSLDIR/MODULESDIR/ENGINESDIR at all, as it makes no sense to define
paths at build time that have no meaning at install time.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
To prevent inadvertent use of insecure directories, we need to be able
to detect and react when our new registry keys aren't set, which implies
allowing the values for the dynamic representations of
OPENSSLDIR/ENGINESDIR/MODULESDIR to return NULL.  This in turn requires
that we detect and handle NULL string in several call sites that
previously assumed they would never be NULL.  This commit fixes those up

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
The behavior of windows with registry keys is somewhat confusing, and
based on both build time defines, and reg key availablility.  Add a
table defining behavior in all cases

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Don't need the -w option on non-windows builds

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Fix up some indenting, and ensure that the run_once routines don't get
defined if OSSL_WINCTX isn't defined to avoid compiler errors

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
we want patch level updates to use the same keys, so only create the key
against the major.minor version

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
Because openssl with -DOSSL_WINCTX no longer falls back to build time
defines, we have a chicken and egg problem.  CI needs to query openssl
for its version string so registry keys can be set properly, but openssl
version refuses to run because no configuration file can be found

So we work around it by, for the purposes of setting the registry keys,
we set OPENSSL_CONF to a know config file, so that openssl version runs
properly.

Once the version is extracted, we can set the registry keys, and openssl
will function properly without OPENSSL_CONF set

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
The addition of sed and awk, while available in the windows vm's for CI
in powershell, don't behave as I would expect (though the same commands
work with a local installation on windows using GnuWin32).  In trying to
figure out what was going on I found it was far more stable and
predictable to use the powershell -split and -replace commands instead
of sed and awk

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
openssl-machine pushed a commit that referenced this pull request Jul 9, 2024
the openssl application attempts to load a config file on startup
always, calling x509_get_default_cert_area() to locate the file.  On
Windows builds with -DOSSL_WINCTX set, this fails if the corresponding
registry keys are unset. allow openssl to continue to function properly
for applets that don't actually require a configuration file.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #24450)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Merge to master branch severity: fips change The pull request changes FIPS provider sources tests: present The PR has suitable tests present triaged: feature The issue/pr requests/adds a feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Implement relocatable binaries for windows installer
8 participants