Try to solve gpg-preset-passphrase

This commit is contained in:
CrazyMax 2020-05-04 19:17:01 +02:00
parent cb88a0fce7
commit 2d5664ca5a
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
3 changed files with 58 additions and 21 deletions

36
dist/index.js generated vendored
View file

@ -1015,6 +1015,7 @@ const core = __importStar(__webpack_require__(470));
const gpg = __importStar(__webpack_require__(207)); const gpg = __importStar(__webpack_require__(207));
const openpgp = __importStar(__webpack_require__(781)); const openpgp = __importStar(__webpack_require__(781));
const stateHelper = __importStar(__webpack_require__(153)); const stateHelper = __importStar(__webpack_require__(153));
const exec = __importStar(__webpack_require__(986));
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
@ -1023,6 +1024,7 @@ function run() {
return; return;
} }
core.info('📣 GnuPG info'); core.info('📣 GnuPG info');
yield exec.exec('which', ['gpg']);
const version = yield gpg.getVersion(); const version = yield gpg.getVersion();
const dirs = yield gpg.getDirs(); const dirs = yield gpg.getDirs();
core.info(`Version : ${version.gnupg} (libgcrypt ${version.libgcrypt})`); core.info(`Version : ${version.gnupg} (libgcrypt ${version.libgcrypt})`);
@ -1114,6 +1116,24 @@ const exec = __importStar(__webpack_require__(807));
exports.agentConfig = `default-cache-ttl 7200 exports.agentConfig = `default-cache-ttl 7200
max-cache-ttl 31536000 max-cache-ttl 31536000
allow-preset-passphrase`; allow-preset-passphrase`;
const getGpgPresetPassphrasePath = () => __awaiter(void 0, void 0, void 0, function* () {
const { libexecdir: libexecdir } = yield exports.getDirs();
let gpgPresetPassphrasePath = path.join(libexecdir, 'gpg-preset-passphrase');
if (os.platform() == 'win32' && !gpgPresetPassphrasePath.includes(':')) {
gpgPresetPassphrasePath = path.join(process.env.HOMEDRIVE || '', libexecdir, 'gpg-preset-passphrase.exe');
}
return gpgPresetPassphrasePath;
});
const getGnupgHome = () => __awaiter(void 0, void 0, void 0, function* () {
if (process.env.GNUPGHOME) {
return process.env.GNUPGHOME;
}
let homedir = path.join(process.env.HOME || '', '.gnupg');
if (os.platform() == 'win32' && !process.env.HOME) {
homedir = path.join(process.env.USERPROFILE || '', '.gnupg');
}
return homedir;
});
exports.getVersion = () => __awaiter(void 0, void 0, void 0, function* () { exports.getVersion = () => __awaiter(void 0, void 0, void 0, function* () {
return yield exec.exec('gpg', ['--version'], true).then(res => { return yield exec.exec('gpg', ['--version'], true).then(res => {
if (res.stderr != '') { if (res.stderr != '') {
@ -1162,10 +1182,10 @@ exports.getDirs = () => __awaiter(void 0, void 0, void 0, function* () {
} }
} }
return { return {
libdir: path.normalize(libdir), libdir: libdir,
libexecdir: path.normalize(libexecdir), libexecdir: libexecdir,
datadir: path.normalize(datadir), datadir: datadir,
homedir: path.normalize(homedir) homedir: homedir
}; };
}); });
}); });
@ -1205,11 +1225,7 @@ exports.getKeygrip = (fingerprint) => __awaiter(void 0, void 0, void 0, function
}); });
}); });
exports.configureAgent = (config) => __awaiter(void 0, void 0, void 0, function* () { exports.configureAgent = (config) => __awaiter(void 0, void 0, void 0, function* () {
let homedir = path.join(process.env.HOME || '', '.gnupg'); const gpgAgentConf = path.join(yield getGnupgHome(), 'gpg-agent.conf');
if (os.platform() == 'win32') {
homedir = path.join(process.env.USERPROFILE || '', '.gnupg');
}
const gpgAgentConf = path.join(homedir, 'gpg-agent.conf');
yield fs.writeFile(gpgAgentConf, config, function (err) { yield fs.writeFile(gpgAgentConf, config, function (err) {
if (err) if (err)
throw err; throw err;
@ -1222,7 +1238,7 @@ exports.configureAgent = (config) => __awaiter(void 0, void 0, void 0, function*
}); });
exports.presetPassphrase = (keygrip, passphrase) => __awaiter(void 0, void 0, void 0, function* () { exports.presetPassphrase = (keygrip, passphrase) => __awaiter(void 0, void 0, void 0, function* () {
yield exec yield exec
.exec('gpg-preset-passphrase', ['--verbose', '--preset', '--passphrase', `"${passphrase}"`, keygrip], true) .exec(yield getGpgPresetPassphrasePath(), ['--verbose', '--preset', '--passphrase', `"${passphrase}"`, keygrip], true)
.then(res => { .then(res => {
if (res.stderr != '' && !res.success) { if (res.stderr != '' && !res.success) {
throw new Error(res.stderr); throw new Error(res.stderr);

View file

@ -19,6 +19,26 @@ export interface Dirs {
homedir: string; homedir: string;
} }
const getGpgPresetPassphrasePath = async (): Promise<string> => {
const {libexecdir: libexecdir} = await getDirs();
let gpgPresetPassphrasePath = path.join(libexecdir, 'gpg-preset-passphrase');
if (os.platform() == 'win32' && !gpgPresetPassphrasePath.includes(':')) {
gpgPresetPassphrasePath = path.join(process.env.HOMEDRIVE || '', libexecdir, 'gpg-preset-passphrase.exe');
}
return gpgPresetPassphrasePath;
};
const getGnupgHome = async (): Promise<string> => {
if (process.env.GNUPGHOME) {
return process.env.GNUPGHOME;
}
let homedir: string = path.join(process.env.HOME || '', '.gnupg');
if (os.platform() == 'win32' && !process.env.HOME) {
homedir = path.join(process.env.USERPROFILE || '', '.gnupg');
}
return homedir;
};
export const getVersion = async (): Promise<Version> => { export const getVersion = async (): Promise<Version> => {
return await exec.exec('gpg', ['--version'], true).then(res => { return await exec.exec('gpg', ['--version'], true).then(res => {
if (res.stderr != '') { if (res.stderr != '') {
@ -69,10 +89,10 @@ export const getDirs = async (): Promise<Dirs> => {
} }
return { return {
libdir: path.normalize(libdir), libdir: libdir,
libexecdir: path.normalize(libexecdir), libexecdir: libexecdir,
datadir: path.normalize(datadir), datadir: datadir,
homedir: path.normalize(homedir) homedir: homedir
}; };
}); });
}; };
@ -116,12 +136,7 @@ export const getKeygrip = async (fingerprint: string): Promise<string> => {
}; };
export const configureAgent = async (config: string): Promise<void> => { export const configureAgent = async (config: string): Promise<void> => {
let homedir: string = path.join(process.env.HOME || '', '.gnupg'); const gpgAgentConf = path.join(await getGnupgHome(), 'gpg-agent.conf');
if (os.platform() == 'win32') {
homedir = path.join(process.env.USERPROFILE || '', '.gnupg');
}
const gpgAgentConf = path.join(homedir, 'gpg-agent.conf');
await fs.writeFile(gpgAgentConf, config, function (err) { await fs.writeFile(gpgAgentConf, config, function (err) {
if (err) throw err; if (err) throw err;
}); });
@ -135,7 +150,11 @@ export const configureAgent = async (config: string): Promise<void> => {
export const presetPassphrase = async (keygrip: string, passphrase: string): Promise<string> => { export const presetPassphrase = async (keygrip: string, passphrase: string): Promise<string> => {
await exec await exec
.exec('gpg-preset-passphrase', ['--verbose', '--preset', '--passphrase', `"${passphrase}"`, keygrip], true) .exec(
await getGpgPresetPassphrasePath(),
['--verbose', '--preset', '--passphrase', `"${passphrase}"`, keygrip],
true
)
.then(res => { .then(res => {
if (res.stderr != '' && !res.success) { if (res.stderr != '' && !res.success) {
throw new Error(res.stderr); throw new Error(res.stderr);

View file

@ -2,6 +2,7 @@ import * as core from '@actions/core';
import * as gpg from './gpg'; import * as gpg from './gpg';
import * as openpgp from './openpgp'; import * as openpgp from './openpgp';
import * as stateHelper from './state-helper'; import * as stateHelper from './state-helper';
import * as exec from '@actions/exec';
async function run(): Promise<void> { async function run(): Promise<void> {
try { try {
@ -11,6 +12,7 @@ async function run(): Promise<void> {
} }
core.info('📣 GnuPG info'); core.info('📣 GnuPG info');
await exec.exec('which', ['gpg']);
const version = await gpg.getVersion(); const version = await gpg.getVersion();
const dirs = await gpg.getDirs(); const dirs = await gpg.getDirs();
core.info(`Version : ${version.gnupg} (libgcrypt ${version.libgcrypt})`); core.info(`Version : ${version.gnupg} (libgcrypt ${version.libgcrypt})`);