README ¶
RDAP
RDAP (Registration Data Access Protocol) is a library to be used in clients and servers to make the life easier when building requests and responses. You will find all RDAP protocol types in the protocol package and can use the clients to build your own client tool.
Implements the RFCs:
- 7480 - HTTP Usage in the Registration Data Access Protocol (RDAP)
- 7482 - Registration Data Access Protocol (RDAP) Query Format
- 7483 - JSON Responses for the Registration Data Access Protocol (RDAP)
- 7484 - Finding the Authoritative Registration Data (RDAP) Service
Also support the extensions:
- NIC.br RDAP extension
Usage
Download the project with:
go get github.com/registrobr/rdap
And build a program like bellow for direct RDAP server requests:
package main
import (
"encoding/json"
"fmt"
"url"
"github.com/registrobr/rdap"
)
func main() {
c := rdap.NewClient([]string{"https://rdap.beta.registro.br"})
d, _, err := c.Query("nic.br", nil, nil)
if err != nil {
fmt.Println(err)
return
}
output, err := json.MarshalIndent(d, "", " ")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(output))
// Another example for a direct domain query adding a "ticket" parameter
queryString := make(url.Values)
queryString.Set("ticket", "5439886")
d, _, err = c.Domain("rafael.net.br", nil, queryString)
if err != nil {
fmt.Println(err)
return
}
output, err = json.MarshalIndent(d, "", " ")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(output))
}
You can also try with bootstrap support:
package main
import (
"encoding/json"
"fmt"
"github.com/registrobr/rdap"
)
func main() {
c := rdap.NewClient(nil)
ipnetwork, _, err := c.Query("214.1.2.3", nil, nil)
if err != nil {
fmt.Println(err)
return
}
output, err := json.MarshalIndent(ipnetwork, "", " ")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(output))
}
For advanced users you probably want to reuse the HTTP client and add a cache layer:
package main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/registrobr/rdap"
)
func main() {
var httpClient http.Client
cacheDetector := rdap.CacheDetector(func(resp *http.Response) bool {
return resp.Header.Get("X-From-Cache") == "1"
})
c := rdap.Client{
Transport: rdap.NewBootstrapFetcher(&httpClient, rdap.IANABootstrap, cacheDetector),
}
ipnetwork, _, err := c.Query("214.1.2.3", http.Header{
"X-Forwarded-For": []string{"127.0.0.1"},
}, nil)
if err != nil {
fmt.Println(err)
return
}
output, err := json.MarshalIndent(ipnetwork, "", " ")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(output))
}
An example of usage can be found in the project: https://github.com/registrobr/rdap-client
Documentation ¶
Overview ¶
Package rdap is a RDAP (Registration Data Access Protocol) library to be used in clients and servers to make the life easier when building requests and responses.
Index ¶
- Constants
- Variables
- type CacheDetector
- type Client
- func (c *Client) ASN(asn uint32, header http.Header, queryString url.Values) (*protocol.AS, http.Header, error)
- func (c *Client) Domain(fqdn string, header http.Header, queryString url.Values) (*protocol.Domain, http.Header, error)
- func (c *Client) Entity(identifier string, header http.Header, queryString url.Values) (*protocol.Entity, http.Header, error)
- func (c *Client) IP(ip net.IP, header http.Header, queryString url.Values) (*protocol.IPNetwork, http.Header, error)
- func (c *Client) IPNetwork(ipnet *net.IPNet, header http.Header, queryString url.Values) (*protocol.IPNetwork, http.Header, error)
- func (c *Client) Query(object string, header http.Header, queryString url.Values) (interface{}, http.Header, error)
- func (c *Client) Ticket(ticketNumber int, header http.Header, queryString url.Values) (*protocol.Domain, http.Header, error)
- type Fetcher
- type QueryType
Examples ¶
Constants ¶
const ( // IANABootstrap stores the default URL to query to retrieve the RDAP // servers that contain the desired information IANABootstrap = "https://data.iana.org/rdap/%s.json" )
Variables ¶
var ( // ErrNotFound is used when the RDAP server doesn't contain any // information of the requested object ErrNotFound = errors.New("not found") ErrForbidden = errors.New("forbidden") )
Functions ¶
This section is empty.
Types ¶
type CacheDetector ¶
CacheDetector is used to define how do you detect if a HTTP response is from cache when performing bootstrap. This depends on the proxy that you are using between the client and the bootstrap server
type Client ¶
type Client struct { // Transport is the network layer that you can fill with a direct query to // the RDAP servers or with an extra layer of RDAP bootstrap strategy Transport Fetcher // URIs store the addresses of the RDAP servers that you want to query // directly. Remember that if you use a bootstrap transport layer this // information might not be used URIs []string }
Client is responsible for building, sending the request and parsing the result. It can set the URIs attribute if you want to query RDAP servers directly without using bootstrap
Example ¶
Output:
func NewClient ¶
NewClient is an easy way to create a client with bootstrap support or not, depending if you inform direct RDAP addresses
func (*Client) ASN ¶
func (c *Client) ASN(asn uint32, header http.Header, queryString url.Values) (*protocol.AS, http.Header, error)
ASN will query each RDAP server to retrieve the desired information and will parse and store the response into a protocol AS object. You can optionally define the HTTP headers parameters to send to the RDAP server. If something goes wrong an error will be returned, and if nothing is found the error ErrNotFound will be returned. The HTTP header of the RDAP response is also returned to analyze any specific flag
func (*Client) Domain ¶
func (c *Client) Domain(fqdn string, header http.Header, queryString url.Values) (*protocol.Domain, http.Header, error)
Domain will query each RDAP server to retrieve the desired information and will parse and store the response into a protocol Domain object. You can optionally define the HTTP headers parameters to send to the RDAP server. If something goes wrong an error will be returned, and if nothing is found the error ErrNotFound will be returned. The HTTP header of the RDAP response is also returned to analyze any specific flag
func (*Client) Entity ¶
func (c *Client) Entity(identifier string, header http.Header, queryString url.Values) (*protocol.Entity, http.Header, error)
Entity will query each RDAP server to retrieve the desired information and will parse and store the response into a protocol Entity object. You can optionally define the HTTP headers parameters to send to the RDAP server. If something goes wrong an error will be returned, and if nothing is found the error ErrNotFound will be returned. The HTTP header of the RDAP response is also returned to analyze any specific flag
func (*Client) IP ¶
func (c *Client) IP(ip net.IP, header http.Header, queryString url.Values) (*protocol.IPNetwork, http.Header, error)
IP will query each RDAP server to retrieve the desired information and will parse and store the response into a protocol IP object. You can optionally define the HTTP headers parameters to send to the RDAP server. If something goes wrong an error will be returned, and if nothing is found the error ErrNotFound will be returned. The HTTP header of the RDAP response is also returned to analyze any specific flag
func (*Client) IPNetwork ¶
func (c *Client) IPNetwork(ipnet *net.IPNet, header http.Header, queryString url.Values) (*protocol.IPNetwork, http.Header, error)
IPNetwork will query each RDAP server to retrieve the desired information and will parse and store the response into a protocol IPNetwork object. You can optionally define the HTTP headers parameters to send to the RDAP server. If something goes wrong an error will be returned, and if nothing is found the error ErrNotFound will be returned. The HTTP header of the RDAP response is also returned to analyze any specific flag
func (*Client) Query ¶
func (c *Client) Query(object string, header http.Header, queryString url.Values) (interface{}, http.Header, error)
Query will try to search the object in the following order: ASN, IP, IP network, domain and entity. If the format is not valid for the specific search, the search is ignored. The HTTP header of the RDAP response is also returned to analyze any specific flag
func (*Client) Ticket ¶
func (c *Client) Ticket(ticketNumber int, header http.Header, queryString url.Values) (*protocol.Domain, http.Header, error)
Ticket will query each RDAP server to retrieve the desired information and will parse and store the response into a protocol Domain object. You can optionally define the HTTP headers parameters to send to the RDAP server. If something goes wrong an error will be returned, and if nothing is found the error ErrNotFound will be returned. The HTTP header of the RDAP response is also returned to analyze any specific flag
type Fetcher ¶
type Fetcher interface {
Fetch(uris []string, queryType QueryType, queryValue string, header http.Header, queryString url.Values) (*http.Response, error)
}
Fetcher represents the network layer responsible for retrieving the resource information from a RDAP server
func NewBootstrapFetcher ¶
func NewBootstrapFetcher(httpClient httpClient, bootstrapURI string, cacheDetector CacheDetector) Fetcher
NewBootstrapFetcher returns a transport layer that tries to find the resource in a bootstrap strategy to detect the RDAP servers that can contain the information. After finding the RDAP servers, it will send the requests to retrieve the desired information
func NewDefaultFetcher ¶
func NewDefaultFetcher(httpClient httpClient) Fetcher
NewDefaultFetcher returns a transport layer that send requests directly to the RDAP servers
type QueryType ¶
type QueryType string
QueryType stores the query type when sending a query to an RDAP server
const ( // QueryTypeDomain used to identify reverse DNS (RIR) or domain name (DNR) // information and associated data referenced using a fully qualified domain // name QueryTypeDomain QueryType = "domain" // QueryTypeTicket used to query a domain request. This query type was // created by NIC.br to allow retrieving information about the domain // requests QueryTypeTicket QueryType = "ticket" // QueryTypeAutnum used to identify Autonomous System number registrations // and associated data referenced using an asplain Autonomous System number QueryTypeAutnum QueryType = "autnum" // QueryTypeIP used to identify IP networks and associated data referenced // using either an IPv4 or IPv6 address QueryTypeIP QueryType = "ip" // QueryTypeEntity used to identify an entity information query using a // string identifier QueryTypeEntity QueryType = "entity" )
List of resource type path segments for exact match lookup as described in RFC 7482, section 3.1