Add initial values support - values to feed the shared database on first startup. 99/39299/11
authorMaciej J. Karpiuk <m.karpiuk2@samsung.com>
Fri, 8 May 2015 12:00:24 +0000 (14:00 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 22 May 2015 10:06:47 +0000 (03:06 -0700)
Change-Id: Iec81d8aa168dd30072aae86827124744798ef33d

29 files changed:
doc/example.xml
packaging/key-manager.spec
src/CMakeLists.txt
src/manager/initial-values/BufferHandler.cpp [new file with mode: 0644]
src/manager/initial-values/BufferHandler.h [new file with mode: 0644]
src/manager/initial-values/CertHandler.cpp [new file with mode: 0644]
src/manager/initial-values/CertHandler.h [new file with mode: 0644]
src/manager/initial-values/DataHandler.cpp [new file with mode: 0644]
src/manager/initial-values/DataHandler.h [new file with mode: 0644]
src/manager/initial-values/EncodingType.h [new file with mode: 0644]
src/manager/initial-values/InitialValueHandler.cpp [new file with mode: 0644]
src/manager/initial-values/InitialValueHandler.h [new file with mode: 0644]
src/manager/initial-values/InitialValuesFile.cpp [new file with mode: 0644]
src/manager/initial-values/InitialValuesFile.h [new file with mode: 0644]
src/manager/initial-values/KeyHandler.cpp [new file with mode: 0644]
src/manager/initial-values/KeyHandler.h [new file with mode: 0644]
src/manager/initial-values/PermissionHandler.cpp [new file with mode: 0644]
src/manager/initial-values/PermissionHandler.h [new file with mode: 0644]
src/manager/initial-values/parser.cpp
src/manager/initial-values/parser.h
src/manager/initial-values/xml-utils.cpp [new file with mode: 0644]
src/manager/initial-values/xml-utils.h [new file with mode: 0644]
src/manager/service/ckm-logic.cpp
src/manager/service/ckm-logic.h
tests/CMakeLists.txt
tests/XML_1_okay.xml
tests/XML_1_wrong.xml
tests/XML_2_structure.xml
tests/test_xml-parser.cpp

index 67b73f9..c5d2874 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<InitialValues version="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="initial_values.xsd ">
-  <Key name="key1" type="RSA_PRV" password="123">
+<InitialValues version="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="initial_values.xsd ">
+  <Key name="key1" type="RSA_PUB" password="123">
     <PEM>
       -----BEGIN PUBLIC KEY-----
       MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2b1bXDa+S8/MGWnMkru4
       zQIDAQAB
       -----END PUBLIC KEY-----
     </PEM>
+    <Permission accessor="web_app1"/>
+    <Permission accessor="web_app2"/>
+  </Key>
+  <Key name="key2" type="RSA_PRV" exportable="true">
+    <DER>
+      MIIEpAIBAAKCAQEAyJjUHY2pJJUBRBCrlerrgcS7aBiWlY3594dufu3m4qy48b9hsw1R/AHSNUPU
+      11vzQ+kUcXkEZOby5SHRHBAXIJ1dLbTPtRwsVwgf1nmc/ZGGV/XOrOaKi7nSKgYHaglPgc9dLPuu
+      osRHs/EdIWh3o59MdY6rA6y+QTJrQm3axRKdT7unX3kFS3SsId02GWBkLtrw+yQVtvhCYlY/n2/T
+      uZBJpZN7vT2it0rJS4fQkfjcjAi8f/isZLrfUgDqxIDSWVbVyjlQOphIO+K3ABjev3ZbJMWl+w10
+      pV0nbmF8lviEYft9mhERS9kUdQwzy3KIgyjyt+ewQG6hjyMJ/5y5KwIDAQABAoIBAQC3S06nIoZn
+      su/RLhpbhqljjkxgNfeC+JRsJghFW0UZ4xGrdGDlp0o+p7tYiH63uoFykEvp09a8DHvt+xSEO/+m
+      AaTe2tTgfLnXXMkaxU06Nfs37JfJTW9TdZwgYhnsPk20I7LUI7XTbN7IAY3ItRh9HlZTJOYHGZVP
+      Ja70qES6xUOTaVOvKIbB2W9XeiMX6cNoHTLM9rl1I8bA13Er0M0acKRtF4Rfw4z43nJKzORCYKm3
+      mA3zqtQja7z+zdQBib34RHZiKgvuJDqg89p7FTLT9z+lbXONH+K/3MldaYG1O8mtgt4zv6onH199
+      QBOrww158Z6keH3tBz+xsrClfIpBAoGBAPkar4ugZYLRgyuythby3uHrlMBNajmJf2gFwngvfUgO
+      JS45fLN2AIDrA5VYUiT8cFjVFfzEiu1xa33Juy8rfHlQuY8yOIVDnbdGJvOBYsrvlyYWY+9jEydd
+      cLctQKquACLb3jNYbrC9m8cBBcSZelRAVSF4O1k8HdlcdV7IIVyjAoGBAM4mY5PNLr3I/pyyNizw
+      7cUmHdblU+sScwFdC/KDwfG5WOI3WorTLutD4EiEA3yQIDStuVJLiray4Pu+bqhUPAJumpRrpQJ4
+      PCPxr/M98FhXvMmDWzGu/xK/6hLP5g1Ngp6qvVygnYNBkyqMzfM0rUAxQLS3qmocWk2xBKDEnjHZ
+      AoGBAJkWgVO52yiuQYKVbbpkv/zvnpcf/GwnyBjRkVXzOXcS2l6yDaTsnBqeU7FweespCJJPQhf5
+      YbfSwFCprVOr0e9sYN1T69BaYY7EmiOEHIbC/4z0ra3soVTL4/1u3hMGpCbIIKJFcqFDpXyDcFwG
+      RluIvci37yFEBMQUQj1hmL8pAoGAJBHtfG/7TLO9cRdxiT2CrOs1b2Ni4o+w1b09GOra5XujxLkg
+      u4el/v46YRXQMlxZdj4rXe3f0IXN/d5dKFDMyzQlEfEfxyXYiAWC3tGomxyG6M92BmRzNwmjYDVG
+      MG+ueiqvxWRJCy1PHbPTWUmPQtsbUkOMqtJZLpzZjXO5pkkCgYA9uyQ8os9yfjALc1VDZ4HtGxaC
+      Uq8zy0jJEJxchRn1JUNHop/skaRA65x613lWDygfNCuakozjP5x+GA5WEIuxIE8V7JPac1zpEZW4
+      5nwmxoR1l3HUDT8kRYkLzMIo55PpLG9arNLwH9mSRh/taG8020aGg3nFSNCJNDs12x/9RA==
+    </DER>
   </Key>
   <Cert exportable="true" name="cert1">
     <DER>
-      MIIEgDCCA2igAwIBAgIIcjtBYJGQtOAwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE
-      BhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMxJTAjBgNVBAMTHEdvb2dsZSBJbnRl
-      cm5ldCBBdXRob3JpdHkgRzIwHhcNMTQwNTIyMTEyOTQyWhcNMTQwODIwMDAwMDAw
-      WjBtMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwN
-      TW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzEcMBoGA1UEAwwTYWNj
-      rHva8A==
+      MIIDnzCCAoegAwIBAgIJAMH/ADkC5YSTMA0GCSqGSIb3DQEBBQUAMGYxCzAJBgNVBAYTAkFVMRMw
+      EQYDVQQIDApTb21lLVN0YXRlMQ0wCwYDVQQKDARBQ01FMRAwDgYDVQQLDAdUZXN0aW5nMSEwHwYD
+      VQQDDBhUZXN0IHJvb3QgY2EgY2VydGlmaWNhdGUwHhcNMTQxMjMwMTcyMTUyWhcNMjQxMjI3MTcy
+      MTUyWjBmMQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTENMAsGA1UECgwEQUNNRTEQ
+      MA4GA1UECwwHVGVzdGluZzEhMB8GA1UEAwwYVGVzdCByb290IGNhIGNlcnRpZmljYXRlMIIBIjAN
+      BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0EJRdUtd2th0vTVF7QxvDKzyFCF3w9vC9IDE/Yr1
+      2w+a9jd0s7/eG96qTHIYffS3B7x2MB+d4n+SR3W0qmYh7xk8qfEgH3daeDoV59IZ9r543KM+g8jm
+      6KffYGX1bIJVVY5OhBRbO9nY6byYpd5kbCIUB6dCf7/WrQl1aIdLGFIegAzPGFPXDcU6F192686x
+      54bxt/itMX4agHJ9ZC/rrTBIZghVsjJo5/AH5WZpasv8sfrGiiohAxtieoYoJkv5MOYP4/2lPlOY
+      +Cgw1Yoz+HHv31AllgFsBquBb/kJVmCCNsAOcnvQzTZUsW/TXz9G2nwRdqI1nSy2JvVjZGsqGQID
+      AQABo1AwTjAdBgNVHQ4EFgQUt6pkzFt1PZlfYRL/HGnufF4frdwwHwYDVR0jBBgwFoAUt6pkzFt1
+      PZlfYRL/HGnufF4frdwwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAQEAld7Qwq0cdzDQ
+      51w1RVLwTR8Oy25PB3rzwEHcSGJmdqlMi3xOdaz80S1R1BBXldvGBG5Tn0vT7xSuhmSgI2/HnBpy
+      9ocHVOmhtNB4473NieEpfTYrnGXrFxu46Wus9m/ZnugcQ2G6C54A/NFtvgLmaC8uH8M7gKdS6uYU
+      wJFQEofkjmd4UpOYSqmcRXhSJzd5FYFWkJhKJYp3nlENSOD8CUFFVGekm05nFN2gRVc/qaqQkEX7
+      7+XYvhodLRsVqMn7nf7taidDKLO2T4bhujztnTYOhhaXKgPy7AtZ28N2wvX96VyAPB/vrchGmyBK
+      kOg11TpPdNDkhb1J4ZCh2gupDg==
     </DER>
   </Cert>
   <Data name="data1">
@@ -33,4 +71,4 @@
     <Permission accessor="web_app1"/>
     <Permission accessor="web_app2"/>
   </Key>
-</InitialValues>
\ No newline at end of file
+</InitialValues>
index 7855988..f5b8cc6 100644 (file)
@@ -128,6 +128,8 @@ mkdir -p %{buildroot}/usr/share/license
 cp LICENSE %{buildroot}/usr/share/license/%{name}
 cp LICENSE %{buildroot}/usr/share/license/libkey-manager-client
 cp LICENSE %{buildroot}/usr/share/license/libkey-manager-control-client
+mkdir -p %{buildroot}/opt/data/ckm/initial_values
+cp doc/initial_values.xsd %{buildroot}/opt/data/ckm/initial_values
 mkdir -p %{buildroot}/etc/security/
 mkdir -p %{buildroot}/usr/share/ckm/scripts
 cp data/scripts/*.sql %{buildroot}/usr/share/ckm/scripts
@@ -222,6 +224,8 @@ fi
 %{_unitdir}/central-key-manager-api-ocsp.socket
 %{_datadir}/license/%{name}
 %{_datadir}/ckm/scripts/*.sql
+/opt/data/ckm/initial_values/initial_values.xsd
+%{_datadir}/
 %attr(444, root, root) %{_datadir}/ckm/scripts/*.sql
 /etc/opt/upgrade/230.key-manager-migrate-dkek.patch.sh
 /etc/gumd/userdel.d/10_key-manager.post
index ce6680a..b245860 100644 (file)
@@ -35,6 +35,14 @@ SET(KEY_MANAGER_SOURCES
     ${KEY_MANAGER_PATH}/service/ocsp-service.cpp
     ${KEY_MANAGER_PATH}/service/ocsp-logic.cpp
     ${KEY_MANAGER_PATH}/initial-values/parser.cpp
+    ${KEY_MANAGER_PATH}/initial-values/BufferHandler.cpp
+    ${KEY_MANAGER_PATH}/initial-values/CertHandler.cpp
+    ${KEY_MANAGER_PATH}/initial-values/DataHandler.cpp
+    ${KEY_MANAGER_PATH}/initial-values/KeyHandler.cpp
+    ${KEY_MANAGER_PATH}/initial-values/PermissionHandler.cpp
+    ${KEY_MANAGER_PATH}/initial-values/InitialValueHandler.cpp
+    ${KEY_MANAGER_PATH}/initial-values/InitialValuesFile.cpp
+    ${KEY_MANAGER_PATH}/initial-values/xml-utils.cpp
     ${KEY_MANAGER_PATH}/dpl/core/src/assert.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/sql_connection.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/naive_synchronization_object.cpp
diff --git a/src/manager/initial-values/BufferHandler.cpp b/src/manager/initial-values/BufferHandler.cpp
new file mode 100644 (file)
index 0000000..1ce108c
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        BufferHandler.cpp
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       BufferHandler class implementation.
+ */
+
+#include <string>
+#include <algorithm>
+#include <cctype>
+#include <BufferHandler.h>
+#include <xml-utils.h>
+#include <base64.h>
+
+namespace CKM {
+namespace InitialValues {
+
+BufferHandler::BufferHandler(EncodingType type) : m_encoding(type) {}
+BufferHandler::~BufferHandler() {}
+
+void BufferHandler::Start(const XML::Parser::Attributes &)
+{
+}
+
+
+void BufferHandler::Characters(const std::string & data)
+{
+    m_data.reserve(m_data.size() + data.size());
+    m_data.insert(m_data.end(), data.begin(), data.end());
+}
+
+void BufferHandler::End()
+{
+    switch(m_encoding)
+    {
+        // PEM requires that "----- END" section comes right after "\n" character
+        case PEM:
+        {
+            std::string trimmed = XML::trimEachLine(std::string(m_data.begin(), m_data.end()));
+            m_data = RawBuffer(trimmed.begin(), trimmed.end());
+            break;
+        }
+
+        // Base64 decoder also does not accept any whitespaces
+        case DER:
+        case BASE64:
+        {
+            std::string trimmed = XML::trimEachLine(std::string(m_data.begin(), m_data.end()));
+            Base64Decoder base64;
+            base64.reset();
+            base64.append(RawBuffer(trimmed.begin(), trimmed.end()));
+            base64.finalize();
+            m_data = base64.get();
+            break;
+        }
+
+        default:
+            break;
+    }
+}
+
+}
+}
diff --git a/src/manager/initial-values/BufferHandler.h b/src/manager/initial-values/BufferHandler.h
new file mode 100644 (file)
index 0000000..4961bd0
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        BufferHandler.h
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       BufferHandler class.
+ */
+
+#ifndef BUFFERHANDLER_H_
+#define BUFFERHANDLER_H_
+
+#include <parser.h>
+#include <EncodingType.h>
+#include <ckm/ckm-type.h>
+
+namespace CKM {
+namespace InitialValues {
+
+class BufferHandler : public XML::Parser::ElementHandler
+{
+public:
+    typedef std::shared_ptr<BufferHandler> BufferHandlerPtr;
+
+    BufferHandler(EncodingType type);
+    virtual ~BufferHandler();
+
+    virtual void Start(const XML::Parser::Attributes &);
+    virtual void Characters(const std::string & data);
+    virtual void End();
+
+    const RawBuffer & getData() const {
+        return m_data;
+    }
+private:
+    EncodingType    m_encoding;
+    RawBuffer  m_data;
+};
+
+}
+}
+#endif /* BUFFERHANDLER_H_ */
diff --git a/src/manager/initial-values/CertHandler.cpp b/src/manager/initial-values/CertHandler.cpp
new file mode 100644 (file)
index 0000000..e7d3712
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        CertHandler.cpp
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       CertHandler class implementation.
+ */
+
+#include <parser.h>
+#include <CertHandler.h>
+#include <InitialValueHandler.h>
+
+namespace CKM {
+namespace InitialValues {
+
+CertHandler::~CertHandler() {}
+
+DataType CertHandler::getDataType() const
+{
+    return DataType::CERTIFICATE;
+}
+
+}
+}
diff --git a/src/manager/initial-values/CertHandler.h b/src/manager/initial-values/CertHandler.h
new file mode 100644 (file)
index 0000000..4050411
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        CertHandler.h
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       CertHandler class.
+ */
+
+#ifndef CERTHANDLER_H_
+#define CERTHANDLER_H_
+
+#include <parser.h>
+#include <InitialValueHandler.h>
+
+namespace CKM {
+namespace InitialValues {
+
+class CertHandler : public InitialValueHandler
+{
+public:
+    explicit CertHandler(CKMLogic & db_logic) : InitialValueHandler(db_logic) {}
+    virtual ~CertHandler();
+
+    virtual DataType getDataType() const;
+};
+
+}
+}
+#endif /* CERTHANDLER_H_ */
diff --git a/src/manager/initial-values/DataHandler.cpp b/src/manager/initial-values/DataHandler.cpp
new file mode 100644 (file)
index 0000000..b4d5945
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        DataHandler.cpp
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       DataHandler class implementation.
+ */
+
+#include <parser.h>
+#include <DataHandler.h>
+#include <InitialValueHandler.h>
+
+namespace CKM {
+namespace InitialValues {
+
+DataHandler::~DataHandler() {}
+
+DataType DataHandler::getDataType() const
+{
+    return DataType::BINARY_DATA;
+}
+
+}
+}
diff --git a/src/manager/initial-values/DataHandler.h b/src/manager/initial-values/DataHandler.h
new file mode 100644 (file)
index 0000000..1ccc4e8
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        DataHandler.h
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       DataHandler class.
+ */
+
+#ifndef DATAHANDLER_H_
+#define DATAHANDLER_H_
+
+#include <parser.h>
+#include <InitialValueHandler.h>
+
+namespace CKM {
+namespace InitialValues {
+
+class DataHandler : public InitialValueHandler
+{
+public:
+    explicit DataHandler(CKMLogic & db_logic) : InitialValueHandler(db_logic) {}
+    virtual ~DataHandler();
+
+    virtual DataType getDataType() const;
+};
+
+}
+}
+#endif /* DATAHANDLER_H_ */
diff --git a/src/manager/initial-values/EncodingType.h b/src/manager/initial-values/EncodingType.h
new file mode 100644 (file)
index 0000000..b7f513d
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        EncodingType.h
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       Encoding type constants.
+ */
+
+#ifndef ENCODINGTYPE_H_
+#define ENCODINGTYPE_H_
+
+namespace CKM {
+namespace InitialValues {
+
+enum EncodingType {
+    PEM,
+    DER,
+    ASCII,
+    BASE64
+};
+
+}
+}
+#endif /* ENCODINGTYPE_H_ */
diff --git a/src/manager/initial-values/InitialValueHandler.cpp b/src/manager/initial-values/InitialValueHandler.cpp
new file mode 100644 (file)
index 0000000..b811aa7
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        InitialValueHandler.cpp
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       InitialValueHandler class implementation.
+ */
+
+#include <sstream>
+#include <algorithm>
+#include <memory>
+#include <exception>
+#include <InitialValueHandler.h>
+#include <EncodingType.h>
+#include <ckm/ckm-type.h>
+
+namespace
+{
+const char * const XML_ATTR_NAME        = "name";
+const char * const XML_ATTR_PASSWORD    = "password";
+const char * const XML_ATTR_EXPORTABLE  = "exportable";
+}
+
+namespace CKM {
+namespace InitialValues {
+
+void InitialValueHandler::Start(const XML::Parser::Attributes &attr)
+{
+    // get name
+    if(attr.find(XML_ATTR_NAME) != attr.end())
+        m_name = Alias(attr.at(XML_ATTR_NAME));
+
+    // get password
+    if(attr.find(XML_ATTR_PASSWORD) != attr.end())
+        m_password = Password(attr.at(XML_ATTR_PASSWORD).c_str());
+
+    // get exportable
+    if(attr.find(XML_ATTR_EXPORTABLE) != attr.end())
+    {
+        std::string flagVal = attr.at(XML_ATTR_EXPORTABLE);
+        std::transform(flagVal.begin(), flagVal.end(), flagVal.begin(), ::tolower);
+        std::istringstream is(flagVal);
+        is >> std::boolalpha >> m_exportable;
+    }
+}
+
+void InitialValueHandler::Characters(const std::string &)
+{
+    throw std::runtime_error("error: value handler detected raw data outside data-specific tag");
+}
+
+void InitialValueHandler::End()
+{
+    if(m_bufferHandler)
+    {
+        // save data
+        Policy policy(m_password, m_exportable);
+        int ec = m_db_logic.verifyAndSaveDataHelper(
+                Credentials(CKMLogic::SYSTEM_DB_UID, LABEL_SYSTEM_DB),
+                m_name,
+                LABEL_SYSTEM_DB,
+                m_bufferHandler->getData(),
+                getDataType(),
+                PolicySerializable(policy));
+        if(CKM_API_SUCCESS == ec)
+        {
+            // save permissions
+            for(const auto & permission : m_permissions)
+            {
+                ec = m_db_logic.setPermissionHelper(
+                        Credentials(CKMLogic::SYSTEM_DB_UID, LABEL_SYSTEM_DB),
+                        m_name,
+                        LABEL_SYSTEM_DB,
+                        permission->getAccessor(),
+                        Permission::READ);
+                if(CKM_API_SUCCESS != ec)
+                    LogError("Saving permission to: " << m_name << " with params: accessor("<<permission->getAccessor()<<") failed, code: " << ec);
+            }
+        }
+        else
+            LogError("Saving type: " << getDataType() << " with params: name("<<m_name<<"), exportable("<<m_exportable<<") failed, code: " << ec);
+    }
+    else
+        LogError("Invalid data with name: " << m_name << ", reason: no key data!");
+}
+
+BufferHandler::BufferHandlerPtr InitialValueHandler::CreateBufferHandler(EncodingType type)
+{
+    m_bufferHandler = std::make_shared<BufferHandler>(type);
+    return m_bufferHandler;
+}
+
+PermissionHandler::PermissionHandlerPtr InitialValueHandler::CreatePermissionHandler()
+{
+    PermissionHandler::PermissionHandlerPtr newPermission = std::make_shared<PermissionHandler>();
+    m_permissions.push_back(newPermission);
+    return newPermission;
+}
+
+}
+}
diff --git a/src/manager/initial-values/InitialValueHandler.h b/src/manager/initial-values/InitialValueHandler.h
new file mode 100644 (file)
index 0000000..7d23fa9
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        InitialValueHandler.h
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       InitialValueHandler class.
+ */
+
+#ifndef INITIALVALUEHANDLER_H_
+#define INITIALVALUEHANDLER_H_
+
+#include <parser.h>
+#include <BufferHandler.h>
+#include <PermissionHandler.h>
+#include <EncodingType.h>
+#include <ckm/ckm-type.h>
+#include <ckm-logic.h>
+#include <protocols.h>
+
+namespace CKM {
+namespace InitialValues {
+
+class InitialValueHandler : public XML::Parser::ElementHandler
+{
+public:
+    typedef std::shared_ptr<InitialValueHandler> InitialValueHandlerPtr;
+
+    explicit InitialValueHandler(CKMLogic & db_logic) : m_exportable(false),
+                                                        m_db_logic(db_logic) {}
+    virtual ~InitialValueHandler() {};
+
+    BufferHandler::BufferHandlerPtr CreateBufferHandler(EncodingType type);
+    PermissionHandler::PermissionHandlerPtr CreatePermissionHandler();
+    virtual void Start(const XML::Parser::Attributes &);
+    virtual void Characters(const std::string & data);
+    virtual void End();
+
+protected:
+    virtual DataType getDataType() const = 0;
+
+    Alias      m_name;
+    Password   m_password;
+    bool       m_exportable;
+    CKMLogic & m_db_logic;
+
+    BufferHandler::BufferHandlerPtr m_bufferHandler;
+    std::vector<PermissionHandler::PermissionHandlerPtr> m_permissions;
+};
+
+}
+}
+#endif /* INITIALVALUEHANDLER_H_ */
diff --git a/src/manager/initial-values/InitialValuesFile.cpp b/src/manager/initial-values/InitialValuesFile.cpp
new file mode 100644 (file)
index 0000000..bc5fbec
--- /dev/null
@@ -0,0 +1,247 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        InitialValuesFile.cpp
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       InitialValuesFile class implementation.
+ */
+
+#include <iostream>
+#include <InitialValuesFile.h>
+#include <InitialValueHandler.h>
+#include <BufferHandler.h>
+#include <EncodingType.h>
+#include <KeyHandler.h>
+#include <CertHandler.h>
+#include <DataHandler.h>
+#include <EncodingType.h>
+#include <dpl/log/log.h>
+
+namespace {
+const int          XML_CURRENT_VERSION      = 1;
+const char * const XML_TAG_INITIAL_VALUES   = "InitialValues";
+const char * const XML_TAG_KEY              = "Key";
+const char * const XML_TAG_DATA             = "Data";
+const char * const XML_TAG_CERT             = "Cert";
+const char * const XML_TAG_PEM              = "PEM";
+const char * const XML_TAG_DER              = "DER";
+const char * const XML_TAG_ASCII            = "ASCII";
+const char * const XML_TAG_BASE64           = "Base64";
+const char * const XML_TAG_PERMISSION       = "Permission";
+const char * const XML_ATTR_VERSION         = "version";
+}
+
+namespace CKM {
+namespace InitialValues {
+
+InitialValuesFile::InitialValuesFile(const std::string &XML_filename, CKMLogic & db_logic)
+        : m_parser(XML_filename), m_db_logic(db_logic),
+          m_header(std::make_shared<HeaderHandler>(*this))
+{
+    m_parser.RegisterErrorCb(InitialValuesFile::Error);
+    m_parser.RegisterElementCb(XML_TAG_INITIAL_VALUES,
+            [this]() -> XML::Parser::ElementHandlerPtr
+            {
+                return m_header;
+            },
+            [this](const XML::Parser::ElementHandlerPtr &) {});
+}
+
+void InitialValuesFile::registerElementListeners()
+{
+    m_parser.RegisterElementCb(XML_TAG_KEY,
+            [this]() -> XML::Parser::ElementHandlerPtr
+            {
+                return GetObjectHandler(ObjectType::KEY);
+            },
+            [this](const XML::Parser::ElementHandlerPtr &)
+            {
+                ReleaseObjectHandler(ObjectType::KEY);
+            });
+    m_parser.RegisterElementCb(XML_TAG_CERT,
+            [this]() -> XML::Parser::ElementHandlerPtr
+            {
+                return GetObjectHandler(ObjectType::CERT);
+            },
+            [this](const XML::Parser::ElementHandlerPtr &)
+            {
+                ReleaseObjectHandler(ObjectType::CERT);
+            });
+    m_parser.RegisterElementCb(XML_TAG_DATA,
+            [this]() -> XML::Parser::ElementHandlerPtr
+            {
+                return GetObjectHandler(ObjectType::DATA);
+            },
+            [this](const XML::Parser::ElementHandlerPtr &)
+            {
+                ReleaseObjectHandler(ObjectType::DATA);
+            });
+
+    m_parser.RegisterElementCb(XML_TAG_PEM,
+            [this]() -> XML::Parser::ElementHandlerPtr
+            {
+                return GetBufferHandler(EncodingType::PEM);
+            },
+            [this](const XML::Parser::ElementHandlerPtr &)
+            {
+                ReleaseBufferHandler(EncodingType::PEM);
+            });
+    m_parser.RegisterElementCb(XML_TAG_DER,
+            [this]() -> XML::Parser::ElementHandlerPtr
+            {
+                return GetBufferHandler(EncodingType::DER);
+            },
+            [this](const XML::Parser::ElementHandlerPtr &)
+            {
+                ReleaseBufferHandler(EncodingType::DER);
+            });
+    m_parser.RegisterElementCb(XML_TAG_ASCII,
+            [this]() -> XML::Parser::ElementHandlerPtr
+            {
+                return GetBufferHandler(EncodingType::ASCII);
+            },
+            [this](const XML::Parser::ElementHandlerPtr &)
+            {
+                ReleaseBufferHandler(EncodingType::ASCII);
+            });
+    m_parser.RegisterElementCb(XML_TAG_BASE64,
+            [this]() -> XML::Parser::ElementHandlerPtr
+            {
+                return GetBufferHandler(EncodingType::BASE64);
+            },
+            [this](const XML::Parser::ElementHandlerPtr &)
+            {
+                ReleaseBufferHandler(EncodingType::BASE64);
+            });
+    m_parser.RegisterElementCb(XML_TAG_PERMISSION,
+            [this]() -> XML::Parser::ElementHandlerPtr
+            {
+                return GetPermissionHandler();
+            },
+            [this](const XML::Parser::ElementHandlerPtr &)
+            {
+                ReleasePermissionHandler();
+            });
+}
+
+void InitialValuesFile::Error(const XML::Parser::ErrorType errorType,
+                              const std::string & log_msg)
+{
+    switch(errorType)
+    {
+        case XML::Parser::VALIDATION_ERROR:
+            LogWarning("validating error: " << log_msg);
+            break;
+        case XML::Parser::PARSE_WARNING:
+            LogWarning("parsing warning: " << log_msg);
+            break;
+        case XML::Parser::PARSE_ERROR:
+            LogWarning("parsing error: " << log_msg);
+            break;
+    }
+}
+
+int InitialValuesFile::Validate(const std::string &XSD_file)
+{
+    return m_parser.Validate(XSD_file);
+}
+
+int InitialValuesFile::Parse()
+{
+    int ec = m_parser.Parse();
+    if(!m_header || !m_header->isCorrectVersion()) {
+        LogError("bypassing XML file: " << m_filename << " - wrong file version!");
+        ec = XML::Parser::ERROR_INVALID_VERSION;
+    }
+    return ec;
+}
+
+XML::Parser::ElementHandlerPtr InitialValuesFile::GetObjectHandler(ObjectType type)
+{
+    switch(type)
+    {
+        case KEY:
+            m_currentHandler = std::make_shared<KeyHandler>(m_db_logic);
+            break;
+
+        case CERT:
+            m_currentHandler = std::make_shared<CertHandler>(m_db_logic);
+            break;
+
+        case DATA:
+            m_currentHandler = std::make_shared<DataHandler>(m_db_logic);
+            break;
+
+        default:
+            m_currentHandler.reset();
+            break;
+    }
+
+    return m_currentHandler;
+}
+
+void InitialValuesFile::ReleaseObjectHandler(ObjectType /*type*/)
+{
+    m_currentHandler.reset();
+}
+
+
+
+
+XML::Parser::ElementHandlerPtr InitialValuesFile::GetBufferHandler(EncodingType type)
+{
+    if( !m_currentHandler )
+        return XML::Parser::ElementHandlerPtr();
+
+    return m_currentHandler->CreateBufferHandler(type);
+}
+void InitialValuesFile::ReleaseBufferHandler(EncodingType /*type*/)
+{
+}
+
+
+XML::Parser::ElementHandlerPtr InitialValuesFile::GetPermissionHandler()
+{
+    if( !m_currentHandler )
+        return XML::Parser::ElementHandlerPtr();
+
+    return m_currentHandler->CreatePermissionHandler();
+}
+void InitialValuesFile::ReleasePermissionHandler()
+{
+}
+
+
+InitialValuesFile::HeaderHandler::HeaderHandler(InitialValuesFile & parent)
+    : m_version(-1), m_parent(parent) {}
+void InitialValuesFile::HeaderHandler::Start(const XML::Parser::Attributes & attr)
+{
+    // get key type
+    if(attr.find(XML_ATTR_VERSION) != attr.end())
+    {
+        m_version = atoi(attr.at(XML_ATTR_VERSION).c_str());
+
+        if(isCorrectVersion())
+            m_parent.registerElementListeners();
+    }
+}
+bool InitialValuesFile::HeaderHandler::isCorrectVersion() const {
+    return m_version == XML_CURRENT_VERSION;
+}
+
+}
+}
diff --git a/src/manager/initial-values/InitialValuesFile.h b/src/manager/initial-values/InitialValuesFile.h
new file mode 100644 (file)
index 0000000..8226822
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        InitialValuesFile.h
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       InitialValuesFile class.
+ */
+
+#ifndef INITIALVALUESFILE_H_
+#define INITIALVALUESFILE_H_
+
+#include <parser.h>
+#include <InitialValueHandler.h>
+#include <ckm-logic.h>
+
+namespace CKM {
+namespace InitialValues {
+
+class InitialValuesFile
+{
+public:
+    InitialValuesFile(const std::string &XML_filename,
+                      CKMLogic & db_logic);
+
+    int Validate(const std::string &XSD_file);
+    int Parse();
+
+protected:
+    enum ObjectType {
+        KEY,
+        CERT,
+        DATA
+    };
+
+    XML::Parser::ElementHandlerPtr GetObjectHandler(ObjectType type);
+    void ReleaseObjectHandler(ObjectType type);
+
+    XML::Parser::ElementHandlerPtr GetBufferHandler(EncodingType type);
+    void ReleaseBufferHandler(EncodingType type);
+
+    XML::Parser::ElementHandlerPtr GetPermissionHandler();
+    void ReleasePermissionHandler();
+private:
+    std::string m_filename;
+    XML::Parser m_parser;
+    InitialValueHandler::InitialValueHandlerPtr m_currentHandler;
+    CKMLogic & m_db_logic;
+
+    class HeaderHandler : public XML::Parser::ElementHandler
+    {
+    public:
+        explicit HeaderHandler(InitialValuesFile & parent);
+        virtual void Start(const XML::Parser::Attributes & attr);
+        virtual void Characters(const std::string &) {};
+        virtual void End() {};
+
+        bool isCorrectVersion() const;
+
+    private:
+        int m_version;
+        InitialValuesFile & m_parent;
+    };
+    typedef std::shared_ptr<HeaderHandler> HeaderHandlerPtr;
+    HeaderHandlerPtr m_header;
+
+    void registerElementListeners();
+    static void Error(const XML::Parser::ErrorType errorType,
+                      const std::string & logMsg);
+
+};
+
+}
+}
+#endif /* INITIALVALUESFILE_H_ */
diff --git a/src/manager/initial-values/KeyHandler.cpp b/src/manager/initial-values/KeyHandler.cpp
new file mode 100644 (file)
index 0000000..5b2bb46
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        KeyHandler.cpp
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       KeyHandler class implementation.
+ */
+
+#include <string>
+#include <algorithm>
+#include <parser.h>
+#include <KeyHandler.h>
+#include <InitialValueHandler.h>
+#include <ckm/ckm-type.h>
+
+namespace
+{
+const char * const XML_ATTR_TYPE    = "type";
+const char * const XML_ATTR_TYPE_VAL_RSA_PRV    =   "RSA_PRV";
+const char * const XML_ATTR_TYPE_VAL_RSA_PUB    =   "RSA_PUB";
+const char * const XML_ATTR_TYPE_VAL_DSA_PRV    =   "DSA_PRV";
+const char * const XML_ATTR_TYPE_VAL_DSA_PUB    =   "DSA_PUB";
+const char * const XML_ATTR_TYPE_VAL_ECDSA_PRV  =   "ECDSA_PRV";
+const char * const XML_ATTR_TYPE_VAL_ECDSA_PUB  =   "ECDSA_PUB";
+const char * const XML_ATTR_TYPE_VAL_AES        =   "AES";
+}
+
+namespace CKM {
+namespace InitialValues {
+
+KeyHandler::~KeyHandler() {}
+
+void KeyHandler::Start(const XML::Parser::Attributes &attr)
+{
+    InitialValueHandler::Start(attr);
+
+    // get key type
+    if(attr.find(XML_ATTR_TYPE) != attr.end())
+        m_keyType = KeyHandler::parseType(attr.at(XML_ATTR_TYPE));
+}
+
+KeyType KeyHandler::parseType(const std::string & typeStr)
+{
+    if     (typeStr == XML_ATTR_TYPE_VAL_RSA_PRV)      return KeyType::KEY_RSA_PRIVATE;
+    else if(typeStr == XML_ATTR_TYPE_VAL_RSA_PUB)      return KeyType::KEY_RSA_PUBLIC;
+    else if(typeStr == XML_ATTR_TYPE_VAL_DSA_PRV)      return KeyType::KEY_DSA_PRIVATE;
+    else if(typeStr == XML_ATTR_TYPE_VAL_DSA_PUB)      return KeyType::KEY_DSA_PUBLIC;
+    else if(typeStr == XML_ATTR_TYPE_VAL_ECDSA_PRV)    return KeyType::KEY_ECDSA_PRIVATE;
+    else if(typeStr == XML_ATTR_TYPE_VAL_ECDSA_PUB)    return KeyType::KEY_ECDSA_PUBLIC;
+    else if(typeStr == XML_ATTR_TYPE_VAL_AES)          return KeyType::KEY_AES;
+    else // should not happen
+        throw std::runtime_error("error: invalid value discovered as key type");
+}
+
+DataType KeyHandler::getDataType() const
+{
+    return DataType(m_keyType);
+}
+
+}
+}
diff --git a/src/manager/initial-values/KeyHandler.h b/src/manager/initial-values/KeyHandler.h
new file mode 100644 (file)
index 0000000..c26e429
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        KeyHandler.h
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       KeyHandler class.
+ */
+
+#ifndef KEYHANDLER_H_
+#define KEYHANDLER_H_
+
+#include <parser.h>
+#include <InitialValueHandler.h>
+#include <ckm/ckm-type.h>
+
+namespace CKM {
+namespace InitialValues {
+
+class KeyHandler : public InitialValueHandler
+{
+public:
+    explicit KeyHandler(CKMLogic & db_logic) : InitialValueHandler(db_logic),
+                                               m_keyType(KeyType::KEY_NONE) {}
+    virtual ~KeyHandler();
+
+    virtual void Start(const XML::Parser::Attributes &);
+
+    virtual DataType getDataType() const;
+protected:
+    static KeyType parseType(const std::string & typeStr);
+
+    KeyType m_keyType;
+};
+
+}
+}
+#endif /* KEYHANDLER_H_ */
diff --git a/src/manager/initial-values/PermissionHandler.cpp b/src/manager/initial-values/PermissionHandler.cpp
new file mode 100644 (file)
index 0000000..ea97c6d
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        PermissionHandler.cpp
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       PermissionHandler class implementation.
+ */
+
+#include <ckm/ckm-type.h>
+#include <PermissionHandler.h>
+
+namespace
+{
+const char * const XML_ATTR_ACCESSOR    = "accessor";
+}
+
+namespace CKM {
+namespace InitialValues {
+
+PermissionHandler::~PermissionHandler() {}
+
+void PermissionHandler::Start(const XML::Parser::Attributes & attr)
+{
+    // get accessor label
+    if(attr.find(XML_ATTR_ACCESSOR) != attr.end())
+        m_accessor = Label(attr.at(XML_ATTR_ACCESSOR));
+}
+void PermissionHandler::Characters(const std::string &)
+{
+    throw std::runtime_error("error: value handler detected raw data while none allowed");
+}
+void PermissionHandler::End()
+{
+}
+
+}
+}
diff --git a/src/manager/initial-values/PermissionHandler.h b/src/manager/initial-values/PermissionHandler.h
new file mode 100644 (file)
index 0000000..7980ba8
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        PermissionHandler.h
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       PermissionHandler class.
+ */
+
+#ifndef PERMISSIONHANDLER_H_
+#define PERMISSIONHANDLER_H_
+
+#include <parser.h>
+#include <ckm/ckm-type.h>
+
+namespace CKM {
+namespace InitialValues {
+
+class PermissionHandler : public XML::Parser::ElementHandler
+{
+public:
+    typedef std::shared_ptr<PermissionHandler> PermissionHandlerPtr;
+
+    virtual ~PermissionHandler();
+
+    virtual void Start(const XML::Parser::Attributes &);
+    virtual void Characters(const std::string &);
+    virtual void End();
+
+    const Label & getAccessor() const {
+        return m_accessor;
+    }
+private:
+    Label   m_accessor;
+};
+
+}
+}
+#endif /* PERMISSIONHANDLER_H_ */
index 06f8143..4693728 100644 (file)
 #include <libxml/valid.h>
 #include <libxml/xmlschemas.h>
 #include <parser.h>
+#include <xml-utils.h>
 #include <dpl/log/log.h>
 
-using namespace XML;
+namespace CKM {
+namespace XML {
 
-namespace
-{
-const char * const WHITESPACE = " \n\r\t";
-std::string trim_left(const std::string& s)
-{
-    size_t startpos = s.find_first_not_of(WHITESPACE);
-    return (startpos == std::string::npos) ? "" : s.substr(startpos);
-}
-
-std::string trim_right(const std::string& s)
-{
-    size_t endpos = s.find_last_not_of(WHITESPACE);
-    return (endpos == std::string::npos) ? "" : s.substr(0, endpos+1);
-}
-std::string trim(const std::string& s)
-{
-    return trim_right(trim_left(s));
-}
-}
-
-Parser::Parser(const char *XML_filename)
+Parser::Parser(const std::string &XML_filename)
     : m_errorCb(0)
 {
-    if(XML_filename)
-        m_XMLfile = XML_filename;
+    m_XMLfile = XML_filename;
     memset(&m_saxHandler, 0, sizeof(m_saxHandler));
     m_saxHandler.startElement = &Parser::StartElement;
     m_saxHandler.endElement = &Parser::EndElement;
@@ -69,16 +50,16 @@ Parser::~Parser()
     xmlCleanupParser();
 }
 
-int Parser::Validate(const char *XSD_schema)
+int Parser::Validate(const std::string &XSD_schema)
 {
-    if(!XSD_schema) {
+    if(XSD_schema.empty()) {
         LogError("no XSD file path given");
         return ERROR_INVALID_ARGUMENT;
     }
 
     int retCode;
     std::unique_ptr<xmlSchemaParserCtxt, void(*)(xmlSchemaParserCtxtPtr)>
-            parserCtxt(xmlSchemaNewParserCtxt(XSD_schema),
+            parserCtxt(xmlSchemaNewParserCtxt(XSD_schema.c_str()),
                        [](xmlSchemaParserCtxtPtr ctx){ xmlSchemaFreeParserCtxt(ctx); });
     if(!parserCtxt) {
         LogError("XSD file path is invalid");
@@ -113,7 +94,7 @@ int Parser::Validate(const char *XSD_schema)
         retCode = ERROR_XML_VALIDATION_FAILED;
     }
     else
-        retCode = SUCCESS;
+        retCode = PARSE_SUCCESS;
 
     return retCode;
 }
@@ -134,7 +115,7 @@ int Parser::Parse()
         LogError("Critical error detected while parsing.");
         return ERROR_INTERNAL;
     }
-    return SUCCESS;
+    return PARSE_SUCCESS;
 }
 
 int Parser::RegisterErrorCb(const ErrorCb newCb)
@@ -144,7 +125,7 @@ int Parser::RegisterErrorCb(const ErrorCb newCb)
         return ERROR_CALLBACK_PRESENT;
     }
     m_errorCb = newCb;
-    return SUCCESS;
+    return PARSE_SUCCESS;
 }
 
 int Parser::RegisterElementCb(const char * elementName,
@@ -162,7 +143,7 @@ int Parser::RegisterElementCb(const char * elementName,
     }
 
     m_elementListenerMap[key] = {startCb, endCb};
-    return SUCCESS;
+    return PARSE_SUCCESS;
 }
 
 void Parser::StartElement(const xmlChar *name,
@@ -212,7 +193,7 @@ void Parser::EndElement(const xmlChar *name)
 
     ElementHandlerPtr &currentHandler = m_elementHandlerStack.top();
     if(currentHandler)
-        currentHandler.get()->End();
+        currentHandler->End();
 
     const ElementListener & current = m_elementListenerMap[key];
     if(current.endCb)
@@ -231,7 +212,7 @@ void Parser::Characters(const xmlChar *ch, size_t chLen)
     {
         ElementHandlerPtr &currentHandler = m_elementHandlerStack.top();
         if(currentHandler)
-            currentHandler.get()->Characters(chars);
+            currentHandler->Characters(chars);
     }
 }
 
@@ -336,3 +317,5 @@ void Parser::Warning(void *userData,
 //
 // -------------------------- end of static wrappers --------------------------
 //
+}
+}
index 01790e8..605ba49 100644 (file)
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 
-namespace XML
-{
+namespace CKM {
+namespace XML {
 
 class Parser
 {
 public:
     enum ErrorCode {
-        SUCCESS                        =   0,
+        PARSE_SUCCESS                  =   0,
         ERROR_UNKNOWN                  =   -1000,
         ERROR_XML_VALIDATION_FAILED    =   -1001,
         ERROR_XSD_PARSE_FAILED         =   -1002,
         ERROR_XML_PARSE_FAILED         =   -1003,
         ERROR_INVALID_ARGUMENT         =   -1004,
         ERROR_CALLBACK_PRESENT         =   -1005,
-        ERROR_INTERNAL                 =   -1006,
-        ERROR_NO_MEMORY                =   -1007
+        ERROR_INVALID_VERSION          =   -1006,
+        ERROR_INTERNAL                 =   -1007,
+        ERROR_NO_MEMORY                =   -1008
     };
 
-    explicit Parser(const char *XML_filename);
+    explicit Parser(const std::string &XML_filename);
     virtual ~Parser();
 
-    int Validate(const char *XSD_schema);
+    int Validate(const std::string &XSD_schema);
     int Parse();
 
     enum ErrorType {
@@ -128,4 +129,5 @@ private:
 };
 
 }
+}
 #endif /* XML_PARSER_H_ */
diff --git a/src/manager/initial-values/xml-utils.cpp b/src/manager/initial-values/xml-utils.cpp
new file mode 100644 (file)
index 0000000..8b1abdb
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        parser.cpp
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       XML parser class implementation.
+ */
+
+#include <string>
+#include <sstream>
+#include <algorithm>
+#include <xml-utils.h>
+
+namespace
+{
+const char * const WHITESPACE       = " \n\r\t\v";
+const char * const LINE_WHITESPACE  = " \t";
+
+std::string trim_left(const std::string& s, const char *whitespaces)
+{
+    size_t startpos = s.find_first_not_of(whitespaces);
+    return (startpos == std::string::npos) ? "" : s.substr(startpos);
+}
+
+std::string trim_right(const std::string& s, const char *whitespaces)
+{
+    size_t endpos = s.find_last_not_of(whitespaces);
+    return (endpos == std::string::npos) ? "" : s.substr(0, endpos+1);
+}
+
+std::string trim(const std::string& s, const char *whitespaces)
+{
+    return trim_right(trim_left(s, whitespaces), whitespaces);
+}
+}
+
+namespace CKM {
+namespace XML {
+std::string trim(const std::string& s)
+{
+    return ::trim(s, WHITESPACE);
+}
+
+std::string trimEachLine(const std::string& s)
+{
+    std::istringstream stream(s);
+    size_t line_cnt = 0;
+    std::string line, output;
+    while(std::getline(stream, line)) {
+        if(line_cnt>0)
+            output += "\n";
+        output += ::trim(line, LINE_WHITESPACE);
+        line_cnt ++;
+    }
+    return output;
+}
+}
+}
diff --git a/src/manager/initial-values/xml-utils.h b/src/manager/initial-values/xml-utils.h
new file mode 100644 (file)
index 0000000..c385598
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed 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
+ *
+ *
+ * @file        xml-utils.h
+ * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
+ * @version     1.0
+ * @brief       XML utils.
+ */
+
+#ifndef XML_UTILS_H_
+#define XML_UTILS_H_
+
+#include <string>
+namespace CKM {
+namespace XML
+{
+
+std::string trim(const std::string& s);
+std::string trimEachLine(const std::string &s);
+
+}
+}
+#endif /* XML_UTILS_H_ */
index b9b5301..2f3c247 100644 (file)
 #include <key-impl.h>
 #include <certificate-config.h>
 #include <certificate-store.h>
+#include <dirent.h>
+#include <algorithm>
+#include <InitialValuesFile.h>
 
 #include <generic-backend/exception.h>
 #include <sw-backend/crypto-service.h>
 
 namespace {
-const char * const CERT_SYSTEM_DIR  = "/etc/ssl/certs";
-const uid_t        SYSTEM_DB_UID    = 0;
-const char * const SYSTEM_DB_PASSWD = "cAtRugU7";
+const char * const CERT_SYSTEM_DIR          = "/etc/ssl/certs";
+const char * const INIT_VALUES_DIR          = "/opt/data/ckm/initial_values/";
+const char * const INIT_VALUES_XSD          = "/opt/data/ckm/initial_values/initial_values.xsd";
+const char * const INIT_VALUES_FILE_SUFFIX  = ".xml";
+const char * const SYSTEM_DB_PASSWD         = "cAtRugU7";
 
 bool isLabelValid(const CKM::Label &label) {
     // TODO: copy code from libprivilege control (for check smack label)
@@ -54,11 +59,50 @@ bool isNameValid(const CKM::Name &name) {
 
 namespace CKM {
 
+const uid_t CKMLogic::SYSTEM_DB_UID = 0;
+
 CKMLogic::CKMLogic()
 {
     CertificateConfig::addSystemCertificateDir(CERT_SYSTEM_DIR);
 
     m_accessControl.updateCCMode();
+
+    // make initial file list
+    std::vector<std::string> filesToParse;
+    DIR *dp = opendir(INIT_VALUES_DIR);
+    if(dp)
+    {
+        struct dirent *entry;
+        while ((entry = readdir(dp)))
+        {
+            std::string filename = std::string(entry->d_name);
+
+            // check if XML file
+            std::string lowercaseFilename = filename;
+            std::transform(lowercaseFilename.begin(), lowercaseFilename.end(), lowercaseFilename.begin(), ::tolower);
+            if(lowercaseFilename.find(INIT_VALUES_FILE_SUFFIX) == std::string::npos)
+                continue;
+
+            filesToParse.push_back(std::string(INIT_VALUES_DIR) + filename);
+        }
+        closedir(dp);
+    }
+
+    // parse
+    for(const auto & file : filesToParse)
+    {
+        InitialValues::InitialValuesFile xmlFile(file.c_str(), *this);
+        int rc = xmlFile.Validate(INIT_VALUES_XSD);
+        if(rc == XML::Parser::PARSE_SUCCESS)
+        {
+            rc = xmlFile.Parse();
+            if(rc != XML::Parser::PARSE_SUCCESS)
+                LogError("invalid initial values file: " << file << ", parsing code: " << rc);
+        }
+        else
+            LogError("invalid initial values file: " << file << ", validation code: " << rc);
+        unlink(file.c_str());
+    }
 }
 
 CKMLogic::~CKMLogic(){}
@@ -404,7 +448,15 @@ DB::Row CKMLogic::createEncryptedRow(
     return row;
 }
 
-int CKMLogic::verifyBinaryData(DataType dataType, const RawBuffer &input_data) const
+int CKMLogic::verifyBinaryData(DataType dataType, RawBuffer &input_data) const
+{
+    RawBuffer dummy;
+    return toBinaryData(dataType, input_data, dummy);
+}
+
+int CKMLogic::toBinaryData(DataType dataType,
+                           const RawBuffer &input_data,
+                           RawBuffer &output_data) const
 {
     // verify the data integrity
     if (dataType.isKey())
@@ -415,6 +467,7 @@ int CKMLogic::verifyBinaryData(DataType dataType, const RawBuffer &input_data) c
             LogError("provided binary data is not valid key data");
             return CKM_API_ERROR_INPUT_PARAM;
         }
+        output_data = output_key->getDER();
     }
     else if (dataType.isCertificate() || dataType.isChainCert())
     {
@@ -424,14 +477,16 @@ int CKMLogic::verifyBinaryData(DataType dataType, const RawBuffer &input_data) c
             LogError("provided binary data is not valid certificate data");
             return CKM_API_ERROR_INPUT_PARAM;
         }
+        output_data = cert->getDER();
     }
+    else
+        output_data = input_data;
     // TODO: add here BINARY_DATA verification, i.e: max size etc.
     return CKM_API_SUCCESS;
 }
 
-RawBuffer CKMLogic::saveData(
+int CKMLogic::verifyAndSaveDataHelper(
     const Credentials &cred,
-    int commandId,
     const Name &name,
     const Label &label,
     const RawBuffer &data,
@@ -442,10 +497,11 @@ RawBuffer CKMLogic::saveData(
 
     try {
         // check if data is correct
-        retCode = verifyBinaryData(dataType, data);
+        RawBuffer binaryData;
+        retCode = toBinaryData(dataType, data, binaryData);
         if(retCode == CKM_API_SUCCESS)
         {
-            retCode = saveDataHelper(cred, name, label, dataType, data, policy);
+            retCode = saveDataHelper(cred, name, label, dataType, binaryData, policy);
         }
     } catch (const KeyProvider::Exception::Base &e) {
         LogError("KeyProvider failed with message: " << e.GetMessage());
@@ -469,7 +525,19 @@ RawBuffer CKMLogic::saveData(
         LogError("CKM::Exception: " << e.GetMessage());
         retCode = CKM_API_ERROR_SERVER_ERROR;
     }
+    return retCode;
+}
 
+RawBuffer CKMLogic::saveData(
+    const Credentials &cred,
+    int commandId,
+    const Name &name,
+    const Label &label,
+    const RawBuffer &data,
+    DataType dataType,
+    const PolicySerializable &policy)
+{
+    int retCode = verifyAndSaveDataHelper(cred, name, label, data, dataType, policy);
     auto response = MessageBuffer::Serialize(static_cast<int>(LogicCommand::SAVE),
                                              commandId,
                                              retCode,
index 124cfc8..341d23d 100644 (file)
@@ -48,6 +48,7 @@ struct UserData {
 
 class CKMLogic {
 public:
+    static const uid_t SYSTEM_DB_UID;
     class Exception
     {
     public:
@@ -184,6 +185,21 @@ public:
         const Label &accessor_label,
         const PermissionMask permissionMask);
 
+    int setPermissionHelper(
+            const Credentials &cred,
+            const Name &name,
+            const Label &ownerLabel,
+            const Label &accessorLabel,
+            const PermissionMask permissionMask);
+
+    int verifyAndSaveDataHelper(
+        const Credentials &cred,
+        const Name &name,
+        const Label &label,
+        const RawBuffer &data,
+        DataType dataType,
+        const PolicySerializable &policy);
+
 private:
 
     // select private/system database depending on asking uid and owner label.
@@ -205,7 +221,12 @@ private:
 
     int verifyBinaryData(
         DataType dataType,
-        const RawBuffer &input_data) const;
+        RawBuffer &input_data) const;
+
+    int toBinaryData(
+        DataType dataType,
+        const RawBuffer &input_data,
+        RawBuffer &output_data) const;
 
     int checkSaveConditions(
         const Credentials &cred,
@@ -332,13 +353,6 @@ private:
         bool useTrustedSystemCertificates,
         RawBufferVector &chainRawVector);
 
-    int setPermissionHelper(
-        const Credentials &cred,
-        const Name &name,
-        const Label &ownerLabel,
-        const Label &accessorLabel,
-        const PermissionMask permissionMask);
-
     int getDataListHelper(
         const Credentials &cred,
         const DataType dataType,
index 42530c5..650c5e7 100644 (file)
@@ -45,6 +45,7 @@ SET(TEST_MERGED_SOURCES
     ${KEY_MANAGER_PATH}/service/db-crypto.cpp
     ${KEY_MANAGER_PATH}/service/key-provider.cpp
     ${KEY_MANAGER_PATH}/initial-values/parser.cpp
+    ${KEY_MANAGER_PATH}/initial-values/xml-utils.cpp
     ${KEY_MANAGER_PATH}/client-async/descriptor-set.cpp
     ${KEY_MANAGER_PATH}/dpl/core/src/assert.cpp
     ${KEY_MANAGER_PATH}/dpl/core/src/colors.cpp
index dae9fcf..2a78b05 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<InitialValues version="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="initial_values.xsd ">
-  <Key name="key1" type="RSA_PRV" password="123">
+<InitialValues version="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="initial_values.xsd ">
+  <Key name="key1" type="RSA_PUB" password="123">
     <PEM>
       -----BEGIN PUBLIC KEY-----
       MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2b1bXDa+S8/MGWnMkru4
       zQIDAQAB
       -----END PUBLIC KEY-----
     </PEM>
+    <Permission accessor="web_app1"/>
+    <Permission accessor="web_app2"/>
+  </Key>
+  <Key name="key2" type="RSA_PRV" exportable="true">
+    <DER>
+      MIIEpAIBAAKCAQEAyJjUHY2pJJUBRBCrlerrgcS7aBiWlY3594dufu3m4qy48b9hsw1R/AHSNUPU
+      11vzQ+kUcXkEZOby5SHRHBAXIJ1dLbTPtRwsVwgf1nmc/ZGGV/XOrOaKi7nSKgYHaglPgc9dLPuu
+      osRHs/EdIWh3o59MdY6rA6y+QTJrQm3axRKdT7unX3kFS3SsId02GWBkLtrw+yQVtvhCYlY/n2/T
+      uZBJpZN7vT2it0rJS4fQkfjcjAi8f/isZLrfUgDqxIDSWVbVyjlQOphIO+K3ABjev3ZbJMWl+w10
+      pV0nbmF8lviEYft9mhERS9kUdQwzy3KIgyjyt+ewQG6hjyMJ/5y5KwIDAQABAoIBAQC3S06nIoZn
+      su/RLhpbhqljjkxgNfeC+JRsJghFW0UZ4xGrdGDlp0o+p7tYiH63uoFykEvp09a8DHvt+xSEO/+m
+      AaTe2tTgfLnXXMkaxU06Nfs37JfJTW9TdZwgYhnsPk20I7LUI7XTbN7IAY3ItRh9HlZTJOYHGZVP
+      Ja70qES6xUOTaVOvKIbB2W9XeiMX6cNoHTLM9rl1I8bA13Er0M0acKRtF4Rfw4z43nJKzORCYKm3
+      mA3zqtQja7z+zdQBib34RHZiKgvuJDqg89p7FTLT9z+lbXONH+K/3MldaYG1O8mtgt4zv6onH199
+      QBOrww158Z6keH3tBz+xsrClfIpBAoGBAPkar4ugZYLRgyuythby3uHrlMBNajmJf2gFwngvfUgO
+      JS45fLN2AIDrA5VYUiT8cFjVFfzEiu1xa33Juy8rfHlQuY8yOIVDnbdGJvOBYsrvlyYWY+9jEydd
+      cLctQKquACLb3jNYbrC9m8cBBcSZelRAVSF4O1k8HdlcdV7IIVyjAoGBAM4mY5PNLr3I/pyyNizw
+      7cUmHdblU+sScwFdC/KDwfG5WOI3WorTLutD4EiEA3yQIDStuVJLiray4Pu+bqhUPAJumpRrpQJ4
+      PCPxr/M98FhXvMmDWzGu/xK/6hLP5g1Ngp6qvVygnYNBkyqMzfM0rUAxQLS3qmocWk2xBKDEnjHZ
+      AoGBAJkWgVO52yiuQYKVbbpkv/zvnpcf/GwnyBjRkVXzOXcS2l6yDaTsnBqeU7FweespCJJPQhf5
+      YbfSwFCprVOr0e9sYN1T69BaYY7EmiOEHIbC/4z0ra3soVTL4/1u3hMGpCbIIKJFcqFDpXyDcFwG
+      RluIvci37yFEBMQUQj1hmL8pAoGAJBHtfG/7TLO9cRdxiT2CrOs1b2Ni4o+w1b09GOra5XujxLkg
+      u4el/v46YRXQMlxZdj4rXe3f0IXN/d5dKFDMyzQlEfEfxyXYiAWC3tGomxyG6M92BmRzNwmjYDVG
+      MG+ueiqvxWRJCy1PHbPTWUmPQtsbUkOMqtJZLpzZjXO5pkkCgYA9uyQ8os9yfjALc1VDZ4HtGxaC
+      Uq8zy0jJEJxchRn1JUNHop/skaRA65x613lWDygfNCuakozjP5x+GA5WEIuxIE8V7JPac1zpEZW4
+      5nwmxoR1l3HUDT8kRYkLzMIo55PpLG9arNLwH9mSRh/taG8020aGg3nFSNCJNDs12x/9RA==
+    </DER>
   </Key>
   <Cert exportable="true" name="cert1">
     <DER>
-      MIIEgDCCA2igAwIBAgIIcjtBYJGQtOAwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE
-      BhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMxJTAjBgNVBAMTHEdvb2dsZSBJbnRl
-      cm5ldCBBdXRob3JpdHkgRzIwHhcNMTQwNTIyMTEyOTQyWhcNMTQwODIwMDAwMDAw
-      WjBtMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwN
-      TW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzEcMBoGA1UEAwwTYWNj
-      rHva8A==
+      MIIDnzCCAoegAwIBAgIJAMH/ADkC5YSTMA0GCSqGSIb3DQEBBQUAMGYxCzAJBgNVBAYTAkFVMRMw
+      EQYDVQQIDApTb21lLVN0YXRlMQ0wCwYDVQQKDARBQ01FMRAwDgYDVQQLDAdUZXN0aW5nMSEwHwYD
+      VQQDDBhUZXN0IHJvb3QgY2EgY2VydGlmaWNhdGUwHhcNMTQxMjMwMTcyMTUyWhcNMjQxMjI3MTcy
+      MTUyWjBmMQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTENMAsGA1UECgwEQUNNRTEQ
+      MA4GA1UECwwHVGVzdGluZzEhMB8GA1UEAwwYVGVzdCByb290IGNhIGNlcnRpZmljYXRlMIIBIjAN
+      BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0EJRdUtd2th0vTVF7QxvDKzyFCF3w9vC9IDE/Yr1
+      2w+a9jd0s7/eG96qTHIYffS3B7x2MB+d4n+SR3W0qmYh7xk8qfEgH3daeDoV59IZ9r543KM+g8jm
+      6KffYGX1bIJVVY5OhBRbO9nY6byYpd5kbCIUB6dCf7/WrQl1aIdLGFIegAzPGFPXDcU6F192686x
+      54bxt/itMX4agHJ9ZC/rrTBIZghVsjJo5/AH5WZpasv8sfrGiiohAxtieoYoJkv5MOYP4/2lPlOY
+      +Cgw1Yoz+HHv31AllgFsBquBb/kJVmCCNsAOcnvQzTZUsW/TXz9G2nwRdqI1nSy2JvVjZGsqGQID
+      AQABo1AwTjAdBgNVHQ4EFgQUt6pkzFt1PZlfYRL/HGnufF4frdwwHwYDVR0jBBgwFoAUt6pkzFt1
+      PZlfYRL/HGnufF4frdwwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAQEAld7Qwq0cdzDQ
+      51w1RVLwTR8Oy25PB3rzwEHcSGJmdqlMi3xOdaz80S1R1BBXldvGBG5Tn0vT7xSuhmSgI2/HnBpy
+      9ocHVOmhtNB4473NieEpfTYrnGXrFxu46Wus9m/ZnugcQ2G6C54A/NFtvgLmaC8uH8M7gKdS6uYU
+      wJFQEofkjmd4UpOYSqmcRXhSJzd5FYFWkJhKJYp3nlENSOD8CUFFVGekm05nFN2gRVc/qaqQkEX7
+      7+XYvhodLRsVqMn7nf7taidDKLO2T4bhujztnTYOhhaXKgPy7AtZ28N2wvX96VyAPB/vrchGmyBK
+      kOg11TpPdNDkhb1J4ZCh2gupDg==
     </DER>
   </Cert>
   <Data name="data1">
index 72a565a..22752d0 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<InitialValues version="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="initial_values.xsd ">
+<InitialValues version="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="initial_values.xsd ">
   <Key name="key1" type="RSA_PRV" password="123">
     <PEM>
       -----BEGIN PUBLIC KEY-----
index 02538c4..0d5e298 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<StructureTest version="0">
+<StructureTest version="1">
 <Add>1</Add>
 <Add powerFactor="4">2</Add>
 <Add>3</Add>
index 04bc72e..9771849 100644 (file)
@@ -24,6 +24,7 @@
 #include <boost/test/unit_test.hpp>
 #include <parser.h>
 
+using namespace CKM;
 using namespace XML;
 
 namespace
@@ -58,13 +59,14 @@ BOOST_AUTO_TEST_SUITE(XML_PARSER_TEST)
 
 BOOST_AUTO_TEST_CASE(XmlParserTest_wrong_argument)
 {
-    XML::Parser parser(0);
-    BOOST_REQUIRE(Parser::ErrorCode::ERROR_INVALID_ARGUMENT == parser.Validate(0));
+    std::string emptyPath;
+    XML::Parser parser(emptyPath);
+    BOOST_REQUIRE(Parser::ErrorCode::ERROR_INVALID_ARGUMENT == parser.Validate(emptyPath));
 
     // no listeners
     BOOST_REQUIRE(Parser::ErrorCode::ERROR_INVALID_ARGUMENT == parser.Parse());
 
-    BOOST_REQUIRE(Parser::ErrorCode::SUCCESS == parser.RegisterElementCb("Key", dummyStartCallback, dummyEndCallback));
+    BOOST_REQUIRE(Parser::ErrorCode::PARSE_SUCCESS == parser.RegisterElementCb("Key", dummyStartCallback, dummyEndCallback));
     BOOST_REQUIRE(Parser::ErrorCode::ERROR_XML_PARSE_FAILED == parser.Parse());
 }
 
@@ -97,8 +99,8 @@ BOOST_AUTO_TEST_CASE(XmlParserTest_XML1_correct_parse_incorrect_callbacks)
     XML::Parser parser(format_test_path(XML_1_okay).c_str());
     BOOST_REQUIRE(0 == parser.Validate(format_test_path(XSD_1_okay).c_str()));
 
-    BOOST_REQUIRE(Parser::ErrorCode::SUCCESS == parser.RegisterElementCb("Data", NULL, NULL));
-    BOOST_REQUIRE(Parser::ErrorCode::SUCCESS == parser.Parse());
+    BOOST_REQUIRE(Parser::ErrorCode::PARSE_SUCCESS == parser.RegisterElementCb("Data", NULL, NULL));
+    BOOST_REQUIRE(Parser::ErrorCode::PARSE_SUCCESS == parser.Parse());
 }
 
 BOOST_AUTO_TEST_CASE(XmlParserTest_XML1_correct_parse)
@@ -106,11 +108,11 @@ BOOST_AUTO_TEST_CASE(XmlParserTest_XML1_correct_parse)
     XML::Parser parser(format_test_path(XML_1_okay).c_str());
     BOOST_REQUIRE(0 == parser.Validate(format_test_path(XSD_1_okay).c_str()));
 
-    BOOST_REQUIRE(Parser::ErrorCode::SUCCESS == parser.RegisterElementCb("Key", dummyStartCallback, NULL));
-    BOOST_REQUIRE(Parser::ErrorCode::SUCCESS == parser.RegisterElementCb("Cert", NULL, dummyEndCallback));
+    BOOST_REQUIRE(Parser::ErrorCode::PARSE_SUCCESS == parser.RegisterElementCb("Key", dummyStartCallback, NULL));
+    BOOST_REQUIRE(Parser::ErrorCode::PARSE_SUCCESS == parser.RegisterElementCb("Cert", NULL, dummyEndCallback));
     startCallbackFlag = false;
     endCallbackFlag = false;
-    BOOST_REQUIRE(Parser::ErrorCode::SUCCESS == parser.Parse());
+    BOOST_REQUIRE(Parser::ErrorCode::PARSE_SUCCESS == parser.Parse());
     BOOST_REQUIRE(startCallbackFlag == true);
     BOOST_REQUIRE(endCallbackFlag == true);
 }