A characterization of quasipositive two-bridge knots