| 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 // This program converts the information in | 5 // This program converts the information in |
| 6 // transport_security_state_static.json and | 6 // transport_security_state_static.json and |
| 7 // transport_security_state_static.certs into | 7 // transport_security_state_static.certs into |
| 8 // transport_security_state_static.h. The input files contain information about | 8 // transport_security_state_static.h. The input files contain information about |
| 9 // public key pinning and HTTPS-only sites that is compiled into Chromium. | 9 // public key pinning and HTTPS-only sites that is compiled into Chromium. |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 "strings" | 31 "strings" |
| 32 ) | 32 ) |
| 33 | 33 |
| 34 // A pin represents an entry in transport_security_state_static.certs. It's a | 34 // A pin represents an entry in transport_security_state_static.certs. It's a |
| 35 // name associated with a SubjectPublicKeyInfo hash and, optionally, a | 35 // name associated with a SubjectPublicKeyInfo hash and, optionally, a |
| 36 // certificate. | 36 // certificate. |
| 37 type pin struct { | 37 type pin struct { |
| 38 name string | 38 name string |
| 39 cert *x509.Certificate | 39 cert *x509.Certificate |
| 40 spkiHash []byte | 40 spkiHash []byte |
| 41 » spkiHashFunc string // i.e. "sha1" | 41 » spkiHashFunc string // i.e. "sha1" |
| 42 } | 42 } |
| 43 | 43 |
| 44 // preloaded represents the information contained in the | 44 // preloaded represents the information contained in the |
| 45 // transport_security_state_static.json file. This structure and the two | 45 // transport_security_state_static.json file. This structure and the two |
| 46 // following are used by the "json" package to parse the file. See the comments | 46 // following are used by the "json" package to parse the file. See the comments |
| 47 // in transport_security_state_static.json for details. | 47 // in transport_security_state_static.json for details. |
| 48 type preloaded struct { | 48 type preloaded struct { |
| 49 Pinsets []pinset `json:"pinsets"` | 49 Pinsets []pinset `json:"pinsets"` |
| 50 Entries []hsts `json:"entries"` | 50 Entries []hsts `json:"entries"` |
| 51 } | 51 } |
| 52 | 52 |
| 53 type pinset struct { | 53 type pinset struct { |
| 54 Name string `json:"name"` | 54 Name string `json:"name"` |
| 55 Include []string `json:"static_spki_hashes"` | 55 Include []string `json:"static_spki_hashes"` |
| 56 Exclude []string `json:"bad_static_spki_hashes"` | 56 Exclude []string `json:"bad_static_spki_hashes"` |
| 57 } | 57 } |
| 58 | 58 |
| 59 type hsts struct { | 59 type hsts struct { |
| 60 Name string `json:"name"` | 60 Name string `json:"name"` |
| 61 Subdomains bool `json:"include_subdomains"` | 61 Subdomains bool `json:"include_subdomains"` |
| 62 » Mode string `json:"mode"` | 62 » Mode string `json:"mode"` |
| 63 Pins string `json:"pins"` | 63 Pins string `json:"pins"` |
| 64 SNIOnly bool `json:"snionly"` | 64 SNIOnly bool `json:"snionly"` |
| 65 } | 65 } |
| 66 | 66 |
| 67 func main() { | 67 func main() { |
| 68 if len(os.Args) != 3 { | 68 if len(os.Args) != 3 { |
| 69 fmt.Fprintf(os.Stderr, "Usage: %s <json file> <certificates file
>\n", os.Args[0]) | 69 fmt.Fprintf(os.Stderr, "Usage: %s <json file> <certificates file
>\n", os.Args[0]) |
| 70 os.Exit(1) | 70 os.Exit(1) |
| 71 } | 71 } |
| 72 | 72 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // given CN. | 276 // given CN. |
| 277 func matchNames(name, v string) error { | 277 func matchNames(name, v string) error { |
| 278 words := strings.Split(name, " ") | 278 words := strings.Split(name, " ") |
| 279 if len(words) == 0 { | 279 if len(words) == 0 { |
| 280 return errors.New("no words in certificate name") | 280 return errors.New("no words in certificate name") |
| 281 } | 281 } |
| 282 firstWord := words[0] | 282 firstWord := words[0] |
| 283 if strings.HasSuffix(firstWord, ",") { | 283 if strings.HasSuffix(firstWord, ",") { |
| 284 firstWord = firstWord[:len(firstWord)-1] | 284 firstWord = firstWord[:len(firstWord)-1] |
| 285 } | 285 } |
| 286 if strings.HasPrefix(firstWord, "*.") { |
| 287 firstWord = firstWord[2:] |
| 288 } |
| 286 if pos := strings.Index(firstWord, "."); pos != -1 { | 289 if pos := strings.Index(firstWord, "."); pos != -1 { |
| 287 firstWord = firstWord[:pos] | 290 firstWord = firstWord[:pos] |
| 288 } | 291 } |
| 289 if pos := strings.Index(firstWord, "-"); pos != -1 { | 292 if pos := strings.Index(firstWord, "-"); pos != -1 { |
| 290 firstWord = firstWord[:pos] | 293 firstWord = firstWord[:pos] |
| 291 } | 294 } |
| 292 » if !strings.HasPrefix(v, firstWord) { | 295 » if len(firstWord) == 0 { |
| 296 » » return errors.New("first word of certificate name is empty") |
| 297 » } |
| 298 » firstWord = strings.ToLower(firstWord) |
| 299 » lowerV := strings.ToLower(v) |
| 300 » if !strings.HasPrefix(lowerV, firstWord) { |
| 293 return errors.New("the first word of the certificate name isn't
a prefix of the variable name") | 301 return errors.New("the first word of the certificate name isn't
a prefix of the variable name") |
| 294 } | 302 } |
| 295 | 303 |
| 296 for i, word := range words { | 304 for i, word := range words { |
| 297 if word == "Class" && i+1 < len(words) { | 305 if word == "Class" && i+1 < len(words) { |
| 298 if strings.Index(v, word+words[i+1]) == -1 { | 306 if strings.Index(v, word+words[i+1]) == -1 { |
| 299 return errors.New("class specification doesn't a
ppear in the variable name") | 307 return errors.New("class specification doesn't a
ppear in the variable name") |
| 300 } | 308 } |
| 301 } else if len(word) == 1 && word[0] >= '0' && word[0] <= '9' { | 309 } else if len(word) == 1 && word[0] >= '0' && word[0] <= '9' { |
| 302 if strings.Index(v, word) == -1 { | 310 if strings.Index(v, word) == -1 { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 var name string | 457 var name string |
| 450 var l int | 458 var l int |
| 451 for _, label := range labels { | 459 for _, label := range labels { |
| 452 if len(label) > 63 { | 460 if len(label) > 63 { |
| 453 panic("DNS label too long") | 461 panic("DNS label too long") |
| 454 } | 462 } |
| 455 name += fmt.Sprintf("\\%03o", len(label)) | 463 name += fmt.Sprintf("\\%03o", len(label)) |
| 456 name += label | 464 name += label |
| 457 l += len(label) + 1 | 465 l += len(label) + 1 |
| 458 } | 466 } |
| 459 » l += 1 // For the length of the root label. | 467 » l += 1 // For the length of the root label. |
| 460 | 468 |
| 461 return name, l | 469 return name, l |
| 462 } | 470 } |
| 463 | 471 |
| 464 // domainConstant converts the domain name |s| into a string of the form | 472 // domainConstant converts the domain name |s| into a string of the form |
| 465 // "DOMAIN_" + uppercase last two labels. | 473 // "DOMAIN_" + uppercase last two labels. |
| 466 func domainConstant(s string) string { | 474 func domainConstant(s string) string { |
| 467 labels := strings.Split(s, ".") | 475 labels := strings.Split(s, ".") |
| 468 gtld := strings.ToUpper(labels[len(labels)-1]) | 476 gtld := strings.ToUpper(labels[len(labels)-1]) |
| 469 domain := strings.Replace(strings.ToUpper(labels[len(labels)-2]), "-", "
_", -1) | 477 domain := strings.Replace(strings.ToUpper(labels[len(labels)-2]), "-", "
_", -1) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 writeHSTSEntry(out, entry) | 546 writeHSTSEntry(out, entry) |
| 539 } | 547 } |
| 540 | 548 |
| 541 out.WriteString(`}; | 549 out.WriteString(`}; |
| 542 static const size_t kNumPreloadedSNISTS = ARRAYSIZE_UNSAFE(kPreloadedSNISTS); | 550 static const size_t kNumPreloadedSNISTS = ARRAYSIZE_UNSAFE(kPreloadedSNISTS); |
| 543 | 551 |
| 544 `) | 552 `) |
| 545 | 553 |
| 546 return nil | 554 return nil |
| 547 } | 555 } |
| OLD | NEW |