mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
Use libsignal key types internally
Co-authored-by: trevor-signal <trevor@signal.org>
This commit is contained in:
@@ -204,26 +204,6 @@ export function hydrateSignedPreKey(
|
||||
);
|
||||
}
|
||||
|
||||
export function freezePublicKey(publicKey: PublicKey): Uint8Array {
|
||||
return publicKey.serialize();
|
||||
}
|
||||
export function freezePreKey(preKey: PreKeyRecord): KeyPairType {
|
||||
const keyPair = {
|
||||
pubKey: preKey.publicKey().serialize(),
|
||||
privKey: preKey.privateKey().serialize(),
|
||||
};
|
||||
return keyPair;
|
||||
}
|
||||
export function freezeSignedPreKey(
|
||||
signedPreKey: SignedPreKeyRecord
|
||||
): KeyPairType {
|
||||
const keyPair = {
|
||||
pubKey: signedPreKey.publicKey().serialize(),
|
||||
privKey: signedPreKey.privateKey().serialize(),
|
||||
};
|
||||
return keyPair;
|
||||
}
|
||||
|
||||
type SessionCacheEntry = CacheEntryType<SessionType, SessionRecord>;
|
||||
type SenderKeyCacheEntry = CacheEntryType<SenderKeyType, SenderKeyRecord>;
|
||||
|
||||
@@ -296,10 +276,12 @@ export class SignalProtocolStore extends EventEmitter {
|
||||
'Invalid identity key serviceId'
|
||||
);
|
||||
const { privKey, pubKey } = map.value[serviceId];
|
||||
this.#ourIdentityKeys.set(serviceId, {
|
||||
privKey,
|
||||
pubKey,
|
||||
});
|
||||
const privateKey = PrivateKey.deserialize(Buffer.from(privKey));
|
||||
const publicKey = PublicKey.deserialize(Buffer.from(pubKey));
|
||||
this.#ourIdentityKeys.set(
|
||||
serviceId,
|
||||
new IdentityKeyPair(publicKey, privateKey)
|
||||
);
|
||||
}
|
||||
})(),
|
||||
(async () => {
|
||||
@@ -627,8 +609,8 @@ export class SignalProtocolStore extends EventEmitter {
|
||||
id,
|
||||
keyId: key.keyId,
|
||||
ourServiceId,
|
||||
publicKey: key.keyPair.pubKey,
|
||||
privateKey: key.keyPair.privKey,
|
||||
publicKey: key.keyPair.publicKey.serialize(),
|
||||
privateKey: key.keyPair.privateKey.serialize(),
|
||||
createdAt: now,
|
||||
};
|
||||
|
||||
@@ -780,8 +762,8 @@ export class SignalProtocolStore extends EventEmitter {
|
||||
id,
|
||||
ourServiceId,
|
||||
keyId,
|
||||
publicKey: keyPair.pubKey,
|
||||
privateKey: keyPair.privKey,
|
||||
publicKey: keyPair.publicKey.serialize(),
|
||||
privateKey: keyPair.privateKey.serialize(),
|
||||
created_at: createdAt,
|
||||
confirmed: Boolean(confirmed),
|
||||
};
|
||||
@@ -2537,10 +2519,7 @@ export class SignalProtocolStore extends EventEmitter {
|
||||
const pniPrivateKey = identityKeyPair.privateKey.serialize();
|
||||
|
||||
// Update caches
|
||||
this.#ourIdentityKeys.set(pni, {
|
||||
pubKey: pniPublicKey,
|
||||
privKey: pniPrivateKey,
|
||||
});
|
||||
this.#ourIdentityKeys.set(pni, identityKeyPair);
|
||||
this.#ourRegistrationIds.set(pni, registrationId);
|
||||
|
||||
// Update database
|
||||
@@ -2564,10 +2543,10 @@ export class SignalProtocolStore extends EventEmitter {
|
||||
this.storeSignedPreKey(
|
||||
pni,
|
||||
signedPreKey.id(),
|
||||
{
|
||||
privKey: signedPreKey.privateKey().serialize(),
|
||||
pubKey: signedPreKey.publicKey().serialize(),
|
||||
},
|
||||
new IdentityKeyPair(
|
||||
signedPreKey.publicKey(),
|
||||
signedPreKey.privateKey()
|
||||
),
|
||||
true,
|
||||
signedPreKey.timestamp()
|
||||
),
|
||||
@@ -2647,11 +2626,8 @@ export class SignalProtocolStore extends EventEmitter {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const pniIdentity = new IdentityKeyPair(
|
||||
PublicKey.deserialize(Buffer.from(pniKeyPair.pubKey)),
|
||||
PrivateKey.deserialize(Buffer.from(pniKeyPair.privKey))
|
||||
);
|
||||
const aciPubKey = PublicKey.deserialize(Buffer.from(aciKeyPair.pubKey));
|
||||
const pniIdentity = pniKeyPair;
|
||||
const aciPubKey = aciKeyPair.publicKey;
|
||||
this.#cachedPniSignatureMessage = {
|
||||
pni: ourPni,
|
||||
signature: pniIdentity.signAlternateIdentity(aciPubKey),
|
||||
|
||||
Reference in New Issue
Block a user