Skip to content

Commit

Permalink
Return DefaultID from server during join call
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Heckel committed Jun 27, 2021
1 parent 8e10f07 commit e4950aa
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 18 deletions.
9 changes: 2 additions & 7 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ func (c *Client) FileInfo(id string) (*server.File, error) {
// fall back to skipping certificate verification. In the latter case, it will download and return
// the server certificate so the client can pin them.
func (c *Client) ServerInfo() (*server.Info, error) {
var cert *x509.Certificate
var err error

// First attempt to retrieve info with secure HTTP client
Expand All @@ -244,17 +243,13 @@ func (c *Client) ServerInfo() (*server.Info, error) {
}

// Retrieve bad cert(s) for cert pinning
cert, err = c.retrieveCert()
info.Cert, err = c.retrieveCert()
if err != nil {
return nil, err
}
}

return &server.Info{
ServerAddr: info.ServerAddr,
Salt: info.Salt,
Cert: cert,
}, nil
return info, nil
}

// Verify verifies that the given key (derived from the user password) is in fact correct
Expand Down
1 change: 1 addition & 0 deletions cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func execJoin(c *cli.Context) error {
// Write config file
conf := config.New()
conf.ServerAddr = config.CollapseServerAddr(info.ServerAddr)
conf.DefaultID = info.DefaultID
conf.Key = key // May be nil, but that's ok
if err := conf.WriteFile(configFile); err != nil {
return err
Expand Down
7 changes: 3 additions & 4 deletions config/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
#
# ListenAddr :2586

# Default ID used when using the CLI without an ID. If this is left empty, a random ID
# will be chosen by the server.
#
# This is a client-only option (pcp/ppaste). It has no effect for the server.
# Default ID used when using the CLI without an ID. If this is left empty, a random ID will be chosen by
# the server. When this option is set in the server-side config, new clients will receive the default ID
# upon joining the clipboard.
#
# Format: string consisting only of 0-9a-z.-_, but has to start with 0-9a-z
# Default: default
Expand Down
7 changes: 3 additions & 4 deletions config/config.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
#
{{if and (eq ":2586" .ListenHTTPS) (eq "" .ListenHTTP)}}# ListenAddr :2586/https{{else if and .ListenHTTPS .ListenHTTP}}ListenAddr {{.ListenHTTPS}}/https {{.ListenHTTP}}/http{{else if .ListenHTTPS}}ListenAddr {{.ListenHTTPS}}/https{{else if .ListenHTTP}}ListenAddr {{.ListenHTTP}}/http{{else}}# ListenAddr :2586/https{{end}}

# Default ID used when using the CLI without an ID. If this is left empty, a random ID
# will be chosen by the server.
#
# This is a client-only option (pcp/ppaste). It has no effect for the server.
# Default ID used when using the CLI without an ID. If this is left empty, a random ID will be chosen by
# the server. When this option is set in the server-side config, new clients will receive the default ID
# upon joining the clipboard.
#
# Format: string consisting only of 0-9a-z.-_, but has to start with 0-9a-z
# Default: default
Expand Down
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ type visitor struct {
// Info contains information about the server needed o join a server.
type Info struct {
ServerAddr string `json:"serverAddr"`
DefaultID string `json:"defaultID"`
Salt []byte `json:"salt"`
Cert *x509.Certificate `json:"-"`
}
Expand Down Expand Up @@ -293,6 +294,7 @@ func (s *Server) handleInfo(w http.ResponseWriter, r *http.Request) error {

response := &Info{
ServerAddr: s.config.ServerAddr,
DefaultID: s.config.DefaultID,
Salt: salt,
}

Expand Down
1 change: 0 additions & 1 deletion server/server_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func TestServerRouter_StartStopWithVhostOnSamePorts(t *testing.T) {
conf2.ListenHTTPS = ":11443"
conf2.ListenHTTP = ":11080"
serverRouter := startTestServerRouter(t, conf1, conf2)
defer serverRouter.Stop()

test.WaitForPortUp(t, "11443")
test.WaitForPortUp(t, "11080")
Expand Down
5 changes: 3 additions & 2 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ func TestServer_NewServerInvalidCertFile(t *testing.T) {

func TestServer_HandleInfoUnprotected(t *testing.T) {
_, conf := configtest.NewTestConfig(t)
conf.DefaultID = ""
server := newTestServer(t, conf)

rr := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/info", nil)
server.Handle(rr, req)

test.Response(t, rr, http.StatusOK, `{"serverAddr":"https://localhost:12345","salt":null}`)
test.Response(t, rr, http.StatusOK, `{"serverAddr":"https://localhost:12345","defaultID":"","salt":null}`)
}

func TestServer_HandleVerify(t *testing.T) {
Expand All @@ -90,7 +91,7 @@ func TestServer_HandleInfoProtected(t *testing.T) {
req, _ := http.NewRequest("GET", "/info", nil)
server.Handle(rr, req)

test.Response(t, rr, http.StatusOK, `{"serverAddr":"https://localhost:12345","salt":"c29tZSBzYWx0"}`)
test.Response(t, rr, http.StatusOK, `{"serverAddr":"https://localhost:12345","defaultID":"default","salt":"c29tZSBzYWx0"}`)
}

func TestServer_HandleDoesNotExist(t *testing.T) {
Expand Down

0 comments on commit e4950aa

Please sign in to comment.