View Javadoc
1   package org.metricshub.ipmi.core.sm.states;
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 org.metricshub.ipmi.core.coding.Encoder;
26  import org.metricshub.ipmi.core.coding.commands.session.Rakp1;
27  import org.metricshub.ipmi.core.coding.commands.session.Rakp3;
28  import org.metricshub.ipmi.core.coding.protocol.encoder.Protocolv20Encoder;
29  import org.metricshub.ipmi.core.coding.rmcp.RmcpMessage;
30  import org.metricshub.ipmi.core.sm.StateMachine;
31  import org.metricshub.ipmi.core.sm.actions.ErrorAction;
32  import org.metricshub.ipmi.core.sm.actions.GetSikAction;
33  import org.metricshub.ipmi.core.sm.events.Rakp2Ack;
34  import org.metricshub.ipmi.core.sm.events.StateMachineEvent;
35  
36  /**
37   * At this state RAKP Message 2 was received - waiting for the confirmation to
38   * send RAKP Message 3. Transition to {@link Rakp3Waiting} on {@link Rakp2Ack}.
39   */
40  public class Rakp1Complete extends State {
41  
42      private Rakp1 rakp1;
43  
44      /**
45       * Initiates state.
46       *
47       * @param rakp1
48       *            - the {@link Rakp1} message that was sent earlier in the
49       *            authentification process.
50       */
51      public Rakp1Complete(Rakp1 rakp1) {
52          this.rakp1 = rakp1;
53      }
54  
55      @Override
56      public void doTransition(StateMachine stateMachine,
57              StateMachineEvent machineEvent) {
58          if (machineEvent instanceof Rakp2Ack) {
59              Rakp2Ack event = (Rakp2Ack) machineEvent;
60  
61              Rakp3 rakp3 = new Rakp3(event.getStatusCode(),
62                      event.getManagedSystemSessionId(), event.getCipherSuite(),
63                      rakp1, event.getRakp1ResponseData());
64  
65              try {
66                  stateMachine.setCurrent(new Rakp3Waiting(event
67                          .getSequenceNumber(), rakp1, event
68                          .getRakp1ResponseData(), event.getCipherSuite()));
69                  stateMachine.sendMessage(Encoder.encode(
70                          new Protocolv20Encoder(), rakp3,
71                          event.getSequenceNumber(), 0, 0));
72                  stateMachine.doExternalAction(new GetSikAction(rakp1
73                          .calculateSik(event.getRakp1ResponseData())));
74              } catch (Exception e) {
75                  stateMachine.setCurrent(this);
76                  stateMachine.doExternalAction(new ErrorAction(e));
77              }
78          } else {
79              stateMachine.doExternalAction(new ErrorAction(
80                      new IllegalArgumentException("Invalid transition")));
81          }
82  
83      }
84  
85      @Override
86      public void doAction(StateMachine stateMachine, RmcpMessage message) {
87          // No action is needed
88      }
89  
90  }