Modify the code location of FIPS mode setting 56/28856/1
authoryuseok.jeon <yuseok.jeon@samsung.com>
Tue, 7 Oct 2014 04:04:52 +0000 (13:04 +0900)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Thu, 16 Oct 2014 13:44:31 +0000 (15:44 +0200)
Change-Id: I087bf3451e46427943e1a9f2a8ea37d6368e1631
Signed-off-by: yuseok.jeon <yuseok.jeon@samsung.com>
src/manager/service/CryptoService.cpp
src/manager/service/ckm-logic.cpp

index 3152f2a..534cd64 100644 (file)
@@ -40,25 +40,13 @@ CryptoService::~CryptoService(){
 
 
 int CryptoService::initialize() {
-    int mode = 0;
-    int rc = 0;
-    int hw_rand_ret = 0, u_rand_ret = 0;
+    int hw_rand_ret = 0;
+    int u_rand_ret = 0;
 
     // try to initialize using ERR_load_crypto_strings and OpenSSL_add_all_algorithms
     ERR_load_crypto_strings();
     OpenSSL_add_all_algorithms();
 
-    // turn on FIPS_mode
-    mode = FIPS_mode();
-
-    if(mode == 0) {
-        rc = FIPS_mode_set(1);
-
-        if(rc == 0) {
-            LogError("Error in FIPS_mode_set function");
-        }
-    }
-
     // initialize entropy
     std::ifstream ifile(DEV_HW_RANDOM_FILE);
     if(ifile.is_open()) {
index e6f0cbb..f6f70db 100644 (file)
@@ -116,12 +116,31 @@ RawBuffer CKMLogic::unlockUserKey(uid_t user, const Password &password) {
 RawBuffer CKMLogic::setCCModeStatus(CCModeState mode_status) {
 
     int retCode = CKM_API_SUCCESS;
+    int fipsModeStatus = 0;
+    int rc = 0;
 
     if((mode_status != CCModeState:: CC_MODE_OFF) && (mode_status != CCModeState:: CC_MODE_ON)) {
         retCode = CKM_API_ERROR_INPUT_PARAM;
     }
 
     cc_mode_status = mode_status;
+    fipsModeStatus = FIPS_mode();
+
+    if(cc_mode_status == CCModeState:: CC_MODE_ON) {
+        if(fipsModeStatus == 0) { // If FIPS mode off
+            rc = FIPS_mode_set(1); // Change FIPS_mode from off to on
+            if(rc == 0) {
+                LogError("Error in FIPS_mode_set function");
+            }
+        }
+    } else {
+        if(fipsModeStatus == 1) { // If FIPS mode on
+            rc = FIPS_mode_set(0); // Change FIPS_mode from on to off
+            if(rc == 0) {
+                LogError("Error in FIPS_mode_set function");
+            }
+        }
+    }
 
     MessageBuffer response;
     Serialization::Serialize(response, retCode);