initial commit

master
Jean-Louis Huynen 2019-03-27 16:39:46 +01:00
parent 474442da38
commit d351ac3ca4
No known key found for this signature in database
GPG Key ID: 4CDEBABACE9A5DC9
3 changed files with 60 additions and 0 deletions

3
.gitignore vendored
View File

@ -10,3 +10,6 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# vscode
*.vscode

7
README.md Normal file
View File

@ -0,0 +1,7 @@
analyzer-d4-passivessl fetch a redis feed of certificate and TLS sessions and massage the dataset to be usable by lookup-d4-passivessl service.
# Dependencies
```bash
go get github.com/gomodule/redigo/redis
go get github.com/lib/pq
```

50
main.go Normal file
View File

@ -0,0 +1,50 @@
package main
// APACHE 2.0
import (
"database/sql"
"fmt"
"io/ioutil"
"log"
"github.com/gomodule/redigo/redis"
_ "github.com/lib/pq"
)
func main() {
// connect to redis
c, err := redis.Dial("tcp", ":6380", redis.DialDatabase(2))
defer c.Close()
if err != nil {
panic(err)
}
// connect to db
connStr := "user=postgres password=postgres dbname=passivessl"
db, err := sql.Open("postgres", connStr)
defer db.Close()
if err != nil {
panic(err)
}
// pop redis queue
for {
jsonPath, err := redis.String(c.Do("LPOP", "analyzer:ja3-jl:0894517855f047d2a77b4473d3a9cc5b"))
if err != nil {
log.Fatal("Queue processed")
}
// read corresponding json file
dat, err := ioutil.ReadFile(jsonPath)
if err != nil {
log.Fatal(err)
}
q := `INSERT INTO sessions (data) VALUES ($1) RETURNING id`
id := 0
err = db.QueryRow(q, dat).Scan(&id)
if err != nil {
panic(err)
}
fmt.Println("New record ID is:", id)
}
}