-
Notifications
You must be signed in to change notification settings - Fork 54
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
Lower required Android API to 9 and use Animal Sniffer #18
Conversation
buffer.get(identifierByteRepresentation); | ||
return identifierByteRepresentation; | ||
return identifier.getBytes(Charset.forName("UTF-8")); | ||
// final ByteBuffer buffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(identifier)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be removed? (the comments)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commented stuff can go, I missed that bit. Thank you :)
public final static Instant EXPIRED_KEY_CREATION_TIME = ZonedDateTime | ||
.parse("2018-03-25T10:55:31Z").toInstant(); | ||
public final static Date EXPIRED_KEY_CREATION_TIME = | ||
new Date(1521975331000L); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a 'readable' date
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to look into how to parse a date string directly into a Date, but I will see what I can do :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2018-12-31 23:59")
should so the trick :-)
@@ -327,7 +329,7 @@ public void encrypt_decrypt_yieldsOriginalPlaintext() | |||
final OutputStream outputStream = BouncyGPG | |||
.encryptToStream() | |||
.withConfig(Configs.keyringConfigFromFilesForSender()) | |||
.setReferenceDateForKeyValidityTo(Instant.MAX) | |||
.setReferenceDateForKeyValidityTo(new Date(Long.MAX_VALUE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly not sure if this is supported (haven't checked it though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instant.MAX
will create an Instant representing "1000000000-12-31T23:59:59.999999999Z", while new Date(Long.MAX_VALUE)
will represent "292278994-17-08T00:12:55MST". I'm not sure if this is an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is fine then. neither will hit any of us during our livetime :-)
@@ -63,11 +63,13 @@ public void addPublicKey(byte[] encodedPublicKey) throws IOException, PGPExcepti | |||
this.publicKeyRings = PGPPublicKeyRingCollection | |||
.addPublicKeyRing(this.publicKeyRings, pgpPub); | |||
} | |||
catch (IOException e) { | |||
catch (Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why that? have you experienced 'non-IOSExceptions'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to make sure that the Streams are also closed on PGPExceptions.
Hi Paul, thanks for the contribution! Although possible, I am a bit reluctant to force the library to Java 7 features. But this is not necessarily a blocker (for now). Are you restricted to Android API 9? Java 8 is supported with SDK 24. SDK 24 is used on ~35% of all devices. From what I have heard Bouncy Castle does not run well on android, but that could be old news. Have you already tried to run Bouncy Castle on API v9 devices? (see the linked Spongy Castle issue) |
I'm also fine with maintaining my own fork for now :) I just hope that my contributions might benefit others, so I try to upstream as much as possible :D |
I am all for "upstream" commits :-). The codebases does not use many Java 8 features, so this is no real loss (yet). If my lib helps your project I am willing to merge. I'll do a more thorough review tomorrow (or the day after)! Out of curiosity: Both XEPs state
|
That only means that there was no input on the XEP after one year. There are no implementations afaik, so I'm kinda sailing into unknown waters :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The major thing is: this is breaking the API (Instant --> Date). Can you relax your API requirements?
BuildDecryptionInputStreamAPI.this.keySelectionStrategy = new Rfc4880KeySelectionStrategy( | ||
Instant.now()); | ||
BuildDecryptionInputStreamAPI.this.keySelectionStrategy = | ||
new Rfc4880KeySelectionStrategy(new Date()); | ||
} | ||
|
||
public Validation setReferenceDateForKeyValidityTo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing public Validation setReferenceDateForKeyValidityTo(Instant)
to public Validation setReferenceDateForKeyValidityTo(Date)
would break the published API. Although 2.1 is not yet used widely this is not good. Unfortunately Instant
got added to android in API Level 26.
The best way would be to loosen your "support (very) old devices" requirement.
} | ||
|
||
public WithAlgorithmSuite setReferenceDateForKeyValidityTo( | ||
Instant dateOfTimestampVerification) { | ||
Date dateOfTimestampVerification) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above (breaks API)
|
||
/** | ||
* The date used for key expiration date checks as "now". | ||
* | ||
* @return dateOfTimestampVerification | ||
*/ | ||
protected Instant getDateOfTimestampVerification() { | ||
protected Date getDateOfTimestampVerification() { | ||
return dateOfTimestampVerification; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also breaks API, it is possible but unlikely that this will cause a major fuss (I'll skip over the next "breaking changes" )
@@ -116,52 +119,61 @@ public PGPPublicKey selectPublicKey(PURPOSE purpose, String uid, KeyringConfig k | |||
|
|||
final PGPSecretKeyRingCollection secretKeyRings = keyringConfig.getSecretKeyRings(); | |||
|
|||
PGPPublicKey publicKey = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment to the method (if there is none yet) to say that the last matching key is selected ("use the newest").
.filter(hasPrivateKey(secretKeyRings)) | ||
.reduce((a, b) -> b) | ||
.orElse(null); | ||
for (PGPPublicKeyRing ring : publicKeyrings) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move this to a dedicated method?
@@ -179,10 +191,10 @@ protected boolean isExpired(PGPPublicKey pubKey) { | |||
final boolean isExpired; | |||
|
|||
if (hasExpiryDate) { | |||
final Instant expiryDate = pubKey.getCreationTime().toInstant() | |||
.plusSeconds(pubKey.getValidSeconds()); | |||
final Date expiryDate = new Date(pubKey.getCreationTime().getTime() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a comment, or better yet: Using the (ugly) Calendar API:
https://stackoverflow.com/questions/8035125/java-how-to-add-seconds-to-timestamp
@@ -327,7 +329,7 @@ public void encrypt_decrypt_yieldsOriginalPlaintext() | |||
final OutputStream outputStream = BouncyGPG | |||
.encryptToStream() | |||
.withConfig(Configs.keyringConfigFromFilesForSender()) | |||
.setReferenceDateForKeyValidityTo(Instant.MAX) | |||
.setReferenceDateForKeyValidityTo(new Date(Long.MAX_VALUE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is fine then. neither will hit any of us during our livetime :-)
Unfortunately that is not an option for me. Smack is apparently used primarily in developing countries, so having support for old devices is a requirement. I think for now I will go with creating a fork of your project that fits my needs :) |
No worries! If I can help you, just give me a note (create an issue :-) ), and if it is good for bouncy_gpg I'll add it, so you can merge into your fork. |
Hi!
This PR removes the usage of some newer Java features like stream semantics in order to allow the library to be used in Android applications targeting API level 9 and above.
I hope I didn't break anything, but the test cases (which I had to alter as well) are all passing.
I created this PR as I'm participating in this years Google Summer of Code. As part of my project I want to utilize this library to implement XEP-0373 and XEP-0374 (OpenPGP for XMPP) for the XMPP client library Smack.
I appreciate any feedback :)