Skip to content

Commit cd52919

Browse files
Small fixes
1 parent 7611d17 commit cd52919

8 files changed

Lines changed: 24 additions & 19 deletions

File tree

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ linters:
2828
- goheader
2929
- gosec
3030
- gomodguard
31-
- goprintffuncname
3231
- gosmopolitan
3332
- govet
3433
- grouper

credentials.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Credential struct {
4343
// PasswordIsEmptyString is true when an empty Password field should not be
4444
// interpreted as a missing password but as a password that happens to be
4545
// empty.
46-
PasswordIsEmtpyString bool
46+
PasswordIsEmptyString bool
4747
// CCacheIsFromEnv indicates whether the CCache was set explicitly or
4848
// implicitly through an environment variable.
4949
CCacheIsFromEnv bool
@@ -83,7 +83,7 @@ func CredentialFromPFXBytes(
8383

8484
rsaKey, ok := key.(*rsa.PrivateKey)
8585
if !ok {
86-
return nil, fmt.Errorf("PFX key is not an RSA private key but %T", rsaKey)
86+
return nil, fmt.Errorf("PFX key is not an RSA private key but %T", key)
8787
}
8888

8989
cred.ClientCert = cert

dcerpcauth/dcerpcauth.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,14 @@ func DCERPCCredentials(ctx context.Context, creds *adauth.Credential, options *O
163163
options.debug("Authenticating with NT hash")
164164

165165
return credential.NewFromNTHash(creds.LogonNameWithUpperCaseDomain(), creds.NTHash), nil
166-
case creds.PasswordIsEmtpyString:
166+
case creds.PasswordIsEmptyString:
167167
options.debug("Authenticating with empty password")
168168

169-
return credential.NewFromPassword(strings.ToUpper(creds.Domain)+`\`+creds.Username, ""), nil
169+
return credential.NewFromPassword(
170+
strings.ToUpper(creds.Domain)+`\`+creds.Username,
171+
"",
172+
credential.AllowEmptyPassword(),
173+
), nil
170174
case creds.ClientCert != nil:
171175
options.debug("Authenticating with client certificate (PKINIT)")
172176

ldapauth/gssapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (client *gssapiClient) InitSecContextWithOptions(
254254
}
255255

256256
if token.IsKRBError() {
257-
return nil, !false, token.KRBError
257+
return nil, true, token.KRBError
258258
}
259259

260260
return make([]byte, 0), !completed, nil

ldapauth/ldap.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ func connect(ctx context.Context, target *adauth.Target, opts *Options) (conn *l
162162

163163
err = tlsConn.HandshakeContext(ctx)
164164
if err != nil {
165+
_ = tcpConn.Close()
166+
165167
return nil, err
166168
}
167169

@@ -217,9 +219,9 @@ func bind(
217219
switch {
218220
case opts.SimpleBind:
219221
switch {
220-
case creds.Password == "" && !creds.PasswordIsEmtpyString:
222+
case creds.Password == "" && !creds.PasswordIsEmptyString:
221223
return fmt.Errorf("specify a password for simple bind or -p '' for an unauthenticated simple bind")
222-
case creds.Password == "" && creds.PasswordIsEmtpyString:
224+
case creds.Password == "" && creds.PasswordIsEmptyString:
223225
opts.Debug("using unauthenticated simple bind")
224226
default:
225227
opts.Debug("authenticating with simple bind")
@@ -228,15 +230,15 @@ func bind(
228230
_, err = conn.SimpleBind(&ldap.SimpleBindRequest{
229231
Username: creds.UPN(),
230232
Password: creds.Password,
231-
AllowEmptyPassword: creds.PasswordIsEmtpyString,
233+
AllowEmptyPassword: creds.PasswordIsEmptyString,
232234
})
233235
if err != nil {
234236
return fmt.Errorf("simple bind: %w", err)
235237
}
236238
case !target.UseKerberos && creds.ClientCert == nil:
237239
opts.Debug("authenticating using NTLM bind")
238240

239-
if !creds.PasswordIsEmtpyString && (creds.Password == "" && creds.NTHash == "") {
241+
if !creds.PasswordIsEmptyString && (creds.Password == "" && creds.NTHash == "") {
240242
return fmt.Errorf("no credentials available for NTLM")
241243
}
242244

@@ -245,7 +247,7 @@ func bind(
245247
Username: creds.Username,
246248
Password: creds.Password,
247249
Hash: creds.NTHash,
248-
AllowEmptyPassword: creds.PasswordIsEmtpyString,
250+
AllowEmptyPassword: creds.PasswordIsEmptyString,
249251
}
250252

251253
tlsState, ok := conn.TLSConnectionState()
@@ -347,7 +349,7 @@ func kerberosClient(
347349
}
348350

349351
switch {
350-
case creds.Password != "" || creds.PasswordIsEmtpyString:
352+
case creds.Password != "" || creds.PasswordIsEmptyString:
351353
opts.Debug("authenticating using GSSAPI bind (password)")
352354

353355
authClient = &gssapiClient{

options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func (opts *Options) preliminaryCredential() (*Credential, error) {
279279
AESKey: aesKey,
280280
CCache: ccache,
281281
dc: opts.DomainController,
282-
PasswordIsEmtpyString: opts.Password == "" && (opts.flagset != nil && opts.flagset.Changed("password")),
282+
PasswordIsEmptyString: opts.Password == "" && (opts.flagset != nil && opts.flagset.Changed("password")),
283283
CCacheIsFromEnv: opts.CCache != "" && (opts.flagset != nil && !opts.flagset.Changed("ccache")),
284284
Resolver: opts.Resolver,
285285
}

pkinit/asrep.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ func ExtractNegotiatedKey(
8585
return ekey, fmt.Errorf("unmarshal key info: %w", err)
8686
}
8787

88-
if len(keyInfo.SubjectPublicKey.Bytes) < 7 {
89-
return ekey, fmt.Errorf("public key is too short")
90-
}
91-
9288
pubkeyData, err := asn1.Marshal(keyInfo.SubjectPublicKey)
9389
if err != nil {
9490
return ekey, fmt.Errorf("marshal public key: %w", err)
9591
}
9692

93+
if len(pubkeyData) < 7 {
94+
return ekey, fmt.Errorf("public key is too short")
95+
}
96+
9797
pubKey := big.NewInt(0)
9898
pubKey.SetBytes(pubkeyData[7:])
9999

pkinit/diffie_hellman.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
)
88

99
var (
10-
// DiffieHellmanPrime is the Diffie Hellman prime (P) that is acccepted by PKINIT.
10+
// DiffieHellmanPrime is the Diffie Hellman prime (P) that is accepted by PKINIT.
1111
DiffieHellmanPrime = big.NewInt(0)
12-
// DiffieHellmanPrime is the Diffie Hellman base (G) that is acccepted by PKINIT.
12+
// DiffieHellmanBase is the Diffie Hellman base (G) that is accepted by PKINIT.
1313
DiffieHellmanBase = big.NewInt(2)
1414
)
1515

0 commit comments

Comments
 (0)