platform/core/security/key-manager.git
19 months agoRefactor KeyProvider 11/282611/1
Krzysztof Jackiewicz [Wed, 5 Oct 2022 13:51:33 +0000 (15:51 +0200)]
Refactor KeyProvider

Apply modifications while keeping key file format and encryption scheme
unchanged:
* Remove unused code
* Deduplicate code
* Unify key naming
* Simplify structures keeping various forms of keys and their metadata
* Update tests

Change-Id: I38caceb6c38bfecbdbbb290df39042ba7b17b394

19 months agoadd debug log and fix a bug 58/282558/3
isaac2.lee [Thu, 6 Oct 2022 01:17:12 +0000 (10:17 +0900)]
add debug log and fix a bug

Change-Id: I35d284cb29ec3bfe53500f4473994ed5c8217e61

19 months agoRelease 0.1.47 50/282550/1
Dongsun Lee [Wed, 5 Oct 2022 10:07:05 +0000 (19:07 +0900)]
Release 0.1.47

* add the se-backend for db encryption

Change-Id: Id0c036cb08a11215e74be5e6bb2343785fd6bc93

19 months agoadd the se-backend for db encryption 49/282549/1
이이삭/System Security Lab(SR)/삼성전자 [Wed, 5 Oct 2022 07:10:38 +0000 (16:10 +0900)]
add the se-backend for db encryption

* add the se-backend for db encryption
* change se-backend include dependancy and remove the unavailable codes
* remove migration DBDEK and rearrange KeyProvider structures

Change-Id: I52e07ac5af7b41d0f79b7fee818221f25b1d60cd

19 months agoRelease 0.1.46 65/282065/1
Krzysztof Jackiewicz [Mon, 26 Sep 2022 14:28:11 +0000 (16:28 +0200)]
Release 0.1.46

* Fix encryption request handling
* Add Samsung's Analysis Hub service configuration
* Remove unused sec_build_binary_debug_enable build macro

Change-Id: I909ddd67218797199f44d35582d20fb77e47f9ef

19 months agoFix encryption request handling 50/282050/1
Krzysztof Jackiewicz [Mon, 26 Sep 2022 10:47:24 +0000 (12:47 +0200)]
Fix encryption request handling

The key used in m_requestMap is not unique which may lead to errors when
requests from multiple clients are processed.

Use a separate request counter as the key.

Change-Id: Iffbf0a3c43ea0c091eb3d714ef0a77211f9b3a78

19 months agoAdd Samsung's Analysis Hub service configuration 54/281754/1 sandbox/tswierczek/ahub_test
Tomasz Swierczek [Wed, 21 Sep 2022 10:30:25 +0000 (12:30 +0200)]
Add Samsung's Analysis Hub service configuration

Configuration allows skipping sqlcipher.c file,
which is external open source, from static analysis.

Change-Id: Ia1ed85e403c8feefdfe659018b660af5dbe27daa

2 years agoRemove unused sec_build_binary_debug_enable build macro 00/267100/1
Dariusz Michaluk [Thu, 25 Nov 2021 10:46:28 +0000 (11:46 +0100)]
Remove unused sec_build_binary_debug_enable build macro

Change-Id: I3fc241eabb7ba6b8f737149f99410da0af028953

2 years agoRelease 0.1.45 92/261992/1 accepted/tizen_7.0_unified_hotfix tizen_7.0_hotfix accepted/tizen/6.5/unified/20211028.121009 accepted/tizen/7.0/unified/hotfix/20221116.105609 accepted/tizen/unified/20210809.125009 submit/tizen/20210802.071931 submit/tizen_6.5/20211028.162401 tizen_6.5.m2_release tizen_7.0_m2_release
Tomasz Swierczek [Tue, 27 Jul 2021 06:39:17 +0000 (08:39 +0200)]
Release 0.1.45

* Deprecate ckmc_ocsp_check API

Change-Id: I248a647047782f6a7f403cd51b3c9b76152936b0

2 years agoDeprecate ckmc_ocsp_check API 91/261991/1
Tomasz Swierczek [Tue, 27 Jul 2021 06:01:47 +0000 (08:01 +0200)]
Deprecate ckmc_ocsp_check API

OCSP test certificate management is problematic, and Tizen platform
has another ocsp API in OpenSSL which can be officially recommended.

Change-Id: Ifc115c300e79a64b65361deaa848ee396e654240

2 years agoRelease 0.1.44 39/260539/1 accepted/tizen/unified/20210630.144039 submit/tizen/20210628.124714 submit/tizen/20210628.130131
Michał Szaknis [Mon, 28 Jun 2021 12:22:49 +0000 (14:22 +0200)]
Release 0.1.44

* Use fixed object ID in TZ backend
* Add more tests to increase coverage

Change-Id: I989df7e1b5b8c9f783014b40b4eb700c263d1cd3

2 years agoUse fixed object ID in TZ backend 44/260344/5
Michał Szaknis [Wed, 21 Apr 2021 15:28:08 +0000 (17:28 +0200)]
Use fixed object ID in TZ backend

Calculate the object ID as a hash of credentials and alias instead of
using a random ID.

Change-Id: Ice164d6f8eda9acd157c4d74f47d45fef49f6ddc

2 years agoAdd tests for `try_catch` and `try_catch_enclosure` 93/258693/5
Michał Szaknis [Fri, 21 May 2021 14:17:20 +0000 (16:17 +0200)]
Add tests for `try_catch` and `try_catch_enclosure`

Change-Id: If74b22ad53961a32c75d3d7feae48f2a41d09508

2 years agoAdd tests for ckmc-type-converter.cpp 91/258691/5
Michał Szaknis [Fri, 21 May 2021 08:18:35 +0000 (10:18 +0200)]
Add tests for ckmc-type-converter.cpp

Change-Id: Idd90ad6f954ec491d718b955bea2f43624986160

2 years agoAdd tests for AliasSupport class 90/258690/4
Michał Szaknis [Thu, 20 May 2021 15:16:14 +0000 (17:16 +0200)]
Add tests for AliasSupport class

Change-Id: I509160e10ca4ac00418d3ee408c32915c6aa5511

2 years agoAdd test to xml-utils.cpp 89/258689/4
Michał Szaknis [Thu, 20 May 2021 10:30:06 +0000 (12:30 +0200)]
Add test to xml-utils.cpp

Change-Id: I74c1130c20245ade53dbb86c72e38528409be23f

3 years agoRelease 0.1.43 37/258337/1 submit/tizen/20210514.053932
Krzysztof Jackiewicz [Thu, 13 May 2021 13:34:32 +0000 (15:34 +0200)]
Release 0.1.43

* Open legacy db in R/W mode
* Fix coverage generation in rpm 4.14.1
* Suppress TEEC deprecated declarations warnings
* Remove unnecessary cast to double in db perf test

Change-Id: I44b581084930e2253ea3112e362733f47a0c9479

3 years agoOpen legacy db in R/W mode 35/258335/1
Krzysztof Jackiewicz [Thu, 13 May 2021 12:53:32 +0000 (14:53 +0200)]
Open legacy db in R/W mode

If due to a failure during previous transaction a rollback journal is
generated, the original legacy database has to be restored to the
original state before it can be dumped. However, it can't be done
unless the database is opened in R/W mode.

Change-Id: Icc455f4e820a5be8b0628e95895680e9cbb14eb6

3 years agoFix coverage generation in rpm 4.14.1 90/254490/1
Tomasz Swierczek [Wed, 3 Mar 2021 13:56:26 +0000 (14:56 +0100)]
Fix coverage generation in rpm 4.14.1

Debug source package directories now have different names.

Change-Id: I40f13e79fc90569b9f2f8d03a5a03c3759186363

3 years agoSuppress TEEC deprecated declarations warnings 48/253848/2
Dariusz Michaluk [Thu, 18 Feb 2021 12:16:28 +0000 (13:16 +0100)]
Suppress TEEC deprecated declarations warnings

Change-Id: Iaaf6d24ceef6f981398f6c780f41c420555ee191

3 years agoRemove unnecessary cast to double in db perf test 32/253832/2
Krzysztof Jackiewicz [Thu, 18 Feb 2021 09:43:19 +0000 (10:43 +0100)]
Remove unnecessary cast to double in db perf test

Change-Id: I7ef26e137010f303c378cb135404a39bf13ec181

3 years agoRelease 0.1.42 77/253377/1 accepted/tizen/unified/20210210.130258 submit/tizen/20210209.105321
Tomasz Swierczek [Tue, 9 Feb 2021 10:03:25 +0000 (11:03 +0100)]
Release 0.1.42

* Updated to match recent systemd changes

Change-Id: I053812d12e9ae4fce5664def0d8bf8adde9f379e

3 years agoChange systemd-devel package name 95/252795/2
INSUN PYO [Tue, 2 Feb 2021 08:57:32 +0000 (17:57 +0900)]
Change systemd-devel package name

Change-Id: Ia1df8a4567c2f72ef1777bd70b831220fce0b0a4

3 years agoRelease 0.1.41 78/252978/1 submit/tizen/20210203.135344
Krzysztof Jackiewicz [Wed, 3 Feb 2021 13:31:31 +0000 (14:31 +0100)]
Release 0.1.41

* Remove useless socket description timeout initialization
* Check sockets received from services
* Cynara socket tests
* Make SocketDescription getters const
* Validate cynara sockets
* Refrain from retrying close(int) (per man 2 close)
* Catch exceptions before returning to cynara
* Use eventfd instead of pipes for notifications
* Add randomized socket manager stress test
* Prevent writing to a socket marked as closed
* Refactor SocketManager's timeout queue
* Add timeout queue stress test
* Add check for connection counter in the server
* Start SocketManager as not working

Change-Id: I40682e7d061bbc4e522b1193b328e81abbe6e8e9

3 years agoRemove useless socket description timeout initialization 16/252816/3
Krzysztof Jackiewicz [Tue, 2 Feb 2021 10:09:00 +0000 (11:09 +0100)]
Remove useless socket description timeout initialization

* Socket description vector uses raw monotonic clock for timeouts.
* Not all sockets use timeouts.
* Those that use are initialized at later stage.

Change-Id: Ifd9ce8c29882fc9f8cf8752a0dbd0a72b953b8f3

3 years agoCheck sockets received from services 15/252815/3
Krzysztof Jackiewicz [Tue, 2 Feb 2021 10:07:42 +0000 (11:07 +0100)]
Check sockets received from services

Change-Id: Ibb4b79a9e4e1c36223409c695c58c40f695e538c

3 years agoCynara socket tests 99/252599/4
Krzysztof Jackiewicz [Mon, 25 Jan 2021 09:40:58 +0000 (10:40 +0100)]
Cynara socket tests

Change-Id: I6615bf57b4a0a8bde39c14a7f82d21b000c52286

3 years agoMake SocketDescription getters const 98/252598/3
Krzysztof Jackiewicz [Mon, 25 Jan 2021 15:01:56 +0000 (16:01 +0100)]
Make SocketDescription getters const

Change-Id: Ide41dc35598b423f8dac320b02b136b17a21c3cf

3 years agoValidate cynara sockets 97/252597/3
Krzysztof Jackiewicz [Mon, 25 Jan 2021 08:09:05 +0000 (09:09 +0100)]
Validate cynara sockets

Socket descriptors received from cynara are not validated which may lead
to:
- m_socketDescriptionVector buffer overflow/UB
- reuse of already opened descriptors for cynara
- growing m_socketDescriptionVector
- closure of descriptors used by other parts of code
- more than one cynara socket opened at the same time

Change-Id: I5c6cd521fbde2a461f24e175571b74885d163b50

3 years agoMerge "Catch exceptions before returning to cynara" into tizen
Konrad Lipinski [Fri, 29 Jan 2021 15:58:37 +0000 (15:58 +0000)]
Merge "Catch exceptions before returning to cynara" into tizen

3 years agoRefrain from retrying close(int) (per man 2 close) 02/252302/2
Konrad Lipinski [Tue, 26 Jan 2021 09:09:17 +0000 (10:09 +0100)]
Refrain from retrying close(int) (per man 2 close)

Change-Id: I3343546c8aa2590e0147b89dc3c336d5e47a2d07

3 years agoCatch exceptions before returning to cynara 96/252596/2
Krzysztof Jackiewicz [Mon, 25 Jan 2021 08:07:44 +0000 (09:07 +0100)]
Catch exceptions before returning to cynara

Callbacks registered in cynara may throw. Let's not propagate exceptions
to cynara.

Change-Id: Idc3bec6208495d0bfdb4d41c3ea0451352c9715b

3 years agoUse eventfd instead of pipes for notifications 11/252011/3
Krzysztof Jackiewicz [Thu, 21 Jan 2021 12:10:45 +0000 (13:10 +0100)]
Use eventfd instead of pipes for notifications

The kernel overhead of an eventfd file descriptor is much lower than
that of a pipe, and only one file descriptor is required.

Change-Id: Ie6d04d1ea8125190c35e1ef1655f517406eff807

3 years agoAdd randomized socket manager stress test 35/251535/10
Krzysztof Jackiewicz [Thu, 14 Jan 2021 20:35:46 +0000 (21:35 +0100)]
Add randomized socket manager stress test

Registers several test services in the manager.
In a loop:
* Selects a random service
* Selects a random action:
  * Create a new connection
  * Disconnect a random existing connection
  * Send random data through a random connection
  * Try to receive data from a random connection

Change-Id: Id208e3a6ffbd1db82cd3389ba72bd0ff998d7c61

3 years agoPrevent writing to a socket marked as closed 34/251534/8
Krzysztof Jackiewicz [Thu, 14 Jan 2021 12:54:15 +0000 (13:54 +0100)]
Prevent writing to a socket marked as closed

It is possible that select() marks a descriptor as ready for both read
and write operation. If, additionally, the socket becomes closed in
ReadyForRead(), the following call to ReadyForWrite() will attempt to
write to a closed socket. It is harmless, unless the closed descriptor
is already reused by another thread at the time of write().

This commit prevents it.

Change-Id: Idaa829ef74d6df9f24c263f289aeca910b679713

3 years agoRefactor SocketManager's timeout queue 00/251400/10
Krzysztof Jackiewicz [Wed, 13 Jan 2021 09:40:17 +0000 (10:40 +0100)]
Refactor SocketManager's timeout queue

SocketManager changes:
* Remove timeout queue elements on socket closure. Until now it was
  possible to make the timeout queue grow because its elements were not
  removed upon socket closure.
* The queue now contains only socket numbers of corresponding
  m_socketDescriptionVector elements. The code responsible for timeout
  updates in the queue is no longer neccessary and has been removed.
* Modify the timeout queue only if corresponding socket has a timeout
  enabled.
* Remove unnecessary 'open' and 'timeout' socket flag check if a
  timeout occurs. Only the main thread modifies these flags. If there's
  a timeout, it must have been triggered by an opened socket with
  timeout enabled.

Growing queue test changes:
* Compare timeout queue size and connection count in the SocketManager
  thread.
* Assume that first AcceptEvent is triggered by the most reccent
  connection attempt.
* Match client and server sockets to properly detect CloseEvents.
* Add more stress to the test with more initial connections.
* Throw std exceptions from SocketManager thread.
* Wrap SocketManager thread in an object. Check a possible exception in
  the destructor.
* Get rid of unnecessary timeouts.

Change-Id: Icd63696a58c4ef6a66c2e487819423df610ca580

3 years agoAdd timeout queue stress test 99/251399/5
Krzysztof Jackiewicz [Tue, 12 Jan 2021 11:37:18 +0000 (12:37 +0100)]
Add timeout queue stress test

While one socket connection is active and its timeout not reached yet,
we can open and close many new connections, which will push items on
SocketManager::m_timeoutQueue. Because first socket has an earliest
timeout, the second connection elements won't be touched. Because
m_timeoutQueue elements are not removed on socket close, the queue will
grow. Still nothing bad should happen.

Change-Id: Ied20d2e1517ad471e465c6fa601e368469a4cc37

3 years agoAdd check for connection counter in the server 97/251397/3
Krzysztof Jackiewicz [Tue, 12 Jan 2021 11:30:01 +0000 (12:30 +0100)]
Add check for connection counter in the server

This is just a precaution targeted more at stress tests rather than
regular key-manager usage.

Also remove unused ConnectionID operator.

Change-Id: I090b7bd29594d8a47cc4142a7713ccfb4c9b121e

3 years agoStart SocketManager as not working 98/251398/2
Krzysztof Jackiewicz [Tue, 12 Jan 2021 11:33:53 +0000 (12:33 +0100)]
Start SocketManager as not working

The m_working flag should be set to true only inside MainLoop().

Change-Id: I47138d2036ff87712b4b5ac4b4df385917cd866b

3 years agoRelease 0.1.40 60/251160/2 accepted/tizen/unified/20210111.024859 submit/tizen/20210108.164308
Dariusz Michaluk [Fri, 8 Jan 2021 16:31:00 +0000 (17:31 +0100)]
Release 0.1.40

* packaging: rpm scriptlet cleanup, handle -p /sbin/ldconfig
* Use memcpy to avoid unaligned access
* Make IEncryptionService destructor protected

Change-Id: Id6c04467097f0a89c58403c5e824d8b2d0a35aea

3 years agopackaging: rpm scriptlet cleanup, handle -p /sbin/ldconfig 44/251144/2
Dariusz Michaluk [Fri, 8 Jan 2021 13:52:19 +0000 (14:52 +0100)]
packaging: rpm scriptlet cleanup, handle -p /sbin/ldconfig

The RPM documention indicates that during an rpm install or erase, the
script(lets): %post, %preun, and %postun (and %pre, %build, %install,
etc.) are copied to a temp file, and then the temp file is run as a
(/bin/sh or bash) script.

Unfortunately the documentation is not clear about how rpmbuild and/or
rpm determine where the end of any scriptlet is when it is copied to
the file.

Most things in the key-manager.spec work correctly as is. These are the
%preun, %post, and %postun scriptlets that are "closed" by a following
%preun, %post, and %postun, or potentially another scriptlet, e.g.
%file.

The ones that don't work correctly (only one actually) are those where
there is a comment in the spec file before it is closed by another
scriptlet. Further complicating things is that the type of scriptlet
affects what rpm does and what `rpm -qp --scripts ...` shows.

The specific one that didn't work was the
"postun -n libkey-manager-client -p /sbin/ldconfig" scriptlet.
It is followed by a comment before being "closed" by the %files section (or
scriptlet). It can be written two ways:
"%postun -n libkey-manager-client\n/sbin/ldconfig"
or "%postun -n libkey-manager-client -p /sbin/ldconfig".
Either way it's written, `rpm -qp --scripts libkey-manager-client...`
will include the comment lines between the %postun line and the following %files line.

But the way rpm executes these depends on how they're written. If
written as "%postun -n libkey-manager-client\n/sbin/ldconfig" rpm will simply run
/sbin/ldconfig with no command line options, i.e.
  execve ("/sbin/ldconfig", [ "/sbin/ldconfig" ], [ ]);

But when written as "%postun -n libkey-manager-client -p /sbin/ldconfig",
it will copy the comment lines to a temp file, and pass the temp file name and "1"
 as (command line) parameters, i.e.
  execve ("/sbin/ldconfig", [ "/sbin/ldconfig", "/tmp/tmpXXXXXX", "1" ],
          [ ]);

Which results in ldconfig exiting with an error. (Remember, both ways show
the comment in `rpm -qp --scripts ...`)

Problematic comment line was removed and whole file comments style was adjusted.
Additionally some cleanup was performed.

Change-Id: I966f0930d7a7b46b401f399aaf2e5c748edc0a1f

3 years agoUse memcpy to avoid unaligned access 90/250790/3
Krzysztof Jackiewicz [Mon, 4 Jan 2021 13:56:28 +0000 (14:56 +0100)]
Use memcpy to avoid unaligned access

Casting unsigned char* to signalfd_siginfo* may cause an unaligned
access (see -Wcast-align). Use memcpy to avoid it.

Verify by sending SIGTERM to key-manager, observing the logs and
systemctl status. The service should stop without errors.

systemctl start central-key-manager
kill -SIGTERM `pidof key-manager`
systemctl status central-key-manager

Change-Id: I061cc2f488cba9252ed65b0d8ca22840f725a433

3 years agoMake IEncryptionService destructor protected 53/250753/1
Krzysztof Jackiewicz [Mon, 4 Jan 2021 09:01:30 +0000 (10:01 +0100)]
Make IEncryptionService destructor protected

The implicitly-defined destructor is non-virtual and public. We don't
want the EncryptionService to be destroyed via IEncryptionService.

Change-Id: Iaf2b180cdd4f60a4f20cc1c9e1d593dcd1c1f220

3 years agoRelease 0.1.39 64/249764/1 accepted/tizen/unified/20201217.124248 submit/tizen/20201216.144517
Tomasz Swierczek [Wed, 16 Dec 2020 11:11:27 +0000 (12:11 +0100)]
Release 0.1.39

* Replace sqlcipher with upstream 4.4.2
* Unit tests improvements
* Small fixes

Change-Id: I94a213c7b122c0867915c38c14ebb25db1258420

3 years agoChange DB access credentials variable name 57/249457/2
Tomasz Swierczek [Fri, 11 Dec 2020 14:28:51 +0000 (15:28 +0100)]
Change DB access credentials variable name

Change-Id: I8aa5a80fc082049dda9697b3b648a53e351b1a0b

3 years agoUpgrade to sqlcipher 4.4.2 80/249280/1 accepted/tizen/unified/20201214.124456 submit/tizen/20201211.092147
Dariusz Michaluk [Tue, 8 Dec 2020 15:24:46 +0000 (16:24 +0100)]
Upgrade to sqlcipher 4.4.2

Change-Id: I7ca21a3c9ce5618463173ed444c73d6361f405d8

3 years ago[NOT COMPILING] Replace sqlcipher with upstream 4.4.2 79/249279/1
Dariusz Michaluk [Tue, 8 Dec 2020 14:57:43 +0000 (15:57 +0100)]
[NOT COMPILING] Replace sqlcipher with upstream 4.4.2

Change-Id: I6afb8cb44fb932ff01d1a29877717f909e178948

3 years agoFix UB in LogSystem 65/249065/2
Krzysztof Jackiewicz [Fri, 4 Dec 2020 15:58:12 +0000 (16:58 +0100)]
Fix UB in LogSystem

Passing NULL to std::string constructor is an undefined behavior.

Check values returned from getenv() to avoid passing NULL to
std::string constructor. Use std::string when appropriate.

Update unit tests.

Change-Id: I56dd60f432c8e6e6033e9674601ced0b6432fc28

3 years agoFix negative CBC decryption test 50/248850/1
Krzysztof Jackiewicz [Wed, 2 Dec 2020 17:07:09 +0000 (18:07 +0100)]
Fix negative CBC decryption test

There's a high chance that the padding ^ 0x1 will produce a 0x01
trailing byte which happens to be a valid padding. In such case make
sure that the length of the decrypted data is different.

Change-Id: I60b7f9e708d850c49dbddbdda64ff178d730b4f7

3 years agoAutomate code coverage measurement - adjustment 05/243505/3
Dariusz Michaluk [Mon, 7 Sep 2020 16:16:17 +0000 (18:16 +0200)]
Automate code coverage measurement - adjustment

To gather unit tests coverage report:
- use COVERAGE build_type,
- instal key-manager-coverage rpm,
- run key-manager-coverage.sh script.

Change-Id: I6d2efd2bcec79a37a45ed56ca9efa148de13be4e

3 years agoFix misplaced parentheses in error code comparison 24/245224/1
Mateusz Cegielka [Mon, 5 Oct 2020 15:18:13 +0000 (17:18 +0200)]
Fix misplaced parentheses in error code comparison

Some newer SVACE version I happened to run locally detected misplaced
parentheses here. Fortunately, this would only result in returning a
wrong error code and not ignoring the error.

I have fixed the mistake, also removing the use of an assignment in an
if statement because there is no reason to do so.

Change-Id: I441e882ffbd484b6a7ec47eeaf5999b5e7992cd7

3 years agoMake custom unique_ptr deleters stateless 82/243182/6
Konrad Lipinski [Thu, 3 Sep 2020 17:29:58 +0000 (19:29 +0200)]
Make custom unique_ptr deleters stateless

Change-Id: Ic82b018c4c9c0ca3d3e10f1f9a0b3632aa79d670

3 years agoConstrain async tryCatch to Observer::ReceivedError 71/244271/1
Konrad Lipinski [Wed, 16 Sep 2020 12:42:23 +0000 (14:42 +0200)]
Constrain async tryCatch to Observer::ReceivedError

Change-Id: I360bc2a70aafa7436f4b7a7f4917c26d32a10e13

3 years agoShrink ManagerAsync::Impl code 76/243176/5
Konrad Lipinski [Thu, 3 Sep 2020 16:19:46 +0000 (18:19 +0200)]
Shrink ManagerAsync::Impl code

Change-Id: I84d18c8e965c2a430332b9a6b55d95f48ae707eb

3 years agoDeduplicate exception handling in CKMLogic a wee bit 54/243054/5
Konrad Lipinski [Wed, 2 Sep 2020 17:55:07 +0000 (19:55 +0200)]
Deduplicate exception handling in CKMLogic a wee bit

Change-Id: I330fc80d01393a7709fb3b4c05c563de96681e66

3 years agoTurn some CKMLogic members into free functions 53/243053/5
Konrad Lipinski [Wed, 2 Sep 2020 16:18:05 +0000 (18:18 +0200)]
Turn some CKMLogic members into free functions

Change-Id: I4748050fb0476d0406c5b0ea117f0bc579522d10

3 years agoShrink client manager impl a bit 52/243052/5
Konrad Lipinski [Wed, 2 Sep 2020 15:30:02 +0000 (17:30 +0200)]
Shrink client manager impl a bit

Change-Id: I766a79b2504b0d564db4b4b3811fcd8a176001af

3 years agoRefactor ocspDoVerify a bit 81/242681/8
Konrad Lipinski [Fri, 28 Aug 2020 17:25:28 +0000 (19:25 +0200)]
Refactor ocspDoVerify a bit

Change-Id: I717cf06ff6a7cbb34b12349ee305f19d2bab0deb

3 years agoShrink ocsp.h to a single free function 80/242680/5
Konrad Lipinski [Fri, 28 Aug 2020 11:56:08 +0000 (13:56 +0200)]
Shrink ocsp.h to a single free function

Change-Id: I36188ddfa3c0678a1a53fad6b4048cfaa6e9afdb

3 years agoDeduplicate client manager impl de/serialization 52/242552/6
Konrad Lipinski [Thu, 27 Aug 2020 18:29:24 +0000 (20:29 +0200)]
Deduplicate client manager impl de/serialization

Change-Id: Iddcc5b42250584b7bed73a8ab6f64e0b61bd3520

3 years agoForward retCode in alias vector getters 70/244270/1
Konrad Lipinski [Wed, 16 Sep 2020 10:56:09 +0000 (12:56 +0200)]
Forward retCode in alias vector getters

Change-Id: I16c94d941ed145fa93de359327bc6c8717578d89

3 years agoDeduplicate client manager impl deserialization 51/242551/4
Konrad Lipinski [Thu, 27 Aug 2020 15:21:41 +0000 (17:21 +0200)]
Deduplicate client manager impl deserialization

Change-Id: I9205aac1c97dd1d9a4f16caffdd24e6e7b1f2b85

3 years agoDeduplicate sw backend keyPair creation 50/242550/4
Konrad Lipinski [Thu, 27 Aug 2020 14:03:41 +0000 (16:03 +0200)]
Deduplicate sw backend keyPair creation

Change-Id: Iff7d579d02e54e841140ba419aa6fffd19086dd3

3 years agoDeduplicate ckmc_get_*_alias_list 49/242549/4
Konrad Lipinski [Thu, 27 Aug 2020 13:08:47 +0000 (15:08 +0200)]
Deduplicate ckmc_get_*_alias_list

Change-Id: I0d2906da9ee277ff77787a4d5fe8945b46be4557

3 years agoPrevent some CAPI exception leakage 48/242548/4
Konrad Lipinski [Mon, 14 Sep 2020 13:10:02 +0000 (15:10 +0200)]
Prevent some CAPI exception leakage

Change-Id: Ic9fb8985f6052479e7c9c6e24cf24607f34e3526

3 years agoRefactor base64 implementation 19/240019/8
Mateusz Cegielka [Fri, 31 Jul 2020 11:12:52 +0000 (13:12 +0200)]
Refactor base64 implementation

This codebase contains two slightly different base64 encoding wrappers,
both using low-level OpenSSL BIO API. The wrappers provide access to a
streaming interface, despite the fact that this property is not used
anywhere. To handle errors, the wrappers sometimes use exceptions and
sometimes return codes. To implement this, a stateful class was used,
and these four facts resulted in needlessly verbose code.

I have merged the two implementations and simplified them to two free
functions. The encode function now uses higher-level OpenSSL EVP API,
and the decode function was refactored.

Change-Id: I5016723158321d0c1aa10810aa9067cd2249f38e

3 years agoOptimize, fix memory zeroing and refactor BinaryQueue 70/240670/6
Mateusz Cegielka [Mon, 10 Aug 2020 11:24:35 +0000 (13:24 +0200)]
Optimize, fix memory zeroing and refactor BinaryQueue

BinaryQueue is a class responsible for buffering data received from
sockets before deserialization, vendored from DPL. It stores the
received data as a list of blocks, which is probably the optimal
approach given the constraints of the services framework here. However,
its implementation is a little inefficient and incorrect:

- Stores data in std::vector<unsigned char> instead of RawBuffer.
  Because of that, any piece of data that passes through a socket may
  live in memory much longer than it should.
- Erases elements from the front of a std::vector. This means all the
  other elements need to be shifted, which could even result in
  quadratic complexity given large enough socket reads and small enough
  messages.
- Always copies incoming data. This means all of incoming traffic has to
  be copied one more time than it needs to.

I have fixed the first issue in the obvious way. To fix the second
issue, I have added a new member that tracks how many bytes have been
read from the first bucket in the queue, which makes physically erasing
elements from the vector unnecessary. Lastly, I changed the push
signature from taking a pointer and a size to taking a RawBuffer&&,
which eliminated some copies and made the remaining ones more explicit.

Change-Id: I36932d5492815e38bf1cdab249327d26c9805ac6

3 years agoOptimize message serialization 69/240669/5
Mateusz Cegielka [Mon, 10 Aug 2020 11:24:30 +0000 (13:24 +0200)]
Optimize message serialization

There is a MessageBuffer class, which stores a list of byte slices as
std::list<std::vector<unsigned char>> and can be used for serializing
structs. Every member calls a Write method, which creates a new vector
and appends it to the list. After the list is built, a vector with an
exactly right size is allocated and the data is copied. Also, the class
contains unnecessary mutable state, because the logic is shared with
streaming deserialization.

I have replaced the serialization methods with a single function, which
serializes all objects twice. The first pass ignores the data and only
computes the message size, which allows the second pass that actually
writes the data to only use a single allocation. The new interface is
also simpler and more robust.

Change-Id: I6091b71083997faf9302ad8549ade467deb23a58

3 years agoAdd automatic data decryption to ckm_db_tool 31/238831/14
Mateusz Cegielka [Fri, 17 Jul 2020 15:30:16 +0000 (17:30 +0200)]
Add automatic data decryption to ckm_db_tool

The key manager stores key data in an encrypted database. The project
also contains a ckm_db_tool CLI utility, which decrypts the database and
launches an interactive SQL shell. However, inside the decrypted
database, the data column is still encrypted with application-specific
keys. This is inconvenient during debugging, as there is no easy way to
see the data. Also, decrypting some objects' data may require
object-specific passwords.

This patch adds a --decrypt flag, which automatically decrypts contents
of any column called "data" in all SQL query results. Additionally, if
decryption of an object requires a password, it prompts the user to
enter the password and uses it to decrypt the object's data.

The implementation finds "data", "dataType" and "idx" columns in the
output, assumes they come from the "objects" table, and uses the three
values to fetch and decrypt object data with existing CKM APIs. All rows
are prefixed with a message detailing whether the decryption was
successful.

Change-Id: I01462c5d3b24a0d7a2fea92446c4e46949b1b4f4

3 years agoAdd consistent error messages to ckm_db_tool 00/239200/8
Mateusz Cegielka [Wed, 22 Jul 2020 09:23:37 +0000 (11:23 +0200)]
Add consistent error messages to ckm_db_tool

ckm_db_tool is a set of CLI utilities for debugging key-manager. Various
displayed error messages are inconsistent, do not display all available
information, and contain minor gramatical errors. Also, new interactive
features are planned to be introduced, which will require reading and
writing more information to the terminal.

A simple helper functions has been created for displaying error, warning
and info messages. All error messages have been changed to use them,
received grammar fixes, started displaying APICodeToString result when
possible, and rewritten to follow a consistent style. Finally, warning
and askPassword functions were implemented to prepare for next patches.

Change-Id: Ifd0608637f3f4ef3ce31c2fe7c79074da9a93bbb

3 years agoRemove CryptoExt class in favor of friendship 49/239049/10
Mateusz Cegielka [Mon, 20 Jul 2020 15:59:15 +0000 (17:59 +0200)]
Remove CryptoExt class in favor of friendship

In the ckm_db_tool CLI helper project, CKMLogicExt and CryptoExt classes
are responsible for breaking encapsulation of CKMLogic and Crypto
classes. However, code used for extracting a Crypto member and casting
it to the CryptoExt type is repeated two times (soon three), and rather
dangerous.

This refactor makes CKMLogicExt a friend of the Crypto class. This makes
it possible to implement additional methods directly in CKMLogicExt
without doing dangerous slicing object casts.

Change-Id: Ice7261b76f46f9a6206f7ae1faded1f3d8e359cb

3 years agoChange safe-buffer test structure 32/240232/3
Mateusz Cegielka [Tue, 4 Aug 2020 13:29:11 +0000 (15:29 +0200)]
Change safe-buffer test structure

test_safe-buffer.cpp contains tests that ensure std::vector fails to
erase possibly confidential memory when its destructor is called, which
try to make sure the SafeBuffer testing method is valid. Since the
SafeBuffer test results may be completely wrong if these tests fail, it
would be better to merge them into one test to avoid misleading results.

I have merged the 4 tests into a single test and added some comments.

Change-Id: I9d58a7a3942a0318c0fa96047a1bdb7e708a69d4

3 years agoMove Token and CryptoBackend to common 31/240031/3
Mateusz Cegielka [Fri, 31 Jul 2020 14:13:33 +0000 (16:13 +0200)]
Move Token and CryptoBackend to common

Both Token and CryptoBackend are small types used on the server, both in
the crypto and the service modules. They are defined in the service
module, and crypto submodules have to include these headers. Other than
that, the crypto module is not aware of the service module, and creating
an unnecessary cyclic dependency here shows up in static analysis.

Since they are minor types which don't contain any logic and are used in
different contexts in different modules, I have moved them to the
src/manager/common directory.

Change-Id: Ifd55ec97173b6e99c9c2fec154803dccfa48a1ae

3 years agoRemove most CommunicationManager tests 25/240225/1
Mateusz Cegielka [Tue, 4 Aug 2020 11:13:11 +0000 (13:13 +0200)]
Remove most CommunicationManager tests

CommunicationManager is a class responsible for adding std::functions to
a std::vector, and calling all of them with an argument (this takes 4
lines of actual logic). However, it has 7 redundant tests, including a
randomized stress test and some interesting helper classes.

I have reduced this number to 2 simple tests, testing basic and
exception-related behavior.

Change-Id: Ie8ce196df1f0e2a1c280c7aad4bd36c5911a6ada

3 years agoRemove unused Stringify macro variants 24/240224/1
Mateusz Cegielka [Tue, 4 Aug 2020 11:07:54 +0000 (13:07 +0200)]
Remove unused Stringify macro variants

Stringify is a helper macro used for formatting variadic arguments to a
string in error messages. The code also contains unused StringifyAvoid,
StringifyDebug and StringifyError macros.

I have removed the unused macros and their tests.

Change-Id: I08d00480a2e6ba73ba1a6c573c7afc4fccc36500

3 years agoImprove KeyProvider tests 42/238842/2
Krzysztof Jackiewicz [Fri, 17 Jul 2020 20:32:21 +0000 (22:32 +0200)]
Improve KeyProvider tests

More negative tests added. Existing tests refactored and fixed where necessary.
Redundant check removed from KeyProvider ctor.

Change-Id: I5210c0f4c79851543c0f9dcb532a30aa7dc8168f

3 years agoRemove KeyProvider lib initialization from tests 41/238841/2
Krzysztof Jackiewicz [Fri, 17 Jul 2020 14:57:46 +0000 (16:57 +0200)]
Remove KeyProvider lib initialization from tests

It's a NOOP on tizen.org.

Change-Id: I915bba5e55a6f21925c363687b1990d24bf2f2cf

3 years agoAdd negative forEachFile tests 12/238812/2
Krzysztof Jackiewicz [Fri, 17 Jul 2020 12:11:56 +0000 (14:11 +0200)]
Add negative forEachFile tests

Change-Id: Ic4869009234676967e3571868ad2fa1e1d950c6a

3 years agoException tests refactoring 09/238809/2
Krzysztof Jackiewicz [Fri, 17 Jul 2020 11:52:17 +0000 (13:52 +0200)]
Exception tests refactoring

* Positive tests merged into one.
* Macros replaced with templates.
* Missing exceptions added.

Change-Id: Ia2da4262e874119a70940c1005d7c018aea9641b

3 years agoAdd negative DescriptorSet tests 04/238804/2
Krzysztof Jackiewicz [Fri, 17 Jul 2020 10:12:29 +0000 (12:12 +0200)]
Add negative DescriptorSet tests

Change-Id: Idfb7dcd64c17aab418380a8fdb5b807a67710239

3 years agoMove db perf tests to a separate exec 27/238627/2
Krzysztof Jackiewicz [Wed, 15 Jul 2020 19:25:26 +0000 (21:25 +0200)]
Move db perf tests to a separate exec

Performance tests are not unit tests and do not improve code coverage. Also
they are all "positive". This commit moves them to a separate binary.

Also fixed performance calculation and few other minor issues.

Code slightly refactored.

Change-Id: Ifcf2463be28001a0e88e5127dd95ee081771382a

3 years agoImprove DB::Crypto negative test ratio 26/238626/1
Krzysztof Jackiewicz [Wed, 15 Jul 2020 14:57:51 +0000 (16:57 +0200)]
Improve DB::Crypto negative test ratio

Redundant positive tests removed.
Negative constructor tests added.

Change-Id: Ic1c2d30d4121c4e901485cae63cb7a203865af7d

3 years agoGet rid of the openssl 1.0.2 specific code 11/238511/1
Krzysztof Jackiewicz [Tue, 14 Jul 2020 16:21:34 +0000 (18:21 +0200)]
Get rid of the openssl 1.0.2 specific code

Also move entropy initialization to key-manager-main.cpp where it is used.

Change-Id: I187c76565b3864b6042a31a6eb71ac5921dc1ffd

3 years agoMake BeginTransaction exclusive and use it 10/238510/1
Krzysztof Jackiewicz [Tue, 14 Jul 2020 15:32:32 +0000 (17:32 +0200)]
Make BeginTransaction exclusive and use it

Change-Id: Ie37fb0a36c25079eadab374093065f1e466d22f9

3 years agoRemove unused SqlConnection::DataCommand::Reset 09/238509/1
Krzysztof Jackiewicz [Tue, 14 Jul 2020 15:31:44 +0000 (17:31 +0200)]
Remove unused SqlConnection::DataCommand::Reset

Change-Id: Ib4279ccd14c6066efc980ec00bd63e76b699ca6a

3 years agoImprove DB::Crypto code coverage 12/238412/2
Krzysztof Jackiewicz [Tue, 7 Jul 2020 07:14:35 +0000 (09:14 +0200)]
Improve DB::Crypto code coverage

Change-Id: I0fcb65833641ef75ab2af3c265e15df4d45231b6

3 years agoReturn if there are no rows to save 08/238508/1
Krzysztof Jackiewicz [Tue, 14 Jul 2020 14:35:48 +0000 (16:35 +0200)]
Return if there are no rows to save

Before this change, an attempt to save an empty list of objects would populate
the NAME and PERMISSIONS table but insert no objects into the OBJECTS table.

Change-Id: I08a2b68831ed51564e43ef4a01fca28d2c789641

3 years agoRemove unused DB::Crypto methods 13/237913/5
Krzysztof Jackiewicz [Mon, 6 Jul 2020 10:55:32 +0000 (12:55 +0200)]
Remove unused DB::Crypto methods

Change-Id: Ie9f54b02736f1eebd72a496f87e250bbdd48b7aa

3 years agoAdd unit tests related to Pkcs 12 02/237602/6
Krzysztof Jackiewicz [Wed, 1 Jul 2020 20:53:14 +0000 (22:53 +0200)]
Add unit tests related to Pkcs 12

* Implement unit tests.
* Add p12 test files for different types of keys.
* Slightly refactor PKCS12Serializable API.

Change-Id: I87e4d9ee50e75aff8cc4e042bb239983a1f3c4d9

3 years agoSW backend unit tests 78/235778/14
Krzysztof Jackiewicz [Tue, 9 Jun 2020 16:27:23 +0000 (18:27 +0200)]
SW backend unit tests

Also:
* Hide SW::Internals functions unused outside and add few asserts.
* Add missing openssl errors.
* Properly handle rsa encryption output.
* Properly handle missing asymmetric key.
* Old partial tests replaced.
* Minor code cleanup.

Change-Id: I1f83f6dc6bcdc99708b2f1f081b4be6fef8a4b08

3 years agoUnwrap 4 lines in SW::Internals to make them covered 66/237366/2
Krzysztof Jackiewicz [Mon, 29 Jun 2020 16:33:32 +0000 (18:33 +0200)]
Unwrap 4 lines in SW::Internals to make them covered

Seriously.

Also remove one duplicated line exposed thanks to the lcov flaw.

Change-Id: If2c9ac01db6bbccf2e30a7d9ccecfbda9c2994ee

3 years agoInstall all source files with coverage package 65/237365/2
Krzysztof Jackiewicz [Mon, 29 Jun 2020 16:09:33 +0000 (18:09 +0200)]
Install all source files with coverage package

We only need to calculate code coverage for code in src subdirectory. However,
if unit-tests sourcess are not provided, the lcov fails to notice some of the
covered code paths in header files.

This commit installs all the sources, but removes irrelevant ones from the
report. It adds ~ +5% and +10% to line and function coverage respectively.

Change-Id: If17259ee4b8b76b8c7060c8d49ec92577d997eaf

3 years agoCoverage only mode 68/235868/3
Krzysztof Jackiewicz [Fri, 22 May 2020 14:47:26 +0000 (16:47 +0200)]
Coverage only mode

Additional "COVERAGE_ONLY" build type for skipping key-manager binaries and
RPMs. Translates to debug build with additional "coverage_only" flag.

Build key-manager with --define "build_type COVERAGE_ONLY".

Change-Id: I1e4a762b14d611ea6ad170f8b63f13af541fd8b1

3 years agoRemove key-manager requirement from unit tests 15/236215/1
Krzysztof Jackiewicz [Mon, 15 Jun 2020 15:06:26 +0000 (17:06 +0200)]
Remove key-manager requirement from unit tests

Unit tests package does not require key-manager anymore.

Change-Id: Ia9de48c188b4b9ca63cc53721c58f25ccc4ec4fc

3 years agoAutomate code coverage measurement 67/235867/2
Krzysztof Jackiewicz [Fri, 22 May 2020 14:47:26 +0000 (16:47 +0200)]
Automate code coverage measurement

* Unit-tests built and linked with coverage flags in debug mode only.
* Separate rpm for code coverage built in debug mode only, including:
** All the *.cpp and *.h files in /home/abuild/... in case lcov needs them
   (missing files issue).
** All the key-manager's *.gcno files produced during compilation
   (test/tools/misc files skipped).
** A helper script taking care of whole code coverage measurement, that is:
*** Removing old *.gcda files.
*** Launching internal test.
*** Gathering runtime *.gcda files.
*** Preparing a report with lcov. Fails if any error or warning is reported
    (e.g. a missing file warning). Files external to the project are excluded.
*** Preparing an html report based on lcov output.

Usage:
* Build key-manager in debug mode mode.
* Install the key-manager-unit-tests and key-manager-coverage RPMs.
* Execute ckm-coverage.sh to produce lcov html report.

Change-Id: I5118b8ffba05e40d05e732c5162bd924a2f24120

3 years agoImprove KeyImpl & KeyAesImpl code coverage 73/235573/7
Krzysztof Jackiewicz [Fri, 5 Jun 2020 19:50:34 +0000 (21:50 +0200)]
Improve KeyImpl & KeyAesImpl code coverage

Also unify key API.

KeyAesImpl() will now return an empty object instead of throwing. This will
unify the error code returned for symmetric and asymmetric keys from
ckmc_get_key(). It will also fix asynchronous C++ API. Observer will receive
an empty key instead of not being called at all.

Unify the type returned from empty keys. C++ API is a platform one and
getType() function is not used in tizen.org according to CodeGrok.

Change-Id: I7de8f32dfe59b1c5af441dfb9a0b8bee5c0d0bcf

3 years agoReorganize project structure and RPM packages 36/234236/12
Krzysztof Jackiewicz [Fri, 22 May 2020 14:47:26 +0000 (16:47 +0200)]
Reorganize project structure and RPM packages

* Internal tests package and binary renamed.
* Scheme test moved to a separate binary as they are not actual unit tests.
  They use internal API, client library and need a running server. These tests
  should be rewritten.
* New key-manager-misc RPM containing scheme test binary and helper tools.
* Project structure reorganized to better fit rpm packages.
* CMakeFiles.txt refactoring.

Change-Id: I4875f0a7189a960f193747591cc917fd5b9e2799

3 years agoUpdate DataType unit-tests 30/232730/2
Krzysztof Jackiewicz [Thu, 7 May 2020 09:18:02 +0000 (11:18 +0200)]
Update DataType unit-tests

Change-Id: I1a15e4fa665fc8be551eea23bb997bd4aa869c82

3 years agoRefactor DataType related code 22/232722/6
Krzysztof Jackiewicz [Thu, 7 May 2020 08:27:08 +0000 (10:27 +0200)]
Refactor DataType related code

* Remove unnecessary DataType methods.
* Remove unnecessary Type enumeration scope.
* Make DataType serializable to avoid static casts.
* Use DataType checker methods instead of explicit DataType::Type comparison.

Change-Id: I01dc355050326ad1e40c34c869acbc07613c57db

3 years agoDon't return command in client-server communication 46/233046/3
Krzysztof Jackiewicz [Mon, 11 May 2020 18:49:53 +0000 (20:49 +0200)]
Don't return command in client-server communication

Client already has an id of the message sent to the server. There's no
point in returning the command from server and checking in on the
client's side.

* Stop returning command from server.
* Stop receiving and checking the command in the client.
* Unify naming.

Change-Id: I74bde065c5edcf414820b9c398d18e6bc0d299dd