summaryrefslogtreecommitdiff
path: root/source/directories.rst
blob: 73e436500a05092f98adecb6893b84592bc9917e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
===================
Directory structure
===================

root Directory
==============

The root directory contains

- a :file:`.gitignore` file with a list of excluded files
- a :file:`LICENSE` file the `GPL`_ license text
- a :file:`README` file with very rudimentary documentation stating the
  license and a list of system requirements

.. _GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0

.. index:: cgi-bin

Directory :file:`cgi-bin`
=========================

The `cgi-bin` directory contains

.. index:: PHP

.. _cgi-bin-siteseal-cgi:

- :file:`siteseal.cgi` a PHP CGI script that generates some JavaScript code
  to invoke :ref:`sealgen.php <www-sealgen-php>`. The configuration on
  www.cacert.org does not seem to support this script
  https://www.cacert.org/cgi-bin/siteseal.cgi returns a 403 response.

.. todo: check whether this is linked anywhere or can be removed

.. index:: commModule
.. index:: Perl
.. index:: bash

Directory :file:`CommModule`
============================

This directory contains the CommModule that is implemented in Perl:

.. _commmodule-client-pl:

- :file:`client.pl` the :doc:`signer protocol <signer>` client, running
  on the webserver and talking to the server via a serial link.

  The style of the Perl code seems a bit inconsistent (mix of uppercase and
  lowercase function names, usage of brackets). The code uses database polling
  in a loop. It might be a better idea to use some kind of queueing (Redis,
  AMQP, ...) to not waste resources when there is nothing to do). Function
  parameters are not named which makes the code hard to read.

  The script calls several system binaries that need to be present in
  compatible versions:

  - :program:`openssl`
  - :program:`xdelta`

  The script uses several Perl standard library modules as well as the
  following third party modules:

  .. index:: Perl, thirdparty

  - `DBD::mysql <https://metacpan.org/pod/DBD::mysql>`_
  - `DBI <https://metacpan.org/pod/DBI>`_
  - `Device::SerialPort <https://metacpan.org/pod/Device::SerialPort>`_
  - `File::CounterFile <https://metacpan.org/pod/File::CounterFile>`_

  The script references several openssl configuration files in the HandleCerts
  function that are not included in the code repository. There are some
  openssl configuration files with similar names in
  https://svn.cacert.org/CAcert/SystemAdministration/signer/

  The database password is parsed from
  :ref:`includes/mysql.php <includes-mysql-php>` and relies on the
  exact code that is defined there. Database name, user and host are hardcoded
  in the DBI->connect call.

  The script implements the client side of the signer protocol which is
  specified in :doc:`signer`.

  The script performs the following operations:

  - parse password from :file:`includes/mysql.php`
  - read a list of CRL files and logs their SHA-1 hashes
  - read :file:`serial.conf`, create a Device::SerialPort instance `$portObj`,
    sets serial parameters and saves :file:`serial.conf`
  - run a main loop as long as a file :file:`./client.pl-active` is present.
    The main loop performs the following tasks

    - handle pending OpenPGP key signing request via ``HandleGPG()``
    - handle pending certificate signing requests:

      - personal client certificates via ``HandleCerts(0, 0)``
      - personal server certificates via ``HandleCerts(0, 1)``
      - organization client certificates via ``HandleCerts(1, 0)``
      - organization server certificates via ``HandleCerts(1, 1)``

    - handle pending certificate revocation requests

      - personal client certificates via ``RevokeCerts(0, 0)``
      - personal server certificates via ``RevokeCerts(0, 1)``
      - organization client certificates via ``RevokeCerts(1, 0)``
      - organization server certificates via ``RevokeCerts(1, 1)``

    - refresh :term:`CRLs <CRL>` via ``RefreshCRLs()`` in every 100st
      iteration
    - send a :ref:`NUL request <signer-nul-request-format>` to keep the signer
      connection alive
    - sleep for 2.7 seconds

  There is potential for optimization in the main loop. The CRL update could
  be performed if a certificate has been revoked. The NUL request needs only
  to be sent if no other request has been sent.

  The script uses a lot of temporary files instead of piping input and
  output to and from external commands.

  .. todo:: describe more in-depth what each of the main loop steps does

- :file:`commdaemon` a script to run :ref:`client.pl <commmodule-client-pl>`
  or :ref:`server.pl <commmodule-server-pl>`

  This bash script is automatically restarting the :file:`{script}` given as
  the first parameter as long as a file :file:`{script}-active` exists.
  Informational messages and errors are logged to syslog via
  :command:`logger`.

  The script is most probably used to recover from crashed scripts. This
  could be implemented via :command:`supervisor` or :command:`systemd`
  instead of a custom script.

- :file:`commmodule` a System V style init script for startup/shutdown of
  CommModule

  On test.cacert.org two slightly different versions are deployed in
  :file:`/etc/init.d` the first version starts
  :ref:`client.pl <commmodule-client-pl>` in
  :file:`/home/cacert/www/CommModule/` and the
  second variant starts :ref:`server.pl <commmodule-server-pl>` in
  :file:`/home/signer/cacert-devel/CommModule/`.

- :file:`logclean.sh` maintenance script for logfiles generated by CommModule

  The :file:`logclean.sh` script performs log rotation of signer logfiles.

  .. todo::

     discuss replacement of this script with :command:`logrotate` and a
     custom logrotate.conf for the signer

- :file:`serial.conf` serial port configuration file

  This file is read and written by both
  :ref:`client.pl <commmodule-client-pl>` and
  :ref:`server.pl <commmodule-server-pl>` therefore both cannot be run from
  the same directory without interfering with each other.

  .. todo::

     add a serial.conf template and move the actual serial.conf into
     configuration management

.. _commmodule-server-pl:

- :file:`server.pl` the real server, running on the signing server

  This script implements the signer (server) side of the :doc:`signer
  protocol <signer>` and performs the actual signing operations.

  The script contains a some code that is duplicated by
  :ref:`client.pl <commmodule-client-pl>`.

  .. note::

     The :file:`server.pl` used on test.cacert.org is different from the
     version in the cacert-devel repository. The git origin is recorded as
     `git://git-cacert.it-sls.de/cacert-devel.git` and there are some small
     uncommitted changes too.

  .. todo::

     get the versions of server.pl on git.cacert.org, the real production
     signer and the cacert-devel repository synchronized

- :file:`usbclient.pl` obsoleted USB version of
  :ref:`client.pl <commmodule-client-pl>` above

  .. todo:: remove unused file (usbclient.pl)
  
.. index:: includes 
.. index:: PHP

Directory :file:`includes`
==============================

.. _includes-.cvsignore:

.. sourcefile: includes/.cvsignore

- :file:`.cvsignore` includes the parameters for CVS, which files to ignore by versioning

.. _includes-.directory:

.. sourcefile: includes/.gitignore

- :file:`.gitignore` includes the parameters for GIT, which files to ignore by versioning

.. _includes-about_menu.php:

.. sourcefile: includes/about_menu.php
   :links: http://blog.cacert.org/
   :links: http://wiki.CAcert.org/
   :links: www/policy/
   :links: //wiki.cacert.org/FAQ/Privileges
   :links: www/index.php?id=47
   :links: www/logos.php
   :links: www/stats.php
   :links: http://blog.CAcert.org/feed/
   :links: www/index.php?id=7
   :links: //wiki.cacert.org/Board
   :links: https://lists.cacert.org/wws
   :links: www/src-lic.php

- :file:`about_menu.php` is a part (<div>) of a PHP-Page, containing most of the CAcert-related links.   

.. _includes-account_stuff.php:

.. sourcefile: includes/account_stuff.php

- :file:`account_stuff.php`

.. _includes-account.php:

.. sourcefile: includes/account.php
   :uses: includes/about_menu.php
   :uses: .... showheader  

- :file:`account.php`

.. _includes-general_stuff.php:

.. sourcefile: includes/general_stuff.php

- :file:`general_stuff.php`

.. _includes-general.php:

.. sourcefile: includes/general.php

- :file:`general.php`

.. _includes-keygen.php:

.. sourcefile: includes/keygen.php

- :file:`keygen.php`

.. _includes-loggedin.php:

.. sourcefile: includes/loggedin.php

- :file:`loggedin.php`

.. _includes-mysql-php:
.. _includes-mysql-php-sample:

- :file:`mysql.php.sample` is a template for the database connection handling
  code that is meant to be copied to :file:`mysql.php`.

  The template defines the MySQL connection as a session variable `mconn` and
  tries to connect to that database. It also defines the session variables
  `normalhostname`, `securehostname` and `tverify`.

  The template defines a function :php:func:`sendmail` for sending mails.

  .. php:function:: sendmail($to, $subject, $message, $from, $replyto="", \
         $toname="", $fromname="", $errorsto="returns@cacert.org", \
         $use_utf8=true)

     Send an email. The function reimplements functionality that is readily
     available in PHP. The function does not properly escape headers and
     sends raw SMTP commands.

     :param string $to:       recipient email address
     :param string $subject:  subject
     :param string $message:  email body
     :param string $from:     from email address
     :param string $replyto:  reply-to email address
     :param string $fromname: unused in the code
     :param string $toname:   unused in the code
     :param string $errorsto: email address used for Sender and Errors-To
                              headers
     :param bool $use_utf8:   decides whether the Content-Type header uses
                              a charset parameter of utf-8 or iso-8859-1

  Configuration and actual code are mixed. It would be better to have a
  separate file that just includes configuration.

  This file is parsed by :ref:`CommModule/client.pl <commmodule-client-pl>`
  format changes might break the CommModule code.
  
.. _includes-notary.inc.php:

.. sourcefile: includes/notary.inc.php

- :file:`notary.inc.php`

.. _includes-shutdown.php:

.. sourcefile: includes/shutdown.php

- :file:`shutdown.php`

.. _includes-sponsorinfo.php:

.. sourcefile: includes/sponsorinfo.php

- :file:`sponsorinfo.php`

.. _includes-tverify_stuff.php:

.. sourcefile: includes/tverify_stuff.php

- :file:`tverify_stuff.php`

.. index:: includes/lib
.. index:: PHP

Directory :file:`includes/lib`
==============================

.. _includes-lib-account.php:

.. sourcefile: includes/lib/account.php

- :file:`account.php`

.. _includes-lib-check_weak_key.php:

.. sourcefile: includes/lib/check_weak_key.php

- :file:`check_weak_key.php`

.. _includes-lib-general.php:

.. sourcefile: includes/lib/general.php

- :file:`general.php`

.. _includes-lib-l10n.php:

.. sourcefile: includes/lib/l10n.php

- :file:`l10n.php`

.. index:: locale

Directory :file:`locale`
========================

.. index:: C

.. _locale-cv.c:

.. sourcefile: locale/cv.c

- :file:`cv.c`

.. index:: PHP
.. _locale-escape_special_chars.php:

.. sourcefile: locale/escape_special_chars.php

- :file:`escape_special_chars.php`

.. index:: bash
.. _locale-makefile:

.. sourcefile: locale/makefile

- :file:`makefile`

.. index:: pages

Directory :file:`pages`
=======================

This directory only contains other (sub-) directorys, structured according to specific topics.

.. include:: DIR-pages.rst

.. index:: scripts
.. index:: PHP
.. index:: txt

Directory :file:`scripts`
=========================

.. include:: DIR-scripts.rst


.. index:: WWW
.. index:: PHP

Directory :file:`www`
=====================

This contains the PHP code that is the entry point to the application:

.. _www-sealgen-php:

- :file:`sealgen.php` generates a small site seal image from
  :ref:`www/images/secured.png <www-images-secured-png>`. This could be
  replaced with a static image if it is used at all. This is referenced
  by :ref:`cgi-bin/siteseal.cgi <cgi-bin-siteseal-cgi>`

Directory :file:`www/images`
============================

.. _www-images-secured-png:

- :file:`secured.png` is a small image used by
  :ref:`www/sealgen.php <www-sealgen-php>`