js: Demoextension update
-- * src/Signature: typo * src/gpgmejs.js: fixed wrong scope in verification * right now verify does not succeed in the DemoExtension. This is probably a problem in conversion or line ending.
This commit is contained in:
parent
d27703ea4f
commit
88e7f8ec2e
@ -27,7 +27,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
Gpgmejs.init().then(function(gpgmejs){
|
||||
document.getElementById('buttonencrypt').addEventListener('click',
|
||||
function(){
|
||||
let data = document.getElementById('cleartext').value;
|
||||
let data = document.getElementById('inputtext').value;
|
||||
let keyId = document.getElementById('pubkey').value;
|
||||
gpgmejs.encrypt(data, keyId).then(
|
||||
function(answer){
|
||||
@ -42,7 +42,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
document.getElementById('buttondecrypt').addEventListener('click',
|
||||
function(){
|
||||
let data = document.getElementById('ciphertext').value;
|
||||
let data = document.getElementById('inputtext').value;
|
||||
gpgmejs.decrypt(data).then(
|
||||
function(answer){
|
||||
if (answer.data){
|
||||
@ -57,11 +57,46 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
document.getElementById('getdefaultkey').addEventListener('click',
|
||||
function(){
|
||||
gpgmejs.Keyring.getDefaultKey().then(function(answer){
|
||||
document.getElementById('defaultkey').textContent =
|
||||
document.getElementById('pubkey').value =
|
||||
answer.fingerprint;
|
||||
}, function(errormsg){
|
||||
alert(errormsg.message);
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('signtext').addEventListener('click',
|
||||
function(){
|
||||
let data = document.getElementById('inputtext').value;
|
||||
let keyId = document.getElementById('pubkey').value;
|
||||
gpgmejs.sign(data, keyId).then(
|
||||
function(answer){
|
||||
if (answer.data){
|
||||
document.getElementById(
|
||||
'answer').value = answer.data;
|
||||
}
|
||||
}, function(errormsg){
|
||||
alert( errormsg.message);
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('verifytext').addEventListener('click',
|
||||
function(){
|
||||
let data = document.getElementById('inputtext').value;
|
||||
gpgmejs.verify(data).then(
|
||||
function(answer){
|
||||
let vals = '';
|
||||
if (answer.all_valid === true){
|
||||
vals = 'Success! ';
|
||||
} else {
|
||||
vals = 'Failure! ';
|
||||
}
|
||||
vals = vals + (answer.count - answer.failures) + 'of '
|
||||
+ answer.count + ' signature(s) were successfully '
|
||||
+ 'verified.\n\n' + answer.data;
|
||||
document.getElementById('answer').value = vals;
|
||||
}, function(errormsg){
|
||||
alert( errormsg.message);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -7,38 +7,37 @@
|
||||
<script src="maindemo.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<ul>
|
||||
<li>
|
||||
<span class="label">Text: </span>
|
||||
<input type="text" id='cleartext' />
|
||||
</li>
|
||||
<li>
|
||||
<span class="label">Public key ID: </span>
|
||||
<input type="text" id="pubkey" value="" />
|
||||
</li>
|
||||
</ul>
|
||||
<button id="buttonencrypt">Encrypt</button><br>
|
||||
<hr>
|
||||
<ul>
|
||||
<li>
|
||||
<span class="label">Encrypted armored Text: </span>
|
||||
<textarea rows="5" cols="65" id="ciphertext" wrap="hard"></textarea>
|
||||
</li>
|
||||
</ul>
|
||||
<button id="buttondecrypt">Decrypt</button><br>
|
||||
<hr>
|
||||
<h3>Result data:</h3>
|
||||
<textarea id="answer" rows="5" cols="65" wrap="hard"></textarea>
|
||||
<div>
|
||||
|
||||
<hr>
|
||||
<ul>
|
||||
<li>
|
||||
<span class="label">Default Key:</span>
|
||||
<button id="getdefaultkey">Get</button><br>
|
||||
<span id="defaultkey"></span>
|
||||
</li>
|
||||
<div class="left">
|
||||
<ul>
|
||||
<li>
|
||||
<span class="label">Input</span>
|
||||
<textarea rows="5" cols="65" id="inputtext" wrap="hard"></textarea>
|
||||
</li>
|
||||
<li>
|
||||
<span class="label">Fingerprint of Key to use: </span>
|
||||
</li>
|
||||
<input type="text" id="pubkey" value="" /> <br>
|
||||
<button id="getdefaultkey">Set to default signing key</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="right">
|
||||
<ul>
|
||||
<li>
|
||||
<span class="label">Result</span>
|
||||
<textarea id="answer" rows="5" cols="65" wrap="hard"></textarea>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="center">
|
||||
<button id="buttonencrypt">Encrypt input text</button><br>
|
||||
<button id="buttondecrypt">Decrypt input text</button><br>
|
||||
<button id="signtext">Sign input text</button> <br>
|
||||
<button id="verifytext">Verify input text</button><br>
|
||||
|
||||
|
||||
</ul>
|
||||
</body>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -8,3 +8,26 @@ ul li span {
|
||||
width: 120px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
div .left {
|
||||
float: left;
|
||||
align-items: stretch;
|
||||
width: 40%;
|
||||
}
|
||||
div .center {
|
||||
width: 50%;
|
||||
align-content: space-between;
|
||||
}
|
||||
|
||||
div .center button {
|
||||
align-self: stretch;
|
||||
}
|
||||
div .right {
|
||||
float: right;
|
||||
align-items: stretch;
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
div .bottom {
|
||||
clear:both;
|
||||
}
|
@ -35,7 +35,7 @@ export function createSignature(sigObject){
|
||||
if (
|
||||
typeof(sigObject) !=='object' ||
|
||||
!sigObject.hasOwnProperty('summary') ||
|
||||
!sigObject.hasOwnProperty('fingerpprint') ||
|
||||
!sigObject.hasOwnProperty('fingerprint') ||
|
||||
!sigObject.hasOwnProperty('timestamp')
|
||||
//TODO check if timestamp is mandatory in specification
|
||||
){
|
||||
@ -67,6 +67,7 @@ export function createSignature(sigObject){
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('sig created');
|
||||
return new GPGME_Signature(sigObject);
|
||||
}
|
||||
|
||||
@ -178,7 +179,8 @@ const expSum = {
|
||||
'crl-missing': 'boolean',
|
||||
'crl-too-old': 'boolean',
|
||||
'bad-policy': 'boolean',
|
||||
'sys-error': 'boolean'
|
||||
'sys-error': 'boolean',
|
||||
'sigsum': 'object'
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -168,7 +168,7 @@ export class GpgME {
|
||||
|
||||
/**
|
||||
* Sign a Message
|
||||
* @param {String|Object} data text/data to be decrypted. Accepts Strings
|
||||
* @param {String|Object} data text/data to be signed. Accepts Strings
|
||||
* and Objects with a gettext methos
|
||||
* @param {GPGME_Key|String|Array<String>|Array<GPGME_Key>} keys The
|
||||
* key/keys to use for signing
|
||||
@ -238,7 +238,7 @@ export class GpgME {
|
||||
*/
|
||||
verify(data, signature, base64 = false){
|
||||
let msg = createMessage('verify');
|
||||
let dt = this.putData(msg, data);
|
||||
let dt = putData(msg, data);
|
||||
if (dt instanceof Error){
|
||||
return Promise.reject(dt);
|
||||
}
|
||||
@ -317,7 +317,7 @@ function collectSignatures(sigs){
|
||||
for (let i=0; i< sigs.length; i++){
|
||||
let sigObj = createSignature(sigs[i]);
|
||||
if (sigObj instanceof Error){
|
||||
return gpgme_error('SIG_WRONG');
|
||||
return gpgme_error(sigObj);
|
||||
}
|
||||
if (sigObj.valid !== true){
|
||||
summary.failures += 1;
|
||||
|
Loading…
Reference in New Issue
Block a user