Skip to content

Add a URI decoder, with tests#1961

Closed
levitte wants to merge 12 commits intoopenssl:masterfrom
levitte:uri
Closed

Add a URI decoder, with tests#1961
levitte wants to merge 12 commits intoopenssl:masterfrom
levitte:uri

Conversation

@levitte
Copy link
Member

@levitte levitte commented Nov 19, 2016

Checklist
  • documentation is added or updated
  • tests are added or updated
  • CLA is signed
Description of change

The test uses test/uritests.txt. That file could use some more tests, please suggest some.

Fixes #1957

@richsalz
Copy link
Contributor

have you looked at any tests from w3c? Google it, there's a bunch.

@levitte
Copy link
Member Author

levitte commented Nov 20, 2016

Most tests are about uri joining, which this module doesn't do.
I finally found a file with a large number of "interesting" uris, though. I'm currently working through it to fill uritests.txt

@levitte
Copy link
Member Author

levitte commented Nov 20, 2016

Ok, that's a load of test URIs, and the bugs they helped clear out fixed

@levitte
Copy link
Member Author

levitte commented Dec 6, 2016

Rebased on top of a fresher master

@levitte
Copy link
Member Author

levitte commented Feb 21, 2017

Update: there is now a function to decode the authority into its smaller parts, user, password, host and service, as well as a function to do percent decoding inline.

Copy link
Contributor

@richsalz richsalz left a comment

Choose a reason for hiding this comment

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

you find it useful/interesting to look at the stanza stuff in bntest.c

}

static int linecounter = 0;
static TEST_DATA *read_test_data(FILE *f)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a useful function; e.g., bntest and exptest could use it.


if (*p == '\n') {
if (test_data != NULL)
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

add skip lines starting with #

@richsalz
Copy link
Contributor

richsalz commented Mar 1, 2017

Actually, perhaps go the other say. Look at test/bntest.c, which has a generic key/value reader. Pull that out and then use it in your code here, with semantics on top of the PAIRs.

@levitte
Copy link
Member Author

levitte commented Mar 1, 2017

Ok, @mattcaswell, I think I've responded to all your comments.

@levitte
Copy link
Member Author

levitte commented Mar 1, 2017

The better idea would be to make a stanza library for everyone to use instead of doing reuse-by-copy.

@richsalz
Copy link
Contributor

richsalz commented Mar 1, 2017

well, yeah, that's what i was suggesting you do :)

@levitte
Copy link
Member Author

levitte commented Mar 1, 2017

Ah. Frankly, I'd rather do that refactor in a separate PR.

@levitte
Copy link
Member Author

levitte commented Mar 1, 2017

@richsalz, I noticed your comments about uri_charmap, even though github seems to have lost them.

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 took another scan through this and picked up a few more nits.

The main stumbling block for me on this is the licence question.

crypto/uri.c Outdated
if (++dblcolon > 1)
break;
maxcolons -= 2;
} else
Copy link
Member

Choose a reason for hiding this comment

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

{} on else

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup


/* Check if the loop stopped because of an invalid character */
if (!is_valid(p[off])) {
char tmpbuf[200];
Copy link
Member

Choose a reason for hiding this comment

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

newline after this

Copy link
Member Author

Choose a reason for hiding this comment

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

Okie

crypto/uri.c Outdated
{
const char *p = uri;

OPENSSL_init_crypto(0, NULL);
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if this is actually necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's been some time, I do recall there was a reason but cannot remember what it was...

Copy link
Member

Choose a reason for hiding this comment

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

It would be good to know. The thing is we are supposed to auto-initialise if we call any functions that need it. These functions don't seem to need it themselves (e.g. no shared global data etc), so if this call was necessary then it suggests some other function call was made that didn't auto-initialise when (possibly) it should have done.

Copy link
Member Author

Choose a reason for hiding this comment

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

It might be something in the STORE effort that got jinxed... Anyway, I've just taken those inits away, things are still working fine, so...

crypto/uri.c Outdated
{
const char *p = authority;

OPENSSL_init_crypto(0, NULL);
Copy link
Member

Choose a reason for hiding this comment

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

and here

} else if (strcasecmp(key, "scheme") == 0
|| strcasecmp(key, "decoded_scheme") == 0) {
if (test_data != NULL && test_data->expected.scheme == NULL) {
test_data->expected.scheme = value;
Copy link
Member

Choose a reason for hiding this comment

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

Weren't you going to do this stuff in a macro?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, right!

@levitte
Copy link
Member Author

levitte commented Mar 2, 2017

As for licensing, if we don't get an answer, I'll simply take it all away and we'll just add new cases as time goes.

@levitte
Copy link
Member Author

levitte commented Mar 2, 2017

I just discovered that the IPv6 address parser failed on some perfectly acceptable addresses...

@levitte
Copy link
Member Author

levitte commented Mar 2, 2017

I rewrote test/uritests.txt to only include URIs I've written myself, or some taken from a CC0 licensed document (verifiable)

Also fixed a few errors in the IPv6address check

@levitte levitte requested review from mattcaswell and richsalz March 2, 2017 15:31
@levitte
Copy link
Member Author

levitte commented Mar 2, 2017

With a simplification of #2011, this turned out not to be necessary any more.

@cweb, sorry about the noise.

@levitte levitte closed this Mar 2, 2017
@dwmw2
Copy link
Contributor

dwmw2 commented Jun 1, 2017

This is abandoned, right? If it comes back, does it need to support RFC7512 URIs too?

I was actually inclined to just use libp11-kit for a PKCS#11 STORE so I don't really need it, but if OpenSSL has a URI parser then it would make sense for me to use it.

@levitte
Copy link
Member Author

levitte commented Jun 1, 2017

It is abandoned, yes.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

URI decoder

6 participants