-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a working txt record fetcher that produces the instructions needed.
- Loading branch information
Showing
9 changed files
with
1,078 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,5 @@ | |
go.work | ||
|
||
xmidt-agent | ||
|
||
internal/jwtxt/cmd/example/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-FileCopyrightText: 2023 Comcast Cable Communications Management, LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/xmidt-org/xmidt-agent/internal/jwtxt" | ||
"github.com/xmidt-org/xmidt-agent/internal/jwtxt/event" | ||
) | ||
|
||
func main() { | ||
url := os.Args[1] | ||
id := os.Args[2] | ||
pemFile := os.Args[3] | ||
|
||
pem, err := os.ReadFile(pemFile) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
instructions, err := jwtxt.New( | ||
jwtxt.BaseURL(url), | ||
jwtxt.DeviceID(id), | ||
jwtxt.Algorithms("EdDSA", | ||
"ES256", "ES384", "ES512", | ||
"PS256", "PS384", "PS512", | ||
"RS256", "RS384", "RS512"), | ||
jwtxt.WithPEMs(pem), | ||
jwtxt.Timeout(5*time.Second), | ||
jwtxt.WithFetchListener(event.FetchListenerFunc(func(fe event.Fetch) { | ||
fmt.Printf(" FQDN: %s\n", fe.FQDN) | ||
fmt.Printf(" Server: %s\n", fe.Server) | ||
fmt.Printf(" Found: %t\n", fe.Found) | ||
fmt.Printf(" Timeout: %t\n", fe.Timeout) | ||
fmt.Printf("PriorExpiration: %s\n", fe.PriorExpiration) | ||
fmt.Printf(" Expiration: %s\n", fe.Expiration) | ||
fmt.Printf(" TemporaryErr: %t\n", fe.TemporaryErr) | ||
fmt.Printf(" Endpoint: %s\n", fe.Endpoint) | ||
fmt.Printf(" Payload: %s\n", fe.Payload) | ||
if fe.Err != nil { | ||
fmt.Printf(" Err: %s\n", fe.Err) | ||
} else { | ||
fmt.Printf(" Err: nil\n") | ||
} | ||
})), | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
endpoint, err := instructions.Endpoint(context.Background()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("\n\nEndpoint: '%s'\n", endpoint) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-FileCopyrightText: 2023 Comcast Cable Communications Management, LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package event | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// Fetch is an event that is emitted when a TXT record fetch is attempted. | ||
type Fetch struct { | ||
// FQDN is the fully qualified domain name of the TXT record. | ||
FQDN string | ||
|
||
// Server is the DNS server that was queried. | ||
Server string | ||
|
||
// Found indicates whether the TXT record was found. | ||
Found bool | ||
|
||
// Timeout indicates whether the query timed out. | ||
Timeout bool | ||
|
||
// PriorExpiration is the expiration time of the previous TXT record. | ||
PriorExpiration time.Time | ||
|
||
// Expiration is the expiration time of the TXT record. | ||
Expiration time.Time | ||
|
||
// TemporaryErr indicates whether a temporary error occurred during the query. | ||
TemporaryErr bool | ||
|
||
// The endpoint that was found in the TXT record. | ||
Endpoint string | ||
|
||
// Payload is the payload of the TXT record. | ||
Payload []byte | ||
|
||
// Err indicates whether an error occurred during the query. | ||
Err error | ||
} | ||
|
||
// FetchListener is a sink for registration events. | ||
type FetchListener interface { | ||
OnFetchEvent(Fetch) | ||
} | ||
|
||
// FetchListenerFunc is a function type that implements FetchListener. | ||
type FetchListenerFunc func(Fetch) | ||
|
||
func (f FetchListenerFunc) OnFetchEvent(fe Fetch) { | ||
f(fe) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-FileCopyrightText: 2023 Comcast Cable Communications Management, LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package jwtxt | ||
|
||
const ( | ||
pemECPublic = "" + //nolint:golint,unused | ||
"-----BEGIN PUBLIC KEY-----\n" + | ||
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE2JebmtU5WHi5yHBHmzhyiEGbg6OL\n" + | ||
"r463xYdqs/Nzlh2OkaIikanpi7opOuD6wiqFVd9xaMjA54L5vjb5oLcLuA==\n" + | ||
"-----END PUBLIC KEY-----" | ||
|
||
pemECPrivate = "" + //nolint:golint,unused | ||
"-----BEGIN EC PRIVATE KEY-----\n" + | ||
"MHcCAQEEIHJCsQFvPLEV45BXU3DLWEVUPiKSYte8knw7ZtrIj6YxoAoGCCqGSM49\n" + | ||
"AwEHoUQDQgAE2JebmtU5WHi5yHBHmzhyiEGbg6OLr463xYdqs/Nzlh2OkaIikanp\n" + | ||
"i7opOuD6wiqFVd9xaMjA54L5vjb5oLcLuA==\n" + | ||
"-----END EC PRIVATE KEY-----" | ||
|
||
pemEdPublic = "" + //nolint:golint,unused | ||
"-----BEGIN PUBLIC KEY-----\n" + | ||
"MCowBQYDK2VwAyEA0WQIwE/DiCikp79XIkJ0H1vDiERaOieGL/1N8B+k7s8=\n" + | ||
"-----END PUBLIC KEY-----\n" | ||
|
||
pemEdPrivate = "" + //nolint:golint,unused | ||
"-----BEGIN PRIVATE KEY-----\n" + | ||
"MC4CAQAwBQYDK2VwBCIEIHdPSdNde11yNaBYj+q/4044LbOo2lVAb73u7aL13UcH\n" + | ||
"-----END PRIVATE KEY-----" | ||
|
||
pemRSAPublic = "" + //nolint:golint,unused | ||
"-----BEGIN PUBLIC KEY-----\n" + | ||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx3HGBMr6UCtsABqMkG9s\n" + | ||
"w0DLRuRZK9M4b535T4vC3i37+3YCLHB9wvOhEOo6b7h6lJehX9Px7pL3ppWu+tr9\n" + | ||
"LuCxW+Nz46gpgKAXvVbbuc7VU2O0XUBuus0WsOgUQUzqHN6ZNpA/eY3mMndEKR79\n" + | ||
"DWdJMSNylBPGvS54WEtgIE8hDor/pPx/cTleXGXq3DasfqnoOlD/ALKL0eqkzbnX\n" + | ||
"GGUzN2K79RCw7mm/CQeS5a7mLgRypT83fR3Kg1SgsyXCUjTNPupQVgWggxfWbRIj\n" + | ||
"T5Q1LkBRl3SDKM6OaPb3xh5NncuQktbjSFO5NLlGdL6Ylzfm0OlK3nBvrpfmac46\n" + | ||
"7QIDAQAB\n" + | ||
"-----END PUBLIC KEY-----\n" | ||
|
||
pemRSAPrivate = "" + //nolint:golint,unused | ||
"-----BEGIN RSA PRIVATE KEY-----\n" + | ||
"MIIEowIBAAKCAQEAx3HGBMr6UCtsABqMkG9sw0DLRuRZK9M4b535T4vC3i37+3YC\n" + | ||
"LHB9wvOhEOo6b7h6lJehX9Px7pL3ppWu+tr9LuCxW+Nz46gpgKAXvVbbuc7VU2O0\n" + | ||
"XUBuus0WsOgUQUzqHN6ZNpA/eY3mMndEKR79DWdJMSNylBPGvS54WEt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AZgYPmqB2htem1dLNu7M4xjz+t0BDzPeOhAoq71j2Ov\n" + | ||
"4xiAGmkwVrluWeqFPnteCVtfRm1oeWeMoTzFI+Ltc371Zrna1RZKp9aLOPp8wcMk\n" + | ||
"BoP80HCvtwkhq/wsACeXqJECgYAdSJ7gLqjFGZeNjHXEJf5XrqgFtrIYjo9HQSzO\n" + | ||
"3W5xlpyIp6am13FndCdj4HLmOn9kEPRbxNzyYQJORtjpRN6lye0kWswxwbDG3Flt\n" + | ||
"0ADCvGaT+2kscfEWXWPAwdee2KxgrhyBVLAMohbIxdU0RB+W5VrF4btXuXUudj2l\n" + | ||
"LJBIVQKBgCHdEUCWOacO5+B/yZijAbRTnKHH4Ht3B3bYJy6M5qIysSVzG4/Pls90\n" + | ||
"bAQvlAyBG5I+yY1zBfeziI6Uopg/XCrxNNv+8sxiPXt1D8QkCPN08wKulj7DnCuf\n" + | ||
"re3wR8zUZNUhRARSWJa68r7sDJVxxDxZjeh3OywmEBPYpQTBM5sa\n" + | ||
"-----END RSA PRIVATE KEY-----\n" | ||
) | ||
|
||
func publicECOption() Option { | ||
return WithPEMs([]byte(pemECPublic)) | ||
} | ||
|
||
func anyPublicOption() Option { | ||
return WithPEMs([]byte(pemECPublic), []byte(pemEdPublic), []byte(pemRSAPublic)) | ||
} |
Oops, something went wrong.