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

Support indefinite length BER encodings in PKCS #7 #1380

Merged
merged 5 commits into from
Feb 22, 2018

Conversation

SparkiDev
Copy link
Contributor

Also support explicit octet string in enveloped data.

@SparkiDev SparkiDev force-pushed the ber_indef branch 2 times, most recently from 53e6812 to 5158da6 Compare February 19, 2018 07:08
* returns the length of the DER data on success, ASN_PARSE_E if the BER data is
* invalid and BAD_FUNC_ARG if ber is NULL.
*/
int wc_BerToDer(byte* ber, word32 length, byte* der)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a public function we should have a length input for Der size as well so we don't overwrite the Der buffer. It will also catch programming errors on our side.

pkcs7->der = XMALLOC(len, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
if (pkcs7->der == NULL)
return MEMORY_E;
wc_BerToDer(pkiMsg, pkiMsgSz, pkcs7->der);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check the return code here, there's no guarantee in the future that if the first call succeeds on the length check that the second call will succeed as well. Also a good static analyzer should warn on this.

pkcs7->der = XMALLOC(len, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
if (pkcs7->der == NULL)
return MEMORY_E;
wc_BerToDer(pkiMsg, pkiMsgSz, pkcs7->der);
Copy link
Contributor

Choose a reason for hiding this comment

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

return code check needed.

@toddouska
Copy link
Contributor

Looks good, please resolve conflict.

@SparkiDev SparkiDev removed their assignment Feb 20, 2018
Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

Do we have a BER indefinite length encoded message we can add a test with? It would be ideal to have a wolfCrypt test for wc_BerToDer or for the PKCS7 calls.

ret = wc_BerToDer(pkiMsg, pkiMsgSz, NULL, &len);
if (ret != LENGTH_ONLY_E)
return ret;
pkcs7->der = XMALLOC(len, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
Copy link
Contributor

Choose a reason for hiding this comment

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

We find results from XMALLOC need to have a cast in front due to some compilers. (byte*)XMALLOC().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -16702,6 +16702,9 @@ int pkcs7encrypted_test(void)
pkcs7.unprotectedAttribs = testVectors[i].attribs;
pkcs7.unprotectedAttribsSz = testVectors[i].attribsSz;
pkcs7.heap = HEAP_HINT;
#ifdef ASN_BER_TO_DER
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend doing an wc_PKCS7_Init above and remove this. Our test examples should do the init, so the PKCS7 struct is memset to 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@JacobBarthelmeh
Copy link
Contributor

@dgarske sent an example case by email just in case we still need one.

Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

The changes look great! I'm marking this approved. Up to you if you want to add a BER to DER test in this PR or if you want to add later.

Copy link
Contributor

@toddouska toddouska left a comment

Choose a reason for hiding this comment

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

thanks

@toddouska toddouska merged commit 20e7d2d into wolfSSL:master Feb 22, 2018
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.

4 participants