Using Ed25519 generated with OpenSSL
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 366
- Forks
- 85
- Avg merge
- 2d 39m
- Merged PRs (30d)
- 6
Description
Summary
Hi there.
I'm building a JVM based application that relies on pre-generated Ed25519 keys to provide safe communication between peers.
I'm observing some weird behavior that feels like a bug.
Expected behavior
Given a Ed25519 key generated via open ssl:
*@*:/tmp ⍉
▶ openssl genpkey -algorithm Ed25519 -out ed25519_private.pem && openssl pkey -in ed25519_private.pem -pubout -out ed25519_public.pem
*@*:/tmp ▶ ll ed25519_p*.pem
Permissions Size User Date Modified Name
.rw------- 119 viperey 3 Apr 08:50 ed25519_private.pem
.rw-r--r-- 113 viperey 3 Apr 08:50 ed25519_public.pem
*@*:/tmp ▶ cat ed25519_p*.pem
│ File: ed25519_private.pem
1 │ -----BEGIN PRIVATE KEY-----
2 │ MC4CAQAwBQYDK2VwBCIEIH9ZvvvlDocfq7dDFBjsLJEF8oo8N+2VeI7K2QIJkWPx
3 │ -----END PRIVATE KEY-----
────────────────────────────────────────────────────────── │ File: ed25519_public.pem
1 │ -----BEGIN PUBLIC KEY-----
2 │ MCowBQYDK2VwAyEA08ZD6jfldUOHtv/77PFbVWCq+ZnrYQm3u8ucW3bh0fw=
3 │ -----END PUBLIC KEY-----
───────┴──────────────────────────────────────────────────
When a host is created with the private key, the peerId derivated via (private key in disk -> public key generated by lib-p2p -> peerId) won't be the same as if generating one via (public key in disk -> peerId).
Some (scala) code to observe this behavior:
val privateKeyFs: PrivKey = Ed25519Kt
.unmarshalEd25519PrivateKey(
Base64.getDecoder.decode(
"MC4CAQAwBQYDK2VwBCIEIH9ZvvvlDocfq7dDFBjsLJEF8oo8N+2VeI7K2QIJkWPx"
)
)
val publicKeyFs = privateKeyFs.publicKey()
val publicKeyFsStr = Base64.getEncoder.encodeToString(publicKeyFsStr.bytes())
val peerIdFS: PeerId = PeerId.fromPubKey(publicKeyFs)
val directlyPublicKey = Ed25519Kt.unmarshalEd25519PublicKey(
Base64.getDecoder.decode("MCowBQYDK2VwAyEA08ZD6jfldUOHtv/77PFbVWCq+ZnrYQm3u8ucW3bh0fw=")
)
val directlyPublicKeyStr = Base64.getEncoder.encodeToString(directlyPublicKeyStr.bytes())
val directlyPeerId: PeerId = PeerId.fromPubKey(
directlyPublicKey
)
assert(directlyPublicKeyStr == publicKeyFsStr)
assert(directlyPeerId == peerIdFS)
(The assertions fails)
Actual behavior
The public key values do not match and neither the peerId values.
In both (private and public) cases the unmarshalling works, but the values simply do not match.
Relevant log output
No response
Possible Solution
No response
Version
1.1.0-RELEASE
Would you like to work on fixing this bug ?
Maybe
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Ed25519Kt.unmarshalEd25519PrivateKey and unmarshalEd25519PublicKey, using the OpenSSL-generated key values and Scala reproduction in the issue. Compare the public key bytes and derived peer IDs from both paths, then add a regression test showing that they match for these inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, scala
- Domain
- cryptography
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100