1 package org.metricshub.ipmi.core.coding.protocol;
2
3 /*-
4 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5 * IPMI Java Client
6 * ჻჻჻჻჻჻
7 * Copyright 2023 Verax Systems, MetricsHub
8 * ჻჻჻჻჻჻
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Lesser Public License for more details.
18 *
19 * You should have received a copy of the GNU General Lesser Public
20 * License along with this program. If not, see
21 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
23 */
24
25 import java.security.InvalidKeyException;
26
27 import org.metricshub.ipmi.core.coding.protocol.encoder.IpmiEncoder;
28 import org.metricshub.ipmi.core.coding.security.ConfidentialityAlgorithm;
29
30 /**
31 * Wrapper class for IPMI v2.0 message
32 */
33 public class Ipmiv20Message extends IpmiMessage {
34 private boolean payloadEncrypted;
35
36 private boolean payloadAuthenticated;
37
38 private PayloadType payloadType;
39
40 private int oemIANA;
41
42 private Object oemPayloadID;
43
44 public void setPayloadEncrypted(boolean payloadEncrypted) {
45 this.payloadEncrypted = payloadEncrypted;
46 }
47
48 public boolean isPayloadEncrypted() {
49 return payloadEncrypted;
50 }
51
52 public void setPayloadAuthenticated(boolean payloadAuthenticated) {
53 this.payloadAuthenticated = payloadAuthenticated;
54 }
55
56 public boolean isPayloadAuthenticated() {
57 return payloadAuthenticated;
58 }
59
60 public void setPayloadType(PayloadType payloadType) {
61 this.payloadType = payloadType;
62 }
63
64 public PayloadType getPayloadType() {
65 return payloadType;
66 }
67
68 public void setOemIANA(int oemIANA) {
69 this.oemIANA = oemIANA;
70 }
71
72 public int getOemIANA() {
73 return oemIANA;
74 }
75
76 public void setOemPayloadID(Object oemPayloadID) {
77 this.oemPayloadID = oemPayloadID;
78 }
79
80 public Object getOemPayloadID() {
81 return oemPayloadID;
82 }
83
84 public Ipmiv20Message(ConfidentialityAlgorithm confidentialityAlgorithm) {
85 setConfidentialityAlgorithm(confidentialityAlgorithm);
86 }
87
88 /**
89 * Gets base for integrity algorithm calculations. If used for the message
90 * being created, does not contain AuthCode field so amount of Integrity Pad
91 * bytes cannot be calculated. Therefore integrity algorithms using this
92 * base must add proper amount of the Integrity Pad bytes and modify the Pad
93 * Length byte.
94 *
95 * @param encoder
96 * - {@link IpmiEncoder} to be used to convert message to byte
97 * array format. Must be able to handle null authCode field with
98 * {@link #isPayloadAuthenticated()} == true since this method is
99 * used in its generation.
100 * @return base for integrity algorithm calculations
101 * @throws InvalidKeyException
102 * - when initiation of the confidentiality algorithm fails
103 */
104 public byte[] getIntegrityAlgorithmBase(IpmiEncoder encoder) throws InvalidKeyException {
105 return encoder.encode(this);
106 }
107 }