Package nts

Class NtsImpl

All Implemented Interfaces:
NtpV3Packet, NtpV4Packet, NtsPacket

public class NtsImpl extends NtpV4Impl implements NtsPacket
Implements NtsPacket to convert Java objects to and from the Network Time Protocol (NTP) data message header format described in RFC-1305.
  • Field Details

    • associatedDataLenght

      public int associatedDataLenght
    • plaintext

      public byte[] plaintext
    • authAndEncEF

      public NTSExtensionField authAndEncEF
  • Constructor Details

    • NtsImpl

      public NtsImpl(byte[] key)
      Creates a new instance of NtsImpl
  • Method Details

    • buildRequest

      public void buildRequest(byte[] cookie, int num_cookies)
      Build an NTS packet
      Specified by:
      buildRequest in interface NtsPacket
      Parameters:
      cookie - The NTS cookie to use in the packet
      num_cookies - Number of cookies to request
    • addUniqueIdentifierEF

      public void addUniqueIdentifierEF(byte[] unique_identifier_body)
      Adds a unique identifier extension field to the NTSv4 packet.
      Specified by:
      addUniqueIdentifierEF in interface NtsPacket
      Parameters:
      unique_identifier_body - the unique identifier byte array, must be at least 32 bytes long.
    • addCookieEF

      public void addCookieEF(byte[] cookie_body)
      Adds a cookie extension field to the NTSv4 packet.
      Specified by:
      addCookieEF in interface NtsPacket
      Parameters:
      cookie_body - a cookie received from the NTS KE process or from a server response.
    • addCookiePlaceholderEF

      public void addCookiePlaceholderEF(byte[] existing_cookie)
      Adds a cookie placeholder extension filed to the NTSv4 packet
      Specified by:
      addCookiePlaceholderEF in interface NtsPacket
      Parameters:
      existing_cookie - The cookie to be replaced
    • prepareAuthAndEncEF

      public void prepareAuthAndEncEF()
      Constructs all the possible variables that will be used for the authentication and encryption extension field. This is done here to avoid unnecessary delays in the time measurement after timestamping of the request packet. This should be called after all the Extension Fields and other parameters have been added to the packet.
      Specified by:
      prepareAuthAndEncEF in interface NtsPacket
    • createAuthAndEncEF

      public void createAuthAndEncEF(byte[] nonce)
      Creates the AuthAndEnc EF with the given keys and nonce. This is done after the NTP packet has been timestamped. Must be called after prepareAuthAndEncEF() has been called.
      Specified by:
      createAuthAndEncEF in interface NtsPacket
      Parameters:
      nonce - the nonce to be used for encryption
    • createAuthAndEncEF

      public void createAuthAndEncEF()
      Creates the AuthAndEnc EF with the given keys and a random nonce. This is done after the NTP packet has been timestamped. Must be called after prepareAuthAndEncEF() has been called.
      Specified by:
      createAuthAndEncEF in interface NtsPacket
    • decryptAndVerify

      public byte[] decryptAndVerify() throws AuthenticationFailureException
      Decrypt and verify a received NTS packet
      Specified by:
      decryptAndVerify in interface NtsPacket
      Throws:
      AuthenticationFailureException
    • validate

      Validate a response packet given a request packet
      Specified by:
      validate in interface NtsPacket
      Parameters:
      req - - The request packet
      Throws:
      IOException - - On failure
      NtsNakException
      AuthenticationFailureException