Legal - of course - but it will void any warranty unless it is one of the parts that Apple approve for user upgrade. For example, on my Mac Mini there would be no problem in upgrading the RAM but if I tried changing the processor then any chance of repairs under warranty, or goodwill, from Apple would be out the window.