cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kis...@apache.org
Subject git commit: updated refs/heads/master to 1d0b146
Date Thu, 10 Apr 2014 06:23:18 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 0615d4e6a -> 1d0b14673


CLOUDSTACK-6354 : removing the hard coding of key path in EncryptionSecretKeyChecker


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

Branch: refs/heads/master
Commit: 1d0b14673da2b877112a4030c17496e26cf3f531
Parents: 0615d4e
Author: Damodar Reddy <damoder.reddy@citrix.com>
Authored: Wed Apr 9 17:56:05 2014 +0530
Committer: Kishan Kavala <kishan@cloud.com>
Committed: Thu Apr 10 11:44:18 2014 +0530

----------------------------------------------------------------------
 .../utils/crypt/EncryptionSecretKeyChecker.java | 21 +++++----
 .../crypto/EncryptionSecretKeyCheckerTest.java  | 45 ++++++++++++++++++++
 2 files changed, 55 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1d0b1467/utils/src/com/cloud/utils/crypt/EncryptionSecretKeyChecker.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/crypt/EncryptionSecretKeyChecker.java b/utils/src/com/cloud/utils/crypt/EncryptionSecretKeyChecker.java
index 0e995c4..b28b067 100755
--- a/utils/src/com/cloud/utils/crypt/EncryptionSecretKeyChecker.java
+++ b/utils/src/com/cloud/utils/crypt/EncryptionSecretKeyChecker.java
@@ -20,10 +20,8 @@
 package com.cloud.utils.crypt;
 
 import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.net.ServerSocket;
@@ -45,8 +43,8 @@ public class EncryptionSecretKeyChecker {
     private static final Logger s_logger = Logger.getLogger(EncryptionSecretKeyChecker.class);
 
     // Two possible locations with the new packaging naming
-    private static final String s_altKeyFile = "/etc/cloudstack/management/key";
-    private static final String s_keyFile = "/etc/cloudstack/management/key";
+    private static final String s_altKeyFile = "key";
+    private static final String s_keyFile = "key";
     private static final String s_envKey = "CLOUD_SECRET_KEY";
     private static StandardPBEStringEncryptor s_encryptor = new StandardPBEStringEncryptor();
     private static boolean s_useEncryption = false;
@@ -78,17 +76,18 @@ public class EncryptionSecretKeyChecker {
         SimpleStringPBEConfig stringConfig = new SimpleStringPBEConfig();
 
         if (encryptionType.equals("file")) {
-            File keyFile = new File(s_keyFile);
-            if (!keyFile.exists()) {
-                keyFile = new File(s_altKeyFile);
+            InputStream is = this.getClass().getClassLoader().getResourceAsStream(s_keyFile);
+            if (is == null) {
+              is = this.getClass().getClassLoader().getResourceAsStream(s_altKeyFile);
+            }
+            if(is == null) {  //This is means we are not able to load key file from the classpath.
+              throw new CloudRuntimeException(s_keyFile + " File containing secret key not
found in the classpath: ");
             }
             BufferedReader in = null;
             try {
-                in = new BufferedReader(new FileReader(keyFile));
+                in = new BufferedReader(new InputStreamReader(is));
                 secretKey = in.readLine();
                 //Check for null or empty secret key
-            } catch (FileNotFoundException e) {
-                throw new CloudRuntimeException("File containing secret key not found: "
+ s_keyFile, e);
             } catch (IOException e) {
                 throw new CloudRuntimeException("Error while reading secret key from: " +
s_keyFile, e);
             } finally {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1d0b1467/utils/test/com/cloud/utils/crypto/EncryptionSecretKeyCheckerTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/crypto/EncryptionSecretKeyCheckerTest.java b/utils/test/com/cloud/utils/crypto/EncryptionSecretKeyCheckerTest.java
new file mode 100644
index 0000000..0f3f058
--- /dev/null
+++ b/utils/test/com/cloud/utils/crypto/EncryptionSecretKeyCheckerTest.java
@@ -0,0 +1,45 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.utils.crypto;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Properties;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.cloud.utils.crypt.EncryptionSecretKeyChecker;
+import com.cloud.utils.db.DbProperties;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class EncryptionSecretKeyCheckerTest {
+
+  private EncryptionSecretKeyChecker checker = new EncryptionSecretKeyChecker();
+
+  @Test(expected = CloudRuntimeException.class)
+  public void testKeyFileDoesNotExists() throws IOException, URISyntaxException {
+    Assert.assertNotNull(checker);
+    Properties properties = DbProperties.getDbProperties();
+    properties.setProperty("db.cloud.encryption.type", "file");
+    checker.check(properties);
+  }
+
+}
\ No newline at end of file


Mime
View raw message