2
0
mirror of https://github.com/namecoin/ncdns synced 2024-11-16 00:13:01 +00:00
ncdns/tlshook/tlshook.go

61 lines
1.3 KiB
Go
Raw Normal View History

//go:build !no_namecoin_tls
2019-10-04 03:10:40 +00:00
// +build !no_namecoin_tls
package tlshook
import (
2017-11-04 08:00:09 +00:00
"github.com/hlandau/xlog"
"github.com/namecoin/ncdns/certdehydrate"
"github.com/namecoin/ncdns/certinject"
"github.com/namecoin/ncdns/ncdomain"
)
var log, Log = xlog.New("ncdns.tlshook")
func DomainValueHookTLS(qname string, ncv *ncdomain.Value) (err error) {
2017-11-04 08:00:09 +00:00
log.Info("Intercepted a Value for ", qname)
if protocol, ok := ncv.Map["_tcp"]; ok { // TODO: look into allowing non-TCP protocols
log.Info("Saw a request with TCP")
if port, ok := protocol.Map["_443"]; ok { // TODO: check all ports, not just 443
log.Info("Saw a request with TCP port 443")
2017-11-04 08:00:09 +00:00
// For dehydrated certificates
if len(port.TLSAGenerated) > 0 {
2017-11-04 08:00:09 +00:00
log.Info("Just saw a TLS port 443 capable domain request for ", qname, "!")
2017-11-04 08:00:09 +00:00
for index, cert := range port.TLSAGenerated {
2017-11-04 08:00:09 +00:00
log.Info("Using dehydrated certificate # ", index)
2017-11-04 08:00:09 +00:00
template := cert
2017-11-04 08:00:09 +00:00
var derBytes []byte
2017-11-04 08:00:09 +00:00
derBytes, err = certdehydrate.FillRehydratedCertTemplate(template, qname)
if err != nil {
log.Info("Failed to create certificate: ", err)
continue
}
2017-11-04 08:00:09 +00:00
// TODO: check return value
certinject.InjectCert(derBytes)
2017-11-04 08:00:09 +00:00
}
2017-11-04 08:00:09 +00:00
}
2017-11-04 08:00:09 +00:00
// TODO: support non-dehydrated certificates
}
}
2017-11-04 08:00:09 +00:00
// remove any certs that aren't valid anymore
certinject.CleanCerts()
2017-11-04 08:00:09 +00:00
err = nil
2017-11-04 08:00:09 +00:00
return
2017-11-04 08:00:09 +00:00
}