-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathverification.html
More file actions
197 lines (170 loc) Β· 6.18 KB
/
Copy pathverification.html
File metadata and controls
197 lines (170 loc) Β· 6.18 KB
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
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8" />
<title>Digital Signature Verification</title>
<link rel="icon" href="images/lotusrex.ico" type="image/x-icon">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/forge/1.3.1/forge.min.js"></script>
<style>
body {
font-family: 'Segoe UI', sans-serif;
background: #f0f4f8;
margin: 0;
padding: 2rem;
color: #333;
}
.container {
max-width: 600px;
margin: auto;
background: white;
padding: 2rem;
border-radius: 12px;
box-shadow: 0 8px 16px rgba(0,0,0,0.1);
}
h2 {
text-align: center;
color: #2c3e50;
}
#zipInput {
width: 100%;
padding: 0.8rem;
border: 2px dashed #ccc;
border-radius: 8px;
background-color: #f9f9f9;
cursor: pointer;
margin-bottom: 1rem;
}
#zipInput:hover {
background-color: #e8f0fe;
}
.result-card {
border-radius: 10px;
padding: 1.5rem;
margin-top: 1rem;
background: #f8f8f8;
border-left: 6px solid #bbb;
}
.success {
border-left-color: #2ecc71;
background-color: #e9f9f1;
}
.error {
border-left-color: #e74c3c;
background-color: #faeaea;
}
.label {
font-weight: bold;
color: #555;
}
.value {
margin-bottom: 0.5rem;
}
.image-compare {
display: flex;
gap: 1rem;
margin-top: 1.5rem;
}
.image-compare div {
flex: 1;
text-align: center;
}
.image-compare img {
max-width: 50%;
border: 1px solid #ccc;
border-radius: 8px;
}
.footer {
text-align: center;
font-size: 0.9rem;
color: #999;
margin-top: 2rem;
}
</style>
</head>
<body>
<div class="container">
<h2>π Digital Signature Verification</h2>
<p>Upload the ZIP file containing <code>signature.json</code> to verify the digital signature.</p>
<input type="file" id="zipInput" accept=".zip" />
<h2 id="txtres" style="display: none;"><center>Result</center></h2>
<div id="result" class="result-card" style="display: none;"></div>
<div class="image-compare" style="display: none;" id="imageCompare">
<p><i><center>Example Result</center></i></p>
<div>
<p>β
<i> Valid</i></p>
<img src="images/success-example.png" alt="Contoh Valid">
</div>
<div>
<p>β<i> NOT Valid</i></p>
<img src="images/failed-example.png" alt="Contoh Tidak Valid">
</div>
</div>
<div class="footer">Powered by JSZip + Forge + WebCrypto</div>
<div><center>Made by Alextian Creative</center></div>
</div>
<script>
function base64ToBigInt(base64) {
return new forge.jsbn.BigInteger(forge.util.createBuffer(forge.util.decode64(base64)).toHex(), 16);
}
document.getElementById('zipInput').addEventListener('change', async (event) => {
const file = event.target.files[0];
const resultTxt = document.getElementById('txtres');
const resultDiv = document.getElementById('result');
const imageCompare = document.getElementById('imageCompare');
resultTxt.style.display = "block";
resultDiv.style.display = "block";
imageCompare.style.display = "block";
if (!file) {
resultDiv.className = 'result-card error';
resultDiv.innerText = "β No ZIP files uploaded. Please select a valid ZIP file containing signature.json.";
return;
}
try {
const zip = await JSZip.loadAsync(file);
const sigJson = JSON.parse(await zip.file("signature.json").async("string"));
const originalFile = await zip.file(sigJson.FileName).async("uint8array");
// Hash SHA-256 dari file
const hashBuffer = await crypto.subtle.digest("SHA-256", originalFile);
const hashBase64 = btoa(String.fromCharCode(...new Uint8Array(hashBuffer)));
if (hashBase64 !== sigJson.SHA256Hash) {
resultDiv.className = 'result-card error';
resultDiv.innerHTML = `<strong>β File has been modified</strong><br>File HASH does not match signature.<br>Expected: <code>${wrapSignature(sigJson.SHA256Hash)}</code><br>Actual: <code>${hashBase64}</code>`;
return;
}
// Siapkan public key
const modulus = base64ToBigInt(sigJson.PublicKeyModulus);
const exponent = base64ToBigInt(sigJson.PublicKeyExponent);
const rsa = forge.pki.rsa.setPublicKey(modulus, exponent);
const signatureBytes = forge.util.decode64(sigJson.Signature);
const digest = forge.md.sha256.create();
digest.update(forge.util.createBuffer(originalFile).getBytes());
const isValid = rsa.verify(digest.digest().bytes(), signatureBytes);
if (isValid) {
resultDiv.className = 'result-card success';
// Membungkus Signature agar rapi (maks 64 karakter per baris)
function wrapSignature(sig, width = 64) {
return sig.replace(new RegExp(`(.{1,${width}})`, 'g'), '$1<br>').replace(/<br>$/, '');
}
resultDiv.innerHTML = `
<div class="value"><span class="label">β
Signature VALID</span></div>
<div class="value"><span class="label">Signer :</span> ${sigJson.Signer}</div>
<div class="value"><span class="label">Dates :</span> ${sigJson.Date}</div>
<div class="value"><span class="label">Filename :</span> ${sigJson.FileName}</div>
<div class="value"><span class="label">Signature :</span><br>
<code style="word-break:break-all;white-space:pre-line;">${wrapSignature(sigJson.Signature)}</code>
</div>
`;
} else {
resultDiv.className = 'result-card error';
resultDiv.innerHTML = `β Signature is NOT valid! Files or data may have been changed.`;
}
} catch (err) {
console.error(err);
resultDiv.className = 'result-card error';
resultDiv.innerText = "β An error occurred while verifying the file.\nSignature is NOT valid or there is another problem.\n" + err.message;
}
});
</script>
</body>
</html>