ticket47838_test.py 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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. LDAPSPORT = '10636'
  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. # clear the tmp directory
  64. standalone.clearTmpDir(__file__)
  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', LDAPSPORT)])
  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. log.info("\n######################### Restarting the server ######################\n")
  168. topology.standalone.restart(timeout=120)
  169. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  170. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  171. ecount = int(enabled.readline().rstrip())
  172. dcount = int(disabled.readline().rstrip())
  173. log.info("Enabled ciphers: %d" % ecount)
  174. log.info("Disabled ciphers: %d" % dcount)
  175. if nss_version >= NSS320:
  176. assert ecount >= 53
  177. assert dcount <= 17
  178. else:
  179. assert ecount >= 60
  180. assert dcount <= 7
  181. global plus_all_ecount
  182. global plus_all_dcount
  183. plus_all_ecount = ecount
  184. plus_all_dcount = dcount
  185. weak = os.popen('egrep "SSL alert:" %s | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  186. wcount = int(weak.readline().rstrip())
  187. log.info("Weak ciphers: %d" % wcount)
  188. assert wcount <= 29
  189. comp_nsSSLEnableCipherCount(topology, ecount)
  190. def _47838_run_1(topology):
  191. """
  192. Check nsSSL3Ciphers: +all
  193. All ciphers are enabled except null.
  194. Note: default allowWeakCipher (i.e., off) for +all
  195. """
  196. _header(topology, 'Test Case 2 - Check the ciphers availability for "+all" with default allowWeakCiphers')
  197. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  198. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '64')])
  199. # Make sure allowWeakCipher is not set.
  200. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_DELETE, 'allowWeakCipher', None)])
  201. log.info("\n######################### Restarting the server ######################\n")
  202. log.info("\n######################### Restarting the server ######################\n")
  203. topology.standalone.stop(timeout=10)
  204. os.system('mv %s %s.47838_0' % (topology.standalone.errlog, topology.standalone.errlog))
  205. os.system('touch %s' % (topology.standalone.errlog))
  206. topology.standalone.start(timeout=120)
  207. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  208. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  209. ecount = int(enabled.readline().rstrip())
  210. dcount = int(disabled.readline().rstrip())
  211. global plus_all_ecount_noweak
  212. global plus_all_dcount_noweak
  213. plus_all_ecount_noweak = ecount
  214. plus_all_dcount_noweak = dcount
  215. log.info("Enabled ciphers: %d" % ecount)
  216. log.info("Disabled ciphers: %d" % dcount)
  217. assert ecount >= 31
  218. assert dcount <= 36
  219. weak = os.popen('egrep "SSL alert:" %s | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  220. wcount = int(weak.readline().rstrip())
  221. log.info("Weak ciphers: %d" % wcount)
  222. assert wcount <= 29
  223. comp_nsSSLEnableCipherCount(topology, ecount)
  224. def _47838_run_2(topology):
  225. """
  226. Check nsSSL3Ciphers: +rsa_aes_128_sha,+rsa_aes_256_sha
  227. rsa_aes_128_sha, tls_rsa_aes_128_sha, rsa_aes_256_sha, tls_rsa_aes_256_sha are enabled.
  228. default allowWeakCipher
  229. """
  230. _header(topology, 'Test Case 3 - Check the ciphers availability for "+rsa_aes_128_sha,+rsa_aes_256_sha" with default allowWeakCipher')
  231. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  232. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+rsa_aes_128_sha,+rsa_aes_256_sha')])
  233. log.info("\n######################### Restarting the server ######################\n")
  234. topology.standalone.stop(timeout=10)
  235. os.system('mv %s %s.47838_1' % (topology.standalone.errlog, topology.standalone.errlog))
  236. os.system('touch %s' % (topology.standalone.errlog))
  237. topology.standalone.start(timeout=120)
  238. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  239. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  240. ecount = int(enabled.readline().rstrip())
  241. dcount = int(disabled.readline().rstrip())
  242. log.info("Enabled ciphers: %d" % ecount)
  243. log.info("Disabled ciphers: %d" % dcount)
  244. global plus_all_ecount
  245. global plus_all_dcount
  246. assert ecount == 2
  247. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  248. comp_nsSSLEnableCipherCount(topology, ecount)
  249. def _47838_run_3(topology):
  250. """
  251. Check nsSSL3Ciphers: -all
  252. All ciphers are disabled.
  253. default allowWeakCipher
  254. """
  255. _header(topology, 'Test Case 4 - Check the ciphers availability for "-all"')
  256. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  257. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '-all')])
  258. log.info("\n######################### Restarting the server ######################\n")
  259. topology.standalone.stop(timeout=10)
  260. os.system('mv %s %s.47838_2' % (topology.standalone.errlog, topology.standalone.errlog))
  261. os.system('touch %s' % (topology.standalone.errlog))
  262. topology.standalone.start(timeout=120)
  263. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  264. ecount = int(enabled.readline().rstrip())
  265. log.info("Enabled ciphers: %d" % ecount)
  266. global plus_all_ecount
  267. assert ecount == 0
  268. disabledmsg = os.popen('egrep "Disabling SSL" %s' % topology.standalone.errlog)
  269. log.info("Disabling SSL message?: %s" % disabledmsg.readline())
  270. assert disabledmsg != ''
  271. comp_nsSSLEnableCipherCount(topology, ecount)
  272. def _47838_run_4(topology):
  273. """
  274. Check no nsSSL3Ciphers
  275. Default ciphers are enabled.
  276. default allowWeakCipher
  277. """
  278. _header(topology, 'Test Case 5 - Check no nsSSL3Ciphers (default setting) with default allowWeakCipher')
  279. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  280. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_DELETE, 'nsSSL3Ciphers', '-all')])
  281. log.info("\n######################### Restarting the server ######################\n")
  282. topology.standalone.stop(timeout=10)
  283. os.system('mv %s %s.47838_3' % (topology.standalone.errlog, topology.standalone.errlog))
  284. os.system('touch %s' % (topology.standalone.errlog))
  285. topology.standalone.start(timeout=120)
  286. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  287. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  288. ecount = int(enabled.readline().rstrip())
  289. dcount = int(disabled.readline().rstrip())
  290. log.info("Enabled ciphers: %d" % ecount)
  291. log.info("Disabled ciphers: %d" % dcount)
  292. global plus_all_ecount
  293. global plus_all_dcount
  294. assert ecount == 20
  295. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  296. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  297. wcount = int(weak.readline().rstrip())
  298. log.info("Weak ciphers in the default setting: %d" % wcount)
  299. assert wcount == 0
  300. comp_nsSSLEnableCipherCount(topology, ecount)
  301. def _47838_run_5(topology):
  302. """
  303. Check nsSSL3Ciphers: default
  304. Default ciphers are enabled.
  305. default allowWeakCipher
  306. """
  307. _header(topology, 'Test Case 6 - Check default nsSSL3Ciphers (default setting) with default allowWeakCipher')
  308. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  309. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', 'default')])
  310. log.info("\n######################### Restarting the server ######################\n")
  311. topology.standalone.stop(timeout=10)
  312. os.system('mv %s %s.47838_4' % (topology.standalone.errlog, topology.standalone.errlog))
  313. os.system('touch %s' % (topology.standalone.errlog))
  314. topology.standalone.start(timeout=120)
  315. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  316. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  317. ecount = int(enabled.readline().rstrip())
  318. dcount = int(disabled.readline().rstrip())
  319. log.info("Enabled ciphers: %d" % ecount)
  320. log.info("Disabled ciphers: %d" % dcount)
  321. global plus_all_ecount
  322. global plus_all_dcount
  323. if nss_version >= NSS320:
  324. assert ecount == 20
  325. else:
  326. assert ecount == 12
  327. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  328. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  329. wcount = int(weak.readline().rstrip())
  330. log.info("Weak ciphers in the default setting: %d" % wcount)
  331. assert wcount == 0
  332. comp_nsSSLEnableCipherCount(topology, ecount)
  333. def _47838_run_6(topology):
  334. """
  335. Check nsSSL3Ciphers: +all,-rsa_rc4_128_md5
  336. All ciphers are disabled.
  337. default allowWeakCipher
  338. """
  339. _header(topology, 'Test Case 7 - Check nsSSL3Ciphers: +all,-tls_dhe_rsa_aes_128_gcm_sha with default allowWeakCipher')
  340. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  341. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+all,-tls_dhe_rsa_aes_128_gcm_sha')])
  342. log.info("\n######################### Restarting the server ######################\n")
  343. topology.standalone.stop(timeout=10)
  344. os.system('mv %s %s.47838_5' % (topology.standalone.errlog, topology.standalone.errlog))
  345. os.system('touch %s' % (topology.standalone.errlog))
  346. topology.standalone.start(timeout=120)
  347. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  348. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  349. ecount = int(enabled.readline().rstrip())
  350. dcount = int(disabled.readline().rstrip())
  351. log.info("Enabled ciphers: %d" % ecount)
  352. log.info("Disabled ciphers: %d" % dcount)
  353. global plus_all_ecount_noweak
  354. global plus_all_dcount_noweak
  355. log.info("ALL Ecount: %d" % plus_all_ecount_noweak)
  356. log.info("ALL Dcount: %d" % plus_all_dcount_noweak)
  357. assert ecount == (plus_all_ecount_noweak - 1)
  358. assert dcount == (plus_all_dcount_noweak + 1)
  359. comp_nsSSLEnableCipherCount(topology, ecount)
  360. def _47838_run_7(topology):
  361. """
  362. Check nsSSL3Ciphers: -all,+rsa_rc4_128_md5
  363. All ciphers are disabled.
  364. default allowWeakCipher
  365. """
  366. _header(topology, 'Test Case 8 - Check nsSSL3Ciphers: -all,+rsa_rc4_128_md5 with default allowWeakCipher')
  367. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  368. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '-all,+rsa_rc4_128_md5')])
  369. log.info("\n######################### Restarting the server ######################\n")
  370. topology.standalone.stop(timeout=10)
  371. os.system('mv %s %s.47838_6' % (topology.standalone.errlog, topology.standalone.errlog))
  372. os.system('touch %s' % (topology.standalone.errlog))
  373. topology.standalone.start(timeout=120)
  374. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  375. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  376. ecount = int(enabled.readline().rstrip())
  377. dcount = int(disabled.readline().rstrip())
  378. log.info("Enabled ciphers: %d" % ecount)
  379. log.info("Disabled ciphers: %d" % dcount)
  380. global plus_all_ecount
  381. global plus_all_dcount
  382. assert ecount == 1
  383. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  384. comp_nsSSLEnableCipherCount(topology, ecount)
  385. def _47838_run_8(topology):
  386. """
  387. Check nsSSL3Ciphers: default + allowWeakCipher: off
  388. Strong Default ciphers are enabled.
  389. """
  390. _header(topology, 'Test Case 9 - Check default nsSSL3Ciphers (default setting + allowWeakCipher: off)')
  391. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  392. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', 'default'),
  393. (ldap.MOD_REPLACE, 'allowWeakCipher', 'off')])
  394. log.info("\n######################### Restarting the server ######################\n")
  395. topology.standalone.stop(timeout=10)
  396. os.system('mv %s %s.47838_7' % (topology.standalone.errlog, topology.standalone.errlog))
  397. os.system('touch %s' % (topology.standalone.errlog))
  398. topology.standalone.start(timeout=120)
  399. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  400. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  401. ecount = int(enabled.readline().rstrip())
  402. dcount = int(disabled.readline().rstrip())
  403. log.info("Enabled ciphers: %d" % ecount)
  404. log.info("Disabled ciphers: %d" % dcount)
  405. global plus_all_ecount
  406. global plus_all_dcount
  407. if nss_version >= NSS320:
  408. assert ecount == 20
  409. else:
  410. assert ecount == 12
  411. assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
  412. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  413. wcount = int(weak.readline().rstrip())
  414. log.info("Weak ciphers in the default setting: %d" % wcount)
  415. assert wcount == 0
  416. comp_nsSSLEnableCipherCount(topology, ecount)
  417. def _47838_run_9(topology):
  418. """
  419. Check no nsSSL3Ciphers
  420. Default ciphers are enabled.
  421. allowWeakCipher: on
  422. nsslapd-errorlog-level: 0
  423. """
  424. _header(topology, 'Test Case 10 - Check no nsSSL3Ciphers (default setting) with no errorlog-level & allowWeakCipher on')
  425. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  426. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', None),
  427. (ldap.MOD_REPLACE, 'allowWeakCipher', 'on')])
  428. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', None)])
  429. log.info("\n######################### Restarting the server ######################\n")
  430. topology.standalone.stop(timeout=10)
  431. os.system('mv %s %s.47838_8' % (topology.standalone.errlog, topology.standalone.errlog))
  432. os.system('touch %s' % (topology.standalone.errlog))
  433. topology.standalone.start(timeout=120)
  434. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  435. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  436. ecount = int(enabled.readline().rstrip())
  437. dcount = int(disabled.readline().rstrip())
  438. log.info("Enabled ciphers: %d" % ecount)
  439. log.info("Disabled ciphers: %d" % dcount)
  440. if nss_version >= NSS320:
  441. assert ecount == 27
  442. else:
  443. assert ecount == 23
  444. assert dcount == 0
  445. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  446. wcount = int(weak.readline().rstrip())
  447. log.info("Weak ciphers in the default setting: %d" % wcount)
  448. if nss_version >= NSS320:
  449. assert wcount == 7
  450. else:
  451. assert wcount == 11
  452. comp_nsSSLEnableCipherCount(topology, ecount)
  453. def _47838_run_10(topology):
  454. """
  455. Check nsSSL3Ciphers: -TLS_RSA_WITH_NULL_MD5,+TLS_RSA_WITH_RC4_128_MD5,
  456. +TLS_RSA_EXPORT_WITH_RC4_40_MD5,+TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5,
  457. +TLS_DHE_RSA_WITH_DES_CBC_SHA,+SSL_RSA_FIPS_WITH_DES_CBC_SHA,
  458. +TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA,+SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA,
  459. +TLS_RSA_EXPORT1024_WITH_RC4_56_SHA,+TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA,
  460. -SSL_CK_RC4_128_WITH_MD5,-SSL_CK_RC4_128_EXPORT40_WITH_MD5,
  461. -SSL_CK_RC2_128_CBC_WITH_MD5,-SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5,
  462. -SSL_CK_DES_64_CBC_WITH_MD5,-SSL_CK_DES_192_EDE3_CBC_WITH_MD5
  463. allowWeakCipher: on
  464. nsslapd-errorlog-level: 0
  465. """
  466. _header(topology, 'Test Case 11 - Check nsSSL3Ciphers: long list using the NSS Cipher Suite name with allowWeakCipher on')
  467. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  468. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers',
  469. '-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')])
  470. log.info("\n######################### Restarting the server ######################\n")
  471. topology.standalone.stop(timeout=10)
  472. os.system('mv %s %s.47838_9' % (topology.standalone.errlog, topology.standalone.errlog))
  473. os.system('touch %s' % (topology.standalone.errlog))
  474. topology.standalone.start(timeout=120)
  475. enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
  476. disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
  477. ecount = int(enabled.readline().rstrip())
  478. dcount = int(disabled.readline().rstrip())
  479. log.info("Enabled ciphers: %d" % ecount)
  480. log.info("Disabled ciphers: %d" % dcount)
  481. global plus_all_ecount
  482. global plus_all_dcount
  483. if nss_version >= NSS320:
  484. assert ecount == 5
  485. else:
  486. assert ecount == 9
  487. assert dcount == 0
  488. weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
  489. wcount = int(weak.readline().rstrip())
  490. log.info("Weak ciphers in the default setting: %d" % wcount)
  491. topology.standalone.log.info("ticket47838 was successfully verified.")
  492. comp_nsSSLEnableCipherCount(topology, ecount)
  493. def _47838_run_11(topology):
  494. """
  495. Check nsSSL3Ciphers: +fortezza
  496. SSL_GetImplementedCiphers does not return this as a secuire cipher suite
  497. """
  498. _header(topology, 'Test Case 12 - Check nsSSL3Ciphers: +fortezza, which is not supported')
  499. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  500. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+fortezza')])
  501. log.info("\n######################### Restarting the server ######################\n")
  502. topology.standalone.stop(timeout=10)
  503. os.system('mv %s %s.47838_10' % (topology.standalone.errlog, topology.standalone.errlog))
  504. os.system('touch %s' % (topology.standalone.errlog))
  505. topology.standalone.start(timeout=120)
  506. errmsg = os.popen('egrep "SSL alert:" %s | egrep "is not available in NSS"' % topology.standalone.errlog)
  507. if errmsg != "":
  508. log.info("Expected error message:")
  509. log.info("%s" % errmsg.readline())
  510. else:
  511. log.info("Expected error message was not found")
  512. assert False
  513. comp_nsSSLEnableCipherCount(topology, 0)
  514. def _47928_run_0(topology):
  515. """
  516. No SSL version config parameters.
  517. Check SSL3 (TLS1.0) is off.
  518. """
  519. _header(topology, 'Test Case 13 - No SSL version config parameters')
  520. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  521. # add them once and remove them
  522. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3', 'off'),
  523. (ldap.MOD_REPLACE, 'nsTLS1', 'on'),
  524. (ldap.MOD_REPLACE, 'sslVersionMin', 'TLS1.1'),
  525. (ldap.MOD_REPLACE, 'sslVersionMax', 'TLS1.2')])
  526. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_DELETE, 'nsSSL3', None),
  527. (ldap.MOD_DELETE, 'nsTLS1', None),
  528. (ldap.MOD_DELETE, 'sslVersionMin', None),
  529. (ldap.MOD_DELETE, 'sslVersionMax', None)])
  530. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '64')])
  531. log.info("\n######################### Restarting the server ######################\n")
  532. topology.standalone.stop(timeout=10)
  533. os.system('mv %s %s.47838_11' % (topology.standalone.errlog, topology.standalone.errlog))
  534. os.system('touch %s' % (topology.standalone.errlog))
  535. topology.standalone.start(timeout=120)
  536. errmsg = os.popen('egrep "SSL alert:" %s | egrep "Default SSL Version settings; Configuring the version range as min: TLS1.1"' % topology.standalone.errlog)
  537. if errmsg != "":
  538. log.info("Expected message:")
  539. log.info("%s" % errmsg.readline())
  540. else:
  541. log.info("Expected message was not found")
  542. assert False
  543. def _47928_run_1(topology):
  544. """
  545. No nsSSL3, nsTLS1; sslVersionMin > sslVersionMax
  546. Check sslVersionMax is ignored.
  547. """
  548. _header(topology, 'Test Case 14 - No nsSSL3, nsTLS1; sslVersionMin > sslVersionMax')
  549. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  550. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'sslVersionMin', 'TLS1.2'),
  551. (ldap.MOD_REPLACE, 'sslVersionMax', 'TLS1.1')])
  552. log.info("\n######################### Restarting the server ######################\n")
  553. topology.standalone.stop(timeout=10)
  554. os.system('mv %s %s.47838_12' % (topology.standalone.errlog, topology.standalone.errlog))
  555. os.system('touch %s' % (topology.standalone.errlog))
  556. topology.standalone.start(timeout=120)
  557. errmsg = os.popen('egrep "SSL alert:" %s | egrep "The min value of NSS version range"' % topology.standalone.errlog)
  558. if errmsg != "":
  559. log.info("Expected message:")
  560. log.info("%s" % errmsg.readline())
  561. else:
  562. log.info("Expected message was not found")
  563. assert False
  564. errmsg = os.popen('egrep "SSL Initialization" %s | egrep "Configured SSL version range: min: TLS1.2, max: TLS1"' % topology.standalone.errlog)
  565. if errmsg != "":
  566. log.info("Expected message:")
  567. log.info("%s" % errmsg.readline())
  568. else:
  569. log.info("Expected message was not found")
  570. assert False
  571. def _47928_run_2(topology):
  572. """
  573. nsSSL3: on; sslVersionMin: TLS1.1; sslVersionMax: TLS1.2
  574. Conflict between nsSSL3 and range; nsSSL3 is disabled
  575. """
  576. _header(topology, 'Test Case 15 - nsSSL3: on; sslVersionMin: TLS1.1; sslVersionMax: TLS1.2')
  577. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  578. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'sslVersionMin', 'TLS1.1'),
  579. (ldap.MOD_REPLACE, 'sslVersionMax', 'TLS1.2'),
  580. (ldap.MOD_REPLACE, 'nsSSL3', 'on')])
  581. log.info("\n######################### Restarting the server ######################\n")
  582. topology.standalone.stop(timeout=10)
  583. os.system('mv %s %s.47838_13' % (topology.standalone.errlog, topology.standalone.errlog))
  584. os.system('touch %s' % (topology.standalone.errlog))
  585. topology.standalone.start(timeout=120)
  586. errmsg = os.popen('egrep "SSL alert:" %s | egrep "Found unsecure configuration: nsSSL3: on"' % topology.standalone.errlog)
  587. if errmsg != "":
  588. log.info("Expected message:")
  589. log.info("%s" % errmsg.readline())
  590. else:
  591. log.info("Expected message was not found")
  592. assert False
  593. errmsg = os.popen('egrep "SSL alert:" %s | egrep "Respect the supported range."' % topology.standalone.errlog)
  594. if errmsg != "":
  595. log.info("Expected message:")
  596. log.info("%s" % errmsg.readline())
  597. else:
  598. log.info("Expected message was not found")
  599. assert False
  600. errmsg = os.popen('egrep "SSL Initialization" %s | egrep "Configured SSL version range: min: TLS1.1, max: TLS1"' % topology.standalone.errlog)
  601. if errmsg != "":
  602. log.info("Expected message:")
  603. log.info("%s" % errmsg.readline())
  604. else:
  605. log.info("Expected message was not found")
  606. assert False
  607. def _47928_run_3(topology):
  608. """
  609. nsSSL3: on; nsTLS1: off; sslVersionMin: TLS1.1; sslVersionMax: TLS1.2
  610. Conflict between nsSSL3/nsTLS1 and range; nsSSL3 is disabled; nsTLS1 is enabled.
  611. """
  612. _header(topology, 'Test Case 16 - nsSSL3: on; nsTLS1: off; sslVersionMin: TLS1.1; sslVersionMax: TLS1.2')
  613. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  614. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'sslVersionMin', 'TLS1.1'),
  615. (ldap.MOD_REPLACE, 'sslVersionMax', 'TLS1.2'),
  616. (ldap.MOD_REPLACE, 'nsSSL3', 'on'),
  617. (ldap.MOD_REPLACE, 'nsTLS1', 'off')])
  618. log.info("\n######################### Restarting the server ######################\n")
  619. topology.standalone.stop(timeout=10)
  620. os.system('mv %s %s.47838_14' % (topology.standalone.errlog, topology.standalone.errlog))
  621. os.system('touch %s' % (topology.standalone.errlog))
  622. topology.standalone.start(timeout=120)
  623. errmsg = os.popen('egrep "SSL alert:" %s | egrep "Found unsecure configuration: nsSSL3: on"' % topology.standalone.errlog)
  624. if errmsg != "":
  625. log.info("Expected message:")
  626. log.info("%s" % errmsg.readline())
  627. else:
  628. log.info("Expected message was not found")
  629. assert False
  630. errmsg = os.popen('egrep "SSL alert:" %s | egrep "Respect the configured range."' % topology.standalone.errlog)
  631. if errmsg != "":
  632. log.info("Expected message:")
  633. log.info("%s" % errmsg.readline())
  634. else:
  635. log.info("Expected message was not found")
  636. assert False
  637. errmsg = os.popen('egrep "SSL Initialization" %s | egrep "Configured SSL version range: min: TLS1.1, max: TLS1"' % topology.standalone.errlog)
  638. if errmsg != "":
  639. log.info("Expected message:")
  640. log.info("%s" % errmsg.readline())
  641. else:
  642. log.info("Expected message was not found")
  643. assert False
  644. def _47838_run_last(topology):
  645. """
  646. Check nsSSL3Ciphers: all <== invalid value
  647. All ciphers are disabled.
  648. """
  649. _header(topology, 'Test Case 17 - Check nsSSL3Ciphers: all, which is invalid')
  650. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  651. topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', None)])
  652. topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3Ciphers', 'all')])
  653. log.info("\n######################### Restarting the server ######################\n")
  654. topology.standalone.stop(timeout=10)
  655. os.system('mv %s %s.47838_15' % (topology.standalone.errlog, topology.standalone.errlog))
  656. os.system('touch %s' % (topology.standalone.errlog))
  657. topology.standalone.start(timeout=120)
  658. errmsg = os.popen('egrep "SSL alert:" %s | egrep "invalid ciphers"' % topology.standalone.errlog)
  659. if errmsg != "":
  660. log.info("Expected error message:")
  661. log.info("%s" % errmsg.readline())
  662. else:
  663. log.info("Expected error message was not found")
  664. assert False
  665. comp_nsSSLEnableCipherCount(topology, 0)
  666. topology.standalone.log.info("ticket47838, 47880, 47908, 47928 were successfully verified.")
  667. def _47838_final(topology):
  668. topology.standalone.delete()
  669. log.info('Testcase PASSED')
  670. def test_ticket47838(topology):
  671. '''
  672. run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
  673. To run isolated without py.test, you need to
  674. - edit this file and comment '@pytest.fixture' line before 'topology' function.
  675. - set the installation prefix
  676. - run this program
  677. '''
  678. global installation_prefix
  679. installation_prefix = None
  680. _47838_init(topology)
  681. _47838_run_0(topology)
  682. _47838_run_1(topology)
  683. _47838_run_2(topology)
  684. _47838_run_3(topology)
  685. _47838_run_4(topology)
  686. _47838_run_5(topology)
  687. _47838_run_6(topology)
  688. _47838_run_7(topology)
  689. _47838_run_8(topology)
  690. _47838_run_9(topology)
  691. _47838_run_10(topology)
  692. _47838_run_11(topology)
  693. _47928_run_0(topology)
  694. _47928_run_1(topology)
  695. _47928_run_2(topology)
  696. _47928_run_3(topology)
  697. _47838_run_last(topology)
  698. _47838_final(topology)
  699. if __name__ == '__main__':
  700. # Run isolated
  701. # -s for DEBUG mode
  702. CURRENT_FILE = os.path.realpath(__file__)
  703. pytest.main("-s %s" % CURRENT_FILE)