Skip to content

Commit 448fe6d

Browse files
authored
Revert "Feature/totp default admin (#111)" (#122)
This reverts commit 0470100.
1 parent 0470100 commit 448fe6d

File tree

8 files changed

+2
-173
lines changed

8 files changed

+2
-173
lines changed

cmd/subspace/config.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
"sort"
1818
"sync"
1919
"time"
20-
21-
"github.com/pquerna/otp/totp"
2220
)
2321

2422
var (
@@ -63,7 +61,6 @@ type Info struct {
6361
Email string `json:"email"`
6462
Password []byte `json:"password"`
6563
Secret string `json:"secret"`
66-
TotpKey string `json:"totp_key"`
6764
Configured bool `json:"configure"`
6865
Domain string `json:"domain"`
6966
HashKey string `json:"hash_key"`
@@ -425,32 +422,3 @@ func (c *Config) save() error {
425422
}
426423
return Overwrite(c.filename, b, 0644)
427424
}
428-
429-
func (c *Config) ResetTotp() error {
430-
c.Lock()
431-
defer c.Unlock()
432-
433-
c.Info.TotpKey = ""
434-
435-
if err := c.save(); err != nil {
436-
return err
437-
}
438-
439-
return c.GenerateTOTP()
440-
}
441-
442-
func (c *Config) GenerateTOTP() error {
443-
key, err := totp.Generate(
444-
totp.GenerateOpts{
445-
Issuer: httpHost,
446-
AccountName: config.Info.Email,
447-
},
448-
)
449-
if err != nil {
450-
return err
451-
}
452-
453-
tempTotpKey = key
454-
455-
return nil
456-
}

cmd/subspace/handlers.go

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package main
22

33
import (
4-
"bytes"
54
"fmt"
6-
"image/png"
75
"io/ioutil"
86
"net/http"
97
"os"
108
"regexp"
119
"strings"
1210

1311
"github.com/julienschmidt/httprouter"
14-
"github.com/pquerna/otp/totp"
1512
"golang.org/x/crypto/bcrypt"
1613

1714
qrcode "github.com/skip2/go-qrcode"
@@ -232,7 +229,6 @@ func signinHandler(w *Web) {
232229

233230
email := strings.ToLower(strings.TrimSpace(w.r.FormValue("email")))
234231
password := w.r.FormValue("password")
235-
passcode := w.r.FormValue("totp")
236232

237233
if email != config.FindInfo().Email {
238234
w.Redirect("/signin?error=invalid")
@@ -243,13 +239,6 @@ func signinHandler(w *Web) {
243239
w.Redirect("/signin?error=invalid")
244240
return
245241
}
246-
247-
if config.FindInfo().TotpKey != "" && !totp.Validate(passcode, config.FindInfo().TotpKey) {
248-
// Totp has been configured and the provided code doesn't match
249-
w.Redirect("/signin?error=invalid")
250-
return
251-
}
252-
253242
if err := w.SigninSession(true, ""); err != nil {
254243
Error(w.w, err)
255244
return
@@ -258,36 +247,6 @@ func signinHandler(w *Web) {
258247
w.Redirect("/")
259248
}
260249

261-
func totpQRHandler(w *Web) {
262-
if !w.Admin {
263-
Error(w.w, fmt.Errorf("failed to view config: permission denied"))
264-
return
265-
}
266-
267-
if config.Info.TotpKey != "" {
268-
// TOTP is already configured, don't allow the current one to be leaked
269-
w.Redirect("/")
270-
return
271-
}
272-
273-
var buf bytes.Buffer
274-
img, err := tempTotpKey.Image(200, 200)
275-
if err != nil {
276-
Error(w.w, err)
277-
return
278-
}
279-
280-
png.Encode(&buf, img)
281-
282-
w.w.Header().Set("Content-Type", "image/png")
283-
w.w.Header().Set("Content-Length", fmt.Sprintf("%d", len(buf.Bytes())))
284-
if _, err := w.w.Write(buf.Bytes()); err != nil {
285-
Error(w.w, err)
286-
return
287-
}
288-
289-
}
290-
291250
func userEditHandler(w *Web) {
292251
userID := w.ps.ByName("user")
293252
if userID == "" {
@@ -579,9 +538,6 @@ func settingsHandler(w *Web) {
579538
currentPassword := w.r.FormValue("current_password")
580539
newPassword := w.r.FormValue("new_password")
581540

582-
resetTotp := w.r.FormValue("reset_totp")
583-
totpCode := w.r.FormValue("totp_code")
584-
585541
config.UpdateInfo(func(i *Info) error {
586542
i.SAML.IDPMetadata = samlMetadata
587543
i.Email = email
@@ -621,26 +577,6 @@ func settingsHandler(w *Web) {
621577
})
622578
}
623579

624-
if resetTotp == "true" {
625-
err := config.ResetTotp()
626-
if err != nil {
627-
w.Redirect("/settings?error=totp")
628-
return
629-
}
630-
631-
w.Redirect("/settings?success=totp")
632-
return
633-
}
634-
635-
if config.Info.TotpKey == "" && totpCode != "" {
636-
if !totp.Validate(totpCode, tempTotpKey.Secret()) {
637-
w.Redirect("/settings?error=totp")
638-
return
639-
}
640-
config.Info.TotpKey = tempTotpKey.Secret()
641-
config.save()
642-
}
643-
644580
w.Redirect("/settings?success=settings")
645581
}
646582

cmd/subspace/main.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"time"
1919

2020
"github.com/julienschmidt/httprouter"
21-
"github.com/pquerna/otp"
2221

2322
"github.com/crewjam/saml"
2423
"github.com/crewjam/saml/samlsp"
@@ -80,9 +79,6 @@ var (
8079

8180
// theme
8281
semanticTheme string
83-
84-
// Totp
85-
tempTotpKey *otp.Key
8682
)
8783

8884
func init() {
@@ -148,12 +144,6 @@ func main() {
148144
logger.Fatal(err)
149145
}
150146

151-
// TOTP
152-
err = config.GenerateTOTP()
153-
if err != nil {
154-
logger.Fatal(err)
155-
}
156-
157147
// Secure token
158148
securetoken = securecookie.New([]byte(config.FindInfo().HashKey), []byte(config.FindInfo().BlockKey))
159149

@@ -180,7 +170,6 @@ func main() {
180170
r.GET("/saml/acs", Log(samlHandler))
181171
r.POST("/saml/acs", Log(samlHandler))
182172

183-
r.GET("/totp/image", Log(WebHandler(totpQRHandler, "totp/image")))
184173
r.GET("/signin", Log(WebHandler(signinHandler, "signin")))
185174
r.GET("/signout", Log(WebHandler(signoutHandler, "signout")))
186175
r.POST("/signin", Log(WebHandler(signinHandler, "signin")))

cmd/subspace/web.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/crewjam/saml"
1515
"github.com/crewjam/saml/samlsp"
16-
"github.com/pquerna/otp"
1716

1817
"golang.org/x/net/publicsuffix"
1918

@@ -59,7 +58,6 @@ type Web struct {
5958
TargetProfiles []Profile
6059

6160
SemanticTheme string
62-
TempTotpKey *otp.Key
6361
}
6462

6563
func init() {
@@ -161,7 +159,6 @@ func WebHandler(h func(*Web), section string) httprouter.Handle {
161159
Info: config.FindInfo(),
162160
SAML: samlSP,
163161
SemanticTheme: semanticTheme,
164-
TempTotpKey: tempTotpKey,
165162
}
166163

167164
if section == "signin" || section == "forgot" || section == "configure" {

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
github.com/jteeuwen/go-bindata v3.0.8-0.20180305030458-6025e8de665b+incompatible
1010
github.com/julienschmidt/httprouter v1.3.0
1111
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
12-
github.com/pquerna/otp v1.2.0 // indirect
1312
github.com/sirupsen/logrus v1.6.0
1413
github.com/skip2/go-qrcode v0.0.0-20200519171959-a3b48390827e
1514
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37

go.sum

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
github.com/beevik/etree v1.0.1 h1:lWzdj5v/Pj1X360EV7bUudox5SRipy4qZLjY0rhb0ck=
22
github.com/beevik/etree v1.0.1/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
3-
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
4-
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
53
github.com/crewjam/saml v0.3.0 h1:nsICCm1susKcMzqhZ+XwOvYUG55Omu1dHlyyknhgh1M=
64
github.com/crewjam/saml v0.3.0/go.mod h1:pzACCdpqjQKTvpPZs5P3FzFNQ+RSOJX5StwHwh7ZUgw=
75
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -31,8 +29,6 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb
3129
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
3230
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3331
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
34-
github.com/pquerna/otp v1.2.0 h1:/A3+Jn+cagqayeR3iHs/L62m5ue7710D35zl1zJ1kok=
35-
github.com/pquerna/otp v1.2.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
3632
github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7 h1:J4AOUcOh/t1XbQcJfkEqhzgvMJ2tDxdCVvmHxW5QXao=
3733
github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7/go.mod h1:Oz4y6ImuOQZxynhbSXk7btjEfNBtGlj2dcaOvXl2FSM=
3834
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
@@ -42,7 +38,6 @@ github.com/skip2/go-qrcode v0.0.0-20200519171959-a3b48390827e/go.mod h1:XV66xRDq
4238
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4339
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
4440
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
45-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
4641
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
4742
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
4843
github.com/zenazn/goji v0.9.1-0.20160507202103-64eb34159fe5/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=

web/templates/settings.html

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
Device removed successfully
1414
{{else if eq $success "configured"}}
1515
Admin account is setup. Configure SAML for SSO (optional).
16-
{{else if eq $success "totp"}}
17-
TOTP reset for default user, please reconfigure for improved security.
1816
{{end}}
1917
</div>
2018
<a class="close-link" href="/settings"><i class="close icon"></i></a>
@@ -28,8 +26,6 @@
2826
<div class="header">
2927
{{if eq $error "invalid"}}
3028
Invalid. Please try again.
31-
{{else if eq $error "totp"}}
32-
Error Resetting totp settings.
3329
{{else}}
3430
Error. Please try again.
3531
{{end}}
@@ -78,7 +74,7 @@
7874

7975
<div class="ui hidden section divider"></div>
8076

81-
<div class="ui {{$.SemanticTheme}} dividing header">Admin Account: Reset Password</div>
77+
<div class="ui {{$.SemanticTheme}} dividing header">Admin Account</div>
8278
<div class="ui hidden divider"></div>
8379
<div class="field">
8480
<div class="ui small header">Email Address</div>
@@ -102,47 +98,6 @@
10298
</div>
10399
</div>
104100
</div>
105-
106-
<div class="ui hidden section divider"></div>
107-
{{if and $.Admin $.Info.TotpKey}}
108-
109-
<div class="ui {{$.SemanticTheme}} dividing header">Admin Account: Reset TOTP</div>
110-
<div class="ui hidden divider"></div>
111-
<input type="hidden" name="reset_totp" value="true"/>
112-
<div class="equal width fields">
113-
<div class="field mobile hidden">&nbsp;</div>
114-
<div class="field">
115-
<div class="two ui buttons">
116-
<a href="/" class="ui huge button">Cancel</a>
117-
<button type="submit" class="ui huge red button">Remove Totp</button>
118-
</div>
119-
</div>
120-
</div>
121-
{{else}}
122-
<div class="ui {{$.SemanticTheme}} dividing header">Admin Account: Setup MFA</div>
123-
<div class="ui hidden divider"></div>
124-
<div class="ui text container">Scan the below with your Authenticator App of choice (Google Authenticator, Authy etc...) and then put the code into the input box below</div>
125-
<div class="ui hidden divider"></div>
126-
<div class="ui centered segment">
127-
<div class="ui bottom attached label">Secret: {{$.TempTotpKey.Secret}}</div>
128-
<img class="ui centered image" src="/totp/image" alt="TOTP qr-code could not be displayed">
129-
</div>
130-
<div class="ui hidden divider"></div>
131-
<div class="field">
132-
<div class="ui small header">TOTP Code</div>
133-
<input name="totp_code" type="text" placeholder="totp key" value="">
134-
</div>
135-
<div class="ui hidden divider"></div>
136-
<div class="equal width fields">
137-
<div class="field mobile hidden">&nbsp;</div>
138-
<div class="field">
139-
<div class="two ui buttons">
140-
<a href="/" class="ui huge button">Cancel</a>
141-
<button type="submit" class="ui huge {{$.SemanticTheme}} button">Save</button>
142-
</div>
143-
</div>
144-
</div>
145-
{{end}}
146101
</form>
147102
</div>
148103
</div>

web/templates/signin.html

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,9 @@
4343
<div class="field">
4444
<div class="ui left icon input">
4545
<i class="key icon"></i>
46-
<input name="password" type="password" placeholder="Password" autofocus required>
46+
<input name="password" type="password" placeholder="Password" autofocus>
4747
</div>
4848
</div>
49-
50-
{{ if $.Info.TotpKey}}
51-
<div class="field">
52-
<div class="ui left icon input">
53-
<i class="clock icon"></i>
54-
<input name="totp" type="text" placeholder="One Time Password" autofocus required>
55-
</div>
56-
</div>
57-
{{end}}
58-
5949
<div class="center-aligned field">
6050
<button type="submit" class="ui huge fluid {{$.SemanticTheme}} button">Sign in</button>
6151
<div class="ui hidden divider"></div>

0 commit comments

Comments
 (0)