Update structure for partials and examples

This commit is contained in:
Petr Bokoc 2022-01-13 20:42:40 +01:00
parent b1b3d6a960
commit 531ddf0721
89 changed files with 79 additions and 79 deletions

View file

@ -81,7 +81,7 @@ and its usage to sign data.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-HSM-OpenSSL.adoc[] include::example$Features-HSM-OpenSSL.adoc[]
---- ----
==== ====
@ -104,7 +104,7 @@ and its usage to sign data.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-HSM-GNUTLS.adoc[] include::example$Features-HSM-GNUTLS.adoc[]
---- ----
==== ====
@ -119,7 +119,7 @@ An example PIN callback function is shown below.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-HSM-GNUTLS-PIN.adoc[] include::example$Features-HSM-GNUTLS-PIN.adoc[]
---- ----
==== ====
@ -145,7 +145,7 @@ The following example demonstrates a typical NSS application for signing.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-HSM-NSS.adoc[] include::example$Features-HSM-NSS.adoc[]
---- ----
==== ====
@ -173,7 +173,7 @@ $ NSS_Sign_Example "${token_name}:${cert_name}"
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-HSM-NSS-PIN.adoc[] include::example$Features-HSM-NSS-PIN.adoc[]
---- ----
==== ====

View file

@ -3,7 +3,7 @@
[[chap-Defensive_Coding-TLS]] [[chap-Defensive_Coding-TLS]]
= Transport Layer Security (TLS) = Transport Layer Security (TLS)
include::{partialsdir}/entities.adoc[] include::partial$entities.adoc[]
Transport Layer Security (TLS, formerly Secure Sockets Transport Layer Security (TLS, formerly Secure Sockets
Layer/SSL) is the recommended way to to protect integrity and Layer/SSL) is the recommended way to to protect integrity and
@ -62,7 +62,7 @@ duration of the handshake), or use the Linux-specific
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-Nagle.adoc[] include::example$Features-TLS-Nagle.adoc[]
---- ----
==== ====
@ -133,7 +133,7 @@ due to a connection teardown by the other end).
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-OpenSSL-Errors.adoc[] include::example$Features-TLS-OpenSSL-Errors.adoc[]
---- ----
==== ====
@ -309,7 +309,7 @@ The OpenSSL library needs explicit initialization (see <<ex-Defensive_Coding-TLS
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-OpenSSL-Init.adoc[] include::example$Features-TLS-Client-OpenSSL-Init.adoc[]
---- ----
@ -332,7 +332,7 @@ be cumbersome.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-OpenSSL-CTX.adoc[] include::example$Features-TLS-Client-OpenSSL-CTX.adoc[]
---- ----
==== ====
@ -380,7 +380,7 @@ name.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-OpenSSL-Connect.adoc[] include::example$Features-TLS-Client-OpenSSL-Connect.adoc[]
---- ----
==== ====
@ -397,7 +397,7 @@ transport, using `BIO_set_ssl`.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-OpenSSL-Connection-Use.adoc[] include::example$Features-TLS-Client-OpenSSL-Connection-Use.adoc[]
---- ----
==== ====
@ -418,7 +418,7 @@ socket after the connection object has been freed.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-OpenSSL-Connection-Close.adoc[] include::example$Features-TLS-OpenSSL-Connection-Close.adoc[]
---- ----
==== ====
@ -433,7 +433,7 @@ because no further TLS connections will be established.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-OpenSSL-Context-Close.adoc[] include::example$Features-TLS-OpenSSL-Context-Close.adoc[]
---- ----
==== ====
@ -456,7 +456,7 @@ CAs (<<ex-Defensive_Coding-TLS-Client-GNUTLS-Credentials>>).
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-GNUTLS-Credentials.adoc[] include::example$Features-TLS-Client-GNUTLS-Credentials.adoc[]
---- ----
==== ====
@ -466,7 +466,7 @@ object should be freed:
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-GNUTLS-Credentials-Close.adoc[] include::example$Features-TLS-GNUTLS-Credentials-Close.adoc[]
---- ----
During its lifetime, the credentials object can be used to During its lifetime, the credentials object can be used to
@ -486,7 +486,7 @@ This is shown in <<ex-Defensive_Coding-TLS-Client-GNUTLS-Connect>>.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-GNUTLS-Connect.adoc[] include::example$Features-TLS-Client-GNUTLS-Connect.adoc[]
---- ----
==== ====
@ -505,7 +505,7 @@ can be omitted if the functionality is not needed.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-GNUTLS-Verify.adoc[] include::example$Features-TLS-Client-GNUTLS-Verify.adoc[]
---- ----
==== ====
@ -519,7 +519,7 @@ receiving data, as in <<ex-Defensive_Coding-TLS-GNUTLS-Use>>.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-GNUTLS-Use.adoc[] include::example$Features-TLS-GNUTLS-Use.adoc[]
---- ----
==== ====
@ -535,7 +535,7 @@ Finally, the session object can be deallocated using
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-GNUTLS-Disconnect.adoc[] include::example$Features-TLS-GNUTLS-Disconnect.adoc[]
---- ----
==== ====
@ -548,7 +548,7 @@ classes:
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-OpenJDK-Import.adoc[] include::example$Features-TLS-Client-OpenJDK-Import.adoc[]
---- ----
@ -579,7 +579,7 @@ be supported as a fall-back option. This is shown in <<ex-Defensive_Coding-TLS-C
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-OpenJDK-Context.adoc[] include::example$Features-TLS-Client-OpenJDK-Context.adoc[]
---- ----
==== ====
@ -595,7 +595,7 @@ connections.
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Features-TLS-OpenJDK-Parameters.adoc[] include::example$Features-TLS-OpenJDK-Parameters.adoc[]
---- ----
==== ====
@ -606,7 +606,7 @@ separately, and this is only supported by OpenJDK 7 and later:
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-OpenJDK-Hostname.adoc[] include::example$Features-TLS-Client-OpenJDK-Hostname.adoc[]
---- ----
All application protocols can use the All application protocols can use the
@ -629,7 +629,7 @@ internal API on OpenJDK 6.
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-OpenJDK-Connect.adoc[] include::example$Features-TLS-Client-OpenJDK-Connect.adoc[]
---- ----
==== ====
@ -650,7 +650,7 @@ The TLS socket can be used as a regular socket, as shown in
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-OpenJDK-Use.adoc[] include::example$Features-TLS-Client-OpenJDK-Use.adoc[]
---- ----
==== ====
@ -675,7 +675,7 @@ the server certificate is identified by its SHA-256 hash.
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-OpenJDK-MyTrustManager.adoc[] include::example$Features-TLS-Client-OpenJDK-MyTrustManager.adoc[]
---- ----
==== ====
@ -690,7 +690,7 @@ This trust manager has to be passed to the
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-OpenJDK-Context_For_Cert.adoc[] include::example$Features-TLS-Client-OpenJDK-Context_For_Cert.adoc[]
---- ----
==== ====
@ -735,7 +735,7 @@ Using NSS needs several header files, as shown in
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-NSS-Includes.adoc[] include::example$Features-TLS-NSS-Includes.adoc[]
---- ----
==== ====
@ -761,7 +761,7 @@ load trusted CA certificates from a file.)
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-NSS-Init.adoc[] include::example$Features-TLS-NSS-Init.adoc[]
---- ----
@ -772,7 +772,7 @@ the following function calls:
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-NSS-Close.adoc[] include::example$Features-TLS-NSS-Close.adoc[]
---- ----
After NSS has been initialized, the TLS connection can be After NSS has been initialized, the TLS connection can be
@ -808,7 +808,7 @@ certificate is verified and matched against the host name.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-NSS-Connect.adoc[] include::example$Features-TLS-Client-NSS-Connect.adoc[]
---- ----
==== ====
@ -822,7 +822,7 @@ the NSPR descriptor to communicate with the server.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-NSS-Use.adoc[] include::example$Features-TLS-NSS-Use.adoc[]
---- ----
==== ====
@ -836,7 +836,7 @@ shows how to close the connection.
[source,c] [source,c]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-NSS-Close.adoc[] include::example$Features-TLS-Client-NSS-Close.adoc[]
---- ----
@ -877,7 +877,7 @@ certificate returned by `getpeercert`.
[source,python] [source,python]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-Python-check_host_name.adoc[] include::example$Features-TLS-Client-Python-check_host_name.adoc[]
---- ----
==== ====
@ -923,7 +923,7 @@ manually against the host name, by calling the
[source,python] [source,python]
---- ----
include::{partialsdir}/snippets/Features-TLS-Client-Python-Connect.adoc[] include::example$Features-TLS-Client-Python-Connect.adoc[]
---- ----
==== ====
@ -933,12 +933,12 @@ be used like a regular socket:
[source,python] [source,python]
---- ----
include::{partialsdir}/snippets/Features-TLS-Python-Use.adoc[] include::example$Features-TLS-Python-Use.adoc[]
---- ----
Closing the TLS socket is straightforward as well: Closing the TLS socket is straightforward as well:
[source,python] [source,python]
---- ----
include::{partialsdir}/snippets/Features-TLS-Python-Close.adoc[] include::example$Features-TLS-Python-Close.adoc[]
---- ----

View file

@ -1,5 +1,5 @@
:experimental: :experimental:
include::{partialsdir}/entities.adoc[] include::partial$entities.adoc[]
= Defensive coding guide = Defensive coding guide
@ -15,6 +15,6 @@ concrete recommendations.
-- --
image::title_logo.svg[] image::title_logo.svg[]
include::{partialsdir}/Legal_Notice.adoc[] include::partial$Legal_Notice.adoc[]
include::{partialsdir}/Author_Group.adoc[] include::partial$Author_Group.adoc[]

View file

@ -56,7 +56,7 @@ The cast silences a compiler warning;
[source,c] [source,c]
---- ----
include::partial$snippets/C-Pointers-remaining.adoc[] include::example$C-Pointers-remaining.adoc[]
---- ----
@ -86,7 +86,7 @@ see <<ex-Defensive_Coding-C-Arithmetic-bad>>.
[source,c] [source,c]
---- ----
include::partial$snippets/C-Arithmetic-add.adoc[] include::example$C-Arithmetic-add.adoc[]
---- ----
@ -113,7 +113,7 @@ additions have to be checked in this way.
[source,c] [source,c]
---- ----
include::partial$snippets/C-Arithmetic-add_unsigned.adoc[] include::example$C-Arithmetic-add_unsigned.adoc[]
---- ----
==== ====
@ -129,7 +129,7 @@ see <<ex-Defensive_Coding-C-Arithmetic-mult>>.
[source,c] [source,c]
---- ----
include::partial$snippets/C-Arithmetic-mult.adoc[] include::example$C-Arithmetic-mult.adoc[]
---- ----
==== ====
@ -189,7 +189,7 @@ after the `*`, and not before it.
[source,c] [source,c]
---- ----
include::partial$snippets/C-Globals-String_Array.adoc[] include::example$C-Globals-String_Array.adoc[]
---- ----

View file

@ -1,7 +1,7 @@
:experimental: :experimental:
include::{partialsdir}/entities.adoc[] include::partial$entities.adoc[]
[[sect-Defensive_Coding-C-Libc]] [[sect-Defensive_Coding-C-Libc]]
== The C Standard Library == The C Standard Library
@ -127,7 +127,7 @@ size is allocated on the heap, consider use
[source,c] [source,c]
---- ----
include::partial$snippets/C-String-Functions-snprintf.adoc[] include::example$C-String-Functions-snprintf.adoc[]
---- ----
@ -157,7 +157,7 @@ invariant. After the loop, the result string is in the
[source,c] [source,c]
---- ----
include::partial$snippets/C-String-Functions-snprintf-incremental.adoc[] include::example$C-String-Functions-snprintf-incremental.adoc[]
---- ----
@ -192,7 +192,7 @@ function (see <<ex-Defensive_Coding-C-String-Functions-format-Attribute>>).
[source,c] [source,c]
---- ----
include::partial$snippets/C-String-Functions-format.adoc[] include::example$C-String-Functions-format.adoc[]
---- ----
@ -207,7 +207,7 @@ ensuring NUL termination is:
[source,c] [source,c]
---- ----
include::partial$snippets/C-String-Functions-strncpy.adoc[] include::example$C-String-Functions-strncpy.adoc[]
---- ----
@ -216,7 +216,7 @@ function for this purpose:
[source,c] [source,c]
---- ----
include::partial$snippets/C-String-Functions-strncat-as-strncpy.adoc[] include::example$C-String-Functions-strncat-as-strncpy.adoc[]
---- ----
@ -239,7 +239,7 @@ approach similar to <<ex-Defensive_Coding-C-String-Functions-snprintf-incrementa
[source,c] [source,c]
---- ----
include::partial$snippets/C-String-Functions-strncat-emulation.adoc[] include::example$C-String-Functions-strncat-emulation.adoc[]
---- ----
@ -249,7 +249,7 @@ string:
[source,c] [source,c]
---- ----
include::partial$snippets/C-String-Functions-strncat-merged.adoc[] include::example$C-String-Functions-strncat-merged.adoc[]
---- ----

View file

@ -53,7 +53,7 @@ details.
[source,go] [source,go]
---- ----
include::partial$snippets/Go-Error_Handling-Regular.adoc[] include::example$Go-Error_Handling-Regular.adoc[]
---- ----
@ -73,7 +73,7 @@ returning both data and an error at the same time.
[source,go] [source,go]
---- ----
include::partial$snippets/Go-Error_Handling-IO.adoc[] include::example$Go-Error_Handling-IO.adoc[]
---- ----

View file

@ -31,7 +31,7 @@ data, implementing an exponential growth policy. See the
[source,java] [source,java]
---- ----
include::partial$snippets/Java-Language-ReadArray.adoc[] include::example$Java-Language-ReadArray.adoc[]
---- ----
@ -62,7 +62,7 @@ possible and should not throw any exceptions.
[source,java] [source,java]
---- ----
include::partial$snippets/Java-Finally.adoc[] include::example$Java-Finally.adoc[]
---- ----
@ -87,7 +87,7 @@ used instead. The Java compiler will automatically insert the
[source,java] [source,java]
---- ----
include::partial$snippets/Java-TryWithResource.adoc[] include::example$Java-TryWithResource.adoc[]
---- ----

View file

@ -75,7 +75,7 @@ beginning of the array.
[source,java] [source,java]
---- ----
include::partial$snippets/Java-JNI-Pointers.adoc[] include::example$Java-JNI-Pointers.adoc[]
---- ----

View file

@ -110,7 +110,7 @@ shows how to run a piece code of with reduced privileges.
[source,java] [source,java]
---- ----
include::partial$snippets/Java-SecurityManager-Unprivileged.adoc[] include::example$Java-SecurityManager-Unprivileged.adoc[]
---- ----
@ -123,7 +123,7 @@ on all files in the current directory) can be used:
[source,java] [source,java]
---- ----
include::partial$snippets/Java-SecurityManager-CurrentDirectory.adoc[] include::example$Java-SecurityManager-CurrentDirectory.adoc[]
---- ----
@ -208,7 +208,7 @@ shows how to request additional privileges.
[source,java] [source,java]
---- ----
include::partial$snippets/Java-SecurityManager-Privileged.adoc[] include::example$Java-SecurityManager-Privileged.adoc[]
---- ----
@ -249,7 +249,7 @@ invocation out of the privileged code section, of course.)
[source,java] [source,java]
---- ----
include::partial$snippets/Java-SecurityManager-Callback.adoc[] include::example$Java-SecurityManager-Callback.adoc[]
---- ----

View file

@ -3,7 +3,7 @@
[[chap-Defensive_Coding-Shell]] [[chap-Defensive_Coding-Shell]]
= Shell Programming and [application]*bash* = Shell Programming and [application]*bash*
include::{partialsdir}/entities.adoc[] include::partial$entities.adoc[]
This chapter contains advice about shell programming, specifically This chapter contains advice about shell programming, specifically
in [application]*bash*. Most of the advice will apply in [application]*bash*. Most of the advice will apply
@ -350,7 +350,7 @@ POSIX shells.
[source,bash] [source,bash]
---- ----
include::partial$snippets/Shell-Input_Validation.adoc[] include::example$Shell-Input_Validation.adoc[]
---- ----

View file

@ -1,6 +1,6 @@
:experimental: :experimental:
include::{partialsdir}/entities.adoc[] include::partial$entities.adoc[]
[[chap-Defensive_Coding-Tasks-File_System]] [[chap-Defensive_Coding-Tasks-File_System]]
= File System Manipulation = File System Manipulation

View file

@ -3,7 +3,7 @@
[[sect-Defensive_Coding-Tasks-Processes]] [[sect-Defensive_Coding-Tasks-Processes]]
= Processes = Processes
include::{partialsdir}/entities.adoc[] include::partial$entities.adoc[]
[[sect-Defensive_Coding-Tasks-Processes-Creation]] [[sect-Defensive_Coding-Tasks-Processes-Creation]]
== Creating Safe Processes == Creating Safe Processes

View file

@ -267,7 +267,7 @@ problems related to that.
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Tasks-Serialization-XML-Expat-EntityDeclHandler.adoc[] include::example$Tasks-Serialization-XML-Expat-EntityDeclHandler.adoc[]
---- ----
@ -282,7 +282,7 @@ This handler must be installed when the
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Tasks-Serialization-XML-Expat-Create.adoc[] include::example$Tasks-Serialization-XML-Expat-Create.adoc[]
---- ----
@ -315,7 +315,7 @@ parsing to stop when encountering entity declarations.
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Tasks-Serialization-XML-Qt-NoEntityHandler.adoc[] include::example$Tasks-Serialization-XML-Qt-NoEntityHandler.adoc[]
---- ----
@ -336,7 +336,7 @@ may need adjusting.
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Tasks-Serialization-XML-Qt-NoEntityReader.adoc[] include::example$Tasks-Serialization-XML-Qt-NoEntityReader.adoc[]
---- ----
@ -358,7 +358,7 @@ return value and report any error.
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Tasks-Serialization-XML-Qt-QDomDocument.adoc[] include::example$Tasks-Serialization-XML-Qt-QDomDocument.adoc[]
---- ----
@ -389,7 +389,7 @@ external ID resolution.
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Tasks-Serialization-XML-OpenJDK-NoEntityResolver.adoc[] include::example$Tasks-Serialization-XML-OpenJDK-NoEntityResolver.adoc[]
---- ----
@ -401,7 +401,7 @@ include::{partialsdir}/snippets/Tasks-Serialization-XML-OpenJDK-NoEntityResolver
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Tasks-Serialization-XML-OpenJDK-NoResourceResolver.adoc[] include::example$Tasks-Serialization-XML-OpenJDK-NoResourceResolver.adoc[]
---- ----
==== ====
@ -415,7 +415,7 @@ shows the imports used by the examples.
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Tasks-Serialization-XML-OpenJDK-Imports.adoc[] include::example$Tasks-Serialization-XML-OpenJDK-Imports.adoc[]
---- ----
==== ====
@ -435,7 +435,7 @@ instance in the `inputStream` variable.
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Tasks-Serialization-XML-OpenJDK_Parse-DOM.adoc[] include::example$Tasks-Serialization-XML-OpenJDK_Parse-DOM.adoc[]
---- ----
==== ====
@ -467,7 +467,7 @@ using a SAX-based approach. The XML data is read from an
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Tasks-Serialization-XML-OpenJDK_Parse-XMLSchema_SAX.adoc[] include::example$Tasks-Serialization-XML-OpenJDK_Parse-XMLSchema_SAX.adoc[]
---- ----
==== ====
@ -490,7 +490,7 @@ to perform the schema-based validation on the
[source,java] [source,java]
---- ----
include::{partialsdir}/snippets/Tasks-Serialization-XML-OpenJDK_Parse-XMLSchema_DOM.adoc[] include::example$Tasks-Serialization-XML-OpenJDK_Parse-XMLSchema_DOM.adoc[]
---- ----
==== ====