summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorDhanuka Warusadura <csx@tuta.io>2021-08-04 18:19:49 +0530
committerDhanuka Warusadura <csx@tuta.io>2021-08-12 21:14:26 +0530
commitea57d269300a1f9cbfa1807d2f8370b50e8bfa8b (patch)
tree95e8bfbc235153b5e4b66d34122ba7d409b7d92f /tool
parent2f0558fe577eca8b45acf22dc7734b0cc30dd753 (diff)
downloadlibsecret-ea57d269300a1f9cbfa1807d2f8370b50e8bfa8b.tar.gz
Add TPM2 integration to secret file backend
These changes add TPM2 derived encryption key to secret file backend.
Diffstat (limited to 'tool')
-rw-r--r--tool/meson.build8
-rwxr-xr-xtool/test-secret-tool-tpm2.sh101
2 files changed, 109 insertions, 0 deletions
diff --git a/tool/meson.build b/tool/meson.build
index 13cb4c9..642cd59 100644
--- a/tool/meson.build
+++ b/tool/meson.build
@@ -17,3 +17,11 @@ if get_option('gcrypt') and host_machine.system() != 'windows'
suite: 'secret-tool',
)
endif
+
+if get_option('tpm2')
+ test('test-secret-tool-tpm2.sh',
+ find_program('test-secret-tool-tpm2.sh'),
+ env: test_env,
+ suite: 'secret-tool',
+ )
+endif
diff --git a/tool/test-secret-tool-tpm2.sh b/tool/test-secret-tool-tpm2.sh
new file mode 100755
index 0000000..c09b18d
--- /dev/null
+++ b/tool/test-secret-tool-tpm2.sh
@@ -0,0 +1,101 @@
+#!/bin/sh
+
+set -e
+
+testdir=$PWD/test-secret-tool-tpm2-$$
+test -d "$testdir" || mkdir "$testdir"
+
+cleanup () {
+ rm -rf "$testdir"
+}
+trap cleanup 0
+
+cd "$testdir"
+
+SECRET_BACKEND=file
+export SECRET_BACKEND
+
+SECRET_FILE_TEST_PATH=$testdir/keyring
+export SECRET_FILE_TEST_PATH
+
+: ${SECRET_TOOL="$abs_top_builddir"/tool/secret-tool}
+
+: ${DIFF=diff}
+
+echo 1..6
+
+echo test1 | ${SECRET_TOOL} store --label label1 foo bar
+if test $? -eq 0; then
+ echo "ok 1 /secret-tool/store1"
+else
+ echo "not ok 1 /secret-tool/store1"
+fi
+
+echo test2 | ${SECRET_TOOL} store --label label2 foo bar apple orange
+if test $? -eq 0; then
+ echo "ok 2 /secret-tool/store2"
+else
+ echo "not ok 2 /secret-tool/store2"
+fi
+
+echo test1 > lookup.exp
+${SECRET_TOOL} lookup foo bar > lookup.out
+if ${DIFF} lookup.exp lookup.out > lookup.diff; then
+ echo "ok 3 /secret-tool/lookup"
+else
+ echo "not ok 3 /secret-tool/lookup"
+ sed 's/^/# /' lookup.diff
+ exit 1
+fi
+
+cat > search.exp <<EOF
+[no path]
+label = label1
+secret = test1
+
+[no path]
+label = label2
+secret = test2
+
+EOF
+
+${SECRET_TOOL} search foo bar | sed '/^created\|^modified/d' > search.out
+if test $? -ne 0; then
+ echo "not ok 4 /secret-tool/search"
+ exit 1
+fi
+if ${DIFF} search.exp search.out > search.diff; then
+ echo "ok 4 /secret-tool/search"
+else
+ echo "not ok 4 /secret-tool/search"
+ sed 's/^/# /' search.diff
+ exit 1
+fi
+
+${SECRET_TOOL} clear apple orange
+if test $? -eq 0; then
+ echo "ok 5 /secret-tool/clear"
+else
+ echo "not ok 5 /secret-tool/clear"
+ exit 1
+fi
+
+cat > search-after-clear.exp <<EOF
+[no path]
+label = label1
+secret = test1
+
+EOF
+
+${SECRET_TOOL} search foo bar | sed '/^created\|^modified/d' > search-after-clear.out
+if test $? -ne 0; then
+ echo "not ok 6 /secret-tool/search-after-clear"
+ exit 1
+fi
+if ${DIFF} search-after-clear.exp search-after-clear.out > search-after-clear.diff; then
+ echo "ok 6 /secret-tool/search-after-clear"
+else
+ echo "not ok 6 /secret-tool/search-after-clear"
+ sed 's/^/# /' search-after-clear.diff
+ exit 1
+fi