├── .gitignore ├── .travis.yml ├── README.md ├── binding.gyp ├── index.js ├── package.json ├── src ├── addon.cc ├── context.cc └── context.h └── tests └── context.js /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | node_modules/ 3 | npm-debug.log* 4 | .DS_Store 5 | *~ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: node_js 4 | 5 | env: 6 | - CXX=g++-4.8 7 | 8 | addons: 9 | apt: 10 | sources: 11 | - ubuntu-toolchain-r-test 12 | packages: 13 | - g++-4.8 14 | - libgpgme11-dev 15 | 16 | node_js: 17 | - "6" 18 | - "5" 19 | - "4" 20 | - "0.12" 21 | - "iojs" 22 | 23 | 24 | install: 25 | - npm install 26 | 27 | script: 28 | - npm test 29 | 30 | notifications: 31 | email: false 32 | 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # node-gpgme [![Build Status](https://travis-ci.org/kiddouk/node-gpgme.svg?branch=master)](https://travis-ci.org/kiddouk/node-gpgme) 2 | This module gives you access to GpgMe librairy and its underlying GPG backend. With this module, you can : 3 | 4 | * Add and remove key to your keyring 5 | * Cipher a payload valid for one or more recipients 6 | * Decipher a payload 7 | * Payloads can (but not necessary) be Ascii Armored if needed be 8 | 9 | This module is aiming at (finally!) give access to gpg key manipulation for node user respecting a couple of JS good practices like: 10 | 11 | * using promises for callbacks 12 | * handling multiple "gpg context" (see the context as a session. One session could output everything in ASCII, while the other one can output everything in binary, or 2 sessions could use a different keyring if you want to). 13 | 14 | ## Requirements 15 | 16 | * node-gyp 17 | * `npm install node-gyp -g` 18 | * libgpgme11 19 | * linux: `apt-get install libgpgme11 libgpgme11-dev` 20 | * osx: `brew install gpgme` 21 | 22 | ## Installation 23 | 24 | Simply run `npm install node-gpgme`. Make sure you have the requirements installed correctly. 25 | 26 | ## Configuration 27 | 28 | The configuration objects allows you to specify the path of the keyring to use, if armored is to be used and the backend engine you want to use (so far, we only support OpenPGP). 29 | 30 | ```js 31 | var GpgMe = require('gpgme') 32 | var gpgme = new GpgMe({armored: true, keyring_path: '/tmp'}); 33 | ``` 34 | 35 | ## Key Manipulation ## 36 | 37 | So far, you can only add a key (public or secret) and list those keys. Simple. 38 | 39 | 1. Adding a key 40 | 41 | var s = "-----BEGIN PGP PUBLIC KEY BLOCK ..." 42 | var fingerprint = gpgme.importKey(s) 43 | if (fingerprint === false) { 44 | console.log("Couldn't import key.") 45 | } else { 46 | console.log("Key fingerprint :" + fingerprint); 47 | } 48 | 49 | 2. Listing keys 50 | ```js 51 | var keys = gpgme.listKeys(); 52 | console.log(keys[0]); 53 | ``` 54 | 55 | ```js 56 | { fingerprint: '3B2302E57CC7AA3D8D4600E89DAC32BD82A1C9DC', 57 | email: 'sebastien@requiem.fr', 58 | name: 'Sebastien Requiem', 59 | revoked: false, 60 | expired: false, 61 | disabled: false, 62 | invalid: false, 63 | can_encrypt: true, 64 | secret: false } 65 | ``` 66 | 67 | ## Ciphering a message ## 68 | You can cipher a message to *one* recipient at a time for the moment bu using the fingerprint of the key previously retrieved. 69 | 70 | ```js 71 | var fingerprint = '3B2302E57CC7AA3D8D4600E89DAC32BD82A1C9DC'; 72 | var message = "Can you read this ?"; 73 | var cipher = gpgme.cipher(fingerprint, message); 74 | ``` 75 | 76 | ``` 77 | -----BEGIN PGP MESSAGE----- 78 | Version: GnuPG v2 79 | 80 | hQEMA7xBZ+vX1VJHAQf/QpzEn8jwgWcuEgP/kF+NoihSOz5PDQbrf52EgykSajF4 81 | XipaoqnceMrZpwkWTF9yZGcvCyMAX0pgiKNlThHloHsLkTjjq3L6/KFWk0odpG+C 82 | UMer5X6yQsIjLsYGcWU2W8Qb6x4giX/v/yL4DGy6TYRb9tKf4r+0i2BD/1PrB2eN 83 | qXhz6RFmbZg4qWjozyg2CYo5Bz2HDmF/mciRnejP/THCGKKmbf45LAZsS37Y07d6 84 | cb35+YG0anwU/qZHDnrDsqlHTQ7+rdJui6KXobJpikAa873mziaqunDykl7Fve3l 85 | 26SzxiWhvgxk2+mhIW+syobFalLZCI40+ryAHvumhNJDATMw3MfGeZnBnRYZu+Ay 86 | 9EXXFCVn9A86Gli2B5gyYVk8kbAadfXAd8Vj+ysPw0in/HGoUH/NTDUp/C/SN4Nl 87 | L4KxYQ== 88 | =ACDC 89 | -----END PGP MESSAGE----- 90 | ``` 91 | 92 | 93 | 94 | ## Limitations 95 | So far, this module not respecting the nature of node when fetching keys or encrypting large payload. If you have 1000 keys in your keyring, except things to block long enough to be noticed. Same goes for large messages to cipher. 96 | 97 | As this is a very early release coded in few days only, I tried my best to deallocate memory blocks when possible but expect this module to leak for now. 98 | 99 | 100 | ## TODO 101 | 1. Use libuv for asynchronous keyfetching 102 | 2. Use libuv for asynchronous ciphering 103 | 3. Unit tests should be written both in JS and C++ 104 | 4. Use key pattern for key a faster key retrieving 105 | 106 | 107 | 108 | ## Changelog 109 | v0.0.6 110 | ------ 111 | * Fix an issue with a non inistialized memory allocated buffer for 112 | encrypted payloads 113 | 114 | v0.0.5 115 | ------ 116 | * Add travis-ci integration 117 | * Change the attribute GpgMeContext to exports object (sorry folks) 118 | 119 | v0.0.4 120 | ------ 121 | * Fix #1 122 | * First version tracked by changelog 123 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "gpgme", 5 | "sources": [ "src/addon.cc", 6 | "src/context.cc", 7 | ], 8 | "include_dirs": [ 9 | "", 3 | "contributors": [ 4 | { 5 | "name": "Gabriel Pedro", 6 | "email": "contato@gpedro.net" 7 | } 8 | ], 9 | "name": "node-gpgme", 10 | "description": "GpgMe bindings", 11 | "version": "0.0.6", 12 | "gypfile": true, 13 | "main": "index.js", 14 | "scripts": { 15 | "test": "tape tests/*.js" 16 | }, 17 | "keywords": [ 18 | "node-gyp", 19 | "gpg", 20 | "gpgme" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "git@github.com:kiddouk/node-gpgme.git" 25 | }, 26 | "engines": { 27 | "node": ">= 0.10.0" 28 | }, 29 | "dependencies": { 30 | "bindings": "^1.2.1", 31 | "nan": "^2.3.5" 32 | }, 33 | "license": "MIT", 34 | "bugs": { 35 | "url": "https://github.com/kiddouk/node-gpgme/issues" 36 | }, 37 | "homepage": "https://github.com/kiddouk/node-gpgme", 38 | "devDependencies": { 39 | "tape": "^4.2.0" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/addon.cc: -------------------------------------------------------------------------------- 1 | // addon.cc 2 | #include 3 | #include "context.h" 4 | 5 | using namespace v8; 6 | 7 | NODE_MODULE(target, ContextWrapper::Init); 8 | -------------------------------------------------------------------------------- /src/context.cc: -------------------------------------------------------------------------------- 1 | #include /* locale support */ 2 | #include "context.h" 3 | #include 4 | using namespace v8; 5 | 6 | Nan::Persistent ContextWrapper::constructor; 7 | 8 | ContextWrapper::ContextWrapper(Local conf) : _context(NULL) { 9 | 10 | /* Fetch the configuration options or use defaults */ 11 | /* TODO: Should be refactored to a more usable multitype HashMap */ 12 | Local key = Nan::New("armored").ToLocalChecked(); 13 | bool armored = true; 14 | if (conf->Has(key) && conf->Get(key)->IsBoolean()) { 15 | armored = Nan::To(conf->Get(key)).ToLocalChecked()->Value(); 16 | } 17 | 18 | key = Nan::New("keyring_path").ToLocalChecked(); 19 | Local keyring_path; 20 | if (conf->Has(key) && conf->Get(key)->IsString()) { 21 | keyring_path = Nan::To(conf->Get(key)).ToLocalChecked(); 22 | } else { 23 | // TODO: Find the real TMP Directory for the plateform 24 | keyring_path = Nan::New("/tmp").ToLocalChecked(); 25 | } 26 | 27 | /* The function `gpgme_check_version' must be called before any other 28 | * function in the library, because it initializes the thread support 29 | * subsystem in GPGME. (from the info page) */ 30 | gpg_error_t err; 31 | gpgme_engine_info_t enginfo; 32 | 33 | setlocale (LC_ALL, ""); 34 | gpgme_check_version(NULL); 35 | /* set locale, because tests do also */ 36 | gpgme_set_locale(NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); 37 | 38 | /* check for OpenPGP support */ 39 | err = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); 40 | if(err != GPG_ERR_NO_ERROR) { 41 | Nan::ThrowError("OpenGPG is not supported on your plateform."); 42 | return; 43 | } 44 | 45 | /* get engine information */ 46 | err = gpgme_get_engine_info(&enginfo); 47 | if(err != GPG_ERR_NO_ERROR) { 48 | Nan::ThrowError("Cannot get the engine information"); 49 | return; 50 | } 51 | 52 | /* create our own context */ 53 | err = gpgme_new(&_context); 54 | if(err != GPG_ERR_NO_ERROR) { 55 | Nan::ThrowError("Cannot create gpgme context object"); 56 | return; 57 | } 58 | 59 | /* set protocol to use in our context */ 60 | err = gpgme_set_protocol(_context, GPGME_PROTOCOL_OpenPGP); 61 | if(err != GPG_ERR_NO_ERROR) { 62 | Nan::ThrowError("Cannot set protocol to OpenPGP"); 63 | return; 64 | } 65 | 66 | /* Allocated memory to get the value of the path option */ 67 | 68 | char *keyring_path_buffer = StringToCharPointer(keyring_path); 69 | 70 | err = gpgme_ctx_set_engine_info (_context, GPGME_PROTOCOL_OpenPGP, 71 | enginfo->file_name, 72 | keyring_path_buffer); 73 | free(keyring_path_buffer); 74 | if (err != GPG_ERR_NO_ERROR) { 75 | Nan::ThrowError("Cannot set engine options, are you sure about the path for the keyring ?"); 76 | return; 77 | } 78 | gpgme_set_armor(_context, armored); 79 | } 80 | 81 | ContextWrapper::~ContextWrapper() { 82 | if (_context != NULL) { 83 | gpgme_release(_context); 84 | } 85 | } 86 | 87 | 88 | NAN_MODULE_INIT(ContextWrapper::Init) { 89 | Local tpl = Nan::New(New); 90 | tpl->SetClassName(Nan::New("GpgMeContext").ToLocalChecked()); 91 | tpl->InstanceTemplate()->SetInternalFieldCount(1); 92 | 93 | SetPrototypeMethod(tpl, "toString", toString); 94 | SetPrototypeMethod(tpl, "importKey", importKey); 95 | SetPrototypeMethod(tpl, "listKeys", listKeys); 96 | SetPrototypeMethod(tpl, "cipher", cipher); 97 | 98 | constructor.Reset(tpl->GetFunction()); 99 | Nan::Set(target, Nan::New("GpgMeContext").ToLocalChecked(), tpl->GetFunction()); 100 | 101 | } 102 | 103 | NAN_METHOD(ContextWrapper::New) { 104 | if (info.IsConstructCall()) { 105 | Local configuration; 106 | // Invoked as constructor: `new MyObject(...)` 107 | if (info.Length() >= 1 && info[0]->IsObject()) { 108 | configuration = Nan::To(info[0]).ToLocalChecked(); 109 | } else { 110 | configuration = Nan::New(); 111 | } 112 | 113 | ContextWrapper *contextWrapper = new ContextWrapper(configuration); 114 | 115 | contextWrapper->Wrap(info.This()); 116 | info.GetReturnValue().Set(info.This()); 117 | } else { 118 | const int argc = 0; 119 | Local cons = Nan::New(constructor); 120 | info.GetReturnValue().Set(cons->NewInstance(argc, NULL)); 121 | } 122 | } 123 | 124 | 125 | NAN_METHOD(ContextWrapper::toString) { 126 | ContextWrapper* context = ObjectWrap::Unwrap(info.This()); 127 | 128 | char *version = context->getVersion(); 129 | if (version == NULL) return; 130 | 131 | info.GetReturnValue().Set(Nan::New(version).ToLocalChecked()); 132 | } 133 | 134 | NAN_METHOD(ContextWrapper::importKey) { 135 | ContextWrapper* context = ObjectWrap::Unwrap(info.This()); 136 | if (info.Length() != 1) Nan::ThrowError("Missing key argument"); 137 | if (!info[0]->IsString()) Nan::ThrowError("Arg1 should be a string"); 138 | 139 | std::string fingerprint; 140 | Local key = Nan::To(info[0]).ToLocalChecked(); 141 | 142 | char *key_buffer = context->StringToCharPointer(key); 143 | bool res = context->addKey(key_buffer, key->Length(), fingerprint); 144 | free(key_buffer); 145 | if (res == false) { 146 | info.GetReturnValue().Set(false); 147 | return; 148 | } 149 | 150 | info.GetReturnValue().Set(Nan::New(fingerprint).ToLocalChecked()); 151 | } 152 | 153 | 154 | NAN_METHOD(ContextWrapper::cipher) { 155 | ContextWrapper* context = ObjectWrap::Unwrap(info.This()); 156 | //arg0 should be the finger print of the key to use 157 | //arg1 should be the payload to cipher 158 | 159 | if (info.Length() != 2) Nan::ThrowError("Missing argument (fingerprint, message)"); 160 | if (!info[0]->IsString()) Nan::ThrowError("fingerprint should be a string"); 161 | if (!info[1]->IsString()) Nan::ThrowError("message should be a string"); 162 | 163 | Local fingerprint = Nan::To(info[0]).ToLocalChecked(); 164 | Local message = Nan::To(info[1]).ToLocalChecked(); 165 | 166 | char *data = context->cipherPayload(fingerprint, message); 167 | if (data == NULL) { 168 | info.GetReturnValue().Set(false); 169 | return; 170 | } 171 | 172 | info.GetReturnValue().Set(Nan::New(data).ToLocalChecked()); 173 | gpgme_free(data); 174 | } 175 | 176 | 177 | 178 | NAN_METHOD(ContextWrapper::listKeys) { 179 | ContextWrapper* context = ObjectWrap::Unwrap(info.This()); 180 | 181 | std::list keys; 182 | bool res = context->getKeys(&keys); 183 | 184 | if (res == false) { 185 | Nan::ThrowError("Internal error when retrieving the keys"); 186 | return; 187 | } 188 | 189 | Local v8Keys= Nan::New(); 190 | std::list::const_iterator iterator; 191 | int i; 192 | for (i = 0, iterator = keys.begin(); iterator != keys.end(); ++iterator, ++i) { 193 | Local v8Key = Nan::New(); 194 | 195 | if ((*iterator)->subkeys->fpr) { 196 | v8Key->Set(Nan::New("fingerprint").ToLocalChecked(), Nan::New( (*iterator)->subkeys->fpr).ToLocalChecked()); 197 | } 198 | 199 | if ((*iterator)->uids->email) { 200 | v8Key->Set(Nan::New("email").ToLocalChecked(), Nan::New( (*iterator)->uids->email).ToLocalChecked()); 201 | } 202 | 203 | if ((*iterator)->uids->name) { 204 | v8Key->Set(Nan::New("name").ToLocalChecked(), Nan::New( (*iterator)->uids->name).ToLocalChecked()); 205 | } 206 | 207 | v8Key->Set(Nan::New("revoked").ToLocalChecked(), (*iterator)->revoked ? Nan::True() : Nan::False()); 208 | 209 | v8Key->Set(Nan::New("expired").ToLocalChecked(), (*iterator)->revoked ? Nan::True() : Nan::False()); 210 | 211 | v8Key->Set(Nan::New("disabled").ToLocalChecked(), (*iterator)->disabled ? Nan::True() : Nan::False()); 212 | 213 | v8Key->Set(Nan::New("invalid").ToLocalChecked(), (*iterator)->invalid ? Nan::True() : Nan::False()); 214 | 215 | v8Key->Set(Nan::New("can_encrypt").ToLocalChecked(), (*iterator)->can_encrypt ? Nan::True() : Nan::False()); 216 | v8Keys->Set(i, v8Key); 217 | 218 | v8Key->Set(Nan::New("secret").ToLocalChecked(), (*iterator)->secret ? Nan::True() : Nan::False()); 219 | 220 | v8Keys->Set(i, v8Key); 221 | gpgme_key_unref((*iterator)); 222 | } 223 | 224 | info.GetReturnValue().Set(v8Keys); 225 | } 226 | 227 | char* ContextWrapper::getVersion() { 228 | gpgme_error_t err; 229 | gpgme_engine_info_t enginfo; 230 | 231 | err = gpgme_get_engine_info(&enginfo); 232 | if(err != GPG_ERR_NO_ERROR) return NULL; 233 | 234 | return enginfo->version; 235 | } 236 | 237 | 238 | bool ContextWrapper::addKey(char *key, int length, std::string& fingerprint) { 239 | gpgme_data_t gpgme_key_data; 240 | gpgme_error_t err; 241 | 242 | gpgme_data_new(&gpgme_key_data); 243 | 244 | err = gpgme_data_new_from_mem(&gpgme_key_data, key, length, 1); 245 | if (err != GPG_ERR_NO_ERROR) return false; 246 | 247 | err = gpgme_op_import(_context, gpgme_key_data); 248 | if(err != GPG_ERR_NO_ERROR) return false; 249 | 250 | gpgme_import_result_t result = gpgme_op_import_result(_context); 251 | 252 | if (result->considered != 1) return false; 253 | 254 | fingerprint.assign(result->imports->fpr); 255 | return true; 256 | } 257 | 258 | 259 | bool ContextWrapper::getKeys(std::list *keys) { 260 | gpgme_error_t err; 261 | gpgme_key_t key = NULL; 262 | 263 | /* List all keys, no pattern, not only secret keys */ 264 | err = gpgme_op_keylist_start(_context, NULL, 0); 265 | if (err != GPG_ERR_NO_ERROR) return false; 266 | 267 | do { 268 | err = gpgme_op_keylist_next(_context, &key); 269 | if (err) break; 270 | keys->insert(keys->end(), key); 271 | } while (err == GPG_ERR_NO_ERROR); 272 | if (gpg_err_code (err) != GPG_ERR_EOF) { 273 | std::cout << "FAIL\n"; 274 | // TODO: release objects 275 | return false; 276 | } 277 | return true; 278 | } 279 | 280 | char *ContextWrapper::cipherPayload(Local fpr, Local msg) { 281 | 282 | gpgme_error_t err; 283 | gpgme_key_t recp[2] = { NULL, NULL }; 284 | char *fingerprint = StringToCharPointer(fpr); 285 | char *message = StringToCharPointer(msg); 286 | 287 | err = gpgme_get_key(_context, fingerprint, &recp[0], 0); 288 | if(err != GPG_ERR_NO_ERROR) { 289 | free(fingerprint); 290 | free(message); 291 | return NULL; 292 | } 293 | 294 | gpgme_data_t message_data; 295 | err = gpgme_data_new_from_mem(&message_data, message, msg->Length(), 0); 296 | if(err != GPG_ERR_NO_ERROR) { 297 | free(fingerprint); 298 | free(message); 299 | return NULL; 300 | } 301 | 302 | gpgme_data_t cipher; 303 | gpgme_data_new(&cipher); 304 | err = gpgme_op_encrypt(_context, recp, GPGME_ENCRYPT_ALWAYS_TRUST, message_data, cipher); 305 | free(fingerprint); 306 | free(message); 307 | 308 | if (err != GPG_ERR_NO_ERROR) { 309 | gpgme_data_release(cipher); 310 | return NULL; 311 | } 312 | 313 | gpgme_encrypt_result_t res = gpgme_op_encrypt_result(_context); 314 | if (res->invalid_recipients != NULL) { 315 | gpgme_data_release(cipher); 316 | return NULL; 317 | }; 318 | 319 | size_t nread; 320 | char *data = gpgme_data_release_and_get_mem(cipher, &nread); 321 | char *encrypted_message = (char *) malloc((nread + 1) * sizeof(char)); 322 | memset(encrypted_message, 0, nread); 323 | memcpy(encrypted_message, data, nread); 324 | gpgme_free(data); 325 | return encrypted_message; 326 | } 327 | 328 | 329 | char *ContextWrapper::StringToCharPointer(Local str) { 330 | 331 | int nbytesWritten; 332 | char *buffer; 333 | int size = str->Utf8Length() + 1; 334 | buffer = (char *) malloc((size) * sizeof(char)); 335 | if (buffer == NULL) { 336 | Nan::ThrowError("Memory allocation failed"); 337 | return NULL; 338 | } 339 | 340 | str->WriteUtf8(buffer, size, &nbytesWritten, 0); 341 | //TODO : Ensure that all bytes have been copied properly 342 | 343 | return buffer; 344 | } 345 | -------------------------------------------------------------------------------- /src/context.h: -------------------------------------------------------------------------------- 1 | #ifndef GPGMECONTEXT_H 2 | #define GPGMECONTEXT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | using namespace Nan; 13 | 14 | class ContextWrapper : public ObjectWrap { 15 | 16 | private: 17 | gpgme_ctx_t _context; 18 | 19 | explicit ContextWrapper(v8::Local conf); 20 | ~ContextWrapper(); 21 | 22 | char* getVersion(); 23 | bool addKey(char *key, int length, std::string& fingerprint); 24 | bool getKeys(std::list *keys); 25 | char *cipherPayload(v8::Local fpr, v8::Local msg); 26 | char *StringToCharPointer(v8::Local str); 27 | 28 | static NAN_METHOD(New); 29 | static NAN_METHOD(toString); 30 | static NAN_METHOD(importKey); 31 | static NAN_METHOD(listKeys); 32 | static NAN_METHOD(cipher); 33 | 34 | public: 35 | static Persistent constructor; 36 | 37 | static NAN_MODULE_INIT(Init); 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /tests/context.js: -------------------------------------------------------------------------------- 1 | var test = require('tape'); 2 | var GpgMe = require('..'); 3 | 4 | test('import_keys', function (t) { 5 | t.plan(2); 6 | 7 | var ascii_key = '-----BEGIN PGP PUBLIC KEY BLOCK-----\n\ 8 | Version: GnuPG v1\n\ 9 | \n\ 10 | mQENBFKY4I8BCAC4iNRHrSovmkw12T7YV0l86E1E7TeuFC6zlv3o4+e1Yb9KlYW/\n\ 11 | +TZ6VTVOB4zmey/459MRnj2dRv/CWrAdAMEq1Btt08+enIbSmXcYsQkusI5EO/UJ\n\ 12 | 7O3uhO7UCHfQqGWi3VyfI2PSCnJoNoiRQreAiRWi0Ooh/ZuK9jfw4u0Oy8+Wp76U\n\ 13 | j1uSp8a27p2Q0jtzFh7NrmK3y89dDwVmmLlUg3YAzOY4xW1NJaDwEoh1HSfpQTsa\n\ 14 | I8yaqgH3BlrsLyZmn9Jg7Qxwe8aWclLVDxjtgIDttgmzYNtWBB4NXg51iM4PS5ZZ\n\ 15 | I19yv7Lg5hbdDWKAPyePH3PNCfdSyYyPh53BABEBAAG0Q1NlYmFzdGllbiBSZXF1\n\ 16 | aWVtIChTZWJhc3RpZW4ncyBvZmZpY2lhbCBrZXkpIDxzZWJhc3RpZW5AcmVxdWll\n\ 17 | bS5mcj6JATgEEwECACIFAlKY4I8CGwMGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheA\n\ 18 | AAoJEJ2sMr2CocnclAsH/iwkhfGArMse12H2IyVlXsxNxyInEFon5BWIOsxpY3/O\n\ 19 | J5J1NdosT7k+A4OJFgSihV1G4Hil03FRyCu4GLdbPg5afba2+GU3OIiU2WkiISjf\n\ 20 | 7Sku0QxTprIB13NOCa1/3NFV9bOBUwXY8lhh9YlPFT8xWwSrC3fTo44+0Kqz6tLe\n\ 21 | 5vhobT4LehThIPzZsYEOburUQ0ej6O4dvzqrqD6A731fs+zQUdBcu5FKHlc7TSzG\n\ 22 | m+pl1MCboW5mnJnw+qzz0b76xjXK4keDhkMjBOv6pYcJWRddwUVpqKivU5aX6szd\n\ 23 | EJSv/OsCFmREmzlK4GYnNfg3Nz4NeIkR2phZr17JFwu5AQ0EUpjgjwEIAOqBm1RA\n\ 24 | a6638Rex90ldrpvXLIZqYt0BBgLU5TKMxKK/dpjYVDvyG8i6hFJmnmqnlafoui1q\n\ 25 | katWNhoh/3QNZZXeSRewDUSz2Uw5loycIGl0Fhk6anlnnVCOuL4Lh7PIy0MdvfVb\n\ 26 | daF/rTdyMo3rjVmTWC9Tl/WUQdEYECwvCJq0XDNNO5LHFvF/4YWUm79ix4TK9W97\n\ 27 | 2GjCPG06rh1ygFvJqYwbJtZn2lcHYc8Kt4BAKKewzQcdSjldK/wGs0nGB0vPp0xD\n\ 28 | OFzJvNeeayXAUAEGOJN/dyMiu4UxPQPRsRaoqfP8HoeB9/FtHKlLaXROlzsP+cxW\n\ 29 | rKEuDx5HSbo7JScAEQEAAYkBHwQYAQIACQUCUpjgjwIbDAAKCRCdrDK9gqHJ3L7K\n\ 30 | B/91rZbbSl1DpvT1LsbK/RiCsxeE2mrqUS9eV60y7hWuwBLUC+kFdY7O53TStSjH\n\ 31 | xn2Fm6/SAu4hkWNHRDejaiqWaipfUt0C9SnPhoiYscfkbEMwAYJOs/19ZCgvcwuF\n\ 32 | A9iO1zl9apMomkE1CXjk0wxEsrwwvgXkYqj8BhQq74KZIJkZisHA1jUVo5uKqs2p\n\ 33 | +nYEpBBsna3jWIMo0t0nS7yShOXTPzz/numy6HwBkZMfS7JyKJUT8s363FyJ9DSB\n\ 34 | hRdoZcvrkhSh5RKiADM8RfW04UEkb/tDHSuvkH7HrgdIzd/WQwDsZHnIjNMQAEMl\n\ 35 | oezv1L1SiuNonPtwiYcbphGo\n\ 36 | =2bdq\n\ 37 | -----END PGP PUBLIC KEY BLOCK-----', 38 | 39 | fingerprint = '3B2302E57CC7AA3D8D4600E89DAC32BD82A1C9DC', 40 | import_fingerprint, 41 | gpgme; 42 | 43 | gpgme = new GpgMe(); 44 | import_fingerprint = gpgme.importKey(ascii_key); 45 | t.equal(fingerprint, import_fingerprint); 46 | 47 | ascii_key = 'This is not a key'; 48 | import_fingerprint = gpgme.importKey(ascii_key); 49 | t.equal(false, import_fingerprint); 50 | 51 | }); 52 | 53 | test('list_keys', function (t) { 54 | t.plan(2); 55 | 56 | var keys, 57 | gpgme, 58 | fingerprint = '3B2302E57CC7AA3D8D4600E89DAC32BD82A1C9DC', 59 | email = 'sebastien@requiem.fr'; 60 | 61 | gpgme = new GpgMe(); 62 | keys = gpgme.listKeys(); 63 | 64 | t.equal(fingerprint, keys[0].fingerprint); 65 | t.equal(email, keys[0].email); 66 | }); 67 | 68 | test('cipher', function (t) { 69 | t.plan(2); 70 | 71 | var gpgme, 72 | fingerprint = '3B2302E57CC7AA3D8D4600E89DAC32BD82A1C9DC', 73 | payload = 'Can you read this ?', 74 | needle = '-----BEGIN PGP MESSAGE-----', 75 | cipher; 76 | 77 | gpgme = new GpgMe(); 78 | 79 | cipher = gpgme.cipher(fingerprint, payload); 80 | t.equal(0, cipher.indexOf(needle)); 81 | 82 | 83 | cipher = gpgme.cipher('unknown-fingerprint', payload); 84 | t.equal(false, cipher); 85 | }); 86 | --------------------------------------------------------------------------------