2 * Copyright (c) 2014 Contextream, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.lispflowmapping.southbound.authentication;
10 import java.nio.ByteBuffer;
11 import org.opendaylight.lispflowmapping.interfaces.lisp.ILispAuthentication;
12 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkey;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public final class LispAuthenticationUtil {
21 protected static final Logger LOG = LoggerFactory.getLogger(LispAuthenticationUtil.class);
23 // Utility class, should not be instantiated
24 private LispAuthenticationUtil() {
27 private static ILispAuthentication resolveAuthentication(final MapRegister mapRegister, final Eid eid, final
30 LOG.warn("Authentication failed: mapping authentication key is null");
34 if (mapRegister.getKeyId() != null) {
35 keyId = mapRegister.getKeyId();
37 if (keyId != key.getKeyType().shortValue()) {
38 LOG.warn("Authentication failed: key-ID in Map-Register is different from the one on file for {}",
39 LispAddressStringifier.getString(eid));
42 return LispAuthenticationFactory.getAuthentication(LispKeyIDEnum.valueOf(keyId));
46 public static boolean validate(MapRegister mapRegister, ByteBuffer byteBuffer, Eid eid, MappingAuthkey key) {
47 final ILispAuthentication authentication = resolveAuthentication(mapRegister, eid, key);
48 return authentication == null ? false : authentication.validate(byteBuffer, mapRegister.getAuthenticationData(),
52 public static byte[] createAuthenticationData(MapNotify mapNotify, String key) {
53 // We assume that the key-ID is correctly set in the Map-Notify message
54 ILispAuthentication authentication = LispAuthenticationFactory.getAuthentication(
55 LispKeyIDEnum.valueOf(mapNotify.getKeyId()));
56 return authentication.getAuthenticationData(mapNotify, key);