How can I add UnsignedProperties? - java

I'm trying to sign a XML document using XADES-BES and the smart card.
I made some changes in the class SignerBES.java according to my needs and the signature creation is working well !
My question: How can I add UnsignedProperties to get something like this :
<SignerRole>
<ClaimedRoles>
<ClaimedRole>EST</ClaimedRole>
</ClaimedRoles>
</SignerRole>
</SignedSignatureProperties>
<SignedDataObjectProperties>
<DataObjectFormat ObjectReference="#sigId">
<Description>des</Description>
<MimeType>text/xml</MimeType>
<Encoding>base64</Encoding>
</DataObjectFormat>
<CommitmentTypeIndication>
<CommitmentTypeId>
<Identifier/>
</CommitmentTypeId>
<AllSignedDataObjects/>
<CommitmentTypeQualifiers>
<CommitmentTypeQualifier>commitment</CommitmentTypeQualifier>
</CommitmentTypeQualifiers>
</CommitmentTypeIndication>
</SignedDataObjectProperties>
</SignedProperties>
<UnsignedProperties>
<UnsignedSignatureProperties>
<SignatureTimeStamp>
<EncapsulatedTimeStamp>noTimStampToken</EncapsulatedTimeStamp>
</SignatureTimeStamp>
<CounterSignature/>
<CompleteCertificateRefs/>
<CompleteRevocationRefs/>
<SigAndRefsTimeStamp/>
<RefsOnlyTimeStamp/>
<CertificatesValues/>
<RevocationValues/>
<ArchiveTimeStamp/>
</UnsignedSignatureProperties>
</UnsignedProperties>
</QualifyingProperties>
</ds:Object>
this is a code snippet SignerBES.java:
Collection<SignedSignatureProperty> fsssp = new ArrayList<SignedSignatureProperty>(2);
Collection<UnsignedSignatureProperty> fsusp = new ArrayList<UnsignedSignatureProperty>(2);
getFormatSpecificSignatureProperties(fsssp, fsusp, signingCertificateChain);
// Gather all the signature and data objects properties.
QualifyingProperties qualifProps = qualifPropsProcessor.getQualifyingProperties(
signedDataObjects, fsssp, fsusp);
// LOG
System.out.println("fsusp"+fsusp.size());
I tried to add it at SignerBES.java and DefaultSignaturePropertiesProvider.java but I do not know how I can add it :
public class DefaultSignaturePropertiesProvider implements SignaturePropertiesProvider
{
#Override
public void provideProperties(SignaturePropertiesCollector signaturePropsCol)
{
signaturePropsCol.setSigningTime(new SigningTimeProperty());
signaturePropsCol.setSignerRole(new SignerRoleProperty("EST"));
// UnsignedProperty
// OtherUnsignedSignatureProperty otherUnsignedProp=null;
// signaturePropsCol.addOtherSignatureProperty(otherUnsignedProp);
}}

I don't think I understand completely what you're trying, since it seems you're messing around the lib source code. Anyway, check out this page on the project docs.
Many of the unsigned qualifying properties are added automatically by xades4j when you use one of the signing profiles (e.g. if you use XAdesCSigningProfile, CompleteCertificateRefs/CompleteRevocationRefs are added).
Other properties are part of advanced forms and can only be added during validation of an existing signature. Refer to this wiki page and [this javadocs page](http://luisgoncalves.github.io/xades4j/javadocs/1.4.0/reference/xades4j/verification/XadesVerifier.html#verify(org.w3c.dom.Element, xades4j.verification.SignatureSpecificVerificationOptions, xades4j.production.XadesSignatureFormatExtender, xades4j.verification.XAdESForm)) for additional info.
Finally, some properties (e.g. CounterSignature) are not tied to any specific form, and can be added to any signature using a custom SignaturePropertiesProvider, registered on the signing profile that you are using.

Related

Azure Function (Java) add attribute to CustomDimensions

I am desperatly searching on how to add a new attribute to the custom dimensions collection in the request table of the log analytics in the context of a Java function.
I know in C# you can do it using Activity and ITelementryInitializer but for Java I can not get it to work.
Any hints are appreciated. ;)
Azure Function (Java) add attribute to CustomDimensions
In Java, we have the Span attributes concept for adding the optional (extra) fields to the App Insights Schema that populates with the customDimensions in the form of various tables such as traces, exceptions, dependencies.
For that, one of the dependencies is required which is opentelemetry-api-1.jar.
AttributeKey newAttributeKey= AttributeKey.stringKey("resourcecustomDimension"); Span.current().setAttribute(newAttributeKey, "customDimValue");
This brings us the custom attributes for the custom dimensions that will be added to the Telemetry data.
Refer to this MS Doc for more information on adding the attributes to the customDimensions and found the GitHub issue 13310 regarding the user seeking for the Java Code on ITelemetryInitializer where the sample code on it provided by #dhaval24 user.

LibGDX Android Production Failing to Load from JSON

I have developed and released a game using LibGDX platform for Android. I'm using Json to save and load information:
To save an object (a rocket class):
Json json = new Json();
String rocketStr = json.toJson(rocket);
To load this object:
Rocket rocket = json.fromJson(Rocket.class, rocketStr);
After the release, I have added a new advertising provider (adMob) and released the update to the game. I have not made any changes to the classes which are being saved. And I have not changed any library versions. The only change was some new classes added and used in the project.
With this new update the game could no longer load the saved objects with Json - it would come up with an exception when trying to run json.fromJson(Rocket.class, rocketStr); Exceptions would differ but mainly there were two: 1) property not found or 2) unable to cast value to some property.
After some experimenting, I found out that in production Android (or LibGDX?) obscures all the class names and property names and when Json is writing a class the resulting string looks like this:
{A:97.50652,A2:{E:RIGHTTHRUSTER,F:true,a:Liberator Thrusters,b:2,d:false,f:true,g:{}},H:24.934832,I:10,J:true,K:30,M2:1587,N2:1647,O2:1527,Y:-7.3379517,a:{seed0:28965116732361103,seed1:-4728429348234121846},a0:-19.308016,b:Liberator,b0:17.0175,c:1,d:1,e:false,j0:{a:500},m:true,o:497.43192,p:1587,s:100,t:100,u2:{E:TOP,F:true,a:Liberator Nose,b:1,c:1,d:false,f:true,f0:[],g:{}},z2:{E:LEFTTHRUSTER,F:true,a:Liberator Thrusters,b:2,c:1,d:false,f:true,f0:[],g:{}}}
And after the update, the same object saved has some different field names:
{B2:{E:LEFTTHRUSTER,F:true,a:Liberator Thrusters,b:43,c:1,f:true,f0:[],g:{}},C:100,D2:{E:RIGHTTHRUSTER,F:true,a:Liberator Thrusters,b:43,f:true,g:{}},J:0.128269,K:-7.5,L:true,N:true,O2:1587,P2:1647,Q2:1527,R:-5,a0:-2.9551423,c:{seed0:-3537680883966184457,seed1:6879650071827728698},d:Liberator,e:17,f:1,l0:{a:500},o:true,q:595.54803,r:1587,u:100,v:100,w2:{E:TOP,F:true,a:Liberator Nose,b:42,c:1,f:true,f0:[],g:{}}}
For example, in first example one of the properties is called 'A2' and in the second example the same property is called 'D2'
Is my understanding correct that Android (or LibGDX?) can change the obfuscated class names for the same classes when I make some changes to the project?
And most importantly, what can I do to make sure that the class / property names stay the same to be able to save and load the same object with Json after any updates? Are there any alternatives / better methods to save / load information?

How do i add drop down field for credentials in the plugin im devloping

I am some what new to extending Jenkins and was wondering how would i generate the code for adding a credentials drop down like the one in this picture.
(source: jenkins.io)
I have looked at some examples and noted they used this jelly code
<f:entry title="${%Credentials}" field="credentialsId">
<c:select/>
</f:entry>
But when i implement this my Credentials line in the build job settings dose not contain the drop down.
Note figured it out. Posting answer for others benefit. In order to dynamically fill the list you must create a doFillCredentialsIdItems like the method bellow along with adding a import to the credentials plugin.
public ListBoxModel doFillCredentialsIdItems(#AncestorInPath Item item, #QueryParameter String credentialsId) {
StandardListBoxModel result = new StandardListBoxModel();
return result
.includeEmptyValue()
.includeAs(ACL.SYSTEM, Jenkins.get(),
UsernamePasswordCredentialsImpl.class)
.includeCurrentValue(credentialsId);
}

Java method that writes to file does nothing when invoked from a JSP

Hey, all! I have a class method who's primary function is to get a Map object, which works fine; however, it's an expensive operation that doesn't need to be done every time, so I'd like to have the results stored in an XML file using JAXB, to be read from for the majority of calls and updated infrequently.
When I run a class that calls it out of NetBeans the file is created no problem with exactly what I want -- but when I have my JSP call the method nothing happens whatsoever, even though the rest of the information is passed normally. I have the feeling it's somehow lacking write privileges, but the file is just in the root directory so I'm not sure what I'm missing. Thanks for the help!
The code looks roughly like this:
public class DataHandler() {
...
public void config() {
MapHolder bucket = new MapHolder();
MapExporter exp = new MapExporter();
Map map = makeMap();
bucket.setMap(map);
exp.exportMap(bucket);
}
}
And then the JSP has a javabean of Datahandler, and this line:
databean.config();
It's probably a tad more fragmented than it needs to be; the whole bucket rigamarole was because I was stumbling trying to learn how to write a map to an xml file. Mapholder is just a class that I wrap around the map, and MapExporter just uses a JAXB marshaller, and it all does work properly when run from NetBeans.
OK turns out I'm just dumb; everything was working fine, the file was just being stored in a folder at the localhost location. Whoops! That'd be my inexperience with web development at work.

Scala Lift - Reading a file from "/resources/toserve"

I'm attempting to provide a StreamingResponse for files stored under Lifts resources/toserve directory, in order to authorize access for different users.
I can access an image for example with:
localhost:8080/classpath/images/test.jpg
But when I try and actually read the file using scala I keep getting file not found exceptions:
val file = new java.io.FileInputStream("/classpath/images/test.jpg")
Is there a specific method to reading files located on classpath?
Thanks in advance, much appreciated :)
To read resources from the toserve-directory you need to do a call like
LiftRules.getResource("/toserve/images/test.jpg")
If you try to use 'classpath' instead of 'toserve' you will receive an empty box.
By default, Lift uses two different path-prefixes to locate resources either programmatically within the server or through a link-element from HTML. For the former, you will use the 'toserve'-prefix, for the latter the 'classpath'-prefix.
This behavior is specified in the objects net.liftweb.http.LiftRules and net.liftweb.http.ResourceServer. In particular, you can there specify (i.e. replace) the path to the resources. The relevant code is:
/** (from net.liftweb.http.ResourceServer)
* The base package for serving resources. This way, resource names can't be spoofed
*/
var baseResourceLocation = "toserve"
You might also want to look at the following method in LiftRules, which allows you to redefine the name used to serve resources through the server:
/** (from net.liftweb.http.LiftRules)
* The path to handle served resources
*/
#volatile var resourceServerPath = "classpath"
If you wish to use the same prefix to refer both to resources you can use either (or both) of these settings to achieve your purpose.
Have you tried:
LiftRules.getResource("/classpath/images/test.jpg")
That should return a java.net.URL to the item you are looking for.
This may also have more information on what you are looking to do: http://exploring.liftweb.net/master/index-9.html#lst:streaming-download

Categories

Resources