Skip to content

Commit

Permalink
Add one-time-key logic (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
h0x0er authored Jun 6, 2024
1 parent fcf4599 commit e1d89e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ func Run(ctx context.Context, configFilePath string, hostDNSServer DNSServer,
return err
}

apiclient := &ApiClient{Client: &http.Client{Timeout: 3 * time.Second}, APIURL: config.APIURL, DisableTelemetry: config.DisableTelemetry, EgressPolicy: config.EgressPolicy}
apiclient := &ApiClient{Client: &http.Client{Timeout: 3 * time.Second}, APIURL: config.APIURL, DisableTelemetry: config.DisableTelemetry, EgressPolicy: config.EgressPolicy, OneTimeKey: config.OneTimeKey}

config.OneTimeKey = ""
// TODO: pass in an iowriter/ use log library
WriteLog(fmt.Sprintf("read config \n %+v", config))
WriteLog("\n")
Expand Down
2 changes: 2 additions & 0 deletions apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type ApiClient struct {
APIURL string
DisableTelemetry bool
EgressPolicy string
OneTimeKey string
}

const agentApiBaseUrl = "https://apiurl/v1"
Expand Down Expand Up @@ -113,6 +114,7 @@ func (apiclient *ApiClient) sendApiRequest(method, url string, body interface{})
return err
}

req.Header.Add("x-one-time-key", apiclient.OneTimeKey)
if body != nil {
req.Header.Add("Content-Type", "application/json; charset=UTF-8")
}
Expand Down
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type config struct {
RunId string
WorkingDirectory string
APIURL string
OneTimeKey string
Endpoints map[string][]Endpoint
EgressPolicy string
DisableTelemetry bool
Expand All @@ -35,6 +36,7 @@ type configFile struct {
RunId string `json:"run_id"`
WorkingDirectory string `json:"working_directory"`
APIURL string `json:"api_url"`
OneTimeKey string `json:"one_time_key"`
AllowedEndpoints string `json:"allowed_endpoints"`
EgressPolicy string `json:"egress_policy"`
DisableTelemetry bool `json:"disable_telemetry"`
Expand Down Expand Up @@ -67,6 +69,7 @@ func (c *config) init(configFilePath string) error {
c.DisableSudo = configFile.DisableSudo
c.DisableFileMonitoring = configFile.DisableFileMonitoring
c.Private = configFile.Private
c.OneTimeKey = configFile.OneTimeKey
return nil
}

Expand Down

0 comments on commit e1d89e8

Please sign in to comment.