Skip to content

issue #1057 Parsing/decrypting of complex PGP messages in Kotlin#1331

Merged
tomholub merged 6 commits intomasterfrom
ip-1057
Jul 7, 2021
Merged

issue #1057 Parsing/decrypting of complex PGP messages in Kotlin#1331
tomholub merged 6 commits intomasterfrom
ip-1057

Conversation

@IvanPizhenko
Copy link
Contributor

@IvanPizhenko IvanPizhenko commented Jul 4, 2021

This PR introduces native Kotlin-base processing of the complex email messages

close #1057

  • Tests added

To be filled by reviewers

I have reviewed that this PR... (tick whichever items you personally focused on during this review):

  • addresses the issue it closes (if any)
  • code is readable and understandable
  • is accompanied with tests, or tests are not needed
  • is free of vulnerabilities

@IvanPizhenko IvanPizhenko requested review from DenBond7 and tomholub July 4, 2021 17:17
@IvanPizhenko IvanPizhenko requested a review from seisvelas as a code owner July 4, 2021 17:17
@IvanPizhenko
Copy link
Contributor Author

@tomholub I can see some Snyk tests failed, however I can't see what exactly. Please check.

@seisvelas
Copy link
Contributor

@IvanPizhenko Sorry to answer a question not directed at me, but I checked on Snyk and it appears this PR introduces a vulnerable dependency. Specifically, com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20200713.1, which is introduced here:

implementation 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20200713.1'

Depends on a version of com.google.guava which suffers an Information Disclosure vulnerability (you can learn more about how this specific vuln works / can be exploited in Guava here: https://snyk.io/vuln/SNYK-JAVA-COMGOOGLEGUAVA-1015415)

The codebase on https://github.com/OWASP/java-html-sanitizer has actually updated to a non-vulnerable Guava version (here: OWASP/java-html-sanitizer@ad287c3), but there hasn't been a release in quite some time which is why we're having this problem.

The actual vulnerability is that files used in the temp dir created via Guava's createTempDir are readable by all users on the system. Upon deeper inspection, it appears owasp-java-html-sanitizer doesn't even use the vulnerable method, so in practice we should be safe.

Consequently, I've told Snyk to skip this check and mark it as passed.

seisvelas
seisvelas previously approved these changes Jul 5, 2021
@tomholub
Copy link
Collaborator

tomholub commented Jul 5, 2021

Thank you Alex for looking into this 👍

Copy link
Collaborator

@tomholub tomholub left a comment

Choose a reason for hiding this comment

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

Thanks! So far only reviewed the tests. Sorry if the answer is obvious.

}
}

// -------------------------------------------------------------------------------------------
Copy link
Collaborator

Choose a reason for hiding this comment

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

Approximately 14 test files (.txt) were added below, but this test is using only a handful of them. Where are they being loaded and used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All these files should be used in the tests here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like mime-email-*.txt are not used. Will remove them

Copy link
Collaborator

@DenBond7 DenBond7 left a comment

Choose a reason for hiding this comment

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

@IvanPizhenko Please look at my comments. I didn't try your realization yet but it will be a start point of the final migration. On the current stage it's hard to say what is good or not good.

Comment on lines 124 to 127
val type: PgpDecrypt.DecryptionErrorType,
val message: String,
val cause: Throwable? = null
)
) : Parcelable {
Copy link
Collaborator

Choose a reason for hiding this comment

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

unfortunately, we can't use Throwable in Parcelable implementation in data classes. We can't compare Throwable instance here. That's why some of JUnit tests were failed.

Copy link
Collaborator

@tomholub tomholub left a comment

Choose a reason for hiding this comment

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

This PR is pretty massive 👀 which reflects the issue is a complicated one. It looks good. On my end, I mainly want to make sure that all provided test cases are indeed tested (see earlier question) and if not, that we file an issue to test all soon.

Comment on lines +21 to +23
val firstChars = msg.copyOfRange(0, msg.size.coerceAtMost(1000))
.toString(StandardCharsets.US_ASCII)
.toLowerCase(Locale.ROOT)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if the conversion to String can fail with an exception if we give it arbitrary bytes that are non-ascii. If it can fail by throwing, we should catch the error and return false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did the small test:

import java.nio.charset.StandardCharsets
import java.util.Locale

fun main() {
    val a = ByteArray(256)
    for (i in 0..255) a[i] = i.toByte()
    val s = a.toString(StandardCharsets.US_ASCII).toLowerCase(Locale.ROOT)
    println(s)
}

Works for all source byte values.

@tomholub
Copy link
Collaborator

tomholub commented Jul 5, 2021

@IvanPizhenko Please look at my comments. I didn't try your realization yet but it will be a start point of the final migration. On the current stage it's hard to say what is good or not good.

As long as it passes the supplied test cases, then it's well good enough. Of course, some adjustments will be needed once you start integrating, but if we confirm that supplied test cases pass the way they do on TypeScript code (and code style stuff gets adjusted) then this is perfectly fine for merging even if we didn't try to integrate it yet.

@IvanPizhenko
Copy link
Contributor Author

@IvanPizhenko Sorry to answer a question not directed at me, but I checked on Snyk and it appears this PR introduces a vulnerable dependency. Specifically, com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20200713.1, which is introduced here:

implementation 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20200713.1'

Depends on a version of com.google.guava which suffers an Information Disclosure vulnerability (you can learn more about how this specific vuln works / can be exploited in Guava here: https://snyk.io/vuln/SNYK-JAVA-COMGOOGLEGUAVA-1015415)

The codebase on https://github.com/OWASP/java-html-sanitizer has actually updated to a non-vulnerable Guava version (here: OWASP/java-html-sanitizer@ad287c3), but there hasn't been a release in quite some time which is why we're having this problem.

The actual vulnerability is that files used in the temp dir created via Guava's createTempDir are readable by all users on the system. Upon deeper inspection, it appears owasp-java-html-sanitizer doesn't even use the vulnerable method, so in practice we should be safe.

Consequently, I've told Snyk to skip this check and mark it as passed.

Thanks Alex!

@DenBond7 DenBond7 added the PR submitted PR is submitted for this issue label Jul 7, 2021
@DenBond7 DenBond7 added this to the 1.1.9 milestone Jul 7, 2021
@DenBond7
Copy link
Collaborator

DenBond7 commented Jul 7, 2021

@IvanPizhenko I've added some changes to fix tests

Copy link
Collaborator

@tomholub tomholub left a comment

Choose a reason for hiding this comment

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

I've reviewed the changes and they look good. I'll still give it a review regarding the test cases, then can merge.

@@ -0,0 +1,14 @@
-----BEGIN PGP MESSAGE-----
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file is not used anywhere that I can find

@@ -0,0 +1,36 @@
-----BEGIN PGP MESSAGE-----
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file is not used anywhere that I can find

@tomholub tomholub merged commit 7e1ca93 into master Jul 7, 2021
@tomholub tomholub deleted the ip-1057 branch July 7, 2021 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR submitted PR is submitted for this issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parsing/decrypting of complex PGP messages in Kotlin

4 participants