Change some error messages to debug.
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Thu, 26 Jun 2014 16:40:37 +0000 (18:40 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Fri, 12 Sep 2014 12:58:47 +0000 (14:58 +0200)
Add additional debug messages.

Change-Id: I8f92f0b55a5ff2f3a3fa4a85a1687cc27d090e48

src/manager/common/certificate-impl.cpp
src/manager/common/certificate-store.cpp
src/manager/service/ckm-logic.cpp
src/manager/service/ckm-service.cpp

index 0be48eb..56362d3 100644 (file)
@@ -35,6 +35,8 @@ CertificateImpl::CertificateImpl(const RawBuffer &der, DataFormat format)
     const unsigned char *ptr;
     RawBuffer tmp;
 
+    LogDebug("Certificate to parse. Size: " << der.size());
+
     if (DataFormat::FORM_DER_BASE64 == format) {
         Base64Decoder base64;
         base64.reset();
@@ -52,6 +54,7 @@ CertificateImpl::CertificateImpl(const RawBuffer &der, DataFormat format)
         BIO *buff = BIO_new(BIO_s_mem());
         BIO_write(buff, der.data(), der.size());
         m_x509 = PEM_read_bio_X509(buff, NULL, NULL, NULL);
+        BIO_free_all(buff);
     } else {
         // TODO
         LogError("Unknown certificate format");
@@ -59,7 +62,7 @@ CertificateImpl::CertificateImpl(const RawBuffer &der, DataFormat format)
 
     if (!m_x509) {
         // TODO
-        LogError("Error in parsing certificate.");
+        LogError("Certificate could not be parsed.");
 //        ThrowMsg(Exception::OpensslInternalError,
 //          "Internal Openssl error in d2i_X509 function.");
     }
@@ -76,6 +79,7 @@ CertificateImpl::CertificateImpl(const CertificateImpl &second){
 CertificateImpl::CertificateImpl(CertificateImpl &&second) {
     m_x509 = second.m_x509;
     second.m_x509 = NULL;
+    LogDebug("Certificate moved: " << (void*)m_x509);
 }
 
 CertificateImpl& CertificateImpl::operator=(CertificateImpl &&second) {
@@ -84,6 +88,7 @@ CertificateImpl& CertificateImpl::operator=(CertificateImpl &&second) {
     X509_free(m_x509);
     m_x509 = second.m_x509;
     second.m_x509 = NULL;
+    LogDebug("Certificate moved: " << (void*)m_x509);
     return *this;
 }
 
@@ -104,7 +109,7 @@ RawBuffer CertificateImpl::getDER(void) const {
     int size = i2d_X509(m_x509, &rawDer);
     if (!rawDer || size <= 0) {
         // TODO
-//        LogError("i2d_X509 failed");
+        LogError("i2d_X509 failed");
 //        ThrowMsg(Exception::OpensslInternalError,
 //          "i2d_X509 failed");
     }
index f2783da..e0b02a6 100644 (file)
@@ -79,10 +79,13 @@ int CertificateStore::verifyCertificate(
 {
     STACK_OF(X509) *untrusted = NULL;
 
+    LogDebug("Verfication with " << chainVector.size() << " untrusted certificates");
+
     if (!untrustedVector.empty()) {
         untrusted = sk_X509_new_null();
-        for (auto &e : untrustedVector)
+        for (auto &e : untrustedVector) {
             sk_X509_push(untrusted, e.getX509());
+        }
     }
 
     X509_STORE_CTX *csc = X509_STORE_CTX_new();
@@ -91,6 +94,8 @@ int CertificateStore::verifyCertificate(
         return CKM_API_ERROR_UNKNOWN;
     }
 
+    LogDebug("Certificate for verfication ptr: " << (void*)cert.getX509());
+
     if (0 == X509_STORE_CTX_init(csc, m_store, cert.getX509(), untrusted)) {
         LogError("failed to X509_STORE_CTX_init");
         return CKM_API_ERROR_UNKNOWN;
@@ -98,7 +103,7 @@ int CertificateStore::verifyCertificate(
 
     int result = X509_verify_cert(csc); // 1 == ok; 0 == fail; -1 == error
 
-    LogDebug("Verification result: " << result);
+    LogDebug("Openssl verification result: " << result);
 
     if (result > 0) {
         STACK_OF(X509) *chain = X509_STORE_CTX_get_chain(csc);
index 48fbd17..bddd5fa 100644 (file)
@@ -292,8 +292,6 @@ int CKMLogic::getDataHelper(
     }
     handler.crypto.decryptRow(password, row);
 
-    LogError("Datatype: " << (int) row.dataType);
-
     return CKM_API_SUCCESS;
 }
 
@@ -325,8 +323,6 @@ RawBuffer CKMLogic::getData(
         row.dataType = dataType;
     }
 
-    LogError("Sending dataType: " << (int)row.dataType);
-
     MessageBuffer response;
     Serialization::Serialize(response, static_cast<int>(LogicCommand::GET));
     Serialization::Serialize(response, commandId);
@@ -555,6 +551,8 @@ RawBuffer CKMLogic::getCertificateChain(
     for (auto &e: untrustedRawCertVector)
         untrustedCertVector.push_back(CertificateImpl(e, DataFormat::FORM_DER));
 
+    LogDebug("Cert is empty: " << cert.empty());
+
     int retCode = m_certStore.verifyCertificate(cert, untrustedCertVector, chainVector);
 
     if (retCode == CKM_API_SUCCESS) {
index 167ed08..a9798cb 100644 (file)
@@ -112,6 +112,8 @@ RawBuffer CKMService::processControl(MessageBuffer &buffer) {
     Deserialization::Deserialize(buffer, command);
     Deserialization::Deserialize(buffer, user);
 
+    LogDebug("Process control. Command: " << command);
+
     cc = static_cast<ControlCommand>(command);
 
     switch(cc) {
@@ -145,6 +147,8 @@ RawBuffer CKMService::processStorage(Credentials &cred, MessageBuffer &buffer){
     Deserialization::Deserialize(buffer, command);
     Deserialization::Deserialize(buffer, commandId);
 
+    LogDebug("Process storage. Command: " << command);
+
     switch(static_cast<LogicCommand>(command)) {
         case LogicCommand::SAVE:
         {