Skip to content

Add support for PKCS#1 keys#6

Merged
aaschmid merged 3 commits intoaaschmid:pkcs1.and.pem.bc.by.bgregos#6from
bgregos:master
Feb 8, 2020
Merged

Add support for PKCS#1 keys#6
aaschmid merged 3 commits intoaaschmid:pkcs1.and.pem.bc.by.bgregos#6from
bgregos:master

Conversation

@bgregos
Copy link
Contributor

@bgregos bgregos commented Jan 13, 2020

A quick and dirty implementation that allows for PKCS#1 keys. This is helpful for taskservers like inthe.am. The major downside to adding this code is that BouncyCastle is now added as a dependency, but I don't at present see a good way around it.

@bgregos
Copy link
Contributor Author

bgregos commented Jan 13, 2020

I see a good bit of low-hanging fruit for cleanup, I'll try to update this soon.

@aaschmid
Copy link
Owner

@bgregos: Thanks for your changes. In sum I like them pretty much. I would appreciate some tests, though. But as I haven't had some myself, I thing I first need to provide some infrastructure for testing this.
Can you discuss my review points?

} catch (IOException e) {
throw new TaskwarriorKeyStoreException(e, "Could not read private key '%s' via input stream: %s", privateKeyFile,
e.getMessage());
e.printStackTrace();
Copy link
Owner

Choose a reason for hiding this comment

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

Why removed throwing the exception?

e.printStackTrace();
}

String privateKeyString = "----...";
Copy link
Owner

Choose a reason for hiding this comment

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

The rest should go to a separate method.

} catch (InvalidKeySpecException e) {
throw new TaskwarriorKeyStoreException(e, "Could not generate private key for '%s': %s", privateKeyFile, e.getMessage());
PemReader pemReader;
pemReader = new PemReader(new InputStreamReader(new ByteArrayInputStream(privKeyBytes)));
Copy link
Owner

Choose a reason for hiding this comment

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

Merge with the line above.


privateKeyObject = pemReader.readPemObject();
} catch (Exception e) {
e.printStackTrace();
Copy link
Owner

Choose a reason for hiding this comment

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

I prefer throwing an exception or logging it. What's your opinion?

e.printStackTrace();
}
} else {
throw new RuntimeException("Unsupported key type: " + privateKeyObject.getType());
Copy link
Owner

Choose a reason for hiding this comment

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

UnsupportedOperationException?

)
);
} catch (IOException e) {
e.printStackTrace();
Copy link
Owner

Choose a reason for hiding this comment

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

;-)

@aaschmid aaschmid force-pushed the master branch 2 times, most recently from a89e83a to 79954b2 Compare January 23, 2020 22:00
Copy link
Owner

@aaschmid aaschmid left a comment

Choose a reason for hiding this comment

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

I am still not sure if I want to include such a "huge"(TM) library into my "core" application but maybe I will provide another version. There is one other possibility (see http://magnus-k-karlsson.blogspot.com/2018/05/how-to-read-pem-pkcs1-or-pkcs8-encoded.html) with the ugly tradeoff that it uses sun.* packages. Would they be available on android jdk?


dependencies {
// https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.60'
Copy link
Owner

@aaschmid aaschmid Jan 31, 2020

Choose a reason for hiding this comment

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

I prefer to create a shadow jar including BC using https://imperceptiblethoughts.com/shadow/. But we could that later on as well...


dependencies {
// https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.60'
Copy link
Owner

@aaschmid aaschmid Jan 31, 2020

Choose a reason for hiding this comment

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

I prefer to create a shadow jar including BC using https://imperceptiblethoughts.com/shadow/. But we could that later on as well...

@aaschmid
Copy link
Owner

aaschmid commented Feb 1, 2020

And it would be nice to sign-off your commits as stated in https://github.com/aaschmid/taskwarrior-java-client/blob/master/CONTRIBUTING.md and agree the terms of the license agreement. Thanks @bgregos

@@ -23,12 +23,8 @@ task wrapper(type: Wrapper) {
dependencies {
// https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.60'
Copy link
Owner

Choose a reason for hiding this comment

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

I need to use org.bouncycastle:bcpkix-jdk15on to satisfy all used classes in your code.

@aaschmid
Copy link
Owner

aaschmid commented Feb 1, 2020

Maybe you can already rebase your changes onto https://github.com/aaschmid/taskwarrior-java-client/tree/pkcs1.and.pem.support.%232. That would be very helpful @bgregos. But please give me a hint if I should do myself :-)

@aaschmid aaschmid force-pushed the master branch 2 times, most recently from e15ca06 to 48fc394 Compare February 3, 2020 22:55
aaschmid added a commit that referenced this pull request Feb 8, 2020
…ient into bgregos-master (#6)

* 'master' of git://github.com/bgregos/taskwarrior-java-client:
  cleanup
  add support for PKCS#1 keys

Signed-off-by: Andreas Schmid <service@aaschmid.de>
@aaschmid aaschmid changed the base branch from master to pkcs1.and.pem.bc.by.bgregos#6 February 8, 2020 15:11
@aaschmid aaschmid merged commit 84fcb3a into aaschmid:pkcs1.and.pem.bc.by.bgregos#6 Feb 8, 2020
@aaschmid
Copy link
Owner

aaschmid commented Feb 8, 2020

@bgregos: I merged your branch into a branch of mine in order to use your changes to my code for a version use bouncycastle for support of PKCS#1 keys. I would be very nice if you could agree the terms of the license agreement as in https://github.com/aaschmid/taskwarrior-java-client/blob/master/CONTRIBUTING.md. Thanks!

aaschmid pushed a commit that referenced this pull request Feb 8, 2020
* dependencies require to use `org.bouncycastle:bcpkix-jdk15on` to
  satisfy all used classes
* reformat and cleanup code
* throw exceptions rather than siliently swallow with
  `e.printStackTrace()`
* fix spotbugs warning using byte stream without encoding
* NOT DONE:
  * split up into separate methods -> will follow later using kept
    but currently unused methods

Signed-off-by: Andreas Schmid <service@aaschmid.de>
aaschmid added a commit that referenced this pull request Feb 8, 2020
* pkcs1.and.pem.bc.#6:
  refactor if-else-cascade to switch and improve method names and error messages
  package and publish dependencies (esp. bouncycastle) using shadow jar
  replace hard-coded key type with constants
  inline method and improve error message for PKCS#8 key generation
  replace properitary `sun.securtiy.*` API with bouncycastle code
  reuse already existing private key generation from bytes for PKSC#8 standard
  incorporate requested review changes from #6
  document the new key probabilities in README.md
  use newly introduced PKCS1 and PKCS8 support for pem files (#2)
  add PKCS1 and PKCS8 support for pem files (#2)
  enhance integration tests to be able to cover all kinds of key types easily (#2)
  cleanup
  add support for PKCS#1 keys
@bgregos
Copy link
Contributor Author

bgregos commented Feb 14, 2020

Hello, apologies for the delay. I hereby agree to the terms of the Taskwarrior Java client License Agreement. Thanks for your additions to the PR as well; let me know if anything else needs done in relation to this PR.

@aaschmid
Copy link
Owner

Thanks, all the things are included in the version on Maven Central.

I am actually curious about your results including the published version into your Android app :-)

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