-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability for html test to accept servers using AIA.
Generate an error instead of a warning as these are likely due to issues with a remote server out of your control and will work in most browsers.
- Loading branch information
1 parent
d9b1c7e
commit 7cb03ea
Showing
4 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<html> | ||
|
||
<body> | ||
|
||
<p>Blah blah blah. <a href="https://github.com/octocat/Spoon-Knife/issues">An HTTPS link!</a></p> | ||
|
||
<p> | ||
<a href="https://incomplete-chain.badssl.com/">incomplete-chain</a> | ||
</p> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,78 @@ | ||
package htmltest | ||
|
||
import "net/http" | ||
import ( | ||
"crypto/x509" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
type CertChainErr struct { | ||
cert *x509.Certificate | ||
chain *x509.CertPool | ||
hintErr error | ||
} | ||
|
||
func (e CertChainErr) Error() string { | ||
s := "x509: could not validate certificate chain" | ||
if e.hintErr != nil { | ||
s += fmt.Sprintf(" (possibly because of %q)", e.hintErr) | ||
} | ||
return s | ||
} | ||
|
||
func statusCodeValid(code int) bool { | ||
return code == http.StatusPartialContent || code == http.StatusOK | ||
} | ||
|
||
func validateCertChain(cert *x509.Certificate) (err error) { | ||
if cert.IssuingCertificateURL == nil { | ||
return CertChainErr{cert: cert} | ||
} | ||
|
||
intermediates := x509.NewCertPool() | ||
//roots, err := x509.SystemCertPool() | ||
if err != nil { | ||
return CertChainErr{cert: cert} | ||
} | ||
var certsToFetch []string = cert.IssuingCertificateURL | ||
|
||
for i := 0; i < len(certsToFetch); i++ { | ||
url := certsToFetch[i] | ||
|
||
resp, err := http.Get(url) | ||
if err != nil { | ||
return CertChainErr{cert: cert, chain: intermediates, hintErr: err} | ||
} | ||
|
||
if resp.StatusCode != 200 { | ||
return CertChainErr{cert: cert, chain: intermediates, hintErr: fmt.Errorf("could not fetch certificate at %s (status %d)", url, resp.StatusCode)} | ||
} | ||
|
||
certBytes, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return CertChainErr{cert: cert, chain: intermediates, hintErr: err} | ||
} | ||
|
||
newCert, err := x509.ParseCertificate(certBytes) | ||
if err != nil { | ||
return CertChainErr{cert: cert, chain: intermediates, hintErr: err} | ||
} | ||
|
||
if newCert.CheckSignatureFrom(cert) == nil { | ||
// we have out root | ||
break | ||
} | ||
|
||
intermediates.AddCert(newCert) | ||
|
||
if newCert.IssuingCertificateURL != nil { | ||
certsToFetch = append(certsToFetch, newCert.IssuingCertificateURL...) | ||
} | ||
} | ||
|
||
_, err = cert.Verify(x509.VerifyOptions{ | ||
Intermediates: intermediates, | ||
}) | ||
return | ||
} |