xades4j: how to produce an signature with a transform in the signedproperties reference - xades4j

I received an example xades signature that I have to reproduce using xades4j ("like a template").
The example signature is this (an excerpt):
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="xmldsig-qualifyingproperties-yada-yada">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<ds:Reference URI="#xmldsig-signedproperties-yada-yada">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<ds:DigestValue>yada-yada-yada-yada-yada-yada-yada</ds:DigestValue>
</ds:Reference>
(...)
I know that this reference is not xades compliant, because there is no attribute Type there.
My issue is with the Transform in that Reference. I'm not able to find how can I set this option with xades4j. Can this be done?
Also, I don't know if that is here make sense, because at the signature top, it says that the canonicalization method is one then in the signedproperties reference it says the canonicalization method is another one... Am I reading this correctly?

You cannot set transforms on the signed properties reference. This is motivated by both:
being uncertain about the need - the resource being signed (the actual signed properties element) is actually generated by xades4j so it doesn't make much sense to allow external control.
security - arbitrary transforms cannot be allowed because the library needs to be sure that the reference points to the SignedProperties element.
Probably the only transform that could be used is canonicalization, but XML-DSIG already specifies that if the dereferenced resource is a nodeset it must be canonicalized before digest using C14N as default algorithm, which xades4j/santuario will use. On your example, the algorithm is the same, with the difference that it includes the comment nodes on the digest generation.
As for having 2 canonicalization algorithms, it's because they are different: the one in the reference's transforms is applied over the result of dereferencing that data object. on the other hand, the one at the top specifies the canonicalization algorithm that is used over the SignedInfo element to get the actual signature input (octet stream)

Related

How to include a remote vocabulary/namespace to OntModel using Jena?

I'm new to Semantic Web and Jena.
I want to generate an ontology from a OntModel in Jena and I need to use vocabulary and ontologies predefined to caracterize my classes and properties.
In Jena, there are default ontologies like RDF, FOAF...So we can specify class and add property to resource like:
ontClass.setSameAs(FOAF.Person);
ontClass.addProperty(FOAF.name, "name");
or
ontProperty.setRange(XSD.xstring);
But how can I refer my ontClass to another vocabulary/ontology that does not exist in Jena (GeoSparql, Geofla, vocabulary that I defined myself,etc.)? Knowing that I can have the URI for these vocabularies?
This question's already been raised in this topic: How to add vocabulary in Jena? which suggests using Jena Schemagen but I can't see how to do it.
Thank you a lot for helping!
I guess one of the option is to import (or read) theses vocabularies/ontologies so that you can use them using Jena Ontology API.
For example (if we assume that your ontModel is named m) you can read the OWL-Time ontology into your model like so :
m.read("http://www.w3.org/2006/time")
and then you can use the elements it defines using Jena's programmatic API :
OntClass instant = dataModel.getOntClass("http://www.w3.org/2006/time#Instant");
If you don't wan't to read the whole ontology within your model, you can also just "create" the necessary ressource / property using its URI :
Property inXSDDateTime = m.createDatatypeProperty(
"http://www.w3.org/2006/time#inXSDDateTime");
Resource resource = m.createResource("someURIForThisRessource");
Statement s = m.createStatement(
resource, inXSDDateTime, m.createTypedLiteral(someValue));
m.add(s);
It should write the result as expected (but, by doing this, you are not loading the axioms of the ontology you are referencing, so you won't be able to reason about it - but according to your comment, I'm thinking maybe that's what you want)

Where exactly does trainable_variables method belong in Tensorflow?

I'm a newbie in both deep learning and tensorflow and now trying to learn how to implement deep learning codes based on function API (not keras) by following example codes.
Inside the codes I'm looking at, I found out sources saying 'gradients=tape.gradient(loss,model.trainable variables)'
I intuitionally got what trainable variables mean, however in order to understand clearly,I tried to search on tensorflow documentation (which module or class the method belongs to, which are key arguments, etc) ,but I wasn't able to find the information I want. ('trainable variables' method was not in their documentation index and I'm wondering why)
So can anyone please tell me the module/class which trainable_variable method belongs to, and which arguments it takes, and also how it is able to judge and get all the trainable variables from the model ?
The reason you did not find this method is because trainable_variables is not a method, but an attribute/property. The Model class has a trainable_variables attribute, which is not documented officialy. It is inherited from the base class Layer, and to put it shortly, the list (of trainable variables) gets populated as new layers are added, since all layers have an init parameter trainable (this comes from base class Layer too). You can check the source code if you want to: "the source of the property", "adding new weights to layer appends to the list".

Two colons before the array`s toString() method

What does the two colons before the toString() method invocation mean?
For instance, I found the following code:
orderXml.ns::['status'].toString();
Is it the same as ['status'].toString().call(orderXml.ns);?
I am using the Demandware Script above.
Thank you.
In Demandware Script you'll find that a long-deprecated concept called E4X which extends the JavaScript 1.6/ES3 syntax still exists. However, it's usage is now discouraged. You can find some documentation for this syntax here: https://developer.mozilla.org/en-US/docs/Archive/Web/E4X/Processing_XML_with_E4X
In the script snippet you provided, the colons are used to identify the XML namespace of the following expression. Without that namespace, you may find that the incorrect object is referenced or you may get an undefined reference. See the specific area of the documentation archive linked above that pertains to Namespaces: https://developer.mozilla.org/en-US/docs/Archive/Web/E4X/Processing_XML_with_E4X#Handling_namespaces
The code essentially looks for an object property with the name: status. This isn't actually Array notation as it appears upon cursory inspection. Specifically, it looks for a namespaced property. It would not be the same as calling:
['status'].toString().call(orderXml.ns);
The .toString() method is used to ensure we get the String representation of the property rather than a reference to an instance of that XML Node.
Please note that Demandware uses a modified version of the Mozilla Rhino 1.7R5 JavaScript implementation. See feature matrix here: https://mozilla.github.io/rhino/compat/engines.html

What is the difference between LSP and OCP?

I have been trying to break down the differences between the Open Closed Principal and Liskov's Substitution Principal. And the best and most common examples of either use the exact same problem. Finding the Area of a shape class.
They use slightly different means, but effectively solve the same problem with the same solution.
As these are both parts of SOLID, I'm really trying to find a reason to support why both are called out.
I'm looking for an explanation that doesn't work for both.
Thanks.
LSP:
Consumers target an abstraction (e.g. interface) and should not need to know which concrete implementation stands behind the interface. For example, a client (e.g. a DocumentProcessor class) holds a dependency on IDocumentStore. If in V1, you gave it a SqlSeverDocumentStore instance, and then in V2 you gave it a FileSystemDocumentStore, the client (DocumentProcessor) should work without modification. This can be achieved by making sure the contract of IDocumentStore is well defined and that DocumentProcessor, SqlSeverDocumentStore and FileSystemDocumentStore abide by this contract.
The contract means much more than an interface. Having two classes implement the same interface does not mean they abide by the same contract (although they should).
For example, does both implementations support saving documents which are smaller or equal to 20MB? Or does one of them support documents that are at most 10MB? If it is part of the contract that an implementation should support 20MB documents, then all implementations should support this.
OCP:
We should avoid modifying a unit of composition (e.g. a class or a function) after we release it. One way to achieve this is to make the units parameterized. For example, if you have a function (say, ProcessImages) that reads images from the file system, compresses them and then sends them to some web service, you can parameterize this function to accept other functions that are responsible for (1) reading images, (2) compressing them, (3) sending them.
E.g. (in C#):
public static void ProcessImages(
Func<Image[]> getImages,
Func<Image, CompressedImage> compressImage,
Action<CompressedImage> sendImage)
{
//... Orchestrate the operation here
}
And, in the Composition Root:
Action processImages = () => ProcessImages(ReadImages, CompressImage, SendImage);
Where ReadImages, CompressImage, SendImage are themselves functions.
This way, if you want to change how the images are compressed, you will not modify the ProcessImages function. Instead you will create a new compression function (say CompressImageInADifferentWay) and then compose the ProcessImages function in the Composition Root like this:
Action processImages =
() => ProcessImages(ReadImages, CompressImageInADifferentWay, SendImage);
If you apply the OCP in a perfect way, only the Composition Root itself will change.
LSP allows us to achieve OCP. For example, because CompressImage and CompressImageInADifferentWay abide by some contract that ProcessImages knows about, we can replace CompressImage with CompressImageInADifferentWay without modifying ProcessImages.

ILSpy (a.k.a. .NET Reflector) shows a method as just calling itself, why?

When passing anonymous types to an HtmlHelper method like TextBox, you'll get binding errors (because anonymous type members have internal access only), unless you use a RouteDataDictionary to extract the members.
When I saw that the (HtmlHelper extension) InputExtensions.TextBox method accepted anonymous types, I knew it had to be doing some conversion internally or it would fail with the same error.
Sure enough, it calls HtmlHelper.AnonymousObjectToHtmlAttributes method, whose documentation tries to play down the issue by not mentioning it, instead suggesting it's just replacing underscores with dashes to ensure valid attribute names are used. Sure. Anyway...
I wanted to see exactly what that conversion looks like, but when I inspect HtmlHelper's static method with that name in ILSpy, the method appears to just call itself. What is going on here?
public static RouteValueDictionary AnonymousObjectToHtmlAttributes(object htmlAttributes)
{
return HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
}
The method AnonymousObjectToHtmlAttributes from System.Web.MVC.HtmlHelper is calling a method with the same name but from System.Web.WebPages.Html.HtmlHelper.
The ILSpy is not explicitly about that. I needed to hover the class to show from where it was coming:
I asked a similar question that was anwered here.