From 19ca7b27e9c0c96cde814922187fbfe5e2e5632d Mon Sep 17 00:00:00 2001 From: Ben Cartwright-Cox Date: Tue, 21 Feb 2023 22:05:50 +0000 Subject: [PATCH] Add BGPsec Router Key support to rtrdump Tag: https://github.com/bgp/stayrtr/issues/57 --- cmd/rtrdump/rtrdump.go | 13 +++++++++++++ prefixfile/prefixfile.go | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/rtrdump/rtrdump.go b/cmd/rtrdump/rtrdump.go index 3972df6..4c6c442 100644 --- a/cmd/rtrdump/rtrdump.go +++ b/cmd/rtrdump/rtrdump.go @@ -2,6 +2,7 @@ package main import ( "crypto/tls" + "encoding/hex" "encoding/json" "flag" "fmt" @@ -96,6 +97,18 @@ func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) { c.Data.Data = append(c.Data.Data, rj) c.Data.Metadata.Counts++ + if *LogDataPDU { + log.Debugf("Received: %v", pdu) + } + case *rtr.PDURouterKey: + skiHex := hex.EncodeToString(pdu.SubjectKeyIdentifier) + rj := prefixfile.BgpSecKeyJson{ + Asn: uint32(pdu.ASN), + Pubkey: pdu.SubjectPublicKeyInfo, + Ski: skiHex, + } + c.Data.BgpSecKeys = append(c.Data.BgpSecKeys, rj) + if *LogDataPDU { log.Debugf("Received: %v", pdu) } diff --git a/prefixfile/prefixfile.go b/prefixfile/prefixfile.go index 7c7c1fa..093a417 100644 --- a/prefixfile/prefixfile.go +++ b/prefixfile/prefixfile.go @@ -38,7 +38,7 @@ type VRPList struct { type BgpSecKeyJson struct { Asn uint32 `json:"asn"` Expires *uint32 `json:"expires,omitempty"` - Ta string `json:"ta"` + Ta string `json:"ta,omitempty"` // Base32 encoded, but encoding/json handles this for us // Example: MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE4FxJr0n2bux1uX1Evl+QWwZYvIadPjLuFX2mxqKuAGUhKnr7VLLDgrE++l9p5eH2kWTNVAN22FUU3db/RKpE2w==