Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 createJwt(){
var pubKey = this.state.keypair.pubKeyObj;
const jwkPrv2 = KEYUTIL.getJWKFromKey(this.state.keypair.prvKeyObj);
const jwkPub2 = KEYUTIL.getJWKFromKey(this.state.keypair.pubKeyObj);
console.log(pubKey);
const currentTime = KJUR.jws.IntDate.get('now');
const endTime = KJUR.jws.IntDate.get('now + 1day');
const kid = KJUR.jws.JWS.getJWKthumbprint(jwkPub2)
// const pubPem = {"pem":KEYUTIL.getPEM(pubKey),"id":kid};
const pubPem = {"pem":jwkPub2,"id":kid};
// Check if the public key is already in the db
const checkForPublic = await fetch("http://localhost:3001/public_keys?id="+kid,{
"headers":{
"Content-Type":"application/json"
},
"method":"GET"
}).then(response => {return response.json()});
if(!checkForPublic.length){
async createJwt(){
var pubKey = this.state.keypair.pubKeyObj;
const jwkPrv2 = KEYUTIL.getJWKFromKey(this.state.keypair.prvKeyObj);
const jwkPub2 = KEYUTIL.getJWKFromKey(this.state.keypair.pubKeyObj);
console.log(pubKey);
const currentTime = KJUR.jws.IntDate.get('now');
const endTime = KJUR.jws.IntDate.get('now + 1day');
const kid = KJUR.jws.JWS.getJWKthumbprint(jwkPub2)
// const pubPem = {"pem":KEYUTIL.getPEM(pubKey),"id":kid};
const pubPem = {"pem":jwkPub2,"id":kid};
// Check if the public key is already in the db
const checkForPublic = await fetch("http://localhost:3001/public_keys?id="+kid,{
"headers":{
"Content-Type":"application/json"
},
"method":"GET"
}).then(response => {return response.json()});
if(!checkForPublic.length){
// POST key to db if it's not already there
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});
}else{
this.setState({editMode:false});