return err } if err = json.Unmarshal(data, c); err != nil { return err } log.Info("Loaded credentials from %s.", filename) return nil } // CRAMMD5MaxRequests is the maximum number of requests that an // unauthenticated client is allowed to make (this should be enough to // perform authentication). const CRAMMD5MaxRequests = 2 var ( AuthenticationServer = rpc.NewServer() DefaultAuthenticatorCRAMMD5 = NewAuthenticatorCRAMMD5() ) // AuthenticationFailed is returned when the client fails to // authenticate. var AuthenticationFailed = errors.New("authentication error: authentication failed") func NewAuthenticatorCRAMMD5() *AuthenticatorCRAMMD5 { return &AuthenticatorCRAMMD5{make(cramMD5Credentials)} } // LoadCredentials loads credentials stored in the JSON file named // filename into the default authenticator. func LoadCredentials(filename string) error { return DefaultAuthenticatorCRAMMD5.Credentials.Load(filename)
http.Handle(GetRpcPath(codecName, false), &rpcHandler{cFactory, false}) } // ServeRPC handles rpc requests using the hijack scheme of rpc func ServeAuthRPC(codecName string, cFactory ServerCodecFactory) { http.Handle(GetRpcPath(codecName, true), &rpcHandler{cFactory, true}) } // ServeHTTP handles rpc requests in HTTP compliant POST form func ServeHTTP(codecName string, cFactory ServerCodecFactory) { http.Handle(GetHttpPath(codecName), &httpHandler{cFactory}) } // AuthenticatedServer is an rpc.Server instance that serves // authenticated calls. var AuthenticatedServer = rpc.NewServer() // RegisterAuthenticated registers a receiver with the authenticated // rpc server. func RegisterAuthenticated(rcvr interface{}) error { // TODO(szopa): This should be removed after the transition // period, when all the clients know about authentication. if err := rpc.Register(rcvr); err != nil { return err } return AuthenticatedServer.Register(rcvr) } // ServeCodec calls ServeCodec for the appropriate server // (authenticated or default). func (h *rpcHandler) ServeCodecWithContext(c rpc.ServerCodec, context *proto.Context) {