use of iso.std.iso_iec._24727.tech.schema.DIDAuthenticationStateType in project open-ecard by ecsec.
the class AndroidMarshaller method parseDIDAuthenticationState.
private DIDAuthenticationStateType parseDIDAuthenticationState(XmlPullParser parser) throws XmlPullParserException, IOException {
DIDAuthenticationStateType didAuthenticationState = new DIDAuthenticationStateType();
int eventType;
do {
parser.next();
eventType = parser.getEventType();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("DIDName")) {
didAuthenticationState.setDIDName(parser.nextText());
} else if (parser.getName().equals("DIDScope")) {
didAuthenticationState.setDIDScope(DIDScopeType.fromValue(parser.nextText()));
} else if (parser.getName().equals("DIDState")) {
didAuthenticationState.setDIDState(Boolean.parseBoolean(parser.nextText()));
} else if (parser.getName().equals("DIDStateQualifier")) {
didAuthenticationState.setDIDStateQualifier(StringUtils.toByteArray(parser.nextText()));
} else {
throw new IOException(parser.getName() + " not yet implemented");
}
}
} while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("DIDAuthentication")));
return didAuthenticationState;
}
use of iso.std.iso_iec._24727.tech.schema.DIDAuthenticationStateType in project open-ecard by ecsec.
the class CIFCreator method createDidCond.
private SecurityConditionType createDidCond(String didName) {
SecurityConditionType cond = new SecurityConditionType();
DIDAuthenticationStateType authState = new DIDAuthenticationStateType();
authState.setDIDName(didName);
authState.setDIDState(true);
cond.setDIDAuthentication(authState);
return cond;
}
use of iso.std.iso_iec._24727.tech.schema.DIDAuthenticationStateType in project open-ecard by ecsec.
the class ACLResolver method filterSatisfiedDIDs.
private List<DIDStructureType> filterSatisfiedDIDs(List<DIDAuthenticationStateType> states) throws WSException {
ArrayList<DIDStructureType> result = new ArrayList<>(states.size());
for (DIDAuthenticationStateType state : states) {
if (state.isDIDState()) {
// perform DIDGet to see if the DID is authenticated
DIDGet req = new DIDGet();
req.setConnectionHandle(handle);
req.setDIDName(state.getDIDName());
// search everywhere
req.setDIDScope(DIDScopeType.GLOBAL);
DIDGetResponse res = (DIDGetResponse) dispatcher.safeDeliver(req);
WSHelper.checkResult(res);
// add it if not authenticated
if (!res.getDIDStructure().isAuthenticated()) {
result.add(res.getDIDStructure());
}
}
}
return result;
}
use of iso.std.iso_iec._24727.tech.schema.DIDAuthenticationStateType 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;
}
use of iso.std.iso_iec._24727.tech.schema.DIDAuthenticationStateType in project open-ecard by ecsec.
the class CardStateEntry method checkSecurityCondition.
private boolean checkSecurityCondition(SecurityConditionType securityCondition) {
byte[] cardApplication;
try {
if (securityCondition.isAlways()) {
return true;
}
} catch (NullPointerException e) {
// ignore
}
if (securityCondition.getDIDAuthentication() != null) {
DIDAuthenticationStateType didAuthenticationState = securityCondition.getDIDAuthentication();
cardApplication = getInfo().getApplicationIdByDidName(didAuthenticationState.getDIDName(), null);
if (didAuthenticationState.isDIDState()) {
return isAuthenticated(didAuthenticationState.getDIDName(), cardApplication);
} else {
return !isAuthenticated(didAuthenticationState.getDIDName(), cardApplication);
}
} else if (securityCondition.getOr() != null) {
for (SecurityConditionType securityConditionOR : securityCondition.getOr().getSecurityCondition()) {
if (checkSecurityCondition(securityConditionOR)) {
return true;
}
}
} else if (securityCondition.getAnd() != null) {
for (SecurityConditionType securityConditionAND : securityCondition.getAnd().getSecurityCondition()) {
if (!checkSecurityCondition(securityConditionAND)) {
return false;
}
}
return true;
} else if (securityCondition.getNot() != null) {
return !checkSecurityCondition(securityCondition.getNot());
}
return false;
}
Aggregations