Skip to content

Commit

Permalink
Added wait for certificate to get indexed into ES when pushed
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdiba committed Feb 8, 2015
1 parent bd6992d commit 195d85c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/certAnalyser/analyserPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,38 @@ func HandleCertChain(certificate *x509.Certificate, intermediates []*x509.Certif

}

func waitForIndexedCert(ID string) bool {

wasIndexed := false

maxwait := time.Second * 2

start := time.Now()

for {
searchJson := `{
"query" : {
"term" : { "_id" : "` + ID + `" }
}
}`
res, e := es.Search("certificates", "certificateInfo", nil, searchJson)
panicIf(e)
if res.Hits.Total > 0 {
wasIndexed = true
break
}

if time.Now().After(start.Add(maxwait)) {
log.Println("Timeout passed waiting for cert:", ID)
break
}

time.Sleep(time.Millisecond * 5)
}

return wasIndexed
}

//Returns the first parent found for a certificate in a given certificate list ( does not verify signature)
func getFirstParent(cert *x509.Certificate, certs []*x509.Certificate) *x509.Certificate {
for _, c := range certs {
Expand Down Expand Up @@ -418,6 +450,9 @@ func pushCertificate(cert *x509.Certificate, parentSignature string, domain, ip,
log.Println("Stored cert id", SHA256Hash(cert.Raw), "subject cn", cert.Subject.CommonName)
}

//wait for the certificate to get indexed in ES
waitForIndexedCert(SHA256Hash(cert.Raw))

}

func getExtKeyUsageAsStringArray(cert *x509.Certificate) []string {
Expand Down

2 comments on commit 195d85c

@jvehent
Copy link
Contributor

@jvehent jvehent commented on 195d85c Feb 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently ES indexes every second by default, so maybe the waiter should sleep for 300ms between iterations, and never more than 3 to 5 seconds?

@0xdiba
Copy link
Contributor Author

@0xdiba 0xdiba commented on 195d85c Feb 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. I'll update the code.

Thanks

Please sign in to comment.