Skip to content

Commit e4950aa

Browse files
author
Philipp Heckel
committed
Return DefaultID from server during join call
1 parent 8e10f07 commit e4950aa

File tree

7 files changed

+14
-18
lines changed

7 files changed

+14
-18
lines changed

client/client.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ func (c *Client) FileInfo(id string) (*server.File, error) {
225225
// fall back to skipping certificate verification. In the latter case, it will download and return
226226
// the server certificate so the client can pin them.
227227
func (c *Client) ServerInfo() (*server.Info, error) {
228-
var cert *x509.Certificate
229228
var err error
230229

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

246245
// Retrieve bad cert(s) for cert pinning
247-
cert, err = c.retrieveCert()
246+
info.Cert, err = c.retrieveCert()
248247
if err != nil {
249248
return nil, err
250249
}
251250
}
252251

253-
return &server.Info{
254-
ServerAddr: info.ServerAddr,
255-
Salt: info.Salt,
256-
Cert: cert,
257-
}, nil
252+
return info, nil
258253
}
259254

260255
// Verify verifies that the given key (derived from the user password) is in fact correct

cmd/join.go

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func execJoin(c *cli.Context) error {
102102
// Write config file
103103
conf := config.New()
104104
conf.ServerAddr = config.CollapseServerAddr(info.ServerAddr)
105+
conf.DefaultID = info.DefaultID
105106
conf.Key = key // May be nil, but that's ok
106107
if err := conf.WriteFile(configFile); err != nil {
107108
return err

config/config.conf

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
#
2626
# ListenAddr :2586
2727

28-
# Default ID used when using the CLI without an ID. If this is left empty, a random ID
29-
# will be chosen by the server.
30-
#
31-
# This is a client-only option (pcp/ppaste). It has no effect for the server.
28+
# Default ID used when using the CLI without an ID. If this is left empty, a random ID will be chosen by
29+
# the server. When this option is set in the server-side config, new clients will receive the default ID
30+
# upon joining the clipboard.
3231
#
3332
# Format: string consisting only of 0-9a-z.-_, but has to start with 0-9a-z
3433
# Default: default

config/config.conf.tmpl

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
#
2727
{{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}}
2828

29-
# Default ID used when using the CLI without an ID. If this is left empty, a random ID
30-
# will be chosen by the server.
31-
#
32-
# This is a client-only option (pcp/ppaste). It has no effect for the server.
29+
# Default ID used when using the CLI without an ID. If this is left empty, a random ID will be chosen by
30+
# the server. When this option is set in the server-side config, new clients will receive the default ID
31+
# upon joining the clipboard.
3332
#
3433
# Format: string consisting only of 0-9a-z.-_, but has to start with 0-9a-z
3534
# Default: default

server/server.go

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ type visitor struct {
168168
// Info contains information about the server needed o join a server.
169169
type Info struct {
170170
ServerAddr string `json:"serverAddr"`
171+
DefaultID string `json:"defaultID"`
171172
Salt []byte `json:"salt"`
172173
Cert *x509.Certificate `json:"-"`
173174
}
@@ -293,6 +294,7 @@ func (s *Server) handleInfo(w http.ResponseWriter, r *http.Request) error {
293294

294295
response := &Info{
295296
ServerAddr: s.config.ServerAddr,
297+
DefaultID: s.config.DefaultID,
296298
Salt: salt,
297299
}
298300

server/server_router_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ func TestServerRouter_StartStopWithVhostOnSamePorts(t *testing.T) {
6262
conf2.ListenHTTPS = ":11443"
6363
conf2.ListenHTTP = ":11080"
6464
serverRouter := startTestServerRouter(t, conf1, conf2)
65-
defer serverRouter.Stop()
6665

6766
test.WaitForPortUp(t, "11443")
6867
test.WaitForPortUp(t, "11080")

server/server_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ func TestServer_NewServerInvalidCertFile(t *testing.T) {
6262

6363
func TestServer_HandleInfoUnprotected(t *testing.T) {
6464
_, conf := configtest.NewTestConfig(t)
65+
conf.DefaultID = ""
6566
server := newTestServer(t, conf)
6667

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

71-
test.Response(t, rr, http.StatusOK, `{"serverAddr":"https://localhost:12345","salt":null}`)
72+
test.Response(t, rr, http.StatusOK, `{"serverAddr":"https://localhost:12345","defaultID":"","salt":null}`)
7273
}
7374

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

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

9697
func TestServer_HandleDoesNotExist(t *testing.T) {

0 commit comments

Comments
 (0)