ticket47838_test.py 37 KB

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