Skip to content

Commit

Permalink
initial changes for Relation types
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Oct 26, 2024
1 parent 6a46f48 commit 609557a
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 147 deletions.
241 changes: 96 additions & 145 deletions asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,192 +29,149 @@ const (
IPNetRecord AssetType = "IPNetRecord"
Location AssetType = "Location"
Netblock AssetType = "Netblock"
NetworkEndpoint AssetType = "NetworkEndpoint"
Organization AssetType = "Organization"
Person AssetType = "Person"
Phone AssetType = "Phone"
Service AssetType = "Service"
SocketAddress AssetType = "SocketAddress"
Source AssetType = "Source"
TLSCertificate AssetType = "TLSCertificate"
URL AssetType = "URL"
)

var AssetList = []AssetType{
AutnumRecord, AutonomousSystem, ContactRecord, DomainRecord, EmailAddress, File,
Fingerprint, FQDN, IPAddress, IPNetRecord, Location, Netblock, NetworkEndpoint,
Organization, Person, Phone, Service, SocketAddress, Source, TLSCertificate, URL,
AutnumRecord, AutonomousSystem, ContactRecord, DomainRecord, EmailAddress, File, Fingerprint, FQDN,
IPAddress, IPNetRecord, Location, Netblock, Organization, Person, Phone, Service, TLSCertificate, URL,
}

var locationRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
}
var locationRels = map[string]map[RelationType]AssetType{}

var phoneRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
}
var phoneRels = map[string]map[RelationType]AssetType{}

var emailRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"domain": {FQDN},
var emailRels = map[string]map[RelationType]AssetType{
"domain": {SimpleRelation: FQDN},
}

var domainRecordRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"name_server": {FQDN},
"whois_server": {FQDN},
"registrar_contact": {ContactRecord},
"registrant_contact": {ContactRecord},
"admin_contact": {ContactRecord},
"technical_contact": {ContactRecord},
"billing_contact": {ContactRecord},
"associated_with": {AutnumRecord, DomainRecord, IPNetRecord},
var domainRecordRels = map[string]map[RelationType]AssetType{
"name_server": {SimpleRelation: FQDN},
"whois_server": {SimpleRelation: FQDN},
"registrar_contact": {SimpleRelation: ContactRecord},
"registrant_contact": {SimpleRelation: ContactRecord},
"admin_contact": {SimpleRelation: ContactRecord},
"technical_contact": {SimpleRelation: ContactRecord},
"billing_contact": {SimpleRelation: ContactRecord},
"associated_with": {
SimpleRelation: AutnumRecord,
SimpleRelation: DomainRecord,

Check failure on line 63 in asset.go

View workflow job for this annotation

GitHub Actions / lint

duplicate key "SimpleRelation" in map literal

Check failure on line 63 in asset.go

View workflow job for this annotation

GitHub Actions / unit

duplicate key "SimpleRelation" in map literal
SimpleRelation: IPNetRecord,

Check failure on line 64 in asset.go

View workflow job for this annotation

GitHub Actions / lint

duplicate key "SimpleRelation" in map literal

Check failure on line 64 in asset.go

View workflow job for this annotation

GitHub Actions / unit

duplicate key "SimpleRelation" in map literal
},
}

var autnumRecordRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"whois_server": {FQDN},
"registrant": {ContactRecord},
"admin_contact": {ContactRecord},
"abuse_contact": {ContactRecord},
"technical_contact": {ContactRecord},
"rdap_url": {URL},
"associated_with": {AutnumRecord, DomainRecord, IPNetRecord},
var autnumRecordRels = map[string]map[RelationType]AssetType{
"whois_server": {SimpleRelation: FQDN},
"registrant": {SimpleRelation: ContactRecord},
"admin_contact": {SimpleRelation: ContactRecord},
"abuse_contact": {SimpleRelation: ContactRecord},
"technical_contact": {SimpleRelation: ContactRecord},
"rdap_url": {SimpleRelation: URL},
"associated_with": {
SimpleRelation: AutnumRecord,
SimpleRelation: DomainRecord,

Check failure on line 77 in asset.go

View workflow job for this annotation

GitHub Actions / lint

duplicate key "SimpleRelation" in map literal

Check failure on line 77 in asset.go

View workflow job for this annotation

GitHub Actions / unit

duplicate key "SimpleRelation" in map literal
SimpleRelation: IPNetRecord,

Check failure on line 78 in asset.go

View workflow job for this annotation

GitHub Actions / lint

duplicate key "SimpleRelation" in map literal

Check failure on line 78 in asset.go

View workflow job for this annotation

GitHub Actions / unit

duplicate key "SimpleRelation" in map literal
},
}

var ipnetRecordRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"whois_server": {FQDN},
"registrant": {ContactRecord},
"admin_contact": {ContactRecord},
"abuse_contact": {ContactRecord},
"technical_contact": {ContactRecord},
"rdap_url": {URL},
"associated_with": {AutnumRecord, DomainRecord, IPNetRecord},
var ipnetRecordRels = map[string]map[RelationType]AssetType{
"whois_server": {SimpleRelation: FQDN},
"registrant": {SimpleRelation: ContactRecord},
"admin_contact": {SimpleRelation: ContactRecord},
"abuse_contact": {SimpleRelation: ContactRecord},
"technical_contact": {SimpleRelation: ContactRecord},
"rdap_url": {SimpleRelation: URL},
"associated_with": {
SimpleRelation: AutnumRecord,
SimpleRelation: DomainRecord,

Check failure on line 91 in asset.go

View workflow job for this annotation

GitHub Actions / lint

duplicate key "SimpleRelation" in map literal

Check failure on line 91 in asset.go

View workflow job for this annotation

GitHub Actions / unit

duplicate key "SimpleRelation" in map literal
SimpleRelation: IPNetRecord,

Check failure on line 92 in asset.go

View workflow job for this annotation

GitHub Actions / lint

duplicate key "SimpleRelation" in map literal

Check failure on line 92 in asset.go

View workflow job for this annotation

GitHub Actions / unit

duplicate key "SimpleRelation" in map literal
},
}

var personRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
}
var personRels = map[string]map[RelationType]AssetType{}

var orgRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
}
var orgRels = map[string]map[RelationType]AssetType{}

var ipRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"port": {SocketAddress},
"ptr_record": {FQDN},
var ipRels = map[string]map[RelationType]AssetType{
"port": {PortRelation: Service},
"ptr_record": {SimpleRelation: FQDN},
}

var netblockRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"contains": {IPAddress},
"registration": {IPNetRecord},
var netblockRels = map[string]map[RelationType]AssetType{
"contains": {SimpleRelation: IPAddress},
"registration": {SimpleRelation: IPNetRecord},
}

var autonomousSystemRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"announces": {Netblock},
"registration": {AutnumRecord},
var autonomousSystemRels = map[string]map[RelationType]AssetType{
"announces": {SimpleRelation: Netblock},
"registration": {SimpleRelation: AutnumRecord},
}

var fileRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"url": {URL},
"contains": {ContactRecord, URL},
var fileRels = map[string]map[RelationType]AssetType{
"url": {SimpleRelation: URL},
"contains": {
SimpleRelation: ContactRecord,
SimpleRelation: URL,

Check failure on line 119 in asset.go

View workflow job for this annotation

GitHub Actions / lint

duplicate key "SimpleRelation" in map literal

Check failure on line 119 in asset.go

View workflow job for this annotation

GitHub Actions / unit

duplicate key "SimpleRelation" in map literal
},
}

var fqdnRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"port": {NetworkEndpoint},
var fqdnRels = map[string]map[RelationType]AssetType{
"port": {PortRelation: Service},
"a_record": {IPAddress},

Check failure on line 125 in asset.go

View workflow job for this annotation

GitHub Actions / lint

missing key in map literal

Check failure on line 125 in asset.go

View workflow job for this annotation

GitHub Actions / unit

missing key in map literal
"aaaa_record": {IPAddress},

Check failure on line 126 in asset.go

View workflow job for this annotation

GitHub Actions / lint

missing key in map literal

Check failure on line 126 in asset.go

View workflow job for this annotation

GitHub Actions / unit

missing key in map literal
"cname_record": {FQDN},

Check failure on line 127 in asset.go

View workflow job for this annotation

GitHub Actions / unit

missing key in map literal
"ns_record": {FQDN},
"ptr_record": {FQDN},
"mx_record": {FQDN},
"srv_record": {FQDN, IPAddress},
"node": {FQDN},
"registration": {DomainRecord},
}

var tlscertRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"common_name": {FQDN},
"subject_contact": {ContactRecord},
"issuer_contact": {ContactRecord},
"san_dns_name": {FQDN},
"san_email_address": {EmailAddress},
"san_ip_address": {IPAddress},
"san_url": {URL},
"issuing_certificate": {TLSCertificate},
"issuing_certificate_url": {URL},
"ocsp_server": {URL},
"associated_with": {AutnumRecord, DomainRecord, IPNetRecord},
}

var socketAddressRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"service": {Service},
"node": {SimpleRelation: FQDN},
"registration": {SimpleRelation: DomainRecord},
}

var networkEndpointRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"service": {Service},
var tlscertRels = map[string]map[RelationType]AssetType{
"common_name": {SimpleRelation: FQDN},
"subject_contact": {SimpleRelation: ContactRecord},
"issuer_contact": {SimpleRelation: ContactRecord},
"san_dns_name": {SimpleRelation: FQDN},
"san_email_address": {SimpleRelation: EmailAddress},
"san_ip_address": {SimpleRelation: IPAddress},
"san_url": {SimpleRelation: URL},
"issuing_certificate": {SimpleRelation: TLSCertificate},
"issuing_certificate_url": {SimpleRelation: URL},
"ocsp_server": {SimpleRelation: URL},
"associated_with": {
SimpleRelation: AutnumRecord,
SimpleRelation: DomainRecord,
SimpleRelation: IPNetRecord,
},
}

var urlRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"domain": {FQDN},
"ip_address": {IPAddress},
"port": {SocketAddress, NetworkEndpoint},
"service": {Service},
"file": {File},
var urlRels = map[string]map[RelationType]AssetType{
"domain": {SimpleRelation: FQDN},
"ip_address": {SimpleRelation: IPAddress},
"port": {PortRelation: Service},
"file": {SimpleRelation: File},
}

var fingerprintRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
}

var contactRecordRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"person": {Person},
"organization": {Organization},
"location": {Location},
"email": {EmailAddress},
"phone": {Phone},
"url": {URL},
}
var fingerprintRels = map[string]map[RelationType]AssetType{}

var sourceRels = map[string][]AssetType{
"contact_record": {ContactRecord},
var contactRecordRels = map[string]map[RelationType]AssetType{
"person": {SimpleRelation: Person},
"organization": {SimpleRelation: Organization},
"location": {SimpleRelation: Location},
"email": {SimpleRelation: EmailAddress},
"phone": {SimpleRelation: Phone},
"url": {SimpleRelation: URL},
}

var serviceRels = map[string][]AssetType{
"source": {Source},
"monitored_by": {Source},
"fingerprint": {Fingerprint},
"certificate": {TLSCertificate},
var serviceRels = map[string]map[RelationType]AssetType{
"fingerprint": {SimpleRelation: Fingerprint},
"certificate": {SimpleRelation: TLSCertificate},
}

// GetAssetOutgoingRelations returns the relation types allowed to be used
Expand Down Expand Up @@ -263,8 +220,6 @@ func assetTypeRelations(atype AssetType) map[string][]AssetType {
relations = fileRels
case FQDN:
relations = fqdnRels
case NetworkEndpoint:
relations = networkEndpointRels
case DomainRecord:
relations = domainRecordRels
case AutnumRecord:
Expand All @@ -283,16 +238,12 @@ func assetTypeRelations(atype AssetType) map[string][]AssetType {
relations = orgRels
case TLSCertificate:
relations = tlscertRels
case SocketAddress:
relations = socketAddressRels
case URL:
relations = urlRels
case Fingerprint:
relations = fingerprintRels
case ContactRecord:
relations = contactRecordRels
case Source:
relations = sourceRels
case Service:
relations = serviceRels
default:
Expand Down
2 changes: 0 additions & 2 deletions asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func TestAssetTypeConstants(t *testing.T) {
EmailAddress,
Person,
Organization,
SocketAddress,
URL,
Fingerprint,
TLSCertificate,
Expand All @@ -56,7 +55,6 @@ func TestAssetTypeConstants(t *testing.T) {
"EmailAddress",
"Person",
"Organization",
"SocketAddress",
"URL",
"Fingerprint",
"TLSCertificate",
Expand Down
22 changes: 22 additions & 0 deletions relation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright © by Jeff Foley 2017-2024. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0

package open_asset_model

type Relation interface {
RelationType() RelationType
JSON() ([]byte, error)
}

type RelationType string

const (
SimpleRelation RelationType = "SimpleRelation"
PortRelation RelationType = "PortRelation"
)

var RelationList = []RelationType{
PortRelation,
SimpleRelation,
}
24 changes: 24 additions & 0 deletions relation/simple.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright © by Jeff Foley 2017-2024. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0

package relation

import (
"encoding/json"

model "github.com/owasp-amass/open-asset-model"
)

// SimpleRelation represents a simple relation in the graph with no additional data required.
type SimpleRelation struct{}

// RelationType implements the Relation interface.
func (r SimpleRelation) RelationType() model.RelationType {
return model.SimpleRelation
}

// JSON implements the Relation interface.
func (r SimpleRelation) JSON() ([]byte, error) {
return json.Marshal(r)
}
Loading

0 comments on commit 609557a

Please sign in to comment.