Which JDK your plugin runs on
The IntelliJ Platform docs say IDEs built on the platform rely on JetBrains Runtime (JBR), a custom version of OpenJDK. Your plugin runs on whichever JBR ships with the IDE the user installed. JEP 339 added EdDSA, including Ed25519, to the JDK’s security providers in version 15, so a runtime from 15 on needs no library.
Which JBR your oldest supported IDE has is something to check, not assume: run Signature.getInstance("Ed25519") in the sandbox IDE for each version you list as supported. If one fails, bundle a library for that range, and test it against the IDE’s own copies of the same library, which can clash.
The token format is sgt1.<payload>.<signature>, described in the offline verification reference, and the validation guide is where the token comes from.
The verifier
The JDK reads an Ed25519 public key in X.509 SubjectPublicKeyInfo form, and Clavem’s public key is the 32 raw bytes. For Ed25519 the SubjectPublicKeyInfo is a fixed 12-byte header followed by those bytes, which is the SPKI_PREFIX below. Java’s Base64.getUrlDecoder() accepts unpadded input, which is how Clavem encodes the key, payload and signature.
package com.example.inkwell
import com.google.gson.Gson
import com.google.gson.JsonParseException
import com.intellij.openapi.diagnostic.thisLogger
import java.security.GeneralSecurityException
import java.security.KeyFactory
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import java.security.Signature
import java.security.spec.X509EncodedKeySpec
import java.util.Base64
object LicenseToken {
private const val PUBLIC_KEY = "YOUR_PUBLIC_KEY" // from your product page: 32 raw bytes, base64url
private const val PRODUCT_ID = 75L // from your product page
data class Claims(
val v: Int = 0, val lid: Long = 0, val pid: Long = 0, val kh: String = "", val status: String = "",
val valid: Boolean = false, val iid: String? = null, val fp: String? = null, val email: String? = null,
val iat: Long = 0, val exp: Long? = null, val refresh_by: Long = 0,
)
// DER header of an Ed25519 SubjectPublicKeyInfo. The 32 raw key bytes follow it.
private val SPKI_PREFIX = byteArrayOf(0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00)
private val base64Url = Base64.getUrlDecoder()
/** Returns the claims when the signature is good, otherwise null. */
fun verify(token: String): Claims? {
val parts = token.split('.')
if (parts.size != 3 || parts[0] != "sgt1") return null
return try {
val raw = base64Url.decode(PUBLIC_KEY)
val signature = base64Url.decode(parts[2])
if (raw.size != 32 || signature.size != 64) return null
val publicKey = KeyFactory.getInstance("Ed25519").generatePublic(X509EncodedKeySpec(SPKI_PREFIX + raw))
val verifier = Signature.getInstance("Ed25519")
verifier.initVerify(publicKey)
// The signed text is the first two parts exactly as received.
verifier.update("${parts[0]}.${parts[1]}".toByteArray(Charsets.US_ASCII))
if (!verifier.verify(signature)) return null
Gson().fromJson(String(base64Url.decode(parts[1]), Charsets.UTF_8), Claims::class.java)
} catch (e: NoSuchAlgorithmException) {
thisLogger().warn("Ed25519 is not available in this runtime", e)
null
} catch (e: GeneralSecurityException) {
null // malformed key or signature
} catch (e: IllegalArgumentException) {
null // not base64url
} catch (e: JsonParseException) {
null
}
}
/** The checks your plugin should make on a verified token. */
fun isLicensed(claims: Claims?, now: Long = System.currentTimeMillis() / 1000): Boolean =
claims != null && claims.v == 1 && claims.pid == PRODUCT_ID && claims.valid &&
(claims.exp?.let { it > now } ?: true) && claims.refresh_by > now
/** Optional: was this token issued for the key the user typed? */
fun matchesKey(claims: Claims, licenseKey: String): Boolean {
val key = licenseKey.trim()
val native = Regex("^[0-9A-Za-z]{5}(-[0-9A-Za-z]{5}){4}$").matches(key)
val normalized = if (native) key.uppercase().replace(Regex("[IL]"), "1").replace('O', '0').replace('U', 'V') else key.lowercase()
val digest = MessageDigest.getInstance("SHA-256").digest(normalized.toByteArray())
return digest.joinToString("") { "%02x".format(it) }.take(16) == claims.kh
}
}
Claims gives every field a default, so Kotlin generates a no-argument constructor and Gson can fill only the fields the token has. A token without exp leaves it null, which isLicensed reads as perpetual.
What I ran
I could not compile or run this Kotlin: no Kotlin compiler or IDE was available. I checked the one piece that is easy to get wrong without a JVM. In Node 26, the 12 header bytes followed by the 32 key bytes parse as a valid Ed25519 public key, that key verifies a valid test token and rejects a tampered one, and Node’s re-export of the key matches the header and key byte for byte. The tokens came from a throwaway key pair in Clavem’s format, because the real demo product’s public key is not published. The claims logic is the same as in the TypeScript, Python and PHP versions I ran against eight test tokens, which agreed on every row.
JetBrains traps
- Silent failure on an old runtime.
NoSuchAlgorithmExceptionis aGeneralSecurityException, so a plain catch would hide it and report every user as unlicensed. The separate catch comes first and logs. - Do not log tokens.
idea.logis the file users attach to bug reports, and the payload holds the buyer’s email address. - Clock set back. Store the highest
iatyou have seen in the same state class as the token, and treat a system clock more than a few minutes earlier than it as stale. - No EDT concern. Verification is a few arithmetic operations on public data, so it is safe on any thread. The network and
PasswordSafecalls in the validation guide are the ones that must stay off the EDT. - The public key is in the jar. A plugin jar is easy to decompile, so anyone can find the key and the checks. The key is meant to be public. The checks can be edited by someone who wants to.
- Offline is normal. A laptop in a tunnel or behind a strict firewall can run for 14 days on a token. After
refresh_by, show a notification asking the user to connect once, not an error dialog on every action.
Doing this with Clavem
Each product has its own key pair. Copy the public key from the product page into PUBLIC_KEY. The token decoder shows the claims of a token you paste when a check fails and you want to know why.
Questions
Which Java version does a plugin need for Ed25519?
java.security gained Ed25519 in JDK 15. IDEs run on JetBrains Runtime, a custom build of OpenJDK, and its version depends on the IDE build. Check the runtime of the oldest IDE your plugin supports, for example in Help, About, or by calling Signature.getInstance("Ed25519") in the sandbox IDE.
What happens on a runtime without Ed25519?
Signature.getInstance throws NoSuchAlgorithmException. The code below logs a warning and returns null, so the license reads as invalid. Without the log line, every user would look unlicensed with no clue why.