()
| 55 | } |
| 56 | |
| 57 | func (m *mkcert) checkJava() bool { |
| 58 | if !hasKeytool { |
| 59 | return false |
| 60 | } |
| 61 | |
| 62 | // exists returns true if the given x509.Certificate's fingerprint |
| 63 | // is in the keytool -list output |
| 64 | exists := func(c *x509.Certificate, h hash.Hash, keytoolOutput []byte) bool { |
| 65 | h.Write(c.Raw) |
| 66 | fp := strings.ToUpper(hex.EncodeToString(h.Sum(nil))) |
| 67 | return bytes.Contains(keytoolOutput, []byte(fp)) |
| 68 | } |
| 69 | |
| 70 | keytoolOutput, err := exec.Command(keytoolPath, "-list", "-keystore", cacertsPath, "-storepass", storePass).CombinedOutput() |
| 71 | fatalIfCmdErr(err, "keytool -list", keytoolOutput) |
| 72 | // keytool outputs SHA1 and SHA256 (Java 9+) certificates in uppercase hex |
| 73 | // with each octet pair delimitated by ":". Drop them from the keytool output |
| 74 | keytoolOutput = bytes.Replace(keytoolOutput, []byte(":"), nil, -1) |
| 75 | |
| 76 | // pre-Java 9 uses SHA1 fingerprints |
| 77 | s1, s256 := sha1.New(), sha256.New() |
| 78 | return exists(m.caCert, s1, keytoolOutput) || exists(m.caCert, s256, keytoolOutput) |
| 79 | } |
| 80 | |
| 81 | func (m *mkcert) installJava() { |
| 82 | args := []string{ |
no test coverage detected