All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH v2][QUILT] Add gpg signing to quilt mail
@ 2011-10-04 17:46 Steven Rostedt
  2011-10-04 18:02 ` Greg KH
                   ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Steven Rostedt @ 2011-10-04 17:46 UTC (permalink / raw)
  To: quilt-dev
  Cc: LKML, Peter Zijlstra, Andrew Morton, John Kacur, H. Peter Anvin,
	Greg Kroah-Hartman, Andreas Gruenbacher

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";



^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2011-10-11  2:39 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-04 17:46 [RFC][PATCH v2][QUILT] Add gpg signing to quilt mail Steven Rostedt
2011-10-04 18:02 ` 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

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.