Package nts
Class NtsImpl
java.lang.Object
nts.NtpV3Impl
nts.NtpV4Impl
nts.NtsImpl
- All Implemented Interfaces:
NtpV3Packet,NtpV4Packet,NtsPacket
Implements
NtsPacket to convert Java objects to and from the Network Time Protocol (NTP) data message header format described in RFC-1305.-
Field Summary
FieldsModifier and TypeFieldDescriptionintbyte[]Fields inherited from class nts.NtpV4Impl
extensionFieldsFields inherited from interface nts.NtpV3Packet
LI_ALARM_CONDITION, LI_LAST_MINUTE_HAS_59_SECONDS, LI_LAST_MINUTE_HAS_61_SECONDS, LI_NO_WARNING, MODE_BROADCAST, MODE_CLIENT, MODE_CONTROL_MESSAGE, MODE_PRIVATE, MODE_RESERVED, MODE_SERVER, MODE_SYMMETRIC_ACTIVE, MODE_SYMMETRIC_PASSIVE, NTP_MAXCLOCK, NTP_MAXPOLL, NTP_MINCLOCK, NTP_MINPOLL, NTP_PORT, TYPE_DAYTIME, TYPE_ICMP, TYPE_NTP, TYPE_TIME, VERSION_3, VERSION_4 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCookieEF(byte[] cookie_body) Adds a cookie extension field to the NTSv4 packet.voidaddCookiePlaceholderEF(byte[] existing_cookie) Adds a cookie placeholder extension filed to the NTSv4 packetvoidaddUniqueIdentifierEF(byte[] unique_identifier_body) Adds a unique identifier extension field to the NTSv4 packet.voidbuildRequest(byte[] cookie, int num_cookies) Build an NTS packetvoidCreates the AuthAndEnc EF with the given keys and a random nonce.voidcreateAuthAndEncEF(byte[] nonce) Creates the AuthAndEnc EF with the given keys and nonce.byte[]Decrypt and verify a received NTS packetvoidConstructs all the possible variables that will be used for the authentication and encryption extension field.voidValidate a response packet given a request packetMethods inherited from class nts.NtpV4Impl
addExtensionField, addExtensionFields, equals, getExtensionFields, getExtensionFields, toStringMethods inherited from class nts.NtpV3Impl
buildRequest, getDatagramPacket, getDatagramPacket, getLeapIndicator, getMode, getModeName, getOriginateTimeStamp, getPoll, getPrecision, getReceiveTimeStamp, getReferenceId, getReferenceIdString, getReferenceTimeStamp, getRootDelay, getRootDelayInMillisDouble, getRootDispersion, getRootDispersionInMillis, getRootDispersionInMillisDouble, getStratum, getTransmitTimeStamp, getType, getVersion, hashCode, setDatagramPacket, setLeapIndicator, setMode, setOriginateTimeStamp, setPoll, setPrecision, setReceiveTimeStamp, setReferenceId, setReferenceTime, setRootDelay, setRootDispersion, setStratum, setTransmitTime, setVersion, ui, ul, validateMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface nts.NtpV3Packet
buildRequest, getDatagramPacket, getDatagramPacket, getLeapIndicator, getMode, getModeName, getOriginateTimeStamp, getPoll, getPrecision, getReceiveTimeStamp, getReferenceId, getReferenceIdString, getReferenceTimeStamp, getRootDelay, getRootDelayInMillisDouble, getRootDispersion, getRootDispersionInMillis, getRootDispersionInMillisDouble, getStratum, getTransmitTimeStamp, getType, getVersion, setDatagramPacket, setLeapIndicator, setMode, setOriginateTimeStamp, setPoll, setPrecision, setReceiveTimeStamp, setReferenceId, setReferenceTime, setRootDelay, setRootDispersion, setStratum, setTransmitTime, setVersion, validateMethods inherited from interface nts.NtpV4Packet
addExtensionField, addExtensionFields, getExtensionFields, getExtensionFields
-
Field Details
-
associatedDataLenght
public int associatedDataLenght -
plaintext
public byte[] plaintext -
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:
buildRequestin interfaceNtsPacket- Parameters:
cookie- The NTS cookie to use in the packetnum_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:
addUniqueIdentifierEFin interfaceNtsPacket- 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:
addCookieEFin interfaceNtsPacket- 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:
addCookiePlaceholderEFin interfaceNtsPacket- 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:
prepareAuthAndEncEFin interfaceNtsPacket
-
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:
createAuthAndEncEFin interfaceNtsPacket- 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:
createAuthAndEncEFin interfaceNtsPacket
-
decryptAndVerify
Decrypt and verify a received NTS packet- Specified by:
decryptAndVerifyin interfaceNtsPacket- Throws:
AuthenticationFailureException
-
validate
public void validate(NtsPacket req) throws IOException, NtsNakException, AuthenticationFailureException Validate a response packet given a request packet- Specified by:
validatein interfaceNtsPacket- Parameters:
req- - The request packet- Throws:
IOException- - On failureNtsNakExceptionAuthenticationFailureException
-