-
Notifications
You must be signed in to change notification settings - Fork 0
/
stable.html
240 lines (209 loc) · 8.56 KB
/
stable.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
canvas {
max-width: 144px;
max-height: 82px;
}
</style>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
</head>
<body>
<main role="main" class="container">
<div>
<h1>Video Decoding Test Page</h1>
<p class="lead">This page collects some information about your browser, including how it decodes video.<br>After collecting, please take the time to fill in some information about your device and submit it to help us understand the data!</p>
<div class="controls"></div>
<hr>
</div>
<div class="row submit" style="display:none;">
<div class="col-sm">
<h2>Submit Fingerprint</h2>
<form action="http://206.189.67.146/" method="post">
<div class="form-group">
<label for="cpu">CPU Model</label>
<input type="text" class="form-control" id="cpu" name="cpu" aria-describedby="cpuHelp" placeholder="ex. Intel Core i7-7700K">
<small id="cpuHelp" class="form-text text-muted">Leave blank if not applicable or unknown</small>
</div>
<div class="form-group">
<label for="gpu">Graphics Card Model</label>
<input type="text" class="form-control" id="gpu" name="gpu" aria-describedby="gpuHelp" placeholder="ex. Nvidia GeForce GTX 1080 Ti">
<small id="gpuHelp" class="form-text text-muted">Leave blank if not applicable or unknown</small>
</div>
<div class="form-group">
<label for="model">Device Model</label>
<input type="text" class="form-control" id="model" name="model" aria-describedby="modelHelp" placeholder="ex. iPhone 8 Plus">
<small id="modelHelp" class="form-text text-muted">Leave blank if not applicable or unknown</small>
</div>
<input type="hidden" id="videos" name="videos" />
<input type="hidden" id="renderer" name="renderer" />
<input type="hidden" id="useragent" name="useragent" />
<input type="hidden" id="time" name="time" />
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
<div class="row fingerprint" style="display:none; padding: 16px;">
<div class="col-sm data border border-secondary">
<h2>Visual Fingerprint</h2>
<div class="visual"></div>
<h2>Hashed Fingerprint</h2>
<div class="hashes"></div>
</div>
</div>
</main>
<script src="bitview.js"></script>
<script>
var assetURL = 'output_frag.mp4';
var mimeCodec = 'video/mp4; codecs="avc1.640015"';
var emptyHash = "9ae5abd3298c7ca041d4e8f8f4d66a6b5c956ea1e81b82424472bac2060ef449";
var indexes = [-1];
var current = -1;
var attempt = 0;
var asset;
var cleanAsset;
var video = document.createElement('video');
video.addEventListener('canplay', function() {
setTimeout(getHash, attempt*100);
});
video.addEventListener('error', function() {
console.log(video.error);
if(!(current in hashes)) hashes[current] = [];
hashes[current].push("null");
loadNext();
});
var hashes = {};
function sha256(imageData) {
return crypto.subtle.digest("SHA-256", imageData.data).then(function (hash) {
return hex(hash);
});
}
function hex(buffer) {
var hexCodes = [];
var view = new DataView(buffer);
for (var i = 0; i < view.byteLength; i += 4) {
var value = view.getUint32(i)
var stringValue = value.toString(16)
var padding = '00000000'
var paddedValue = (padding + stringValue).slice(-padding.length)
hexCodes.push(paddedValue);
}
return hexCodes.join("");
}
function loadAsset() {
var xhr = new XMLHttpRequest;
xhr.open('get', assetURL);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
asset = xhr.response;
setup();
};
xhr.send();
}
function fuzz(index) {
if(index == -1) return cleanAsset.slice(0);
var buf = asset.slice(0);
var bv = new BitView(buf);
bv.setBit(index, !bv.getBit(index));
return buf;
}
function getHash() {
var canvas = document.createElement('canvas');
canvas.id = current;
canvas.height = video.videoHeight;
canvas.width = video.videoWidth;
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
var data = ctx.getImageData(0, 0, canvas.width, canvas.height);
sha256(data).then(function(digest) {
if(!(current in hashes)) hashes[current] = [];
if(digest != emptyHash || attempt > 2) {
canvas.setAttribute("data-hash", digest);
document.querySelector(".visual").appendChild(canvas);
hashes[current].push(digest);
}
loadNext();
});
}
function setup() {
startTime = performance.now();
loadNext();
}
function sourceOpen (_) {
var mediaSource = this;
mediaSource.removeEventListener('sourceopen', sourceOpen);
sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
sourceBuffer.appendBuffer(fuzz(current));
}
function getNext() {
for(var i = 0; i < indexes.length; i++) {
if(indexes[i] in hashes) {
if(hashes[indexes[i]].length < 1) return indexes[i];
} else {
return indexes[i];
}
}
return null;
}
function loadNext() {
last = current;
current = getNext();
if(last == current) {
attempt++;
} else {
attempt = 0;
}
if(current === null) {
finish();
} else {
if ('MediaSource' in window && MediaSource.isTypeSupported(mimeCodec)) {
var mediaSource = new MediaSource;
video.src = URL.createObjectURL(mediaSource);
mediaSource.addEventListener('sourceopen', sourceOpen);
} else {
console.error('Unsupported MIME type or codec: ', mimeCodec);
}
}
}
function finish() {
var time = performance.now() - startTime;
var pre = document.createElement("pre");
pre.innerHTML = JSON.stringify(hashes, undefined, 2);
document.querySelector(".hashes").appendChild(pre);
var renderer = null;
try {
var canvas = document.createElement('canvas');
var gl = canvas.getContext('webgl');
var debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
} catch(e) {
}
document.querySelector("#useragent").value = navigator.userAgent;
document.querySelector("#renderer").value = renderer;
document.querySelector("#videos").value = JSON.stringify(hashes);
document.querySelector("#time").value = time;
document.querySelector(".submit").style.display = "block";
}
var button = document.createElement("button");
button.setAttribute("type", "button");
button.setAttribute("class", "btn btn-primary");
button.innerHTML = "Collect Fingerprint";
button.addEventListener("click", function() {
button.setAttribute("disabled", "true");
document.querySelector(".fingerprint").style.display = "block";
var xhr = new XMLHttpRequest;
xhr.open('get', prompt("Please enter assetUrl", "")+".mp4");
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
cleanAsset = xhr.response;
loadAsset();
};
xhr.send();
});
document.querySelector(".controls").appendChild(button);
</script>
</body>
</html>