ticket47838_test.py 35 KB

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