Skip to content

[FEATURE REQUEST] Support keys in PKCS1 PEM format #2

@ngortheone

Description

@ngortheone

Hey @aaschmid

I have my key formatted in PKCS1 PEM format and it works perfectly fine with taskwarrior client and server .In fact the key was generated by taskd scripts that way, I never bothered to check what kind of key I had until I tried using it with this client. Hence the following feature request:

What

minimal

Support private key formatted in PKCS1 PEM

desired

Automatically detect key file format and use any valid format

Rationale

The rationale of this feature request is that it would be nice from user friendliness to support keys that are generated when user follows taskserver docs so that user does not have to manually convert they key

stacktrace I try to use my key with this library
Exception in thread "main" de.aaschmid.taskwarrior.ssl.TaskwarriorKeyStoreException: Could not generate private key for '/Users/ihorantonov/.task/client.key.pem': java.security.InvalidKeyException: invalid key format
	at de.aaschmid.taskwarrior.ssl.KeyStoreBuilder.createPrivateKeyFor(KeyStoreBuilder.java:143)
	at de.aaschmid.taskwarrior.ssl.KeyStoreBuilder.build(KeyStoreBuilder.java:100)
	at de.aaschmid.taskwarrior.TaskwarriorClient.<init>(TaskwarriorClient.java:46)
	at de.aaschmid.taskwarrior.TaskwarriorClientTest.main(TaskwarriorClientTest.java:24)
Caused by: java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: invalid key format
Caused by: java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: invalid key format

	at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:217)
	at java.security.KeyFactory.generatePrivate(KeyFactory.java:372)
	at de.aaschmid.taskwarrior.ssl.KeyStoreBuilder.createPrivateKeyFor(KeyStoreBuilder.java:138)
	... 3 more
Caused by: java.security.InvalidKeyException: invalid key format
Caused by: java.security.InvalidKeyException: invalid key format

	at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:331)
	at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:356)
	at sun.security.rsa.RSAPrivateCrtKeyImpl.<init>(RSAPrivateCrtKeyImpl.java:91)
	at sun.security.rsa.RSAPrivateCrtKeyImpl.newKey(RSAPrivateCrtKeyImpl.java:75)
	at sun.security.rsa.RSAKeyFactory.generatePrivate(RSAKeyFactory.java:316)
	at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:213)
	... 5 more

Execution failed for task ':TaskwarriorClientTest.main()'.

I have to convert my key with

# convert PKCS1 to PKCS8
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in client.key.pem -out  client.pkcs8.key.pem   

# convert PEM to DER  
openssl pkcs8 -topk8 -nocrypt -in client.pkcs8.key.pem -inform PEM -out client.pkcs8.key.der -outform DER

It is likely that above is also doable in a single invocation, but this is how I got it to work.


more about key formats:
https://stackoverflow.com/a/48960291/3177479

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions