Search in sources :

Example 1 with AuthorizedKeysDecoder

use of org.opendaylight.netconf.callhome.protocol.AuthorizedKeysDecoder in project netconf by opendaylight.

the class CallhomeStatusReporter method reportFailedAuth.

@Override
public void reportFailedAuth(final PublicKey sshKey) {
    AuthorizedKeysDecoder decoder = new AuthorizedKeysDecoder();
    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;
        }
        try {
            PublicKey pubKey = decoder.decodePublicKey(keyString);
            if (sshKey.getAlgorithm().equals(pubKey.getAlgorithm()) && sshKey.equals(pubKey)) {
                Device failedDevice = withFailedAuthStatus(device);
                if (failedDevice == null) {
                    return;
                }
                LOG.info("Setting auth failed status for callhome device id:{}.", failedDevice.getUniqueId());
                setDeviceStatus(failedDevice);
                return;
            }
        } catch (GeneralSecurityException e) {
            LOG.error("Failed decoding a device key with host key: {}", keyString, e);
            return;
        }
    }
    LOG.error("No match found for the failed auth device (should have been filtered by whitelist). Key: {}", sshKey);
}
Also used : Device(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device) PublicKey(java.security.PublicKey) GeneralSecurityException(java.security.GeneralSecurityException) Ssh(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Ssh) AuthorizedKeysDecoder(org.opendaylight.netconf.callhome.protocol.AuthorizedKeysDecoder)

Aggregations

GeneralSecurityException (java.security.GeneralSecurityException)1 PublicKey (java.security.PublicKey)1 AuthorizedKeysDecoder (org.opendaylight.netconf.callhome.protocol.AuthorizedKeysDecoder)1 Device (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device)1 Ssh (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Ssh)1