>From 44e6043dea0d5b6bc36ddd9e70a485493b8d8316 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Thu, 21 May 2015 02:43:31 -0400 Subject: [PATCH] Use SimpleProperties to handle raw profile format The store() method of the 'Properties' class escapes '=' and ':' in values, corrupting the profile data. Continue using 'Properties' to read the input (unescaping values) then copy the properties into a 'SimpleProperties' object so that unwanted backslashes do not appear in the output. --- .../dogtagpki/server/ca/rest/ProfileService.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/base/ca/src/org/dogtagpki/server/ca/rest/ProfileService.java b/base/ca/src/org/dogtagpki/server/ca/rest/ProfileService.java index 78f89b01231c17128c1fcea5fe3d38e073a5efc7..0e708f4f447dcf3904a2ea9f5daaadb3e2273086 100644 --- a/base/ca/src/org/dogtagpki/server/ca/rest/ProfileService.java +++ b/base/ca/src/org/dogtagpki/server/ca/rest/ProfileService.java @@ -80,6 +80,7 @@ import com.netscape.cms.realm.PKIPrincipal; import com.netscape.cms.servlet.base.PKIService; import com.netscape.cms.servlet.profile.PolicyConstraintFactory; import com.netscape.cms.servlet.profile.PolicyDefaultFactory; +import com.netscape.cmscore.base.SimpleProperties; /** * @author alee @@ -537,6 +538,8 @@ public class ProfileService extends PKIService implements ProfileResource { Map auditParams = new LinkedHashMap(); String profileId = null; String classId = null; + // First read the data into a Properties to process escaped + // separator characters (':', '=') in values Properties properties = new Properties(); try { // load data and read profileId and classId @@ -555,9 +558,16 @@ public class ProfileService extends PKIService implements ProfileResource { properties.remove("profileId"); properties.remove("classId"); + // Now copy into SimpleProperties to avoid unwanted escapes + // of separator characters in output + SimpleProperties simpleProperties = new SimpleProperties(); + for (String k : properties.stringPropertyNames()) { + simpleProperties.setProperty(k, properties.getProperty(k)); + } + try { ByteArrayOutputStream out = new ByteArrayOutputStream(); - properties.store(out, null); + simpleProperties.store(out, null); data = out.toByteArray(); // original data sans profileId, classId IProfile profile = ps.getProfile(profileId); @@ -655,6 +665,8 @@ public class ProfileService extends PKIService implements ProfileResource { throw new BadRequestException("Cannot change profile data. Profile must be disabled"); } + // First read the data into a Properties to process escaped + // separator characters (':', '=') in values Properties properties = new Properties(); try { properties.load(new ByteArrayInputStream(data)); @@ -664,6 +676,13 @@ public class ProfileService extends PKIService implements ProfileResource { properties.remove("profileId"); properties.remove("classId"); + // Now copy into SimpleProperties to avoid unwanted escapes + // of separator characters in output + SimpleProperties simpleProperties = new SimpleProperties(); + for (String k : properties.stringPropertyNames()) { + simpleProperties.setProperty(k, properties.getProperty(k)); + } + try { IProfile profile = ps.getProfile(profileId); if (profile == null) { @@ -671,7 +690,7 @@ public class ProfileService extends PKIService implements ProfileResource { } ByteArrayOutputStream out = new ByteArrayOutputStream(); - properties.store(out, null); + simpleProperties.store(out, null); data = out.toByteArray(); // original data sans profileId, classId profile.getConfigStore().load(new ByteArrayInputStream(data)); -- 2.1.0