airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject [03/13] airavata git commit: test certificate credential - AIRAVATA-1561
Date Tue, 24 Feb 2015 15:57:56 GMT
test certificate credential - AIRAVATA-1561


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/e6803974
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/e6803974
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/e6803974

Branch: refs/heads/queue-gfac-rabbitmq
Commit: e68039748fcff30e608cdcfeebc83d18963bfa92
Parents: d262e9f
Author: Chathuri Wimalasena <kamalasini@gmail.com>
Authored: Tue Feb 10 15:27:30 2015 -0500
Committer: Chathuri Wimalasena <kamalasini@gmail.com>
Committed: Tue Feb 10 15:27:30 2015 -0500

----------------------------------------------------------------------
 .../airavata/credential/store/client/TestSSLClient.java     | 9 ++++++++-
 .../store/server/CredentialStoreServerHandler.java          | 7 +++++--
 2 files changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/e6803974/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/client/TestSSLClient.java
----------------------------------------------------------------------
diff --git a/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/client/TestSSLClient.java
b/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/client/TestSSLClient.java
index dc0889e..12105e2 100644
--- a/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/client/TestSSLClient.java
+++ b/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/client/TestSSLClient.java
@@ -44,6 +44,7 @@ import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
+import org.apache.commons.codec.binary.Base64;
 
 public class TestSSLClient {
     private void invoke() {
@@ -102,7 +103,13 @@ public class TestSSLClient {
             char[] password = "airavata".toCharArray();
             ks.load(fis,password);
             x509Certificates[0] = (X509Certificate) ks.getCertificate("airavata");
-            certificateCredential.setX509Cert(x509Certificates[0].toString());
+            Base64 encoder = new Base64(64);
+            String cert_begin = "-----BEGIN CERTIFICATE-----\n";
+            String end_cert = "-----END CERTIFICATE-----";
+            byte[] derCert = x509Certificates[0].getEncoded();
+            String pemCertPre = new String(encoder.encode(derCert));
+            String pemCert = cert_begin + pemCertPre + end_cert;
+            certificateCredential.setX509Cert(pemCert);
             String token = client.addCertificateCredential(certificateCredential);
             System.out.println("Certificate Token :" + token);
             CertificateCredential credential = client.getCertificateCredential(token, "testGateway");

http://git-wip-us.apache.org/repos/asf/airavata/blob/e6803974/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java
----------------------------------------------------------------------
diff --git a/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java
b/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java
index a364618..1675781 100644
--- a/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java
+++ b/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java
@@ -36,9 +36,11 @@ import org.apache.airavata.credential.store.store.impl.CredentialReaderImpl;
 import org.apache.airavata.credential.store.store.impl.SSHCredentialWriter;
 import org.apache.airavata.credential.store.util.TokenGenerator;
 import org.apache.airavata.credential.store.util.Utility;
+import org.apache.commons.codec.binary.Base64;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import sun.security.provider.X509Factory;
 
 import java.io.ByteArrayInputStream;
 import java.security.cert.CertificateFactory;
@@ -108,9 +110,10 @@ public class CredentialStoreServerHandler implements CredentialStoreService.Ifac
                     certificateCredential.getCommunityUser().getUsername(), certificateCredential.getCommunityUser().getUserEmail()));
             String token = TokenGenerator.generateToken(certificateCredential.getCommunityUser().getGatewayNmae(),
null);
             credential.setToken(token);
+            Base64 encoder = new Base64(64);
+            byte [] decoded = encoder.decode(certificateCredential.getX509Cert().replaceAll(X509Factory.BEGIN_CERT,
"").replaceAll(X509Factory.END_CERT, ""));
             CertificateFactory cf = CertificateFactory.getInstance("X.509");
-            ByteArrayInputStream stream = new ByteArrayInputStream(certificateCredential.getX509Cert().getBytes());
-            X509Certificate certificate = (X509Certificate)cf.generateCertificate(stream);
+            X509Certificate certificate = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(decoded));
             X509Certificate[] certificates = new X509Certificate[1];
             certificates[0] = certificate;
             credential.setCertificates(certificates);


Mime
View raw message