Red Sox finalize Hanrahan trade