intellij-platform-gradle-plugin icon indicating copy to clipboard operation
intellij-platform-gradle-plugin copied to clipboard

signPlugin fails with NullPointerException

Open mwalter opened this issue 2 years ago • 2 comments

I followed the tutorial to set up everything needed to publish a plugin to the marketplace. So I added the PUBLISH_TOKEN, PRIVATEE_KEY, CERTIFICATE_CHAIN and PRIVATE_KEY_PASSWORD to the environment variables of the Run Configuration. When the signPlugin task is executed I always get a NullPointerException: pemObject must not be null.

Exception in thread "main" java.lang.NullPointerException: pemObject must not be null at org.jetbrains.zip.signer.signer.PrivateKeyUtils.loadKeyPair(PrivateKeyUtils.kt:62) at org.jetbrains.zip.signer.signer.PrivateKeyUtils.loadKeyPair(PrivateKeyUtils.kt:48) at org.jetbrains.zip.signer.signer.SignerInfoLoader.loadSignerInfoFromText(SignerInfoLoader.kt:30) at org.jetbrains.zip.signer.ZipSigningTool.sign(ZipSigningTool.kt:58) at org.jetbrains.zip.signer.ZipSigningTool.main(ZipSigningTool.kt:29) [gradle-intellij-plugin :MavenDependencyChecker:signPlugin] Error during Marketplace ZIP Signer CLI execution: Exception in thread "main" java.lang.NullPointerException: pemObject must not be null at org.jetbrains.zip.signer.signer.PrivateKeyUtils.loadKeyPair(PrivateKeyUtils.kt:62) at org.jetbrains.zip.signer.signer.PrivateKeyUtils.loadKeyPair(PrivateKeyUtils.kt:48) at org.jetbrains.zip.signer.signer.SignerInfoLoader.loadSignerInfoFromText(SignerInfoLoader.kt:30) at org.jetbrains.zip.signer.ZipSigningTool.sign(ZipSigningTool.kt:58) at org.jetbrains.zip.signer.ZipSigningTool.main(ZipSigningTool.kt:29)

mwalter avatar Jan 07 '22 21:01 mwalter

@mwalter I have tried reproducing this error, but with no luck. After generating chain.crt and private.pem files as described in Plugin Signing article, everything works well.

Could you please provide more information regarding your setup?

hsz avatar Feb 01 '22 13:02 hsz

@hsz thank you very much for your support!

I added the generated chain.crt and private.pem to the IntelliJ Run Configuration by copy & pasting the file contents to the environment section. I found a discussion in a Jetbrains forum about the problem. It has something to do with multiline parsing. The file contents span over multiple lines and and the gradle-intellij-plugin is not able to read the multiline contents from the Run Configuration. I tried to remove all line breaks and still it did not work (same error).

I now use the workaround stated in the forum: certificateChain.set(File(System.getenv("CERTIFICATE_CHAIN") ?: "./certs/chain.crt").readText(Charsets.UTF_8))

But it would be very nice if I could use the Gradle plugin task for signing.

mwalter avatar Feb 01 '22 14:02 mwalter

This conversion is required – SDK Docs were properly modified. Thanks for the update, Marc.

hsz avatar Nov 13 '22 21:11 hsz

@hsz thank you very much for your support!

I added the generated chain.crt and private.pem to the IntelliJ Run Configuration by copy & pasting the file contents to the environment section. I found a discussion in a Jetbrains forum about the problem. It has something to do with multiline parsing. The file contents span over multiple lines and and the gradle-intellij-plugin is not able to read the multiline contents from the Run Configuration. I tried to remove all line breaks and still it did not work (same error).

I now use the workaround stated in the forum: certificateChain.set(File(System.getenv("CERTIFICATE_CHAIN") ?: "./certs/chain.crt").readText(Charsets.UTF_8))

But it would be very nice if I could use the Gradle plugin task for signing.

Interesting.. The solution specified in the above comment does not work... checkout the full log here.

* What went wrong:
Could not determine the dependencies of task ':publishPlugin'.
> Could not create task ':signPlugin'.
   > valueof(EnvironmentVariableValueSource) (No such file or directory)

dinbtechit avatar Mar 14 '23 18:03 dinbtechit

The problem wasn't solved.

Exception in thread "main" java.lang.NullPointerException: pemObject must not be null

nabato avatar Oct 23 '23 20:10 nabato

@nabato - are you facing this issue in github actions or in your local environment?

dinbtechit avatar Oct 23 '23 21:10 dinbtechit

@nabato - are you facing this issue in github actions or in your local environment?

Both. With base64 encoded private key and with not encoded private key.

I provided the link to a failing github job. https://github.com/JetBrains/gradle-intellij-plugin/issues/1482

nabato avatar Oct 23 '23 21:10 nabato

To fix github actions. (Follow the below steps)

Important— Ensure base64 encoded string does not contain any space or newline characters.

To convert pem and crt files to base64 string

Note - Below commands are for MacOS. But could work in other OS if you have openssl installed.

  1. Encode private.pem to Base64 encoded string.
openssl enc -A -base64 -in private.pem -out private_base64.pem
cat private_base64.pem

output: <<base64 Encode string>>

Copy & Paste the base64 string into github -> settings -> security -> secrets and variables -> Repository Secrets -> PRIVATE_KEY


  1. Encode chain.crt to Base64 encoded string.
openssl enc -A -base64 -in chain.crt -out chain-base64.crt 
cat chain-base64.crt

output: <<base64 Encode string>>

Copy & Paste the base64 string into github -> settings -> security -> secrets and variables -> Repository Secrets -> CERTIFICATE_CHAIN


image

dinbtechit avatar Oct 23 '23 21:10 dinbtechit

@dinbtechit, thank you for trying to help. But:

Both. With base64 encoded private key and with not encoded private key.

nabato avatar Oct 23 '23 21:10 nabato

Sorry I misread your comment.

Let's tackle this with github actions first. For github actions it needs to be base64 encoded. Can you confirm if you have set the base64 encoded PRIVATE key in the right place?

Github Repo -> settings -> security -> secrets and variables -> Repository Secrets -> PRIVATE_KEY

dinbtechit avatar Oct 23 '23 21:10 dinbtechit

@dinbtechit, confirm. I checked that encoded strings don't contain anything like newline characters with https://www.soscisurvey.de/tools/view-chars.php.

nabato avatar Oct 23 '23 21:10 nabato

https://github.com/nabato/alabaster-themes/actions/runs/6619320521/job/17979588487

nabato avatar Oct 23 '23 21:10 nabato

Your github configuration looks good to me. So there is something going on when you create the base64 encoded string.

I had the exact same problem basically when I used the default MacOS base64 encoder, it did not work. But when I used the openSSL base64 encoder it worked. If you use MacOS you can try using the commands I provided above.

The important thing is the -A flag - openssl enc -A -base64

image

dinbtechit avatar Oct 23 '23 21:10 dinbtechit

@dinbtechit, I encoded it on Linux with:

openssl enc -A -base64 -in private.pem -out private_base64.pem openssl enc -A -base64 -in chain.crt -out chain-base64.crt

It's an official way from the documentation. Who wrote the documentation?

nabato avatar Oct 23 '23 21:10 nabato

This issue must be reopened by the plugin team.

nabato avatar Oct 23 '23 21:10 nabato

Someone else on the slack had the same problem, but that was because of the encoder. Maybe it is causing due to some other reason for you.

image image

dinbtechit avatar Oct 23 '23 22:10 dinbtechit

@dinbtechit, I also tried https://www.base64encode.org with no luck. I'm of the opinion that it's not my job to fix Jetbrains' buggy plugin by trying different random stuff whereas the steps in the documentation lead to a broken build. That's a terrbile job on Jetbrains' side and they must fix it. Instead of fixing the problem that is more than two years old they disparage plugin developers. https://intellij-support.jetbrains.com/hc/en-us/community/posts/4408839632146-Signing-Plugin-always-throws-NullPointerException-pemObject-must-not-be-null Screenshot from 2023-10-24 01-09-13

nabato avatar Oct 23 '23 22:10 nabato

@nabato There is no need to call names publicly. Please keep a professional attitude.

YannCebron avatar Oct 24 '23 06:10 YannCebron

@nabato There is no need to call names publicly. Please keep a professional attitude.

Reported for misinformation.

The bug is still here and you don't reopen it.

nabato avatar Oct 24 '23 07:10 nabato

@YannCebron I still get the error: pemObject must not be null

gradle plugin version: 1.16.1

Drjacky avatar Dec 02 '23 17:12 Drjacky