Skip to content

Commit 05fd9d3

Browse files
committed
Security protocols
1 parent 7612b5e commit 05fd9d3

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

models/login_source.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ var LoginNames = map[LoginType]string{
4444
}
4545

4646
var SecurityProtocolNames = map[ldap.SecurityProtocol]string{
47-
ldap.SECURITY_PROTOCOL_UNENCRYPTED: "Unencrypted",
48-
ldap.SECURITY_PROTOCOL_LDAPS: "LDAPS",
49-
ldap.SECURITY_PROTOCOL_START_TLS: "StartTLS",
47+
ldap.SecurityProtocolUnencrypted: "Unencrypted",
48+
ldap.SecurityProtocolLdaps: "LDAPS",
49+
ldap.SecurityProtocolStartTls: "StartTLS",
5050
}
5151

5252
// Ensure structs implemented interface.
@@ -182,14 +182,14 @@ func (source *LoginSource) IsPAM() bool {
182182

183183
func (source *LoginSource) HasTLS() bool {
184184
return ((source.IsLDAP() || source.IsDLDAP()) &&
185-
source.LDAP().SecurityProtocol > ldap.SECURITY_PROTOCOL_UNENCRYPTED) ||
185+
source.LDAP().SecurityProtocol > ldap.SecurityProtocolUnencrypted) ||
186186
source.IsSMTP()
187187
}
188188

189189
func (source *LoginSource) UseTLS() bool {
190190
switch source.Type {
191191
case LoginLdap, LoginDldap:
192-
return source.LDAP().SecurityProtocol != ldap.SECURITY_PROTOCOL_UNENCRYPTED
192+
return source.LDAP().SecurityProtocol != ldap.SecurityProtocolUnencrypted
193193
case LoginSmtp:
194194
return source.SMTP().TLS
195195
}

modules/auth/ldap/ldap.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ type SecurityProtocol int
2020

2121
// Note: new type must be added at the end of list to maintain compatibility.
2222
const (
23-
SECURITY_PROTOCOL_UNENCRYPTED SecurityProtocol = iota
24-
SECURITY_PROTOCOL_LDAPS
25-
SECURITY_PROTOCOL_START_TLS
23+
SecurityProtocolUnencrypted SecurityProtocol = iota
24+
SecurityProtocolLdaps
25+
SecurityProtocolStartTls
2626
)
2727

2828
// Basic LDAP authentication service
@@ -118,7 +118,7 @@ func dial(ls *Source) (*ldap.Conn, error) {
118118
ServerName: ls.Host,
119119
InsecureSkipVerify: ls.SkipVerify,
120120
}
121-
if ls.SecurityProtocol == SECURITY_PROTOCOL_LDAPS {
121+
if ls.SecurityProtocol == SecurityProtocolLdaps {
122122
return ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ls.Host, ls.Port), tlsCfg)
123123
}
124124

@@ -127,7 +127,7 @@ func dial(ls *Source) (*ldap.Conn, error) {
127127
return nil, fmt.Errorf("Dial: %v", err)
128128
}
129129

130-
if ls.SecurityProtocol == SECURITY_PROTOCOL_START_TLS {
130+
if ls.SecurityProtocol == SecurityProtocolStartTls {
131131
if err = conn.StartTLS(tlsCfg); err != nil {
132132
conn.Close()
133133
return nil, fmt.Errorf("StartTLS: %v", err)

routers/admin/auths.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ var (
5454
{models.LoginNames[models.LoginPam], models.LoginPam},
5555
}
5656
securityProtocols = []dropdownItem{
57-
{models.SecurityProtocolNames[ldap.SECURITY_PROTOCOL_UNENCRYPTED], ldap.SECURITY_PROTOCOL_UNENCRYPTED},
58-
{models.SecurityProtocolNames[ldap.SECURITY_PROTOCOL_LDAPS], ldap.SECURITY_PROTOCOL_LDAPS},
59-
{models.SecurityProtocolNames[ldap.SECURITY_PROTOCOL_START_TLS], ldap.SECURITY_PROTOCOL_START_TLS},
57+
{models.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted], ldap.SecurityProtocolUnencrypted},
58+
{models.SecurityProtocolNames[ldap.SecurityProtocolLdaps], ldap.SecurityProtocolLdaps},
59+
{models.SecurityProtocolNames[ldap.SecurityProtocolStartTls], ldap.SecurityProtocolStartTls},
6060
}
6161
)
6262

@@ -67,7 +67,7 @@ func NewAuthSource(ctx *context.Context) {
6767

6868
ctx.Data["type"] = models.LoginLdap
6969
ctx.Data["CurrentTypeName"] = models.LoginNames[models.LoginLdap]
70-
ctx.Data["CurrentSecurityProtocol"] = models.SecurityProtocolNames[ldap.SECURITY_PROTOCOL_UNENCRYPTED]
70+
ctx.Data["CurrentSecurityProtocol"] = models.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted]
7171
ctx.Data["smtp_auth"] = "PLAIN"
7272
ctx.Data["is_active"] = true
7373
ctx.Data["AuthSources"] = authSources
@@ -127,7 +127,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
127127
switch models.LoginType(form.Type) {
128128
case models.LoginLdap, models.LoginDldap:
129129
config = parseLDAPConfig(form)
130-
hasTLS = ldap.SecurityProtocol(form.SecurityProtocol) > ldap.SECURITY_PROTOCOL_UNENCRYPTED
130+
hasTLS = ldap.SecurityProtocol(form.SecurityProtocol) > ldap.SecurityProtocolUnencrypted
131131
case models.LoginSmtp:
132132
config = parseSMTPConfig(form)
133133
hasTLS = true

0 commit comments

Comments
 (0)