test_local_revocation.py.in 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!@PYTHON@
  2. # This file is part of GNUnet.
  3. # (C) 2010, 2018 Christian Grothoff (and other contributing authors)
  4. #
  5. # GNUnet is free software: you can redistribute it and/or modify it
  6. # under the terms of the GNU Affero General Public License as published
  7. # by the Free Software Foundation, either version 3 of the License,
  8. # or (at your option) any later version.
  9. #
  10. # GNUnet is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # SPDX-License-Identifier: AGPL3.0-or-later
  19. #
  20. # Testcase for ego revocation
  21. import sys
  22. import os
  23. import subprocess
  24. import re
  25. import shutil
  26. if os.name == 'posix':
  27. config = 'gnunet-config'
  28. gnunetarm = 'gnunet-arm'
  29. ident = 'gnunet-identity'
  30. revoc = './gnunet-revocation'
  31. elif os.name == 'nt':
  32. config = 'gnunet-config.exe'
  33. gnunetarm = 'gnunet-arm.exe'
  34. ident = 'gnunet-identity.exe'
  35. revoc = './gnunet-revocation.exe'
  36. TEST_CONFIGURATION = "test_revocation.conf"
  37. TEST_REVOCATION_EGO = "revoc_test"
  38. get_clean = subprocess.Popen([config, '-c', TEST_CONFIGURATION, '-s', 'PATHS', '-o', 'GNUNET_HOME', '-f'], stdout=subprocess.PIPE)
  39. cleandir, x = get_clean.communicate()
  40. cleandir = cleandir.decode("utf-8")
  41. cleandir = cleandir.rstrip('\n').rstrip('\r')
  42. if os.path.isdir(cleandir):
  43. shutil.rmtree(cleandir, True)
  44. res = 0
  45. arm = subprocess.Popen([gnunetarm, '-s', '-c', TEST_CONFIGURATION])
  46. arm.communicate()
  47. try:
  48. print("Creating an ego " + TEST_REVOCATION_EGO)
  49. sys.stdout.flush()
  50. sys.stderr.flush()
  51. idc = subprocess.Popen([ident, '-C', TEST_REVOCATION_EGO, '-c', TEST_CONFIGURATION])
  52. idc.communicate()
  53. if idc.returncode != 0:
  54. raise Exception("gnunet-identity failed to create an ego `" + TEST_REVOCATION_EGO + "'")
  55. sys.stdout.flush()
  56. sys.stderr.flush()
  57. idd = subprocess.Popen([ident, '-d'], stdout=subprocess.PIPE)
  58. rev_key, x = idd.communicate()
  59. rev_key = rev_key.decode("utf-8")
  60. if len(rev_key.split()) < 3:
  61. raise Exception("can't get revocation key out of `" + rev_key + "'")
  62. rev_key = rev_key.split()[2]
  63. print("Testing key " + rev_key)
  64. sys.stdout.flush()
  65. sys.stderr.flush()
  66. tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE)
  67. output_not_revoked, x = tst.communicate()
  68. output_not_revoked = output_not_revoked.decode("utf-8")
  69. if tst.returncode != 0:
  70. raise Exception("gnunet-revocation failed to test a key - " + str(tst.returncode) + ": " + output_not_revoked)
  71. if 'valid' not in output_not_revoked:
  72. res = 1
  73. print("Key was not valid")
  74. else:
  75. print("Key was valid")
  76. print("Revoking key " + rev_key)
  77. sys.stdout.flush()
  78. sys.stderr.flush()
  79. rev = subprocess.Popen([revoc, '-R', TEST_REVOCATION_EGO, '-p', '-c', TEST_CONFIGURATION])
  80. rev.communicate()
  81. if rev.returncode != 0:
  82. raise Exception("gnunet-revocation failed to revoke a key")
  83. print("Testing revoked key " + rev_key)
  84. sys.stdout.flush()
  85. sys.stderr.flush()
  86. tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE)
  87. output_revoked, x = tst.communicate()
  88. output_revoked = output_revoked.decode("utf-8")
  89. if tst.returncode != 0:
  90. raise Exception("gnunet-revocation failed to test a revoked key")
  91. if 'revoked' not in output_revoked:
  92. res = 1
  93. print("Key was not revoked")
  94. else:
  95. print("Key was revoked")
  96. finally:
  97. arm = subprocess.Popen([gnunetarm, '-e', '-c', TEST_CONFIGURATION])
  98. arm.communicate()
  99. if os.path.isdir(cleandir):
  100. shutil.rmtree(cleandir, True)
  101. sys.exit(res)