Skip to content

issue #1098 encrypt and decrypt private keys with PGPainless#1103

Merged
DenBond7 merged 3 commits intomasterfrom
ip-1098-enc-dec-pgpainless
Mar 22, 2021
Merged

issue #1098 encrypt and decrypt private keys with PGPainless#1103
DenBond7 merged 3 commits intomasterfrom
ip-1098-enc-dec-pgpainless

Conversation

@IvanPizhenko
Copy link
Contributor

@IvanPizhenko IvanPizhenko commented Mar 20, 2021

close #1098

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.

Looks good, adding a code clarity request.

Not sure about tests, our Android tests can be quite brittle when run in CI, so it's not clear if it passes or not sometimes until Den runs them locally. Hopefully over time it can be improved.

val clipboardText = msg.obj as String
try {
val nodeKeyDetails = NodeCallsExecutor.parseKeys(clipboardText)
val nodeKeyDetails = PgpKey.parseKeys(clipboardText.toByteArray()).second
Copy link
Collaborator

Choose a reason for hiding this comment

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

These .first and .second are not obvious enough - we should find a way to refer to them in a more obvious way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to not introduce extra classes and just use standard Pair class. This can be improved by adding a new data class with more readable field names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively we can completely drop returning format indication (I just tried to mimic what Typescrpt does) and return just key list, as NodeCallsExecutor.parseKeys() did.

Copy link
Contributor Author

@IvanPizhenko IvanPizhenko Mar 21, 2021

Choose a reason for hiding this comment

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

I don't see actually that such indication is used anywhere - so maybe just drop it is the best way to improve.

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 good, adding a code clarity request.

Not sure about tests, our Android tests can be quite brittle when run in CI, so it's not clear if it passes or not sometimes until Den runs them locally. Hopefully over time it can be improved.

Yes, Android tests constantly fail here or there. Can we do something to improve that? Last time I've increased time limit and they've passed - maybe another increase needed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Data class is much, much better here. PgpKey.parseKeys(clipboardText.toByteArray()).isArmored and PgpKey.parseKeys(clipboardText.toByteArray()).keys is much better than .first and .second from code clarity perspective. The added data class is always worth it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@tomholub @IvanPizhenko JUnit tests were broken. That's why tests were not passed.
I will be able to look at them in the morning.

@tomholub tomholub mentioned this pull request Mar 21, 2021
var passphrase: String?,
var errorMsg: String?) : Parcelable {
var errorMsg: String?,
val keyRing: PGPKeyRing? = 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.

@IvanPizhenko Please note if you change a constructor of data class that implements Parcelable you should modify the implementation of Parcelable methods. Otherwise, you will receive a runtime error. It's Android thing. I hope in the future after #1034 we will have not to do that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@IvanPizhenko Please don't try to fix that for now. It seems I need to make some code changes. Too many Android things.

Copy link
Contributor Author

@IvanPizhenko IvanPizhenko Mar 23, 2021

Choose a reason for hiding this comment

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

well, I didn't try to fix anything. Also I didn't know that, I'm generally not developing for Android.

@DenBond7 DenBond7 self-assigned this Mar 22, 2021
.done()
.armorWithFlowcryptHeaders()
} catch (ex: Exception) {
""
Copy link
Collaborator

Choose a reason for hiding this comment

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

@IvanPizhenko Please tell me is there any reason to don't print the stacktrace of an exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DenBond7 This was done to mimic what the Typescript does - it returns empty string on failure. Of course, we can output the exception. But I am just not sure what is the right way to do it on the Android? Just println()? Some logger? Please advice.

Copy link
Contributor Author

@IvanPizhenko IvanPizhenko Mar 23, 2021

Choose a reason for hiding this comment

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

Looked around - looks like just e.printStackTrace() would work good - will add

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, e.printStackTrace() - it will be enough. Anyway, don't need to drop using e.printStackTrace() over the whole Java(Kotlin) code if you don't have enough reason to do that. Usually, it helps to debug errors.

DenBond7
DenBond7 previously approved these changes Mar 22, 2021
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.

Approved after some code changes

@DenBond7 DenBond7 merged commit 63b6748 into master Mar 22, 2021
@DenBond7 DenBond7 deleted the ip-1098-enc-dec-pgpainless branch March 22, 2021 12:19
@DenBond7
Copy link
Collaborator

@DenBond7 should I put this annotation on the any new tests that I'm introducing? I've assumed tests would go to CI by default, but seems like you are marking test explicitly to have them in the CI.

Yes, if we are talking about Android Instrumentation tests (../FlowCrypt/src/androidTest/java). Don't need to do that for Junit tests (../FlowCrypt/src/test/java)

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.

encrypt and decrypt keys using pgpainless

3 participants

Comments