| 1 | # Copyright © 2021-2022 Guillem Jover <guillem@debian.org> | ||||||||||||||||||||
| 2 | # | ||||||||||||||||||||
| 3 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 4 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||
| 5 | # the Free Software Foundation; either version 2 of the License, or | ||||||||||||||||||||
| 6 | # (at your option) any later version. | ||||||||||||||||||||
| 7 | # | ||||||||||||||||||||
| 8 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||
| 11 | # GNU General Public License for more details. | ||||||||||||||||||||
| 12 | # | ||||||||||||||||||||
| 13 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||
| 14 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =encoding utf8 | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | Dpkg::OpenPGP::Backend::SOP - OpenPGP backend for SOP | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | This module provides a class that implements the OpenPGP backend | ||||||||||||||||||||
| 25 | for the Stateless OpenPGP Command-Line Interface, as described in | ||||||||||||||||||||
| 26 | L<https://datatracker.ietf.org/doc/draft-dkg-openpgp-stateless-cli/>. | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | B<Note>: This is a private module, its API can change at any time. | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | package Dpkg::OpenPGP::Backend::SOP 0.01; | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 6 | ▶ | use v5.36; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 6 | ▶ | use POSIX qw(:sys_wait_h); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 6 | ▶ | use Dpkg::ErrorHandling; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | 6 | ▶ | use Dpkg::IPC; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 40 | 6 | ▶ | use Dpkg::OpenPGP::ErrorCodes; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 6 | ▶ | use parent qw(Dpkg::OpenPGP::Backend); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | # - Once the SOP MR !23 is finalized and merged, implement a way to select | ||||||||||||||||||||
| 45 | # whether the SOP instance supports the expected draft. | ||||||||||||||||||||
| 46 | # Ref: https://gitlab.com/dkg/openpgp-stateless-cli/-/merge_requests/23 | ||||||||||||||||||||
| 47 | # - Once the SOP issue #42 is resolved we can perhaps remove the alternative | ||||||||||||||||||||
| 48 | # dependencies and commands to check? | ||||||||||||||||||||
| 49 | # Ref: https://gitlab.com/dkg/openpgp-stateless-cli/-/issues/42 | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 7 | ▶ | sub DEFAULT_CMDV { | ||||||||||||||||||
|
Subroutine
DEFAULT_CMDV: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 52 | 7 | return [ qw(sqopv rsopv sopv) ]; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 6 | ▶ | sub DEFAULT_CMD { | ||||||||||||||||||
|
Subroutine
DEFAULT_CMD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 56 | 6 | return [ qw(sqop rsop gosop hop pgpainless-cli) ]; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | sub _sop_exec | ||||||||||||||||||||
| 60 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_sop_exec: not called CC=7 SCAR=40.3
| |||||||||||||||||||||
| 61 | 0 | my ($self, %sop) = @_; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | my $cmd; | |||||||||||||||||||
| 64 | 0 | ▶ | if ($sop{verify}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 0 | ▶ | $cmd = $self->{cmdv} || $self->{cmd}; | ||||||||||||||||||
|
Condition0%0/3
$self->{'cmdv'} || $self->{'cmd'}
MC/DC0%0/2
$self->{'cmdv'} || $self->{'cmd'}
$self->{'cmdv'}
$self->{'cmd'}
Truth table0%0/3
A || B
A= $self->{'cmdv'}B= $self->{'cmd'}
| |||||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||
| 67 | 0 | $cmd = $self->{cmd}; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | ▶ | return OPENPGP_MISSING_CMD unless $cmd; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | ▶ | $sop{out} //= '/dev/null'; | ||||||||||||||||||
|
Condition0%0/2
$sop{"out"} //= "/dev/null"
MC/DC0%0/1
$sop{"out"} //= "/dev/null"
$sop{"out"}
Truth table0%0/2
A
A= $sop{"out"}
| |||||||||||||||||||||
| 73 | 0 | my $stderr; | |||||||||||||||||||
| 74 | spawn( | ||||||||||||||||||||
| 75 | 0 | exec => [ $cmd, @{$sop{args}} ], | |||||||||||||||||||
| 76 | wait_child => 1, | ||||||||||||||||||||
| 77 | no_check => 1, | ||||||||||||||||||||
| 78 | timeout => 10, | ||||||||||||||||||||
| 79 | from_file => $sop{in}, | ||||||||||||||||||||
| 80 | to_file => $sop{out}, | ||||||||||||||||||||
| 81 | 0 | error_to_string => \$stderr, | |||||||||||||||||||
| 82 | ); | ||||||||||||||||||||
| 83 | 0 | ▶ | if (WIFEXITED($?)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 0 | my $status = WEXITSTATUS($?); | |||||||||||||||||||
| 85 | 0 | ▶ | print { *STDERR } "$stderr" if $status; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 86 | 0 | return $status; | |||||||||||||||||||
| 87 | } else { | ||||||||||||||||||||
| 88 | 0 | subprocerr("$cmd @{$sop{args}}"); | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | # XXX: We cannot use the SOP armor/dearmor interfaces, because concatenated | ||||||||||||||||||||
| 93 | # ASCII Armor is not a well supported construct, and not all SOP | ||||||||||||||||||||
| 94 | # implementations support. But we still need to handle this given the | ||||||||||||||||||||
| 95 | # data we are managing. Remove these implementations for now and use | ||||||||||||||||||||
| 96 | # the generic parent implementations. Once we can guarantee that our | ||||||||||||||||||||
| 97 | # data has been sanitized, then we could switch back to use pure SOP | ||||||||||||||||||||
| 98 | # interfaces. | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | sub inline_verify | ||||||||||||||||||||
| 101 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
inline_verify: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 102 | 0 | my ($self, $inlinesigned, $data, @certs) = @_; | |||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 0 | ▶ | return OPENPGP_MISSING_KEYRINGS if @certs == 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | return $self->_sop_exec( | |||||||||||||||||||
| 107 | args => [ 'inline-verify', @certs ], | ||||||||||||||||||||
| 108 | verify => 1, | ||||||||||||||||||||
| 109 | in => $inlinesigned, | ||||||||||||||||||||
| 110 | out => $data, | ||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | sub verify | ||||||||||||||||||||
| 115 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
verify: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 116 | 0 | my ($self, $data, $sig, @certs) = @_; | |||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 0 | ▶ | return OPENPGP_MISSING_KEYRINGS if @certs == 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | return $self->_sop_exec( | |||||||||||||||||||
| 121 | args => [ 'verify', $sig, @certs ], | ||||||||||||||||||||
| 122 | verify => 1, | ||||||||||||||||||||
| 123 | in => $data, | ||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | sub inline_sign | ||||||||||||||||||||
| 128 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
inline_sign: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 129 | 0 | my ($self, $data, $inlinesigned, $key) = @_; | |||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 0 | ▶ | return OPENPGP_NEEDS_KEYSTORE if $key->needs_keystore(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 0 | return $self->_sop_exec( | |||||||||||||||||||
| 134 | args => [ qw(inline-sign --as clearsigned --), $key->handle ], | ||||||||||||||||||||
| 135 | in => $data, | ||||||||||||||||||||
| 136 | out => $inlinesigned, | ||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | =head1 CHANGES | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =head2 Version 0.xx | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | This is a private module. | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 6 | 1; | |||||||||||||||||||