ticket47838_test.py 35 KB

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