@@ -210,6 +210,9 @@ public class HFCAClient {
210210 private final boolean isSSL ;
211211 private final Properties properties ;
212212
213+ // Cache the payload type, so don't need to make get cainfo call everytime
214+ private Boolean newPayloadType ;
215+
213216 /**
214217 * The Certificate Authority name.
215218 *
@@ -1334,12 +1337,12 @@ String httpPost(String url, String body, UsernamePasswordCredentials credentials
13341337 }
13351338
13361339 JsonObject httpPost (String url , String body , User registrar ) throws Exception {
1337- String authHTTPCert = getHTTPAuthCertificate (registrar .getEnrollment (), body );
1340+ String authHTTPCert = getHTTPAuthCertificate (registrar .getEnrollment (), "POST" , url , body );
13381341 return post (url , body , authHTTPCert );
13391342 }
13401343
13411344 JsonObject httpPost (String url , String body , Enrollment enrollment ) throws Exception {
1342- String authHTTPCert = getHTTPAuthCertificate (enrollment , body );
1345+ String authHTTPCert = getHTTPAuthCertificate (enrollment , "POST" , url , body );
13431346 return post (url , body , authHTTPCert );
13441347 }
13451348
@@ -1369,8 +1372,8 @@ JsonObject httpGet(String url, User registrar) throws Exception {
13691372 }
13701373
13711374 JsonObject httpGet (String url , User registrar , Map <String , String > queryMap ) throws Exception {
1372- String authHTTPCert = getHTTPAuthCertificate (registrar .getEnrollment (), "" );
13731375 String getURL = getURL (url , queryMap );
1376+ String authHTTPCert = getHTTPAuthCertificate (registrar .getEnrollment (), "GET" , getURL , "" );
13741377 HttpGet httpGet = new HttpGet (getURL );
13751378 httpGet .setConfig (getRequestConfig ());
13761379 logger .debug (format ("httpGet %s, authHTTPCert: %s" , url , authHTTPCert ));
@@ -1390,7 +1393,7 @@ JsonObject httpGet(String url, User registrar, Map<String, String> queryMap) thr
13901393 }
13911394
13921395 JsonObject httpPut (String url , String body , User registrar ) throws Exception {
1393- String authHTTPCert = getHTTPAuthCertificate (registrar .getEnrollment (), body );
1396+ String authHTTPCert = getHTTPAuthCertificate (registrar .getEnrollment (), "PUT" , url , body );
13941397 String putURL = addCAToURL (url );
13951398 HttpPut httpPut = new HttpPut (putURL );
13961399 httpPut .setConfig (getRequestConfig ());
@@ -1412,7 +1415,7 @@ JsonObject httpPut(String url, String body, User registrar) throws Exception {
14121415 }
14131416
14141417 JsonObject httpDelete (String url , User registrar ) throws Exception {
1415- String authHTTPCert = getHTTPAuthCertificate (registrar .getEnrollment (), "" );
1418+ String authHTTPCert = getHTTPAuthCertificate (registrar .getEnrollment (), "DELETE" , url , " " );
14161419 String deleteURL = addCAToURL (url );
14171420 HttpDelete httpDelete = new HttpDelete (deleteURL );
14181421 httpDelete .setConfig (getRequestConfig ());
@@ -1518,11 +1521,37 @@ JsonObject getResult(HttpResponse response, String body, String type) throws HTT
15181521 return result ;
15191522 }
15201523
1521- String getHTTPAuthCertificate (Enrollment enrollment , String body ) throws Exception {
1524+ String getHTTPAuthCertificate (Enrollment enrollment , String method , String url , String body ) throws Exception {
15221525 Base64 .Encoder b64 = Base64 .getEncoder ();
15231526 String cert = b64 .encodeToString (enrollment .getCert ().getBytes (UTF_8 ));
15241527 body = b64 .encodeToString (body .getBytes (UTF_8 ));
1525- String signString = body + "." + cert ;
1528+ String signString ;
1529+ // Cache the version, so don't need to make info call everytime the same client is used
1530+ if (newPayloadType == null ) {
1531+ newPayloadType = true ;
1532+
1533+ // If CA version is less than 1.4.0, use old payload
1534+ String caVersion = info ().getVersion ();
1535+ logger .info (format ("CA Version: %s" , caVersion ));
1536+
1537+ if (Utils .isNullOrEmpty (caVersion )) {
1538+ newPayloadType = false ;
1539+ }
1540+
1541+ String version = caVersion + "." ;
1542+ if (version .startsWith ("1.1." ) || version .startsWith ("1.2." ) || version .startsWith ("1.3." )) {
1543+ newPayloadType = false ;
1544+ }
1545+ }
1546+
1547+ if (newPayloadType ) {
1548+ url = addCAToURL (url );
1549+ String file = b64 .encodeToString (new URL (url ).getFile ().getBytes (UTF_8 ));
1550+ signString = method + "." + file + "." + body + "." + cert ;
1551+ } else {
1552+ signString = body + "." + cert ;
1553+ }
1554+
15261555 byte [] signature = cryptoSuite .sign (enrollment .getKey (), signString .getBytes (UTF_8 ));
15271556 return cert + "." + b64 .encodeToString (signature );
15281557 }
0 commit comments