ticket47838_test.py 36 KB

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