Skip to content

Commit

Permalink
ip address obfuscation
Browse files Browse the repository at this point in the history
  • Loading branch information
fippo committed May 22, 2016
1 parent 491f8f7 commit 8ece744
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var config = require('config');
var uuid = require('uuid');
var statsMangler = require('./getstats-mangle');
var statsDecompressor = require('./getstats-deltacompression').decompress;
var obfuscate = require('./obfuscator');
var express = require('express');

var Store = require('./store')({
Expand Down Expand Up @@ -126,6 +127,7 @@ function run(keys) {
});
break;
default:
obfuscate(data);
if (!db[referer][clientid].peerConnections[data[1]]) {
db[referer][clientid].peerConnections[data[1]] = [];
baseStats[data[1]] = {};
Expand Down
34 changes: 34 additions & 0 deletions obfuscator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// obfuscate ip addresses which should not be stored long-term.

var SDPUtils = require('sdp');

// obfuscate ip, keeping address family intact.
// TODO: keep private addresses and only strip certain parts?
function obfuscateIP(ip) {
return ip.indexOf(':') === -1 ? '0.0.0.0' : '::1';
}

// obfuscate the ip in ice candidates. Does NOT obfuscate the ip of the TURN server to allow
// selecting/grouping sessions by TURN server.
function obfuscateCandidate(candidate) {
var cand = SDPUtils.parseCandidate(candidate);
if (cand.type !== 'relay') {
cand.ip = obfuscateIP(cand.ip);
}
if (cand.relatedAddress) {
cand.relatedAddress = obfuscateIP(cand.relatedAddress);
}
return SDPUtils.writeCandidate(cand);
}

module.exports = function(data) {
var lines;
switch(data[0]) {
case 'addIceCandidate':
case 'onicecandidate':
if (data[2] && data[2].candidate) {
data[2].candidate = obfuscateCandidate(data[2].candidate);
}
break;
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"pg": "^4.4.6",
"pg-promise": "^3.2.3",
"platform": "^1.3.1",
"sdp": "^1.0.0",
"uuid": "^2.0.1",
"ws": "^0.8.1"
},
Expand Down
6 changes: 3 additions & 3 deletions test/clienttest.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"time": "2016-01-28T18:24:20.304Z",
"type": "onicecandidate",
"value": {
"candidate": "candidate:1608896916 1 udp 2122194687 10.1.5.92 47183 typ host generation 0",
"candidate": "candidate:1608896916 1 udp 2122194687 10.1.5.92 47183 typ srflx raddr 1.2.3.4 rport 47183 generation 0",
"sdpMid": "audio",
"sdpMLineIndex": 0
}
Expand All @@ -107,7 +107,7 @@
"time": "2016-01-28T18:24:20.308Z",
"type": "onicecandidate",
"value": {
"candidate": "candidate:211962667 2 udp 2122260222 10.0.3.1 52923 typ host generation 0",
"candidate": "candidate:211962667 2 udp 2122260222 10.0.3.1 52923 typ relay raddr 1.2.3.4 rport 52923 generation 0",
"sdpMid": "audio",
"sdpMLineIndex": 0
}
Expand Down Expand Up @@ -11168,4 +11168,4 @@
}
]
}
}
}

0 comments on commit 8ece744

Please sign in to comment.