contrib: Add helper to build Android dependencies.
[libpwmd.git] / doc / tutorial.lyx
blob671568a31c657504f79ab13af299a6504639bb4d
1 #LyX 2.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 544
3 \begin_document
4 \begin_header
5 \save_transient_properties true
6 \origin unavailable
7 \textclass docbook
8 \use_default_options false
9 \maintain_unincluded_children false
10 \language english
11 \language_package default
12 \inputencoding auto
13 \fontencoding global
14 \font_roman "default" "default"
15 \font_sans "default" "default"
16 \font_typewriter "default" "default"
17 \font_math "auto" "auto"
18 \font_default_family default
19 \use_non_tex_fonts false
20 \font_sc false
21 \font_osf false
22 \font_sf_scale 100 100
23 \font_tt_scale 100 100
24 \use_microtype false
25 \use_dash_ligatures true
26 \graphics default
27 \default_output_format default
28 \output_sync 0
29 \bibtex_command default
30 \index_command default
31 \paperfontsize default
32 \spacing single
33 \use_hyperref false
34 \papersize default
35 \use_geometry false
36 \use_package amsmath 0
37 \use_package amssymb 0
38 \use_package cancel 1
39 \use_package esint 0
40 \use_package mathdots 1
41 \use_package mathtools 1
42 \use_package mhchem 1
43 \use_package stackrel 1
44 \use_package stmaryrd 1
45 \use_package undertilde 1
46 \cite_engine basic
47 \cite_engine_type default
48 \biblio_style plain
49 \use_bibtopic false
50 \use_indices false
51 \paperorientation portrait
52 \suppress_date false
53 \justification true
54 \use_refstyle 0
55 \use_minted 0
56 \index Index
57 \shortcut idx
58 \color #008000
59 \end_index
60 \secnumdepth 3
61 \tocdepth 3
62 \paragraph_separation indent
63 \paragraph_indentation default
64 \is_math_indent 0
65 \math_numbering_side default
66 \quotes_style english
67 \dynamic_quotes 0
68 \papercolumns 1
69 \papersides 1
70 \paperpagestyle default
71 \tracking_changes false
72 \output_changes false
73 \html_math_output 0
74 \html_css_as_file 0
75 \html_be_strict false
76 \end_header
78 \begin_body
80 \begin_layout Title
81 Libpwmd Tutorial
82 \end_layout
84 \begin_layout Date
85 Sep-21-2016
86 \end_layout
88 \begin_layout Author
89 Ben Kibbey
90 \begin_inset Foot
91 status open
93 \begin_layout Plain Layout
94 bjk@luxsci.net
95 \end_layout
97 \end_inset
100 \end_layout
102 \begin_layout Author
103 \begin_inset CommandInset toc
104 LatexCommand tableofcontents
106 \end_inset
109 \end_layout
111 \begin_layout Section
112 Introduction
113 \end_layout
115 \begin_layout Standard
116 This is a tutorial showing the basic usage of libpwmd
117 \begin_inset Foot
118 status open
120 \begin_layout Plain Layout
121 https://gitlab.com/bjk/libpwmd/wikis
122 \end_layout
124 \end_inset
127  Libpwmd
128 \emph on
130 \emph default
131 is a library making it easy for applications to use pwmd
132 \begin_inset Foot
133 status open
135 \begin_layout Plain Layout
136 https://gitlab.com/bjk/pwmd/wikis
137 \end_layout
139 \end_inset
142 \emph on
143 Password Manager Daemon).
144  Password Manager Daemon
145 \emph default
146  is a universal data server.
147  It began as a way to keep track of passwords for accounts like email and
148  websites but has evolved to store anything you want.
149  There are other password management tools but pwmd has a couple of distinguishi
150 ng features:
151 \end_layout
153 \begin_layout Itemize
154 It does not depend on a desktop environment but has the ability for applications
155  to connect to it like a desktop solution provides.
156 \end_layout
158 \begin_layout Itemize
159 Some portion of a stored data can be shared with another portion in the
160  same data file.
161  This feature behaves a lot like a symbolic link on a file system, XML entities,
162  or HTML targets if you're familiar with those, but implemented in a different
163  way.
164  This means less duplication of content.
165  See 
166 \begin_inset CommandInset ref
167 LatexCommand ref
168 reference "sec:Linking-elements"
170 \end_inset
172  for details.
173 \end_layout
175 \begin_layout Itemize
176 The XML document is OpenPGP encrypted and signed using an existing or newly
177  generated key pair.
178  Symmetric encryption is also supported as well as smartcards.
179  All crypto operations are done using GpgME which in turn uses gnupg.
180 \end_layout
182 \begin_layout Standard
183 Other features include:
184 \end_layout
186 \begin_layout Itemize
187 Multi-threaded.
188  More than one client may access the same data file while optionally locking
189  out other clients.
190 \end_layout
192 \begin_layout Itemize
193 Secure memory management.
194  Pwmd will zero out memory before freeing it and the contents of the cached
195  document are encrypted.
196 \end_layout
198 \begin_layout Itemize
199 Remote connections over TLS with client certificates used as authentication.
200 \end_layout
202 \begin_layout Itemize
203 Remote connections over SSH (some configuration needed).
204 \end_layout
206 \begin_layout Itemize
207 ACL's for each element in an element path, listening socket and filename.
208 \end_layout
210 \begin_layout Section
211 File Format and Element Paths
212 \end_layout
214 \begin_layout Standard
215 The document is in XML format and is manipulated by commands sent from a
216  client.
217  Commands that access previously stored data take what is called an 
218 \emph on
219 element path
220 \emph default
221  as an argument.
222  An element path is a character string containing element names representing
223  branches of an element tree.
224  The branches are separated with a TAB (ASCII 0x09) character.
225  Why a TAB? So other characters can be used in the element name.
226  If for example a '/' were used as the separator, then a URL (i.e., http://sf.net/)
227  could not be used as an element name since it would be an XML syntax error.
228  For the rest of this tutorial, when you see <TAB>, replace it with a real
229  TAB character.
230 \end_layout
232 \begin_layout Standard
233 For example, the element path "root<TAB>child<TAB>last" has the following
234  element tree structure:
235 \end_layout
237 \begin_layout Code
238 <root>
239 \end_layout
241 \begin_layout Code
242     <child>
243 \end_layout
245 \begin_layout Code
246         <last>
247 \end_layout
249 \begin_layout Code
250 Content or XML CDATA of the "last" element.
251 \end_layout
253 \begin_layout Code
254         </last>
255 \end_layout
257 \begin_layout Code
258     </child>
259 \end_layout
261 \begin_layout Code
262 </root>
263 \end_layout
265 \begin_layout Standard
266 I should say that the XML structure that pwmd uses is a little more complicated.
267  It really looks like the following internally, but we will use the above
268  format in this tutorial for simplicity:
269 \end_layout
271 \begin_layout Code
272 <element _name="root">
273 \end_layout
275 \begin_layout Code
276     <element _name="child">
277 \end_layout
279 \begin_layout Code
280         <element _name="last">
281 \end_layout
283 \begin_layout Code
284 Content or CDATA of the "last" element.
285 \end_layout
287 \begin_layout Code
288         </element>
289 \end_layout
291 \begin_layout Code
292     </element>
293 \end_layout
295 \begin_layout Code
296 </element>
297 \end_layout
299 \begin_layout Standard
300 Every element created has an element named 
301 \emph on
302 element
303 \emph default
304  with an attribute 
305 \emph on
306 _name
307 \emph default
308  associated with it.
309  The value of the 
310 \emph on
311 _name
312 \emph default
313  attribute is what an element in an element path refers to.
314  It is done this way so that a wider range of characters can be used in
315  an element name while maintaining valid XML.
316  In fact the only restriction of an element name is that it not contain
317  whitespace characters.
318 \end_layout
320 \begin_layout Standard
321 There is one other difference from your normal XML document in that only
322  the first match of an element is considered for the current element tree
323  depth.
324  When an element of the current depth of an element tree is found, the next
325  element in the element path is searched for beginning at the child node
326  of the found element.
327  From the example above:
328 \end_layout
330 \begin_layout Code
331 <root>
332 \end_layout
334 \begin_layout Code
335     <child>
336 \end_layout
338 \begin_layout Code
339         <last>
340 \end_layout
342 \begin_layout Code
343 Content or XML CDATA of the "last" element.
344 \end_layout
346 \begin_layout Code
347         </last>
348 \end_layout
350 \begin_layout Code
351     </child>
352 \end_layout
354 \begin_layout Code
355     <child>
356 \end_layout
358 \begin_layout Code
359 This element will never be reached.
360 \end_layout
362 \begin_layout Code
363     </child>
364 \end_layout
366 \begin_layout Code
367 </root>
368 \end_layout
370 \begin_layout Standard
371 The second "<child>" element is never reached because it has the same name
372  as its sibling element 
373 \begin_inset Quotes eld
374 \end_inset
376 above
377 \begin_inset Quotes erd
378 \end_inset
380  it.
381 \end_layout
383 \begin_layout Section
384 Connecting to PWMD
385 \end_layout
387 \begin_layout Standard
388 You will need a 
389 \emph on
390 pwmd
391 \emph default
392  client to send commands to the pwmd server.
394 \emph on
395 libpwmd
396 \emph default
397  includes a client named 
398 \emph on
399 pwmc
400 \emph default
402  It is command-line based and there are not any fancy graphics, but it is
403  good for understanding how 
404 \emph on
405 pwmd
406 \emph default
407  commands are processed.
408  If you want a more user friendly client that resembles a file manager and
409  has a point and click interface, try QPwmc 
410 \begin_inset Foot
411 status open
413 \begin_layout Plain Layout
414 https://gitlab.com/bjk/qpwmc/wikis
415 \end_layout
417 \end_inset
419  which uses the Qt4 or Qt5 toolkit and is also a full featured client.
420 \end_layout
422 \begin_layout Standard
423 In this tutorial we will use the 
424 \emph on
425 pwmc
426 \emph default
427  client included with libpwmd.
429 \emph on
430 pwmc
431 \emph default
432  has two modes that commands are read from: interactive and stdin.
433  The interactive mode uses the readline library and has command history,
434  while reading from standard input (stdin) makes shell scripting and automation
435  easy.
436  For the examples, we will be connecting to the default local unix domain
437  socket (UDS) that pwmd waits for connections on and use interactive mode.
438  Remote connections are also possible over TLS or an SSH channel but those
439  are not covered here.
440  Read the pwmc(1) manual page for details about how to do that.
441 \end_layout
443 \begin_layout Standard
444 The example filename we will use is "datafile".
445  It is initially a non-existent file but it will be created once we have
446  saved to it.
447  Now let us connect to the server in interactive mode and open the data
448  file:
449 \end_layout
451 \begin_layout Code
452 $ pwmc datafile
453 \end_layout
455 \begin_layout Code
456 Connected.
457 \end_layout
459 \begin_layout Code
460 pwmc:datafile>
461 \end_layout
463 \begin_layout Standard
464 The "pwmc>" prompt is a readline prompt that has command history and can
465  also do filename completion when doing a dot command that requires a filename
466  on the local filesystem.
467 \end_layout
469 \begin_layout Section
470 Commands
471 \end_layout
473 \begin_layout Standard
474 There are two different types of commands: client commands and protocol
475  commands.
476  The client commands are 
477 \emph on
478 pwmc
479 \emph default
480  specific and only available to the 
481 \emph on
482 pwmc
483 \emph default
484  client.
485  Protocol commands are commands sent from any client and to the 
486 \emph on
487 pwmd
488 \emph default
489  server.
490  All pwmc client commands are prefixed with a dot '.' followed by the command
491  name.
492  Protocol commands are sent without any dot prefix.
493  To see the available pwmc and protocol commands, send the .help or HELP
494  commands:
495 \end_layout
497 \begin_layout Code
498 pwmc:datafile> .help
499 \end_layout
501 \begin_layout Standard
503 \end_layout
505 \begin_layout Code
506 pwmc:datafile> help
507 \end_layout
509 \begin_layout Standard
510 To store some data in an element path or to create an element path, you
511  will need to know what element path to create.
512  It is up to you how you want your data organized.
513  If for example you will be storing account information it may be good to
514  categorize what the account is for: email, instant messaging, blogging,
515  etc.
516  An application that uses libpwmd may require that a certain element path
517  exists.
518  Refer to that applications documentation to determine what element paths
519  need to be created.
520 \end_layout
522 \begin_layout Standard
523 In the following example we will setup mail server element paths which can
524  be used for other applications requiring a mail server configuration.
525  First, lets create the hostname element path:
526 \end_layout
528 \begin_layout Code
529 pwmc:datafile> STORE
530 \end_layout
532 \begin_layout Code
533 Press CTRL-D to send the current line.
534  Press twice to end.
535  DATA:
536 \end_layout
538 \begin_layout Standard
539 The STORE command is a 
540 \emph on
541 pwmd
542 \emph default
543  protocol command.
544  This, and a few other commands, use what is called a 
545 \emph on
546 server inquire
547 \emph default
548  to retrieve additional command parameters from the client while other commands
549  require only the command itself with its command arguments.
550  The server inquire will wait for the client to finish sending its' data
551  before completing the command.
552  When responding to a server inquire in pwmc, pwmc will show a message informing
553  you that it is waiting for data to be sent.
554  Enter the element path and its content, then press <CTRL-D> twice to finish
555  sending the data and to let 
556 \emph on
557 pwmd
558 \emph default
559  complete the command:
560 \end_layout
562 \begin_layout Code
563 email<TAB>isp<TAB>IMAP<TAB>hostname<TAB>imap.server.com<CTRL-D><CTRL-D>
564 \end_layout
566 \begin_layout Standard
567 Remember that you should replace <TAB> in the examples with a real TAB character.
568  After pressing the first <CTRL-D>, the characters that were entered are
569  sent to 
570 \emph on
571 pwmd
572 \emph default
573  and the inquire continues.
574  To terminate the inquire and finish sending data for the command press
575  <CTRL-D> a second time.
576 \end_layout
578 \begin_layout Standard
579 If you were to have pressed <RETURN> before any <CTRL-D> then the inquired
580  line would have been sent in full including a newline character.
581  Since in this example a newline character in a hostname is not a valid
582  hostname, this is not what we want.
583 \end_layout
585 \begin_layout Standard
586 We have just created an element path whose XML structure looks like the
587  following:
588 \end_layout
590 \begin_layout Code
591 <email>
592 \end_layout
594 \begin_layout Code
595     <isp>
596 \end_layout
598 \begin_layout Code
599         <IMAP>
600 \end_layout
602 \begin_layout Code
603             <hostname>imap.server.com</hostname>
604 \end_layout
606 \begin_layout Code
607         </IMAP>
608 \end_layout
610 \begin_layout Code
611     </isp>
612 \end_layout
614 \begin_layout Code
615 </email>
616 \end_layout
618 \begin_layout Standard
619 The GET protocol command returns the value, or content, of the last element
620  of an element path.
621  To retrieve the hostname of the element path we just created, do:
622 \end_layout
624 \begin_layout Code
625 pwmc:datafile> GET email<TAB>isp<TAB>IMAP<TAB>hostname
626 \end_layout
628 \begin_layout Code
629 imap.server.com
630 \end_layout
632 \begin_layout Code
633 pwmc:datafile>
634 \end_layout
636 \begin_layout Standard
637 Let us create the rest of the needed elements:
638 \end_layout
640 \begin_layout Code
641 pwmc:datafile> STORE
642 \end_layout
644 \begin_layout Code
645 email<TAB>isp<TAB>IMAP<TAB>port<TAB>993<CTRL-D><CTRL-D>
646 \end_layout
648 \begin_layout Code
650 \end_layout
652 \begin_layout Code
653 pwmc:datafile> STORE
654 \end_layout
656 \begin_layout Code
657 email<TAB>isp<TAB>IMAP<TAB>ssl<TAB>1<CTRL-D><CTRL-D>
658 \end_layout
660 \begin_layout Code
662 \end_layout
664 \begin_layout Code
665 pwmc:datafile> STORE
666 \end_layout
668 \begin_layout Code
669 email<TAB>isp<TAB>username<TAB>myusername<CTRL-D><CTRL-D>
670 \end_layout
672 \begin_layout Code
674 \end_layout
676 \begin_layout Code
677 pwmc:datafile> STORE
678 \end_layout
680 \begin_layout Code
681 email<TAB>isp<TAB>password<TAB>mypassword<CTRL-D><CTRL-D>
682 \end_layout
684 \begin_layout Standard
685 Now the element structure for the "email" element looks like this:
686 \end_layout
688 \begin_layout Code
689 <email>
690 \end_layout
692 \begin_layout Code
693     <isp>
694 \end_layout
696 \begin_layout Code
697         <IMAP>
698 \end_layout
700 \begin_layout Code
701               <hostname>imap.server.com</hostname>
702 \end_layout
704 \begin_layout Code
705               <port>993</port>
706 \end_layout
708 \begin_layout Code
709               <ssl>1</ssl>
710 \end_layout
712 \begin_layout Code
713         </IMAP>
714 \end_layout
716 \begin_layout Code
717         <username>myusername</username>
718 \end_layout
720 \begin_layout Code
721         <password>mypassword</password>
722 \end_layout
724 \begin_layout Code
725     </isp>
726 \end_layout
728 \begin_layout Code
729 </email>
730 \end_layout
732 \begin_layout Standard
733 If you wanted to change your password (after changing it on the mail server,
734  of course) just do as you did when initially creating the password element
735  path.
736  The new content will overwrite the existing content:
737 \end_layout
739 \begin_layout Code
740 pwmc:datafile> STORE
741 \end_layout
743 \begin_layout Code
744 email<TAB>isp<TAB>password<TAB>newpassword<CTRL-D><CTRL-D>
745 \end_layout
747 \begin_layout Code
748 pwmc:datafile>
749 \end_layout
751 \begin_layout Standard
752 An application using libpwmd that requires mail server information now has
753  the basic information it needs.
754  It may require more elements and they can be created just as these elements
755  have been.
756  The only thing left to do now is to save the changes:
757 \end_layout
759 \begin_layout Code
760 pwmc:datafile> <CTRL-D>
761 \end_layout
763 \begin_layout Standard
764 After pressing <CTRL-D> a prompt will be shown asking what to do next.
765  Press 
766 \begin_inset Quotes eld
767 \end_inset
770 \begin_inset Quotes erd
771 \end_inset
773  to save what we have created.
774  This will generate a new encryption and signing key pair by default.
775  If you would rather use an existing encryption and signing key or use symmetric
776  encryption, you will need to use the .save pwmc command along with the required
777  SAVE protocol command options.
778  The .save command lets libpwmd set some things that may be needed for the
779  current connection such as pinentry settings.
780  Type:
781 \end_layout
783 \begin_layout Code
784 pwmc:datafile> help save
785 \end_layout
787 \begin_layout Standard
788 to see SAVE syntax and options.
789 \end_layout
791 \begin_layout Standard
792 When the save has completed the encrypted data file has been written to
793  disk and is also stored in pwmd's file cache.
794  A cached document is the same document on disc that is stored in memory.
795  This means that the next time the document is opened a passphrase won't
796  be required until pwmd's cache timer removes it from the cache.
797  By default, the cache timeout for each data file is 600 seconds, or 10
798  minutes.
799  This setting can be changed in pwmd's configuration and set independently
800  for each file and can also be set to not cache the file at all or to cache
801  it indefinately.
802 \end_layout
804 \begin_layout Section
805 \begin_inset CommandInset label
806 LatexCommand label
807 name "sec:Linking-elements"
809 \end_inset
811 Linking elements
812 \end_layout
814 \begin_layout Standard
815 One distinguishing feature of pwmd is the ability to share data of one element
816  path with another.
817  If for example your ISP lets you host a blog on their server and you use
818  a blogging client that can use libpwmd for authentication details, you
819  can share authentication information with the email example above when
820  the account details are the same.
821  When element linking is used, this avoids the need to change the content
822  for both the blogging and email password elements.
823 \end_layout
825 \begin_layout Standard
826 This is done by setting a special 
827 \begin_inset Quotes eld
828 \end_inset
830 _target
831 \begin_inset Quotes erd
832 \end_inset
834  attribute for an element.
835  It behaves similarly to the HTML 
836 \begin_inset Quotes eld
837 \end_inset
839 target
840 \begin_inset Quotes erd
841 \end_inset
843  attribute or XML entities or a symbolic link on a filesystem.
845 \end_layout
847 \begin_layout Standard
848 Let's create an example blogging element path:
849 \end_layout
851 \begin_layout Code
852 pwmc:datafile> STORE
853 \end_layout
855 \begin_layout Code
856 blog<TAB>isp<TAB>hostname<TAB>blog.myisp.com<CTRL-D><CTRL-D>
857 \end_layout
859 \begin_layout Code
861 \end_layout
863 \begin_layout Code
864 pwmc:datafile> ATTR SET _target blog<TAB>isp<TAB>username email<TAB>isp<TAB>user
865 name
866 \end_layout
868 \begin_layout Code
869 pwmc:datafile> ATTR SET _target blog<TAB>isp<TAB>password email<TAB>isp<TAB>pass
870 word
871 \end_layout
873 \begin_layout Standard
874 Now each access of the "blog/isp/username" and "blog/isp/password" element
875  paths, which were created if they did not already exist, will point to
876  "email/isp/username" and "email/isp/password", respectively.
877  To retrieve the value or content of an element that contains a "_target"
878  attribute, just use the GET command as you would for any other element:
879 \end_layout
881 \begin_layout Code
882 pwmc:datafile> GET blog<TAB>isp<TAB>password
883 \end_layout
885 \begin_layout Code
886 mypassword
887 \end_layout
889 \begin_layout Code
890 pwmc:datafile>
891 \end_layout
893 \begin_layout Standard
894 A "_target" attribute may also refer to another element with a "_target"
895  attribute.
896  Every "_target" attribute will be followed until there are no others to
897  resolve.
898  To get the real element path and resolve all "_target" attributes, use
899  the REALPATH protocol command:
900 \end_layout
902 \begin_layout Code
903 pwmc:datafile> REALPATH blog<TAB>isp<TAB>password
904 \end_layout
906 \begin_layout Code
907 email<TAB>isp<TAB>password
908 \end_layout
910 \begin_layout Code
911 pwmc:datafile>
912 \end_layout
914 \begin_layout Standard
915 Using the LIST command is useful to show the element structure of a document:
916 \end_layout
918 \begin_layout Code
919 pwmc:datafile> LIST
920 \end_layout
922 \begin_layout Code
923 email
924 \end_layout
926 \begin_layout Code
927 blog
928 \end_layout
930 \begin_layout Code
931 pwmc:datafile> LIST email
932 \end_layout
934 \begin_layout Code
935 email
936 \end_layout
938 \begin_layout Code
939 email<TAB>isp
940 \end_layout
942 \begin_layout Code
943 email<TAB>isp<TAB>username
944 \end_layout
946 \begin_layout Code
947 email<TAB>isp<TAB>password
948 \end_layout
950 \begin_layout Code
951 email<TAB>isp<TAB>IMAP<TAB>hostname
952 \end_layout
954 \begin_layout Code
955 email<TAB>isp<TAB>IMAP<TAB>port
956 \end_layout
958 \begin_layout Code
959 email<TAB>isp<TAB>IMAP<TAB>ssl
960 \end_layout
962 \begin_layout Code
963 pwmc:datafile> LIST blog
964 \end_layout
966 \begin_layout Code
967 blog
968 \end_layout
970 \begin_layout Code
971 blog<TAB>isp
972 \end_layout
974 \begin_layout Code
975 blog<TAB>isp<TAB>hostname
976 \end_layout
978 \begin_layout Code
979 blog<TAB>isp<TAB>username
980 \end_layout
982 \begin_layout Code
983 blog<TAB>isp<TAB>password
984 \end_layout
986 \begin_layout Code
987 pwmc:datafile>
988 \end_layout
990 \end_body
991 \end_document