aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/src/gpgmejs.js
diff options
context:
space:
mode:
Diffstat (limited to 'lang/js/src/gpgmejs.js')
-rw-r--r--lang/js/src/gpgmejs.js138
1 files changed, 130 insertions, 8 deletions
diff --git a/lang/js/src/gpgmejs.js b/lang/js/src/gpgmejs.js
index 7fa7643c..a0f7e968 100644
--- a/lang/js/src/gpgmejs.js
+++ b/lang/js/src/gpgmejs.js
@@ -26,6 +26,7 @@ import {GPGME_Message, createMessage} from './Message';
import {toKeyIdArray} from './Helpers';
import { gpgme_error } from './Errors';
import { GPGME_Keyring } from './Keyring';
+import { createSignature } from './Signature';
export class GpgME {
/**
@@ -107,15 +108,28 @@ export class GpgME {
* Decrypt a Message
* @param {String|Object} data text/data to be decrypted. Accepts Strings
* and Objects with a getText method
- * @returns {Promise<Object>} decrypted message:
- data: The decrypted data.
- base64: Boolean indicating whether data is base64 encoded.
- mime: A Boolean indicating whether the data is a MIME object.
- signatures: Array of signature Objects TODO not yet implemented.
- // should be an object that can tell if all signatures are valid.
+ * @param {Boolean} base64 (optional) false if the data is an armored block,
+ * true if it is base64 encoded binary data
+ * @returns {Promise<Object>} result: Decrypted Message and information
+ * @returns {String} result.data: The decrypted data.
+ * @returns {Boolean} result.base64: indicating whether data is base64
+ * encoded.
+ * @returns {Boolean} result.is_mime: Indicating whether the data is a MIME
+ * object.
+ * @returns {String} result.file_name: The optional original file name
+ * @returns {Object} message.signatures Verification details for signatures:
+ * @returns {Boolean} message.signatures.all_valid: true if all signatures
+ * are valid
+ * @returns {Number} message.signatures.count: Number of signatures found
+ * @returns {Number} message.signatures.failures Number of invalid
+ * signatures
+ * @returns {Array<Object>} message.signatures.signatures. Two arrays
+ * (good & bad) of {@link GPGME_Signature} objects, offering further
+ * information.
+ *
* @async
*/
- decrypt(data){
+ decrypt(data, base64=false){
if (data === undefined){
return Promise.reject(gpgme_error('MSG_EMPTY'));
}
@@ -124,8 +138,32 @@ export class GpgME {
if (msg instanceof Error){
return Promise.reject(msg);
}
+ if (base64 === true){
+ msg.setParameter('base64', true);
+ }
putData(msg, data);
- return msg.post();
+ if (base64 === true){
+ msg.setParameter('base64', true);
+ }
+ return new Promise(function(resolve, reject){
+ msg.post().then(function(result){
+ let _result = {data: result.data};
+ _result.base64 = result.base64 ? true: false;
+ _result.is_mime = result.mime ? true: false;
+ if (result.file_name){
+ _result.file_name = result.file_name;
+ }
+ if (
+ result.hasOwnProperty('signatures') &&
+ Array.isArray(result.signatures)
+ ) {
+ _result.signatures = collectSignatures(result.signatures);
+ }
+ resolve(_result);
+ }, function(error){
+ reject(error);
+ });
+ });
}
/**
@@ -179,6 +217,59 @@ export class GpgME {
});
});
}
+
+ /**
+ * Verifies data.
+ * @param {String|Object} data text/data to be verified. Accepts Strings
+ * and Objects with a gettext method
+ * @param {String} (optional) A detached signature. If not present, opaque
+ * mode is assumed
+ * @param {Boolean} (optional) Data and signature are base64 encoded
+ * // TODO verify if signature really is assumed to be base64
+ * @returns {Promise<Object>} result:
+ * @returns {Boolean} result.data: The verified data
+ * @returns {Boolean} result.is_mime: The message claims it is MIME
+ * @returns {String} result.file_name: The optional filename of the message
+ * @returns {Boolean} result.all_valid: true if all signatures are valid
+ * @returns {Number} result.count: Number of signatures found
+ * @returns {Number} result.failures Number of unsuccessful signatures
+ * @returns {Array<Object>} result.signatures. Two arrays (good & bad) of
+ * {@link GPGME_Signature} objects, offering further information.
+ */
+ verify(data, signature, base64 = false){
+ let msg = createMessage('verify');
+ let dt = this.putData(msg, data);
+ if (dt instanceof Error){
+ return Promise.reject(dt);
+ }
+ if (signature){
+ if (typeof(signature)!== 'string'){
+ return Promise.reject(gpgme_error('PARAM_WRONG'));
+ } else {
+ msg.setParameter('signature', signature);
+ }
+ }
+ if (base64 === true){
+ msg.setParameter('base64', true);
+ }
+ return new Promise(function(resolve, reject){
+ msg.post().then(function (message){
+ if (!message.info.signatures){
+ reject(gpgme_error('SIG_NO_SIGS'));
+ } else {
+ let _result = collectSignatures(message.info.signatures);
+ _result.is_mime = message.info.is_mime? true: false;
+ if (message.info.filename){
+ _result.file_name = message.info.filename;
+ }
+ _result.data = message.data;
+ resolve(_result);
+ }
+ }, function(error){
+ reject(error);
+ });
+ });
+ }
}
/**
@@ -209,3 +300,34 @@ function putData(message, data){
return gpgme_error('PARAM_WRONG');
}
}
+
+function collectSignatures(sigs){
+ if (!Array.isArray(sigs)){
+ return gpgme_error('SIG_NO_SIGS');
+ }
+ let summary = {
+ all_valid: false,
+ count: sigs.length,
+ failures: 0,
+ signatures: {
+ good: [],
+ bad: [],
+ }
+ };
+ for (let i=0; i< sigs.length; i++){
+ let sigObj = createSignature(sigs[i]);
+ if (sigObj instanceof Error){
+ return gpgme_error('SIG_WRONG');
+ }
+ if (sigObj.valid !== true){
+ summary.failures += 1;
+ summary.signatures.bad.push(sigObj);
+ } else {
+ summary.signatures.good.push(sigObj);
+ }
+ }
+ if (summary.failures === 0){
+ summary.all_valid = true;
+ }
+ return summary;
+} \ No newline at end of file
'n347' href='#n347'>347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
%PDF-1.4
%����
1 0 obj<</Metadata 22 0 R/Pages 2 0 R/Type/Catalog>>
endobj
2 0 obj<</Count 1/Type/Pages/Kids[5 0 R]>>
endobj
5 0 obj<</Parent 2 0 R/Contents 16 0 R/BleedBox[0.0 0.0 842.0 595.0]/PieceInfo<</Illustrator 6 0 R>>/ArtBox[43.416 146.34 811.598 476.064]/MediaBox[0.0 0.0 842.0 595.0]/Thumb 21 0 R/TrimBox[0.0 0.0 842.0 595.0]/Resources<</Font<</TT0 14 0 R>>/ProcSet[/PDF/Text]/Properties<</MC0<</Color[20224.0 -32768.0 -1.0]/Visible true/Editable true/Dimmed false/Preview true/Printed true/Title(Ebene 1)>>>>/ExtGState<</GS0 13 0 R>>>>/Type/Page/LastModified(D:20061202165348+02'00')>>
endobj
6 0 obj<</Private 7 0 R/LastModified(D:20061202165348+02'00')>>
endobj
7 0 obj<</RoundtripVersion 11/CreatorVersion 12/ContainerVersion 9/AIMetaData 8 0 R/AIPrivateData1 9 0 R/AIPrivateData2 10 0 R/AIPrivateData3 11 0 R/AIPrivateData4 12 0 R/NumBlock 4>>
endobj
8 0 obj<</Length 883>>stream
%!PS-Adobe-3.0 
%%Creator: Adobe Illustrator(R) 11.0
%%AI8_CreatorVersion: 12.0.0
%%For: (Thomas Wittek) (.zentrifuge.)
%%Title: (logo [Konvertiert].ai)
%%CreationDate: 12/2/2006 4:53 PM
%%BoundingBox: 43 146 812 477
%%HiResBoundingBox: 43.416 146.3398 811.5977 476.064
%%DocumentProcessColors: Cyan
%AI5_FileFormat 7.0
%AI3_ColorUsage: Color
%AI7_ImageSettings: 0
%%CMYKCustomColor: 1 1 1 1 ([Passermarken])
%AI3_TemplateBox: 421 297 421 297
%AI3_TileBox: 25 9.5 817 585.5
%AI3_DocumentPreview: None
%AI5_ArtSize: 842 595
%AI5_RulerUnits: 2
%AI9_ColorModel: 2
%AI5_ArtFlags: 0 0 0 1 0 0 1 0 0
%AI5_TargetResolution: 800
%AI5_NumLayers: 1
%AI9_OpenToView: -206 722 1 1270 865 26 0 0 4 113 0 0 1 1 1 0 1
%AI5_OpenViewLayers: 7
%%PageOrigin:0 0
%AI7_GridSettings: 72 8 72 8 1 0 0.8 0.8 0.8 0.9 0.9 0.9
%AI9_Flatten: 1
%AI12_CMSettings: 00.MO
%%EndComments

endstream
endobj
9 0 obj<</Length 8378>>stream
%%BoundingBox: 43 146 812 477
%%HiResBoundingBox: 43.416 146.3398 811.5977 476.064
%AI7_Thumbnail: 128 56 8
%%BeginData: 8227 Hex Bytes
%0000330000660000990000CC0033000033330033660033990033CC0033FF
%0066000066330066660066990066CC0066FF009900009933009966009999
%0099CC0099FF00CC0000CC3300CC6600CC9900CCCC00CCFF00FF3300FF66
%00FF9900FFCC3300003300333300663300993300CC3300FF333300333333
%3333663333993333CC3333FF3366003366333366663366993366CC3366FF
%3399003399333399663399993399CC3399FF33CC0033CC3333CC6633CC99
%33CCCC33CCFF33FF0033FF3333FF6633FF9933FFCC33FFFF660000660033
%6600666600996600CC6600FF6633006633336633666633996633CC6633FF
%6666006666336666666666996666CC6666FF669900669933669966669999
%6699CC6699FF66CC0066CC3366CC6666CC9966CCCC66CCFF66FF0066FF33
%66FF6666FF9966FFCC66FFFF9900009900339900669900999900CC9900FF
%9933009933339933669933999933CC9933FF996600996633996666996699
%9966CC9966FF9999009999339999669999999999CC9999FF99CC0099CC33
%99CC6699CC9999CCCC99CCFF99FF0099FF3399FF6699FF9999FFCC99FFFF
%CC0000CC0033CC0066CC0099CC00CCCC00FFCC3300CC3333CC3366CC3399
%CC33CCCC33FFCC6600CC6633CC6666CC6699CC66CCCC66FFCC9900CC9933
%CC9966CC9999CC99CCCC99FFCCCC00CCCC33CCCC66CCCC99CCCCCCCCCCFF
%CCFF00CCFF33CCFF66CCFF99CCFFCCCCFFFFFF0033FF0066FF0099FF00CC
%FF3300FF3333FF3366FF3399FF33CCFF33FFFF6600FF6633FF6666FF6699
%FF66CCFF66FFFF9900FF9933FF9966FF9999FF99CCFF99FFFFCC00FFCC33
%FFCC66FFCC99FFCCCCFFCCFFFFFF33FFFF66FFFF99FFFFCC110000001100
%000011111111220000002200000022222222440000004400000044444444
%550000005500000055555555770000007700000077777777880000008800
%000088888888AA000000AA000000AAAAAAAABB000000BB000000BBBBBBBB
%DD000000DD000000DDDDDDDDEE000000EE000000EEEEEEEE0000000000FF
%00FF0000FFFFFF0000FF00FFFFFF00FFFFFF
%524C45FD38FF8B1B1B151B1B3DA9FD76FF851B1461613D141B14153CFD74
%FF851B3D85151B151B141B151B3DFD72FFA915143D1415141B1415141B14
%1560FD71FF3D153D151B61FFFFFF851B151B151BAFFD41FFAF85AFFD2BFF
%AF141B141B85FD05FFAF1B14151461FD3FFF851B151B141B85FD29FF851B
%151B1BFD07FF851B151B15FD3EFF3C15141B1415141B3CFD1BFFA91BA8FD
%0AFF61141B1485FD08FF141B141BA9FD3CFF851B151B3D851B1B151B85FD
%19FF851B1BFD0BFF611B151B85FD08FF1B151B15FD3DFF1B141584FFFFFF
%601B141BFD18FF601B14FD0CFF61141B1485FD08FF141B141BA9FD3CFF14
%1B1BFD05FF151B15FD15FFAF8B151B14AFFD0CFF611B141B85FD08FF1B14
%1B15FD3CFFA9151461FD05FF61141BA9FD0FFFAFAF84611415141B1485FD
%0DFF6114151485FFFFA9FD05FF1415141BAFFD3CFF151B61FD05FF611B15
%FD0BFFAF851B1B151B151B151B151B15AFFD0DFF3D151B151B151B151B1B
%1B151B151B151B61FD07FFAF8B3D613D8BA9FD17FFAF8B61613D6185FD07
%FF85613D6161AFFFFFFFA9151461FD05FF61141BA9FD09FF3C1B1415141B
%1415141B141536FF6185FD0CFF141B1415141B1415141B1415141B1461A9
%FD07FF3C1B143D3C3D141BFD17FFAF141B3D61141B14AFFFFFFF61141B3D
%61141B14FFFFFF1B151B141B151B141B151B141BFD08FF1B1B141B151B14
%1B151B143D858B141BFD0DFF1B141B151B141B151B153D618BA9FD04FF3D
%85FFFFFF1B1B3DFD05FFAFFD17FFAF1B14FFFFFF3D1B1BFFFF3D153DFD05
%FFAFFFFFFF141B1415141B1415141B141514FD07FF141B1415141B141514
%1B141B141B141BA9FD0DFF1415141B3C85A8FFAFFD07FFA91B14AFFFFF60
%1B14FD09FF141B853D141B1485FFFFFF1B14AFFFFFFF3D1485FFFF1415A8
%FFFFAF141BFF85141BFD0AFF1B151B151B151B151B151B151BFD06FF611B
%151B151B151B151B151B151B1561FD0FFF1B1561FD0CFF611B1561A9FFFF
%1B158BFD09FF3D151B1B8B1B1B15FFFFFF1B1B85FFFFFF1B1B85FFAF1B15
%FFFFFFA91B15FF151B85FD0AFF141B1415141B1415141B141514FD06FF1B
%141B1415141B1415141B143D60FF85AFFD0EFF1485FD08FFA9FF8561141B
%61FF148BFFAF141BA9FD05FFAFFFFFFF141B3DFFFFFF141560FFFF1B14AF
%FFFFFF3D1485FFFF1415AFFFFF3D1461A91514AFFD06FFA9FFFFFF1B141B
%151B141B151B141B151BAFFD04FF8B151B141B151B141B153D3D8B856114
%1BAFFD0DFFAFAFFD08FFAFAF618561AFFFFF1B1B85FF851B14FD06FF1B14
%AFFF3D14AFFFFFFF61158BFFFF1B1B85FFFFFF1B1B85FFAF1B153D3D1B15
%3DFFAF151BAFFD05FF1B1B85FFFF1415141B1415141B1415141B14FD05FF
%141B1415141B1415141B1415141B1461FD1FFFAF141B14A9FFAF1415A8FD
%05FF141584FF141584FFFFFF361B85FFFF1B14AFFFFFFF3D148BFFAF141B
%363D3CAFFFFF841B14AFFD04FFAF1B14AFFFFF1B151B151B151B151B151B
%151BFD05FFAF151B151B151B151B151B153D85FD1FFF851B151B151B85FF
%AF1B15AFFD05FF1B15AFFF3D15AFFFFFFF3D158BFFFF1B1B85FFFFFF1B1B
%85FFAF1B15FD07FF151BA9FD05FF1B1BA9FFFF1415141B1415141B141514
%1B14FD06FF8514151485A9FFAFFFAFFD1BFFAF8560613D1B141B1485141B
%14AFFFFF141560FD05FF141585FF141585FFFFFF361B85FFFF1B14AFFFFF
%FF3D148BFFAF141BA9FD06FF1B1461FD05FF1B14AFFFFF1B151B141B151B
%141B151B141BFD07FF1B1BFD23FFAFAF85AFAFFFFFFF3D1B141B85FFFFAF
%151BAFFD04FF1B15AFFF3D15AFFFFFFF3D148BFFFF151B85FFFFFF151B85
%FFAF1B14FD07FF851B15FD05FF141BA9FFFFA8AFA9AFA8AFA9AFA8AFA9AF
%A8FD07FFA9FD29FF853D141B141514AFFFFFFF85141560FFAFAF141B85FF
%141B85FFFFFF361560FFFF61141B3C61141B1485FFFF1415A8FD07FF601B
%1485A9FF851514AFFD21FF858BA9FD13FFAF853D3D3D613D3D151B151B15
%1B151B85FD04FFAF1B1B151B153D61FFFF3D15AFFFFFFF61158BFFFFFF8B
%151B158B3D1B85FFAF1B15FD09FFAF3D151B151B1B8BAFFD06FF853D141B
%143D85FD12FF61141B141B1461AFFD10FF8B616160856161608561856085
%858560FD07FFAFFFAFFD05FFAFFD07FFAFFD05FFAFFFFFFFAFFFFFFFAFFD
%0DFFA9FFAFFD08FF611B141B151B141B61FD10FF1B143D151B141B151BAF
%FD5CFF601B1415141B1415141B60FD0EFF3D141B141B141B141B141BFD5B
%FFAF1B151B15AFAFAF1B1B151BA9FD0CFFAF151B1561FFFFFF8B151B158B
%FD5AFF61141B14FD05FF141B143DFD0CFF3C1B143DFD05FF61141514FD5A
%FF1B1B148BFD05FFAF141B1BFD0CFF1B141B85FD05FFA91B151BFD5AFF1B
%141584FD05FFA915141BFD0CFF141514AFFD05FFAF141B14FD5AFF1B1B15
%AFFD05FFAF151B1BFD0CFF3D151B85FD05FFAF1B151BFD5AFF3D141585FD
%05FFA915141BFD0CFF141514AFFD05FFAF141B14FD11FF84613D3D3C8585
%FD41FF85141B153D3D61FD043D151B3DFD0BFF3D1B151B141B151B141B15
%1B148BFD0FFF8B151B61AFA9AF858B3D8BFD3FFF1415141B1415141B1415
%143D85FFA8FD0AFF1B141B1415141B1415143D85FFFF8BAFFD0BFFA91B14
%85FFAF608585AFAFFF143DAFFD3DFF1B151B151B3D61618BA9FFFFFF851B
%FD0AFF1B1B151B61AF85AFFD05FF3D15FD0BFFAF1B15AFFF8561AFFD06FF
%1B1BFD0CFFAFFD1DFFAFFD0DFFAFFD04FF141560FD09FF3D1514FD0AFF1B
%14AFFD08FF611B1461FD0AFFAF1B1485FF61A9FFFFFFA9FD05FF143DFD08
%FF3D1B141B141B60FD17FFA91B141B141B1485FD05FF8B141B141B143DA9
%FF3D85FD07FF85611461853DAFFD09FF61FD06FFAF85853D3D858B15FD0A
%FF61141BFFAFA9FFAF1B141B158BFFFFFF3D14AFFD05FFAF141B61FFFFAF
%3D1BAFFD17FF141BAFFF851B1585FFFFFF3D141BA9FFAFAF1561FFA8FD06
%FFAF848585FFA81B14FD09FFA9FD07FFA9FFA9FFFF85141BAFFD08FFAF14
%1560FFA9FFA81B1415141B14AFFFFF611514FD04FFAF141584FD05FFA9FF
%FFFFAFFFFFFFAFFD05FFA9FD05FFAFFFA9FFA91514FFFFFF841B14FFFF61
%143DFD06FFA9FD0BFFAF3D1B151BFD13FFAF3D1B151B15FD09FF611B158B
%FFFFFF61151B151B151B3DFFFF8B151BA9FFFFFF3D1B3DFD09FF851B3D8B
%151B153DFFFFFF3D15AFFFFFFF61158BFFFF151BAFFFFFFF151BAFFF151B
%AFFD0DFFAF8561361B143D141B14FD0FFF8585603D1A3D601B141BFD09FF
%1B141584FFFFFF141B1415141B1461FFFF3D151461FFFFA91B148BFD09FF
%AF14151461611B143DFFFF141B85FFFFFF3D1560FFA91514FFFFFFA91B14
%FF601B14FD10FFAFAFAFFF611B141BFD14FF851B141B15FD09FF141B1585
%FFFFFF1B141B151B141B85FFFF1B151B3DFFFFAF141BAFFD09FF851B15FF
%FFFFAF1B14FFFF3D14AFFFFFFF61158BFFFF151BFFFFFF3D1461FF3D1461
%FD06FFAFFD04FFA9AF85858485601B141B141514FD0DFF606136613C1B14
%1B1415141BFD08FFAF15141B3CFFFFFF1415141B141514AFFFFF141B141B
%FFFF851514FD06FF1B148BFFAF141BFD04FF141BA9FF141584FFFFFF361B
%85FFA81B143D361B143DA9FF14153CFD05FF851514FD04FFFD06613D6161
%85618BFD0CFFAF8B858B858B85AF85AF85AFA9FD09FF151B1585FFFFFFAF
%618B85AFAFFFFF8B151B151B1BFFFFAF151BAFFD05FF151B85FF851B1BFD
%04FF1B15FFFF3D15AFFFFFFF61158BFFFF151B3D6161AFFFFFFF3D1561FD
%05FFAF151BFD32FF1B1461FD08FFA985361B1485601B1461FFFFAF1514AF
%FD05FF1B148BFFAF141BFD04FF141BAFFF141585FFFFFF3C1B85FFA91B14
%FD07FF611514FD05FF851514FD32FF3D1B3DFFFFFFA98B3D1B141B151B3D
%8BAF3D141B85FFFFFF1B1B61FD05FF1B1B85FF851B15FFFFFFAF1B15FFFF
%3D15AFFFFFFF61148BFFFF141BAFFD06FFAF151BAFFD04FFAF151BFD32FF
%8B141BFFFF3C15141B1415143D3C6160FF141514FD04FFAF1415A8FD04FF
%1B1485FFAF141BFD04FF141BFFFF141B61FFFFFF141560FFA91514FD08FF
%3D143DFD04FF841B14FD33FF1B15AF151B151B151B151B1B3D85FFAF1B15
%61FD05FF8B151B85FFFFAF151B85FF851B1BFD04FF1B15FFFF8B151B3D67
%1B1B158BFFFF151BAFFD08FF1B153DAFFFFF61151BFD33FF8515141B1415
%141B143D3C6185FFFF85141BA9FD06FFAF141B141B141B3DAFFFAF143DFD
%04FF141BFFFFFF6114151485611560FFA91B14AFFD09FF85141B141B143D
%85FD34FF611B141B151B141B3D6185FFAFAF141BA9FD0BFFAFFD0DFFAFFD
%1BFFAFFFAFFD38FF6015141B3C6136613C1B141B141584FD72FF851B1B1B
%151B151B151B151BAFFD75FF85141B141B141B36AFFD7BFFA9FDC3FFFF
%%EndData

endstream
endobj
10 0 obj<</Length 13560/Filter[/FlateDecode]>>stream
H��W�o"G�ϖ�?�)ړ-���'�J� ����V��)���=�m��_uσ1��wu�%B�Lׯ���U���uB1��j�L��޽;�@����-�n��]:�=$�_*[T����_A*&�1�+�rB���ÙXPE>0�a~HJ���d3�ҡ�
��