Add extension to CertificateRequestMessage - java

I'm trying to put a custom element (a template name to use for the PKI) in my Certificate request that I generate using bouncycastle library.
The RFC says that you can use an extension that follows :
id-regInfo-utf8Pairs OBJECT IDENTIFIER ::= { id-regInfo 1 }
--with syntax UTF8Pairs ::= UTF8String
The few lines of code concerning this are
CertificateRequestMessageBuilder msgbuilder = new
CertificateRequestMessageBuilder(BigInteger.valueOf(reqId));
msgbuilder.addExtension(new ASN1ObjectIdentifier("1.3.6.1.5.5.7.7.5.2.1"), false, ???);
I can't find any information on what to put in that addExtension function, nor any example to adapt from.
I guess the new ASN1ObjectIdentifier("1.3.6.1.5.5.7.7.5.2.1") is close to what is expected, but the following ASN1Encodable that is supposed to be the value of that field is a mystery to me.
I just want to get something along template:encipherment in that field.
This seems like a pretty simple thing to do but the lack of documentation coupled to my lack of experience with BouncyCastle causes me a lot of problems.
The questions are :
Am I doing what I want the correct way ? (Using the extensions of the CRMF to convey my custom field)
If I do, how do I make this work ?

Related

C_FindObjectsInit(..) from PKCS11 class exception

To sign data, I am using signserver open-source code. I was exploring a legacy code where
it gives error at this place:
Module.getPKCS11Module().C_FindObjectsInit(session.getSessionHandle(), attributes,true);
where the Module class is from iaikpkcs11Wrapper.jar (package: iaik.pkcs.pkcs11)
As I navigate further, PKCS11 interface has this method void C_FindObjectsInit(long var1, CK_ATTRIBUTE[] var3, boolean var4) mentioned above.
Moreover, the attributes param is constructed like below:
CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTEKeyStoreContainerBase[2];
attributes[0] = new CK_ATTRIBUTE();
attributes[0].type = PKCS11Constants.CKA_CLASS;
attributes[0].pValue = new Long(PKCS11Constants.CKO_SECRET_KEY);
attributes[1] = new CK_ATTRIBUTE();
attributes[1].type = PKCS11Constants.CKA_ID;
attributes[1].pValue = id; //id is byteArray. For this param's value the error is causing
My question is, do I need to store any kind of key/certificate from where C_FindObjectsInit(..) will read or match as it says that it couldn't find any key? Where does this method search the key or how to resolve this issue?
Btw, I have read C_FindObjectsInit-JavaDoc and couldn't understand this line properly, that's why I am here:
pTemplate - the object's attribute values to match and the number of
attributes in search template (PKCS#11 param: CK_ATTRIBUTE_PTR
pTemplate, CK_ULONG ulCount)
[this may sound peculiar question, but I am really blank and stuck for few days]
PKCS#11 specification don't force us to use some strictly composed data.
But in most implementations I saw it was binary encoded OID field.
Also check for 0 (null) bytes in sequence.

Parse a .ttl file and map it to a Java class

I am new to OWL 2, and I want to parse a ".ttl" file with OWL API, but I found that OWL API is not same as the API I used before. It seems that I should write a "visitor" if I want to get the content within a OWLAxiom or OWLEntity, and so on. I have read some tutorials, but I didn't get the proper way to do it. Also, I found the tutorials searched were use older version of owl api. So I want a detailed example to parse a instance, and store the content to a Java class.
I have made some attempts, my codes are as follows, but I don't know to go on.
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
File file = new File("./source.ttl");
OWLOntology localAcademic = manager.loadOntologyFromOntologyDocument(file);
Stream<OWLNamedIndividual> namedIndividualStream = localAcademic.individualsInSignature();
Iterator<OWLNamedIndividual> iterator = namedIndividualStream.iterator();
while (iterator.hasNext()) {
OWLNamedIndividual namedIndividual = iterator.next();
}
Instance for example are as follows. Specially, I want store the "#en" in the object of "ecrm:P3_has_note".
<http://data.doremus.org/performance/4db95574-8497-3f30-ad1e-f6f65ed6c896>
a mus:M42_Performed_Expression_Creation ;
ecrm:P3_has_note "Créée par Teodoro Anzellotti, son commanditaire, en novembre 1995 à Rotterdam"#en ;
ecrm:P4_has_time-span <http://data.doremus.org/performance/4db95574-8497-3f30-ad1e-f6f65ed6c896/time> ;
ecrm:P9_consists_of [ a mus:M28_Individual_Performance ;
ecrm:P14_carried_out_by "Teodoro Anzellotti"
] ;
ecrm:P9_consists_of [ a mus:M28_Individual_Performance ;
ecrm:P14_carried_out_by "à Rotterdam"
] ;
efrbroo:R17_created <http://data.doremus.org/expression/2fdd40f3-f67c-30a0-bb03-f27e69b9f07f> ;
efrbroo:R19_created_a_realisation_of
<http://data.doremus.org/work/907de583-5247-346a-9c19-e184823c9fd6> ;
efrbroo:R25_performed <http://data.doremus.org/expression/b4bb1588-dd83-3915-ab55-b8b70b0131b5> .
The contents I want are as follows:
class Instance{
String subject;
Map<String, Set<Object>> predicateToObject = new HashMap<String,Set<Object>>();
}
class Object{
String value;
String type;
String language = null;
}
The version of owlapi I am using is 5.1.0. I download the jar and the doc from there. I just want to know how to get the content I need in the java class.
If there are some tutorials that describe the way to do it, please tell me.
Thanks a lot.
Update: I have known how to do it, when I finish it, I will write an answer, I hope it can help latecomers of OWLAPI.
Thanks again.
What you need, once you have the individual, is to retrieve the data property assertion axioms and collect the literals asserted for each property.
So, in the for loop in your code:
// Let's rename your Object class to Literal so we don't get confused with java.lang.Object
Instance instance = new Instance();
localAcademic.dataPropertyAssertionAxioms()
.forEach(ax -> instance.predicateToObject.put(
ax.getProperty().getIRI().toString(),
Collections.singleton(new Literal(ax.getObject))));
This code assumes properties only appear once - if your properties appear multiple times, you'll have to check whether a set already exists for the property and just add to it instead of replacing the value in the map. I left that out to simplify the example.
A visitor is not necessary for this scenario, because you already know what axiom type you're interested in and what methods to call on it. It could have been written as an OWLAxiomVisitor implementing only visit(OWLDataPropertyAssertionAxiom) but in this case there would be little advantage in doing so.

RUL-05717: The identifier "Header.Teachers.Courses" is not valid here

I am trying to add rules in my Oracle dictionary through programming in ADF and JDeveloper:
Rule rule = ruleset.getRuleTable().add();
rule.setName(aliasRule);
rule.setAlias(aliasRule);
rule.setPriority(property);
rule.setAdvancedMode(true);
rule.setDescription(description);
return rule;
then:
diccionaryRules.validate(exceptions, warnings);
I have three warnings with the same message:
RUL-05717: The identifier "Header.Teachers.Courses" is not valid here.
Where in my Oracle.rules file I have three viewobjects connected by links through private key ids:
HeaderVVO
TeachersVVO
CoursesVVO
And the route is correct: Header.Teachers.Courses.
I created an expression from the follwoing path:
Header.Teachers by:
Expression ePath = simpleTest.getExpressionTable().get(0);
ePath.setValue("Header.Teachers");
// Here comes some validation
List<SDKWarning> warnings = new ArrayList<SDKWarning>();
List<SDKException> exceptions = new ArrayList<SDKException>();
ePath.validate(exceptions, warnings);
it doesn't give warnings, but this:
ePath.setValue("Header.Teachers.Courses");
gives the above warning.
I don't know why I get these warnings.
You should presume that most of the people trying to answer this question (myself included) while having a good understanding on ADF, don't know much about Oracle Rules.
That being said, this looks like a problem on Rules side, rather than on ADF. As I see you are using view objects, you can probably test this integration logic from Business Components Tester and you can inject your Rules logic through application modules custom methods.
Bottom line, you are building a Rules client from java, this is not directly related to ADF. If you can make your client work from a java main(String[] args) method, it will work from ADF too.

Exception while creating custom object using Salesforce CRUD Metadata API

I am getting the following exception when I try to create a Custom Object in Salesforce, using CRUD Matadata API.
com.sforce.ws.SoapFaultException: Must specify a {http://www.w3.org/2001/XMLSchema-instance}
type attribute value for the {http://soap.sforce.com/2006/04/metadata}metadata element
at com.sforce.ws.transport.SoapConnection.createException(SoapConnection.java:205)
at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:149)
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:98)
at com.sforce.soap.metadata.MetadataConnection.create(MetadataConnection.java:273)
at com.sfo.service.SalesforceObjectBootstrap.createCustomObject(SalesforceObjectBootstrap.java:226)
I am using the code from this link, The only thing that I changed were the name of the Custom Object
http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_calls_intro.htm
The exception occurs at this step
AsyncResult[] asyncResults = metadataConnection.create(new CustomObject[]{customObject});
The Custom object just before invoking the create method above has the following parameter values.
[CustomObject [Metadata fullName='lead_5273_custom_reg__c'
]
actionOverrides='{[0]}'
articleTypeChannelDisplay='null'
businessProcesses='{[0]}'
customHelp='hey there help me'
customHelpPage='null'
customSettingsType='null'
customSettingsVisibility='null'
deploymentStatus='Deployed'
deprecated='false'
description='Created from backend Webcast API : Lead 5273 Custom Reg'
enableActivities='false'
enableDivisions='false'
enableEnhancedLookup='false'
enableFeeds='false'
enableHistory='false'
enableReports='false'
fieldSets='{[0]}'
fields='{[0]}'
gender='null'
household='false'
label='Lead 5273 Custom Reg'
listViews='{[0]}'
nameField='[CustomField [Metadata fullName='lead_5273_custom_reg__c'
]
caseSensitive='false'
customDataType='null'
defaultValue='null'
deleteConstraint='null'
deprecated='false'
description='field name for a metadata custom object'
displayFormat='null'
escapeMarkup='false'
externalDeveloperName='null'
externalId='false'
formula='null'
formulaTreatBlanksAs='null'
inlineHelpText='null'
label='Lead 5273 Custom Reg'
length='0'
maskChar='null'
maskType='null'
picklist='null'
populateExistingRows='false'
precision='0'
referenceTo='null'
relationshipLabel='null'
relationshipName='null'
relationshipOrder='0'
reparentableMasterDetail='false'
required='false'
restrictedAdminField='false'
scale='0'
startingNumber='0'
stripMarkup='false'
summarizedField='null'
summaryFilterItems='{[0]}'
summaryForeignKey='null'
summaryOperation='null'
trackFeedHistory='false'
trackHistory='false'
type='Text'
unique='false'
visibleLines='0'
writeRequiresMasterRead='false'
]
'
namedFilters='{[0]}'
pluralLabel='Lead 5273 Custom Regs'
recordTypeTrackFeedHistory='false'
recordTypeTrackHistory='false'
recordTypes='{[0]}'
searchLayouts='null'
sharingModel='ReadWrite'
sharingReasons='{[0]}'
sharingRecalculations='{[0]}'
startsWith='null'
validationRules='{[0]}'
webLinks='{[0]}'
]
I used the method mentioned here to generate the WSDL files and its java skeleton.
http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_quickstart.htm#topic-title-sample-code
My code exactly matches the example provided above. I simply copy pasted the whole thing.
I found this link, which mentioned the same exception. But this link is relating to creating a Folder.
http://boards.developerforce.com/t5/Java-Development/Metadata-API-errors-Must-specify-a-type-attribute-value-for-the/td-p/175253
Please let me know how to solve this problem.
I've not played with this myself, but from the looks of the exception, the MetaData block here:
[CustomObject [Metadata fullName='lead_5273_custom_reg__c']
needs to contain the object type, which I'm assuming in this case is CustomObject__c (all custom objects have the __c suffix), so maybe try the following:
[CustomObject [Metadata fullName='lead_5273_custom_reg__c' type='CustomObject__c']
Unless of course, fullname is actually the object name, which could be a possibility.

What does the #sign do?

I have seen the at (#) sign in Groovy files and I don't know if it's a Groovy or Java thing. I have tried to search on Google, Bing, and DuckDuckGo for the mystery at sign, but I haven't found anything. Can anyone please give me a resource to know more about what this operator does?
It's a Java annotation. Read more at that link.
As well as being a sign for an annotation, it's the Groovy Field operator
In Groovy, calling object.field calls the getField method (if one exists). If you actually want a direct reference to the field itself, you use #, ie:
class Test {
String name = 'tim'
String getName() {
"Name: $name"
}
}
def t = new Test()
println t.name // prints "Name: tim"
println t.#name // prints "tim"
'#' is an annotations in java/ Groovy look at the demo :Example with code
Java 5 and above supports the use of annotations to include metadata within programs. Groovy 1.1 and above also supports such annotations.
Annotations are used to provide information to tools and libraries.
They allow a declarative style of providing metadata information and allow it to be stored directly in the source code.
Such information would need to otherwise be provided using non-declarative means or using external files.
It can also be used to access attributes when parsing XML using Groovy's XmlSlurper:
def xml = '''<results><result index="1"/></results>'''
def results = new XmlSlurper().parseText(xml)
def index = results.result[0].#index.text() // prints "1"
http://groovy.codehaus.org/Reading+XML+using+Groovy's+XmlSlurper

Categories