// NewStorageAuthorityServer constructs an RPC server func NewStorageAuthorityServer(rpc RPCServer, impl core.StorageAuthority) error { rpc.Handle(MethodUpdateRegistration, func(req []byte) (response []byte, err error) { var reg core.Registration if err = json.Unmarshal(req, ®); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodUpdateRegistration, err, req) return } err = impl.UpdateRegistration(reg) return }) rpc.Handle(MethodGetRegistration, func(req []byte) (response []byte, err error) { var grReq getRegistrationRequest err = json.Unmarshal(req, &grReq) if err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodGetRegistration, err, req) return } reg, err := impl.GetRegistration(grReq.ID) if err != nil { return } response, err = json.Marshal(reg) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetRegistration, err, req) return } return }) rpc.Handle(MethodGetRegistrationByKey, func(req []byte) (response []byte, err error) { var jwk jose.JsonWebKey if err = json.Unmarshal(req, &jwk); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodGetRegistrationByKey, err, req) return } reg, err := impl.GetRegistrationByKey(jwk) if err != nil { return } response, err = json.Marshal(reg) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetRegistrationByKey, err, req) return } return }) rpc.Handle(MethodGetAuthorization, func(req []byte) (response []byte, err error) { authz, err := impl.GetAuthorization(string(req)) if err != nil { return } response, err = json.Marshal(authz) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetAuthorization, err, req) return } return }) rpc.Handle(MethodGetLatestValidAuthorization, func(req []byte) (response []byte, err error) { var lvar latestValidAuthorizationRequest if err = json.Unmarshal(req, &lvar); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodNewAuthorization, err, req) return } authz, err := impl.GetLatestValidAuthorization(lvar.RegID, lvar.Identifier) if err != nil { return } response, err = json.Marshal(authz) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetLatestValidAuthorization, err, req) return } return }) rpc.Handle(MethodAddCertificate, func(req []byte) (response []byte, err error) { var acReq addCertificateRequest err = json.Unmarshal(req, &acReq) if err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodAddCertificate, err, req) return } id, err := impl.AddCertificate(acReq.Bytes, acReq.RegID) if err != nil { return } response = []byte(id) return }) rpc.Handle(MethodNewRegistration, func(req []byte) (response []byte, err error) { var registration core.Registration err = json.Unmarshal(req, ®istration) if err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodNewRegistration, err, req) return } output, err := impl.NewRegistration(registration) if err != nil { return } response, err = json.Marshal(output) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodNewRegistration, err, req) return } return }) rpc.Handle(MethodNewPendingAuthorization, func(req []byte) (response []byte, err error) { var authz core.Authorization if err = json.Unmarshal(req, &authz); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodNewPendingAuthorization, err, req) return } output, err := impl.NewPendingAuthorization(authz) if err != nil { return } response, err = json.Marshal(output) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodNewPendingAuthorization, err, req) return } return }) rpc.Handle(MethodUpdatePendingAuthorization, func(req []byte) (response []byte, err error) { var authz core.Authorization if err = json.Unmarshal(req, &authz); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodUpdatePendingAuthorization, err, req) return } err = impl.UpdatePendingAuthorization(authz) return }) rpc.Handle(MethodFinalizeAuthorization, func(req []byte) (response []byte, err error) { var authz core.Authorization if err = json.Unmarshal(req, &authz); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodFinalizeAuthorization, err, req) return } err = impl.FinalizeAuthorization(authz) return }) rpc.Handle(MethodGetCertificate, func(req []byte) (response []byte, err error) { cert, err := impl.GetCertificate(string(req)) if err != nil { return } jsonResponse, err := json.Marshal(cert) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetCertificate, err, req) return } return jsonResponse, nil }) rpc.Handle(MethodGetCertificateByShortSerial, func(req []byte) (response []byte, err error) { cert, err := impl.GetCertificateByShortSerial(string(req)) if err != nil { return } jsonResponse, err := json.Marshal(cert) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetCertificateByShortSerial, err, req) return } return jsonResponse, nil }) rpc.Handle(MethodGetCertificateStatus, func(req []byte) (response []byte, err error) { status, err := impl.GetCertificateStatus(string(req)) if err != nil { return } response, err = json.Marshal(status) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetCertificateStatus, err, req) return } return }) rpc.Handle(MethodMarkCertificateRevoked, func(req []byte) (response []byte, err error) { var mcrReq markCertificateRevokedRequest if err = json.Unmarshal(req, &mcrReq); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodMarkCertificateRevoked, err, req) return } err = impl.MarkCertificateRevoked(mcrReq.Serial, mcrReq.OCSPResponse, mcrReq.ReasonCode) return }) rpc.Handle(MethodUpdateOCSP, func(req []byte) (response []byte, err error) { var updateOCSPReq updateOCSPRequest if err = json.Unmarshal(req, &updateOCSPReq); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodUpdateOCSP, err, req) return } err = impl.UpdateOCSP(updateOCSPReq.Serial, updateOCSPReq.OCSPResponse) return }) rpc.Handle(MethodAlreadyDeniedCSR, func(req []byte) (response []byte, err error) { var adcReq alreadyDeniedCSRReq err = json.Unmarshal(req, &adcReq) if err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodAlreadyDeniedCSR, err, req) return } exists, err := impl.AlreadyDeniedCSR(adcReq.Names) if err != nil { return } if exists { response = []byte{1} } else { response = []byte{0} } return }) return nil }
// NewStorageAuthorityServer constructs an RPC server func NewStorageAuthorityServer(rpc Server, impl core.StorageAuthority) error { rpc.Handle(MethodUpdateRegistration, func(req []byte) (response []byte, err error) { var reg core.Registration if err = json.Unmarshal(req, ®); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodUpdateRegistration, err, req) return } err = impl.UpdateRegistration(reg) return }) rpc.Handle(MethodGetRegistration, func(req []byte) (response []byte, err error) { var grReq getRegistrationRequest err = json.Unmarshal(req, &grReq) if err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodGetRegistration, err, req) return } reg, err := impl.GetRegistration(grReq.ID) if err != nil { return } response, err = json.Marshal(reg) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetRegistration, err, req) return } return }) rpc.Handle(MethodGetRegistrationByKey, func(req []byte) (response []byte, err error) { var jwk jose.JsonWebKey if err = json.Unmarshal(req, &jwk); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodGetRegistrationByKey, err, req) return } reg, err := impl.GetRegistrationByKey(jwk) if err != nil { return } response, err = json.Marshal(reg) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetRegistrationByKey, err, req) return } return }) rpc.Handle(MethodGetAuthorization, func(req []byte) (response []byte, err error) { authz, err := impl.GetAuthorization(string(req)) if err != nil { return } response, err = json.Marshal(authz) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetAuthorization, err, req) return } return }) rpc.Handle(MethodGetLatestValidAuthorization, func(req []byte) (response []byte, err error) { var lvar latestValidAuthorizationRequest if err = json.Unmarshal(req, &lvar); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodNewAuthorization, err, req) return } authz, err := impl.GetLatestValidAuthorization(lvar.RegID, lvar.Identifier) if err != nil { return } response, err = json.Marshal(authz) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetLatestValidAuthorization, err, req) return } return }) rpc.Handle(MethodAddCertificate, func(req []byte) (response []byte, err error) { var acReq addCertificateRequest err = json.Unmarshal(req, &acReq) if err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodAddCertificate, err, req) return } id, err := impl.AddCertificate(acReq.Bytes, acReq.RegID) if err != nil { return } response = []byte(id) return }) rpc.Handle(MethodNewRegistration, func(req []byte) (response []byte, err error) { var registration core.Registration err = json.Unmarshal(req, ®istration) if err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodNewRegistration, err, req) return } output, err := impl.NewRegistration(registration) if err != nil { return } response, err = json.Marshal(output) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodNewRegistration, err, req) return } return }) rpc.Handle(MethodNewPendingAuthorization, func(req []byte) (response []byte, err error) { var authz core.Authorization if err = json.Unmarshal(req, &authz); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodNewPendingAuthorization, err, req) return } output, err := impl.NewPendingAuthorization(authz) if err != nil { return } response, err = json.Marshal(output) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodNewPendingAuthorization, err, req) return } return }) rpc.Handle(MethodUpdatePendingAuthorization, func(req []byte) (response []byte, err error) { var authz core.Authorization if err = json.Unmarshal(req, &authz); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodUpdatePendingAuthorization, err, req) return } err = impl.UpdatePendingAuthorization(authz) return }) rpc.Handle(MethodFinalizeAuthorization, func(req []byte) (response []byte, err error) { var authz core.Authorization if err = json.Unmarshal(req, &authz); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodFinalizeAuthorization, err, req) return } err = impl.FinalizeAuthorization(authz) return }) rpc.Handle(MethodRevokeAuthorizationsByDomain, func(req []byte) (response []byte, err error) { var reqObj revokeAuthsRequest err = json.Unmarshal(req, &reqObj) if err != nil { return } aRevoked, paRevoked, err := impl.RevokeAuthorizationsByDomain(reqObj.Ident) if err != nil { return } var raResp = revokeAuthsResponse{FinalRevoked: aRevoked, PendingRevoked: paRevoked} response, err = json.Marshal(raResp) return }) rpc.Handle(MethodGetCertificate, func(req []byte) (response []byte, err error) { cert, err := impl.GetCertificate(string(req)) if err != nil { return } jsonResponse, err := json.Marshal(cert) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetCertificate, err, req) return } return jsonResponse, nil }) rpc.Handle(MethodGetCertificateStatus, func(req []byte) (response []byte, err error) { status, err := impl.GetCertificateStatus(string(req)) if err != nil { return } response, err = json.Marshal(status) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetCertificateStatus, err, req) return } return }) rpc.Handle(MethodMarkCertificateRevoked, func(req []byte) (response []byte, err error) { var mcrReq markCertificateRevokedRequest if err = json.Unmarshal(req, &mcrReq); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodMarkCertificateRevoked, err, req) return } err = impl.MarkCertificateRevoked(mcrReq.Serial, mcrReq.ReasonCode) return }) rpc.Handle(MethodUpdateOCSP, func(req []byte) (response []byte, err error) { var updateOCSPReq updateOCSPRequest if err = json.Unmarshal(req, &updateOCSPReq); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodUpdateOCSP, err, req) return } err = impl.UpdateOCSP(updateOCSPReq.Serial, updateOCSPReq.OCSPResponse) return }) rpc.Handle(MethodAlreadyDeniedCSR, func(req []byte) (response []byte, err error) { var adcReq alreadyDeniedCSRReq err = json.Unmarshal(req, &adcReq) if err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodAlreadyDeniedCSR, err, req) return } exists, err := impl.AlreadyDeniedCSR(adcReq.Names) if err != nil { return } if exists { response = []byte{1} } else { response = []byte{0} } return }) rpc.Handle(MethodCountCertificatesRange, func(req []byte) (response []byte, err error) { var cReq countRequest err = json.Unmarshal(req, &cReq) if err != nil { return } count, err := impl.CountCertificatesRange(cReq.Start, cReq.End) if err != nil { return } return json.Marshal(count) }) rpc.Handle(MethodCountCertificatesByNames, func(req []byte) (response []byte, err error) { var cReq countCertificatesByNamesRequest err = json.Unmarshal(req, &cReq) if err != nil { return } counts, err := impl.CountCertificatesByNames(cReq.Names, cReq.Earliest, cReq.Latest) if err != nil { return } return json.Marshal(counts) }) rpc.Handle(MethodCountRegistrationsByIP, func(req []byte) (response []byte, err error) { var cReq countRegistrationsByIPRequest err = json.Unmarshal(req, &cReq) if err != nil { return } count, err := impl.CountRegistrationsByIP(cReq.IP, cReq.Earliest, cReq.Latest) if err != nil { return } return json.Marshal(count) }) rpc.Handle(MethodCountPendingAuthorizations, func(req []byte) (response []byte, err error) { var cReq countPendingAuthorizationsRequest err = json.Unmarshal(req, &cReq) if err != nil { return } count, err := impl.CountPendingAuthorizations(cReq.RegID) if err != nil { return } return json.Marshal(count) }) rpc.Handle(MethodGetSCTReceipt, func(req []byte) (response []byte, err error) { var gsctReq struct { Serial string LogID string } err = json.Unmarshal(req, &gsctReq) if err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodGetSCTReceipt, err, req) return } sct, err := impl.GetSCTReceipt(gsctReq.Serial, gsctReq.LogID) jsonResponse, err := json.Marshal(sct) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetSCTReceipt, err, req) return } return jsonResponse, nil }) rpc.Handle(MethodAddSCTReceipt, func(req []byte) (response []byte, err error) { var sct core.SignedCertificateTimestamp err = json.Unmarshal(req, &sct) if err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodAddSCTReceipt, err, req) return } err = impl.AddSCTReceipt(core.SignedCertificateTimestamp(sct)) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodAddSCTReceipt, err, req) return } return nil, nil }) return nil }