Compare commits

...

2 Commits

Author SHA1 Message Date
3ae568639e add flag to specify alternative filepath to secret
For the hyp client to be able to support multiple servers, each with their own secret, this capability is requried.
2024-04-11 15:31:08 -06:00
ead7578544 change pcap snaplen to 126 bytes
We really only care getting as far as the UDP header and can discard the rest.  This should reduce load, and perhaps enable full pcap with ports on the BPF filter

UDP header = 8 bytes
IPv4 max size = 60 bytes
IPv6 fixed size = 40 bytes
Ethernet header size = 18 bytes
2024-04-11 15:21:48 -06:00
2 changed files with 11 additions and 3 deletions

View File

@ -31,8 +31,14 @@ Example usage:
`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// load secret and generate ports using secret and current time
secretBytes, err := os.ReadFile("hyp.secret")
secretFilePath, err := cmd.Flags().GetString("secret")
if err != nil {
panic(fmt.Errorf("failed to parse command flag 'secret': %w", err))
}
secretBytes, err := os.ReadFile(secretFilePath)
if err != nil {
log.Fatalf("failed to read file 'hyp.secret': %v", err)
}
@ -56,4 +62,6 @@ Example usage:
func init() {
rootCmd.AddCommand(knockCmd)
knockCmd.PersistentFlags().String("secret", "hyp.secret", "Path to the file containing the hyp secret.")
}

View File

@ -36,7 +36,7 @@ var (
sharedSecret string // base32 encoded shared secret used for totp
)
// packetServer is the main function when operating in server mode
// PacketServer is the main function when operating in server mode
// it sets up the pcap on the capture device and starts a goroutine
// to rotate the knock sequence
func PacketServer(captureDevice string) error {
@ -50,7 +50,7 @@ func PacketServer(captureDevice string) error {
knockSequences = []KnockSequence{}
// Open pcap handle on device
handle, err := pcap.OpenLive(captureDevice, 1600, true, pcap.BlockForever)
handle, err := pcap.OpenLive(captureDevice, 126, true, pcap.BlockForever)
if err != nil {
return fmt.Errorf("failed to open pcap on capture device: %w", err)
}