how to compress and decompress xml present in URL C++ - c++

I writing the saml SP in C++ but don't know how to compress the xml.
http://acme.com:16006/idp/samlv20?SAMLRequest={xmlCompressedandBase64encodedString}
Now xmlCompressedandBase64encodedString is the problematic part I know Base64 encoding but xml compression I am not aware off.
My saml request will be looking like this :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<samlp:AuthnRequest
xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"
xmlns:enc="http://www.w3.org/2001/04/xmlenc#"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:x500="urn:oasis:names:tc:SAML:2.0:profiles:attribute:X500"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
ID="id-_Abcd1234&-rQjG"
Version="2.0"
IssueInstant="2018-05-03T06:02:22Z"
Destination="http://acme.com:16006/idp/samlv20">
<saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">
https://flight.com::14213/sp
</saml:Issuer>
<samlp:NameIDPolicy AllowCreate="true"/>
</samlp:AuthnRequest>
Same goes for decompression of SamlRespone.

There is a wikipedia article indicating that you should use DEFLATE altorithm.
zlib is one of the most famous library that implements DEFLATE algorihm. I heard Boost.iostream can also do that using zlib as dependency, but I am not sure.

Related

Decrypt using RSA private key using windows crypto api

I have a RSA private key in xml format.
<?xml version="1.0" encoding="utf-16"?>
<RSAParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Exponent>....</Exponent>
<Modulus>....</Modulus>
<P>....</P>
<Q>....</Q>
<DP>....</DP>
<DQ>....</DQ>
<InverseQ>....</InverseQ>
<D>....</D>
</RSAParameters>
I have to decrypt some data in C++. I want to use Windows Crypto API in C++.
I am new into C++ and crypto. Cannot find any good sample code for this.
I am finding MSDN documentation a bit not for beginners. All I need is a set of library functions to read my private key from XML and decrypt some data. In C#, it is very straightforward. Don't understand why so complicated in C++.
Can anyone help me with the steps or sample codes or some beginner level resources for this.

Java XSLT processing throws TransformerConfigurationException when run on another machine

I am running a Java application which is supposed to do some XSLT processing based on javax.xml.transform.Transformer. I developed it on an older notebook using java-7-openjdk-amd64.
When I run it on another machine with java-8-openjdk-amd64 installed the Transformer throws the following exception:
javax.xml.transform.TransformerConfigurationException: Failed to
compile stylesheet. 1 error detected.
XPST0017: XPath syntax error [...]
Cannot find a matching 1-argument function named {http://xml.apache.org/xslt/java}java.text.SimpleDateFormat.new()
at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:176)
at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:139)
at net.sf.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:91)
The xsl file looks like this (leaving out unimportant details):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
<xsl:template match="/">
<html>
<body>
<h1>Test Report</h1>
<h2>Test run</a> at
[<xsl:value-of
select="java:format(java:java.text.SimpleDateFormat.new('dd.MM.yyyy HH:mm:ss'), java:java.util.Date.new())" />]
</h2>
So the Transformer obviously has a problem with invoking SimpleDateFormat, but why? I could not find any information about this in respect to Java7 vs. Java8. I even copied the Jar file compiled with Jdk7 an and ran it on the other machine. Same problem, so it seems to be a runtime issue.
There are some Q+A on SO about java and XSLT but nothing turned out to be useful for me.
It turned out be that this declaration <xsl:stylesheet version="2.0" does not ensure that XSLT v2.0 is actually used. javax.xml.transform.Transformer "secretly" used XSLT v1.0 on the old machine (with java-7-openjdk-amd64) and XSLT v2.0 with Saxon v9.1.0 on the other machine (with java-8-openjdk-amd64).
The dependency was set by a maven pom.xml at compile time. But apparently this had no effect when running it with Jre7. I could have noticed it by looking at the stack trace (net.sf.saxon.TransformerFactoryImpl) but since there were no errors before, I was not aware of any specific TransformerFactory implementation.

XSLT 2.0 functions don't work in Safari and Chrome?

This is my XML document:
<?xml version="1.0"?>
<?xml-stylesheet type='text/xml' href='/foo.xsl'?>
<document/>
This is /foo.xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:foo="foo"
version="2.0" exclude-result-prefixes="xs">
<xsl:function name="foo:const" as="xs:string">
<xsl:text>ABC</xsl:text>
</xsl:function>
<xsl:template match="/">
<xsl:value-of select="foo:const()"/>
</xsl:template>
</xsl:stylesheet>
Works fine with Saxon 8.7 and produces ABC, as an output. But in Safari and in Chrome this document doesn't work (just an empty page with no error messages). What is it about? Safari and Chrome don't support XSL functions?
Sadly, none of the browsers yet support XSLT 2.0 natively. I think they're all waiting for the others to move first.
Have you tried using SaxonCE?
This is Saxon 9.x implemented in Javascript -- it is reported to work with any of the five major browsers.
At the last Balisage conference Michael Kay (#Michael Kay ) demoed this working on his iPhone.

Xalan date extension problem

i'm trying to use the ubuntu cli version of xalan:
Xalan version 1.10.0
Xerces version 2.8.0
My problem is how to kick in with date functions. I tryed like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">
<xsl:import href="date/date.xsl" />
<xsl:output method="text" indent="yes" />
date: <xsl:value-of select="date:date()" />
</xsl:stylesheet>
It gives me back this message:
XSLException Type is: XalanXPathException
Message is: The function number 'http://exslt.org/dates-and-times:date' is not available. (file:///home/user/test.xsl, line x, column y)
What files or what do i need to change to make those date functions work?
You need to use a later version of Xalan.
From the Xalan J.2.7.1 documentation:
EXSLT extensions
Xalan-Java supports the EXSLT
initiative to provide a set of
standard extension functions and
elements to XSLT users. Xalan-Java
includes implementations for the
following EXSLT extension modules:
EXSLT common functions EXSLT math
functions EXSLT set functions
EXSLT date-and-time functions
EXSLT dynamic functions
EXSLT string functions
The EXSLT func:function and
func:result elements (see EXSLT -
func:function)
The documentation shows that it has built-in beta implementations for that subset, however it does not say you cannot import and use the functions from exslt.org. Why can't you? Does Xalan-c++ not support importing functions?
Note that, I was able to get the templates working. Just not the functions.
From http://xml.apache.org/xalan-c/extensionslib.html
Xalan-C++ includes beta
implementations for functions in four
of the EXSLT namespaces (some are
calls to extension already in the
Xalan namespace).
And from http://xml.apache.org/xalan-c/apiDocs/XalanEXSLTDateTimeImpl_8hpp.html, it looks like only date:date-time() have been implemented.

Sorting an XML file with Qt

how to to sort an XML file using Qt
my file look like this :
<?xml version="1.0" encoding="UTF-8"?>
<project>
<task next="2" first="1" name="2" value="name1"/>
<task next="3" first="1" name="1" value="name2"/>
<task next="4" first="3" name="4" value="name3"/>
<task next="4" first="1" name="6" value="name4"/>
<task next="5" first="2" name="3" value="name5"/>
<task next="5" first="4" name="5" value="name6"/>
</project>
Thanks.
Basically, you need to parse the XML file into a set of records, sort the records on the appropriate field, then write the result back out as a new XML file. There are zillions of XML parsers out there that are intended to make it easy for you to parse the data. Personally, I've always written my own code to handle it. It's almost as fast to write, and executes quite a bit faster -- but that's me, and the XML I've parsed this was has mostly been fairly simple. If you lack experience at writing parsers and/or don't care as much about execution speed, chances are that using an existing parser will be a better choice.
What do you mean by sorting an xml file?
I think this needs a bit more thought.
Either sort the values after you read them from the file in your app or to work on the XML file directly
You may wish to look into xslt.