// 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 }
func NewStorageAuthorityServer(serverQueue string, channel *amqp.Channel, impl core.StorageAuthority) *AmqpRPCServer { rpc := NewAmqpRPCServer(serverQueue, channel) rpc.Handle(MethodGetRegistration, func(req []byte) (response []byte) { var intReq struct { ID int64 } err := json.Unmarshal(req, &intReq) if err != nil { return nil } reg, err := impl.GetRegistration(intReq.ID) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetRegistration, err, req) return nil } response, err = json.Marshal(reg) if err != nil { return nil } return response }) rpc.Handle(MethodGetRegistrationByKey, func(req []byte) (response []byte) { var jwk jose.JsonWebKey if err := json.Unmarshal(req, &jwk); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodGetRegistrationByKey, err, req) } reg, err := impl.GetRegistrationByKey(jwk) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetRegistrationByKey, err, jwk) return nil } response, err = json.Marshal(reg) if err != nil { return nil } return response }) rpc.Handle(MethodGetAuthorization, func(req []byte) []byte { authz, err := impl.GetAuthorization(string(req)) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetAuthorization, err, req) return nil } jsonAuthz, err := json.Marshal(authz) if err != nil { return nil } return jsonAuthz }) rpc.Handle(MethodAddCertificate, func(req []byte) []byte { var icReq struct { Bytes []byte RegID int64 } err := json.Unmarshal(req, &icReq) if err != nil { return nil } id, err := impl.AddCertificate(icReq.Bytes, icReq.RegID) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodAddCertificate, err, req) return nil } return []byte(id) }) rpc.Handle(MethodNewRegistration, func(req []byte) (response []byte) { var registration core.Registration err := json.Unmarshal(req, registration) if err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodNewRegistration, err, req) return nil } output, err := impl.NewRegistration(registration) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodNewRegistration, err, registration) return nil } jsonOutput, err := json.Marshal(output) if err != nil { return nil } return []byte(jsonOutput) }) rpc.Handle(MethodNewPendingAuthorization, func(req []byte) (response []byte) { id, err := impl.NewPendingAuthorization() if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodNewPendingAuthorization, err, req) } else { response = []byte(id) } return response }) rpc.Handle(MethodUpdatePendingAuthorization, func(req []byte) []byte { 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 nil } if err := impl.UpdatePendingAuthorization(authz); err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodUpdatePendingAuthorization, err, authz) } return nil }) rpc.Handle(MethodFinalizeAuthorization, func(req []byte) []byte { 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 nil } if err := impl.FinalizeAuthorization(authz); err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodFinalizeAuthorization, err, authz) } return nil }) rpc.Handle(MethodGetCertificate, func(req []byte) (response []byte) { cert, err := impl.GetCertificate(string(req)) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetCertificate, err, req) } else { response = []byte(cert) } return response }) rpc.Handle(MethodGetCertificateByShortSerial, func(req []byte) (response []byte) { cert, err := impl.GetCertificateByShortSerial(string(req)) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetCertificateByShortSerial, err, req) } else { response = []byte(cert) } return response }) rpc.Handle(MethodGetCertificateStatus, func(req []byte) (response []byte) { status, err := impl.GetCertificateStatus(string(req)) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodGetCertificateStatus, err, req) return nil } jsonStatus, err := json.Marshal(status) if err != nil { return nil } return jsonStatus }) rpc.Handle(MethodMarkCertificateRevoked, func(req []byte) (response []byte) { var revokeReq struct { Serial string OcspResponse []byte ReasonCode int } if err := json.Unmarshal(req, revokeReq); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodMarkCertificateRevoked, err, req) return nil } // Error explicitly ignored since response is nil anyway err := impl.MarkCertificateRevoked(revokeReq.Serial, revokeReq.OcspResponse, revokeReq.ReasonCode) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodMarkCertificateRevoked, err, revokeReq) } return nil }) rpc.Handle(MethodAddDeniedCSR, func(req []byte) []byte { var csrReq struct { Names []string } if err := json.Unmarshal(req, csrReq); err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodAddDeniedCSR, err, req) return nil } if err := impl.AddDeniedCSR(csrReq.Names); err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodAddDeniedCSR, err, csrReq) } return nil }) rpc.Handle(MethodAlreadyDeniedCSR, func(req []byte) []byte { var csrReq struct { Names []string } err := json.Unmarshal(req, csrReq) if err != nil { // AUDIT[ Improper Messages ] 0786b6f2-91ca-4f48-9883-842a19084c64 improperMessage(MethodAlreadyDeniedCSR, err, req) return nil } exists, err := impl.AlreadyDeniedCSR(csrReq.Names) if err != nil { // AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3 errorCondition(MethodAlreadyDeniedCSR, err, csrReq) return nil } if exists { return []byte{1} } else { return []byte{0} } }) return rpc }