Skip to content

Commit

Permalink
Merge pull request bgpsecurity#44 from evil-twin-tests
Browse files Browse the repository at this point in the history
Reviewed-by: David Mandelberg <[email protected]>
  • Loading branch information
rhansen committed May 12, 2016
2 parents 47382b7 + 1277190 commit 8652b2f
Show file tree
Hide file tree
Showing 34 changed files with 874 additions and 0 deletions.
176 changes: 176 additions & 0 deletions mk/rpki.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,179 @@
######################################################################
## helpers to generate keys, certs, and roas
######################################################################
set_vars= \
target='$@' && \
top_srcdir='${top_srcdir}' && \
target_dir=$${target%/*}
boilerplate= \
${set_vars} && \
mkdir -p "$${target_dir}" && \
TEST_LOG_NAME=$${target\#\#*/} \
TEST_LOG_DIR=$${target_dir} \
STRICT_CHECKS=0 \
${LOG_COMPILER}
create_object = ${boilerplate} bin/rpki-object/create_object/create_object
gen_key = ${boilerplate} bin/rpki-object/gen_key
KEYS = ${CERTS:.cer=.key}
CERTS =
ROAS =
${KEYS}: bin/rpki-object/gen_key
${gen_key} "$${target}" 2048
${CERTS}: bin/rpki-object/create_object/create_object
${create_object} \
-f "$${top_srcdir}"/"$${target%.cer}".options \
CERT \
serial=1 \
notbefore=000101010101Z \
notafter=21001231235959Z \
crldp=rsync://invalid/invalid.crl \
outputfilename="$${target}"
${ROAS}: bin/rpki-object/create_object/create_object
${set_vars} && \
eeopt=$${target%.roa}.options && \
eekey=$$(sed -n -e 's/^subjkeyfile=\(.*\)/\1/p' \
"$${top_srcdir}"/"$${eeopt}") && \
${create_object} \
-f "$${top_srcdir}"/"$${target}".options \
ROA \
eecertlocation="$${target%.roa}".cer \
eekeylocation="$${eekey}" \
outputfilename="$${target}"
check_DATA += ${CERTS} ${KEYS} ${ROAS}
EXTRA_DIST += ${CERTS:.cer=.options} ${ROAS:=.options}
CLEANFILES += ${CERTS} ${KEYS} ${ROAS}

######################################################################
## roa-ee-munge test
######################################################################
# see ticket #28
TESTS += \
tests/subsystem/roa-ee-munge/roa-ee-munge.tap
check_SCRIPTS += \
tests/subsystem/roa-ee-munge/roa-ee-munge.tap
tests/subsystem/roa-ee-munge/roa-ee-munge.tap: \
tests/subsystem/roa-ee-munge/roa-ee-munge.tap.in
MK_SUBST_FILES_EXEC += \
tests/subsystem/roa-ee-munge/roa-ee-munge.tap
CERTS += \
tests/subsystem/roa-ee-munge/ta-good.cer \
tests/subsystem/roa-ee-munge/ta-bad.cer \
tests/subsystem/roa-ee-munge/ee-good.cer \
tests/subsystem/roa-ee-munge/ee-bad.cer
ROAS += \
tests/subsystem/roa-ee-munge/ee-good.roa \
tests/subsystem/roa-ee-munge/ee-bad.roa
tests/subsystem/roa-ee-munge/ta-good.cer: \
tests/subsystem/roa-ee-munge/ta-good.options \
tests/subsystem/roa-ee-munge/ta-good.key
tests/subsystem/roa-ee-munge/ta-bad.cer: \
tests/subsystem/roa-ee-munge/ta-bad.options \
tests/subsystem/roa-ee-munge/ta-bad.key
tests/subsystem/roa-ee-munge/ee-good.cer: \
tests/subsystem/roa-ee-munge/ee-good.options \
tests/subsystem/roa-ee-munge/ee-good.key
tests/subsystem/roa-ee-munge/ee-good.roa: \
tests/subsystem/roa-ee-munge/ee-good.cer \
tests/subsystem/roa-ee-munge/ee-good.key \
tests/subsystem/roa-ee-munge/ee-good.roa.options
tests/subsystem/roa-ee-munge/ee-bad.cer: \
tests/subsystem/roa-ee-munge/ee-bad.options \
tests/subsystem/roa-ee-munge/ee-bad.key
tests/subsystem/roa-ee-munge/ee-bad.roa: \
tests/subsystem/roa-ee-munge/ee-bad.cer \
tests/subsystem/roa-ee-munge/ee-bad.key \
tests/subsystem/roa-ee-munge/ee-bad.roa.options
clean-local: clean-roa-ee-munge
clean-roa-ee-munge:
rm -rf tests/subsystem/roa-ee-munge/roa-ee-munge.tap.cache

######################################################################
## evil twin tests
######################################################################
EVIL_TWIN_TESTS = \
tests/subsystem/evil-twin/evil-twin-ca-invalid-1.tap \
tests/subsystem/evil-twin/evil-twin-ca-invalid-2.tap \
tests/subsystem/evil-twin/evil-twin-ca-valid-1.tap \
tests/subsystem/evil-twin/evil-twin-ca-valid-2.tap \
tests/subsystem/evil-twin/evil-twin-ee-invalid.tap \
tests/subsystem/evil-twin/evil-twin-ee-valid.tap
TESTS += ${EVIL_TWIN_TESTS}
EXTRA_DIST += ${EVIL_TWIN_TESTS}
check_SCRIPTS += \
tests/subsystem/evil-twin/evil-twin-common.sh
tests/subsystem/evil-twin/evil-twin-common.sh: \
tests/subsystem/evil-twin/evil-twin-common.sh.in
MK_SUBST_FILES += \
tests/subsystem/evil-twin/evil-twin-common.sh
CERTS += \
tests/subsystem/evil-twin/ta-good.cer \
tests/subsystem/evil-twin/ta-evil.cer \
tests/subsystem/evil-twin/ca-good.cer \
tests/subsystem/evil-twin/ca-evil-invalid.cer \
tests/subsystem/evil-twin/ca-evil-valid.cer \
tests/subsystem/evil-twin/test1-ca.cer \
tests/subsystem/evil-twin/test2-ee.cer \
tests/subsystem/evil-twin/ee-good.cer \
tests/subsystem/evil-twin/ee-evil-invalid.cer \
tests/subsystem/evil-twin/ee-evil-valid.cer
ROAS += \
tests/subsystem/evil-twin/test2-ee.roa \
tests/subsystem/evil-twin/ee-good.roa \
tests/subsystem/evil-twin/ee-evil-invalid.roa \
tests/subsystem/evil-twin/ee-evil-valid.roa
tests/subsystem/evil-twin/ta-good.cer: \
tests/subsystem/evil-twin/ta-good.options \
tests/subsystem/evil-twin/ta-good.key
tests/subsystem/evil-twin/ta-evil.cer: \
tests/subsystem/evil-twin/ta-evil.options \
tests/subsystem/evil-twin/ta-evil.key
tests/subsystem/evil-twin/ca-good.cer: \
tests/subsystem/evil-twin/ca-good.options \
tests/subsystem/evil-twin/ca-good.key
tests/subsystem/evil-twin/ca-evil-invalid.cer: \
tests/subsystem/evil-twin/ca-evil-invalid.options \
tests/subsystem/evil-twin/ca-evil-invalid.key
tests/subsystem/evil-twin/ca-evil-valid.cer: \
tests/subsystem/evil-twin/ca-evil-valid.options \
tests/subsystem/evil-twin/ca-evil-valid.key
tests/subsystem/evil-twin/test1-ca.cer: \
tests/subsystem/evil-twin/test1-ca.options \
tests/subsystem/evil-twin/test1-ca.key
tests/subsystem/evil-twin/test2-ee.cer: \
tests/subsystem/evil-twin/test2-ee.options \
tests/subsystem/evil-twin/test2-ee.key
tests/subsystem/evil-twin/test2-ee.roa: \
tests/subsystem/evil-twin/test2-ee.cer \
tests/subsystem/evil-twin/test2-ee.key \
tests/subsystem/evil-twin/test2-ee.roa.options
tests/subsystem/evil-twin/ee-good.cer: \
tests/subsystem/evil-twin/ee-good.options \
tests/subsystem/evil-twin/ee-good.key
tests/subsystem/evil-twin/ee-good.roa: \
tests/subsystem/evil-twin/ee-good.cer \
tests/subsystem/evil-twin/ee-good.key \
tests/subsystem/evil-twin/ee-good.roa.options
tests/subsystem/evil-twin/ee-evil-invalid.cer: \
tests/subsystem/evil-twin/ee-evil-invalid.options \
tests/subsystem/evil-twin/ee-evil-invalid.key
tests/subsystem/evil-twin/ee-evil-invalid.roa: \
tests/subsystem/evil-twin/ee-evil-invalid.cer \
tests/subsystem/evil-twin/ee-evil-invalid.key \
tests/subsystem/evil-twin/ee-evil-invalid.roa.options
tests/subsystem/evil-twin/ee-evil-valid.cer: \
tests/subsystem/evil-twin/ee-evil-valid.options \
tests/subsystem/evil-twin/ee-evil-valid.key
tests/subsystem/evil-twin/ee-evil-valid.roa: \
tests/subsystem/evil-twin/ee-evil-valid.cer \
tests/subsystem/evil-twin/ee-evil-valid.key \
tests/subsystem/evil-twin/ee-evil-valid.roa.options
clean-local: clean-evil-twin
clean-evil-twin:
rm -rf ${EVIL_TWIN_TESTS:=.cache}

######################################################################
## chaser
######################################################################
pkglibexec_PROGRAMS += bin/rpki/chaser

bin_rpki_chaser_LDADD = \
Expand Down
2 changes: 2 additions & 0 deletions mk/tests-environment.mk
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ cat-logs:
echo; \
fi; \
done

EXTRA_DIST += tests/util.sh
5 changes: 5 additions & 0 deletions tests/subsystem/evil-twin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*.cache/
/*.cer
/*.key
/*.roa
/evil-twin-common.sh
21 changes: 21 additions & 0 deletions tests/subsystem/evil-twin/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
This directory contains tests for vulnerabilities to the "evil twin"
attack.

The goal of the evil twin attack is to make a good object look bad.
The malicious CA signs and publishes a certificate that reuses the
public key, subject, and SKI from a victim certificate. This new
certificate (the "evil twin" certificate) is either:

* invalid because it uses resources not held by the malicious CA, or

* valid but not a valid parent of the objects signed by the victim
certificate because the objects signed by the victim certificate
have resources outside of the evil twin certificate.

Either way, if the RP software is buggy and considers the evil twin to
be the parent of objects that were actually signed by the victim
(because the subject, SKI, and public keys match), those good objects
would be incorrectly invalidated.

The test scripts in this directory use different toy hierarchies to
cover a wide range of scenarios.
12 changes: 12 additions & 0 deletions tests/subsystem/evil-twin/ca-evil-invalid.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type=CA
issuer=ta-evil
subject=ca-good
aia=rsync://invalid/
sia=r:rsync://invalid/,m:rsync://invalid/invalid.mft
ipv4=0.0.0.0/16
ipv6=::/32
as=1-63
selfsigned=false
parentcertfile=tests/subsystem/evil-twin/ta-evil.cer
parentkeyfile=tests/subsystem/evil-twin/ta-evil.key
subjkeyfile=tests/subsystem/evil-twin/ca-good.key
12 changes: 12 additions & 0 deletions tests/subsystem/evil-twin/ca-evil-valid.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type=CA
issuer=ta-evil
subject=ca-good
aia=rsync://invalid/
sia=r:rsync://invalid/,m:rsync://invalid/invalid.mft
ipv4=1.0.0.0/16
ipv6=1::/32
as=128-191
selfsigned=false
parentcertfile=tests/subsystem/evil-twin/ta-evil.cer
parentkeyfile=tests/subsystem/evil-twin/ta-evil.key
subjkeyfile=tests/subsystem/evil-twin/ca-good.key
12 changes: 12 additions & 0 deletions tests/subsystem/evil-twin/ca-good.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type=CA
issuer=ta-good
subject=ca-good
aia=rsync://invalid/
sia=r:rsync://invalid/,m:rsync://invalid/invalid.mft
ipv4=0.0.0.0/16
ipv6=::/32
as=1-63
selfsigned=false
parentcertfile=tests/subsystem/evil-twin/ta-good.cer
parentkeyfile=tests/subsystem/evil-twin/ta-good.key
subjkeyfile=tests/subsystem/evil-twin/ca-good.key
12 changes: 12 additions & 0 deletions tests/subsystem/evil-twin/ee-evil-invalid.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type=EE
issuer=ta-evil
subject=ee-good
aia=rsync://invalid/
sia=s:rsync://invalid/
ipv4=0.0.0.0/24
ipv6=::/48
as=1-31
selfsigned=false
parentcertfile=tests/subsystem/evil-twin/ta-evil.cer
parentkeyfile=tests/subsystem/evil-twin/ta-evil.key
subjkeyfile=tests/subsystem/evil-twin/ee-good.key
3 changes: 3 additions & 0 deletions tests/subsystem/evil-twin/ee-evil-invalid.roa.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
roaipv4=0.0.0.0/25
roaipv6=::/64
asid=1
12 changes: 12 additions & 0 deletions tests/subsystem/evil-twin/ee-evil-valid.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type=EE
issuer=ta-evil
subject=ee-good
aia=rsync://invalid/
sia=s:rsync://invalid/
ipv4=1.0.0.0/24
ipv6=1::/48
as=128-159
selfsigned=false
parentcertfile=tests/subsystem/evil-twin/ta-evil.cer
parentkeyfile=tests/subsystem/evil-twin/ta-evil.key
subjkeyfile=tests/subsystem/evil-twin/ee-good.key
3 changes: 3 additions & 0 deletions tests/subsystem/evil-twin/ee-evil-valid.roa.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
roaipv4=0.0.0.0/25
roaipv6=::/64
asid=1
12 changes: 12 additions & 0 deletions tests/subsystem/evil-twin/ee-good.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type=EE
issuer=ta-good
subject=ee-good
aia=rsync://invalid/
sia=s:rsync://invalid/
ipv4=0.0.0.0/24
ipv6=::/48
as=1-31
selfsigned=false
parentcertfile=tests/subsystem/evil-twin/ta-good.cer
parentkeyfile=tests/subsystem/evil-twin/ta-good.key
subjkeyfile=tests/subsystem/evil-twin/ee-good.key
3 changes: 3 additions & 0 deletions tests/subsystem/evil-twin/ee-good.roa.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
roaipv4=0.0.0.0/25
roaipv6=::/64
asid=1
40 changes: 40 additions & 0 deletions tests/subsystem/evil-twin/evil-twin-ca-invalid-1.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh

# This scenario uses the following forest:
#
#
# Good TA (valid) Evil TA (valid)
# IPv4: 0.0.0.0/8 IPv4: 1.0.0.0/8
# IPv6: ::/16 IPv6: 1::/16
# AS: 1-127 AS: 128-255
# | |
# | |
# Good CA (valid) Evil CA (invalid, this is the "evil twin" of Good CA)
# IPv4: 0.0.0.0/16 IPv4: 0.0.0.0/16 (outside of issuer resoures)
# IPv6: ::/32 IPv6: ::/32 (outside of issuer resources)
# AS: 1-63 AS: 1-63 (outside of issuer resources)
# |
# |
# Test1 CA (valid)
# IPv4: 0.0.0.0/24
# IPv6: ::/48
# AS: 1-31
#
# The five objects above are added to the database one at a time. To
# ensure that the order in which the objects are added does not affect
# the outcome, all permutations are tried (the database is scrubbed
# between permutations). The result looks like this:
#
# 1. ta-good.cer ta-evil.cer ca-good.cer ca-evil.cer test1-ca.cer
# 2. ta-good.cer ta-evil.cer ca-good.cer test1-ca.cer ca-evil.cer
# 3. ta-good.cer ta-evil.cer ca-evil.cer ca-good.cer test1-ca.cer
# 4. ta-good.cer ta-evil.cer ca-evil.cer test1-ca.cer ca-good.cer
# ...
# 120. test1-ca.cer ca-evil.cer ca-good.cer ta-evil.cer ta-good.cer

. "${TESTS_BUILDDIR}"/evil-twin-common.sh || exit 1

files="ta-good.cer ta-evil.cer ca-good.cer ca-evil-invalid.cer test1-ca.cer"
exp="ta-good.cer ta-evil.cer ca-good.cer test1-ca.cer"

run_tests "${files}" "${exp}"
32 changes: 32 additions & 0 deletions tests/subsystem/evil-twin/evil-twin-ca-invalid-2.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

# This scenario is the same as evil-twin-ca-invalid-1 except the Test1
# CA certificate is replaced by a ROA:
#
# Good TA (valid) Evil TA (valid)
# IPv4: 0.0.0.0/8 IPv4: 1.0.0.0/8
# IPv6: ::/16 IPv6: 1::/16
# AS: 1-127 AS: 128-255
# | |
# | |
# Good CA (valid) Evil CA (invalid, this is the "evil twin" of Good CA)
# IPv4: 0.0.0.0/16 IPv4: 0.0.0.0/16 (outside of issuer resoures)
# IPv6: ::/32 IPv6: ::/32 (outside of issuer resources)
# AS: 1-63 AS: 1-63 (outside of issuer resources)
# |
# |
# Test2 ROA (valid)
# IPv4: 0.0.0.0/25
# IPv6: ::/64
# AS: 1
# via Test2 EE (valid):
# IPv4: 0.0.0.0/24
# IPv6: ::/48
# AS: 1-31

. "${TESTS_BUILDDIR}"/evil-twin-common.sh || exit 1

files="ta-good.cer ta-evil.cer ca-good.cer ca-evil-invalid.cer test2-ee.roa"
exp="ta-good.cer ta-evil.cer ca-good.cer test2-ee.roa test2-ee.roa.cer"

run_tests "${files}" "${exp}"
Loading

0 comments on commit 8652b2f

Please sign in to comment.