credential

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package credential provides domain types for credential leak management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Classification

type Classification string

Classification represents the exposure classification.

const (
	ClassificationInternal Classification = "internal"
	ClassificationExternal Classification = "external"
	ClassificationPartner  Classification = "partner"
	ClassificationVendor   Classification = "vendor"
	ClassificationUnknown  Classification = "unknown"
)

func AllClassifications

func AllClassifications() []Classification

AllClassifications returns all valid classifications.

func ParseClassification

func ParseClassification(str string) (Classification, error)

ParseClassification parses a string into a Classification.

func (Classification) IsValid

func (c Classification) IsValid() bool

IsValid checks if the classification is valid.

func (Classification) String

func (c Classification) String() string

String returns the string representation.

type CredentialContext

type CredentialContext struct {
	Username   string `json:"username,omitempty"`
	Email      string `json:"email,omitempty"`
	Domain     string `json:"domain,omitempty"`
	IPAddress  string `json:"ip_address,omitempty"`
	UserAgent  string `json:"user_agent,omitempty"`
	LineNumber int    `json:"line_number,omitempty"`

	// Additional arbitrary data
	Extra map[string]any `json:"extra,omitempty"`
}

CredentialContext contains additional context about the credential.

type CredentialImport

type CredentialImport struct {
	// Core fields (required)
	Identifier     string         `json:"identifier" validate:"required,max=500"`
	CredentialType CredentialType `json:"credential_type" validate:"required"`

	// Secret value (the actual leaked credential - password, API key, etc.)
	// This is sensitive data and should be encrypted at rest
	SecretValue string `json:"secret_value,omitempty"`

	// Source information (required)
	Source CredentialSource `json:"source" validate:"required"`

	// Severity and classification
	Severity       string         `json:"severity,omitempty"`       // If empty, auto-determined by credential type
	Classification Classification `json:"classification,omitempty"` // internal, external, partner, vendor

	// Deduplication key components
	DedupKey DedupKey `json:"dedup_key"`

	// Context information
	Context CredentialContext `json:"context"`

	// Status flags
	IsVerified bool `json:"is_verified,omitempty"`
	IsRevoked  bool `json:"is_revoked,omitempty"`

	// Tags and notes
	Tags  []string `json:"tags,omitempty"`
	Notes string   `json:"notes,omitempty"`
}

CredentialImport represents a single credential to import.

func (*CredentialImport) CalculateFingerprint

func (c *CredentialImport) CalculateFingerprint(tenantID string) string

CalculateFingerprint generates a SHA256 fingerprint for deduplication. The fingerprint is calculated based on the source type to ensure proper deduplication.

func (*CredentialImport) GetClassification

func (c *CredentialImport) GetClassification() Classification

GetClassification returns the classification or default.

func (*CredentialImport) GetSeverity

func (c *CredentialImport) GetSeverity(autoClassify bool) string

GetSeverity returns the severity, auto-determining if not set.

func (*CredentialImport) GetSourceString

func (c *CredentialImport) GetSourceString() string

GetSourceString returns formatted source string for exposure event.

func (*CredentialImport) ToDetails

func (c *CredentialImport) ToDetails() map[string]any

ToDetails converts credential import to exposure event details map.

type CredentialSource

type CredentialSource struct {
	Type         SourceType `json:"type" validate:"required"`
	Name         string     `json:"name,omitempty"`          // e.g., "HIBP", "SpyCloud", "GitGuardian"
	URL          string     `json:"url,omitempty"`           // Source URL if applicable
	DiscoveredAt *time.Time `json:"discovered_at,omitempty"` // When the credential was discovered
}

CredentialSource contains source information.

type CredentialType

type CredentialType string

CredentialType represents the type of leaked credential.

const (
	CredentialTypePassword      CredentialType = "password"
	CredentialTypePasswordHash  CredentialType = "password_hash"
	CredentialTypeAPIKey        CredentialType = "api_key"
	CredentialTypeAccessToken   CredentialType = "access_token"
	CredentialTypeRefreshToken  CredentialType = "refresh_token"
	CredentialTypePrivateKey    CredentialType = "private_key"
	CredentialTypeSSHKey        CredentialType = "ssh_key"
	CredentialTypeCertificate   CredentialType = "certificate"
	CredentialTypeAWSKey        CredentialType = "aws_key"
	CredentialTypeGCPKey        CredentialType = "gcp_key"
	CredentialTypeAzureKey      CredentialType = "azure_key"
	CredentialTypeDatabaseCred  CredentialType = "database_cred"
	CredentialTypeJWTSecret     CredentialType = "jwt_secret"
	CredentialTypeEncryptionKey CredentialType = "encryption_key"
	CredentialTypeWebhookSecret CredentialType = "webhook_secret"
	CredentialTypeSMTPCred      CredentialType = "smtp_cred"
	CredentialTypeOther         CredentialType = "other"
)

func AllCredentialTypes

func AllCredentialTypes() []CredentialType

AllCredentialTypes returns all valid credential types.

func ParseCredentialType

func ParseCredentialType(s string) (CredentialType, error)

ParseCredentialType parses a string into a CredentialType.

func (CredentialType) DefaultSeverity

func (t CredentialType) DefaultSeverity() string

DefaultSeverity returns the default severity for this credential type.

func (CredentialType) IsValid

func (t CredentialType) IsValid() bool

IsValid checks if the credential type is valid.

func (CredentialType) String

func (t CredentialType) String() string

String returns the string representation.

type DedupKey

type DedupKey struct {
	// For data breach credentials
	BreachName string `json:"breach_name,omitempty"`
	BreachDate string `json:"breach_date,omitempty"` // YYYY-MM-DD format

	// For code repository credentials
	Repository string `json:"repository,omitempty"`
	FilePath   string `json:"file_path,omitempty"`
	CommitHash string `json:"commit_hash,omitempty"`
	Branch     string `json:"branch,omitempty"`

	// For dark web / paste site credentials
	SourceURL string `json:"source_url,omitempty"`
	PasteID   string `json:"paste_id,omitempty"`
}

DedupKey contains fields used for deduplication fingerprint.

type DedupStrategy

type DedupStrategy string

DedupStrategy defines how to handle duplicate credentials.

const (
	DedupStrategySkip           DedupStrategy = "skip"
	DedupStrategyUpdateLastSeen DedupStrategy = "update_last_seen"
	DedupStrategyUpdateAll      DedupStrategy = "update_all"
	DedupStrategyCreateNew      DedupStrategy = "create_new"
)

func AllDedupStrategies

func AllDedupStrategies() []DedupStrategy

AllDedupStrategies returns all valid deduplication strategies.

func ParseDedupStrategy

func ParseDedupStrategy(str string) DedupStrategy

ParseDedupStrategy parses a string into a DedupStrategy.

func (DedupStrategy) IsValid

func (d DedupStrategy) IsValid() bool

IsValid checks if the dedup strategy is valid.

func (DedupStrategy) String

func (d DedupStrategy) String() string

String returns the string representation.

type ImportError

type ImportError struct {
	Index      int    `json:"index"`
	Identifier string `json:"identifier"`
	Error      string `json:"error"`
}

ImportError represents an error during import of a single credential.

type ImportItemResult

type ImportItemResult struct {
	Index      int    `json:"index"`
	Identifier string `json:"identifier"`
	Action     string `json:"action"` // imported, updated, reactivated, skipped, error
	Reason     string `json:"reason,omitempty"`
	ID         string `json:"id,omitempty"` // Exposure event ID if created/updated
}

ImportItemResult represents the result of importing a single credential.

type ImportMetadata

type ImportMetadata struct {
	SourceTool  string    `json:"source_tool,omitempty"` // e.g., "hibp", "spycloud", "manual"
	ImportDate  time.Time `json:"import_date,omitempty"`
	BatchID     string    `json:"batch_id,omitempty"` // For tracking related imports
	Description string    `json:"description,omitempty"`
}

ImportMetadata contains metadata about the import.

type ImportOptions

type ImportOptions struct {
	DedupStrategy        DedupStrategy `json:"dedup_strategy,omitempty"`         // How to handle duplicates
	ReactivateResolved   bool          `json:"reactivate_resolved,omitempty"`    // Reactivate resolved credentials if found again
	NotifyReactivated    bool          `json:"notify_reactivated,omitempty"`     // Send alert when credential is reactivated
	NotifyNewCritical    bool          `json:"notify_new_critical,omitempty"`    // Send alert on new critical findings
	AutoClassifySeverity bool          `json:"auto_classify_severity,omitempty"` // Auto-determine severity if not provided
}

ImportOptions configures import behavior.

func DefaultImportOptions

func DefaultImportOptions() ImportOptions

DefaultImportOptions returns default import options.

type ImportRequest

type ImportRequest struct {
	Credentials []CredentialImport `json:"credentials" validate:"required,min=1,max=1000,dive"`
	Options     ImportOptions      `json:"options"`
	Metadata    ImportMetadata     `json:"metadata"`
}

ImportRequest represents a bulk import request.

type ImportResult

type ImportResult struct {
	Imported    int                `json:"imported"`
	Updated     int                `json:"updated"`
	Reactivated int                `json:"reactivated"`
	Skipped     int                `json:"skipped"`
	Errors      []ImportError      `json:"errors,omitempty"`
	Details     []ImportItemResult `json:"details,omitempty"`
	Summary     ImportSummary      `json:"summary"`
}

ImportResult represents the result of an import operation.

type ImportSummary

type ImportSummary struct {
	TotalProcessed       int  `json:"total_processed"`
	SuccessCount         int  `json:"success_count"`
	ErrorCount           int  `json:"error_count"`
	CriticalCount        int  `json:"critical_count"`
	ReactivatedAlertSent bool `json:"reactivated_alert_sent"`
}

ImportSummary provides summary statistics.

type SourceType

type SourceType string

SourceType represents the source where credential was found.

const (
	// Breach sources
	SourceTypeDataBreach       SourceType = "data_breach"
	SourceTypeDarkWeb          SourceType = "dark_web"
	SourceTypePasteSite        SourceType = "paste_site"
	SourceTypeUndergroundForum SourceType = "underground_forum"

	// Code sources
	SourceTypeCodeRepository SourceType = "code_repository"
	SourceTypeCommitHistory  SourceType = "commit_history"
	SourceTypeConfigFile     SourceType = "config_file"
	SourceTypeLogFile        SourceType = "log_file"
	SourceTypeCICD           SourceType = "ci_cd"
	SourceTypeDockerImage    SourceType = "docker_image"

	// Other sources
	SourceTypePhishing     SourceType = "phishing"
	SourceTypeMalware      SourceType = "malware"
	SourceTypePublicBucket SourceType = "public_bucket"
	SourceTypeAPIResponse  SourceType = "api_response"
	SourceTypeInternal     SourceType = "internal_report"
	SourceTypeOther        SourceType = "other"
)

func AllSourceTypes

func AllSourceTypes() []SourceType

AllSourceTypes returns all valid source types.

func ParseSourceType

func ParseSourceType(str string) (SourceType, error)

ParseSourceType parses a string into a SourceType.

func (SourceType) IsBreachSource

func (s SourceType) IsBreachSource() bool

IsBreachSource returns true if this is a breach-related source.

func (SourceType) IsCodeSource

func (s SourceType) IsCodeSource() bool

IsCodeSource returns true if this is a code-related source.

func (SourceType) IsValid

func (s SourceType) IsValid() bool

IsValid checks if the source type is valid.

func (SourceType) String

func (s SourceType) String() string

String returns the string representation.

Jump to

Keyboard shortcuts

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