Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- #
- # pine-passfile-decode -- encode or decode a decrypted, obfuscated (al)pine
- # passfile
- #
- # The encode/decode routines are lifted verbatim from alpine/alpine/imap.c
- #
- # Since alpine-2.10(ish?) the passfile is encrypted with an x509 cert; use
- # openssl smime to encrypt/decrypt.
- #
- # Decrypt like so:
- # openssl smime -decrypt -inkey ~/.alpine-smime/.pwd/MasterPassword.key -in ~/.alpine.pwd -inform pem | pine-passfile-decode -m decrypt
- #
- # Encrypt like so:
- # pine-passfile-decode -m encrypt | openssl smime -decrypt -inkey .alpine-smime/.pwd/MasterPassword.key -in .alpine.pwd -inform pem
- #
- use strict;
- use Getopt::Std;
- our $FIRSTCH=32;
- our $LASTCH=126;
- our $TABSZ=($LASTCH - $FIRSTCH + 1);
- our $xlate_key=0;
- sub xlate_in($){
- my $c=ord($_[0]);
- my $eti;
- $eti = $xlate_key;
- if(($c >= $FIRSTCH) && ($c <= $LASTCH)){
- $eti += ($c - $FIRSTCH);
- $eti -= ($eti >= 2*$TABSZ) ? 2*$TABSZ : ($eti >= $TABSZ) ? $TABSZ : 0;
- return chr((($xlate_key = $eti) + $FIRSTCH));
- } else {
- return chr($c);
- }
- }
- sub xlate_out($){
- my $c=ord($_[0]);
- my $dti;
- my $xch;
- if(($c >= $FIRSTCH) && ($c <= $LASTCH)){
- $xch = $c - ($dti = $xlate_key);
- $xch += ($xch < $FIRSTCH-$TABSZ) ? 2*$TABSZ : ($xch < $FIRSTCH) ? $TABSZ : 0;
- $dti = ($xch - $FIRSTCH) + $dti;
- $dti -= ($dti >= 2*$TABSZ) ? 2*$TABSZ : ($dti >= $TABSZ) ? $TABSZ : 0;
- $xlate_key = $dti;
- return chr($xch);
- } else {
- return chr($c);
- }
- }
- my %opts;
- getopts("m:", \%opts);
- my $mode=$opts{"m"} || "decrypt";
- my $linenum=0;
- while (my $line=<>){
- $xlate_key=$linenum;
- $line =~ s/\r?\n$//;
- my @words=split(/\t/,$line);
- for (my $i=0;$i <= $#words; $i++){
- my $word=$words[$i];
- my @chars=split(//,$word);
- for my $c (@chars){
- if ($mode eq "decrypt"){
- print xlate_out($c);
- } elsif ($mode eq "encrypt"){
- print xlate_in($c);
- } else {
- warn "Bad mode: $mode\n";
- }
- }
- print "\t" unless ($i == $#words);
- }
- print "\r\n";
- $linenum++;
- }
Advertisement
Add Comment
Please, Sign In to add comment