Шифрование тест
This commit is contained in:
@@ -74,7 +74,8 @@ export function CallProvider(props : CallProviderProps) {
|
||||
const roomIdRef = useRef<string>("");
|
||||
|
||||
const roleRef = useRef<CallRole | null>(null);
|
||||
const [sharedSecret, setSharedSecret] = useState<string>("");
|
||||
//const [sharedSecret, setSharedSecret] = useState<string>("");
|
||||
const sharedSecretRef = useRef<string>("");
|
||||
const iceServersRef = useRef<RTCIceServer[]>([]);
|
||||
const remoteAudioRef = useRef<HTMLAudioElement | null>(null);
|
||||
const iceCandidatesBufferRef = useRef<RTCIceCandidate[]>([]);
|
||||
@@ -246,8 +247,8 @@ export function CallProvider(props : CallProviderProps) {
|
||||
}
|
||||
const sessionKeys = generateSessionKeys();
|
||||
const computedSharedSecret = nacl.box.before(Buffer.from(sharedPublic, 'hex'), sessionKeys.secretKey);
|
||||
setSharedSecret(Buffer.from(computedSharedSecret).toString('hex'));
|
||||
info("Generated shared secret for call session: " + Buffer.from(computedSharedSecret).toString('hex'));
|
||||
sharedSecretRef.current = Buffer.from(computedSharedSecret).toString('hex');
|
||||
info("Generated shared secret for call session: " + sharedSecretRef.current);
|
||||
/**
|
||||
* Нам нужно отправить свой публичный ключ другой стороне, чтобы она тоже могла создать общую секретную сессию
|
||||
*/
|
||||
@@ -284,8 +285,8 @@ export function CallProvider(props : CallProviderProps) {
|
||||
return;
|
||||
}
|
||||
const computedSharedSecret = nacl.box.before(Buffer.from(sharedPublic, 'hex'), sessionKeys.secretKey);
|
||||
info("Generated shared secret for call session: " + Buffer.from(computedSharedSecret).toString('hex'));
|
||||
setSharedSecret(Buffer.from(computedSharedSecret).toString('hex'));
|
||||
sharedSecretRef.current = Buffer.from(computedSharedSecret).toString('hex');
|
||||
info("Generated shared secret for call session: " + sharedSecretRef.current);
|
||||
setCallState(CallState.WEB_RTC_EXCHANGE);
|
||||
}
|
||||
if(signalType == SignalType.CREATE_ROOM) {
|
||||
@@ -326,7 +327,7 @@ export function CallProvider(props : CallProviderProps) {
|
||||
|
||||
peerConnectionRef.current.ontrack = async (event) => {
|
||||
try {
|
||||
await attachReceiverE2EE(event.receiver, Buffer.from(sharedSecret, "hex"));
|
||||
await attachReceiverE2EE(event.receiver, Buffer.from(sharedSecretRef.current, "hex"));
|
||||
} catch (e) {
|
||||
console.error("attachReceiverE2EE failed:", e);
|
||||
}
|
||||
@@ -356,7 +357,7 @@ export function CallProvider(props : CallProviderProps) {
|
||||
streams: [localStream]
|
||||
});
|
||||
|
||||
await attachSenderE2EE(tx.sender, Buffer.from(sharedSecret, "hex"));
|
||||
await attachSenderE2EE(tx.sender, Buffer.from(sharedSecretRef.current, "hex"));
|
||||
|
||||
/**
|
||||
* Отправляем свой оффер другой стороне
|
||||
@@ -369,7 +370,7 @@ export function CallProvider(props : CallProviderProps) {
|
||||
send(offerSignal);
|
||||
return;
|
||||
}
|
||||
}, [activeCall, sessionKeys, sharedSecret]);
|
||||
}, [activeCall, sessionKeys]);
|
||||
|
||||
const openCallsModal = (text : string) => {
|
||||
modals.open({
|
||||
@@ -483,10 +484,10 @@ export function CallProvider(props : CallProviderProps) {
|
||||
* @returns
|
||||
*/
|
||||
const getKeyCast = () => {
|
||||
if(!sharedSecret){
|
||||
if(!sharedSecretRef.current){
|
||||
return "";
|
||||
}
|
||||
return sharedSecret;
|
||||
return sharedSecretRef.current;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ type KeyInput = Buffer | Uint8Array;
|
||||
|
||||
|
||||
async function importAesCtrKey(input: KeyInput): Promise<CryptoKey> {
|
||||
console.info("Importing AES-CTR key for E2EE:", Buffer.from(input).toString('hex'));
|
||||
const keyBytes = toArrayBuffer(input);
|
||||
if (keyBytes.byteLength !== 32) {
|
||||
throw new Error(`E2EE key must be 32 bytes, got ${keyBytes.byteLength}`);
|
||||
|
||||
Reference in New Issue
Block a user