qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oru...@apache.org
Subject svn commit: r1739934 - in /qpid/java/trunk/broker-core/src: main/java/org/apache/qpid/server/model/AttributeValueConverter.java test/java/org/apache/qpid/server/model/AttributeValueConverterTest.java
Date Tue, 19 Apr 2016 14:23:26 GMT
Author: orudyy
Date: Tue Apr 19 14:23:26 2016
New Revision: 1739934

URL: http://svn.apache.org/viewvc?rev=1739934&view=rev
Log:
QPID-7174: Fix conversion of string certificate in PEM format

Modified:
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java
    qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/AttributeValueConverterTest.java

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java?rev=1739934&r1=1739933&r2=1739934&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java
(original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java
Tue Apr 19 14:23:26 2016
@@ -29,6 +29,7 @@ import java.lang.reflect.Proxy;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.net.URI;
+import java.nio.charset.StandardCharsets;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
@@ -168,6 +169,7 @@ abstract class AttributeValueConverter<T
         }
     };
 
+    public static final String BEGIN_CERTIFICATE = "-----BEGIN CERTIFICATE-----";
 
     static final AttributeValueConverter<Certificate> CERTIFICATE_CONVERTER = new AttributeValueConverter<Certificate>()
     {
@@ -205,8 +207,15 @@ abstract class AttributeValueConverter<T
             else if(value instanceof String)
             {
                 String strValue = AbstractConfiguredObject.interpolate(object, (String) value);
-                byte[] certificateBytes = BINARY_CONVERTER.convert(strValue, object);
-                return convert(certificateBytes, object);
+                if (strValue.startsWith(BEGIN_CERTIFICATE))
+                {
+                    return convert(strValue.getBytes(StandardCharsets.UTF_8), object);
+                }
+                else
+                {
+                    byte[] certificateBytes = BINARY_CONVERTER.convert(strValue, object);
+                    return convert(certificateBytes, object);
+                }
             }
             else if(value == null)
             {

Modified: qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/AttributeValueConverterTest.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/AttributeValueConverterTest.java?rev=1739934&r1=1739933&r2=1739934&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/AttributeValueConverterTest.java
(original)
+++ qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/AttributeValueConverterTest.java
Tue Apr 19 14:23:26 2016
@@ -259,4 +259,25 @@ public class AttributeValueConverterTest
         assertEquals("CN=app2@acme.org,OU=art,O=acme,L=Toronto,ST=ON,C=CA", x509Certificate.getSubjectX500Principal().getName());
         assertEquals("CN=MyRootCA,O=ACME,ST=Ontario,C=CA", x509Certificate.getIssuerX500Principal().getName());
     }
+
+    public void testPEMCertificateConverter() throws ParseException
+    {
+        ConfiguredObject object = _objectFactory.create(TestCar.class, _attributes);
+        AttributeValueConverter<Certificate> certificateConverter = getConverter(Certificate.class,
Certificate.class);
+        StringBuffer pemCertificate = new StringBuffer("-----BEGIN CERTIFICATE-----\n");
+        int offset = 0;
+        while(BASE_64_ENCODED_CERTIFICATE.length() - offset > 64)
+        {
+            pemCertificate.append(BASE_64_ENCODED_CERTIFICATE.substring(offset, offset +
64)).append('\n');
+            offset += 64;
+        }
+        pemCertificate.append(BASE_64_ENCODED_CERTIFICATE.substring(offset));
+        pemCertificate.append("\n-----END CERTIFICATE-----\n");
+
+        Certificate certificate = certificateConverter.convert(pemCertificate.toString(),
object);
+        assertTrue("Unexpected certificate", certificate instanceof X509Certificate);
+        X509Certificate x509Certificate = (X509Certificate)certificate;
+        assertEquals("CN=app2@acme.org,OU=art,O=acme,L=Toronto,ST=ON,C=CA", x509Certificate.getSubjectX500Principal().getName());
+        assertEquals("CN=MyRootCA,O=ACME,ST=Ontario,C=CA", x509Certificate.getIssuerX500Principal().getName());
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message