1
0

ticket47838_test.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. import os
  2. import sys
  3. import time
  4. import ldap
  5. import logging
  6. import socket
  7. import pytest
  8. import shutil
  9. from lib389 import DirSrv, Entry, tools
  10. from lib389 import DirSrvTools
  11. from lib389.tools import DirSrvTools
  12. from lib389._constants import *
  13. from lib389.properties import *
  14. from constants import *
  15. log = logging.getLogger(__name__)
  16. installation_prefix = None
  17. CONFIG_DN = 'cn=config'
  18. ENCRYPTION_DN = 'cn=encryption,%s' % CONFIG_DN
  19. RSA = 'RSA'
  20. RSA_DN = 'cn=%s,%s' % (RSA, ENCRYPTION_DN)
  21. LDAPSPORT = '10636'
  22. SERVERCERT = 'Server-Cert'
  23. plus_all_ecount = 0
  24. plus_all_dcount = 0
  25. plus_all_ecount_noweak = 0
  26. plus_all_dcount_noweak = 0
  27. class TopologyStandalone(object):
  28. def __init__(self, standalone):
  29. standalone.open()
  30. self.standalone = standalone
  31. @pytest.fixture(scope="module")
  32. def topology(request):
  33. '''
  34. This fixture is used to standalone topology for the 'module'.
  35. At the beginning, It may exists a standalone instance.
  36. It may also exists a backup for the standalone instance.
  37. Principle:
  38. If standalone instance exists:
  39. restart it
  40. If backup of standalone exists:
  41. create/rebind to standalone
  42. restore standalone instance from backup
  43. else:
  44. Cleanup everything
  45. remove instance
  46. remove backup
  47. Create instance
  48. Create backup
  49. '''
  50. global installation_prefix
  51. if installation_prefix:
  52. args_instance[SER_DEPLOYED_DIR] = installation_prefix
  53. standalone = DirSrv(verbose=False)
  54. # Args for the standalone instance
  55. args_instance[SER_HOST] = HOST_STANDALONE
  56. args_instance[SER_PORT] = PORT_STANDALONE
  57. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  58. args_standalone = args_instance.copy()
  59. standalone.allocate(args_standalone)
  60. # Get the status of the backups
  61. backup_standalone = standalone.checkBackupFS()
  62. # Get the status of the instance and restart it if it exists
  63. instance_standalone = standalone.exists()
  64. if instance_standalone:
  65. # assuming the instance is already stopped, just wait 5 sec max
  66. standalone.stop(timeout=5)
  67. try:
  68. standalone.start(timeout=10)
  69. except ldap.SERVER_DOWN:
  70. pass
  71. if backup_standalone:
  72. # The backup exist, assuming it is correct
  73. # we just re-init the instance with it
  74. if not instance_standalone:
  75. standalone.create()
  76. # Used to retrieve configuration information (dbdir, confdir...)
  77. standalone.open()
  78. # restore standalone instance from backup
  79. standalone.stop(timeout=10)
  80. standalone.restoreFS(backup_standalone)
  81. standalone.start(timeout=10)
  82. else:
  83. # We should be here only in two conditions
  84. # - This is the first time a test involve standalone instance
  85. # - Something weird happened (instance/backup destroyed)
  86. # so we discard everything and recreate all
  87. # Remove the backup. So even if we have a specific backup file
  88. # (e.g backup_standalone) we clear backup that an instance may have created
  89. if backup_standalone:
  90. standalone.clearBackupFS()
  91. # Remove the instance
  92. if instance_standalone:
  93. standalone.delete()
  94. # Create the instance
  95. standalone.create()
  96. # Used to retrieve configuration information (dbdir, confdir...)
  97. standalone.open()
  98. # Time to create the backups
  99. standalone.stop(timeout=10)
  100. standalone.backupfile = standalone.backupFS()
  101. standalone.start(timeout=10)
  102. # clear the tmp directory
  103. standalone.clearTmpDir(__file__)
  104. #
  105. # Here we have standalone instance up and running
  106. # Either coming from a backup recovery
  107. # or from a fresh (re)init
  108. # Time to return the topology
  109. return TopologyStandalone(standalone)
  110. def _header(topology, label):
  111. topology.standalone.log.info("\n\n###############################################")
  112. topology.standalone.log.info("#######")
  113. topology.standalone.log.info("####### %s" % label)
  114. topology.standalone.log.info("#######")
  115. topology.standalone.log.info("###############################################")
  116. def test_ticket47838_init(topology):
  117. """
  118. Generate self signed cert and import it to the DS cert db.
  119. Enable SSL
  120. """
  121. _header(topology, 'Testing Ticket 47838 - harden the list of ciphers available by default')
  122. conf_dir = topology.standalone.confdir
  123. log.info("\n######################### Checking existing certs ######################\n")
  124. os.system('certutil -L -d %s -n "CA certificate"' % conf_dir)
  125. os.system('certutil -L -d %s -n "%s"' % (conf_dir, SERVERCERT))
  126. log.info("\n######################### Create a password file ######################\n")
  127. pwdfile = '%s/pwdfile.txt' % (conf_dir)
  128. opasswd = os.popen("(ps -ef ; w ) | sha1sum | awk '{print $1}'", "r")
  129. passwd = opasswd.readline()
  130. pwdfd = open(pwdfile, "w")
  131. pwdfd.write(passwd)
  132. pwdfd.close()
  133. log.info("\n######################### Create a noise file ######################\n")
  134. noisefile = '%s/noise.txt' % (conf_dir)
  135. noise = os.popen("(w ; ps -ef ; date ) | sha1sum | awk '{print $1}'", "r")
  136. noisewdfd = open(noisefile, "w")
  137. noisewdfd.write(noise.readline())
  138. noisewdfd.close()
  139. log.info("\n######################### Create key3.db and cert8.db database ######################\n")
  140. os.system("ls %s" % pwdfile)
  141. os.system("cat %s" % pwdfile)
  142. os.system('certutil -N -d %s -f %s' % (conf_dir, pwdfile))
  143. log.info("\n######################### Creating encryption key for CA ######################\n")
  144. os.system('certutil -G -d %s -z %s -f %s' % (conf_dir, noisefile, pwdfile))
  145. log.info("\n######################### Creating self-signed CA certificate ######################\n")
  146. os.system('( echo y ; echo ; echo y ) | certutil -S -n "CA certificate" -s "cn=CAcert" -x -t "CT,," -m 1000 -v 120 -d %s -z %s -f %s -2' % (conf_dir, noisefile, pwdfile))
  147. log.info("\n######################### Exporting the CA certificate to cacert.asc ######################\n")
  148. cafile = '%s/cacert.asc' % conf_dir
  149. catxt = os.popen('certutil -L -d %s -n "CA certificate" -a' % conf_dir)
  150. cafd = open(cafile, "w")
  151. while True:
  152. line = catxt.readline()
  153. if (line == ''):
  154. break
  155. cafd.write(line)
  156. cafd.close()
  157. log.info("\n######################### Generate the server certificate ######################\n")
  158. ohostname = os.popen('hostname --fqdn', "r")
  159. myhostname = ohostname.readline()
  160. os.system('certutil -S -n "%s" -s "cn=%s,ou=389 Directory Server" -c "CA certificate" -t "u,u,u" -m 1001 -v 120 -d %s -z %s -f %s' % (SERVERCERT, myhostname.rstrip(), conf_dir, noisefile, pwdfile))
  161. log.info("\n######################### create the pin file ######################\n")
  162. pinfile = '%s/pin.txt' % (conf_dir)
  163. pintxt = 'Internal (Software) Token:%s' % passwd
  164. pinfd = open(pinfile, "w")
  165. pinfd.write(pintxt)
  166. pinfd.close()
  167. log.info("\n######################### enable SSL in the directory server with all ciphers ######################\n")
  168. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  169. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3', 'on'),
  170. (ldap.MOD_REPLACE, 'nsSSLClientAuth', 'allowed'),
  171. (ldap.MOD_REPLACE, 'allowWeakCipher', 'on'),
  172. (ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+all')])
  173. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-security', 'on'),
  174. (ldap.MOD_REPLACE, 'nsslapd-ssl-check-hostname', 'off'),
  175. (ldap.MOD_REPLACE, 'nsslapd-secureport', LDAPSPORT)])
  176. topology.standalone.add_s(Entry((RSA_DN, {'objectclass': "top nsEncryptionModule".split(),
  177. 'cn': RSA,
  178. 'nsSSLPersonalitySSL': SERVERCERT,
  179. 'nsSSLToken': 'internal (software)',
  180. 'nsSSLActivation': 'on'})))
  181. def test_ticket47838_run_0(topology):
  182. """
  183. Check nsSSL3Ciphers: +all
  184. All ciphers are enabled except null.
  185. Note: allowWeakCipher: on
  186. """
  187. _header(topology, 'Test Case 1 - Check the ciphers availability for "+all"; allowWeakCipher: on')
  188. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  189. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '64')])
  190. log.info("\n######################### Restarting the server ######################\n")
  191. topology.standalone.restart(timeout=120)
  192. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  193. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  194. ecount = int(enabled.readline().rstrip())
  195. dcount = int(disabled.readline().rstrip())
  196. log.info("Enabled ciphers: %d" % ecount)
  197. log.info("Disabled ciphers: %d" % dcount)
  198. assert ecount >= 60
  199. assert dcount <= 7
  200. global plus_all_ecount
  201. global plus_all_dcount
  202. plus_all_ecount = ecount
  203. plus_all_dcount = dcount
  204. weak = os.popen('egrep "SSL alert:" %s | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  205. wcount = int(weak.readline().rstrip())
  206. log.info("Weak ciphers: %d" % wcount)
  207. assert wcount <= 29
  208. def test_ticket47838_run_1(topology):
  209. """
  210. Check nsSSL3Ciphers: +all
  211. All ciphers are enabled except null.
  212. Note: default allowWeakCipher (i.e., off) for +all
  213. """
  214. _header(topology, 'Test Case 2 - Check the ciphers availability for "+all" with default allowWeakCiphers')
  215. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  216. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '64')])
  217. # Make sure allowWeakCipher is not set.
  218. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_DELETE, 'allowWeakCipher', None)])
  219. log.info("\n######################### Restarting the server ######################\n")
  220. log.info("\n######################### Restarting the server ######################\n")
  221. topology.standalone.stop(timeout=10)
  222. os.system('mv %s %s.47838_0' % (topology.standalone.errlog, topology.standalone.errlog))
  223. os.system('touch %s' % (topology.standalone.errlog))
  224. topology.standalone.start(timeout=120)
  225. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  226. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  227. ecount = int(enabled.readline().rstrip())
  228. dcount = int(disabled.readline().rstrip())
  229. global plus_all_ecount_noweak
  230. global plus_all_dcount_noweak
  231. plus_all_ecount_noweak = ecount
  232. plus_all_dcount_noweak = dcount
  233. log.info("Enabled ciphers: %d" % ecount)
  234. log.info("Disabled ciphers: %d" % dcount)
  235. assert ecount >= 31
  236. assert dcount <= 36
  237. weak = os.popen('egrep "SSL alert:" %s | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  238. wcount = int(weak.readline().rstrip())
  239. log.info("Weak ciphers: %d" % wcount)
  240. assert wcount <= 29
  241. def test_ticket47838_run_2(topology):
  242. """
  243. Check nsSSL3Ciphers: +rsa_aes_128_sha,+rsa_aes_256_sha
  244. rsa_aes_128_sha, tls_rsa_aes_128_sha, rsa_aes_256_sha, tls_rsa_aes_256_sha are enabled.
  245. default allowWeakCipher
  246. """
  247. _header(topology, 'Test Case 3 - Check the ciphers availability for "+rsa_aes_128_sha,+rsa_aes_256_sha" with default allowWeakCipher')
  248. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  249. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+rsa_aes_128_sha,+rsa_aes_256_sha')])
  250. log.info("\n######################### Restarting the server ######################\n")
  251. topology.standalone.stop(timeout=10)
  252. os.system('mv %s %s.47838_1' % (topology.standalone.errlog, topology.standalone.errlog))
  253. os.system('touch %s' % (topology.standalone.errlog))
  254. topology.standalone.start(timeout=120)
  255. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  256. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  257. ecount = int(enabled.readline().rstrip())
  258. dcount = int(disabled.readline().rstrip())
  259. log.info("Enabled ciphers: %d" % ecount)
  260. log.info("Disabled ciphers: %d" % dcount)
  261. global plus_all_ecount
  262. global plus_all_dcount
  263. assert ecount == 2
  264. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  265. def test_ticket47838_run_3(topology):
  266. """
  267. Check nsSSL3Ciphers: -all
  268. All ciphers are disabled.
  269. default allowWeakCipher
  270. """
  271. _header(topology, 'Test Case 4 - Check the ciphers availability for "-all"')
  272. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  273. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '-all')])
  274. log.info("\n######################### Restarting the server ######################\n")
  275. topology.standalone.stop(timeout=10)
  276. os.system('mv %s %s.47838_2' % (topology.standalone.errlog, topology.standalone.errlog))
  277. os.system('touch %s' % (topology.standalone.errlog))
  278. topology.standalone.start(timeout=120)
  279. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  280. ecount = int(enabled.readline().rstrip())
  281. log.info("Enabled ciphers: %d" % ecount)
  282. global plus_all_ecount
  283. assert ecount == 0
  284. disabledmsg = os.popen('egrep "Disabling SSL" %s' % topology.standalone.errlog)
  285. log.info("Disabling SSL message?: %s" % disabledmsg.readline())
  286. assert disabledmsg != ''
  287. def test_ticket47838_run_4(topology):
  288. """
  289. Check no nsSSL3Ciphers
  290. Default ciphers are enabled.
  291. default allowWeakCipher
  292. """
  293. _header(topology, 'Test Case 5 - Check no nssSSL3Chiphers (default setting) with default allowWeakCipher')
  294. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  295. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_DELETE, 'nsSSL3Ciphers', '-all')])
  296. log.info("\n######################### Restarting the server ######################\n")
  297. topology.standalone.stop(timeout=10)
  298. os.system('mv %s %s.47838_3' % (topology.standalone.errlog, topology.standalone.errlog))
  299. os.system('touch %s' % (topology.standalone.errlog))
  300. topology.standalone.start(timeout=120)
  301. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  302. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  303. ecount = int(enabled.readline().rstrip())
  304. dcount = int(disabled.readline().rstrip())
  305. log.info("Enabled ciphers: %d" % ecount)
  306. log.info("Disabled ciphers: %d" % dcount)
  307. global plus_all_ecount
  308. global plus_all_dcount
  309. assert ecount == 12
  310. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  311. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  312. wcount = int(weak.readline().rstrip())
  313. log.info("Weak ciphers in the default setting: %d" % wcount)
  314. assert wcount == 0
  315. def test_ticket47838_run_5(topology):
  316. """
  317. Check nsSSL3Ciphers: default
  318. Default ciphers are enabled.
  319. default allowWeakCipher
  320. """
  321. _header(topology, 'Test Case 6 - Check default nssSSL3Chiphers (default setting) with default allowWeakCipher')
  322. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  323. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', 'default')])
  324. log.info("\n######################### Restarting the server ######################\n")
  325. topology.standalone.stop(timeout=10)
  326. os.system('mv %s %s.47838_4' % (topology.standalone.errlog, topology.standalone.errlog))
  327. os.system('touch %s' % (topology.standalone.errlog))
  328. topology.standalone.start(timeout=120)
  329. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  330. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  331. ecount = int(enabled.readline().rstrip())
  332. dcount = int(disabled.readline().rstrip())
  333. log.info("Enabled ciphers: %d" % ecount)
  334. log.info("Disabled ciphers: %d" % dcount)
  335. global plus_all_ecount
  336. global plus_all_dcount
  337. assert ecount == 12
  338. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  339. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  340. wcount = int(weak.readline().rstrip())
  341. log.info("Weak ciphers in the default setting: %d" % wcount)
  342. assert wcount == 0
  343. def test_ticket47838_run_6(topology):
  344. """
  345. Check nssSSL3Chiphers: +all,-rsa_rc4_128_md5
  346. All ciphers are disabled.
  347. default allowWeakCipher
  348. """
  349. _header(topology, 'Test Case 7 - Check nssSSL3Chiphers: +all,-tls_dhe_rsa_aes_128_gcm_sha with default allowWeakCipher')
  350. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  351. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+all,-tls_dhe_rsa_aes_128_gcm_sha')])
  352. log.info("\n######################### Restarting the server ######################\n")
  353. topology.standalone.stop(timeout=10)
  354. os.system('mv %s %s.47838_5' % (topology.standalone.errlog, topology.standalone.errlog))
  355. os.system('touch %s' % (topology.standalone.errlog))
  356. topology.standalone.start(timeout=120)
  357. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  358. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  359. ecount = int(enabled.readline().rstrip())
  360. dcount = int(disabled.readline().rstrip())
  361. log.info("Enabled ciphers: %d" % ecount)
  362. log.info("Disabled ciphers: %d" % dcount)
  363. global plus_all_ecount_noweak
  364. global plus_all_dcount_noweak
  365. log.info("ALL Ecount: %d" % plus_all_ecount_noweak)
  366. log.info("ALL Dcount: %d" % plus_all_dcount_noweak)
  367. assert ecount == (plus_all_ecount_noweak - 1)
  368. assert dcount == (plus_all_dcount_noweak + 1)
  369. def test_ticket47838_run_7(topology):
  370. """
  371. Check nssSSL3Chiphers: -all,+rsa_rc4_128_md5
  372. All ciphers are disabled.
  373. default allowWeakCipher
  374. """
  375. _header(topology, 'Test Case 8 - Check nssSSL3Chiphers: -all,+rsa_rc4_128_md5 with default allowWeakCipher')
  376. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  377. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '-all,+rsa_rc4_128_md5')])
  378. log.info("\n######################### Restarting the server ######################\n")
  379. topology.standalone.stop(timeout=10)
  380. os.system('mv %s %s.47838_6' % (topology.standalone.errlog, topology.standalone.errlog))
  381. os.system('touch %s' % (topology.standalone.errlog))
  382. topology.standalone.start(timeout=120)
  383. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  384. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  385. ecount = int(enabled.readline().rstrip())
  386. dcount = int(disabled.readline().rstrip())
  387. log.info("Enabled ciphers: %d" % ecount)
  388. log.info("Disabled ciphers: %d" % dcount)
  389. global plus_all_ecount
  390. global plus_all_dcount
  391. assert ecount == 1
  392. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  393. def test_ticket47838_run_8(topology):
  394. """
  395. Check nsSSL3Ciphers: default + allowWeakCipher: off
  396. Strong Default ciphers are enabled.
  397. """
  398. _header(topology, 'Test Case 9 - Check default nssSSL3Chiphers (default setting + allowWeakCipher: off)')
  399. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  400. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', 'default'),
  401. (ldap.MOD_REPLACE, 'allowWeakCipher', 'off')])
  402. log.info("\n######################### Restarting the server ######################\n")
  403. topology.standalone.stop(timeout=10)
  404. os.system('mv %s %s.47838_7' % (topology.standalone.errlog, topology.standalone.errlog))
  405. os.system('touch %s' % (topology.standalone.errlog))
  406. topology.standalone.start(timeout=120)
  407. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  408. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  409. ecount = int(enabled.readline().rstrip())
  410. dcount = int(disabled.readline().rstrip())
  411. log.info("Enabled ciphers: %d" % ecount)
  412. log.info("Disabled ciphers: %d" % dcount)
  413. global plus_all_ecount
  414. global plus_all_dcount
  415. assert ecount == 12
  416. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  417. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  418. wcount = int(weak.readline().rstrip())
  419. log.info("Weak ciphers in the default setting: %d" % wcount)
  420. assert wcount == 0
  421. def test_ticket47838_run_9(topology):
  422. """
  423. Check no nsSSL3Ciphers
  424. Default ciphers are enabled.
  425. allowWeakCipher: on
  426. nsslapd-errorlog-level: 0
  427. """
  428. _header(topology, 'Test Case 10 - Check no nssSSL3Chiphers (default setting) with no errorlog-level & allowWeakCipher on')
  429. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  430. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', None),
  431. (ldap.MOD_REPLACE, 'allowWeakCipher', 'on')])
  432. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', None)])
  433. log.info("\n######################### Restarting the server ######################\n")
  434. topology.standalone.stop(timeout=10)
  435. os.system('mv %s %s.47838_8' % (topology.standalone.errlog, topology.standalone.errlog))
  436. os.system('touch %s' % (topology.standalone.errlog))
  437. topology.standalone.start(timeout=120)
  438. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  439. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  440. ecount = int(enabled.readline().rstrip())
  441. dcount = int(disabled.readline().rstrip())
  442. log.info("Enabled ciphers: %d" % ecount)
  443. log.info("Disabled ciphers: %d" % dcount)
  444. assert ecount == 23
  445. assert dcount == 0
  446. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  447. wcount = int(weak.readline().rstrip())
  448. log.info("Weak ciphers in the default setting: %d" % wcount)
  449. assert wcount == 11
  450. def test_ticket47838_run_10(topology):
  451. """
  452. Check nssSSL3Chiphers: -TLS_RSA_WITH_NULL_MD5,+TLS_RSA_WITH_RC4_128_MD5,
  453. +TLS_RSA_EXPORT_WITH_RC4_40_MD5,+TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5,
  454. +TLS_DHE_RSA_WITH_DES_CBC_SHA,+SSL_RSA_FIPS_WITH_DES_CBC_SHA,
  455. +TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA,+SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA,
  456. +TLS_RSA_EXPORT1024_WITH_RC4_56_SHA,+TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA,
  457. -SSL_CK_RC4_128_WITH_MD5,-SSL_CK_RC4_128_EXPORT40_WITH_MD5,
  458. -SSL_CK_RC2_128_CBC_WITH_MD5,-SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5,
  459. -SSL_CK_DES_64_CBC_WITH_MD5,-SSL_CK_DES_192_EDE3_CBC_WITH_MD5
  460. allowWeakCipher: on
  461. nsslapd-errorlog-level: 0
  462. """
  463. _header(topology, 'Test Case 11 - Check nssSSL3Chiphers: long list using the NSS Cipher Suite name with allowWeakCipher on')
  464. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  465. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers',
  466. '-TLS_RSA_WITH_NULL_MD5,+TLS_RSA_WITH_RC4_128_MD5,+TLS_RSA_EXPORT_WITH_RC4_40_MD5,+TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5,+TLS_DHE_RSA_WITH_DES_CBC_SHA,+SSL_RSA_FIPS_WITH_DES_CBC_SHA,+TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA,+SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA,+TLS_RSA_EXPORT1024_WITH_RC4_56_SHA,+TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA,-SSL_CK_RC4_128_WITH_MD5,-SSL_CK_RC4_128_EXPORT40_WITH_MD5,-SSL_CK_RC2_128_CBC_WITH_MD5,-SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5,-SSL_CK_DES_64_CBC_WITH_MD5,-SSL_CK_DES_192_EDE3_CBC_WITH_MD5')])
  467. log.info("\n######################### Restarting the server ######################\n")
  468. topology.standalone.stop(timeout=10)
  469. os.system('mv %s %s.47838_9' % (topology.standalone.errlog, topology.standalone.errlog))
  470. os.system('touch %s' % (topology.standalone.errlog))
  471. topology.standalone.start(timeout=120)
  472. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  473. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  474. ecount = int(enabled.readline().rstrip())
  475. dcount = int(disabled.readline().rstrip())
  476. log.info("Enabled ciphers: %d" % ecount)
  477. log.info("Disabled ciphers: %d" % dcount)
  478. global plus_all_ecount
  479. global plus_all_dcount
  480. assert ecount == 9
  481. assert dcount == 0
  482. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  483. wcount = int(weak.readline().rstrip())
  484. log.info("Weak ciphers in the default setting: %d" % wcount)
  485. topology.standalone.log.info("ticket47838 was successfully verified.");
  486. def test_ticket47838_run_11(topology):
  487. """
  488. Check nssSSL3Chiphers: +fortezza
  489. SSL_GetImplementedCiphers does not return this as a secuire cipher suite
  490. """
  491. _header(topology, 'Test Case 12 - Check nssSSL3Chiphers: +fortezza, which is not supported')
  492. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  493. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+fortezza')])
  494. log.info("\n######################### Restarting the server ######################\n")
  495. topology.standalone.stop(timeout=10)
  496. os.system('mv %s %s.47838_10' % (topology.standalone.errlog, topology.standalone.errlog))
  497. os.system('touch %s' % (topology.standalone.errlog))
  498. topology.standalone.start(timeout=120)
  499. errmsg = os.popen('egrep "SSL alert:" %s | egrep "is not available in NSS"' % topology.standalone.errlog)
  500. if errmsg != "":
  501. log.info("Expected error message:")
  502. log.info("%s" % errmsg.readline())
  503. else:
  504. log.info("Expected error message was not found")
  505. assert False
  506. def test_ticket47838_run_last(topology):
  507. """
  508. Check nssSSL3Chiphers: all <== invalid value
  509. All ciphers are disabled.
  510. """
  511. _header(topology, 'Test Case 13 - Check nssSSL3Chiphers: all, which is invalid')
  512. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  513. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', 'all')])
  514. log.info("\n######################### Restarting the server ######################\n")
  515. topology.standalone.stop(timeout=10)
  516. os.system('mv %s %s.47838_10' % (topology.standalone.errlog, topology.standalone.errlog))
  517. os.system('touch %s' % (topology.standalone.errlog))
  518. topology.standalone.start(timeout=120)
  519. errmsg = os.popen('egrep "SSL alert:" %s | egrep "invalid ciphers"' % topology.standalone.errlog)
  520. if errmsg != "":
  521. log.info("Expected error message:")
  522. log.info("%s" % errmsg.readline())
  523. else:
  524. log.info("Expected error message was not found")
  525. assert False
  526. topology.standalone.log.info("ticket47838 was successfully verified.");
  527. def test_ticket47838_final(topology):
  528. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  529. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', None)])
  530. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', 'default'),
  531. (ldap.MOD_REPLACE, 'allowWeakCipher', 'on')])
  532. topology.standalone.stop(timeout=10)
  533. def run_isolated():
  534. '''
  535. run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
  536. To run isolated without py.test, you need to
  537. - edit this file and comment '@pytest.fixture' line before 'topology' function.
  538. - set the installation prefix
  539. - run this program
  540. '''
  541. global installation_prefix
  542. installation_prefix = None
  543. topo = topology(True)
  544. test_ticket47838_init(topo)
  545. test_ticket47838_run_0(topo)
  546. test_ticket47838_run_1(topo)
  547. test_ticket47838_run_2(topo)
  548. test_ticket47838_run_3(topo)
  549. test_ticket47838_run_4(topo)
  550. test_ticket47838_run_5(topo)
  551. test_ticket47838_run_6(topo)
  552. test_ticket47838_run_7(topo)
  553. test_ticket47838_run_8(topo)
  554. test_ticket47838_run_9(topo)
  555. test_ticket47838_run_10(topo)
  556. test_ticket47838_run_11(topo)
  557. test_ticket47838_run_last(topo)
  558. test_ticket47838_final(topo)
  559. if __name__ == '__main__':
  560. run_isolated()