Any copying of a work under copyright is a crime unless there is an exemption in law. It's deny by default. Google and Amazon probably pay license fees to the RIAA. MP3.com was shut down for making unlicensed copies of songs that the users already owned the CD for, so I don't see how you got from them being put out of business to "being legal".

The law is US Title 17

§ 106. Exclusive rights in copyrighted works
Subject to sections 107 through 122, the owner of copyright under this title has the exclusive rights to do and to authorize any of the following:
(1) to reproduce the copyrighted work in copies or phonorecords;
(2) to prepare derivative works based upon the copyrighted work;
(3) to distribute copies or phonorecords of the copyrighted work to the public by sale or other transfer of ownership, or by rental, lease, or lending;
(4) in the case of literary, musical, dramatic, and choreographic works, pantomimes, and motion pictures and other audiovisual works, to perform the copyrighted work publicly;
(5) in the case of literary, musical, dramatic, and choreographic works, pantomimes, and pictorial, graphic, or sculptural works, including the individual images of a motion picture or other audiovisual work, to display the copyrighted work publicly; and
(6) in the case of sound recordings, to perform the copyrighted work publicly by means of a digital audio transmission.

§ 107. Limitations on exclusive rights: Fair use
Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phonorecords or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright. In determining whether the use made of a work in any particular case is a fair use the factors to be considered shall include:
(1) the purpose and character of the use, including whether such use is of a commercial nature or is for nonprofit educational purposes;
(2) the nature of the copyrighted work;
(3) the amount and substantiality of the portion used in relation to the copyrighted work as a whole; and
(4) the effect of the use upon the potential market for or value of the copyrighted work.
The fact that a work is unpublished shall not itself bar a finding of fair use if such finding is made upon consideration of all the above factors.

Of the other sections from 107 through 122,

§ 108 allows libraries to reproduce "no more than one copy or phonorecord of a work".

§ 109 allows the owner of a physical copy to sell it, but forbids renting or lending software media (CDs etc) without a license.

§ 110 allows schools and churches to hold plays.

§ 111 allows the local loop of a network to repeat the network signal without obtaining an extra license for every single retransmission.

§ 112 allows TV stations to save a single copy of their transmission.

§ 113 prevents reproduction of a "pictorial, graphic, or sculptural work"

§ 114 regulates music streaming services.

§ 115 forces the RIAA to allow anyone to license copies of "non-dramatic" music (ringtones) at royalty rates set in law.

§ 116 allows jukebox owners to form a union to negotiate licensing fees.

§ 117 allows you to let your computer make a copy of software from disk to ram to run programs.

§ 118 gives PBS extra powers in negotiating license fees.

§ 119 allows satellite TV to convert the satellite signal to a TV signal.

§ 120 allows people to photograph buildings.

§ 121 allows the government and nonprofits to make Braille copies of copyrighted works.

§ 122 forces the satellite TV networks to obtain an extra license again.

Source:
http://www.law.cornell.edu/uscode/html/uscode17/usc_sup_01_1...