-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement tls client certificate authentication
the imap & smtp servers now allow logging in with tls client authentication and the "external" sasl authentication mechanism. email clients like thunderbird, fairemail, k9, macos mail implement it. this seems to be the most secure among the authentication mechanism commonly implemented by clients. a useful property is that an account can have a separate tls public key for each device/email client. with tls client cert auth, authentication is also bound to the tls connection. a mitm cannot pass the credentials on to another tls connection, similar to scram-*-plus. though part of scram-*-plus is that clients verify that the server knows the client credentials. for tls client auth with imap, we send a "preauth" untagged message by default. that puts the connection in authenticated state. given the imap connection state machine, further authentication commands are not allowed. some clients don't recognize the preauth message, and try to authenticate anyway, which fails. a tls public key has a config option to disable preauth, keeping new connections in unauthenticated state, to work with such email clients. for smtp (submission), we don't require an explicit auth command. both for imap and smtp, we allow a client to authenticate with another mechanism than "external". in that case, credentials are verified, and have to be for the same account as the tls client auth, but the adress can be another one than the login address configured with the tls public key. only the public key is used to identify the account that is authenticating. we ignore the rest of the certificate. expiration dates, names, constraints, etc are not verified. no certificate authorities are involved. users can upload their own (minimal) certificate. the account web interface shows openssl commands you can run to generate a private key, minimal cert, and a p12 file (the format that email clients seem to like...) containing both private key and certificate. the imapclient & smtpclient packages can now also use tls client auth. and so does "mox sendmail", either with a pem file with private key and certificate, or with just an ed25519 private key. there are new subcommands "mox config tlspubkey ..." for adding/removing/listing tls public keys from the cli, by the admin.
- Loading branch information
Showing
38 changed files
with
2,737 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,12 @@ package main | |
|
||
import ( | ||
"context" | ||
"crypto/ed25519" | ||
cryptorand "crypto/rand" | ||
"crypto/x509" | ||
"flag" | ||
"fmt" | ||
"math/big" | ||
"net" | ||
"os" | ||
"path/filepath" | ||
|
@@ -50,6 +54,10 @@ func TestCtl(t *testing.T) { | |
tcheck(t, err, "queue init") | ||
defer queue.Shutdown() | ||
|
||
err = store.Init(ctxbg) | ||
tcheck(t, err, "store init") | ||
defer store.Close() | ||
|
||
testctl := func(fn func(clientctl *ctl)) { | ||
t.Helper() | ||
|
||
|
@@ -334,6 +342,43 @@ func TestCtl(t *testing.T) { | |
ctlcmdConfigAliasRemove(ctl, "[email protected]") | ||
}) | ||
|
||
// accounttlspubkeyadd | ||
certDER := fakeCert(t) | ||
testctl(func(ctl *ctl) { | ||
ctlcmdConfigTlspubkeyAdd(ctl, "[email protected]", "testkey", false, certDER) | ||
}) | ||
|
||
// "accounttlspubkeylist" | ||
testctl(func(ctl *ctl) { | ||
ctlcmdConfigTlspubkeyList(ctl, "") | ||
}) | ||
testctl(func(ctl *ctl) { | ||
ctlcmdConfigTlspubkeyList(ctl, "mjl") | ||
}) | ||
|
||
tpkl, err := store.TLSPublicKeyList(ctxbg, "") | ||
tcheck(t, err, "list tls public keys") | ||
if len(tpkl) != 1 { | ||
t.Fatalf("got %d tls public keys, expected 1", len(tpkl)) | ||
} | ||
fingerprint := tpkl[0].Fingerprint | ||
|
||
// "accounttlspubkeyget" | ||
testctl(func(ctl *ctl) { | ||
ctlcmdConfigTlspubkeyGet(ctl, fingerprint) | ||
}) | ||
|
||
// "accounttlspubkeyrm" | ||
testctl(func(ctl *ctl) { | ||
ctlcmdConfigTlspubkeyRemove(ctl, fingerprint) | ||
}) | ||
|
||
tpkl, err = store.TLSPublicKeyList(ctxbg, "") | ||
tcheck(t, err, "list tls public keys") | ||
if len(tpkl) != 0 { | ||
t.Fatalf("got %d tls public keys, expected 0", len(tpkl)) | ||
} | ||
|
||
// "loglevels" | ||
testctl(func(ctl *ctl) { | ||
ctlcmdLoglevels(ctl) | ||
|
@@ -453,3 +498,15 @@ func TestCtl(t *testing.T) { | |
} | ||
cmdVerifydata(&xcmd) | ||
} | ||
|
||
func fakeCert(t *testing.T) []byte { | ||
t.Helper() | ||
seed := make([]byte, ed25519.SeedSize) | ||
privKey := ed25519.NewKeyFromSeed(seed) // Fake key, don't use this for real! | ||
template := &x509.Certificate{ | ||
SerialNumber: big.NewInt(1), // Required field... | ||
} | ||
localCertBuf, err := x509.CreateCertificate(cryptorand.Reader, template, template, privKey.Public(), privKey) | ||
tcheck(t, err, "making certificate") | ||
return localCertBuf | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,12 @@ Accounts: | |
err = os.WriteFile(filepath.Join(destDataDir, "moxversion"), []byte(moxvar.Version), 0660) | ||
xcheckf(err, "writing moxversion") | ||
|
||
// Populate auth.db | ||
err = store.Init(ctxbg) | ||
xcheckf(err, "store init") | ||
err = store.TLSPublicKeyAdd(ctxbg, &store.TLSPublicKey{Fingerprint: "...", Type: "ecdsa-p256", CertDER: []byte("..."), Account: "test0", LoginAddress: "[email protected]"}) | ||
xcheckf(err, "adding tlspubkey") | ||
|
||
// Populate dmarc.db. | ||
err = dmarcdb.Init() | ||
xcheckf(err, "dmarcdb init") | ||
|
Oops, something went wrong.