Is it legal for a US customs & border protection officer to go?
Probably. Border searches are essentially exempt from Fourth Amendment protections. A border/customs officer can decide to do as thorough a search as he might think is necessary, and not require any probable cause or suspicion. Electronic devices can be included in that search. A gray area is when the device is protected by a password. The officer can demand you provide the password, but its gray as to whether he could arrest you if you refused. He could probably seize the device and attempt to crack the password, and you might or might not get it back. I havent traveled extensively. Ive come though U.S. Customs maybe a dozen times, total. The closest Ive ever come to a close examination was a CBP officer asking me where I got the Seiko watch I was wearing. It was a gift from my wife (purchased in the U.S.), and at that moment was over five years old. He took my word for it and said, Welcome home.