Fix certificate chain

Based on <http://stackoverflow.com/a/8797123/96588>.