  We present a theory of ultrarelativistic collisionless shocks based on the
relativistic kinetic two-stream instability. We demonstrate that the shock
front is unstable to the generation of small-scale, randomly tangled magnetic
fields. These fields are strong enough to scatter the energetic incoming (in
the shock frame) protons and electrons over pitch angle and, therefore, to
convert their kinetic energy of bulk motion into heat with very high
efficiency. This validates the use of MHD approximation and the shock jump
conditions in particular. The effective collisions are also necessary for the
diffusive Fermi acceleration of electrons to operate and produce an observed
power-law. Finally, these strong (sub-equipartition) magnetic fields are also
required for the efficient synchrotron-type radiation emission from the shocks.
  The predicted magnetic fields have an impact on polarization properties of
the observed radiation (e.g., a linear polarization from a jet-like ejecta and
polarization scintillations in radio for a spherical one) and on its spectrum.
We present an analytical theory of jitter radiation, which is emitted when the
magnetic field is correlated on scales smaller then the gyration (Larmor)
radius of the accelerated electrons. A composite jitter+synchrotron model of
GRB $\gamma$-ray emission from internal shocks is capable of resolving many
puzzles of GRB spectra, such as the violation of the ``line of death'', sharp
spectral breaks, and multiple spectral components seen in some bursts (good
examples are GRB910503, GRB910402, etc.). We stress that simultaneous detection
of both spectral components opens a way to a precise diagnostics of the
conditions in GRB shocks. We also discuss the relation of our results to other
systems, such as internal shocks in blazars, radio lobes, and supernova shocks.
