Esempio n. 1
0
func (s *HTTPHandlerSuite) TestPublicKey(c *gc.C) {
	pk, err := sfhttp.PublicKey(s.server.URL+"/publickey", nil)
	c.Assert(err, gc.ErrorMatches, ".*public key must be requested with https.*")
	httpClient := &http.Client{
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: true,
			},
		},
	}
	pk, err = sfhttp.PublicKey(s.tlsServer.URL, httpClient)
	c.Assert(err, gc.IsNil)
	c.Assert(pk.Encode(), gc.Equals, s.keyPair.PublicKey.Encode())
}
Esempio n. 2
0
func newClient(keyPair *sf.KeyPair) (*sfhttp.Client, error) {
	var err error
	var serverKey *sf.PublicKey
	if *serverKeyFlag == "" {
		serverKey, err = sfhttp.PublicKey((*urlFlagVar).String(), nil)
		if err != nil {
			return nil, errgo.Mask(err)
		}
	} else {
		serverKey, err = sf.DecodePublicKey(*serverKeyFlag)
		if err != nil {
			return nil, errgo.Mask(err)
		}
	}

	return sfhttp.NewClient(keyPair, (*urlFlagVar).String(), serverKey, &http.Client{
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: true,
			},
		},
	}), nil
}