Uploaded image for project: 'EJBCA'
  1. EJBCA
  2. ECA-8273

acme: Reduce code duplication

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: EJBCA 7.3.0
    • Component/s: None
    • Labels:
    • Sprint:
      EJBCA Team Bob - 2019 w28, EJBCA Team Bob - 2019 w31

      Description

      AcmeEndPoint:

      // Lines 890-898
      final List<AcmeAuthorization> acmeAuthorizations = acmeRaMasterApiSession.getAcmeAuthorizationsByOrderId(orderId);
              final String url = uriInfo.getBaseUri().toString();
              final String configParamUrlPart = StringUtils.isEmpty(configuration) ? "" : "?"+PARAM_CONFIGURATION + "=" + configuration;
              final AcmeOrderResponse acmeOrderResponse = new AcmeOrderResponse(acmeOrder, url + PATH_ACCOUNT + accountId + "/authz/",
                      url + "cert/", acmeAuthorizations, configParamUrlPart);
              return Response.ok(acmeOrderResponse, AcmeHttpConstants.MEDIA_TYPE_JSON_UTF8)
                      .header(AcmeHttpConstants.HTTP_HEADER_LINK, getHttpHeaderLink(uriInfo, configParamUrlPart, "directory", "index"))
                      .header(REPLAY_NONCE, acmeNonceSingletonBean.getReplayNonce())
                      .build();
      
      // Lines 944-953
      final List<AcmeAuthorization> acmeAuthorizations = acmeRaMasterApiSession.getAcmeAuthorizationsByOrderId(orderId);
      
              final String url = uriInfo.getBaseUri().toString();
              final String configParamUrlPart = StringUtils.isEmpty(configuration) ? "" : "?" + PARAM_CONFIGURATION + "=" + configuration;
              final AcmeOrderResponse acmeOrderResponse = new AcmeOrderResponse(acmeOrderFinal, url + PATH_ACCOUNT + accountId + "/authz/",
                      url + "cert/", acmeAuthorizations, configParamUrlPart);
              return Response.ok(acmeOrderResponse, AcmeHttpConstants.MEDIA_TYPE_JSON_UTF8)
                      .header(AcmeHttpConstants.HTTP_HEADER_LINK, getHttpHeaderLink(uriInfo, configParamUrlPart, "directory", "index"))
                      .header(REPLAY_NONCE, acmeNonceSingletonBean.getReplayNonce())
                      .build();
      
      // Lines 984-991
      final AcmeAuthorizationResponse acmeAuthorizationResponse = new AcmeAuthorizationResponse(acmeAuthorization, challengeBaseUrl, acmeConfiguration.isWildcardCertificateIssuanceAllowed(),
                      acmeChallenges, configParamUrlPart);
      
              final ResponseBuilder responseBuilder = Response
                      .ok(acmeAuthorizationResponse, AcmeHttpConstants.MEDIA_TYPE_JSON_UTF8)
                      .header(AcmeHttpConstants.HTTP_HEADER_LINK, getHttpHeaderLink(uriInfo, configParamUrlPart, "directory", "index"))
                      .header(REPLAY_NONCE, acmeNonceSingletonBean.getReplayNonce());
              return responseBuilder.build();
      
      // Lines 1064-1070
      final AcmeAuthorizationResponse acmeAuthorizationResponse = new AcmeAuthorizationResponse(acmeAuthorization, challengeBaseUrl, acmeConfiguration.isWildcardCertificateIssuanceAllowed(),
                      acmeChallenges, configParamUrlPart);
              final ResponseBuilder responseBuilder = Response
                      .ok(acmeAuthorizationResponse, AcmeHttpConstants.MEDIA_TYPE_JSON_UTF8)
                      .header(AcmeHttpConstants.HTTP_HEADER_LINK, getHttpHeaderLink(uriInfo, configParamUrlPart, "directory", "index"))
                      .header(REPLAY_NONCE, acmeNonceSingletonBean.getReplayNonce());
              return responseBuilder.build();
      
      // Lines 271-278
      public Response newNonceHead(@QueryParam(PARAM_CONFIGURATION) final String configuration) {
              final CacheControl cacheControl = new CacheControl();
              cacheControl.setNoStore(true);
              cacheControl.setNoTransform(false);
              return Response.ok()
                      .header(REPLAY_NONCE, acmeNonceSingletonBean.getReplayNonce())
                      .cacheControl(cacheControl).language(Locale.ENGLISH).build();
          }
      
      // Lines 305-314
      public Response newAccountHead() {
              final CacheControl cacheControl = new CacheControl();
              cacheControl.setNoStore(true);
              cacheControl.setNoTransform(false);
              return Response.ok()
                      .header(REPLAY_NONCE, acmeNonceSingletonBean.getReplayNonce())
                      .cacheControl(cacheControl)
                      .language(Locale.ENGLISH)
                      .build();
          }
      
      // Lines 715-724
      public Response newOrderHead() {
              final CacheControl cacheControl = new CacheControl();
              cacheControl.setNoStore(true);
              cacheControl.setNoTransform(false);
              return Response.ok()
                  .header(REPLAY_NONCE, acmeNonceSingletonBean.getReplayNonce())
                  .cacheControl(cacheControl)
                  .language(Locale.ENGLISH)
                  .build();
          }
      
      // Lines 1309-1318
      public Response revokeCertHead() {
              final CacheControl cacheControl = new CacheControl();
              cacheControl.setNoStore(true);
              cacheControl.setNoTransform(false);
              return Response.ok()
                  .header(REPLAY_NONCE, acmeNonceSingletonBean.getReplayNonce())
                  .cacheControl(cacheControl)
                  .language(Locale.ENGLISH)
                  .build();
          }
      
      // Lines 841-845
      final AuthenticationToken authenticationToken = getAuthenticationToken(null, httpServletRequest);
              final AcmeConfiguration acmeConfiguration = acmeConfigurationSession.getAcmeConfiguration(authenticationToken, configuration);
              final AcmeAccount acmeAccount = acmeAccountSession.getAccountById(accountId);
              acmeAccountSession.assertActiveAcmeAccount(acmeAccount);
              acmeAccountSession.assertTermsOfServiceAgreed(authenticationToken, acmeConfiguration, acmeAccount);
      
      // Lines 879-883
      final AuthenticationToken authenticationToken = getAuthenticationToken(null, httpServletRequest);
              final AcmeConfiguration acmeConfiguration = acmeConfigurationSession.getAcmeConfiguration(authenticationToken, configuration);
              final AcmeAccount acmeAccount = acmeAccountSession.getAccountById(accountId);
              acmeAccountSession.assertActiveAcmeAccount(acmeAccount);
              acmeAccountSession.assertTermsOfServiceAgreed(authenticationToken, acmeConfiguration, acmeAccount);
      
      // Lines 972-976
      final AuthenticationToken authenticationToken = getAuthenticationToken(null, httpServletRequest);
              final AcmeConfiguration acmeConfiguration = acmeConfigurationSession.getAcmeConfiguration(authenticationToken, configuration);
              final AcmeAccount acmeAccount = acmeAccountSession.getAccountById(accountId);
              acmeAccountSession.assertActiveAcmeAccount(acmeAccount);
              acmeAccountSession.assertTermsOfServiceAgreed(authenticationToken, acmeConfiguration, acmeAccount);
      

      AcmeJwsHelper:

      // Lines 271-274
      jwsObject.sign(signer);
                  final AcmeProtectedRequest acmeProtectedRequest = new AcmeProtectedRequest(jwsObject.getHeader().toBase64URL().toString(),
                          jwsObject.getPayload().toBase64URL().toString(), jwsObject.getSignature().toString());
                  final String ret = AcmeJsonHelper.toJsonString(acmeProtectedRequest);
      
      // Lines 313-316
      jwsObject.sign(signer);
              final AcmeProtectedRequest acmeProtectedRequest = new AcmeProtectedRequest(jwsObject.getHeader().toBase64URL().toString(),
                      jwsObject.getPayload().toBase64URL().toString(), jwsObject.getSignature().toString());
              final String ret = AcmeJsonHelper.toJsonString(acmeProtectedRequest);
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              katja_helmes Jekaterina Bunina
              Reporter:
              andrey_helmes Andrey Sergeev (Inactive)
              Verified by:
              Ulf Undmark
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 3 days
                  3d