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