use of org.eclipse.milo.opcua.stack.core.UaException in project milo by eclipse.
the class OpcUaCertificateUsageChecker method check.
@Override
public void check(Certificate cert, Collection<String> unresolvedCritExts) throws CertPathValidatorException {
X509Certificate certificate = (X509Certificate) cert;
Set<String> criticalExtensions = certificate.getCriticalExtensionOIDs();
if (criticalExtensions == null)
criticalExtensions = Collections.emptySet();
if (endEntityCert.equals(cert)) {
try {
CertificateValidationUtil.checkEndEntityKeyUsage((X509Certificate) cert);
LOGGER.debug("validated KeyUsage for end entity: {}", ((X509Certificate) cert).getSubjectX500Principal().getName());
} catch (UaException e) {
if (validationChecks.contains(ValidationCheck.KEY_USAGE_END_ENTITY) || criticalExtensions.contains(KEY_USAGE_OID)) {
throw new CertPathValidatorException(e.getMessage(), e, certPath, certPath.getCertificates().indexOf(cert), PKIXReason.INVALID_KEY_USAGE);
} else {
LOGGER.warn("check suppressed: certificate failed end-entity usage check: {}", ((X509Certificate) cert).getSubjectX500Principal().getName());
}
}
try {
CertificateValidationUtil.checkEndEntityExtendedKeyUsage(certificate, endEntityIsClient);
LOGGER.debug("validated ExtendedKeyUsage for end entity: {}", ((X509Certificate) cert).getSubjectX500Principal().getName());
} catch (UaException e) {
if (validationChecks.contains(ValidationCheck.EXTENDED_KEY_USAGE_END_ENTITY) || criticalExtensions.contains(EXTENDED_KEY_USAGE_OID)) {
throw new CertPathValidatorException(e.getMessage(), e, certPath, certPath.getCertificates().indexOf(cert), PKIXReason.INVALID_KEY_USAGE);
} else {
LOGGER.warn("check suppressed: certificate failed end-entity usage check: {}", ((X509Certificate) cert).getSubjectX500Principal().getName());
}
}
} else {
try {
CertificateValidationUtil.checkIssuerKeyUsage((X509Certificate) cert);
LOGGER.debug("validated KeyUsage for issuer: {}", ((X509Certificate) cert).getSubjectX500Principal().getName());
} catch (UaException e) {
if (validationChecks.contains(ValidationCheck.KEY_USAGE_ISSUER) || criticalExtensions.contains(KEY_USAGE_OID)) {
throw new CertPathValidatorException(e.getMessage(), e, certPath, certPath.getCertificates().indexOf(cert), PKIXReason.INVALID_KEY_USAGE);
} else {
LOGGER.warn("check suppressed: certificate failed issuer usage check: {}", ((X509Certificate) cert).getSubjectX500Principal().getName());
}
}
}
if (unresolvedCritExts != null && !unresolvedCritExts.isEmpty()) {
unresolvedCritExts.remove(KEY_USAGE_OID);
unresolvedCritExts.remove(EXTENDED_KEY_USAGE_OID);
}
}
use of org.eclipse.milo.opcua.stack.core.UaException in project milo by eclipse.
the class AddressSpace method createObjectNodeFromBaseAttributes.
private CompletableFuture<UaObjectNode> createObjectNodeFromBaseAttributes(NodeId nodeId, List<DataValue> baseAttributeValues) {
Set<AttributeId> remainingAttributes = Sets.difference(AttributeId.OBJECT_ATTRIBUTES, AttributeId.BASE_ATTRIBUTES);
CompletableFuture<ReadResponse> attributesFuture = readAttributes(nodeId, remainingAttributes);
CompletableFuture<NodeId> typeDefinitionFuture = readTypeDefinition(nodeId);
return CompletableFuture.allOf(attributesFuture, typeDefinitionFuture).thenCompose(ignored -> {
ReadResponse response = attributesFuture.join();
NodeId typeDefinitionId = typeDefinitionFuture.join();
List<DataValue> attributeValues = new ArrayList<>(baseAttributeValues);
Collections.addAll(attributeValues, response.getResults());
try {
UaObjectNode node = newObjectNode(nodeId, typeDefinitionId, attributeValues);
nodeCache.put(node.getNodeId(), node);
return completedFuture(node);
} catch (UaException e) {
return failedFuture(e);
}
});
}
use of org.eclipse.milo.opcua.stack.core.UaException in project milo by eclipse.
the class AddressSpace method createViewNodeFromBaseAttributes.
private CompletableFuture<UaViewNode> createViewNodeFromBaseAttributes(NodeId nodeId, List<DataValue> baseAttributeValues) {
Set<AttributeId> remainingAttributes = Sets.difference(AttributeId.VIEW_ATTRIBUTES, AttributeId.BASE_ATTRIBUTES);
CompletableFuture<ReadResponse> attributesFuture = readAttributes(nodeId, remainingAttributes);
return attributesFuture.thenCompose(response -> {
List<DataValue> attributeValues = new ArrayList<>(baseAttributeValues);
Collections.addAll(attributeValues, response.getResults());
try {
UaViewNode node = newViewNode(nodeId, attributeValues);
nodeCache.put(node.getNodeId(), node);
return completedFuture(node);
} catch (UaException e) {
return failedFuture(e);
}
});
}
use of org.eclipse.milo.opcua.stack.core.UaException in project milo by eclipse.
the class AddressSpace method getVariableNodeAsync.
/**
* Get a {@link UaVariableNode} instance for the VariableNode identified by {@code nodeId},
* assuming the type definition identified by {@code typeDefinitionId}.
* <p>
* If this type definition is registered with the {@link VariableTypeManager} a
* {@link UaVariableNode} of the appropriate subclass will be returned.
* <p>
* This call completes asynchronously.
*
* @param nodeId the {@link NodeId} identifying the VariableNode to get.
* @param typeDefinitionId the {@link NodeId} identifying the type definition.
* @return a CompletableFuture that completes successfully with a {@link UaVariableNode}
* instance for the VariableNode identified by {@code nodeId} or completes exceptionally if an
* error occurs while creating the VariableNode.
*/
public CompletableFuture<UaVariableNode> getVariableNodeAsync(NodeId nodeId, NodeId typeDefinitionId) {
UaNode cachedNode = nodeCache.getIfPresent(nodeId);
if (cachedNode instanceof UaVariableNode) {
return completedFuture((UaVariableNode) cachedNode);
} else {
CompletableFuture<ReadResponse> future = readAttributes(nodeId, AttributeId.VARIABLE_ATTRIBUTES);
return future.thenCompose(response -> {
List<DataValue> attributeValues = l(response.getResults());
try {
UaVariableNode node = newVariableNode(nodeId, typeDefinitionId, attributeValues);
nodeCache.put(node.getNodeId(), node);
return completedFuture(node);
} catch (UaException e) {
return failedFuture(e);
}
});
}
}
use of org.eclipse.milo.opcua.stack.core.UaException in project milo by eclipse.
the class AddressSpace method newMethodNode.
private UaMethodNode newMethodNode(NodeId nodeId, List<DataValue> attributeValues) throws UaException {
DataValue nodeIdDataValue = attributeValues.get(0);
StatusCode nodeIdStatusCode = nodeIdDataValue.getStatusCode();
if (nodeIdStatusCode != null && nodeIdStatusCode.isBad()) {
throw new UaException(nodeIdStatusCode);
}
try {
NodeClass nodeClass = NodeClass.from((Integer) attributeValues.get(1).getValue().getValue());
Preconditions.checkArgument(nodeClass == NodeClass.Method, "expected NodeClass.Method, got NodeClass." + nodeClass);
QualifiedName browseName = (QualifiedName) attributeValues.get(2).getValue().getValue();
LocalizedText displayName = (LocalizedText) attributeValues.get(3).getValue().getValue();
LocalizedText description = getAttributeOrNull(attributeValues.get(4), LocalizedText.class);
UInteger writeMask = getAttributeOrNull(attributeValues.get(5), UInteger.class);
UInteger userWriteMask = getAttributeOrNull(attributeValues.get(6), UInteger.class);
Boolean executable = (Boolean) attributeValues.get(7).getValue().getValue();
Boolean userExecutable = (Boolean) attributeValues.get(8).getValue().getValue();
return new UaMethodNode(client, nodeId, nodeClass, browseName, displayName, description, writeMask, userWriteMask, executable, userExecutable);
} catch (Throwable t) {
throw UaException.extract(t).orElse(new UaException(StatusCodes.Bad_UnexpectedError, t));
}
}
Aggregations