database

package
v0.0.0-...-74867d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2017 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCertStore = fmt.Errorf("Invalid certificate store provided")

Functions

This section is empty.

Types

type Analyses

type Analyses []Analysis

func (Analyses) Len

func (slice Analyses) Len() int

func (Analyses) Less

func (slice Analyses) Less(i, j int) bool

func (Analyses) Swap

func (slice Analyses) Swap(i, j int)

type Analysis

type Analysis struct {
	ID       int64           `json:"id"`
	Analyzer string          `json:"analyzer"`
	Result   json.RawMessage `json:"result"`
	Success  bool            `json:"success"`
}

type DB

type DB struct {
	*sql.DB
}

func RegisterConnection

func RegisterConnection(dbname, user, password, hostport, sslmode string) (*DB, error)

func (*DB) AddCertToAndroidTruststore

func (db *DB) AddCertToAndroidTruststore(id int64) error

func (*DB) AddCertToAppleTruststore

func (db *DB) AddCertToAppleTruststore(id int64) error

func (*DB) AddCertToMicrosoftTruststore

func (db *DB) AddCertToMicrosoftTruststore(id int64) error

func (*DB) AddCertToMozillaTruststore

func (db *DB) AddCertToMozillaTruststore(id int64) error

func (*DB) AddCertToUbuntuTruststore

func (db *DB) AddCertToUbuntuTruststore(id int64) error

func (*DB) CountDistinctCertsAddedLast24Hours

func (db *DB) CountDistinctCertsAddedLast24Hours() (count int64, err error)

CountDistinctCertsAddedLast24Hours returns the count of unique certificates added over the last 24 hours

func (*DB) CountDistinctCertsSeenLast24Hours

func (db *DB) CountDistinctCertsSeenLast24Hours() (count int64, err error)

CountDistinctCertsSeenLast24Hours returns the count of unique certificates seen over the last 24 hours

func (*DB) CountDistinctTargetsLast24Hours

func (db *DB) CountDistinctTargetsLast24Hours() (count int64, err error)

CountDistinctTargetsLast24Hours returns the number of unique targets scanned over the last 24 hours

func (*DB) CountLast24HoursScans

func (db *DB) CountLast24HoursScans() (hourlyStats []HourlyScansCount, err error)

CountLast24HoursScans returns a list of hourly scans count for the last 24 hours, sorted from most recent the oldest

func (*DB) CountPendingScans

func (db *DB) CountPendingScans() (count int64, err error)

CountPendingScans returns the total number of scans that are pending in the queue

func (*DB) CountTableEntries

func (db *DB) CountTableEntries() (scans, trusts, analyses, certificates int64, err error)

CountTableEntries returns the estimated count of scans, trusts relationships, analyses and certificates stored in database. The count uses Postgres' own stats counter and is not guaranteed to be fully accurate.

func (*DB) GetAllCertsInStore

func (db *DB) GetAllCertsInStore(store string) (out []certificate.Certificate, err error)

func (*DB) GetAnalysisByScan

func (db *DB) GetAnalysisByScan(id int64) ([]Analysis, error)

func (*DB) GetCACertsBySubject

func (db *DB) GetCACertsBySubject(subject certificate.Subject) (certs []*certificate.Certificate, err error)

GetCACertsBySubject returns a list of CA certificates that match a given subject

func (*DB) GetCertByID

func (db *DB) GetCertByID(certID int64) (*certificate.Certificate, error)

GetCertByID fetches a certain certificate from the database. It returns a pointer to a Certificate struct and any errors that occur.

func (*DB) GetCertBySHA1Fingerprint

func (db *DB) GetCertBySHA1Fingerprint(sha1 string) (*certificate.Certificate, error)

GetCertBySHA1Fingerprint fetches a certain certificate from the database. It returns a pointer to a Certificate struct and any errors that occur.

func (*DB) GetCertIDBySHA1Fingerprint

func (db *DB) GetCertIDBySHA1Fingerprint(sha1 string) (id int64, err error)

GetCertIDWithSHA1Fingerprint fetches the database id of the certificate with the given SHA1 fingerprint. Returns the mentioned id and any errors that happen. It wraps the sql.ErrNoRows error in order to avoid passing not existing row errors to upper levels. In that case it returns -1 with no error.

func (*DB) GetCertIDBySHA256Fingerprint

func (db *DB) GetCertIDBySHA256Fingerprint(sha256 string) (id int64, err error)

GetCertIDWithSHA256Fingerprint fetches the database id of the certificate with the given SHA256 fingerprint. Returns the mentioned id and any errors that happen. It wraps the sql.ErrNoRows error in order to avoid passing not existing row errors to upper levels. In that case it returns -1 with no error.

func (*DB) GetCertIDFromTrust

func (db *DB) GetCertIDFromTrust(trustID int64) (id int64, err error)

GetCertIDFromTrust fetches the database id of the certificate in the trust relation with the given id. Returns the mentioned id and any errors that happen. It wraps the sql.ErrNoRows error in order to avoid passing not existing row errors to upper levels. In that case it returns -1 with no error.

func (*DB) GetCertPaths

func (db *DB) GetCertPaths(cert *certificate.Certificate) (paths certificate.Paths, err error)

GetCertPaths returns the various certificates paths from the current cert to roots. It takes a certificate as argument that will be used as the start of the path.

func (*DB) GetCurrentTrustID

func (db *DB) GetCurrentTrustID(certID, issuerID int64) (int64, error)

func (*DB) GetCurrentTrustIDForCert

func (db *DB) GetCurrentTrustIDForCert(certID int64) (int64, error)

func (*DB) GetEECountForIssuerByID

func (db *DB) GetEECountForIssuerByID(certID int64) (count int64, err error)

GetEECountForIssuerByID gets the count of valid end entity certificates in the database that chain to the certificate with the specified ID

func (*DB) GetLastScanTimeForTarget

func (db *DB) GetLastScanTimeForTarget(target string) (int64, time.Time, error)

GetLastScanTimeForTarget searches the database for the latest scan for a specific target. It returns both the scan timestamp and the id of the scan to enable the api to respond to clients with just one db query.

func (*DB) GetScanByID

func (db *DB) GetScanByID(id int64) (Scan, error)

func (*DB) GetValidationMapForCert

func (db *DB) GetValidationMapForCert(certID int64) (map[string]certificate.ValidationInfo, int64, error)

func (*DB) InsertCertificate

func (db *DB) InsertCertificate(cert *certificate.Certificate) (int64, error)

InsertCertificate inserts a x509 certificate to the database. It takes as input a Certificate pointer. It returns the database ID of the inserted certificate ( -1 if an error occurs ) and an error, if it occurs.

func (*DB) InsertTrustToDB

func (db *DB) InsertTrustToDB(cert certificate.Certificate, certID, parID int64) (int64, error)

func (*DB) InsertWorkerAnalysis

func (db *DB) InsertWorkerAnalysis(scanid int64, jsonRes []byte, workerName string) error

func (*DB) IsTrustValid

func (db *DB) IsTrustValid(id int64) (bool, error)

IsTrustValid returns the validity of the trust relationship for the given id. It returns a "valid" if any of the per truststore valitities is valid It returns a boolean that represent if trust is valid or not.

func (*DB) NewScan

func (db *DB) NewScan(domain string, rplay int, jsonParams []byte) (Scan, error)

func (*DB) RegisterScanListener

func (db *DB) RegisterScanListener(dbname, user, password, hostport, sslmode string) <-chan int64

RegisterScanListener "subscribes" to the notifications published to the scan_listener notifier. It has as input the usual db attributes and returns an int64 channel which can be consumed for newly created scan id's.

func (*DB) RemoveCACertFromTruststore

func (db *DB) RemoveCACertFromTruststore(trustedCerts []string, tsName string) error

RemoveCACertFromTruststore takes a list of hashes from certs trusted by a given truststore and disables the trust of all certs not listed but trusted in DB

func (*DB) UpdateCertLastSeen

func (db *DB) UpdateCertLastSeen(cert *certificate.Certificate) error

UpdateCertLastSeen updates the last_seen timestamp of the input certificate. Outputs an error if it occurs.

func (*DB) UpdateCertLastSeenByID

func (db *DB) UpdateCertLastSeenByID(id int64) error

UpdateCertLastSeenWithID updates the last_seen timestamp of the certificate with the given id. Outputs an error if it occurs.

func (*DB) UpdateCertificateRank

func (db *DB) UpdateCertificateRank(id, rank int64) error

UpdateCertificateRank updates the rank integer of the input certificate.

func (*DB) UpdateScanCompletionPercentage

func (db *DB) UpdateScanCompletionPercentage(id int64, p int) error

func (*DB) UpdateTrust

func (db *DB) UpdateTrust(trustID int64, cert certificate.Certificate) (int64, error)

type HourlyScansCount

type HourlyScansCount struct {
	Hour  time.Time `json:"hour"`
	Count int64     `json:"count"`
}

HourlyScansCount represents the number of scans completed over one hour

type Scan

type Scan struct {
	ID               int64                  `json:"id"`
	Timestamp        time.Time              `json:"timestamp"`
	Target           string                 `json:"target"`
	Replay           int                    `json:"replay"` //hours or days
	Has_tls          bool                   `json:"has_tls"`
	Cert_id          int64                  `json:"cert_id"`
	Trust_id         int64                  `json:"trust_id"`
	Is_valid         bool                   `json:"is_valid"`
	Validation_error string                 `json:"validation_error,omitempty"`
	Complperc        int                    `json:"completion_perc"`
	Conn_info        connection.Stored      `json:"connection_info"`
	AnalysisResults  Analyses               `json:"analysis,omitempty"`
	Ack              bool                   `json:"ack"`
	Attempts         int                    `json:"attempts"` //number of retries
	AnalysisParams   map[string]interface{} `json:"analysis_params"`
}

type Scannable

type Scannable interface {
	Scan(dest ...interface{}) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL