1 package org.metricshub.ipmi.core.coding.commands.session;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import org.metricshub.ipmi.core.coding.commands.CommandCodes;
26 import org.metricshub.ipmi.core.coding.commands.IpmiCommandCoder;
27 import org.metricshub.ipmi.core.coding.commands.IpmiVersion;
28 import org.metricshub.ipmi.core.coding.commands.ResponseData;
29 import org.metricshub.ipmi.core.coding.payload.lan.IPMIException;
30 import org.metricshub.ipmi.core.coding.payload.lan.IpmiLanMessage;
31 import org.metricshub.ipmi.core.coding.payload.lan.IpmiLanRequest;
32 import org.metricshub.ipmi.core.coding.payload.lan.NetworkFunction;
33 import org.metricshub.ipmi.core.coding.protocol.AuthenticationType;
34 import org.metricshub.ipmi.core.coding.protocol.IpmiMessage;
35 import org.metricshub.ipmi.core.coding.protocol.Ipmiv20Message;
36 import org.metricshub.ipmi.core.coding.protocol.PayloadType;
37 import org.metricshub.ipmi.core.coding.security.CipherSuite;
38 import org.metricshub.ipmi.core.coding.security.ConfidentialityNone;
39 import org.metricshub.ipmi.core.common.TypeConverter;
40
41 import java.security.InvalidKeyException;
42 import java.security.NoSuchAlgorithmException;
43
44
45
46
47
48 public class GetChannelCipherSuites extends IpmiCommandCoder {
49
50 private byte channelNumber;
51
52 private byte index;
53
54
55
56
57
58
59
60
61
62
63 public void setChannelNumber(int channelNumber) {
64 if (channelNumber < 0 || channelNumber > 0xF || channelNumber == 0xC
65 || channelNumber == 0xD) {
66 throw new IllegalArgumentException("Invalid channel number");
67 }
68 this.channelNumber = TypeConverter.intToByte(channelNumber);
69 }
70
71 public int getChannelNumber() {
72 return TypeConverter.byteToInt(channelNumber);
73 }
74
75 public void setIndex(byte index) {
76 if (index > 0x3F || index < 0) {
77 throw new IllegalArgumentException("Index " + index + " invalid must be (00h-3Fh).");
78 }
79 this.index = index;
80 }
81
82 public byte getIndex() {
83 return index;
84 }
85
86
87
88
89 public GetChannelCipherSuites() {
90 super(IpmiVersion.V20, new CipherSuite((byte) 0, (byte) 0, (byte) 0,
91 (byte) 0), AuthenticationType.RMCPPlus);
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105 public GetChannelCipherSuites(byte channelNumber, byte index) {
106 super(IpmiVersion.V20, new CipherSuite((byte) 0, (byte) 0, (byte) 0,
107 (byte) 0), AuthenticationType.RMCPPlus);
108 setChannelNumber(channelNumber);
109 setIndex(index);
110 }
111
112 @Override
113 public IpmiMessage encodePayload(int messageSequenceNumber, int sessionSequenceNumber, int sessionId)
114 throws NoSuchAlgorithmException, InvalidKeyException {
115 Ipmiv20Message message = new Ipmiv20Message(new ConfidentialityNone());
116
117 message.setAuthenticationType(getAuthenticationType());
118
119 message.setSessionID(0);
120
121 message.setPayloadEncrypted(false);
122
123 message.setPayloadAuthenticated(false);
124
125 message.setSessionSequenceNumber(0);
126
127 message.setPayloadType(PayloadType.Ipmi);
128
129 message.setPayload(preparePayload(messageSequenceNumber));
130
131 return message;
132 }
133
134 @Override
135 protected IpmiLanMessage preparePayload(int sequenceNumber) {
136 byte[] requestData = new byte[3];
137
138 requestData[0] = channelNumber;
139
140 requestData[1] = 0;
141
142 requestData[2] = TypeConverter.intToByte(0x80 | getIndex());
143
144 return new IpmiLanRequest(getNetworkFunction(), getCommandCode(),
145 requestData, TypeConverter.intToByte(sequenceNumber));
146 }
147
148 @Override
149 public byte getCommandCode() {
150 return CommandCodes.GET_CHANNEL_CIPHER_SUITES;
151 }
152
153 @Override
154 public NetworkFunction getNetworkFunction() {
155 return NetworkFunction.ApplicationRequest;
156 }
157
158 @Override
159 public ResponseData getResponseData(IpmiMessage message) throws IPMIException, NoSuchAlgorithmException, InvalidKeyException {
160
161 GetChannelCipherSuitesResponseData data = new GetChannelCipherSuitesResponseData();
162
163 byte[] raw = message.getPayload().getIpmiCommandData();
164
165 data.setChannelNumber(raw[0]);
166
167 if (raw.length > 1) {
168 byte[] cssData = new byte[raw.length - 1];
169
170 System.arraycopy(raw, 1, cssData, 0, cssData.length);
171
172 data.setCipherSuiteData(cssData);
173 } else if(raw.length == 1) {
174 data.setCipherSuiteData(new byte[0]);
175 }
176
177 return data;
178 }
179
180 }