Как расшифровать зашифрованный файл GPG в облаке, не сохраняя закрытый ключ в облаке, используя node.js
Переход от onPrem к облаку Azure. В настоящее время для сервера установлено хранилище onPrem GPG, в хранилище GPG импортированы открытые / закрытые ключи, для расшифровки файлов в коде расшифровки используется отпечаток пальца, но это означает, что закрытый ключ физически присутствует на сервере. С переходом в облако команда безопасности не хочет хранить закрытый ключ на облачных PODS.
В дальнейшем содержимое файла закрытого ключа будет доступно через вызов API.
Попытка расшифровки зашифрованного файла путем передачи объекта ответа API закрытого ключа в качестве «получателя» и «ключа» в качестве аргументов в cryptoReader.js, который использует модули crpto, gpg для выполнения расшифровки. Неудачно.
Если я пытаюсь использовать тот же код на компьютере, на котором закрытый ключ импортируется в хранилище GPG, он работает.
Означает ли это, что закрытый ключ должен быть физически импортирован в хранилище GPG на сервере, где будет выполняться расшифровка?
Как другие компании, чувствительные к безопасности, реализуют это в облаке?
//KeyBuffer contains contents of private key .asc file as response from API call
Decryption call:
stream.decryptFilewithPGP(<encryptedFileName>, { skipEmptyLines: true, encoding: 'utf8' },
{
mode: 'PGP',
// key: keyBuffer,
recipient: keyBuffer,
passphrase: config.asymmetric.passphrase
// fingerprint: config.asymmetric.fingerprint //for onPrem, for cloud no fingerprint
});
Actual decryption implementation:
CryptoReader.prototype.decryptFilewithPGP = function (filepath, options, cipher) {
var self = this;
this._filepath = path.normalize(filepath);
this._encoding = options && options.encoding || 'utf8';
this._skipEmptyLines = options && options.skipEmptyLines || false;
this._streamOptions = { encoding: this._encoding };
if (options && options.start) {
this._streamOptions.start = options.start;
}
if (options && options.end) {
this._streamOptions.end = options.end;
}
let args = [
'--passphrase', self.decode(cipher.passphrase),
//'--recipient', cipher.key,
'--recipient', cipher.recipient,
'--trust-model', 'always',
'--decrypt'
];
console.log(`args: ${JSON.stringify(args)}`);
readStream = this._readStream ? this._readStream : fs.createReadStream(this._filepath);
outStream = this._outStream ? this._outStream : new Stream.PassThrough;
//var outStream = new Stream.PassThrough;
gpg.callStreaming(readStream, outStream, args, function (err) {
if (err) {
self.emit('error', err);
}
else {
var _decData='', lastLine;
outStream.on('data', function (data) {
self._readStream.pause();
self._outStream.pause();
let _data = self._lineFragment.concat(data.toString('utf8'));
self._lines = self._lines.concat(_data.split(/(?:\n|\r\n|\r)/g));
self._lineFragment = self._lines.pop() || ''; //hold last line
//console.log('data chunk size: ' + data.length + ' no. or rows: ' + self._lines.length);
setImmediate(function () {
self._nextLine();
});
});
outStream.on('end', function () {
self._end = true;
setImmediate(function () {
self._nextLine();
});
});
outStream.on('error', function (error) {
self.emit('error', err);
});
}
});
this._readStream = readStream;
this._outStream = outStream;
};
Ожидается: должен расшифровать зашифрованный файл и вернуть открытый текст (как это происходит на сервере onPrem или на компьютере DEV, на котором импортирован закрытый ключ)
Фактически: расшифровка не выполняется.