forked from kjur/jsrsasign
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tool_cades.html
executable file
·351 lines (314 loc) · 13.4 KB
/
tool_cades.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta name="description" content="jsrsasign : conversion tool from The CSR to self signed certificate for factorable.net checker." />
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/stylesheet.css">
<title>CAdES Generator</title>
<script language="JavaScript" type="text/javascript" src="jsrsasign-latest-all-min.js"></script>
<script language="JavaScript" type="text/javascript">
var param = {
content: {str: ""},
signerInfos: [{
hashAlg: 'sha256',
sAttr: {
},
sigAlg: 'SHA256withRSA'
}]
};
var parsedInfo = null;
function doIt() {
var f1 = document.form1;
f1.newcms1.value = "signing ...";
var prvKeyPEM = f1.prvkey1.value;
var certPEM = f1.cert1.value;
param.signerInfos[0].signerCert = certPEM;
param.signerInfos[0].signerPrvKey = prvKeyPEM;
param.certs = [certPEM];
param.content.str = f1.content1.value;
if (f1.attr_sigtime.checked)
param.signerInfos[0].sAttr.SigningTime = {};
if (f1.attr_sigcertv1.checked)
param.signerInfos[0].sAttr.SigningCertificate = {array: [certPEM]};
if (f1.attr_sigcertv2.checked)
param.signerInfos[0].sAttr.SigningCertificateV2 = {array: [certPEM]};
if (f1.attr_sigpol_flag.checked) {
param.signerInfos[0].sAttr.SignaturePolicyIdentifier = {
oid: f1.attr_sigpol_oid.value,
hash: {
alg: f1.attr_sigpol_hashalg.value,
hash: f1.attr_sigpol_hash.value
}
};
}
try {
var sd = KJUR.asn1.cms.CMSUtil.newSignedData(param);
//f1.newcms1.value = sd.getPEM();
f1.newcms1.value = sd.getContentInfoEncodedHex();
} catch (ex) {
f1.newcms1.value = "Error: " + ex;
}
}
function doIt2() {
var f1 = document.form1;
try {
var cms = f1.newcms1.value;
parsedInfo =
KJUR.asn1.cades.CAdESUtil.parseSignedDataForAddingUnsigned(cms);
f1.si_sigval1.value = parsedInfo.si[0].sigval;
} catch (ex) {
f1.si_sigval1.value = "Error: " + ex;
}
}
// _test/z4.* RSA 2048bit
var sTSAKEY =
"-----BEGIN PRIVATE KEY-----\n" +
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDfdOqotHd55SYO\n" +
"0dLz2oXengw/tZ+q3ZmOPeVmMuOMIYO/Cv1wk2U0OK4pug4OBSJPhl09Zs6IwB8N\n" +
"wPOU7EDTgMOcQUYB/6QNCI1J7Zm2oLtuchzz4pIb+o4ZAhVprLhRyvqi8OTKQ7kf\n" +
"Gfs5Tuwmn1M/0fQkfzM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i8B+dFcgRYKFrcpsVaZ1lBmXKsXDRu5QR/Rg3f9DRq4GR1sNH8RLY9uApMl2SN\n" +
"z+sR4zRPG85R/se5Q06Gu0BUQ3UPm67ETVZLAgMBAAGjXzBdMAwGA1UdEwEB/wQC\n" +
"MAAwCwYDVR0PBAQDAgbAMBYGA1UdJQEB/wQMMAoGCCsGAQUFBwMIMCgGA1UdHwQh\n" +
"MB8wHaAboBmGF2h0dHA6Ly90ZXN0LmNvbS9jYTEuY3JsMA0GCSqGSIb3DQEBBQUA\n" +
"A4IBAQBNkm5GniFi3PKqbafCVN8mpHWJjF2stCRTVxeTCIXUC63YD5XKABGzPH+Y\n" +
"2R8fCrOa8cGlHmFXOlJye/lnXeZodPyxJUvAKohTp6sG+rJVId8ISI2Io2i5BF8a\n" +
"CHdm8qd8E0fJvBudqkEc26Ia6tFSA/gEW0ffhsCkN/lXUAjuvDLqtTtU7zBU6dIl\n" +
"h12Pwyf+x6AsYSciA9zWC6OE590K8Jr2z4u85biM7viWvPeZPNHSNM1fe+8wKbP8\n" +
"64JtLj/VrglcsXALaUalyh2Hs7gPQzjyus1fyhEWPO3T6KMcBMXjb6anxL5q9YO5\n" +
"qx1hJTY3L1hahBcMTALQyTEiFv1S\n" +
"-----END CERTIFICATE-----\n";
var tsa = new KJUR.asn1.tsp.SimpleTSAAdapter({
tstInfo: {
policy: '1.2.3.4.5',
messageImprint: {},
serialNumber: {'int': 3},
genTime: {millis: true},
accuracy: {millis: 500},
ordering: true,
nonce: {'int': 3}
},
certs: [sTSACERT],
signerCert: sTSACERT,
hashAlg: 'sha256',
signerPrvKey: sTSAKEY,
sigAlg: 'SHA256withRSA'
});
function doIt3() {
var f1 = document.form1;
var sigval = f1.si_sigval1.value;
f1.si_sigtst1.value = "getting TST from Demo TSA...";
try {
var tst = tsa.getTSTHex(sigval, 'sha256');
f1.si_sigtst1.value = tst;
} catch (ex) {
f1.si_sigtst1.value = "Error: " + ex;
}
}
function doIt4() {
var f1 = document.form1;
var tst = f1.si_sigtst1.value;
f1.cades_t_1.value = "generating CAdES-T by adding SigTS...";
try {
var sd = parsedInfo.obj;
var si = sd.signerInfoList[0];
sd.hTLV = null;
si.addUnsigned(new KJUR.asn1.cades.SignatureTimeStamp({tst: tst}));
f1.cades_t_1.value = sd.getContentInfoEncodedHex();
} catch (ex) {
f1.cades_t_1.value = "Error: " + ex;
}
}
</script>
</head>
<body>
<!-- HEADER -->
<div id="header_wrap" class="outer">
<header class="inner">
<h1 id="project_title">CAdES Generator</h1>
<h2 id="project_tagline">RFC 5126 CAdES Long Term Signature Generator by pure JavaScript</h2>
<a href="http://kjur.github.io/jsrsasign/">TOP</a> |
<a href="https://github.com/kjur/jsrsasign/tags/" target="_blank">DOWNLOADS</a> |
<a href="https://github.com/kjur/jsrsasign/wiki#programming-tutorial">TUTORIALS</a> |
<a href="http://kjur.github.io/jsrsasign/api/" target="_blank">API REFERENCE</a> |
<a href="http://kjur.github.io/jsrsasign/index.html#demo" target="_blank">DEMOS</a> |
</header>
</div>
<!-- MAIN CONTENT -->
<div id="main_content_wrap" class="outer">
<section id="main_content" class="inner">
<!-- now editing -->
This tool can generate CAdES-BES/EPES signature and then
convert it to CAdES-T by adding SignatureTimeStamp.<br/>
NOTE: Currently jsrsasign supports CAdES-BES, EPES and T formats.
<form name="form1">
<h4>(Step1) Generate CAdES-BES or EPES</h4>
<table>
<tr><td colspan="2">
Message to be signed (i.e. eContent):<br/>
<textarea name="content1" cols="65" rows="2">aaa</textarea>
</td></tr>
<tr><th colspan="2">SignerInfo</th></tr>
<tr><td colspan="2">Signer's Private Key (PEM):<br/>
<textarea name="prvkey1" cols="65" rows="3">-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDfdOqotHd55SYO
0dLz2oXengw/tZ+q3ZmOPeVmMuOMIYO/Cv1wk2U0OK4pug4OBSJPhl09Zs6IwB8N
wPOU7EDTgMOcQUYB/6QNCI1J7Zm2oLt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d7u3C/HX7Y16Uq8ohEJ
T5lslveDJ3iNljSK74eMK7kLg7fBM7YDogxccHJ1IHsvInp3e1pmZxOxAoGAO+bS
TUQ4N/UuQezgkF3TDrnBraO67leDGwRbfiE/U0ghQvqh5DA0QSPVzlWDZc9KUitv
j8vxsR9o1PW9GS0an17GJEYuetLnkShKK3NWOhBBX6d1yP9rVdH6JhgIJEy/g0Su
z7TAFiFc8i7JF8u4QJ05C8bZAMhOLotqftQeVOMCgYAid8aaRvaM2Q8a42Jn6ZTT
5ms6AvNr98sv0StnfmNQ+EYXN0bEk2huSW+w2hN34TYYBTjViQmHbhudwwu8lVjE
ccDmIXsUFbHVK+kTIpWGGchy5cYPs3k9s1nMR2av0Lojtw9WRY76xRXvN8W6R7Eh
wA2ax3+gEEYpGhjM/lO2Lg==
-----END PRIVATE KEY-----</textarea>
</td></tr>
<tr><td colspan="2">Signer's Certificate (PEM):<br/>
<textarea name="cert1" cols="65" rows="3">-----BEGIN CERTIFICATE-----
MIIC/zCCAeegAwIBAgIBATANBgkqhkiG9w0BAQUFADAaMQswCQYDVQQGEwJVUzEL
MAkGA1UECgwCWjQwHhcNMTMwODI4MTgyODM0WhcNMjMwODI4MTgyODM0WjAaMQsw
CQYDVQQGEwJVUzELMAkGA1UECgwCWjQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
ggEKAoIBAQDfdOqotHd55SYO0dLz2oXengw/tZ+q3ZmOPeVmMuOMIYO/Cv1wk2U0
OK4pug4OBSJPhl09Zs6IwB8NwPOU7EDTgMOcQUYB/6QNCI1J7Zm2oLtuchzz4pIb
+o4ZAhVprLhRyvqi8OTKQ7kfGfs5Tuwmn1M/0fQkfzMxADpjOKNgf0uy6lN6utjd
TrPKKFUQNdc6/Ty8EeTnQEwUlsT2LAXCfEKxTn5RlRljDztS7Sfgs8VL0FPy1Qi8
B+dFcgRYKFrcpsVaZ1lBmXKsXDRu5QR/Rg3f9DRq4GR1sNH8RLY9uApMl2SNz+sR
4zRPG85R/se5Q06Gu0BUQ3UPm67ETVZLAgMBAAGjUDBOMB0GA1UdDgQWBBQHZPTE
yQVu/0I/3QWhlTyW7WoTzTAfBgNVHSMEGDAWgBQHZPTEyQVu/0I/3QWhlTyW7WoT
zTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQDHxqJ9y8alTH7agVMW
Zfic/RbrdvHwyq+IOrgDToqyo0w+IZ6BCn9vjv5iuhqu4ForOWDAFpQKZW0DLBJE
Qy/7/0+9pk2DPhK1XzdOovlSrkRt+GcEpGnUXnzACXDBbO0+Wrk+hcjEkQRRK1bW
2rknARIEJG9GS+pShP9Bq/0BmNsMepdNcBa0z3a5B0fzFyCQoUlX6RTqxRw1h1Qt
5F00pfsp7SjXVIvYcewHaNASbto1n5hrSz1VY9hLba11ivL1N4WoWbmzAL6BWabs
C2D/MenST2/X6hTKyGXpg3Eg2h3iLvUtwcNny0hRKstc73Jl9xR3qXfXKJH0ThTl
q0gq
-----END CERTIFICATE-----</textarea>
</td></tr>
<tr><th colspan="2">SignerInfo Attributes</th></tr>
<tr><td colspan="2">
SigningTime
<input type="checkbox" name="attr_sigtime" value="1"/>,
SigningCertificate(V1)
<input type="checkbox" name="attr_sigcertv1" value="1"/>,
SigningCertificateV2
<input type="checkbox" name="attr_sigcertv2" value="1" checked/>
</td></tr>
<tr><td>
Signature<br/>Policy</br>(for EPES)<br/>
<input type="checkbox" name="attr_sigpol_flag" value="1"/>
</td>
<td>
policy OID:
<input type="text" name="attr_sigpol_oid" value="1.2.3.4.5" size="40"/>
<br/>
hash alg:
<select name="attr_sigpol_hashalg">
<option value="sha1">SHA-1
<option value="sha256">SHA-256
<option value="sha512">SHA-512
<option value="sha384">SHA-384
<option value="sha224">SHA-224
<option value="md5">MD5
<option value="ripemd160">RIPEMD160
</select>
<br/>
hash value:
<input type="text" name="attr_sigpol_hash" value="a1a2a3a4a5a6a7a8a9a0a1a2a3a4a5a6a7a8a9a0" size="40"/>
</td></tr>
</table>
<input type="button" value="Generate CAdES-BES/EPES" onClick="doIt();"/>
<input type="reset" name="reset" value="Reset"/>
<h6>RESULT:</h6>
<textarea name="newcms1" cols="65" rows="4"></textarea>
<h4>(Step2)Parse CAdES-BES/EPES for adding SigTS</h4>
Parse above CAdES-BES/EPES signature and
and get the signature value of signerInfo.
<br/>
<input type="button" value="Parse CAdES-BES/EPES" onClick="doIt2();"/>
<br/>
<h5>signature value of the first SignerInfo</h5>
<textarea name="si_sigval1" cols="65" rows="3"></textarea>
<br/>
<h4>(Step3)Get TimeStampToken</h4>
Get TimeStampToken for above signature value.
You can get it from trusted time stamp authority or
use sample TSA using jsrsasign.
<br/>
<input type="button" value="Get TimeStampToken for the signature from Demo TSA" onClick="doIt3();"/>
<br/>
<h6>TimeStampToken for the signature value in SignerInfo</h6>
<textarea name="si_sigtst1" cols="65" rows="3"></textarea>
<h4>(Step4)Convert CAdES-BES/EPES to CAdES-T</h4>
You can convert it to CAdES-T signature
by adding SignatureTimeStamp attribute with the above signature time stamp.
<br/>
<input type="button" value="Convert to CAdES-T" onClick="doIt4();"/>
<br/>
<h6>CAdES-T signature as the result</h6>
<textarea name="cades_t_1" cols="65" rows="3"></textarea><br/>
</form>
<!-- now editing -->
</section>
</div>
<!-- FOOTER -->
<div id="footer_wrap" class="outer">
<footer class="inner">
<p class="copyright">jsrsasign maintained by <a href="https://github.com/kjur">kjur</a></p>
<p>Published with <a href="http://pages.github.com">GitHub Pages</a></p>
<div align="center" style="color: white">
Copyright © 2014 Kenji Urushima. All rights reserved.
</div>
</footer>
</div>
</body>
</html>