All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: quilt-dev <quilt-dev@nongnu.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Andrew Morton <akpm@linux-foundation.org>,
	John Kacur <jkacur@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	Andreas Gruenbacher <agruen@suse.de>
Subject: [RFC][PATCH v2][QUILT] Add gpg signing to quilt mail
Date: Tue, 04 Oct 2011 13:46:34 -0400	[thread overview]
Message-ID: <1317750395.18063.11.camel@gandalf.stny.rr.com> (raw)

quilt mail: Add way to sign mail with GPG

After the attack of kernel.org, several kernel developers are getting
paranoid about who is really who. A lot of focus is on signing emails
that verify who people really are using GPG signatures.

Unfortunately, there's no way to sign quilt email as it goes out. This
patch fixes that.

Added the quilt mail option --pass to allow the user to enter a
passphrase and sign their email patches.

Thanks to Peter Zijlstra for recommending --use-agent to solve the
issues of both the passphrase in unlocked memory, and typing something
wrong.

These changes were done in /usr/share/quilt.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

diff --git a/mail b/mail
index c3c8297..ec04964 100755
--- a/mail
+++ b/mail
@@ -63,6 +63,9 @@ first, and a last patch name of \`-' denotes the last patch in the series.
 
 --reply-to message
 	Add the appropriate headers to reply to the specified message.
+
+--pass
+	Sign email with GPG signatures.
 " "/usr/share/doc/quilt/README.MAIL"
 		exit 0
 	else
@@ -115,6 +118,15 @@ references_header() {
 	[ -n "$references" ] && echo "References: $references"
 }
 
+sign_mail()
+{
+	if [ -z "$opt_pass" ]; then
+		cat
+	else
+		$QUILT_DIR/scripts/gpgmail.pl --agent
+	fi
+}
+	
 process_mail()
 {
 	local tmpfile=$(gen_tempfile)
@@ -132,12 +144,12 @@ process_mail()
 			${QUILT_SENDMAIL_ARGS--f "$opt_sender"} "$@"
 		$QUILT_DIR/scripts/edmail --charset $opt_charset \
 				 --remove-header Bcc "$@" < $tmpfile \
-		| ${QUILT_SENDMAIL:-sendmail} \
+		| sign_mail | ${QUILT_SENDMAIL:-sendmail} \
 			${QUILT_SENDMAIL_ARGS--f "$opt_sender"} "$@"
 	else
 		local from_date=$(LC_ALL=C date "+%a %b %e %H:%M:%S %Y")
 		echo "From $opt_sender_address $from_date"
-		sed -e 's/^From />From /' $tmpfile
+		sed -e 's/^From />From /' $tmpfile | sign_mail
 		echo
 	fi
 	rm -f $tmpfile
@@ -154,7 +166,7 @@ join_lines() {
 }
 
 options=`getopt -o m:h --long from:,to:,cc:,bcc:,subject: \
-		       --long send,mbox:,charset:,sender: \
+		       --long send,pass,mbox:,charset:,sender: \
 		       --long prefix:,reply-to:,signature: -- "$@"`
 
 if [ $? -ne 0 ]
@@ -212,6 +224,9 @@ do
 	--reply-to)
 		opt_reply_to=$2
 		shift 2 ;;
+	--pass)
+		opt_pass=1
+		shift ;;
 	--signature)
 		if [ "$2" = - ]
 		then
diff --git a/scripts/gpgmail.pl b/scripts/gpgmail.pl
new file mode 100755
index 0000000..c4484bb
--- /dev/null
+++ b/scripts/gpgmail.pl
@@ -0,0 +1,124 @@
+#!/usr/bin/perl
+
+use strict;
+
+use MIME::QuotedPrint;
+
+my $pass = "";
+
+while ($#ARGV >= 0) {
+    my $opt = $ARGV[0];
+
+    last if ($opt =~ /^--$/ || $opt !~ /^-/);
+
+    if ($opt eq "--passwd") {
+	shift @ARGV;
+	$pass = shift @ARGV;
+    } elsif ($opt eq "--agent") {
+	shift @ARGV;
+	$pass = " --use-agent ";
+    } else {
+	die "undefined option $opt";
+    }
+}
+
+shift @ARGV if ($#ARGV >= 0 && $ARGV eq "--");
+
+if ($#ARGV >= 0) {
+    open(IN, $ARGV[0]) or die "can't read $ARGV[0]";
+} else {
+    *IN = *STDIN;
+}
+
+*OUT = *STDOUT;
+
+my $content;
+my $quot;
+my $quoted = 0;
+
+while (<IN>) {
+    if (/^Content-Type/) {
+	s/$/\r/;
+	$content = $_;
+
+    } elsif (/^Content-Transfer-Encoding/) {
+	s/$/\r/;
+	$quot = $_;
+	$quoted = 1;
+
+    } elsif (/^$/) {
+	last;
+    } else {
+	print OUT;
+    }
+}
+
+my $scissor = sprintf "%s", crypt( sprintf("%d", rand * 1000), sprintf("%d", rand * 100));
+
+print OUT "Content-Type: multipart/signed; micalg=\"pgp-sha1\"; protocol=\"application/pgp-signature\"; boundary=\"$scissor\"";
+
+print OUT "\n\n";
+
+my $convert = 0;
+
+if (!defined($content)) {
+    $content = "Content-Type: text/plain; charset=\"UTF-8\"\r\n";
+    $quot = "Content-Transfer-Encoding: quoted-printable\r\n";
+    $convert = 1;
+    $quoted = 1;
+}
+
+print OUT "--$scissor\n";
+
+my @lines;
+
+$lines[$#lines + 1] = $content;
+if ($quoted) {
+    $lines[$#lines + 1] = $quot;
+}
+$lines[$#lines + 1] = "\r\n";
+
+my @rest;
+
+my @rest = <IN>;
+
+if ($convert) {
+    foreach my $line (@rest) {
+	$line = encode_qp($line,"\r\n");
+    }
+}
+
+@lines = (@lines, @rest);
+
+close IN;
+
+my $tmpfile = "/tmp/gpgmail.$$";
+
+open(TMP, ">", $tmpfile) or die "Can't create a temporary file";
+
+print TMP @lines;
+
+close TMP;
+
+# put the lines back to unix
+foreach my $line (@lines) {
+    $line =~ s/\r//g;
+}
+
+print OUT @lines;
+
+print OUT "\n";
+print OUT "--$scissor\n";
+
+my $pgp = `gpg --simple-sk-checksum -a --detach-sign $pass --output - < $tmpfile`;
+
+unlink $tmpfile;
+
+print OUT "Content-Type: application/pgp-signature; name=\"signature.asc\"\n";
+print OUT "Content-Description: This is a digitally signed message part\n";
+print OUT "\n";
+
+print OUT $pgp;
+
+print OUT "\n";
+print OUT "--$scissor--\n";



             reply	other threads:[~2011-10-04 17:46 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-04 17:46 Steven Rostedt [this message]
2011-10-04 18:02 ` [RFC][PATCH v2][QUILT] Add gpg signing to quilt mail Greg KH
2011-10-04 18:09   ` H. Peter Anvin
2011-10-04 18:18     ` Steven Rostedt
2011-10-04 18:18     ` Greg KH
2011-10-04 19:38     ` Steven Rostedt
2011-10-04 19:41       ` H. Peter Anvin
2011-10-04 19:48         ` Steven Rostedt
     [not found]           ` <1317769149.1662.28.camel@schurl.linbit>
2011-10-10 15:35             ` Steven Rostedt
2011-10-10 15:37               ` [Quilt-dev] " Josh Boyer
2011-10-11  2:39               ` Andreas Gruenbacher
2011-10-04 18:15   ` Steven Rostedt
2011-10-04 18:26     ` Greg KH
2011-10-04 18:37       ` Steven Rostedt
2011-10-05  1:48         ` [Quilt-dev] " Andreas Gruenbacher
2011-10-05  6:53           ` Greg KH
2011-10-05  8:23             ` Andreas Gruenbacher
2011-10-05 11:21             ` Andreas Gruenbacher
2011-10-05 20:12               ` Greg KH
2011-10-05 20:18                 ` Josh Boyer
2011-10-04 18:59 ` Peter Zijlstra
2011-10-04 19:11   ` Steven Rostedt
2011-10-04 19:20   ` Valdis.Kletnieks
2011-10-04 19:35     ` Steven Rostedt
2011-10-06 10:27 ` [RFC][PATCH v2][QUILT] Add Peter Zijlstra
2011-10-06 17:26   ` Andrew Morton
2011-10-06 17:57     ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1317750395.18063.11.camel@gandalf.stny.rr.com \
    --to=rostedt@goodmis.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=agruen@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@suse.de \
    --cc=hpa@zytor.com \
    --cc=jkacur@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quilt-dev@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.