ticket47838_test.py 23 KB

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