// Get the certificate fingerprints from the local peer.
const rtcPeerConnection = new RTCPeerConnection();
const configuration = rtcPeerConnection.getConfiguration();
const certificates = configuration.certificates;
let fingerprintsFromClient;
if (certificates && certificates.length > 0) {
for (const cert of certificates) {
// For purpose of demonstration, just get first certificate
fingerprintsFromClient = cert.getFingerprints();
break;
}
}
// Get the certificate fingerprints from the remote peer for particular certificate (pseudo code)
const fingerprintsFromServer = [/* … */];RTCCertificate: getFingerprints() method / notebook
RTCCertificate: getFingerprints() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
let clientFingerprintDict = Object.fromEntries(
fingerprintsFromClient.map((x) => [x.algorithm, x.value]),
);
let serverFingerprintDict = Object.fromEntries(
fingerprintsFromServer.map((x) => [x.algorithm, x.value]),
);
// Function to compare two objects and return true if there are common properties
// and all common properties match.
function compareObjects(obj1, obj2) {
const commonProperties = Object.keys(obj1).filter((prop) =>
Object.hasOwn(obj2, prop),
);
// Return false if there are no common properties
if (Object.keys(commonProperties).length === 0) return false;
// Return false if any common properties don't match
for (const prop of commonProperties) {
if (obj1[prop] !== obj2[prop]) {
return false;
}
}
return true;
}
const matchingFingerprints = compareObjects(
clientFingerprintDict,
serverFingerprintDict,
);
console.log(matchingFingerprints);