Blame SOURCES/0001-Fixes-for-dealing-with-newer-tang-without-tangd-upda.patch

fbd758
From 16f667d9f3d649e33ca762afa1a8a7f909b953a8 Mon Sep 17 00:00:00 2001
fbd758
From: Sergio Correia <scorreia@redhat.com>
fbd758
Date: Sun, 25 Oct 2020 11:15:46 -0300
fbd758
Subject: [PATCH] Fixes for dealing with newer tang without tangd-update
fbd758
fbd758
---
fbd758
 src/luks/tests/meson.build               | 11 +----------
fbd758
 src/luks/tests/tests-common-functions.in | 19 +++++++++++--------
fbd758
 src/pins/tang/meson.build                | 11 +----------
fbd758
 src/pins/tang/pin-tang                   | 11 ++++++++---
fbd758
 4 files changed, 21 insertions(+), 31 deletions(-)
fbd758
fbd758
diff --git a/src/luks/tests/meson.build b/src/luks/tests/meson.build
fbd758
index ba5f6a2..c0f9dc3 100644
fbd758
--- a/src/luks/tests/meson.build
fbd758
+++ b/src/luks/tests/meson.build
fbd758
@@ -17,14 +17,6 @@ kgen = find_program(
fbd758
   join_paths('/', 'usr', get_option('libexecdir'), 'tangd-keygen'),
fbd758
   required: false
fbd758
 )
fbd758
-updt = find_program(
fbd758
-  join_paths(libexecdir, 'tangd-update'),
fbd758
-  join_paths(get_option('prefix'), get_option('libdir'), 'tangd-update'),
fbd758
-  join_paths(get_option('prefix'), get_option('libexecdir'), 'tangd-update'),
fbd758
-  join_paths('/', 'usr', get_option('libdir'), 'tangd-update'),
fbd758
-  join_paths('/', 'usr', get_option('libexecdir'), 'tangd-update'),
fbd758
-  required: false
fbd758
-)
fbd758
 tang = find_program(
fbd758
   join_paths(libexecdir, 'tangd'),
fbd758
   join_paths(get_option('prefix'), get_option('libdir'), 'tangd'),
fbd758
@@ -58,11 +50,10 @@ env.prepend('PATH',
fbd758
 )
fbd758
 
fbd758
 has_tang = false
fbd758
-if actv.found() and kgen.found() and updt.found() and tang.found()
fbd758
+if actv.found() and kgen.found() and tang.found()
fbd758
   has_tang = true
fbd758
   env.set('SD_ACTIVATE', actv.path())
fbd758
   env.set('TANGD_KEYGEN', kgen.path())
fbd758
-  env.set('TANGD_UPDATE', updt.path())
fbd758
   env.set('TANGD', tang.path())
fbd758
 endif
fbd758
 
fbd758
diff --git a/src/luks/tests/tests-common-functions.in b/src/luks/tests/tests-common-functions.in
fbd758
index 8520715..318d007 100755
fbd758
--- a/src/luks/tests/tests-common-functions.in
fbd758
+++ b/src/luks/tests/tests-common-functions.in
fbd758
@@ -251,18 +251,19 @@ tang_remove_rotated_keys() {
fbd758
         return 1
fbd758
     fi
fbd758
 
fbd758
-    [ -z "${TANGD_UPDATE}" ] && skip_test "WARNING: TANGD_UPDATE is not defined."
fbd758
-
fbd758
     local db="${basedir}/db"
fbd758
-    local cache="${basedir}/cache"
fbd758
     mkdir -p "${db}"
fbd758
-    mkdir -p "${cache}"
fbd758
+
fbd758
+    if [ -n "${TANGD_UPDATE}" ]; then
fbd758
+        local cache="${basedir}/cache"
fbd758
+        mkdir -p "${cache}"
fbd758
+    fi
fbd758
 
fbd758
     pushd "${db}"
fbd758
         find . -name ".*.jwk" -exec rm -f {} \;
fbd758
     popd
fbd758
 
fbd758
-    "${TANGD_UPDATE}" "${db}" "${cache}"
fbd758
+    [ -n "${TANGD_UPDATE}" ] && "${TANGD_UPDATE}" "${db}" "${cache}"
fbd758
     return 0
fbd758
 }
fbd758
 
fbd758
@@ -277,12 +278,12 @@ tang_new_keys() {
fbd758
     fi
fbd758
 
fbd758
     [ -z "${TANGD_KEYGEN}" ] && skip_test "WARNING: TANGD_KEYGEN is not defined."
fbd758
-    [ -z "${TANGD_UPDATE}" ] && skip_test "WARNING: TANGD_UPDATE is not defined."
fbd758
 
fbd758
     local db="${basedir}/db"
fbd758
-    local cache="${basedir}/cache"
fbd758
     mkdir -p "${db}"
fbd758
 
fbd758
+    [ -n "${TANGD_UPDATE}" ] && local cache="${basedir}/cache"
fbd758
+
fbd758
     if [ -n "${rotate}" ]; then
fbd758
         pushd "${db}"
fbd758
             local k
fbd758
@@ -296,7 +297,7 @@ tang_new_keys() {
fbd758
     fi
fbd758
 
fbd758
     "${TANGD_KEYGEN}" "${db}"
fbd758
-    "${TANGD_UPDATE}" "${db}" "${cache}"
fbd758
+    [ -n "${TANGD_UPDATE}" ] && "${TANGD_UPDATE}" "${db}" "${cache}"
fbd758
 
fbd758
     return 0
fbd758
 }
fbd758
@@ -322,6 +323,8 @@ tang_run() {
fbd758
     fi
fbd758
 
fbd758
     local KEYS="${basedir}/cache"
fbd758
+    [ -z "${TANGD_UPDATE}" ] && KEYS="${basedir}/db"
fbd758
+
fbd758
     local inetd='--inetd'
fbd758
     [ "${SD_ACTIVATE##*/}" = "systemd-activate" ] && inetd=
fbd758
 
fbd758
diff --git a/src/pins/tang/meson.build b/src/pins/tang/meson.build
fbd758
index f7d8226..ebcdd4a 100644
fbd758
--- a/src/pins/tang/meson.build
fbd758
+++ b/src/pins/tang/meson.build
fbd758
@@ -12,14 +12,6 @@ kgen = find_program(
fbd758
   join_paths('/', 'usr', get_option('libexecdir'), 'tangd-keygen'),
fbd758
   required: false
fbd758
 )
fbd758
-updt = find_program(
fbd758
-  join_paths(libexecdir, 'tangd-update'),
fbd758
-  join_paths(get_option('prefix'), get_option('libdir'), 'tangd-update'),
fbd758
-  join_paths(get_option('prefix'), get_option('libexecdir'), 'tangd-update'),
fbd758
-  join_paths('/', 'usr', get_option('libdir'), 'tangd-update'),
fbd758
-  join_paths('/', 'usr', get_option('libexecdir'), 'tangd-update'),
fbd758
-  required: false
fbd758
-)
fbd758
 tang = find_program(
fbd758
   join_paths(libexecdir, 'tangd'),
fbd758
   join_paths(get_option('prefix'), get_option('libdir'), 'tangd'),
fbd758
@@ -35,11 +27,10 @@ if curl.found()
fbd758
   bins += join_paths(meson.current_source_dir(), 'clevis-encrypt-tang')
fbd758
   mans += join_paths(meson.current_source_dir(), 'clevis-encrypt-tang.1')
fbd758
 
fbd758
-  if actv.found() and kgen.found() and updt.found() and tang.found()
fbd758
+  if actv.found() and kgen.found() and tang.found()
fbd758
     env = environment()
fbd758
     env.set('SD_ACTIVATE', actv.path())
fbd758
     env.set('TANGD_KEYGEN', kgen.path())
fbd758
-    env.set('TANGD_UPDATE', updt.path())
fbd758
     env.set('TANGD', tang.path())
fbd758
     env.prepend('PATH',
fbd758
       join_paths(meson.source_root(), 'src'),
fbd758
diff --git a/src/pins/tang/pin-tang b/src/pins/tang/pin-tang
fbd758
index 98e5e4d..a63d0a2 100755
fbd758
--- a/src/pins/tang/pin-tang
fbd758
+++ b/src/pins/tang/pin-tang
fbd758
@@ -31,8 +31,12 @@ mkdir -p "$TMP"/db
fbd758
 mkdir -p "$TMP"/cache
fbd758
 
fbd758
 # Generate the server keys
fbd758
+KEYS="$TMP"/db
fbd758
 "${TANGD_KEYGEN}" "$TMP"/db sig exc
fbd758
-"${TANGD_UPDATE}" "$TMP"/db "$TMP"/cache
fbd758
+if which tangd-update; then
fbd758
+    tangd-update "$TMP"/db "$TMP"/cache
fbd758
+    KEYS="$TMP"/cache
fbd758
+fi
fbd758
 
fbd758
 # Start the server
fbd758
 port="$(shuf -i 1024-65536 -n 1)"
fbd758
@@ -40,13 +44,14 @@ port="$(shuf -i 1024-65536 -n 1)"
fbd758
 inetd='--inetd'
fbd758
 [ "${SD_ACTIVATE##*/}" = "systemd-activate" ] && inetd=
fbd758
 
fbd758
-"$SD_ACTIVATE" $inetd -l 127.0.0.1:"$port" -a "$TANGD" "$TMP"/cache &
fbd758
+"$SD_ACTIVATE" $inetd -l 127.0.0.1:"$port" -a "$TANGD" "$KEYS" &
fbd758
 PID=$!
fbd758
 sleep 0.25
fbd758
 
fbd758
 thp="$(jose jwk thp -i "$TMP/db/sig.jwk")"
fbd758
-adv="$TMP/cache/default.jws"
fbd758
 url="http://localhost:${port}"
fbd758
+adv="$TMP/adv"
fbd758
+curl "$url/adv" -o "$adv"
fbd758
 
fbd758
 cfg="$(printf '{"url":"%s","adv":"%s"}' "$url" "$adv")"
fbd758
 enc="$(echo -n "hi" | clevis encrypt tang "$cfg")"
fbd758
-- 
fbd758
2.18.4
fbd758