In the most technical sense it's legal though of course it subverts the entire idea of the justice system by having a court in your pocket.
[1] https://www.vox.com/2015/5/7/8567089/nsa-patriot-act-ruling
[2] https://www.washingtonpost.com/world/national-security/nsa-b...