@@ -1409,23 +1409,53 @@ func mergeUpdate(r *core.Registration, input core.Registration) bool {
14091409 return changed
14101410}
14111411
1412- // UpdateAuthorization updates an authorization with new values.
1412+ // UpdateAuthorization is a legacy function in the process of being replaced by
1413+ // PerformValidation.
1414+ // TODO(@cpu): Remove this. https://github.com/letsencrypt/boulder/issues/3947
14131415func (ra * RegistrationAuthorityImpl ) UpdateAuthorization (
14141416 ctx context.Context ,
14151417 base core.Authorization ,
14161418 challengeIndex int ,
1417- response core.Challenge ) (core.Authorization , error ) {
1419+ _ core.Challenge ) (core.Authorization , error ) {
1420+ authzPB , err := bgrpc .AuthzToPB (base )
1421+ if err != nil {
1422+ return core.Authorization {}, err
1423+ }
1424+ challIndex := int64 (challengeIndex )
1425+ authzPB , err = ra .PerformValidation (ctx , & rapb.PerformValidationRequest {
1426+ Authz : authzPB ,
1427+ ChallengeIndex : & challIndex ,
1428+ })
1429+ if err != nil {
1430+ return core.Authorization {}, err
1431+ }
1432+ return bgrpc .PBToAuthz (authzPB )
1433+ }
1434+
1435+ // PerformValidation initiates validation for a specific challenge associated
1436+ // with the given base authorization. The authorization and challenge are
1437+ // updated based on the results.
1438+ func (ra * RegistrationAuthorityImpl ) PerformValidation (
1439+ ctx context.Context ,
1440+ req * rapb.PerformValidationRequest ) (* corepb.Authorization , error ) {
1441+ base , err := bgrpc .PBToAuthz (req .Authz )
1442+ if err != nil {
1443+ return nil , err
1444+ }
1445+
14181446 // Refuse to update expired authorizations
14191447 if base .Expires == nil || base .Expires .Before (ra .clk .Now ()) {
1420- return core. Authorization {} , berrors .MalformedError ("expired authorization" )
1448+ return nil , berrors .MalformedError ("expired authorization" )
14211449 }
14221450
14231451 authz := base
1424- if challengeIndex >= len (authz .Challenges ) {
1425- return core.Authorization {}, berrors .MalformedError ("invalid challenge index '%d'" , challengeIndex )
1452+ challIndex := int (* req .ChallengeIndex )
1453+ if challIndex >= len (authz .Challenges ) {
1454+ return nil ,
1455+ berrors .MalformedError ("invalid challenge index '%d'" , challIndex )
14261456 }
14271457
1428- ch := & authz .Challenges [challengeIndex ]
1458+ ch := & authz .Challenges [challIndex ]
14291459
14301460 // If TLSSNIRevalidation is enabled, find out whether this was a revalidation
14311461 // (previous certificate existed) or not. If it is a revalidation, we can
@@ -1437,10 +1467,11 @@ func (ra *RegistrationAuthorityImpl) UpdateAuthorization(
14371467 RegID : & authz .RegistrationID ,
14381468 })
14391469 if err != nil {
1440- return core. Authorization {} , err
1470+ return nil , err
14411471 }
14421472 if ! * existsResp .Exists {
1443- return core.Authorization {}, berrors .MalformedError ("challenge type %q no longer allowed" , ch .Type )
1473+ return nil ,
1474+ berrors .MalformedError ("challenge type %q no longer allowed" , ch .Type )
14441475 }
14451476 }
14461477
@@ -1451,34 +1482,23 @@ func (ra *RegistrationAuthorityImpl) UpdateAuthorization(
14511482 // case and return early.
14521483 if ra .reuseValidAuthz && authz .Status == core .StatusValid {
14531484 ra .stats .Inc ("ReusedValidAuthzChallenge" , 1 )
1454- return authz , nil
1485+ return req . Authz , nil
14551486 }
14561487
14571488 if authz .Status != core .StatusPending {
1458- return core. Authorization {} , berrors .WrongAuthorizationStateError ("authorization must be pending" )
1489+ return nil , berrors .WrongAuthorizationStateError ("authorization must be pending" )
14591490 }
14601491
14611492 // Look up the account key for this authorization
14621493 reg , err := ra .SA .GetRegistration (ctx , authz .RegistrationID )
14631494 if err != nil {
1464- return core. Authorization {} , berrors .InternalServerError (err .Error ())
1495+ return nil , berrors .InternalServerError (err .Error ())
14651496 }
14661497
14671498 // Compute the key authorization field based on the registration key
14681499 expectedKeyAuthorization , err := ch .ExpectedKeyAuthorization (reg .Key )
14691500 if err != nil {
1470- return core.Authorization {}, berrors .InternalServerError ("could not compute expected key authorization value" )
1471- }
1472-
1473- // NOTE(@cpu): Historically challenge update required the client to send
1474- // a JSON POST body that included a computed KeyAuthorization. The RA would
1475- // check this provided authorization against its own computation of the key
1476- // authorization and err if they did not match. New ACME specification does
1477- // not require this - the client does not need to send the key authorization.
1478- // To support this for ACMEv2 we only enforce the provided key authorization
1479- // matches expected if the update included it.
1480- if response .ProvidedKeyAuthorization != "" && expectedKeyAuthorization != response .ProvidedKeyAuthorization {
1481- return core.Authorization {}, berrors .MalformedError ("provided key authorization was incorrect" )
1501+ return nil , berrors .InternalServerError ("could not compute expected key authorization value" )
14821502 }
14831503
14841504 // Populate the ProvidedKeyAuthorization such that the VA can confirm the
@@ -1491,7 +1511,7 @@ func (ra *RegistrationAuthorityImpl) UpdateAuthorization(
14911511
14921512 // Double check before sending to VA
14931513 if cErr := ch .CheckConsistencyForValidation (); cErr != nil {
1494- return core. Authorization {} , berrors .MalformedError (cErr .Error ())
1514+ return nil , berrors .MalformedError (cErr .Error ())
14951515 }
14961516
14971517 ra .stats .Inc ("NewPendingAuthorizations" , 1 )
@@ -1506,7 +1526,7 @@ func (ra *RegistrationAuthorityImpl) UpdateAuthorization(
15061526 copy (challenges , authz .Challenges )
15071527 authz .Challenges = challenges
15081528
1509- records , err := ra .VA .PerformValidation (vaCtx , authz .Identifier .Value , authz .Challenges [challengeIndex ], authz )
1529+ records , err := ra .VA .PerformValidation (vaCtx , authz .Identifier .Value , authz .Challenges [challIndex ], authz )
15101530 var prob * probs.ProblemDetails
15111531 if p , ok := err .(* probs.ProblemDetails ); ok {
15121532 prob = p
@@ -1516,7 +1536,7 @@ func (ra *RegistrationAuthorityImpl) UpdateAuthorization(
15161536 }
15171537
15181538 // Save the updated records
1519- challenge := & authz .Challenges [challengeIndex ]
1539+ challenge := & authz .Challenges [challIndex ]
15201540 challenge .ValidationRecord = records
15211541
15221542 if ! challenge .RecordsSane () && prob == nil {
@@ -1529,7 +1549,7 @@ func (ra *RegistrationAuthorityImpl) UpdateAuthorization(
15291549 } else {
15301550 challenge .Status = core .StatusValid
15311551 }
1532- authz .Challenges [challengeIndex ] = * challenge
1552+ authz .Challenges [challIndex ] = * challenge
15331553
15341554 err = ra .onValidationUpdate (vaCtx , authz )
15351555 if err != nil {
@@ -1538,7 +1558,7 @@ func (ra *RegistrationAuthorityImpl) UpdateAuthorization(
15381558 }
15391559 }(authz )
15401560 ra .stats .Inc ("UpdatedPendingAuthorizations" , 1 )
1541- return authz , nil
1561+ return bgrpc . AuthzToPB ( authz )
15421562}
15431563
15441564func revokeEvent (state , serial , cn string , names []string , revocationCode revocation.Reason ) string {
0 commit comments