-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.js
178 lines (135 loc) · 5.7 KB
/
ui.js
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
let pockPem = null;
function createPock() {
const compromisedKeyPem = $('#txtCompromisedKeyPem').val();
errorHandler(function () {
pockPem = createProofOfCompromisedKey(compromisedKeyPem);
displayMessage('success', 'The PoCK has been successfully created');
$('#createPockResult').text(pockPem.replace(/\r/g, ''));
$('#createPockResultContainer').show();
displayCertificateDetails(pockPem, $('#createdPockDetails'));
}, 'Could not create PoCK');
}
function verifyPock() {
const compromisedCertificatePem = $('#txtCompromisedCertificatePem').val();
const pockCertificatePem = $('#txtPockCertificatePem').val();
errorHandler(function () {
verifyProofOfCompromisedKey(compromisedCertificatePem, pockCertificatePem);
displayMessage('success', compromisedCertificatePem ?
'The PoCK has been successfully verified as proof of compromise for the specified certificate' :
'The PoCK has been successfully verified');
}, 'Could not verify PoCK');
}
function getCrtshLinkForThumbprint(type, thumbprint) {
return `https://crt.sh?${type}=${thumbprint}`
}
function getCensysLinkForThumbprint(type, thumbprint) {
return `https://censys.io/certificates?q=parsed.${type}%3A+${thumbprint}`
}
function displayMessage(messageClass, message, heading) {
const div = $('<div />', {'class': `alert alert-${messageClass} alert-dismissible fade show`, role: 'alert'});
const span = $('<span />');
if (heading) {
span.append($('<strong />', {text: `${heading}: `}));
}
span.append(document.createTextNode(message));
div.append(span);
const button = $('<button />', {'class': 'close', type: 'button', 'data-dismiss': 'alert', 'aria-label': 'Close'});
button.append($('<span />', {'aria-hidden': 'true', text: '\u00d7'}));
div.append(button);
$('#message-display').empty().append(div);
}
function displayError(message, heading) {
displayMessage('danger', message, heading);
}
function createListItem (header, value, extra) {
const tr = $('<tr />');
tr.append($('<th />', {scope: 'row', text: header}));
const td = $('<td />', {text: value});
tr.append(td);
if (extra) {
td.append($('<br />'));
td.append(extra);
}
return tr;
}
function getKeyType (key) {
switch (key.constructor) {
case RSAKey:
return 'RSA';
case KJUR.crypto.ECDSA:
return 'ECDSA';
default:
throw 'Unknown key type: ' + key.constructor;
}
}
function displayCertificateDetails (certificatePem, parentDiv) {
parentDiv.empty();
const certificate = readCertificatePem(certificatePem);
const table = $('<table />', {'class': 'table table-sm'});
const tbody = $('<tbody />');
table.append(tbody);
const generateThumbprintLinks = function (crtshType, censysType, thumbprint) {
const span = $('<span />', );
span
.append($('<a />', {href: getCrtshLinkForThumbprint(crtshType, thumbprint), target: '_blank', text: 'crt.sh'}))
.append(document.createTextNode(' '))
.append($('<a />', {href: getCensysLinkForThumbprint(censysType, thumbprint), target: '_blank', text: 'censys.io'}));
return span;
}
const certificateThumbprint = getPemThumbprint(certificatePem);
const spkiThumbprint = KJUR.crypto.Util.hashHex(certificate.getPublicKeyHex(), 'sha256');
tbody
.append(createListItem('Serial Number', certificate.getSerialNumberHex()))
.append(createListItem('Issuer DN', certificate.getIssuerString()))
.append(createListItem('Subject DN', certificate.getSubjectString()))
.append(createListItem('Not After', zulutodate(certificate.getNotAfter().toLocaleString())))
.append(createListItem(
'Certificate SHA-256 Thumbprint',
certificateThumbprint,
generateThumbprintLinks('sha256', 'sha256_fingerprint', certificateThumbprint)))
.append(createListItem(
'SPKI SHA-256 Thumbprint',
spkiThumbprint,
generateThumbprintLinks('spkisha256', 'spki_subject_fingerprint', spkiThumbprint)));
parentDiv.append(table);
}
function displayKeyDetails (keyPem, parentDiv) {
parentDiv.empty();
const key = KEYUTIL.getKey(keyPem);
const table = $('<table />', {'class': 'table table-sm'});
const tbody = $('<tbody />');
table.append(tbody);
tbody
.append(createListItem('Key Type', getKeyType(key)));
parentDiv.append(table);
}
function errorHandler (f, heading) {
try {
f();
}
catch (e) {
console.error(e);
displayError(e.message || e, heading);
}
}
$(function () {
const txtCompromisedKeyPem = $('#txtCompromisedKeyPem');
const txtCompromisedCertificatePem = $('#txtCompromisedCertificatePem');
const txtPockCertificatePem = $('#txtPockCertificatePem');
txtCompromisedKeyPem.on('input', function () {
errorHandler(function () {
displayKeyDetails(txtCompromisedKeyPem.val(), $('#compromisedKeyDetails'));
}, 'Could not parse compromised key');
});
txtCompromisedCertificatePem.on('input', function () {
errorHandler(function () {
displayCertificateDetails(txtCompromisedCertificatePem.val(), $('#compromisedCertificateDetailsVerify'), true);
}, 'Could not parse compromised certificate')
});
txtPockCertificatePem.on('input', function () {
errorHandler(function () {
displayCertificateDetails(txtPockCertificatePem.val(), $('#pockCertificateDetailsVerify'));
}, 'Could not parse PoCK')
});
$('#btnCopyPockPem').click(function () { navigator.clipboard.writeText(pockPem); });
});