ticket47838_test.py 35 KB

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