From 527e1aefc9b2db97bd129b8d782fe5843b24d972 Mon Sep 17 00:00:00 2001 From: AsamK Date: Thu, 12 Oct 2023 21:15:13 +0200 Subject: [PATCH] Refactor generateSignedPreKeyRecord --- .../java/org/asamk/signal/manager/helper/PreKeyHelper.java | 2 +- .../signal/manager/internal/RegistrationManagerImpl.java | 2 +- lib/src/main/java/org/asamk/signal/manager/util/KeyUtils.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/org/asamk/signal/manager/helper/PreKeyHelper.java b/lib/src/main/java/org/asamk/signal/manager/helper/PreKeyHelper.java index 3d298e35bf..1961fc560f 100644 --- a/lib/src/main/java/org/asamk/signal/manager/helper/PreKeyHelper.java +++ b/lib/src/main/java/org/asamk/signal/manager/helper/PreKeyHelper.java @@ -148,7 +148,7 @@ private SignedPreKeyRecord generateSignedPreKey(ServiceIdType serviceIdType, Ide final var accountData = account.getAccountData(serviceIdType); final var signedPreKeyId = accountData.getPreKeyMetadata().getNextSignedPreKeyId(); - var record = KeyUtils.generateSignedPreKeyRecord(signedPreKeyId, identityKeyPair); + var record = KeyUtils.generateSignedPreKeyRecord(signedPreKeyId, identityKeyPair.getPrivateKey()); account.addSignedPreKey(serviceIdType, record); return record; diff --git a/lib/src/main/java/org/asamk/signal/manager/internal/RegistrationManagerImpl.java b/lib/src/main/java/org/asamk/signal/manager/internal/RegistrationManagerImpl.java index 88151be28b..793f2f4985 100644 --- a/lib/src/main/java/org/asamk/signal/manager/internal/RegistrationManagerImpl.java +++ b/lib/src/main/java/org/asamk/signal/manager/internal/RegistrationManagerImpl.java @@ -267,7 +267,7 @@ private PreKeyCollection generatePreKeysForType(ServiceIdType serviceIdType) { final var preKeyMetadata = accountData.getPreKeyMetadata(); final var nextSignedPreKeyId = preKeyMetadata.getNextSignedPreKeyId(); - final var signedPreKey = KeyUtils.generateSignedPreKeyRecord(nextSignedPreKeyId, keyPair); + final var signedPreKey = KeyUtils.generateSignedPreKeyRecord(nextSignedPreKeyId, keyPair.getPrivateKey()); final var privateKey = keyPair.getPrivateKey(); final var kyberPreKeyIdOffset = preKeyMetadata.getNextKyberPreKeyId(); diff --git a/lib/src/main/java/org/asamk/signal/manager/util/KeyUtils.java b/lib/src/main/java/org/asamk/signal/manager/util/KeyUtils.java index 3fd6e30803..758831fc73 100644 --- a/lib/src/main/java/org/asamk/signal/manager/util/KeyUtils.java +++ b/lib/src/main/java/org/asamk/signal/manager/util/KeyUtils.java @@ -61,12 +61,12 @@ var record = new PreKeyRecord(preKeyId, keyPair); } public static SignedPreKeyRecord generateSignedPreKeyRecord( - final int signedPreKeyId, final IdentityKeyPair identityKeyPair + final int signedPreKeyId, final ECPrivateKey privateKey ) { var keyPair = Curve.generateKeyPair(); byte[] signature; try { - signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize()); + signature = Curve.calculateSignature(privateKey, keyPair.getPublicKey().serialize()); } catch (InvalidKeyException e) { throw new AssertionError(e); }