BTS

Issue741

Title zsh aliases for displaying ssl certificate information/fingerprints
Priority wish Status resolved
Superseder Nosy List abe, ft, mika
Assigned To Topics grml-etc-core, zsh

Created on 2009-09-21.01:40:42 by abe, last changed 2009-10-14.07:31:19 by mika.

Files
File name Uploaded Type Edit Remove
0001-Document-ssl-cert-functions.patch abe, 2009-09-21.12:18:34 text/x-diff
Messages
msg2506 (view) Author: mika Date: 2009-10-14.07:31:13
We believe that your issue has been closed by the upload of
Version 0.3.76 of grml-etc-core from Michael Prokop <mika@grml.org>.
The explanation is attached below

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Wed, 14 Oct 2009 09:26:37 +0200
Source: grml-etc-core
Binary: grml-etc-core
Architecture: source all
Version: 0.3.76
Distribution: unstable
Urgency: low
Maintainer: Michael Prokop <mika@grml.org>
Changed-By: Michael Prokop <mika@grml.org>
Description: 
 grml-etc-core - core ecetera files for the grml system
Changes: 
 grml-etc-core (0.3.76) unstable; urgency=low
 .
   [ Frank Terbeck ]
   * zshrc: add openssl hash functions [Closes: issue741]
   * zshrc: use history-incremental-pattern-search-* for incremental history
     searches per default (via ^r and ^s).
   * zshrc: actively do 'setopt unset'
Checksums-Sha1: 
 ad5f590a26323256b2c93199a938bb94a5fb6240 869 grml-etc-core_0.3.76.dsc
 a0ce32f7da3f75fabba3f5f41fba72fd133097bf 113565 grml-etc-core_0.3.76.tar.gz
 06a76b55d5ba3153391a2a911b5322b1e8fe8f0f 117024 grml-etc-core_0.3.76_all.deb
Checksums-Sha256: 
 ea9b8c2ebda6668b0f0e92d775dc504ce3d683928b51c44eb1e4b75f1020955b 869 grml-etc-core_0.3.76.dsc
 5ccbe2677053b2994a86f6d5f4b465758a4c3dc1d5b8d9d2bfd71e40c17e960d 113565 grml-etc-core_0.3.76.tar.gz
 9a13cbcd98b001b49a8c5661c31c3297533760bc50db65ea85bc6d1165962068 117024 grml-etc-core_0.3.76_all.deb
Files: 
 b4ce91ade95d522cdbae76baf1d3b0f2 869 grml optional grml-etc-core_0.3.76.dsc
 d1384e631c434ad24a5716d8914db03a 113565 grml optional grml-etc-core_0.3.76.tar.gz
 e5fba4e248fad503d9097358413a0621 117024 grml optional grml-etc-core_0.3.76_all.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iD8DBQFK1X1a2N9T+zficugRAlpDAJ4zMyFc24WfzXDdPGKLN5mj6P1p+wCeLV95
mp80OKdY9PlCwDo3vStVRr4=
=BaK+
-----END PGP SIGNATURE-----
msg2495 (view) Author: abe Date: 2009-09-21.12:18:35
Hi,

On Mon, Sep 21, 2009 at 01:28:35PM +0200, Frank Terbeck wrote:
> Also, I would like new stuff to go in only with accompanying
> documentation in doc/grmlzshrc.t2t of grml-etc-core's zshrc5 branch.
> 
> Someone who knows what the functions from this patch actually do
> should write entries for them.

Done and attached. Hope it's fine.

		Regards, Axel
-- 
Axel Beckert - abe@deuxchevaux.org, abe@noone.org - http://noone.org/abe/
msg2494 (view) Author: ft Date: 2009-09-21.11:28:52
From 93f4d32d511a3ad59628ec014ede589e33776f7e Mon Sep 17 00:00:00 2001
From: Frank Terbeck <ft@bewatermyfriend.org>
Date: Mon, 21 Sep 2009 13:21:58 +0200
Subject: [PATCH] zshrc: add openssl hash functions

Initially written by mika@grml.org, fixed up a little by me.
---

Frank Terbeck <ft@bewatermyfriend.org>:
> Michael Prokop <bts@bts.grml.org>:
> > Frank, can you please review? Maybe we should add some simple usage information 
> > if $1 is missing?
[...]
> 
> I'd do it like this:
[...]

Well, here's what I got in my repo now.

I'll happily push it, if people *test* and ACK this. - I didn't test
this!

Also, I would like new stuff to go in only with accompanying
documentation in doc/grmlzshrc.t2t of grml-etc-core's zshrc5 branch.

Someone who knows what the functions from this patch actually do
should write entries for them.

The guy who already writes the manual entries for the *existing* code
shouldn't be burdened with documenting *new* code, too.

So: Pretty please. :-)

Regards, Frank

 debian/changelog |    6 ++++++
 etc/zsh/zshrc    |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 020f1fc..35be720 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+grml-etc-core (0.3.76) UNRELEASED; urgency=low
+
+  * zshrc: add openssl hash functions
+
+ -- Frank Terbeck <ft@grml.org>  Mon, 21 Sep 2009 13:20:36 +0200
+
 grml-etc-core (0.3.75) unstable; urgency=low
 
   [ Frank Terbeck ]
diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc
index c7ddace..0cd52bd 100644
--- a/etc/zsh/zshrc
+++ b/etc/zsh/zshrc
@@ -2985,6 +2985,42 @@ exit 0;
     return $?
 }
 
+ssl_hashes=( sha512 sha256 sha1 md5 )
+
+for sh in ${ssl_hashes}; do
+    ssl-cert-${sh}() {
+        emulate -L zsh
+        if [[ -z $1 ]] ; then
+            printf 'usage: %s <hash-name>\n' "ssh-cert-${sh}"
+            printf '  where "hash-name" is one of: %s\n' "${ssl_hashes}"
+            return 1
+        fi
+        openssl x509 -noout -fingerprint -${sh} -in $1
+    }
+done; unset sh
+
+ssl-cert-fingerprints() {
+    emulate -L zsh
+    local i
+    if [[ -z $1 ]] ; then
+        printf 'usage: ssl-cert-fingerprints <file>\n'
+        return 1
+    fi
+    for i in ${ssl_hashes}
+        do ssl-cert-$i $1;
+    done
+}
+
+ssl-cert-info() {
+    emulate -L zsh
+    if [[ -z $1 ]] ; then
+        printf 'usage: ssl-cert-info <file>\n'
+        return 1
+    fi
+    openssl x509 -noout -text -in $1
+    ssl-cert-fingerprints $1
+}
+
 # }}}
 
 # {{{ make sure our environment is clean regarding colors
-- 
1.6.5.rc0
msg2493 (view) Author: ft Date: 2009-09-21.10:45:55
Michael Prokop <bts@bts.grml.org>:
> Frank, can you please review? Maybe we should add some simple usage information 
> if $1 is missing?

Yes, I can[tm].

I'd do it like this:

[snip]
ssl_hashes=( sha512 sha256 sha1 md5 )

for sh in ${ssl_hashes}; do
    ssl-cert-${sh}() {
        emulate -L zsh
        if [[ -z $1 ]] ; then
            printf 'usage: %s <hash-name>\n' "ssh-cert-${sh}"
            printf '  where "hash-name" is one of: %s\n' "${ssl_hashes}"
            return 1
        fi
        openssl x509 -noout -fingerprint -${sh} -in $1
    }
done

ssl-cert-fingerprints() {
    emulate -L zsh
    if [[ -z $1 ]] ; then
        printf 'usage: ssl-cert-fingerprints <file>\n'
        return 1
    fi
    for i in ${ssl_hashes}
        do ssl-cert-$i $1;
    done
}

ssl-cert-info() {
    emulate -L zsh
    if [[ -z $1 ]] ; then
        printf 'usage: ssl-cert-info <file>\n'
        return 1
    fi
    openssl x509 -noout -text -in $1 
    ssl-cert-fingerprints $1
}
[snap]

I thinks that's reasonable.

Also note, that I was assuming for ssl-cert-fingerprints() and
ssl-cert-info() to take a *file* as their sole argument. I got no idea
about the workings of openssl. I'm really just a DAU with it.

Anyway, this is my take on the subject.

Regards, Frank
msg2492 (view) Author: mika Date: 2009-09-21.07:16:07
I can't remember all the openssl stuff on my own, that's why I wrote the 
openssl section in grml-tips. :)

Frank, can you please review? Maybe we should add some simple usage information 
if $1 is missing?

thx && regards,
-mika-
msg2491 (view) Author: abe Date: 2009-09-21.01:40:39
I suggest to add the following aliases/functions to grml's zshrc:

for i in sha512 sha256 sha1 md5; do
  ssl-cert-$i() { openssl x509 -noout -fingerprint -$i -in $1 }
done

ssl-cert-fingerprints() {
  for i in sha512 sha256 sha1 md5; do ssl-cert-$i $1; done
}

ssl-cert-info() {
   openssl x509 -noout -text -in $1 
   ssl-cert-fingerprints $1
}

I never can remember all the options openssl wants for displaying this very
basic information about certificates, so I guess these functions are useful for
others, too.

P.S.: I don't know why, but creating function inside a for loop doesn't seem to
work in bash (3.2). In zsh it just works[tm]. :-)
History
Date User Action Args
2009-10-14 07:31:19mikasetstatus: fixed-in-git -> resolved
nosy: mika, ft, abe
messages: + msg2506
2009-09-21 18:34:15abesetstatus: resolved -> fixed-in-git
nosy: mika, ft, abe
2009-09-21 18:32:34abesetstatus: chatting -> resolved
nosy: mika, ft, abe
2009-09-21 12:18:42abesetfiles: + 0001-Document-ssl-cert-functions.patch
nosy: mika, ft, abe
messages: + msg2495
2009-09-21 11:28:54ftsetnosy: mika, ft, abe
messages: + msg2494
2009-09-21 10:46:01ftsetnosy: mika, ft, abe
messages: + msg2493
2009-09-21 07:16:09mikasetstatus: unread -> chatting
nosy: + ft, mika
messages: + msg2492
2009-09-21 01:40:42abecreate