Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
***************************************************************************/
var parts = jweString.split('.');
if (parts.length !== 5)
return callback(new Error('In jwe.decrypt: invalid JWE string, it has ' + parts.length + ' parts instead of 5'), null);
var header;
try {
header = JSON.parse(base64url.decode(parts[0], 'binary'));
} catch (ex) {
return callback(new Error('In jwe.decrypt: failed to parse JWE header'), null);
}
var aad = createBuffer(parts[0]);
var encrypted_cek = base64url.toBuffer(parts[1]);
var iv = base64url.toBuffer(parts[2]);
var cipherText = base64url.toBuffer(parts[3]);
var authTag = base64url.toBuffer(parts[4]);
log.info('In jwe.decrypt: the header is ' + JSON.stringify(header));
var cek_result;
var content_result;
// special treatment of 'dir'
if (header.alg === 'dir') {
content_result = decryptContentForDir(header, jweKeyStore, cipherText, iv, authTag, aad, log);
} else {
/****************************************************************************
* cek decryption
***************************************************************************/
var cek_result = decryptCEK(header, encrypted_cek, jweKeyStore, log);
if (cek_result.error)
decrypt (key, ciphertext, iv, tag, aad) {
let algorithm = this.params
algorithm.iv = Uint8Array.from(base64url.toBuffer(iv))
algorithm.additionalData = aad
// Decode ciphertext and tag from base64
ciphertext = base64url.toBuffer(ciphertext)
tag = base64url.toBuffer(tag)
// Concatenate the two buffers
let data = new Uint8Array(ciphertext.length + tag.length)
data.set(new Uint8Array(ciphertext), 0)
data.set(new Uint8Array(tag), ciphertext.length)
data = data.buffer
return crypto.subtle
.decrypt(algorithm, key, data)
.then(plaintext => Buffer.from(plaintext).toString())
}
UserCreateViewModel.prototype.addCredential = function (){
let _this = this;
let challengeBase64 = $("meta[name='_challenge']").attr("content");
let challenge = base64url.toBuffer(challengeBase64);
let userHandle = base64url.toBuffer($('#userHandle').val());
let makePublicKeyCredentialOptions = {
// Relying Party:
rp: {
name: "spring-security-webauthn sample"
},
// User:
user: {
id: userHandle,
name: $('#emailAddress').val(),
displayName: $('#firstName').val() + " " + $('#lastName').val(),
icon: null
},
challenge: challenge,
pubKeyCredParams: [
{
UserCreateViewModel.prototype.addCredential = function (){
let _this = this;
let challengeBase64 = $("meta[name='_challenge']").attr("content");
let challenge = base64url.toBuffer(challengeBase64);
let userHandle = base64url.toBuffer($('#userHandle').val());
let makePublicKeyCredentialOptions = {
// Relying Party:
rp: {
name: "spring-security-webauthn sample"
},
// User:
user: {
id: userHandle,
name: $('#emailAddress').val(),
displayName: $('#firstName').val() + " " + $('#lastName').val(),
icon: null
},
challenge: challenge,
pubKeyCredParams: [
var cek = null;
try {
var key_to_use;
if (alg === 'RSA1_5' || alg === 'RSA-OAEP') {
if (key['privatePemKey']) {
log.info('using RSA privatePemKey to decrypt cek');
key_to_use = key['privatePemKey'];
} else {
log.info('converting jwk to RSA privatePemKey to decrypt cek');
key_to_use = jwkToPem(key, {private: true});
}
} else if (alg === 'A128KW' || alg === 'A256KW') {
log.info('using symmetric key to decrypt cek');
key_to_use = base64url.toBuffer(key.k);
} else {
log.info('unsupported alg: ' + alg);
return {'error': error, 'cek': null};
}
if (alg === 'RSA1_5')
cek = crypto.privateDecrypt({ key: key_to_use, padding: constants.RSA_PKCS1_PADDING }, encrypted_cek);
else if (alg === 'RSA-OAEP')
cek = crypto.privateDecrypt({ key: key_to_use, padding: constants.RSA_PKCS1_OAEP_PADDING }, encrypted_cek);
else if (alg === 'A128KW')
cek = AESKeyUnWrap('aes-128-ecb', encrypted_cek, key_to_use);
else if (alg === 'A256KW')
cek = AESKeyUnWrap('aes-256-ecb', encrypted_cek, key_to_use);
else
cek = key_to_use; // dir
} catch (ex) {
verify (key, signature, data) {
let algorithm = this.params
if (typeof signature === 'string') {
signature = Uint8Array.from(base64url.toBuffer(signature))
}
if (typeof data === 'string') {
data = new TextEncoder().encode(data)
}
// ...
return crypto.subtle.verify(algorithm, key, signature, data)
}
this.detectContext()
console.log("document.getElementsByClassName('className').style",document.getElementsByClassName('.btn').style)
window.addEventListener("resize", this.updateDimensions.bind(this));
if(window.location.pathname){
console.log("PATH",window.location.pathname,window.location.pathname.length,window.location.hash)
if(window.location.pathname.indexOf("/pk")>=0){
let tempweb3 = new Web3();
let base64encodedPK = window.location.hash.replace("#","")
let rawPK
if(base64encodedPK.length==64||base64encodedPK.length==66){
console.log("raw pk ",base64encodedPK)
rawPK=base64encodedPK
}else{
rawPK=tempweb3.utils.bytesToHex(base64url.toBuffer(base64encodedPK))
}
this.setState({possibleNewPrivateKey:rawPK})
window.history.pushState({},"", "/");
}else if(window.location.pathname.length==43){
this.changeView('send_to_address')
console.log("CHANGE VIEW")
}else if(window.location.pathname.length==134){
let parts = window.location.pathname.split(";")
let claimId = parts[0].replace("/","")
let claimKey = parts[1]
console.log("DO CLAIM",claimId,claimKey)
this.setState({claimId,claimKey})
window.history.pushState({},"", "/");
}else if(
(window.location.pathname.length>=65&&window.location.pathname.length<=67&&window.location.pathname.indexOf(";")<0) ||
(window.location.hash.length>=65 && window.location.hash.length <=67 && window.location.hash.indexOf(";")<0)
_getChannelJwk () {
const { channelId, channelJwk, channelKey } = this.toJSON();
if (channelJwk) {
return Promise.resolve(channelJwk);
}
const channelKeyBuffer = base64url.toBuffer(channelKey);
const channelIdBuffer = base64url.toBuffer(channelId);
return Promise.all([
this._deriveChannelJwk(channelKeyBuffer, channelIdBuffer),
this._deriveConfirmationCode(channelKeyBuffer, channelIdBuffer),
]).then(([channelJwk, confirmationCode]) => {
this.set({
channelJwk,
confirmationCode,
});
return channelJwk;
});
}
function toSignatureObject (signature) {
const rawsig = base64url.toBuffer(signature)
if (rawsig.length !== 64) throw new Error('wrong signature length')
const r = rawsig.slice(0, 32).toString('hex')
const s = rawsig.slice(32).toString('hex')
return {r, s}
}