Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(data => {
var pk = KEYUTIL.getKey(data);
var sig = new KJUR.crypto.Signature({"alg": "SHA512withRSA"}); // Use "SHA1withRSA" for QZ Tray 2.0 and older
sig.init(pk);
sig.updateString(hash);
var hex = sig.sign();
console.log("DEBUG: \n\n" + stob64(hextorstr(hex)));
resolve(stob64(hextorstr(hex)));
})
.catch(err => console.error(err));
getKeyID(value){
var encodedKey = null;
try{
encodedKey=JSON.parse(value);
}catch(e){
// the key is not JSON formatted
encodedKey=value;
}
keyID = "";
try{
var pubKey = KEYUTIL.getKey(encodedKey);
// this part won't fail
var jwkPub = KEYUTIL.getJWKFromKey(pubKey);
var keyID = KJUR.jws.JWS.getJWKthumbprint(jwkPub);
}catch(e){
// the key cannot be retrieved.
console.log(e);
}
return keyID;
}
updateContent(event){
event.preventDefault();
this.setState({animationClasses:"keyEntry"});
console.log(this.state.animationClasses)
try{
var jwtPub = JSON.parse(this.state.jwt);
}catch(e){
jwtPub = this.state.jwt;
}
try{
var pubKey = KEYUTIL.getKey(jwtPub);
var jwkPub = KEYUTIL.getJWKFromKey(pubKey);
this.setState({jwt: JSON.stringify(jwkPub)})
// Dynamically generating a key id is counterintuitive when you
// can just add a new key that will auto-generate an ID.
// In the unlikely event that users want to be able to directly
// edit an existing key (aka, acutally editing the text in
// the PEM string, or the JSON) this could be useful, but I doubt that anybody
// will be changing individual characters in an encoded string.
var keyID = KJUR.jws.JWS.getJWKthumbprint(jwkPub);
if(keyID !=this.state.kid){
this.props.updateIdCB(this.state.kid,keyID, jwkPub);
this.setState({kid: keyID});
}
this.setState({data: "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(jwkPub))});
async importIdentity(client, label, identity) {
// check the identity type
const cryptoContent = {
signedCertPEM: identity.certificate
};
const publicKey = KEYUTIL.getKey(identity.certificate);
const ecdsakey = new ecdsaKey(publicKey);
cryptoContent.privateKeyObj = await this.cryptoSuite.getKey(Buffer.from(ecdsakey.getSKI(), 'hex'));
await client.createUser({
username: label,
mspid: identity.mspId,
cryptoContent: cryptoContent
});
}
'RS256'
]);
if (!isValid) {
this.loggerService.logWarning(
'incorrect Signature, validation failed for id_token'
);
}
return isValid;
}
}
}
} else {
// kid in the Jose header of id_token
for (const key of jwtkeys.keys) {
if ((key.kid as string) === (kid as string)) {
const publickey = KEYUTIL.getKey(key);
isValid = KJUR.jws.JWS.verify(id_token, publickey, [
'RS256'
]);
if (!isValid) {
this.loggerService.logWarning(
'incorrect Signature, validation failed for id_token'
);
}
return isValid;
}
}
}
return isValid;
}
for (const key of jwtkeys.keys) {
if (key.kty as string === 'RSA' && key.use as string === 'sig') {
const publickey = KEYUTIL.getKey(key);
isValid = KJUR.jws.JWS.verify(id_token, publickey, ['RS256']);
if (!isValid) {
this.oidcSecurityCommon.logWarning('incorrect Signature, validation failed for id_token');
}
return isValid;
}
}
}
} else {
// kid in the Jose header of id_token
for (const key of jwtkeys.keys) {
if (key.kid as string === kid as string) {
const publickey = KEYUTIL.getKey(key);
isValid = KJUR.jws.JWS.verify(id_token, publickey, ['RS256']);
if (!isValid) {
this.oidcSecurityCommon.logWarning('incorrect Signature, validation failed for id_token');
}
return isValid;
}
}
}
return isValid;
}
for (const key of jwtkeys.keys) {
if ((key.kty as string) === 'RSA' && (key.use as string) === 'sig') {
amountOfMatchingKeys = amountOfMatchingKeys + 1;
}
}
if (amountOfMatchingKeys === 0) {
this.loggerService.logWarning('no keys found, incorrect Signature, validation failed for id_token');
return false;
} else if (amountOfMatchingKeys > 1) {
this.loggerService.logWarning('no ID Token kid claim in JOSE header and multiple supplied in jwks_uri');
return false;
} else {
for (const key of jwtkeys.keys) {
if ((key.kty as string) === 'RSA' && (key.use as string) === 'sig') {
const publickey = KEYUTIL.getKey(key);
isValid = KJUR.jws.JWS.verify(id_token, publickey, ['RS256']);
if (!isValid) {
this.loggerService.logWarning('incorrect Signature, validation failed for id_token');
}
return isValid;
}
}
}
} else {
// kid in the Jose header of id_token
for (const key of jwtkeys.keys) {
if ((key.kid as string) === (kid as string)) {
const publickey = KEYUTIL.getKey(key);
isValid = KJUR.jws.JWS.verify(id_token, publickey, ['RS256']);
if (!isValid) {
this.loggerService.logWarning('incorrect Signature, validation failed for id_token');
updateContent(event){
try{
var jwtPub = JSON.parse(this.state.jwt);
}catch(e){
jwtPub = this.state.jwt;
}
try{
var pubKey = KEYUTIL.getKey(jwtPub);
var jwkPub = KEYUTIL.getJWKFromKey(pubKey);
this.setState({jwt: JSON.stringify(jwkPub)})
var keyID = KJUR.jws.JWS.getJWKthumbprint(jwkPub);
// this.props.updateIdCB(this.state.kid,keyID, jwkPub);
this.setState({kid: keyID});
}catch(e){
}
event.preventDefault();
if(!this.state.editMode){
this.setState({editMode:true});
amountOfMatchingKeys = amountOfMatchingKeys + 1;
}
}
if (amountOfMatchingKeys === 0) {
this.loggerService.logWarning('no keys found, incorrect Signature, validation failed for id_token');
return false;
}
else if (amountOfMatchingKeys > 1) {
this.loggerService.logWarning('no ID Token kid claim in JOSE header and multiple supplied in jwks_uri');
return false;
}
else {
for (var _b = 0, _c = jwtkeys.keys; _b < _c.length; _b++) {
var key = _c[_b];
if (key.kty === 'RSA' && key.use === 'sig') {
var publickey = KEYUTIL.getKey(key);
isValid = KJUR.jws.JWS.verify(id_token, publickey, ['RS256']);
if (!isValid) {
this.loggerService.logWarning('incorrect Signature, validation failed for id_token');
}
return isValid;
}
}
}
}
else {
for (var _d = 0, _e = jwtkeys.keys; _d < _e.length; _d++) {
var key = _e[_d];
if (key.kid === kid) {
var publickey = KEYUTIL.getKey(key);
isValid = KJUR.jws.JWS.verify(id_token, publickey, ['RS256']);
if (!isValid) {