KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > mo > snmp > KeyChange


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - KeyChange.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21
22 package org.snmp4j.agent.mo.snmp;
23
24 import org.snmp4j.agent.*;
25 import org.snmp4j.agent.mo.*;
26 import org.snmp4j.security.*;
27 import org.snmp4j.smi.*;
28 import org.snmp4j.agent.request.SubRequest;
29 import org.snmp4j.mp.SnmpConstants;
30
31 public class KeyChange extends MOMutableColumn {
32
33   public KeyChange(int columnID, MOAccess access,
34                    OctetString defaultValue, boolean mutableInService) {
35     super(columnID, SMIConstants.SYNTAX_OCTET_STRING, access,
36           defaultValue, mutableInService);
37   }
38
39   public static OctetString changeKey(AuthenticationProtocol authProtocol,
40                                       OctetString oldKey,
41                                       OctetString keyChange,
42                                       int keyLength) {
43     byte[] random = new byte[keyLength];
44     byte[] delta = new byte[keyChange.length()-keyLength];
45 /*
46     byte[] temp = new byte[keyLength*2];
47     System.arraycopy(oldKey.getValue(), 0, temp, 0, keyLength);
48     System.arraycopy(keyChange.getValue(), 0, temp, keyLength, keyLength);
49     temp = authProtocol.hash(temp);
50     byte[] newKey = new byte[keyLength];
51     System.arraycopy(temp, 0, newKey, 0, keyLength);
52     for (int i=0; i<keyLength; i++) {
53       newKey[i] ^= keyChange.get(keyLength+i);
54     }
55     return new OctetString(newKey);
56  */

57
58     System.arraycopy(keyChange.getValue(), 0, random, 0, keyLength);
59     System.arraycopy(keyChange.getValue(), keyLength, delta, 0,
60                      keyChange.length()-keyLength);
61     byte[] newKey = authProtocol.changeDelta(oldKey.getValue(), delta, random);
62     return new OctetString(newKey, random.length, newKey.length - random.length);
63 // */
64
}
65
66   public void get(SubRequest subRequest, MOTableRow row, int column) {
67     if (getAccess().isAccessibleForRead()) {
68       subRequest.getVariableBinding().setVariable(new OctetString());
69     }
70     else {
71       subRequest.getStatus().setErrorStatus(SnmpConstants.SNMP_ERROR_NO_ACCESS);
72     }
73     subRequest.completed();
74   }
75
76 }
77
Popular Tags