Coverage only mode
[platform/core/security/key-manager.git] / packaging / key-manager.spec
1 %global watchdog_enabled 1
2 %global watchdog_timeout_sec 60
3 %global watchdog_notify_sec  20
4 %global tz_backend_enabled %{?tz_backend:%tz_backend}%{!?tz_backend:OFF}
5 %{!?build_type:%global build_type RELEASE}
6 %global coverage_only 0
7 %if %{build_type} == COVERAGE_ONLY
8     %global build_type DEBUG
9     %global coverage_only 1
10 %endif
11
12 Name:       key-manager
13 Summary:    Central Key Manager and utilities
14 Version:    0.1.38
15 Release:    1
16 Group:      Security/Secure Storage
17 License:    Apache-2.0 and BSD-3-Clause
18 Source0:    %{name}-%{version}.tar.gz
19 Source1001: key-manager-pam-plugin.manifest
20 Source1002: libkey-manager-client.manifest
21 Source1003: libkey-manager-client-devel.manifest
22 Source1004: libkey-manager-common.manifest
23 BuildRequires: cmake
24 BuildRequires: zip
25 BuildRequires: pkgconfig(dlog)
26 BuildRequires: pkgconfig(openssl1.1)
27 BuildRequires: libattr-devel
28 BuildRequires: pkgconfig(libsmack)
29 BuildRequires: pkgconfig(libsystemd-daemon)
30 BuildRequires: pkgconfig(libsystemd-journal)
31 BuildRequires: pkgconfig(libxml-2.0)
32 BuildRequires: pkgconfig(capi-system-info)
33 BuildRequires: pkgconfig(security-manager)
34 BuildRequires: pkgconfig(cynara-client-async)
35 BuildRequires: pkgconfig(cynara-creds-socket)
36 BuildRequires: pkgconfig(libtzplatform-config)
37 BuildRequires: pkgconfig(glib-2.0)
38 BuildRequires: pkgconfig(pkgmgr)
39 BuildRequires: pkgconfig(vconf)
40 BuildRequires: pkgconfig(sqlcipher)
41 %if 0%{?watchdog_enabled}
42 BuildRequires: pkgconfig(argos_watchdog)
43 %endif
44 BuildRequires: boost-devel
45 BuildRequires: ca-certificates-devel
46 %if %{tz_backend_enabled} == ON
47 BuildRequires: key-manager-ta-devel
48 BuildRequires: key-manager-ta-serialization-devel
49 BuildRequires: pkgconfig(tef-libteec)
50 %endif
51 Requires: libkey-manager-common = %{version}-%{release}
52 BuildRequires: lcov
53
54 %{?systemd_requires}
55
56 %global user_name key-manager
57 %global group_name security_fw
58 %global supplementary_group_names key-manager
59 %global service_name key-manager
60 %global smack_domain_name System
61 %global old_rw_data_dir /opt/data/ckm
62 %global rw_data_dir %{?TZ_SYS_DATA:%TZ_SYS_DATA/ckm}%{!?TZ_SYS_DATA:%old_rw_data_dir}
63 %global ro_data_dir %{?TZ_SYS_RO_SHARE:%TZ_SYS_RO_SHARE/ckm}%{!?TZ_SYS_RO_SHARE:%_datadir/ckm}
64 %global unit_tests_dir %{?TZ_SYS_DATA:%TZ_SYS_DATA/ckm-unit-tests}%{!?TZ_SYS_DATA:%/opt/data/ckm-unit-tests}
65 %global misc_dir %{?TZ_SYS_DATA:%TZ_SYS_DATA/ckm-misc}%{!?TZ_SYS_DATA:%/opt/data/ckm-misc}
66 %global coverage_dir %{?TZ_SYS_DATA:%TZ_SYS_DATA/ckm-coverage}%{!?TZ_SYS_DATA:%/opt/data/ckm-coverage}
67 %global bin_dir %{?TZ_SYS_BIN:%TZ_SYS_BIN}%{!?TZ_SYS_BIN:%_bindir}
68 # image creation error occured if /usr/sbin used for ldconfig
69 #%global sbin_dir %{?TZ_SYS_SBIN:%TZ_SYS_SBIN}%{!?TZ_SYS_SBIN:%_sbindir}
70 %global sbin_dir /sbin
71 %global ro_etc_dir %{?TZ_SYS_RO_ETC:%TZ_SYS_RO_ETC}%{!?TZ_SYS_RO_ETC:/etc}
72 %global run_dir %{?TZ_SYS_RUN:%TZ_SYS_RUN}%{!?TZ_SYS_RUN:/var/run}
73 %global initial_values_dir_ro %{ro_data_dir}/initial_values
74 %global initial_values_dir_rw %{rw_data_dir}/initial_values
75 %global ca_certs_dir %{?TZ_SYS_CA_CERTS:%TZ_SYS_CA_CERTS}%{!?TZ_SYS_CA_CERTS:%ro_etc_dir/ssl/certs}
76 %global dump_legacy_db_libname key-manager-dump-legacy-database
77
78 %description
79 Central Key Manager daemon could be used as secure storage
80 for certificate and private/public keys. It gives API for
81 application to sign and verify (DSA/RSA/ECDSA) signatures.
82
83 %package -n libkey-manager-common
84 Summary:    Central Key Manager (common libraries)
85 Group:      Security/Libraries
86 License:    Apache-2.0
87 Requires(post): %{sbin_dir}/ldconfig
88 Requires(postun): %{sbin_dir}/ldconfig
89
90 %description -n libkey-manager-common
91 Central Key Manager package (common library)
92
93 %package -n libkey-manager-client
94 Summary:    Central Key Manager (client)
95 Group:      Security/Libraries
96 License:    Apache-2.0
97 Requires:   key-manager = %{version}-%{release}
98 Requires:   libkey-manager-common = %{version}-%{release}
99 Requires(post): %{sbin_dir}/ldconfig
100 Requires(postun): %{sbin_dir}/ldconfig
101
102 %description -n libkey-manager-client
103 Central Key Manager package (client)
104
105 %package -n libkey-manager-client-devel
106 Summary:    Central Key Manager (client-devel)
107 Group:      Security/Development
108 License:    Apache-2.0
109 BuildRequires: pkgconfig(capi-base-common)
110 Requires:   pkgconfig(capi-base-common)
111 Requires:   libkey-manager-client = %{version}-%{release}
112
113 %description -n libkey-manager-client-devel
114 Central Key Manager package (client-devel)
115
116 %package -n key-manager-unit-tests
117 Summary:    Unit tests for key-manager
118 Group:      Security/Testing
119 License:    Apache-2.0 and BSL-1.0
120 BuildRequires: pkgconfig(libxml-2.0)
121 Requires:   boost-test
122
123 %description -n key-manager-unit-tests
124 Unit tests for key-manager.
125
126 %package -n key-manager-misc
127 Summary:    Miscellaneous tools and tests for key-manager
128 Group:      Security/Testing
129 License:    Apache-2.0 and BSL-1.0
130 Requires:   boost-test
131 Requires:   key-manager = %{version}-%{release}
132
133 %description -n key-manager-misc
134 Miscellaneous tools and tests for key-manager.
135
136 %package -n key-manager-pam-plugin
137 Summary:    CKM login/password module to PAM
138 Group:      Security/Libraries
139 License:    Apache-2.0
140 BuildRequires: pam-devel
141 Requires:   key-manager = %{version}-%{release}
142 Requires(post): %{sbin_dir}/ldconfig
143 Requires(postun): %{sbin_dir}/ldconfig
144
145 %description -n key-manager-pam-plugin
146 CKM login/password module to PAM. Used to monitor user login/logout
147 and password change events from PAM
148
149 %package -n key-manager-initial-values
150 Summary:    CKM initial values tool
151 Group:      Security/Libraries
152 License:    Apache-2.0
153 BuildRequires: cmake
154 BuildRequires: pkgconfig(openssl1.1)
155 BuildRequires: pkgconfig(libxml-2.0)
156 Requires(post): %{sbin_dir}/ldconfig
157 Requires(postun): %{sbin_dir}/ldconfig
158
159 %description -n key-manager-initial-values
160 Includes ckm_initial_values tool for initial values XML generation
161
162 %package -n key-manager-coverage
163 Summary:    Central Key Manager code coverage data
164 Group:      Security/Testing
165 License:    Apache-2.0
166 Requires:      key-manager-unit-tests
167 Requires:      lcov
168 Requires:      gcc
169
170 %description -n key-manager-coverage
171 Central Key Manager code coverage data
172
173 %prep
174 %setup -q
175
176 %build
177 %if 0%{?sec_build_binary_debug_enable}
178     export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
179     export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
180 %endif
181
182 export LDFLAGS+="-Wl,--rpath=%{_libdir},-Bsymbolic-functions"
183
184 %cmake . -DVERSION=%{version} \
185         -DCMAKE_BUILD_TYPE=%{build_type} \
186         -DCMAKE_VERBOSE_MAKEFILE=ON \
187         -DSYSTEMD_UNIT_DIR=%{_unitdir} \
188         -DSYSTEMD_ENV_FILE=%{ro_etc_dir}"/sysconfig/central-key-manager" \
189         -DRUN_DIR:PATH=%{run_dir} \
190         -DSERVICE_NAME=%{service_name} \
191         -DUSER_NAME=%{user_name} \
192         -DGROUP_NAME=%{group_name} \
193         -DSUPPLEMENTARY_GROUP_NAMES="%{supplementary_group_names}" \
194         -DSMACK_DOMAIN_NAME=%{smack_domain_name} \
195         -DOLD_RW_DATA_DIR=%{old_rw_data_dir} \
196         -DRW_DATA_DIR=%{rw_data_dir} \
197         -DRO_DATA_DIR=%{ro_data_dir} \
198         -DRW_ETC_DIR=%{rw_etc_dir} \
199         -DRO_ETC_DIR=%{ro_etc_dir} \
200         -DBIN_DIR=%{bin_dir} \
201         -DINITIAL_VALUES_DIR_RW=%{initial_values_dir_rw} \
202         -DINITIAL_VALUES_DIR_RO=%{initial_values_dir_ro} \
203         -DCA_CERTS_DIR=%{ca_certs_dir} \
204 %if 0%{?watchdog_enabled}
205         -DWATCHDOG_ENABLED=%{watchdog_enabled} \
206         -DWATCHDOG_TIMEOUT_SEC=%{watchdog_timeout_sec} \
207         -DWATCHDOG_NOTIFY_SEC=%{watchdog_notify_sec} \
208 %endif
209 %if %{tz_backend_enabled} == ON
210         -DTZ_BACKEND_ENABLED=ON \
211 %else
212         -DTZ_BACKEND_ENABLED=OFF \
213 %endif
214         -DUNIT_TESTS_DIR=%{unit_tests_dir} \
215         -DMISC_DIR=%{misc_dir} \
216         -DCOVERAGE_DIR=%{coverage_dir} \
217 %if %{coverage_only}
218         -DCOVERAGE_ONLY=ON \
219 %endif
220         -DDUMP_LEGACY_DB_LIBNAME=%{dump_legacy_db_libname}
221
222 make %{?jobs:-j%jobs}
223
224 %install
225 %make_install
226
227 ###############################################################################
228 %if ! %{coverage_only}
229 ###############################################################################
230
231 %install_service multi-user.target.wants central-key-manager.service
232 %install_service sockets.target.wants central-key-manager-api-control.socket
233 %install_service sockets.target.wants central-key-manager-api-storage.socket
234 %install_service sockets.target.wants central-key-manager-api-ocsp.socket
235 %install_service sockets.target.wants central-key-manager-api-encryption.socket
236 cp -a %{SOURCE1001} %{SOURCE1002} %{SOURCE1003} %{SOURCE1004} %{buildroot}%{_datadir}/
237
238 #################### ! %{coverage_only} #######################################
239 %endif
240 ###############################################################################
241
242 %pre
243 # tzplatform-get sync breaked because of on-development situation. comment out just for temporary
244 # fail if runtime dir variable is different than compilation time variable
245 #if [ `tzplatform-get TZ_SYS_DATA | cut -d'=' -f2` != %{TZ_SYS_DATA} ]
246 #then
247 #    echo "Runtime value of TZ_SYS_DATA is different than the compilation time value. Aborting"
248 #    exit 1
249 #fi
250 #if [ `tzplatform-get TZ_SYS_RO_SHARE | cut -d'=' -f2` != %{TZ_SYS_RO_SHARE} ]
251 #then
252 #    echo "Runtime value of TZ_SYS_RO_SHARE is different than the compilation time value. Aborting"
253 #    exit 1
254 #fi
255
256 ## backup plan for manage key-manager user/group is deprecated b/c pwdutils package
257 ## would be excluded from binary
258 # User/group (key-manager/key-manager) should be already added in passwd package.
259 # This is our backup plan if passwd package will not be configured correctly.
260 #id -g %{group_name} > /dev/null 2>&1
261 #if [ $? -eq 1 ]; then
262 #    groupadd %{group_name} -r > /dev/null 2>&1
263 #fi
264 #
265 #id -u %{user_name} > /dev/null 2>&1
266 #if [ $? -eq 1 ]; then
267 #    useradd -d /var/lib/empty -s %{sbin_dir}/nologin -r -g %{group_name} %{user_name} > /dev/null 2>&1
268 #fi
269
270 %post
271 # move data from old path to new one
272 # we have to assume that in case of TZ_SYS_DATA change some upgrade script will move all the data
273 if [ -d "%{old_rw_data_dir}" ] && [ "%{rw_data_dir}" != "%{old_rw_data_dir}" ]
274 then
275     echo "Migrating old rw data to new rw data dir"
276     cp -a %{old_rw_data_dir}/. %{rw_data_dir}/ && rm -rf %{old_rw_data_dir}
277 fi
278
279 systemctl daemon-reload
280 if [ $1 = 1 ]; then
281     # installation
282     systemctl start central-key-manager.service
283 fi
284
285 if [ $1 = 2 ]; then
286     # update
287
288     # In ckm version <= 0.1.18 all files were owned by root.
289     find %{rw_data_dir} -exec chsmack -a %{smack_domain_name} {} \;
290     chown %{user_name}:%{group_name} -R %{rw_data_dir}
291     systemctl restart central-key-manager.service
292 fi
293
294
295 %preun
296 if [ $1 = 0 ]; then
297     # unistall
298     systemctl stop central-key-manager.service
299 fi
300
301 %postun
302 if [ $1 = 0 ]; then
303     # unistall
304     systemctl daemon-reload
305 fi
306
307 %post -n libkey-manager-common -p %{sbin_dir}/ldconfig
308 %post -n libkey-manager-client -p %{sbin_dir}/ldconfig
309 %postun -n libkey-manager-common -p %{sbin_dir}/ldconfig
310 %postun -n libkey-manager-client -p %{sbin_dir}/ldconfig
311
312 ###############################################################################
313 %if ! %{coverage_only}
314 ###############################################################################
315
316 %files -n key-manager
317 %manifest key-manager.manifest
318 %license LICENSE
319 %license LICENSE.BSD-3-Clause
320 %{bin_dir}/key-manager
321 %{_libdir}/lib%{dump_legacy_db_libname}.so
322 %{_unitdir}/multi-user.target.wants/central-key-manager.service
323 %{_unitdir}/central-key-manager.service
324 %{_unitdir}/sockets.target.wants/central-key-manager-api-control.socket
325 %{_unitdir}/central-key-manager-api-control.socket
326 %{_unitdir}/sockets.target.wants/central-key-manager-api-storage.socket
327 %{_unitdir}/central-key-manager-api-storage.socket
328 %{_unitdir}/sockets.target.wants/central-key-manager-api-ocsp.socket
329 %{_unitdir}/central-key-manager-api-ocsp.socket
330 %{_unitdir}/sockets.target.wants/central-key-manager-api-encryption.socket
331 %{_unitdir}/central-key-manager-api-encryption.socket
332 %dir %{ro_data_dir}
333 %{ro_data_dir}/*
334 %dir %attr(770, %{user_name}, %{group_name}) %{rw_data_dir}
335 %dir %attr(550, %{user_name}, %{group_name}) %{initial_values_dir_ro}
336 %dir %attr(770, %{user_name}, %{group_name}) %{initial_values_dir_rw}
337 %attr(755,root,root) /usr/share/upgrade/scripts/295.key-manager_upgrade.sh
338
339 %{ro_etc_dir}/gumd/userdel.d/10_key-manager.post
340 %{bin_dir}/ckm_tool
341
342 %files -n key-manager-pam-plugin
343 %manifest %{_datadir}/key-manager-pam-plugin.manifest
344 %license LICENSE
345 %{_libdir}/security/pam_key_manager_plugin.so*
346
347 %files -n libkey-manager-common
348 %manifest %{_datadir}/libkey-manager-common.manifest
349 %license LICENSE
350 %{_libdir}/libkey-manager-common.so.*
351
352 %files -n libkey-manager-client
353 %manifest %{_datadir}/libkey-manager-client.manifest
354 %license LICENSE
355 %{_libdir}/libkey-manager-client.so.*
356 %{_libdir}/libkey-manager-control-client.so.*
357
358 %files -n libkey-manager-client-devel
359 %manifest %{_datadir}/libkey-manager-client-devel.manifest
360 %license LICENSE
361 %{_libdir}/libkey-manager-client.so
362 %{_libdir}/libkey-manager-control-client.so
363 %{_libdir}/libkey-manager-common.so
364 %{_includedir}/ckm/ckm/ckm-manager.h
365 %{_includedir}/ckm/ckm/ckm-manager-async.h
366 %{_includedir}/ckm/ckm/ckm-certificate.h
367 %{_includedir}/ckm/ckm/ckm-control.h
368 %{_includedir}/ckm/ckm/ckm-error.h
369 %{_includedir}/ckm/ckm/ckm-key.h
370 %{_includedir}/ckm/ckm/ckm-password.h
371 %{_includedir}/ckm/ckm/ckm-pkcs12.h
372 %{_includedir}/ckm/ckm/ckm-raw-buffer.h
373 %{_includedir}/ckm/ckm/ckm-type.h
374 %{_includedir}/ckm/ckm/ckm-zero-memory.h
375 %{_includedir}/ckm/ckmc/ckmc-manager.h
376 %{_includedir}/ckm/ckmc/ckmc-control.h
377 %{_includedir}/ckm/ckmc/ckmc-error.h
378 %{_includedir}/ckm/ckmc/ckmc-type.h
379 %{_libdir}/pkgconfig/*.pc
380
381 %files -n key-manager-initial-values
382 %license LICENSE
383 %{bin_dir}/ckm_initial_values
384
385 %files -n key-manager-misc
386 %manifest key-manager-misc.manifest
387 %license LICENSE
388 %license LICENSE.BSL-1.0
389 %{bin_dir}/ckm-scheme-test
390 %{bin_dir}/ckm_so_loader
391 %{bin_dir}/ckm_db_tool
392 %{bin_dir}/ckm_db_merge
393 %{bin_dir}/ckm_generate_db
394 %misc_dir
395
396 #################### ! %{coverage_only} #######################################
397 %endif
398 ###############################################################################
399
400 %files -n key-manager-unit-tests
401 %manifest key-manager-unit-tests.manifest
402 %license LICENSE
403 %license LICENSE.BSL-1.0
404 %{bin_dir}/ckm-unit-tests
405 %unit_tests_dir
406
407 ###############################################################################
408 %if %{build_type} == DEBUG
409 ###############################################################################
410
411 %files -n key-manager-coverage
412 %license LICENSE
413 %{bin_dir}/key-manager-coverage.sh
414 %{_builddir}/%{name}-%{version}
415 %coverage_dir
416
417 #################### %{build_type} == DEBUG ###################################
418 %endif
419 ###############################################################################