ticket47838_test.py 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. import os
  2. import sys
  3. import time
  4. import ldap
  5. import logging
  6. import pytest
  7. import shutil
  8. from lib389 import DirSrv, Entry, tools
  9. from lib389 import DirSrvTools
  10. from lib389.tools import DirSrvTools
  11. from lib389._constants import *
  12. from lib389.properties import *
  13. log = logging.getLogger(__name__)
  14. installation_prefix = None
  15. CONFIG_DN = 'cn=config'
  16. ENCRYPTION_DN = 'cn=encryption,%s' % CONFIG_DN
  17. RSA = 'RSA'
  18. RSA_DN = 'cn=%s,%s' % (RSA, ENCRYPTION_DN)
  19. LDAPSPORT = '10636'
  20. SERVERCERT = 'Server-Cert'
  21. plus_all_ecount = 0
  22. plus_all_dcount = 0
  23. plus_all_ecount_noweak = 0
  24. plus_all_dcount_noweak = 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. '''
  34. global installation_prefix
  35. if installation_prefix:
  36. args_instance[SER_DEPLOYED_DIR] = installation_prefix
  37. standalone = DirSrv(verbose=False)
  38. # Args for the standalone instance
  39. args_instance[SER_HOST] = HOST_STANDALONE
  40. args_instance[SER_PORT] = PORT_STANDALONE
  41. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  42. args_standalone = args_instance.copy()
  43. standalone.allocate(args_standalone)
  44. # Get the status of the instance and restart it if it exists
  45. instance_standalone = standalone.exists()
  46. # Remove the instance
  47. if instance_standalone:
  48. standalone.delete()
  49. # Create the instance
  50. standalone.create()
  51. # Used to retrieve configuration information (dbdir, confdir...)
  52. standalone.open()
  53. # clear the tmp directory
  54. standalone.clearTmpDir(__file__)
  55. # Here we have standalone instance up and running
  56. return TopologyStandalone(standalone)
  57. def _header(topology, label):
  58. topology.standalone.log.info("\n\n###############################################")
  59. topology.standalone.log.info("#######")
  60. topology.standalone.log.info("####### %s" % label)
  61. topology.standalone.log.info("#######")
  62. topology.standalone.log.info("###############################################")
  63. def test_ticket47838_init(topology):
  64. """
  65. Generate self signed cert and import it to the DS cert db.
  66. Enable SSL
  67. """
  68. _header(topology, 'Testing Ticket 47838 - harden the list of ciphers available by default')
  69. conf_dir = topology.standalone.confdir
  70. log.info("\n######################### Checking existing certs ######################\n")
  71. os.system('certutil -L -d %s -n "CA certificate"' % conf_dir)
  72. os.system('certutil -L -d %s -n "%s"' % (conf_dir, SERVERCERT))
  73. log.info("\n######################### Create a password file ######################\n")
  74. pwdfile = '%s/pwdfile.txt' % (conf_dir)
  75. opasswd = os.popen("(ps -ef ; w ) | sha1sum | awk '{print $1}'", "r")
  76. passwd = opasswd.readline()
  77. pwdfd = open(pwdfile, "w")
  78. pwdfd.write(passwd)
  79. pwdfd.close()
  80. log.info("\n######################### Create a noise file ######################\n")
  81. noisefile = '%s/noise.txt' % (conf_dir)
  82. noise = os.popen("(w ; ps -ef ; date ) | sha1sum | awk '{print $1}'", "r")
  83. noisewdfd = open(noisefile, "w")
  84. noisewdfd.write(noise.readline())
  85. noisewdfd.close()
  86. log.info("\n######################### Create key3.db and cert8.db database ######################\n")
  87. os.system("ls %s" % pwdfile)
  88. os.system("cat %s" % pwdfile)
  89. os.system('certutil -N -d %s -f %s' % (conf_dir, pwdfile))
  90. log.info("\n######################### Creating encryption key for CA ######################\n")
  91. os.system('certutil -G -d %s -z %s -f %s' % (conf_dir, noisefile, pwdfile))
  92. log.info("\n######################### Creating self-signed CA certificate ######################\n")
  93. 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))
  94. log.info("\n######################### Exporting the CA certificate to cacert.asc ######################\n")
  95. cafile = '%s/cacert.asc' % conf_dir
  96. catxt = os.popen('certutil -L -d %s -n "CA certificate" -a' % conf_dir)
  97. cafd = open(cafile, "w")
  98. while True:
  99. line = catxt.readline()
  100. if (line == ''):
  101. break
  102. cafd.write(line)
  103. cafd.close()
  104. log.info("\n######################### Generate the server certificate ######################\n")
  105. ohostname = os.popen('hostname --fqdn', "r")
  106. myhostname = ohostname.readline()
  107. 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))
  108. log.info("\n######################### create the pin file ######################\n")
  109. pinfile = '%s/pin.txt' % (conf_dir)
  110. pintxt = 'Internal (Software) Token:%s' % passwd
  111. pinfd = open(pinfile, "w")
  112. pinfd.write(pintxt)
  113. pinfd.close()
  114. log.info("\n######################### enable SSL in the directory server with all ciphers ######################\n")
  115. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  116. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3', 'off'),
  117. (ldap.MOD_REPLACE, 'nsTLS1', 'on'),
  118. (ldap.MOD_REPLACE, 'nsSSLClientAuth', 'allowed'),
  119. (ldap.MOD_REPLACE, 'allowWeakCipher', 'on'),
  120. (ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+all')])
  121. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-security', 'on'),
  122. (ldap.MOD_REPLACE, 'nsslapd-ssl-check-hostname', 'off'),
  123. (ldap.MOD_REPLACE, 'nsslapd-secureport', LDAPSPORT)])
  124. topology.standalone.add_s(Entry((RSA_DN, {'objectclass': "top nsEncryptionModule".split(),
  125. 'cn': RSA,
  126. 'nsSSLPersonalitySSL': SERVERCERT,
  127. 'nsSSLToken': 'internal (software)',
  128. 'nsSSLActivation': 'on'})))
  129. def comp_nsSSLEnableCipherCount(topology, ecount):
  130. """
  131. Check nsSSLEnabledCipher count with ecount
  132. """
  133. log.info("Checking nsSSLEnabledCiphers...")
  134. msgid = topology.standalone.search_ext(ENCRYPTION_DN, ldap.SCOPE_BASE, 'cn=*', ['nsSSLEnabledCiphers'])
  135. enabledciphercnt = 0
  136. rtype, rdata, rmsgid = topology.standalone.result2(msgid)
  137. topology.standalone.log.info("%d results" % len(rdata))
  138. topology.standalone.log.info("Results:")
  139. for dn, attrs in rdata:
  140. topology.standalone.log.info("dn: %s" % dn)
  141. if 'nsSSLEnabledCiphers' in attrs:
  142. enabledciphercnt = len(attrs['nsSSLEnabledCiphers'])
  143. topology.standalone.log.info("enabledCipherCount: %d" % enabledciphercnt)
  144. assert ecount == enabledciphercnt
  145. def test_ticket47838_run_0(topology):
  146. """
  147. Check nsSSL3Ciphers: +all
  148. All ciphers are enabled except null.
  149. Note: allowWeakCipher: on
  150. """
  151. _header(topology, 'Test Case 1 - Check the ciphers availability for "+all"; allowWeakCipher: on')
  152. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  153. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '64')])
  154. log.info("\n######################### Restarting the server ######################\n")
  155. topology.standalone.restart(timeout=120)
  156. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  157. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  158. ecount = int(enabled.readline().rstrip())
  159. dcount = int(disabled.readline().rstrip())
  160. log.info("Enabled ciphers: %d" % ecount)
  161. log.info("Disabled ciphers: %d" % dcount)
  162. assert ecount >= 60
  163. assert dcount <= 7
  164. global plus_all_ecount
  165. global plus_all_dcount
  166. plus_all_ecount = ecount
  167. plus_all_dcount = dcount
  168. weak = os.popen('egrep "SSL alert:" %s | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  169. wcount = int(weak.readline().rstrip())
  170. log.info("Weak ciphers: %d" % wcount)
  171. assert wcount <= 29
  172. comp_nsSSLEnableCipherCount(topology, ecount)
  173. def test_ticket47838_run_1(topology):
  174. """
  175. Check nsSSL3Ciphers: +all
  176. All ciphers are enabled except null.
  177. Note: default allowWeakCipher (i.e., off) for +all
  178. """
  179. _header(topology, 'Test Case 2 - Check the ciphers availability for "+all" with default allowWeakCiphers')
  180. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  181. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '64')])
  182. # Make sure allowWeakCipher is not set.
  183. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_DELETE, 'allowWeakCipher', None)])
  184. log.info("\n######################### Restarting the server ######################\n")
  185. log.info("\n######################### Restarting the server ######################\n")
  186. topology.standalone.stop(timeout=10)
  187. os.system('mv %s %s.47838_0' % (topology.standalone.errlog, topology.standalone.errlog))
  188. os.system('touch %s' % (topology.standalone.errlog))
  189. topology.standalone.start(timeout=120)
  190. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  191. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  192. ecount = int(enabled.readline().rstrip())
  193. dcount = int(disabled.readline().rstrip())
  194. global plus_all_ecount_noweak
  195. global plus_all_dcount_noweak
  196. plus_all_ecount_noweak = ecount
  197. plus_all_dcount_noweak = dcount
  198. log.info("Enabled ciphers: %d" % ecount)
  199. log.info("Disabled ciphers: %d" % dcount)
  200. assert ecount >= 31
  201. assert dcount <= 36
  202. weak = os.popen('egrep "SSL alert:" %s | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  203. wcount = int(weak.readline().rstrip())
  204. log.info("Weak ciphers: %d" % wcount)
  205. assert wcount <= 29
  206. comp_nsSSLEnableCipherCount(topology, ecount)
  207. def test_ticket47838_run_2(topology):
  208. """
  209. Check nsSSL3Ciphers: +rsa_aes_128_sha,+rsa_aes_256_sha
  210. rsa_aes_128_sha, tls_rsa_aes_128_sha, rsa_aes_256_sha, tls_rsa_aes_256_sha are enabled.
  211. default allowWeakCipher
  212. """
  213. _header(topology, 'Test Case 3 - Check the ciphers availability for "+rsa_aes_128_sha,+rsa_aes_256_sha" with default allowWeakCipher')
  214. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  215. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+rsa_aes_128_sha,+rsa_aes_256_sha')])
  216. log.info("\n######################### Restarting the server ######################\n")
  217. topology.standalone.stop(timeout=10)
  218. os.system('mv %s %s.47838_1' % (topology.standalone.errlog, topology.standalone.errlog))
  219. os.system('touch %s' % (topology.standalone.errlog))
  220. topology.standalone.start(timeout=120)
  221. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  222. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  223. ecount = int(enabled.readline().rstrip())
  224. dcount = int(disabled.readline().rstrip())
  225. log.info("Enabled ciphers: %d" % ecount)
  226. log.info("Disabled ciphers: %d" % dcount)
  227. global plus_all_ecount
  228. global plus_all_dcount
  229. assert ecount == 2
  230. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  231. comp_nsSSLEnableCipherCount(topology, ecount)
  232. def test_ticket47838_run_3(topology):
  233. """
  234. Check nsSSL3Ciphers: -all
  235. All ciphers are disabled.
  236. default allowWeakCipher
  237. """
  238. _header(topology, 'Test Case 4 - Check the ciphers availability for "-all"')
  239. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  240. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '-all')])
  241. log.info("\n######################### Restarting the server ######################\n")
  242. topology.standalone.stop(timeout=10)
  243. os.system('mv %s %s.47838_2' % (topology.standalone.errlog, topology.standalone.errlog))
  244. os.system('touch %s' % (topology.standalone.errlog))
  245. topology.standalone.start(timeout=120)
  246. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  247. ecount = int(enabled.readline().rstrip())
  248. log.info("Enabled ciphers: %d" % ecount)
  249. global plus_all_ecount
  250. assert ecount == 0
  251. disabledmsg = os.popen('egrep "Disabling SSL" %s' % topology.standalone.errlog)
  252. log.info("Disabling SSL message?: %s" % disabledmsg.readline())
  253. assert disabledmsg != ''
  254. comp_nsSSLEnableCipherCount(topology, ecount)
  255. def test_ticket47838_run_4(topology):
  256. """
  257. Check no nsSSL3Ciphers
  258. Default ciphers are enabled.
  259. default allowWeakCipher
  260. """
  261. _header(topology, 'Test Case 5 - Check no nssSSL3Chiphers (default setting) with default allowWeakCipher')
  262. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  263. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_DELETE, 'nsSSL3Ciphers', '-all')])
  264. log.info("\n######################### Restarting the server ######################\n")
  265. topology.standalone.stop(timeout=10)
  266. os.system('mv %s %s.47838_3' % (topology.standalone.errlog, topology.standalone.errlog))
  267. os.system('touch %s' % (topology.standalone.errlog))
  268. topology.standalone.start(timeout=120)
  269. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  270. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  271. ecount = int(enabled.readline().rstrip())
  272. dcount = int(disabled.readline().rstrip())
  273. log.info("Enabled ciphers: %d" % ecount)
  274. log.info("Disabled ciphers: %d" % dcount)
  275. global plus_all_ecount
  276. global plus_all_dcount
  277. assert ecount == 12
  278. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  279. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  280. wcount = int(weak.readline().rstrip())
  281. log.info("Weak ciphers in the default setting: %d" % wcount)
  282. assert wcount == 0
  283. comp_nsSSLEnableCipherCount(topology, ecount)
  284. def test_ticket47838_run_5(topology):
  285. """
  286. Check nsSSL3Ciphers: default
  287. Default ciphers are enabled.
  288. default allowWeakCipher
  289. """
  290. _header(topology, 'Test Case 6 - Check default nssSSL3Chiphers (default setting) with default allowWeakCipher')
  291. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  292. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', 'default')])
  293. log.info("\n######################### Restarting the server ######################\n")
  294. topology.standalone.stop(timeout=10)
  295. os.system('mv %s %s.47838_4' % (topology.standalone.errlog, topology.standalone.errlog))
  296. os.system('touch %s' % (topology.standalone.errlog))
  297. topology.standalone.start(timeout=120)
  298. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  299. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  300. ecount = int(enabled.readline().rstrip())
  301. dcount = int(disabled.readline().rstrip())
  302. log.info("Enabled ciphers: %d" % ecount)
  303. log.info("Disabled ciphers: %d" % dcount)
  304. global plus_all_ecount
  305. global plus_all_dcount
  306. assert ecount == 12
  307. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  308. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  309. wcount = int(weak.readline().rstrip())
  310. log.info("Weak ciphers in the default setting: %d" % wcount)
  311. assert wcount == 0
  312. comp_nsSSLEnableCipherCount(topology, ecount)
  313. def test_ticket47838_run_6(topology):
  314. """
  315. Check nssSSL3Chiphers: +all,-rsa_rc4_128_md5
  316. All ciphers are disabled.
  317. default allowWeakCipher
  318. """
  319. _header(topology, 'Test Case 7 - Check nssSSL3Chiphers: +all,-tls_dhe_rsa_aes_128_gcm_sha with default allowWeakCipher')
  320. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  321. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+all,-tls_dhe_rsa_aes_128_gcm_sha')])
  322. log.info("\n######################### Restarting the server ######################\n")
  323. topology.standalone.stop(timeout=10)
  324. os.system('mv %s %s.47838_5' % (topology.standalone.errlog, topology.standalone.errlog))
  325. os.system('touch %s' % (topology.standalone.errlog))
  326. topology.standalone.start(timeout=120)
  327. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  328. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  329. ecount = int(enabled.readline().rstrip())
  330. dcount = int(disabled.readline().rstrip())
  331. log.info("Enabled ciphers: %d" % ecount)
  332. log.info("Disabled ciphers: %d" % dcount)
  333. global plus_all_ecount_noweak
  334. global plus_all_dcount_noweak
  335. log.info("ALL Ecount: %d" % plus_all_ecount_noweak)
  336. log.info("ALL Dcount: %d" % plus_all_dcount_noweak)
  337. assert ecount == (plus_all_ecount_noweak - 1)
  338. assert dcount == (plus_all_dcount_noweak + 1)
  339. comp_nsSSLEnableCipherCount(topology, ecount)
  340. def test_ticket47838_run_7(topology):
  341. """
  342. Check nssSSL3Chiphers: -all,+rsa_rc4_128_md5
  343. All ciphers are disabled.
  344. default allowWeakCipher
  345. """
  346. _header(topology, 'Test Case 8 - Check nssSSL3Chiphers: -all,+rsa_rc4_128_md5 with default allowWeakCipher')
  347. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  348. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '-all,+rsa_rc4_128_md5')])
  349. log.info("\n######################### Restarting the server ######################\n")
  350. topology.standalone.stop(timeout=10)
  351. os.system('mv %s %s.47838_6' % (topology.standalone.errlog, topology.standalone.errlog))
  352. os.system('touch %s' % (topology.standalone.errlog))
  353. topology.standalone.start(timeout=120)
  354. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  355. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  356. ecount = int(enabled.readline().rstrip())
  357. dcount = int(disabled.readline().rstrip())
  358. log.info("Enabled ciphers: %d" % ecount)
  359. log.info("Disabled ciphers: %d" % dcount)
  360. global plus_all_ecount
  361. global plus_all_dcount
  362. assert ecount == 1
  363. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  364. comp_nsSSLEnableCipherCount(topology, ecount)
  365. def test_ticket47838_run_8(topology):
  366. """
  367. Check nsSSL3Ciphers: default + allowWeakCipher: off
  368. Strong Default ciphers are enabled.
  369. """
  370. _header(topology, 'Test Case 9 - Check default nssSSL3Chiphers (default setting + allowWeakCipher: off)')
  371. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  372. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', 'default'),
  373. (ldap.MOD_REPLACE, 'allowWeakCipher', 'off')])
  374. log.info("\n######################### Restarting the server ######################\n")
  375. topology.standalone.stop(timeout=10)
  376. os.system('mv %s %s.47838_7' % (topology.standalone.errlog, topology.standalone.errlog))
  377. os.system('touch %s' % (topology.standalone.errlog))
  378. topology.standalone.start(timeout=120)
  379. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  380. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  381. ecount = int(enabled.readline().rstrip())
  382. dcount = int(disabled.readline().rstrip())
  383. log.info("Enabled ciphers: %d" % ecount)
  384. log.info("Disabled ciphers: %d" % dcount)
  385. global plus_all_ecount
  386. global plus_all_dcount
  387. assert ecount == 12
  388. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  389. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  390. wcount = int(weak.readline().rstrip())
  391. log.info("Weak ciphers in the default setting: %d" % wcount)
  392. assert wcount == 0
  393. comp_nsSSLEnableCipherCount(topology, ecount)
  394. def test_ticket47838_run_9(topology):
  395. """
  396. Check no nsSSL3Ciphers
  397. Default ciphers are enabled.
  398. allowWeakCipher: on
  399. nsslapd-errorlog-level: 0
  400. """
  401. _header(topology, 'Test Case 10 - Check no nssSSL3Chiphers (default setting) with no errorlog-level & allowWeakCipher on')
  402. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  403. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', None),
  404. (ldap.MOD_REPLACE, 'allowWeakCipher', 'on')])
  405. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', None)])
  406. log.info("\n######################### Restarting the server ######################\n")
  407. topology.standalone.stop(timeout=10)
  408. os.system('mv %s %s.47838_8' % (topology.standalone.errlog, topology.standalone.errlog))
  409. os.system('touch %s' % (topology.standalone.errlog))
  410. topology.standalone.start(timeout=120)
  411. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  412. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  413. ecount = int(enabled.readline().rstrip())
  414. dcount = int(disabled.readline().rstrip())
  415. log.info("Enabled ciphers: %d" % ecount)
  416. log.info("Disabled ciphers: %d" % dcount)
  417. assert ecount == 23
  418. assert dcount == 0
  419. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  420. wcount = int(weak.readline().rstrip())
  421. log.info("Weak ciphers in the default setting: %d" % wcount)
  422. assert wcount == 11
  423. comp_nsSSLEnableCipherCount(topology, ecount)
  424. def test_ticket47838_run_10(topology):
  425. """
  426. Check nssSSL3Chiphers: -TLS_RSA_WITH_NULL_MD5,+TLS_RSA_WITH_RC4_128_MD5,
  427. +TLS_RSA_EXPORT_WITH_RC4_40_MD5,+TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5,
  428. +TLS_DHE_RSA_WITH_DES_CBC_SHA,+SSL_RSA_FIPS_WITH_DES_CBC_SHA,
  429. +TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA,+SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA,
  430. +TLS_RSA_EXPORT1024_WITH_RC4_56_SHA,+TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA,
  431. -SSL_CK_RC4_128_WITH_MD5,-SSL_CK_RC4_128_EXPORT40_WITH_MD5,
  432. -SSL_CK_RC2_128_CBC_WITH_MD5,-SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5,
  433. -SSL_CK_DES_64_CBC_WITH_MD5,-SSL_CK_DES_192_EDE3_CBC_WITH_MD5
  434. allowWeakCipher: on
  435. nsslapd-errorlog-level: 0
  436. """
  437. _header(topology, 'Test Case 11 - Check nssSSL3Chiphers: long list using the NSS Cipher Suite name with allowWeakCipher on')
  438. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  439. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers',
  440. '-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')])
  441. log.info("\n######################### Restarting the server ######################\n")
  442. topology.standalone.stop(timeout=10)
  443. os.system('mv %s %s.47838_9' % (topology.standalone.errlog, topology.standalone.errlog))
  444. os.system('touch %s' % (topology.standalone.errlog))
  445. topology.standalone.start(timeout=120)
  446. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  447. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  448. ecount = int(enabled.readline().rstrip())
  449. dcount = int(disabled.readline().rstrip())
  450. log.info("Enabled ciphers: %d" % ecount)
  451. log.info("Disabled ciphers: %d" % dcount)
  452. global plus_all_ecount
  453. global plus_all_dcount
  454. assert ecount == 9
  455. assert dcount == 0
  456. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  457. wcount = int(weak.readline().rstrip())
  458. log.info("Weak ciphers in the default setting: %d" % wcount)
  459. topology.standalone.log.info("ticket47838 was successfully verified.")
  460. comp_nsSSLEnableCipherCount(topology, ecount)
  461. def test_ticket47838_run_11(topology):
  462. """
  463. Check nssSSL3Chiphers: +fortezza
  464. SSL_GetImplementedCiphers does not return this as a secuire cipher suite
  465. """
  466. _header(topology, 'Test Case 12 - Check nssSSL3Chiphers: +fortezza, which is not supported')
  467. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  468. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+fortezza')])
  469. log.info("\n######################### Restarting the server ######################\n")
  470. topology.standalone.stop(timeout=10)
  471. os.system('mv %s %s.47838_10' % (topology.standalone.errlog, topology.standalone.errlog))
  472. os.system('touch %s' % (topology.standalone.errlog))
  473. topology.standalone.start(timeout=120)
  474. errmsg = os.popen('egrep "SSL alert:" %s | egrep "is not available in NSS"' % topology.standalone.errlog)
  475. if errmsg != "":
  476. log.info("Expected error message:")
  477. log.info("%s" % errmsg.readline())
  478. else:
  479. log.info("Expected error message was not found")
  480. assert False
  481. comp_nsSSLEnableCipherCount(topology, 0)
  482. def test_ticket47928_run_0(topology):
  483. """
  484. No SSL version config parameters.
  485. Check SSL3 (TLS1.0) is off.
  486. """
  487. _header(topology, 'Test Case 13 - No SSL version config parameters')
  488. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  489. # add them once and remove them
  490. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3', 'off'),
  491. (ldap.MOD_REPLACE, 'nsTLS1', 'on'),
  492. (ldap.MOD_REPLACE, 'sslVersionMin', 'TLS1.1'),
  493. (ldap.MOD_REPLACE, 'sslVersionMax', 'TLS1.2')])
  494. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_DELETE, 'nsSSL3', None),
  495. (ldap.MOD_DELETE, 'nsTLS1', None),
  496. (ldap.MOD_DELETE, 'sslVersionMin', None),
  497. (ldap.MOD_DELETE, 'sslVersionMax', None)])
  498. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '64')])
  499. log.info("\n######################### Restarting the server ######################\n")
  500. topology.standalone.stop(timeout=10)
  501. os.system('mv %s %s.47838_11' % (topology.standalone.errlog, topology.standalone.errlog))
  502. os.system('touch %s' % (topology.standalone.errlog))
  503. topology.standalone.start(timeout=120)
  504. errmsg = os.popen('egrep "SSL alert:" %s | egrep "Default SSL Version settings; Configuring the version range as min: TLS1.1"' % topology.standalone.errlog)
  505. if errmsg != "":
  506. log.info("Expected message:")
  507. log.info("%s" % errmsg.readline())
  508. else:
  509. log.info("Expected message was not found")
  510. assert False
  511. def test_ticket47928_run_1(topology):
  512. """
  513. No nsSSL3, nsTLS1; sslVersionMin > sslVersionMax
  514. Check sslVersionMax is ignored.
  515. """
  516. _header(topology, 'Test Case 14 - No nsSSL3, nsTLS1; sslVersionMin > sslVersionMax')
  517. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  518. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'sslVersionMin', 'TLS1.2'),
  519. (ldap.MOD_REPLACE, 'sslVersionMax', 'TLS1.1')])
  520. log.info("\n######################### Restarting the server ######################\n")
  521. topology.standalone.stop(timeout=10)
  522. os.system('mv %s %s.47838_12' % (topology.standalone.errlog, topology.standalone.errlog))
  523. os.system('touch %s' % (topology.standalone.errlog))
  524. topology.standalone.start(timeout=120)
  525. errmsg = os.popen('egrep "SSL alert:" %s | egrep "The min value of NSS version range"' % topology.standalone.errlog)
  526. if errmsg != "":
  527. log.info("Expected message:")
  528. log.info("%s" % errmsg.readline())
  529. else:
  530. log.info("Expected message was not found")
  531. assert False
  532. errmsg = os.popen('egrep "SSL Initialization" %s | egrep "Configured SSL version range: min: TLS1.2, max: TLS1"' % topology.standalone.errlog)
  533. if errmsg != "":
  534. log.info("Expected message:")
  535. log.info("%s" % errmsg.readline())
  536. else:
  537. log.info("Expected message was not found")
  538. assert False
  539. def test_ticket47928_run_2(topology):
  540. """
  541. nsSSL3: on; sslVersionMin: TLS1.1; sslVersionMax: TLS1.2
  542. Conflict between nsSSL3 and range; nsSSL3 is disabled
  543. """
  544. _header(topology, 'Test Case 15 - nsSSL3: on; sslVersionMin: TLS1.1; sslVersionMax: TLS1.2')
  545. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  546. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'sslVersionMin', 'TLS1.1'),
  547. (ldap.MOD_REPLACE, 'sslVersionMax', 'TLS1.2'),
  548. (ldap.MOD_REPLACE, 'nsSSL3', 'on')])
  549. log.info("\n######################### Restarting the server ######################\n")
  550. topology.standalone.stop(timeout=10)
  551. os.system('mv %s %s.47838_13' % (topology.standalone.errlog, topology.standalone.errlog))
  552. os.system('touch %s' % (topology.standalone.errlog))
  553. topology.standalone.start(timeout=120)
  554. errmsg = os.popen('egrep "SSL alert:" %s | egrep "Found unsecure configuration: nsSSL3: on"' % topology.standalone.errlog)
  555. if errmsg != "":
  556. log.info("Expected message:")
  557. log.info("%s" % errmsg.readline())
  558. else:
  559. log.info("Expected message was not found")
  560. assert False
  561. errmsg = os.popen('egrep "SSL alert:" %s | egrep "Respect the supported range."' % topology.standalone.errlog)
  562. if errmsg != "":
  563. log.info("Expected message:")
  564. log.info("%s" % errmsg.readline())
  565. else:
  566. log.info("Expected message was not found")
  567. assert False
  568. errmsg = os.popen('egrep "SSL Initialization" %s | egrep "Configured SSL version range: min: TLS1.1, max: TLS1"' % topology.standalone.errlog)
  569. if errmsg != "":
  570. log.info("Expected message:")
  571. log.info("%s" % errmsg.readline())
  572. else:
  573. log.info("Expected message was not found")
  574. assert False
  575. def test_ticket47928_run_3(topology):
  576. """
  577. nsSSL3: on; nsTLS1: off; sslVersionMin: TLS1.1; sslVersionMax: TLS1.2
  578. Conflict between nsSSL3/nsTLS1 and range; nsSSL3 is disabled; nsTLS1 is enabled.
  579. """
  580. _header(topology, 'Test Case 16 - nsSSL3: on; nsTLS1: off; sslVersionMin: TLS1.1; sslVersionMax: TLS1.2')
  581. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  582. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'sslVersionMin', 'TLS1.1'),
  583. (ldap.MOD_REPLACE, 'sslVersionMax', 'TLS1.2'),
  584. (ldap.MOD_REPLACE, 'nsSSL3', 'on'),
  585. (ldap.MOD_REPLACE, 'nsTLS1', 'off')])
  586. log.info("\n######################### Restarting the server ######################\n")
  587. topology.standalone.stop(timeout=10)
  588. os.system('mv %s %s.47838_14' % (topology.standalone.errlog, topology.standalone.errlog))
  589. os.system('touch %s' % (topology.standalone.errlog))
  590. topology.standalone.start(timeout=120)
  591. errmsg = os.popen('egrep "SSL alert:" %s | egrep "Found unsecure configuration: nsSSL3: on"' % topology.standalone.errlog)
  592. if errmsg != "":
  593. log.info("Expected message:")
  594. log.info("%s" % errmsg.readline())
  595. else:
  596. log.info("Expected message was not found")
  597. assert False
  598. errmsg = os.popen('egrep "SSL alert:" %s | egrep "Respect the configured range."' % topology.standalone.errlog)
  599. if errmsg != "":
  600. log.info("Expected message:")
  601. log.info("%s" % errmsg.readline())
  602. else:
  603. log.info("Expected message was not found")
  604. assert False
  605. errmsg = os.popen('egrep "SSL Initialization" %s | egrep "Configured SSL version range: min: TLS1.1, max: TLS1"' % topology.standalone.errlog)
  606. if errmsg != "":
  607. log.info("Expected message:")
  608. log.info("%s" % errmsg.readline())
  609. else:
  610. log.info("Expected message was not found")
  611. assert False
  612. def test_ticket47838_run_last(topology):
  613. """
  614. Check nssSSL3Chiphers: all <== invalid value
  615. All ciphers are disabled.
  616. """
  617. _header(topology, 'Test Case 17 - Check nssSSL3Chiphers: all, which is invalid')
  618. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  619. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', None)])
  620. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', 'all')])
  621. log.info("\n######################### Restarting the server ######################\n")
  622. topology.standalone.stop(timeout=10)
  623. os.system('mv %s %s.47838_15' % (topology.standalone.errlog, topology.standalone.errlog))
  624. os.system('touch %s' % (topology.standalone.errlog))
  625. topology.standalone.start(timeout=120)
  626. errmsg = os.popen('egrep "SSL alert:" %s | egrep "invalid ciphers"' % topology.standalone.errlog)
  627. if errmsg != "":
  628. log.info("Expected error message:")
  629. log.info("%s" % errmsg.readline())
  630. else:
  631. log.info("Expected error message was not found")
  632. assert False
  633. comp_nsSSLEnableCipherCount(topology, 0)
  634. topology.standalone.log.info("ticket47838, 47880, 47908, 47928 were successfully verified.")
  635. def test_ticket47838_final(topology):
  636. topology.standalone.delete()
  637. log.info('Testcase PASSED')
  638. def run_isolated():
  639. '''
  640. run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
  641. To run isolated without py.test, you need to
  642. - edit this file and comment '@pytest.fixture' line before 'topology' function.
  643. - set the installation prefix
  644. - run this program
  645. '''
  646. global installation_prefix
  647. installation_prefix = None
  648. topo = topology(True)
  649. test_ticket47838_init(topo)
  650. test_ticket47838_run_0(topo)
  651. test_ticket47838_run_1(topo)
  652. test_ticket47838_run_2(topo)
  653. test_ticket47838_run_3(topo)
  654. test_ticket47838_run_4(topo)
  655. test_ticket47838_run_5(topo)
  656. test_ticket47838_run_6(topo)
  657. test_ticket47838_run_7(topo)
  658. test_ticket47838_run_8(topo)
  659. test_ticket47838_run_9(topo)
  660. test_ticket47838_run_10(topo)
  661. test_ticket47838_run_11(topo)
  662. test_ticket47928_run_0(topo)
  663. test_ticket47928_run_1(topo)
  664. test_ticket47928_run_2(topo)
  665. test_ticket47928_run_3(topo)
  666. test_ticket47838_run_last(topo)
  667. test_ticket47838_final(topo)
  668. if __name__ == '__main__':
  669. run_isolated()