]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add tests for signature verification
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 28 Feb 2018 07:59:17 +0000 (13:59 +0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 28 Feb 2018 11:06:45 +0000 (17:06 +0600)
src/tests/modules/cipher/rsa_sign_verify.unlang [new file with mode: 0644]

diff --git a/src/tests/modules/cipher/rsa_sign_verify.unlang b/src/tests/modules/cipher/rsa_sign_verify.unlang
new file mode 100644 (file)
index 0000000..1bca2ef
--- /dev/null
@@ -0,0 +1,108 @@
+update request {
+       &Tmp-String-0 := "Hello world!"
+}
+
+update request {
+       &Tmp-Octets-0 := "%{cipher_rsa_sign:%{Tmp-String-0}}"
+}
+
+if (!&Tmp-Octets-0) {
+       test_fail
+}
+else {
+       test_pass
+}
+
+if (<octets>&Tmp-String-0[0] == &Tmp-Octets-0[0]) {
+       test_fail
+}
+else {
+       test_pass
+}
+
+#
+#  Pass the signature and the original message to the verification function
+#
+update request {
+       &Tmp-String-0 := "%{cipher_rsa_verify:%{Tmp-Octets-0} %{Tmp-String-0}}"
+}
+
+if (&Tmp-String-0 != 'yes') {
+       test_fail
+}
+else {
+       test_pass
+}
+
+#
+#  Verification should now fail
+#
+update request {
+       &Tmp-String-0 := "Goodbye world!"
+}
+update request {
+       &Tmp-String-0 := "%{cipher_rsa_verify:%{Tmp-Octets-0} %{Tmp-String-0}}"
+}
+
+if (&Tmp-String-0 != 'no') {
+       test_fail
+}
+else {
+       test_pass
+}
+
+#
+#  Repeat tests to ensure there are no issues with EVP_PKEY_CTX reuse
+#
+update request {
+       &Tmp-String-0 := "Hello nurse!"
+}
+
+update request {
+       &Tmp-Octets-0 := "%{cipher_rsa_sign:%{Tmp-String-0}}"
+}
+
+if (!&Tmp-Octets-0) {
+       test_fail
+}
+else {
+       test_pass
+}
+
+if (<octets>&Tmp-String-0[0] == &Tmp-Octets-0[0]) {
+       test_fail
+}
+else {
+       test_pass
+}
+
+#
+#  Pass the signature and the original message to the verification function
+#
+update request {
+       &Tmp-String-0 := "%{cipher_rsa_verify:%{Tmp-Octets-0} %{Tmp-String-0}}"
+}
+
+if (&Tmp-String-0 != 'yes') {
+       test_fail
+}
+else {
+       test_pass
+}
+
+#
+#  Verification should now fail
+#
+update request {
+       &Tmp-String-0 := "Goodbye nurse!"
+}
+update request {
+       &Tmp-String-0 := "%{cipher_rsa_verify:%{Tmp-Octets-0} %{Tmp-String-0}}"
+}
+
+if (&Tmp-String-0 != 'no') {
+       test_fail
+}
+else {
+       test_pass
+}