Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,6 @@ func run(

sigHdlr.addWeb(web)

tlsMgr.setWebAPI(web)

statsDir, querylogDir, err := checkStatsAndQuerylogDirs(config, workDir)
fatalOnError(ctx, baseLogger, err)

Expand Down
25 changes: 1 addition & 24 deletions internal/home/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ type tlsManager struct {
// nil.
extTLSConf *aghtls.ExtendedTLSConfig

// web is the web UI and API server. It must not be nil.
//
// TODO(s.chzhen): Temporary cyclic dependency due to ongoing refactoring.
// Resolve it.
web *webAPI

// rootCerts is a pool of root CAs for TLSv1.2.
rootCerts *x509.CertPool

Expand Down Expand Up @@ -106,8 +100,7 @@ type tlsManagerConfig struct {
// newTLSManager initializes the manager of TLS configuration. m is always
// non-nil while any returned error indicates that the TLS configuration isn't
// valid. Thus TLS may be initialized later, e.g. via the web UI. conf must
// not be nil. Note that [tlsManager.web] must be initialized later on by using
// [tlsManager.setWebAPI].
// not be nil.
func newTLSManager(ctx context.Context, conf *tlsManagerConfig) (m *tlsManager, err error) {
m = &tlsManager{
logger: conf.logger,
Expand Down Expand Up @@ -185,14 +178,6 @@ func newTLSManager(ctx context.Context, conf *tlsManagerConfig) (m *tlsManager,
return m, nil
}

// setWebAPI stores the provided web API. It must be called before
// [tlsManager.Start], [tlsManager.reload] or [webAPI.validateTLSSettings].
//
// TODO(s.chzhen): Remove it once cyclic dependency is resolved.
func (m *tlsManager) setWebAPI(webAPI *webAPI) {
m.web = webAPI
}

// setCertFileTime sets [tlsManager.certLastMod] from the certificate. If there
// are errors, setCertFileTime logs them. m.mu is expected to be locked.
func (m *tlsManager) setCertFileTime(ctx context.Context) {
Expand Down Expand Up @@ -1031,14 +1016,6 @@ var _ service.Interface = (*tlsManager)(nil)
// Start implements the [service.Interface] interface for *tlsManager. It
// starts the TLS manager.
func (m *tlsManager) Start(ctx context.Context) (err error) {
m.mu.Lock()
defer m.mu.Unlock()

// The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request.
m.web.tlsConfigChanged(context.Background(), m.extTLSConf)

go m.handleCertFileChange(ctx)

return nil
Expand Down
3 changes: 0 additions & 3 deletions internal/home/tls_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,6 @@ func TestTLSManager_Reload(t *testing.T) {
})
require.NoError(t, err)

web := newTestWeb(t, &webConfig{tlsManager: m})
m.setWebAPI(web)

extTLSConf := m.ExtendedTLSConfig()
assertCertSerialNumber(t, extTLSConf, snBefore)

Expand Down
11 changes: 9 additions & 2 deletions internal/home/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,15 @@ func (web *webAPI) start(ctx context.Context) {

web.logger.InfoContext(ctx, "AdGuard Home is available at the following addresses:")

// For https, we have a separate goroutine loop.
go web.tlsServerLoop(ctx)
go func() {
// Apply the initial TLS configuration. The background context is used
// because tlsConfigChanged wraps context with timeout on its own and shuts
// down the server, which handles current request.
web.tlsConfigChanged(context.Background(), web.tlsConfProvider.ExtendedTLSConfig())

// For https, we have a separate goroutine loop.
web.tlsServerLoop(ctx)
}()

// This loop is used as an ability to change listening host and/or port.
for !web.httpsServer.inShutdown() {
Expand Down
4 changes: 0 additions & 4 deletions internal/home/web_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func TestWebAPI_HandleTLSConfigure(t *testing.T) {
require.NoError(t, err)

web := newTestWeb(t, &webConfig{tlsManager: m})
m.setWebAPI(web)

extTLSConf := m.ExtendedTLSConfig()
assertCertSerialNumber(t, extTLSConf, wantSerialNumber)
Expand Down Expand Up @@ -176,7 +175,6 @@ func TestWebAPI_HandleTLSStatus(t *testing.T) {
require.NoError(t, err)

web := newTestWeb(t, &webConfig{tlsManager: m})
m.setWebAPI(web)

w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/control/tls/status", nil)
Expand Down Expand Up @@ -209,7 +207,6 @@ func TestWebAPI_ValidateTLSSettings(t *testing.T) {
require.NoError(t, err)

web := newTestWeb(t, &webConfig{tlsManager: m})
m.setWebAPI(web)

tcpLn, err := net.Listen("tcp", ":0")
require.NoError(t, err)
Expand Down Expand Up @@ -310,7 +307,6 @@ func TestWebAPI_HandleTLSValidate(t *testing.T) {
require.NoError(t, err)

web := newTestWeb(t, &webConfig{tlsManager: m})
m.setWebAPI(web)

setts := &tlsConfigSettingsExt{
tlsConfigSettings: tlsConfigSettings{
Expand Down
Loading