Skip to content

Commit

Permalink
Refresh docs and cleanup css (lsh123#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsh123 authored Oct 10, 2022
1 parent 6361f2f commit 59d7451
Show file tree
Hide file tree
Showing 37 changed files with 662 additions and 5,444 deletions.
106 changes: 53 additions & 53 deletions docs/api/xmlsec-custom-keys-manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@
<div class="titlepage"><div><div><h3 class="title">
<a name="xmlsec-example-decrypt3"></a>decrypt3.c</h3></div></div></div>
<div class="informalexample"><pre class="programlisting">
/**
/**
* XML Security Library example: Decrypting an encrypted file using a custom keys manager.
*
*
* Decrypts encrypted XML file using a custom files based keys manager.
* We assume that key's name in &lt;dsig:KeyName/&gt; element is just
* We assume that key's name in &lt;dsig:KeyName/&gt; element is just
* key's file name in the current folder.
*
* Usage:
* ./decrypt3 &lt;xml-enc&gt;
*
* Usage:
* ./decrypt3 &lt;xml-enc&gt;
*
* Example:
* ./decrypt3 encrypt1-res.xml
* ./decrypt3 encrypt2-res.xml
*
* This is free software; see Copyright file in the source
* distribution for preciese wording.
*
* Copyright (C) 2002-2016 Aleksey Sanin &lt;[email protected]&gt;. All Rights Reserved.
*
* Copyright (C) 2002-2022 Aleksey Sanin &lt;[email protected]&gt;. All Rights Reserved.
*/
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
Expand All @@ -68,12 +68,12 @@
xmlSecKeysMngrPtr create_files_keys_mngr(void);
int decrypt_file(xmlSecKeysMngrPtr mngr, const char* enc_file);

int
int
main(int argc, char **argv) {
xmlSecKeysMngrPtr mngr;
#ifndef XMLSEC_NO_XSLT
xsltSecurityPrefsPtr xsltSecPrefs = NULL;
#endif /* XMLSEC_NO_XSLT */
#endif /* XMLSEC_NO_XSLT */

assert(argv);

Expand All @@ -89,20 +89,20 @@
xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
xmlSubstituteEntitiesDefault(1);
#ifndef XMLSEC_NO_XSLT
xmlIndentTreeOutput = 1;
xmlIndentTreeOutput = 1;
#endif /* XMLSEC_NO_XSLT */

/* Init libxslt */
#ifndef XMLSEC_NO_XSLT
/* disable everything */
xsltSecPrefs = xsltNewSecurityPrefs();
xsltSecPrefs = xsltNewSecurityPrefs();
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_READ_FILE, xsltSecurityForbid);
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_WRITE_FILE, xsltSecurityForbid);
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_CREATE_DIRECTORY, xsltSecurityForbid);
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_READ_NETWORK, xsltSecurityForbid);
xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_WRITE_NETWORK, xsltSecurityForbid);
xsltSetDefaultSecurityPrefs(xsltSecPrefs);
#endif /* XMLSEC_NO_XSLT */
xsltSetDefaultSecurityPrefs(xsltSecPrefs);
#endif /* XMLSEC_NO_XSLT */

/* Init xmlsec library */
if(xmlSecInit() &lt; 0) {
Expand All @@ -118,15 +118,15 @@

/* Load default crypto engine if we are supporting dynamic
* loading for xmlsec-crypto libraries. Use the crypto library
* name ("openssl", "nss", etc.) to load corresponding
* name ("openssl", "nss", etc.) to load corresponding
* xmlsec-crypto library.
*/
#ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING
if(xmlSecCryptoDLLoadLibrary(NULL) &lt; 0) {
fprintf(stderr, "Error: unable to load default xmlsec-crypto library. Make sure\n"
"that you have it installed and check shared libraries path\n"
"(LD_LIBRARY_PATH and/or LTDL_LIBRARY_PATH) environment variables.\n");
return(-1);
return(-1);
}
#endif /* XMLSEC_CRYPTO_DYNAMIC_LOADING */

Expand All @@ -149,29 +149,29 @@
}

if(decrypt_file(mngr, argv[1]) &lt; 0) {
xmlSecKeysMngrDestroy(mngr);
xmlSecKeysMngrDestroy(mngr);
return(-1);
}
}

/* destroy keys manager */
xmlSecKeysMngrDestroy(mngr);

/* Shutdown xmlsec-crypto library */
xmlSecCryptoShutdown();

/* Shutdown crypto library */
xmlSecCryptoAppShutdown();

/* Shutdown xmlsec library */
xmlSecShutdown();

/* Shutdown libxslt/libxml */
#ifndef XMLSEC_NO_XSLT
xsltFreeSecurityPrefs(xsltSecPrefs);
xsltCleanupGlobals();
xsltCleanupGlobals();
#endif /* XMLSEC_NO_XSLT */
xmlCleanupParser();

return(0);
}

Expand All @@ -180,33 +180,33 @@
* @mngr: the pointer to keys manager.
* @enc_file: the encrypted XML file name.
*
* Decrypts the XML file #enc_file using DES key from #key_file and
* Decrypts the XML file #enc_file using DES key from #key_file and
* prints results to stdout.
*
* Returns 0 on success or a negative value if an error occurs.
*/
int
int
decrypt_file(xmlSecKeysMngrPtr mngr, const char* enc_file) {
xmlDocPtr doc = NULL;
xmlNodePtr node = NULL;
xmlSecEncCtxPtr encCtx = NULL;
int res = -1;

assert(mngr);
assert(enc_file);

/* load template */
doc = xmlParseFile(enc_file);
if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)){
fprintf(stderr, "Error: unable to parse file \"%s\"\n", enc_file);
goto done;
goto done;
}

/* find start node */
node = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeEncryptedData, xmlSecEncNs);
if(node == NULL) {
fprintf(stderr, "Error: start node not found in \"%s\"\n", enc_file);
goto done;
goto done;
}

/* create encryption context */
Expand All @@ -221,7 +221,7 @@
fprintf(stderr,"Error: decryption failed\n");
goto done;
}

/* print decrypted data to stdout */
if(encCtx-&gt;resultReplaced != 0) {
fprintf(stdout, "Decrypted XML data:\n");
Expand All @@ -230,38 +230,38 @@
fprintf(stdout, "Decrypted binary data (" XMLSEC_SIZE_FMT " bytes):\n",
xmlSecBufferGetSize(encCtx-&gt;result));
if(xmlSecBufferGetData(encCtx-&gt;result) != NULL) {
fwrite(xmlSecBufferGetData(encCtx-&gt;result),
1,
fwrite(xmlSecBufferGetData(encCtx-&gt;result),
1,
xmlSecBufferGetSize(encCtx-&gt;result),
stdout);
}
}
fprintf(stdout, "\n");

/* success */
res = 0;

done:
done:
/* cleanup */
if(encCtx != NULL) {
xmlSecEncCtxDestroy(encCtx);
}

if(doc != NULL) {
xmlFreeDoc(doc);
xmlFreeDoc(doc);
}
return(res);
}

/**
* create_files_keys_mngr:
*
* Creates a files based keys manager: we assume that key name is
*
* Creates a files based keys manager: we assume that key name is
* the key file name,
*
* Returns pointer to newly created keys manager or NULL if an error occurs.
*/
xmlSecKeysMngrPtr
xmlSecKeysMngrPtr
create_files_keys_mngr(void) {
xmlSecKeyStorePtr keysStore;
xmlSecKeysMngrPtr mngr;
Expand All @@ -272,7 +272,7 @@
fprintf(stderr, "Error: failed to create keys store.\n");
return(NULL);
}

/* create keys manager */
mngr = xmlSecKeysMngrCreate();
if(mngr == NULL) {
Expand All @@ -288,7 +288,7 @@
xmlSecKeysMngrDestroy(mngr);
return(NULL);
}

/* initialize crypto library specific data in keys manager */
if(xmlSecCryptoKeysMngrInit(mngr) &lt; 0) {
fprintf(stderr, "Error: failed to initialize crypto data in keys manager.\n");
Expand All @@ -303,19 +303,19 @@

/****************************************************************************
*
* Files Keys Store: we assume that key's name (content of the
* &lt;dsig:KeyName/&gt; element is a name of the file with a key (in the
* Files Keys Store: we assume that key's name (content of the
* &lt;dsig:KeyName/&gt; element is a name of the file with a key (in the
* current folder).
* Attention: this probably not a good solution for high traffic systems.
*
*
***************************************************************************/
static xmlSecKeyPtr files_keys_store_find_key (xmlSecKeyStorePtr store,
const xmlChar* name,
xmlSecKeyInfoCtxPtr keyInfoCtx);
static xmlSecKeyStoreKlass files_keys_store_klass = {
sizeof(xmlSecKeyStoreKlass),
sizeof(xmlSecKeyStore),
BAD_CAST "files-based-keys-store", /* const xmlChar* name; */
BAD_CAST "files-based-keys-store", /* const xmlChar* name; */
NULL, /* xmlSecKeyStoreInitializeMethod initialize; */
NULL, /* xmlSecKeyStoreFinalizeMethod finalize; */
files_keys_store_find_key, /* xmlSecKeyStoreFindKeyMethod findKey; */
Expand All @@ -327,13 +327,13 @@

/**
* files_keys_store_get_klass:
*
*
* The files based keys store klass: we assume that key name is the
* key file name,
*
* Returns files based keys store klass.
*/
xmlSecKeyStoreId
xmlSecKeyStoreId
files_keys_store_get_klass(void) {
return(&amp;files_keys_store_klass);
}
Expand All @@ -343,7 +343,7 @@
* @store: the pointer to simple keys store.
* @name: the desired key name.
* @keyInfoCtx: the pointer to &lt;dsig:KeyInfo/&gt; node processing context.
*
*
* Lookups key in the @store. The caller is responsible for destroying
* returned key with #xmlSecKeyDestroy function.
*
Expand All @@ -353,16 +353,16 @@
files_keys_store_find_key(xmlSecKeyStorePtr store, const xmlChar* name, xmlSecKeyInfoCtxPtr keyInfoCtx) {
xmlSecKeyPtr key;
const xmlChar* p;

assert(store);
assert(keyInfoCtx);

/* it's possible to do not have the key name or desired key type
/* it's possible to do not have the key name or desired key type
* but we could do nothing in this case */
if((name == NULL) || (keyInfoCtx-&gt;keyReq.keyId == xmlSecKeyDataIdUnknown)){
return(NULL);
}

/* we don't want to open files in a folder other than "current";
* to prevent it limit the characters in the key name to alpha/digit,
* '.', '-' or '_'.
Expand All @@ -372,7 +372,7 @@
return(NULL);
}
}

if((keyInfoCtx-&gt;keyReq.keyId == xmlSecKeyDataDsaId) || (keyInfoCtx-&gt;keyReq.keyId == xmlSecKeyDataRsaId)) {
/* load key from a pem file, if key is not found then it's an error (is it?) */
key = xmlSecCryptoAppKeyLoad((const char*)name, xmlSecKeyDataFormatPem, NULL, NULL, NULL);
Expand All @@ -393,7 +393,7 @@
if(xmlSecKeySetName(key, name) &lt; 0) {
fprintf(stderr,"Error: failed to set key name for key from \"%s\"\n", (const char*)name);
xmlSecKeyDestroy(key);
return(NULL);
return(NULL);
}

return(key);
Expand Down
Loading

0 comments on commit 59d7451

Please sign in to comment.