OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * HSTS is HTTPS Strict Transport Security: a way for sites to elect to always | 6 * HSTS is HTTPS Strict Transport Security: a way for sites to elect to always |
7 * use HTTPS. See http://dev.chromium.org/sts | 7 * use HTTPS. See http://dev.chromium.org/sts |
8 * | 8 * |
9 * This UI allows a user to query and update the browser's list of HSTS domains. | 9 * This UI allows a user to query and update the browser's list of HSTS domains. |
10 * It also allows users to query and update the browser's list of public key | 10 * It also allows users to query and update the browser's list of public key |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 if (result.result == false) { | 110 if (result.result == false) { |
111 this.queryOutputDiv_.innerHTML = '<b>Not found</b>'; | 111 this.queryOutputDiv_.innerHTML = '<b>Not found</b>'; |
112 yellowFade(this.queryOutputDiv_); | 112 yellowFade(this.queryOutputDiv_); |
113 return; | 113 return; |
114 } | 114 } |
115 | 115 |
116 this.queryOutputDiv_.innerHTML = ''; | 116 this.queryOutputDiv_.innerHTML = ''; |
117 | 117 |
118 var s = addNode(this.queryOutputDiv_, 'span'); | 118 var s = addNode(this.queryOutputDiv_, 'span'); |
119 s.innerHTML = '<b>Found:</b><br/>'; | 119 s.innerHTML = '<b>Found:</b><br/>'; |
120 var t; | |
121 var b; | |
122 | 120 |
123 addTextNode(this.queryOutputDiv_, ' domain: '); | 121 var keys = [ |
124 t = addNodeWithText(this.queryOutputDiv_, 'tt', result.domain); | 122 'domain', 'static_upgrade_mode', 'static_sts_include_subdomains', |
125 b = addNode(this.queryOutputDiv_, 'br'); | 123 'static_pkp_include_subdomains', 'static_sts_observed', |
| 124 'static_pkp_observed', 'static_spki_hashes', 'dynamic_upgrade_mode', |
| 125 'dynamic_sts_include_subdomains', 'dynamic_pkp_include_subdomains', |
| 126 'dynamic_sts_observed', 'dynamic_pkp_observed', 'dynamic_spki_hashes' |
| 127 ]; |
126 | 128 |
127 addTextNode(this.queryOutputDiv_, ' static_upgrade_mode: '); | 129 var kStaticHashKeys = [ |
128 t = addNodeWithText(this.queryOutputDiv_, 'tt', | 130 'public_key_hashes', 'preloaded_spki_hashes', 'static_spki_hashes' |
129 modeToString(result.static_upgrade_mode)); | 131 ]; |
130 b = addNode(this.queryOutputDiv_, 'br'); | |
131 | 132 |
132 addTextNode(this.queryOutputDiv_, ' static_sts_include_subdomains: '); | 133 var staticHashes = []; |
133 t = addNodeWithText(this.queryOutputDiv_, 'tt', | 134 for (var i = 0; i < kStaticHashKeys.length; ++i) { |
134 result.static_sts_include_subdomains); | 135 var staticHashValue = result[kStaticHashKeys[i]]; |
135 b = addNode(this.queryOutputDiv_, 'br'); | 136 if (staticHashValue != undefined && staticHashValue != '') |
| 137 staticHashes.push(staticHashValue); |
| 138 } |
136 | 139 |
137 addTextNode(this.queryOutputDiv_, ' static_pkp_include_subdomains: '); | 140 for (var i = 0; i < keys.length; ++i) { |
138 t = addNodeWithText(this.queryOutputDiv_, 'tt', | 141 var key = keys[i]; |
139 result.static_pkp_include_subdomains); | 142 var value = result[key]; |
140 b = addNode(this.queryOutputDiv_, 'br'); | 143 addTextNode(this.queryOutputDiv_, ' ' + key + ': '); |
141 | 144 |
142 addTextNode(this.queryOutputDiv_, ' static_sts_observed: '); | 145 // If there are no static_hashes, do not make it seem like there is a |
143 t = addNodeWithText(this.queryOutputDiv_, 'tt', | 146 // static PKP policy in place. |
144 result.static_sts_observed); | 147 if (staticHashes.length == 0 && key.indexOf('static_pkp_') == 0) { |
145 b = addNode(this.queryOutputDiv_, 'br'); | 148 addNode(this.queryOutputDiv_, 'br'); |
| 149 continue; |
| 150 } |
146 | 151 |
147 addTextNode(this.queryOutputDiv_, ' static_pkp_observed: '); | 152 if (key === 'static_spki_hashes') { |
148 t = addNodeWithText(this.queryOutputDiv_, 'tt', | 153 addNodeWithText(this.queryOutputDiv_, 'tt', staticHashes.join(',')); |
149 result.static_pkp_observed); | 154 } else if (key.indexOf('_upgrade_mode') >= 0) { |
150 b = addNode(this.queryOutputDiv_, 'br'); | 155 addNodeWithText(this.queryOutputDiv_, 'tt', modeToString(value)); |
151 | 156 } else { |
152 addTextNode(this.queryOutputDiv_, ' static_spki_hashes: '); | 157 addNodeWithText(this.queryOutputDiv_, 'tt', |
153 t = addNode(this.queryOutputDiv_, 'tt'); | 158 value == undefined ? '' : value); |
154 | 159 } |
155 // |public_key_hashes| is an old synonym for what is now | 160 addNode(this.queryOutputDiv_, 'br'); |
156 // |preloaded_spki_hashes|, which in turn is a legacy synonym for | 161 } |
157 // |static_spki_hashes|. | |
158 if (typeof result.public_key_hashes === 'undefined') | |
159 result.public_key_hashes = ''; | |
160 if (typeof result.preloaded_spki_hashes === 'undefined') | |
161 result.preloaded_spki_hashes = ''; | |
162 if (typeof result.static_spki_hashes === 'undefined') | |
163 result.static_spki_hashes = ''; | |
164 | |
165 var hashes = []; | |
166 if (result.public_key_hashes) | |
167 hashes.push(result.public_key_hashes); | |
168 if (result.preloaded_spki_hashes) | |
169 hashes.push(result.preloaded_spki_hashes); | |
170 if (result.static_spki_hashes) | |
171 hashes.push(result.static_spki_hashes); | |
172 | |
173 t.textContent = hashes.join(','); | |
174 b = addNode(this.queryOutputDiv_, 'br'); | |
175 | |
176 addTextNode(this.queryOutputDiv_, ' dynamic_upgrade_mode: '); | |
177 t = addNodeWithText(this.queryOutputDiv_, 'tt', | |
178 modeToString(result.dynamic_upgrade_mode)); | |
179 b = addNode(this.queryOutputDiv_, 'br'); | |
180 | |
181 addTextNode(this.queryOutputDiv_, ' dynamic_sts_include_subdomains: '); | |
182 t = addNodeWithText(this.queryOutputDiv_, 'tt', | |
183 result.dynamic_sts_include_subdomains || ''); | |
184 b = addNode(this.queryOutputDiv_, 'br'); | |
185 | |
186 addTextNode(this.queryOutputDiv_, ' dynamic_pkp_include_subdomains: '); | |
187 t = addNodeWithText(this.queryOutputDiv_, 'tt', | |
188 result.dynamic_pkp_include_subdomains || ''); | |
189 b = addNode(this.queryOutputDiv_, 'br'); | |
190 | |
191 addTextNode(this.queryOutputDiv_, ' dynamic_sts_observed: '); | |
192 t = addNodeWithText(this.queryOutputDiv_, 'tt', | |
193 result.dynamic_sts_observed || ''); | |
194 b = addNode(this.queryOutputDiv_, 'br'); | |
195 | |
196 addTextNode(this.queryOutputDiv_, ' dynamic_pkp_observed: '); | |
197 t = addNodeWithText(this.queryOutputDiv_, 'tt', | |
198 result.dynamic_pkp_observed || ''); | |
199 b = addNode(this.queryOutputDiv_, 'br'); | |
200 | |
201 addTextNode(this.queryOutputDiv_, ' dynamic_spki_hashes: '); | |
202 t = addNodeWithText(this.queryOutputDiv_, 'tt', | |
203 result.dynamic_spki_hashes || ''); | |
204 | 162 |
205 yellowFade(this.queryOutputDiv_); | 163 yellowFade(this.queryOutputDiv_); |
206 } | 164 } |
207 }; | 165 }; |
208 | 166 |
209 function modeToString(m) { | 167 function modeToString(m) { |
210 // These numbers must match those in | 168 // These numbers must match those in |
211 // TransportSecurityState::DomainState::UpgradeMode. | 169 // TransportSecurityState::DomainState::UpgradeMode. |
212 if (m == 0) { | 170 if (m == 0) { |
213 return 'STRICT'; | 171 return 'STRICT'; |
214 } else if (m == 1) { | 172 } else if (m == 1) { |
215 return 'OPPORTUNISTIC'; | 173 return 'OPPORTUNISTIC'; |
216 } else { | 174 } else { |
217 return 'UNKNOWN'; | 175 return 'UNKNOWN'; |
218 } | 176 } |
219 } | 177 } |
220 | 178 |
221 function yellowFade(element) { | 179 function yellowFade(element) { |
222 element.style.webkitTransitionProperty = 'background-color'; | 180 element.style.webkitTransitionProperty = 'background-color'; |
223 element.style.webkitTransitionDuration = '0'; | 181 element.style.webkitTransitionDuration = '0'; |
224 element.style.backgroundColor = '#fffccf'; | 182 element.style.backgroundColor = '#fffccf'; |
225 setTimeout(function() { | 183 setTimeout(function() { |
226 element.style.webkitTransitionDuration = '1000ms'; | 184 element.style.webkitTransitionDuration = '1000ms'; |
227 element.style.backgroundColor = '#fff'; | 185 element.style.backgroundColor = '#fff'; |
228 }, 0); | 186 }, 0); |
229 } | 187 } |
230 | 188 |
231 return HSTSView; | 189 return HSTSView; |
232 })(); | 190 })(); |
OLD | NEW |