Skip to content

Comments

WIP: apps: Switch to using OSSL_STORE for loading keys, certs, ...#7390

Closed
levitte wants to merge 10 commits intoopenssl:masterfrom
levitte:apps-switch-to-store
Closed

WIP: apps: Switch to using OSSL_STORE for loading keys, certs, ...#7390
levitte wants to merge 10 commits intoopenssl:masterfrom
levitte:apps-switch-to-store

Conversation

@levitte
Copy link
Member

@levitte levitte commented Oct 12, 2018

This makes all the format specifiers largely irrelevant, except for
the ENGINE format when a key is given as a key ID only. However, with
the engine loader, it's possible to change this:

-engine {engineid} -key {keyid} -keyformat ENGINE

To this:

-key engine://{engineid}/{keyid}

We retain the ENGINE format for the sake of compatibility. All other
input formats are simply ignored. Note that output formats is a
different story.

Fixes #1963

@petrovr
Copy link

petrovr commented Oct 14, 2018 via email

@levitte
Copy link
Member Author

levitte commented Oct 14, 2018

Ah, there's a precedent for a engine: scheme. Sure, I can use that instead.

Why someone has implemented a store: scheme is beyond me, though. Does that mean that if I want to express a file name in uri form, I would have to write store:file:///home/levitte/foo.pem? Why isn't file:///home/levitte/foo.pem enough? I cannot see why we should support such a contraption...

@petrovr
Copy link

petrovr commented Oct 15, 2018 via email

@levitte
Copy link
Member Author

levitte commented Oct 15, 2018

Perhaps if store fails with "invalid scheme" then code could try to open file (failback case).

The current file loader does this already, i.e. it defaults to file: if no scheme is present.

@levitte
Copy link
Member Author

levitte commented Oct 15, 2018

Drawback of "Store URI" is that engine may not be loaded. Work around is to keep "engine" argument.

The proper workaround is to do what I do in this PR, i.e. define a engine: scheme loader. See apps/app_engine_loader.c

@kaduk
Copy link
Contributor

kaduk commented Oct 15, 2018

@levitte
Copy link
Member Author

levitte commented Oct 15, 2018

You make a good point. Earlier on, I was think that "nah, it's just private to the openssl app", and that doesn't quite fit the need to registration, and I quote from RFC 7595 section 4 "Guidelines for Provisional URI Scheme Registration":

'Provisional' registration can be used for schemes that are not part of any standard but that are intended for use (or observed to be in use) that is not limited to a private environment within a single organization.

But seeing that PKIX-SSH uses the same scheme, and uses a different syntax to boot, that might be qualification enough to make a provisional registration after all. (I don't see it ever changing status to something more provisionalpermanent, btw)

@levitte levitte force-pushed the apps-switch-to-store branch from 45651b9 to cd85f3f Compare October 17, 2018 09:47
@levitte
Copy link
Member Author

levitte commented Oct 17, 2018

Code updated to use engine:{engineid}:{keyid}

@levitte
Copy link
Member Author

levitte commented Oct 18, 2018

Apparently, I hadn't completed what I said. Now fixed, and tests added.

@levitte
Copy link
Member Author

levitte commented Oct 18, 2018

Finally, this builds and tests fine. I will fix the docs, then it will be time for a review

@petrovr
Copy link

petrovr commented Oct 19, 2018 via email

levitte added 6 commits April 21, 2019 11:53
This capability existed internally, and is now made public.
The prompt includes the URI, to make it clear which object needs a
pass phrase.
This involves exposing two pvkfmt.c functions, but only internally.
This helps load keys with the following scheme:

    engine:{engineid}:{keyid}

This is legacy, but added for the time being to support keys given to
the application like this:

    -engine {engineid} -key {keyid} -keyform ENGINE
This makes all the format specifiers largely irrelevant, except for
the ENGINE format when a key is given as a key ID only.  However, with
the engine loader, it's possible to change this:

    -engine {engineid} -key {keyid} -keyformat ENGINE

To this:

    -key engine:{engineid}:{keyid}

We retain the ENGINE format for the sake of compatibility.  All other
input formats are simply ignored.  Note that output formats is a
different story.

Fixes openssl#1963
This adds a bit of functionality in ossltest, so it can now be used to
load PEM files.  It takes the file name as key ID, but just to make
sure faults aren't ignored, it requires all file names to be prefixed
with 'ot:'.
@levitte levitte force-pushed the apps-switch-to-store branch from c055e63 to 34d8735 Compare April 21, 2019 09:54
@levitte levitte mentioned this pull request Apr 22, 2019
2 tasks
@dwmw2
Copy link
Contributor

dwmw2 commented Apr 25, 2019

I'll echo the "please don't use an unregistered URI scheme" comment with its converse: please do support PKCS#11 URIs directly, without them having to be prefixed or mangled. The {engine}:… form mentioned above would have worked for that, given that the name of the engine in question would be pkcs11.

If you end up with a form that doesn't Just Work for RFC7512 PKCS#11 URIs, please special-case them to use the pkcs11 engine. Thanks.

@levitte
Copy link
Member Author

levitte commented Apr 25, 2019

If you create a proper OSSL_STORE loader that registers the scheme "pkcs11:", then you can use that scheme directly.

The "engine:" 'scheme' is an interim construct to allow access via the older ENGINE calls to access keys; ENGINE_load_private_key and ENGINE_load_public_key. However, if the engine offers an OSSL_STORE loader, there is no reason whatsoever to use the "engine:" 'scheme'

@dwmw2
Copy link
Contributor

dwmw2 commented Apr 25, 2019

Perfect. Thank you.

@mattcaswell
Copy link
Member

Needs a rebase

@mattcaswell mattcaswell added the approval: review pending This pull request needs review by a committer label Oct 31, 2019
@mattcaswell
Copy link
Member

But seeing that PKIX-SSH uses the same scheme, and uses a different syntax to boot, that might be qualification enough to make a provisional registration after all. (I don't see it ever changing status to something more provisionalpermanent, btw)

Was the scheme ever registered as suggested here?

@levitte
Copy link
Member Author

levitte commented Nov 4, 2019

Was the scheme ever registered as suggested here?

No, but can certainly be done. I have the impression that it's not very hard...

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.

I'd also suggest a CHANGES entry might be in order for the change in behaviour of "-inform"

char engineid[256];
size_t engineid_l = q - p;

strncpy(engineid, p, engineid_l);
Copy link
Member

Choose a reason for hiding this comment

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

Using strncpy like this seems incorrect. The point of using strncpy is to not exceed the target buffer size - but you instead pass the string length (which therefore won't copy the '\0') and then manually add \0. So this is likely to go wrong for very large engine URIs.

engineid[engineid_l] = '\0';
e = ENGINE_by_id(engineid);

keyid = OPENSSL_strdup(q + 1);
Copy link
Member

Choose a reason for hiding this comment

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

Check for NULL return?

|| !OSSL_STORE_LOADER_set_error(loader, engine_error)
|| !OSSL_STORE_LOADER_set_close(loader, engine_close)
|| !OSSL_STORE_register_loader(loader)) {
OSSL_STORE_LOADER_free(loader);
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this loader might useful beyond the apps. Does it belong it libcrypto?

Copy link
Member Author

Choose a reason for hiding this comment

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

Considering we have declared ENGINE legacy, I dunno how keen I'm on that. But, we could re-evalutate that when I've finished #9389

}

ok = load_cert_crl_http(uri, onecert, onecrl);
return ok;
Copy link
Member

Choose a reason for hiding this comment

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

Just return directly without the intermediate ok

}
unbuffer(stdin);
cert = dup_bio_in(format);
in = dup_bio_in(0); /* Binary work best */
Copy link
Member

Choose a reason for hiding this comment

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

Should use an explicit macro format here...0 is actually FORMAT_UNDEF. The comment suggests you might have meant FORMAT_BINARY...although as far as I can tell with the dup_bio_in function either will do the same thing.

const OPTIONS crl_options[] = {
{"help", OPT_HELP, '-', "Display this summary"},
{"inform", OPT_INFORM, 'F', "Input format; default PEM"},
{"inform", OPT_INFORM, 'F', "DEPRECATED AND IGNORED"},
Copy link
Member

Choose a reason for hiding this comment

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

Not sure there is a need to shout. This will draw attention to this particular option in any "-help" listing, which seems unwarranted. Same comment for other similar occurrences.

int *matchcount,
const UI_METHOD *ui_method,
void *ui_data);
void *ui_data, const char *uri);
Copy link
Member

Choose a reason for hiding this comment

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

The comment above here needs updating


-key engine:eng:something

This is a temporary measure until engines have learned to provide an
Copy link
Member

Choose a reason for hiding this comment

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

I somehow suspect this won't be temporary and this wording will still be here in 10 years time. Perhaps reword?

EVP_CIPHER_fetch 4748 3_0_0 EXIST::FUNCTION:
EVP_CIPHER_mode 4749 3_0_0 EXIST::FUNCTION:
OSSL_STORE_attach 4750 3_0_0 EXIST::FUNCTION:
OSSL_STORE_LOADER_set_attach 4751 3_0_0 EXIST::FUNCTION:
Copy link
Member

Choose a reason for hiding this comment

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

These functions don't seem to be documented.

ok(run(app(["openssl", "rsa", "-text", "-noout", @pubin,
"-in", "engine:ossltest:ot:$file"])));
ok(run(app(["openssl", "rsa", "-text", "-noout", @pubin,
"-in", "engine:ossltest:ot:".to_abs_file($file)])));
Copy link
Member

Choose a reason for hiding this comment

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

Given the extent of the option changes in the apps this seems very light testing

@levitte
Copy link
Member Author

levitte commented Nov 4, 2019

Needs a rebase

Getting at it now

@levitte levitte changed the title apps: Switch to using OSSL_STORE for loading keys, certs, ... WIP: apps: Switch to using OSSL_STORE for loading keys, certs, ... Nov 4, 2019
@levitte
Copy link
Member Author

levitte commented Nov 4, 2019

The more I looked at the branch, the more I realised it's not quite ready for final review. So I put it back in WIP.

Comments are still welcome!

@levitte levitte added branch: master Applies to master branch and removed approval: review pending This pull request needs review by a committer labels Jan 15, 2020
@t-j-h
Copy link
Member

t-j-h commented Feb 13, 2020

This is still a WIP but placing a hold so it doesn't end up in OpenSSL 3.0 without a discussion and decision on the points already raised in the feedback.

@openssl-machine
Copy link
Collaborator

Automated Ping: This issue is in a state where it requires action by @openssl/omc but the last update was 30 days ago

@DDvO
Copy link
Contributor

DDvO commented Oct 9, 2020

This is related to #12647 and likely further more recent PRs..

@t8m
Copy link
Member

t8m commented Jul 22, 2021

Isn't this change already implemented in master/3.0?

@levitte
Copy link
Member Author

levitte commented Jul 22, 2021

Isn't this change already implemented in master/3.0?

Almost, there were nuances that are not caught by @DDvO's changes.
I've left this unchanged for a while for the sake of priority, but intended to rebase this when I've got a chunk of time, to see what there is left.

@t8m t8m added the triaged: feature The issue/pr requests/adds a feature label Jul 23, 2021
@t8m t8m added this to the Post 3.0.0 milestone Aug 9, 2021
@mattcaswell
Copy link
Member

OMC: There is no decision to be made here at this stage.

@t8m
Copy link
Member

t8m commented Jun 28, 2024

This is no longer relevant. The feature is already implemented.

@t8m t8m closed this Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch: master Applies to master branch triaged: feature The issue/pr requests/adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adapt the openssl app to use STORE_load

9 participants