1 /*
   2  * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package com.sun.jmx.snmp.internal;
  26 
  27 import com.sun.jmx.snmp.SnmpSecurityException;
  28 import com.sun.jmx.snmp.SnmpStatusException;
  29 import com.sun.jmx.snmp.SnmpTooBigException;
  30 import com.sun.jmx.snmp.SnmpSecurityParameters;
  31 
  32 /**
  33  * Security model interface. Any security model implementation must implement this interface in order to be integrated in the engine framework. Security models are called when SNMP messages are received or sent. They deal with security (authentication and privacy).
  34  * <p><b>This API is a Sun Microsystems internal API  and is subject
  35  * to change without notice.</b></p>
  36  * @since 1.5
  37  */
  38 public interface SnmpSecurityModel extends SnmpModel {
  39     /**
  40      * Called when a request is to be sent to the network. It must be securized.
  41      * <BR>The specified parameters are defined in RFC 2572 (see also the {@link com.sun.jmx.snmp.SnmpV3Message} class).
  42      * @param cache The cache that has been created by calling <CODE>createSecurityCache</CODE> on this model.
  43      * @param version The SNMP protocol version.
  44      * @param msgID The current request id.
  45      * @param msgMaxSize The message max size.
  46      * @param msgFlags The message flags (reportable, Auth and Priv).
  47      * @param msgSecurityModel This current security model.
  48      * @param params The security parameters that contain the model dependant parameters.
  49      * @param contextEngineID The context engine ID.
  50      * @param contextName The context name.
  51      * @param data The marshalled varbind list.
  52      * @param dataLength The marshalled varbind list length.
  53      * @param outputBytes The buffer to fill with securized request. This is a representation independant marshalled format. This buffer will be sent to the network.
  54      * @return The marshalled byte number.
  55      */
  56     public int generateRequestMsg(SnmpSecurityCache cache,
  57                                   int version,
  58                                   int msgID,
  59                                   int msgMaxSize,
  60                                   byte msgFlags,
  61                                   int msgSecurityModel,
  62                                   SnmpSecurityParameters params,
  63                                   byte[] contextEngineID,
  64                                   byte[] contextName,
  65                                   byte[] data,
  66                                   int dataLength,
  67                                   byte[] outputBytes)
  68         throws SnmpTooBigException, SnmpStatusException,
  69                SnmpSecurityException;
  70 
  71     /**
  72      * Called when a response is to be sent to the network. It must be securized.
  73      * <BR>The specified parameters are defined in RFC 2572 (see also the {@link com.sun.jmx.snmp.SnmpV3Message} class).
  74      * @param cache The cache that has been created by calling <CODE>createSecurityCache</CODE> on this model.
  75      * @param version The SNMP protocol version.
  76      * @param msgID The current request id.
  77      * @param msgMaxSize The message max size.
  78      * @param msgFlags The message flags (reportable, Auth and Priv)
  79      * @param msgSecurityModel This current security model.
  80      * @param params The security parameters that contain the model dependant parameters.
  81      * @param contextEngineID The context engine ID.
  82      * @param contextName The context name.
  83      * @param data The marshalled varbind list.
  84      * @param dataLength The marshalled varbind list length.
  85      * @param outputBytes The buffer to fill with securized request. This is a representation independant marshalled format. This buffer will be sent to the network.
  86      * @return The marshalled byte number.
  87      */
  88     public int generateResponseMsg(SnmpSecurityCache cache,
  89                                    int version,
  90                                    int msgID,
  91                                    int msgMaxSize,
  92                                    byte msgFlags,
  93                                    int msgSecurityModel,
  94                                    SnmpSecurityParameters params,
  95                                    byte[] contextEngineID,
  96                                    byte[] contextName,
  97                                    byte[] data,
  98                                    int dataLength,
  99                                    byte[] outputBytes)
 100         throws SnmpTooBigException, SnmpStatusException,
 101                SnmpSecurityException;
 102     /**
 103      * Called when a request is received from the network. It handles authentication and privacy.
 104      * <BR>The specified parameters are defined in RFC 2572 (see also the {@link com.sun.jmx.snmp.SnmpV3Message} class).
 105      * @param cache The cache that has been created by calling <CODE>createSecurityCache</CODE> on this model.
 106      * @param version The SNMP protocol version.
 107      * @param msgID The current request id.
 108      * @param msgMaxSize The message max size.
 109      * @param msgFlags The message flags (reportable, Auth and Priv)
 110      * @param msgSecurityModel This current security model.
 111      * @param params The security parameters in a marshalled format. The informations contained in this array are model dependant.
 112      * @param contextEngineID The context engine ID or null if encrypted.
 113      * @param contextName The context name or null if encrypted.
 114      * @param data The marshalled varbind list or null if encrypted
 115      * @param encryptedPdu The encrypted pdu or null if not encrypted.
 116      * @param decryptedPdu The decrypted pdu. If no decryption is to be done, the passed context engine ID, context name and data could be used to fill this object.
 117      * @return The decoded security parameters.
 118 
 119      */
 120     public SnmpSecurityParameters
 121         processIncomingRequest(SnmpSecurityCache cache,
 122                                int version,
 123                                int msgID,
 124                                int msgMaxSize,
 125                                byte msgFlags,
 126                                int msgSecurityModel,
 127                                byte[] params,
 128                                byte[] contextEngineID,
 129                                byte[] contextName,
 130                                byte[] data,
 131                                byte[] encryptedPdu,
 132                                SnmpDecryptedPdu decryptedPdu)
 133         throws SnmpStatusException, SnmpSecurityException;
 134  /**
 135      * Called when a response is received from the network. It handles authentication and privacy.
 136      * <BR>The specified parameters are defined in RFC 2572 (see also the {@link com.sun.jmx.snmp.SnmpV3Message} class).
 137      * @param cache The cache that has been created by calling <CODE>createSecurityCache</CODE> on this model.
 138      * @param version The SNMP protocol version.
 139      * @param msgID The current request id.
 140      * @param msgMaxSize The message max size.
 141      * @param msgFlags The message flags (reportable, Auth and Priv)
 142      * @param msgSecurityModel This current security model.
 143      * @param params The security parameters in a marshalled format. The informations cointained in this array are model dependant.
 144      * @param contextEngineID The context engine ID or null if encrypted.
 145      * @param contextName The context name or null if encrypted.
 146      * @param data The marshalled varbind list or null if encrypted
 147      * @param encryptedPdu The encrypted pdu or null if not encrypted.
 148      * @param decryptedPdu The decrypted pdu. If no decryption is to be done, the passed context engine ID, context name and data could be used to fill this object.
 149      * @return The security parameters.
 150 
 151      */
 152     public SnmpSecurityParameters processIncomingResponse(SnmpSecurityCache cache,
 153                                                           int version,
 154                                                           int msgID,
 155                                                           int msgMaxSize,
 156                                                           byte msgFlags,
 157                                                           int msgSecurityModel,
 158                                                           byte[] params,
 159                                                           byte[] contextEngineID,
 160                                                           byte[] contextName,
 161                                                           byte[] data,
 162                                                           byte[] encryptedPdu,
 163                                                           SnmpDecryptedPdu decryptedPdu)
 164         throws SnmpStatusException, SnmpSecurityException;
 165 
 166     /**
 167      * Instantiate an <CODE>SnmpSecurityCache</CODE> that is dependant to the model implementation.
 168      * @return The model dependant security cache.
 169      */
 170     public SnmpSecurityCache createSecurityCache();
 171     /**
 172      * Release the previously created cache.
 173      * @param cache The security cache to release.
 174      */
 175     public void releaseSecurityCache(SnmpSecurityCache cache);
 176 }