We present a simultaneous detection of gravitational magnification and dust reddening effects due to galactic halos and large-scale structure . The measurement is based on correlating the brightness of \sim 85,000 quasars at z > 1 with the position of 20 million galaxies at z \sim 0.3 derived from the Sloan Digital Sky Survey and is used to constrain the galaxy-mass and galaxy-dust correlation functions up to cosmological scales . The presence of dust is detected from 20 kpc to several Mpc , and we find its projected density to follow : \Sigma _ { dust } \sim \theta ^ { -0.8 } , a distribution similar to mass . The amount of dust in galactic halos is found to be comparable to that in disks . On large scales its wavelength dependence is described by { R _ { V } } \simeq 3.9 \pm 2.6 , consistent with interstellar dust . We estimate the resulting opacity of the Universe as a function of redshift and find \langle A _ { V } \rangle \sim 0.03 mag up to z = 0.5 . This , in turn , implies a cosmic dust density of \Omega _ { dust } \simeq 5 \times 10 ^ { -6 } , roughly half of which comes from dust in halos of \sim L ^ { \star } galaxies . We present magnification measurements , corrected for dust extinction , from which the galaxy-mass correlation function is inferred . The mean mass profile around galaxies is found to be \Sigma \sim 30 ( \theta / 1 \arcmin ) ^ { -0.8 } h { M _ { \odot } pc ^ { -2 } } up to a radius of 10 Mpc , in agreement with gravitational shear estimates .