Thomas Hochstein wrote:
>So würde ich das machen.
Ich habe mal beide Codes gemischt, es scheinen jetzt sha256 + sha1
cancel-locks geschrieben zu werden. Hässlich, ich weiss. Irgendwie mochte
er hmac_sha1_base64 nicht, obwohl es die lt. Beschreibung von
Digest::SHA.pm geben soll.
Kann man erfolgreiche Cancel auf Fremdservern irgendwie testen?
filter_nnrpd.pl:
#
# Do any initialization steps.
#
use Digest::SHA qw( sha256_base64 hmac_sha256_base64 sha1 );
use Digest::HMAC_SHA1();
use MIME::Base64();
$CANCEL_LOCK = 'secretword';
#
# Filter
#
sub filter_post {
my $rval = "" ; # assume we'll accept.
$modify_headers = 1;
# Cancel-Lock / Cancel-Key
add_cancel_lock(\%hdr, $user);
if (exists( $hdr{"Control"} ) && $hdr{"Control"} =~ m/^cancel\s+(<[^>]+>)/i) {
my $key = calc_cancel_key_256($user, $1);
add_cancel_item(\%hdr, 'Cancel-Key', $key, 'sha256');
# #hitd
# uncomment next 2 lines if additional sha1 cancel-key should be sent
$key = calc_cancel_key_1($user, $1);
add_cancel_item(\%hdr, 'Cancel-Key', $key, 'sha1');
}
elsif (exists( $hdr{"Supersedes"} )) {
my $key = calc_cancel_key_256($user, $hdr{"Supersedes"});
add_cancel_item(\%hdr, 'Cancel-Key', $key, 'sha256');
# #hitd
# uncomment next 2 lines if additional sha1 cancel-key should be sent
$key = calc_cancel_key_1($user, $hdr{"Supersedes"});
add_cancel_item(\%hdr, 'Cancel-Key', $key, 'sha1');
}
return $rval;
}
#
# Cancel-Lock / Cancel-Key
#
sub add_cancel_item($$$$) {
my ( $r_hdr, $name, $value, $algo ) = @_;
my $prefix = $r_hdr->{$name};
$prefix = defined($prefix) ? $prefix . " $algo:" : "$algo:";
$r_hdr->{$name} = $prefix . $value;
}
sub calc_cancel_key_256($$) {
my ( $user, $message_id ) = @_;
return pad_b64digest(hmac_sha256_base64($message_id, $user . $CANCEL_LOCK));
}
sub calc_cancel_key_1($$) {
my ( $user, $message_id ) = @_;
return MIME::Base64::encode(Digest::HMAC_SHA1::hmac_sha1($message_id, $user . $CANCEL_LOCK), '');
#return pad_b64digest(hmac_sha1_base64($message_id, $user . $CANCEL_LOCK));
}
sub add_cancel_lock($$) {
my ( $r_hdr, $user ) = @_;
my $key = calc_cancel_key_256($user, $r_hdr->{'Message-ID'});
my $lock = pad_b64digest(sha256_base64($key));
add_cancel_item($r_hdr, 'Cancel-Lock', $lock, 'sha256');
# #hitd
# remove comment from next 3 lines, if additional sha1 cancel lock
# will be expected
$key = calc_cancel_key_1($user, $r_hdr->{'Message-ID'});
$lock = MIME::Base64::encode(Digest::SHA::sha1($key), '');
add_cancel_item($r_hdr, 'Cancel-Lock', $lock, 'sha1');
}
sub pad_b64digest($) {
my ($b64_digest) = @_;
while (length($b64_digest) % 4) {
$b64_digest .= '=';
}
return $b64_digest;
}