Fix for _ssl_secure template ciphers and protocols iterator.

Prod-Related: PROD-34583
Change-Id: Ibda4e90add4d46b51fea341bf92ca41b18508010
diff --git a/nginx/files/_ssl_secure.conf b/nginx/files/_ssl_secure.conf
index 319e37b..f9dcaf3 100644
--- a/nginx/files/_ssl_secure.conf
+++ b/nginx/files/_ssl_secure.conf
@@ -1,8 +1,25 @@
   {#- Using this file is deprecated, it may be silensly removed in future. All options are now set from _ssl.conf #}
   {#- Please check README about new option types #}
-  ssl_protocols {{ site.ssl.get('protocols','TLSv1 TLSv1.1 TLSv1.2') }};
+  {%- if site.ssl.protocols is defined  %}
+    {%- set _protocols = [] %}
+    {%- for protocol_name, protocols in site.ssl.get('protocols', {}).iteritems() %}
+      {%- if protocols.get('enabled', False) %}
+        {%- do _protocols.append(protocols.name) %}
+      {%- endif %}
+    {%- endfor %}
+  ssl_protocols {{ ' '.join(_protocols) }};
+  {%- endif %}
+  {%- if site.ssl.ciphers is defined %}
+    {%- set _ciphers = [] %}
+    {%- for cipher_name, ciphers in site.ssl.get('ciphers', {}).iteritems() %}
+      {%- if ciphers.get('enabled', False) %}
+        {%- do _ciphers.append(ciphers.name) %}
+      {%- endif %}
+    {%- endfor %}
   #https://mozilla.github.io/server-side-tls/ssl-config-generator/
-  ssl_ciphers '{{ site.ssl.get('ciphers','ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS') }}';
+  ssl_ciphers {{ ':'.join(_ciphers) }};
+  {%- endif %}
+
   ssl_ecdh_curve {{ site.ssl.get('ecdh_curve','secp521r1') }};
   {%- if site.ssl.prefer_server_ciphers is defined and site.ssl.prefer_server_ciphers == False %}
   ssl_prefer_server_ciphers off;
diff --git a/tests/pillar/horizon_with_ssl_options.sls b/tests/pillar/horizon_with_ssl_options.sls
index 2bf3324..c82cb4c 100644
--- a/tests/pillar/horizon_with_ssl_options.sls
+++ b/tests/pillar/horizon_with_ssl_options.sls
@@ -143,8 +143,47 @@
             6Jw10sI4/PqU5XVTqSCrvmICOOgZbFRWgCLwJzp5rq0cWvJH0N5PyATL6FfhDGm0
             myUGszN7wRKeJqKa1w==
             -----END CERTIFICATE-----
-          protocols: TLSv1.2
-          ciphers: "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256"
+          protocols:
+            TLS1:
+              name: 'TLSv1'
+              enabled: True
+            TLS1_1:
+              name: 'TLSv1.1'
+              enabled: True
+            TLS1_2:
+              name: 'TLSv1.2'
+              enabled: False
+          ciphers:
+            ECDHE-ECDSA-AES256-GCM-SHA384:
+              name: 'ECDHE-ECDSA-AES256-GCM-SHA384'
+              enabled: True
+            ECDHE-RSA-AES256-GCM-SHA384:
+              name: 'ECDHE-RSA-AES256-GCM-SHA384'
+              enabled: True
+            ECDHE-ECDSA-CHACHA20-POLY1305:
+              name: 'ECDHE-ECDSA-CHACHA20-POLY1305'
+              enabled: True
+            ECDHE-RSA-CHACHA20-POLY1305:
+              name: 'ECDHE-RSA-CHACHA20-POLY1305'
+              enabled: True
+            ECDHE-ECDSA-AES128-GCM-SHA256:
+              name: 'ECDHE-ECDSA-AES128-GCM-SHA256'
+              enabled: True
+            ECDHE-RSA-AES128-GCM-SHA256:
+              name: 'ECDHE-RSA-AES128-GCM-SHA256'
+              enabled: True
+            ECDHE-ECDSA-AES256-SHA384:
+              name: 'ECDHE-ECDSA-AES256-SHA384'
+              enabled: True
+            ECDHE-RSA-AES256-SHA384:
+              name: 'ECDHE-RSA-AES256-SHA384'
+              enabled: True
+            ECDHE-ECDSA-AES128-SHA256:
+              name: 'ECDHE-ECDSA-AES128-SHA256'
+              enabled: True
+            ECDHE-RSA-AES128-SHA256:
+              name: 'ECDHE-RSA-AES128-SHA256'
+              enabled: True
           prefer_server_ciphers: false
           ecdh_curve: secp384r1
 horizon: