2013-02-11 08:11:36 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2013-04-29 08:08:01 +00:00
|
|
|
# Tests for Serval keyring
|
2013-02-11 08:11:36 +00:00
|
|
|
#
|
2013-04-29 08:08:01 +00:00
|
|
|
# Copyright 2012-2013 Serval Project, Inc.
|
2013-02-11 08:11:36 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
source "${0%/*}/../testframework.sh"
|
|
|
|
source "${0%/*}/../testdefs.sh"
|
|
|
|
|
|
|
|
shopt -s extglob
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_servald
|
2013-04-29 05:01:50 +00:00
|
|
|
executeOk_servald config \
|
|
|
|
set log.console.level debug \
|
|
|
|
set debug.keyring on
|
2013-03-06 03:45:27 +00:00
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 0
|
2013-02-11 08:11:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_keyring_list() {
|
|
|
|
assertStdoutLineCount --stdout --stderr '==' $1
|
2013-02-28 05:57:26 +00:00
|
|
|
assertStdoutGrep --stderr --matches=$1 "^[0-9a-fA-F]\{64\}:[0-9*#+]*:.*\$"
|
2013-02-11 08:11:36 +00:00
|
|
|
tfw_cat --stdout
|
|
|
|
}
|
|
|
|
|
2013-02-13 06:19:52 +00:00
|
|
|
doc_KeyringCreate="Create keyring destroys existing keys"
|
2013-02-11 08:11:36 +00:00
|
|
|
test_KeyringCreate() {
|
2013-02-13 06:19:52 +00:00
|
|
|
executeOk_servald keyring add ''
|
2013-02-11 08:11:36 +00:00
|
|
|
executeOk_servald keyring add ''
|
|
|
|
executeOk_servald keyring list
|
2013-02-13 06:19:52 +00:00
|
|
|
assert_keyring_list 2
|
2013-02-11 08:11:36 +00:00
|
|
|
executeOk_servald keyring create
|
|
|
|
assert_keyring_list 0
|
|
|
|
}
|
|
|
|
|
2013-02-13 06:19:52 +00:00
|
|
|
doc_Pinless="No keyring PIN with PIN-less identities"
|
|
|
|
test_Pinless() {
|
2013-02-11 08:11:36 +00:00
|
|
|
executeOk_servald keyring add ''
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 1
|
|
|
|
executeOk_servald keyring add ''
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 2
|
|
|
|
executeOk_servald keyring add ''
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 3
|
|
|
|
}
|
|
|
|
|
2013-02-13 06:19:52 +00:00
|
|
|
doc_IdentityPins="No keyring PIN with identity PINs"
|
|
|
|
test_IdentityPins() {
|
2013-02-11 08:11:36 +00:00
|
|
|
executeOk_servald keyring add 'one'
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 0
|
2013-02-13 06:19:52 +00:00
|
|
|
executeOk_servald keyring list --entry-pin 'one'
|
2013-02-11 08:11:36 +00:00
|
|
|
assert_keyring_list 1
|
|
|
|
executeOk_servald keyring add 'two'
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 0
|
2013-02-13 06:19:52 +00:00
|
|
|
executeOk_servald keyring list --entry-pin 'one'
|
2013-02-11 08:11:36 +00:00
|
|
|
assert_keyring_list 1
|
2013-02-13 06:19:52 +00:00
|
|
|
executeOk_servald keyring list --entry-pin 'one' --entry-pin 'two'
|
2013-02-11 08:11:36 +00:00
|
|
|
assert_keyring_list 2
|
|
|
|
executeOk_servald keyring add 'three'
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 0
|
2013-02-13 06:19:52 +00:00
|
|
|
executeOk_servald keyring list --entry-pin 'one'
|
2013-02-11 08:11:36 +00:00
|
|
|
assert_keyring_list 1
|
2013-02-13 06:19:52 +00:00
|
|
|
executeOk_servald keyring list --entry-pin 'one' --entry-pin 'two'
|
2013-02-11 08:11:36 +00:00
|
|
|
assert_keyring_list 2
|
2013-02-13 06:19:52 +00:00
|
|
|
executeOk_servald keyring list --entry-pin 'one' --entry-pin 'two' --entry-pin 'three'
|
2013-02-11 08:11:36 +00:00
|
|
|
assert_keyring_list 3
|
2013-02-13 06:19:52 +00:00
|
|
|
executeOk_servald keyring list --entry-pin 'two' --entry-pin 'three'
|
|
|
|
assert_keyring_list 2
|
|
|
|
executeOk_servald keyring list --entry-pin 'three'
|
|
|
|
assert_keyring_list 1
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_KeyringPinIdentityPinless="Keyring PIN with PIN-less identities"
|
|
|
|
test_KeyringPinIdentityPinless() {
|
|
|
|
executeOk_servald keyring add --keyring-pin=hello ''
|
|
|
|
executeOk_servald keyring list --keyring-pin=hello
|
|
|
|
assert_keyring_list 1
|
|
|
|
executeOk_servald keyring add --keyring-pin=hello ''
|
|
|
|
executeOk_servald keyring list --keyring-pin=hello
|
|
|
|
assert_keyring_list 2
|
|
|
|
executeOk_servald keyring add --keyring-pin=hello ''
|
|
|
|
executeOk_servald keyring list --keyring-pin=hello
|
2013-02-11 08:11:36 +00:00
|
|
|
assert_keyring_list 3
|
2013-02-13 06:19:52 +00:00
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 0
|
2013-02-11 08:11:36 +00:00
|
|
|
}
|
|
|
|
|
2013-04-29 06:30:17 +00:00
|
|
|
doc_KeyringPinIdentityPin="Keyring PIN with identity PINs"
|
|
|
|
test_KeyringPinIdentityPin() {
|
|
|
|
executeOk_servald keyring add --keyring-pin=yellow 'duck'
|
|
|
|
executeOk_servald keyring add --keyring-pin=yellow 'chicken'
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 0
|
|
|
|
executeOk_servald keyring list --keyring-pin=yellow
|
|
|
|
assert_keyring_list 0
|
|
|
|
executeOk_servald keyring list --keyring-pin=yellow --entry-pin=duck
|
|
|
|
assert_keyring_list 1
|
|
|
|
executeOk_servald keyring list --keyring-pin=yellow --entry-pin=chicken
|
|
|
|
assert_keyring_list 1
|
|
|
|
executeOk_servald keyring list --keyring-pin=yellow --entry-pin=duck --entry-pin=chicken
|
|
|
|
assert_keyring_list 2
|
|
|
|
executeOk_servald keyring list --entry-pin=duck --entry-pin=chicken
|
|
|
|
assert_keyring_list 0
|
|
|
|
}
|
|
|
|
|
2013-02-28 05:57:26 +00:00
|
|
|
doc_KeyringAutoCreate="Starting a server with no keyring creates a valid identity"
|
|
|
|
test_KeyringAutoCreate() {
|
2013-03-06 04:59:27 +00:00
|
|
|
start_servald_server
|
2013-03-06 03:45:27 +00:00
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 1
|
|
|
|
}
|
|
|
|
finally_KeyringAutoCreate() {
|
|
|
|
stop_servald_server
|
|
|
|
}
|
|
|
|
teardown_KeyringAutoCreate() {
|
2013-03-06 04:59:27 +00:00
|
|
|
kill_all_servald_processes
|
|
|
|
assert_no_servald_processes
|
2013-03-06 03:45:27 +00:00
|
|
|
report_servald_server
|
2013-02-28 05:57:26 +00:00
|
|
|
}
|
|
|
|
|
2013-04-29 05:41:04 +00:00
|
|
|
doc_CompatibleBack1="Can read old keyring file (1)"
|
|
|
|
setup_CompatibleBack1() {
|
|
|
|
setup_servald
|
|
|
|
executeOk_servald config \
|
|
|
|
set log.console.level debug \
|
|
|
|
set debug.keyring on
|
|
|
|
assert mkdir -p "$SERVALINSTANCE_PATH"
|
|
|
|
assert cp "${TFWSOURCE%/*}/testdata/serval.keyring-1" "$SERVALINSTANCE_PATH/serval.keyring"
|
|
|
|
}
|
|
|
|
test_CompatibleBack1() {
|
2013-04-30 08:26:10 +00:00
|
|
|
executeOk_servald keyring dump --secret
|
|
|
|
assertStdoutLineCount '==' 11
|
|
|
|
assertStdoutGrep "^0: type=.*(CRYPTOBOX).*pub=6EE9BCA4AE1A264D18F42C18EF910915F98F0C5D9ECD853ECB1547B752119F05\b"
|
|
|
|
assertStdoutGrep "^0: type=.*(CRYPTOBOX).*sec=3611C4CC6BC7A167088492AD021103048C78F16AC22724B06B96A3E865163137\b"
|
|
|
|
assertStdoutGrep "^0: type=.*(CRYPTOSIGN).*pub=DA75D0A0EFCC75A9CCA634C2FC36EC19416B0CDE2A014520F911B95D1DB6224A\b"
|
|
|
|
assertStdoutGrep "^0: type=.*(CRYPTOSIGN).*sec=A90608CE5135D54CDBA922426D425F9D5494C8DB83D658EE518D88BCDAF04B1EDA75D0A0EFCC75A9CCA634C2FC36EC19416B0CDE2A014520F911B95D1DB6224A\b"
|
|
|
|
assertStdoutGrep "^0: type=.*(DID).*DID=\"555001234\""
|
|
|
|
assertStdoutGrep "^0: type=.*(DID).*Name=\"Jones\""
|
|
|
|
assertStdoutGrep "^0: type=.*(RHIZOME).*sec=6FBCD69A8DE983324C414F8B5BA83646EF4421AA877BB06F18AFA78EEC42A4BC\b"
|
|
|
|
assertStdoutGrep "^1: type=.*(CRYPTOBOX).*pub=C10C91D24BF210DD6733ED2424B4509E6CC4402D34055B6D29F7A778701AA542\b"
|
|
|
|
assertStdoutGrep "^1: type=.*(CRYPTOBOX).*sec=9D22FF754D90971B062A26BAA1D2E95C03B67688B3C71334C3512DB8FA996570\b"
|
|
|
|
assertStdoutGrep "^1: type=.*(CRYPTOSIGN).*pub=9F40922AD9435B1AD2880442B43D32CC345CAAFF13599DC241C13E421A4D672A\b"
|
|
|
|
assertStdoutGrep "^1: type=.*(CRYPTOSIGN).*sec=648F3171A612F82ED01BA1475AD9F538F97C1D95067D1D9F7F324B8F9C0489289F40922AD9435B1AD2880442B43D32CC345CAAFF13599DC241C13E421A4D672A\b"
|
|
|
|
assertStdoutGrep "^1: type=.*(DID).*DID=\"55500000\""
|
|
|
|
assertStdoutGrep "^1: type=.*(DID).*Name=\"Smith\""
|
|
|
|
assertStdoutGrep "^1: type=.*(RHIZOME).*sec=E78E7F80CCEC0179A07E1DECC9D6C3C89089A9FD3787CF5273FD0F8E9CE62780\b"
|
|
|
|
assertStdoutGrep "^2: type=.*(CRYPTOBOX).*pub=EEBF3AC19E7EE58722A0F6D4A4D5894A72F5C71030C3399FE75808DCF6C6254B\b"
|
|
|
|
assertStdoutGrep "^2: type=.*(CRYPTOBOX).*sec=5822F44BF118F7A533B74046A400FA8C83A6B69EDD0166D8175D0B70267A2CA1\b"
|
|
|
|
assertStdoutGrep "^2: type=.*(CRYPTOSIGN).*pub=13A4B69DE4D4A1D89DB22E1D433B0C7DEB2E9C86A2FD98D9F689B7EDEFB64E20\b"
|
|
|
|
assertStdoutGrep "^2: type=.*(CRYPTOSIGN).*sec=2B221014CED25245A181B5164030D7823B8FC288DE724CAC029CE6A5E195A12713A4B69DE4D4A1D89DB22E1D433B0C7DEB2E9C86A2FD98D9F689B7EDEFB64E20\b"
|
|
|
|
assertStdoutGrep "^2: type=.*(RHIZOME).*sec=4483DF66540740736A05055A96D8C8B84F05D52808380DD52462B8EA5CCAB0D3\b"
|
|
|
|
assertStdoutGrep --matches=0 "^2: type=.*(DID)"
|
|
|
|
assertStdoutGrep --matches=0 "^3:"
|
2013-04-29 05:41:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-30 01:46:41 +00:00
|
|
|
doc_KeyringPathEnv="Use keyring specified by environment variable"
|
|
|
|
setup_KeyringPathEnv() {
|
|
|
|
setup
|
|
|
|
executeOk_servald keyring add ''
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 1
|
|
|
|
orig="$(replayStdout)"
|
|
|
|
}
|
|
|
|
test_KeyringPathEnv() {
|
|
|
|
export SERVALD_KEYRING_PATH="$PWD/keyring"
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 0
|
|
|
|
assert --message="created 'keyring' file" [ -s keyring ]
|
|
|
|
executeOk_servald keyring add ''
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 1
|
|
|
|
assert [ "$(replayStdout)" != "$orig" ]
|
|
|
|
unset SERVALD_KEYRING_PATH
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 1
|
|
|
|
assert [ "$(replayStdout)" == "$orig" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_ReadOnlyEnv="Use keyring specified by environment variable"
|
|
|
|
setup_ReadOnlyEnv() {
|
|
|
|
setup
|
|
|
|
executeOk_servald keyring add ''
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 1
|
|
|
|
orig="$(replayStdout)"
|
|
|
|
}
|
|
|
|
test_ReadOnlyEnv() {
|
|
|
|
export SERVALD_KEYRING_READONLY="true"
|
|
|
|
execute --exit-status=255 $servald keyring add ''
|
|
|
|
tfw_cat --stderr
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 1
|
|
|
|
assert [ "$(replayStdout)" == "$orig" ]
|
|
|
|
export SERVALD_KEYRING_READONLY="false"
|
|
|
|
executeOk_servald keyring add ''
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 2
|
|
|
|
}
|
|
|
|
|
2013-02-11 08:11:36 +00:00
|
|
|
runTests "$@"
|