use of iso.std.iso_iec._24727.tech.schema.CardInfo in project open-ecard by ecsec.
the class AndroidMarshallerTest method testConversionOfCardInfo.
@Test
public void testConversionOfCardInfo() throws Exception {
WSMarshaller m = new AndroidMarshaller();
Object o = m.unmarshal(m.str2doc(NPA_CIF));
if (!(o instanceof CardInfo)) {
throw new Exception("Object should be an instace of CardInfo");
}
CardInfo cardInfo = (CardInfo) o;
assertEquals("http://bsi.bund.de/cif/npa.xml", cardInfo.getCardType().getObjectIdentifier());
assertEquals(new byte[] { 0x3F, 0x00 }, cardInfo.getApplicationCapabilities().getImplicitlySelectedApplication());
assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().size(), 3);
assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getApplicationName(), "MF");
assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getRequirementLevel(), BasicRequirementsType.PERSONALIZATION_MANDATORY);
assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getCardApplicationACL().getAccessRule().size(), 40);
assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getCardApplicationACL().getAccessRule().get(0).getCardApplicationServiceName(), "CardApplicationServiceAccess");
assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getCardApplicationACL().getAccessRule().get(0).getAction().getAPIAccessEntryPoint(), APIAccessEntryPointName.INITIALIZE);
assertTrue(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getCardApplicationACL().getAccessRule().get(0).getSecurityCondition().isAlways());
// last accessrule
assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getCardApplicationACL().getAccessRule().get(39).getAction().getAuthorizationServiceAction(), AuthorizationServiceActionName.ACL_MODIFY);
assertFalse(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getCardApplicationACL().getAccessRule().get(39).getSecurityCondition().isNever());
assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getDIDInfo().get(0).getRequirementLevel(), BasicRequirementsType.PERSONALIZATION_MANDATORY);
assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(0).getDIDInfo().get(0).getDIDACL().getAccessRule().get(0).getCardApplicationServiceName(), "DifferentialIdentityService");
assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(1).getDataSetInfo().get(0).getRequirementLevel(), BasicRequirementsType.PERSONALIZATION_MANDATORY);
assertEquals(cardInfo.getApplicationCapabilities().getCardApplication().get(1).getDataSetInfo().get(0).getDataSetACL().getAccessRule().get(0).getCardApplicationServiceName(), "NamedDataService");
for (DataSetInfoType dataSetInfo : cardInfo.getApplicationCapabilities().getCardApplication().get(2).getDataSetInfo()) {
if (dataSetInfo.getDataSetName().equals("EF.C.ZDA.QES")) {
assertEquals(dataSetInfo.getLocalDataSetName().get(0).getLang(), "DE");
assertEquals(dataSetInfo.getLocalDataSetName().get(0).getValue(), "Zertifikat des ZDA für die QES");
}
}
// Test eGK
o = m.unmarshal(m.str2doc(EGK_CIF));
if (!(o instanceof CardInfo)) {
throw new Exception("Object should be an instace of CardInfo");
}
cardInfo = (CardInfo) o;
assertEquals("http://ws.gematik.de/egk/1.0.0", cardInfo.getCardType().getObjectIdentifier());
CardApplicationType cardApplicationESIGN = cardInfo.getApplicationCapabilities().getCardApplication().get(2);
DIDInfoType didInfo = cardApplicationESIGN.getDIDInfo().get(2);
DifferentialIdentityType differentialIdentity = didInfo.getDifferentialIdentity();
assertEquals(differentialIdentity.getDIDName(), "PrK.CH.AUT_signPKCS1_V1_5");
assertEquals(differentialIdentity.getDIDProtocol(), "urn:oid:1.3.162.15480.3.0.25");
CryptoMarkerType cryptoMarkerType = new CryptoMarkerType(differentialIdentity.getDIDMarker().getCryptoMarker());
assertEquals(cryptoMarkerType.getProtocol(), "urn:oid:1.3.162.15480.3.0.25");
assertEquals(cryptoMarkerType.getAlgorithmInfo().getSupportedOperations().get(0), "Compute-signature");
// uncomment to get output files to make a diff
/*WSMarshaller jaxbMarshaller = new JAXBMarshaller();
CardInfo cardInfoJM = (CardInfo) jaxbMarshaller.unmarshal(jaxbMarshaller.str2doc(egkCif));
File f = new File("cifJM.xml");
FileOutputStream fos = new FileOutputStream(f);
File f2 = new File("cifAM.xml");
FileOutputStream fos2 = new FileOutputStream(f2);
marshalLog(cardInfoJM, fos);
marshalLog(cardInfo, fos2);*/
// Test ecard AT 0.9.0
o = m.unmarshal(m.str2doc(ECARD_AT_CIF));
if (!(o instanceof CardInfo)) {
throw new Exception("Object should be an instance of CardInfo");
}
cardInfo = (CardInfo) o;
}
use of iso.std.iso_iec._24727.tech.schema.CardInfo in project open-ecard by ecsec.
the class MiddlewareConfig method getCardInfoByCardSpec.
/**
* Stores the CardType-Spec in a freshly allocated CardInfo Template.
* The filled CardInfo Template will be returned.
*
* @param cardSpec specification of the card.
* @return {@code CardInfoType} or {@code null} if there is no available CardInfo Template.
*/
public CardInfoType getCardInfoByCardSpec(CardSpecType cardSpec) {
CardInfoType cardInfo = getCardInfoTemplate();
cardInfo.setCardType(mapCardSpecToCardType(cardSpec));
return cardInfo;
}
use of iso.std.iso_iec._24727.tech.schema.CardInfo in project open-ecard by ecsec.
the class MiddlewareConfig method getCardInfoTemplate.
/**
* Returns the CardInfo-Template as CardInfoType.
*
* @return CardInfo-Template or {@code null} if template can not be parsed.
*/
@Nonnull
private synchronized CardInfoType getCardInfoTemplate() {
CardInfoType cardInfo;
try {
WSMarshaller m = MARSHALLER.deref();
assert (m != null);
Document doc = CIF_DOC.deref();
cardInfo = m.unmarshal(doc, CardInfoType.class).getValue();
return cardInfo;
} catch (WSMarshallerException ex) {
String msg = "Can not parse CardInfo-Document.";
LOG.error(msg, ex);
throw new RuntimeException(CARD_IMAGE_PATH, ex);
} catch (InterruptedException ex) {
String msg = "Shutdown requested while retrieving CIF template.";
LOG.debug(msg);
throw new RuntimeException(msg);
} catch (NullPointerException ex) {
String msg = "Marshaller and/ or CIF Template could not be loaded correctly.";
LOG.error(msg, ex);
throw new RuntimeException(msg);
}
}
use of iso.std.iso_iec._24727.tech.schema.CardInfo in project open-ecard by ecsec.
the class MiddlewareSAL method augmentCardInfo.
private CardInfoType augmentCardInfo(@Nonnull ConnectionHandleType handle, @Nonnull CardInfoType template, @Nonnull CardSpecType cardSpec) {
boolean needsConnect = handle.getSlotHandle() == null;
try {
// connect card, so that we have a session
MwSession session;
if (needsConnect) {
MwSlot slot = getMatchingSlot(handle.getIFDName(), handle.getSlotIndex());
if (slot != null) {
session = slot.openSession();
} else {
throw new TokenException("No card available in this slot.", CryptokiLibrary.CKR_TOKEN_NOT_PRESENT);
}
} else {
session = managedSessions.get(handle.getSlotHandle());
}
if (session != null) {
CIFCreator cc = new CIFCreator(session, template, cardSpec);
CardInfoType cif = cc.addTokenInfo();
LOG.info("Finished augmenting CardInfo file.");
return cif;
} else {
LOG.warn("Card not available for object info retrieval anymore.");
return null;
}
} catch (WSMarshallerException ex) {
throw new RuntimeException("Failed to marshal CIF file.", ex);
} catch (CryptokiException ex) {
throw new RuntimeException("Error in PKCS#11 module while requesting CIF data.", ex);
}
}
use of iso.std.iso_iec._24727.tech.schema.CardInfo in project open-ecard by ecsec.
the class ACLResolver method getMissingDids.
private List<DIDStructureType> getMissingDids(List<AccessRuleType> acls, TargetNameType target) throws WSException, SecurityConditionUnsatisfiable {
// find the sign acl
ArrayList<AccessRuleType> tmpAcls = new ArrayList<>();
for (AccessRuleType next : acls) {
if (target.getDIDName() != null) {
CryptographicServiceActionName action = next.getAction().getCryptographicServiceAction();
if (CryptographicServiceActionName.SIGN.equals(action)) {
tmpAcls.add(next);
// there can be only one
break;
}
}
if (target.getDataSetName() != null) {
NamedDataServiceActionName action = next.getAction().getNamedDataServiceAction();
if (NamedDataServiceActionName.DATA_SET_SELECT.equals(action)) {
tmpAcls.add(next);
continue;
}
if (NamedDataServiceActionName.DSI_READ.equals(action)) {
tmpAcls.add(next);
continue;
}
}
}
ArrayList<DIDStructureType> result = new ArrayList<>();
for (AccessRuleType acl : tmpAcls) {
// get the most suitable DID in the tree
SecurityConditionType cond = normalize(acl.getSecurityCondition());
cond = getBestSecurityCondition(cond);
// flatten condition to list of unsatisfied dids
List<DIDAuthenticationStateType> authStates = flattenCondition(cond);
List<DIDStructureType> missingDIDs = filterSatisfiedDIDs(authStates);
result.addAll(missingDIDs);
}
// remove duplicates
TreeSet<String> newDids = new TreeSet<>();
Iterator<DIDStructureType> it = result.iterator();
while (it.hasNext()) {
// this code bluntly assumes, that did names are unique per cardinfo file
DIDStructureType next = it.next();
if (newDids.contains(next.getDIDName())) {
it.remove();
} else {
newDids.add(next.getDIDName());
}
}
return result;
}
Aggregations