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

S3 C++: Replace the remaing c code[WIP] Fixes #11 #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Thaodan
Copy link

@Thaodan Thaodan commented Jun 24, 2020

Currently so far:

  • s3_make_date(): Refactored out

Copy link
Owner

@llewelld llewelld left a comment

Choose a reason for hiding this comment

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

This is great, thank you. There are just a couple of style issues to fix.

There's still some lingering C code being called in S3ListResult::onFinished() that's preventing s3.h from being removed. This can be addressed separately, but I guess I wanted to check that this is intentional. Is that correct?

src/s3access.cpp Outdated Show resolved Hide resolved
src/s3access.cpp Outdated Show resolved Hide resolved
src/s3access.cpp Outdated Show resolved Hide resolved
@Thaodan Thaodan force-pushed the s3_client_c++ branch 4 times, most recently from 7a57eed to 472ad31 Compare June 28, 2020 23:05
@Thaodan
Copy link
Author

Thaodan commented Jul 15, 2020

I don't have much knowledge of the s3 c code but this could be a replacement for the c code in C++/Qt removing the need for direct openssl use:
https://wiki.qt.io/HMAC-SHA1

@llewelld
Copy link
Owner

I don't have much knowledge of the s3 c code but this could be a replacement for the c code in C++/Qt removing the need for direct openssl use:
https://wiki.qt.io/HMAC-SHA1

Sorry for taking so long to reply; I hadn't noticed I'd left this question hanging. That's a nice find, but as it happens the openssl linkage will be needed for other things, so I'd prefer to stick with openssl throughout. However the usage in s3_hmac_sign() can be achieved with just a single openssl call, so it would be good to simplify it. See for example its use here.

@llewelld
Copy link
Owner

It should be possible to simplify the MD5 code similarly: https://www.openssl.org/docs/man1.1.1/man3/MD5.html

@Thaodan Thaodan force-pushed the s3_client_c++ branch 2 times, most recently from c288979 to ff3e4e3 Compare August 2, 2020 20:18
@Thaodan
Copy link
Author

Thaodan commented Aug 2, 2020

Is the md5 function used somewhere?

@llewelld
Copy link
Owner

llewelld commented Aug 2, 2020

Is the md5 function used somewhere?

The only instance I could see was in s3_put(), which isn't used yet (and I think probably won't be needed in the future), so feel free to drop both if you also think they're not needed.

@Thaodan Thaodan force-pushed the s3_client_c++ branch 5 times, most recently from ead11c8 to d8a173f Compare August 4, 2020 10:01
Copy link
Owner

@llewelld llewelld left a comment

Choose a reason for hiding this comment

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

This is really great and looking nice and clean. I tested it, and with the "date" part added in it worked great too. I made a few style requests, but the only change that's essential to getting it to work is for the "date" line to be fixed.

src/s3access.cpp Outdated
break;
}

QString signData = methodStr + "\n\n\n" + + "\n/" + m_bucket + "/";
Copy link
Owner

Choose a reason for hiding this comment

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

There's a date missing from here. It should be:

String signData = methodStr + "\n\n\n" +  date + "\n/" + m_bucket + "/";

src/s3access.cpp Outdated
methodStr = "PUT";
qDebug() << "PUT request";
break;
case GET:
Copy link
Owner

Choose a reason for hiding this comment

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

You can remove the case GET: here to match the code further down (or add the same code at line, but best to stay consistent with it).

src/s3access.cpp Outdated
{
QNetworkRequest request;
char *digest;
unsigned char digest[EVP_MAX_MD_SIZE +1 ]; // +1 for the \0 byte
Copy link
Owner

Choose a reason for hiding this comment

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

The +1 is no longer needed here (since you're not adding the null byte after all).

QString signData = methodStr + "\n\n\n" + + "\n/" + m_bucket + "/";

if (signDataKey != nullptr)
signData+=signDataKey;
Copy link
Owner

Choose a reason for hiding this comment

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

For consistency (and because it's a common source of error) I'd be grateful if you could include the curly brackets here.

@@ -168,7 +177,6 @@ QNetworkReply *S3Access::performOp(Method method, QString const &url, QString co
break;
}

free(digest);

Copy link
Owner

Choose a reason for hiding this comment

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

There's an extra line here after you've removed the free(digest). If you could remove it, that would be appreciated.

Copy link
Author

Choose a reason for hiding this comment

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

I don't see that line, I just removed that line here.

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, I wasn't very clear. I mean if you have this:

1.
2. statement
3.

and then remove statement, you end up with two blank lines:

1.
3.

but for purely aesthetic reasons there should only be a single blank line after the switch statement.

Thaodan added 4 commits August 8, 2020 07:10
Moved the creation of the signData string to performOp making
s3_make_date() unneeded. Added signDataKey to allow for optional
signData key for methods like getFile(). Should also make adding
methods that user other Methods easier.

Also cleanes up the converting of date to QString and just converts it
to QBytearray when needed.
Instead of using s3_hmac_sign() which does everything on its own
resuse HMAC() from OpenSSL. This adds some casting that was done
previously inside s3_hmac_sign() to performOp().
In addition we no longer use the deprecated HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
               const EVP_MD *md) (<1.1).

Removes the usage of:
+ s3_hmac_sign()

Contributes to llewelld#11
The S3 struct is no longer used since all c-style s3 methods are no
longer used.
Remove all code that related to it.

Removes the usage of:
+ s3_free()
+ s3_init()

Contributes to llewelld#11.
@llewelld
Copy link
Owner

llewelld commented Aug 8, 2020

You still have [WIP] in the title, but this is good enough -- and substantial enough -- to merge in its current form. Did you have other changes in mind? If you did, it might make sense to put them in a follow-up PR, if you prefer?

@Thaodan
Copy link
Author

Thaodan commented Aug 8, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants