initial commit
This commit is contained in:
		
							
								
								
									
										9
									
								
								client/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								client/README.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
# hyp-client
 | 
			
		||||
 | 
			
		||||
The client expects there to be a file named hyp.secret in the same directory.  This file is generated by the hypd server using ./hypd generatesecret.  
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
# Example Usage
 | 
			
		||||
# ./hyp-client <server>
 | 
			
		||||
./hyp-client 192.168.50.5
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										5
									
								
								client/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								client/go.mod
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
module deadbeef.codes/steven/hyp-client
 | 
			
		||||
 | 
			
		||||
go 1.22.0
 | 
			
		||||
 | 
			
		||||
require deadbeef.codes/steven/hyp/otphyp v0.0.0-20240407035202-7ccdf4d89fee
 | 
			
		||||
							
								
								
									
										2
									
								
								client/go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								client/go.sum
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
deadbeef.codes/steven/hyp/otphyp v0.0.0-20240407035202-7ccdf4d89fee h1:r9xdoIGPhc/tXzyOj+lCDb+ReYa/zkysqK3ZRCqpyIU=
 | 
			
		||||
deadbeef.codes/steven/hyp/otphyp v0.0.0-20240407035202-7ccdf4d89fee/go.mod h1:NANpGD/K+nDkW+bkomchwaXMrsXWza58+8AR7Sau3fs=
 | 
			
		||||
							
								
								
									
										51
									
								
								client/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								client/main.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net"
 | 
			
		||||
	"os"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"deadbeef.codes/steven/hyp/otphyp"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// MaxNetworkLatency specifies the number of milliseconds
 | 
			
		||||
// A packet-switched network... more like "race condition factory"
 | 
			
		||||
const MaxNetworkLatency = 500
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
 | 
			
		||||
	// validate number of input arguments
 | 
			
		||||
	if len(os.Args) < 2 {
 | 
			
		||||
		usage()
 | 
			
		||||
		os.Exit(1)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// load secret and generate ports using secret and current time
 | 
			
		||||
	secretBytes, err := os.ReadFile("hyp.secret")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatalf("failed to read file 'hyp.secret': %v", err)
 | 
			
		||||
	}
 | 
			
		||||
	sharedSecret := string(secretBytes)
 | 
			
		||||
 | 
			
		||||
	ports, err := otphyp.GeneratePorts(sharedSecret, time.Now())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatalf("failed to generate ports from shared secret: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Transmit
 | 
			
		||||
	fmt.Println("Transmitting knock sequence:", ports)
 | 
			
		||||
	for _, port := range ports {
 | 
			
		||||
		conn, _ := net.Dial("udp", fmt.Sprintf("%s:%d", os.Args[1], port))
 | 
			
		||||
		conn.Write([]byte{0})
 | 
			
		||||
		conn.Close()
 | 
			
		||||
		time.Sleep(time.Millisecond * MaxNetworkLatency)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func usage() {
 | 
			
		||||
	fmt.Println(os.Args[0], "usage")
 | 
			
		||||
	fmt.Println("Supply an ordered list of ports to knock")
 | 
			
		||||
	fmt.Println(os.Args[0], "server")
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user