The Chern-Weil topological theory is applied to a classical formulation of general relativity in four-dimensional spacetime. Einstein--Hilbert gravitational action is shown to be invariant with respect to a novel translation (co-translation) operator up to the total derivative; thus, a topological invariant of a second Chern class exists owing to Chern-Weil theory. Using topological insight, fundamental forms can be introduced as a principal bundle of the spacetime manifold. Canonical quantization of general relativity is performed in a Heisenberg picture using the Nakanishi-Kugo-Ojima formalism in which a complete set of quantum Lagrangian and BRST transformations including auxiliary and ghost fields is provided in a self-consistent manner. An appropriate Hilbert space and physical states are introduced into the theory, and the positivity of these physical states and the unitarity of the transition matrix are ensured according to the Kugo-Ojima theorem. The nonrenormalizability of quantum gravity is reconsidered under the formulation proposed herein.