Skip to content

Commit 81fa4e8

Browse files
committed
feat: Highlight the public key
1 parent 514af23 commit 81fa4e8

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

js/index.html

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ <h2>Headers</h2>
2020
<label for="auth">Authorization Header:</label>
2121
<textarea name="auth" placeholder="Bearer abCDef..."></textarea>
2222
<label for="crypt">Crypto-Key Header:</label>
23-
<p>The public key expressed after "p256ecdsa=" can associate this feed with the dashboard."</p>
23+
<p>The public key expressed after "p256ecdsa=" can associate this feed with the dashboard.</p>
2424
<textarea name="crypt" placeholder="p256ecdsa=abCDef.."></textarea>
2525
<div class="control">
26+
<label for="publicKey">Public Key:</label>
27+
<p>This is the public key you'd use for the Dashboard</p>
28+
<textarea name="publicKey" placeholder="abCDef..." readonly=true></textarea>
2629
<button id="check">Check headers</button>
2730
</div>
2831
</div>
@@ -61,9 +64,9 @@ <h3>Claims JSON object:</h3>
6164
<h2>Exported Keys</h2>
6265
<b>Auto-generated keys:</b>
6366
<p>These are ASN.1 DER formatted version of the public and private keys used to generate
64-
the VAPID headers. These can be useful for languages that use DER for key import.</p>
65-
<label for="priv">Private Key:</label><textarea name="priv"></textarea>
66-
<label for="pub">Public Key:</label><textarea name="pub"></textarea>
67+
the VAPID headers. These can be useful for languages that use DER or PEM for key import.</p>
68+
<label for="priv">DER Private Key:</label><textarea name="priv"></textarea>
69+
<label for="pub">DER Public Key:</label><textarea name="pub"></textarea>
6770
</div>
6871
<div id="err" class="hidden section"></div>
6972
</div>
@@ -212,12 +215,16 @@ <h2>Exported Keys</h2>
212215
.catch(er => error(er, "Public key export failed" ));
213216
vapid.sign(claims)
214217
.then(k => {
215-
let auth = document.getElementsByName("auth")[0]
218+
let auth = document.getElementsByName("auth")[0];
216219
auth.value = k.authorization;
217220
auth.classList.add('updated');
218-
let crypt = document.getElementsByName("crypt")[0]
221+
let crypt = document.getElementsByName("crypt")[0];
219222
crypt.value = k["crypto-key"];
220223
crypt.classList.add('updated');
224+
let pk = document.getElementsByName("publicKey")[0];
225+
// Public Key is the crypto key minus the 'p256ecdsa='
226+
pk.value = k.publicKey;
227+
pk.classList.add('updated');
221228
})
222229
.catch(err => error(err, err_strs.enus.CLAIMS_FAIL));
223230
});

js/vapid.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,11 @@ var vapid = {
257257
*/
258258
return webCrypto.exportKey('raw', this._public_key)
259259
.then( key => {
260+
let pubKey = this.url_btoa(key);
260261
return {
261262
authorization: "Bearer " + content + "." + sig,
262-
"crypto-key": "p256ecdsa=" + this.url_btoa(key),
263+
"crypto-key": "p256ecdsa=" + pubKey,
264+
publicKey: pubKey,
263265
}
264266
})
265267
})

0 commit comments

Comments
 (0)