Skip to content

Commit

Permalink
Handle spaces in filenames properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
busykai committed Nov 7, 2017
1 parent 198cedb commit 57ed053
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 8 deletions.
18 changes: 10 additions & 8 deletions clrtrust
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ is_root_ca() {
# if issuer and subject match, then it's a self-signed certificate, the only
# indication of a Root CA we need to take into account (X.509v3 extensions
# are not)
t=$(openssl x509 -in $1 -noout -issuer -subject 2>/dev/null \
t=$(openssl x509 -in "$1" -noout -issuer -subject 2>/dev/null \
| sed -e 's/^\(issuer\|subject\)=//' | uniq | wc -l)
test $t -eq 1
}
Expand Down Expand Up @@ -161,7 +161,9 @@ $tmp"
mkdir -p $CLR_STORE_STAGE/anchors
mkdir -p $CLR_STORE_STAGE/compat

echo "${ca_certs}" | cut -f 1 | xargs cp -t $CLR_STORE_STAGE/anchors
if [ ! -z "${ca_certs}" ]; then
echo "${ca_certs}" | cut -f 1 | xargs -d '\n' cp -t $CLR_STORE_STAGE/anchors
fi

if ! (cd $CLR_STORE_STAGE/anchors && c_rehash . >/dev/null 2>&1); then
1>&2 echo "Error rehashing the anchors."
Expand Down Expand Up @@ -284,8 +286,8 @@ EOF
continue
fi
fi
fname=$(basename $f)
if [ -f $CLR_LOCAL_TRUST_SRC/trusted/$fname ]; then
fname=$(basename "$f")
if [ -f "$CLR_LOCAL_TRUST_SRC/trusted/$fname" ]; then
# FIXME: it's not a duplicate, should really not be picky about file
# names.
echo "File $fname already exists."
Expand Down Expand Up @@ -492,9 +494,9 @@ $1"
# if certificate is provided by clear trust store, distrust it,
# otherwise remove it
if [ $(dirname $f) = $CLR_CLEAR_TRUST_SRC/trusted ]; then
cp $f $CLR_LOCAL_TRUST_SRC/distrusted
cp "$f" $CLR_LOCAL_TRUST_SRC/distrusted
else
rm $f
rm "$f"
fi
done
cmd_generate
Expand Down Expand Up @@ -573,15 +575,15 @@ case $COMMAND in
exit $?
;;
add)
cmd_add $*
cmd_add "$@"
exit $?
;;
list)
cmd_list $*
exit $?
;;
remove)
cmd_remove $*
cmd_remove "$@"
exit $?
;;
restore|check)
Expand Down
44 changes: 44 additions & 0 deletions test/add-remove-with-spaces.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bats
# Copyright 2017 Intel Corporation

load test_lib

setup() {
find_clrtrust
setup_fs
cp $CERTS/c1.pem "$CLR_CLEAR_TRUST_SRC/trusted/COMODO RSA Certification Authority.pem"
}

@test "add, remove files with spaces in names" {
$CLRTRUST generate
cnt=$(ls $STORE/anchors | wc -l)
[ $cnt -eq 2 ] # file and symlink
run $CLRTRUST list
[ $status -eq 0 ]
cnt=$(echo "$output"| grep ^id | wc -l)
[ $cnt -eq 1 ]
# add file with spaces
$CLRTRUST add $CERTS/'Baltimore CyberTrust Root.crt'
run $CLRTRUST list
cnt=$(echo "$output" | grep ^id | wc -l)
[ $cnt -eq 2 ]
$CLRTRUST add $CERTS/c2.pem
run $CLRTRUST list
cnt=$(echo "$output" | grep ^id | wc -l)
[ $cnt -eq 3 ]
$CLRTRUST remove $CERTS/'Baltimore CyberTrust Root.crt' $CERTS/c2.pem
run $CLRTRUST list
cnt=$(echo "$output" | grep ^id | wc -l)
[ $cnt -eq 1 ]
$CLRTRUST remove "$CLR_CLEAR_TRUST_SRC/trusted/COMODO RSA Certification Authority.pem"
run $CLRTRUST list
cnt=$(echo "$output" | grep ^id | wc -l)
[ $cnt -eq 0 ]
}

teardown() {
true
#remove_fs
}

# vim: ft=sh:sw=4:ts=4:et:tw=80:si:noai:nocin
21 changes: 21 additions & 0 deletions test/certs/Baltimore CyberTrust Root.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDdzCCAl+gAwIBAgIEAgAAuTANBgkqhkiG9w0BAQUFADBaMQswCQYDVQQGEwJJ
RTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDV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