From 4fe095e1c7ce9f75e215772cc5c1b553c4613891 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 14 Feb 2013 00:00:00 +0000 Subject: [PATCH] Use a shorter repository id in the URL, to simplify a tiny bit --- README.rst | 4 ++-- git-remote-gcrypt | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 6add2bd..b975ef6 100644 --- a/README.rst +++ b/README.rst @@ -23,8 +23,8 @@ Example use:: git remote add cryptremote gcrypt::ssh://example.com:repo git push cryptremote master > gcrypt: Setting up new repository at ssh://example.com:repo - > gcrypt: Repository ID is 99b45a84a13168fc5efe - > gcrypt: Repository URL is gcrypt::ssh://example.com:repo/G/99b45a84a13168fc5efe + > gcrypt: Repository ID is KNBr0wKzct52 + > gcrypt: Repository URL is gcrypt::ssh://example.com:repo/G/KNBr0wKzct52 > gcrypt: (configuration for cryptremote updated) > [ more lines .. ] > To gcrypt::[...] diff --git a/git-remote-gcrypt b/git-remote-gcrypt index e758173..b0a4fdf 100755 --- a/git-remote-gcrypt +++ b/git-remote-gcrypt @@ -217,9 +217,10 @@ PRIVDECRYPT() }) } +# Generate $1 random bytes genkey() { - gpg --armor --gen-rand 1 128 | tr -d \\n + gpg --armor --gen-rand 1 "$1" } pack_hash() @@ -260,15 +261,15 @@ make_new_repo() local urlid_= fix_config= echo_info "Setting up new repository at $URL" PUTREPO "$URL" - Masterkey="$(genkey)" + Masterkey="$(genkey 128)" # We need a relatively short ID for URL+REPO # The manifest will be stored at SHA224(urlid_) # Needed assumption: the same user should have no duplicate urlid_ - # For now, we use 20 random hex digits (80 bits), can be increased - urlid_=$(genkey | pack_hash | cut -c 1-20) + # For now, we arbitrarily use 9 random bytes (72 bits) + urlid_=$(genkey 9 | tr '/+' 'Zz') Repoid=$(xecho_n "$urlid_" | pack_hash) - echo_info "Repository ID is" "$urlid_" + echo_info "Repository ID is" "$urlid_" isnoteq "${NAME#gcrypt::}" "$URL" && { git config "remote.$NAME.url" "gcrypt::$URL/G/$urlid_" fix_config=1