If you are buying an OEM licence then it's not legal, as they are only supposed to be sold with a new PC from a system builder.
Some sellers try to sell some hardware - MOBO, RAM or HDD - with the software, but this still doesn't make it legit.
If it is branded - e.g. Dell or HP - then it is OEM and therefore not legal.
You need to purchase a full retail copy, unless you (or a family member) qualify for an educational or other discount version.
Alternatively, you can buy an Upgrade version if you have a legitimate qualifying OS currently installed.
Any PC that was purchased with Windows XP or Vista pre-installed (look for the sticker on the side) is qualified. This is true whether the PC came from a large royalty OEM or a system builder. You can install a retail upgrade of Windows 7 on that PC. You cannot, however, use the OEM license from an old PC to upgrade a new PC without Windows installed.
Any retail full copy of Windows XP or Windows Vista can serve as the qualifying license as well. If have a full retail copy (not an OEM edition) on an old PC, you can un-install that copy from the old PC and use it as the baseline full license for the new PC.
SD