import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.allowed.devices.Device;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.allowed.devices.DeviceBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.allowed.devices.DeviceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.allowed.devices.device.Transport;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.allowed.devices.device.transport.Ssh;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.allowed.devices.device.transport.SshBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParams;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParamsBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
- for (DataTreeModification<Node> change: changes) {
+ for (DataTreeModification<Node> change : changes) {
final DataObjectModification<Node> rootNode = change.getRootNode();
final InstanceIdentifier<Node> identifier = change.getRootPath().getRootIdentifier();
switch (rootNode.getModificationType()) {
}
private static Device newDevice(final String id, final PublicKey serverKey, final Device1.DeviceStatus status) {
+ // used only for netconf devices that are connected via SSH transport and global credentials
String sshEncodedKey = serverKey.toString();
try {
sshEncodedKey = AuthorizedKeysDecoder.encodePublicKey(serverKey);
} catch (IOException e) {
LOG.warn("Unable to encode public key to ssh format.", e);
}
+ final SshClientParams sshParams = new SshClientParamsBuilder().setHostKey(sshEncodedKey).build();
+ final Transport transport = new SshBuilder().setSshClientParams(sshParams).build();
return new DeviceBuilder()
.setUniqueId(id)
.withKey(new DeviceKey(id))
- .setSshHostKey(sshEncodedKey)
- .addAugmentation(new Device1Builder().setDeviceStatus(Device1.DeviceStatus.FAILEDNOTALLOWED).build())
+ .setTransport(transport)
+ .addAugmentation(new Device1Builder().setDeviceStatus(status).build())
.build();
}
private static InstanceIdentifier<Device> buildDeviceInstanceIdentifier(final NodeId nodeId) {
return InstanceIdentifier.create(NetconfCallhomeServer.class)
- .child(AllowedDevices.class)
- .child(Device.class, new DeviceKey(nodeId.getValue()));
+ .child(AllowedDevices.class)
+ .child(Device.class, new DeviceKey(nodeId.getValue()));
}
private static Device withConnectedStatus(final Device opDev) {
}
private static Device deviceWithStatus(final Device opDev, final DeviceStatus status) {
- return new DeviceBuilder()
- .setUniqueId(opDev.getUniqueId())
- .setSshHostKey(opDev.getSshHostKey())
- .addAugmentation(new Device1Builder().setDeviceStatus(status).build())
- .build();
+ final DeviceBuilder deviceBuilder = new DeviceBuilder()
+ .setUniqueId(opDev.getUniqueId())
+ .addAugmentation(new Device1Builder().setDeviceStatus(status).build());
+ if (opDev.getTransport() != null) {
+ deviceBuilder.setTransport(opDev.getTransport());
+ } else {
+ deviceBuilder.setSshHostKey(opDev.getSshHostKey());
+ }
+ return deviceBuilder.build();
}
private void setDeviceStatus(final Device device) {
public void reportFailedAuth(final PublicKey sshKey) {
AuthorizedKeysDecoder decoder = new AuthorizedKeysDecoder();
- for (Device device : getDevicesAsList()) {
- String keyString = device.getSshHostKey();
+ for (final Device device : getDevicesAsList()) {
+ final String keyString;
+ if (device.getTransport() instanceof Ssh) {
+ keyString = ((Ssh) device.getTransport()).getSshClientParams().getHostKey();
+ } else {
+ keyString = device.getSshHostKey();
+ }
if (keyString == null) {
LOG.info("Whitelist device {} does not have a host key, skipping it", device.getUniqueId());
continue;