Skip to content

Commit

Permalink
Merge pull request #66 from akakou/hotfix/sslmate-ct-not-work
Browse files Browse the repository at this point in the history
Hotfix/sslmate ct not work
  • Loading branch information
akakou authored May 14, 2024
2 parents 6deab9f + db954b2 commit 38debd8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
30 changes: 22 additions & 8 deletions ttp/ct/sslmatect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (

"github.com/akakou/ra_webs/ttp/audit"
"github.com/akakou/ra_webs/ttp/core"
"github.com/akakou/ra_webs/ttp/ent/taserver"
"github.com/akakou/sslmate-cert-search-api/api"
"github.com/akakou/sslmate-cert-search-api/monitor"
"github.com/labstack/echo/v4"
)

const LAST_FILE = "./last.txt"
const DEFAULT_SLEEP = monitor.DEFAULT_SLEEP
const DEFAULT_MAX_SLEEP = monitor.DEFAULT_SLEEP

type SSLMateCT struct {
Monitors monitor.Monitors
Expand All @@ -29,7 +30,7 @@ func NewSSLMateCT(token string) *SSLMateCT {
Api: *api.New(token),
BaseQuery: api.Query{},
Last: "",
Sleep: DEFAULT_SLEEP,
Sleep: DEFAULT_MAX_SLEEP,
}

return &ct
Expand All @@ -43,7 +44,14 @@ func (ct *SSLMateCT) Setup(e *echo.Echo, ttp *core.TTP) error {

ct.Last = last

err = ct.SyncFromDB(ttp)
if err != nil {
return err
}

go ct.Monitors.Run(func(certs []x509.Certificate, index *api.Index, err error) {
fmt.Println("Now CT check running...")

if err != nil {
fmt.Printf("%v", err)
}
Expand All @@ -61,20 +69,25 @@ func (ct *SSLMateCT) Setup(e *echo.Echo, ttp *core.TTP) error {
time.Sleep(ct.Sleep)
})

fmt.Println("ct started...")

return nil
}

func (ct *SSLMateCT) Update(ttp *core.TTP) error {
servers, err := ttp.DB.Client.TAServer.Query().All(*ttp.DB.Ctx)
func (ct *SSLMateCT) SyncFromDB(ttp *core.TTP) error {
monitors := []monitor.Monitor{}

domains, err := ttp.DB.Client.TAServer.Query().Select(taserver.FieldDomain).Strings(*ttp.DB.Ctx)

if err != nil {
return err
}

monitors := []monitor.Monitor{}
domains = removeDeplication(domains)

for _, server := range servers {
for _, domain := range domains {
query := ct.BaseQuery
query.Domain = server.Domain
query.Domain = domain
query.After = ct.Last

m := monitor.Monitor{
Expand All @@ -87,10 +100,11 @@ func (ct *SSLMateCT) Update(ttp *core.TTP) error {
}

ct.Monitors = monitors
ct.Sleep = DEFAULT_MAX_SLEEP / time.Duration(len(domains))

return nil
}

func (ct *SSLMateCT) Subscribe(_ string, ttp *core.TTP) error {
return ct.Update(ttp)
return ct.SyncFromDB(ttp)
}
14 changes: 14 additions & 0 deletions ttp/ct/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,17 @@ func writeFile(body string) error {

return nil
}

func removeDeplication(src []string) []string {
midMap := make(map[string]bool)
dest := []string{}

for _, id := range src {
if !midMap[id] {
midMap[id] = true
dest = append(dest, id)
}
}

return dest
}

0 comments on commit 38debd8

Please sign in to comment.