diff --git a/ApplicationServer/src/main/java/utils/Constants.java b/ApplicationServer/src/main/java/utils/Constants.java index 2523045..c694445 100644 --- a/ApplicationServer/src/main/java/utils/Constants.java +++ b/ApplicationServer/src/main/java/utils/Constants.java @@ -15,6 +15,7 @@ public class Constants { public static final int TGS_REPLY_MESSSAGE_TYPE = 13; public static final int AP_REQUEST_MESSAGE_TYPE = 14; public static final int AP_REPLY_MESSAGE_TYPE = 15; + public static final int KRB_ERROR_MESSAGE_TYPE = 30; // Hardcoded Server PrincipalNames public static final PrincipalName AS_SERVER = new PrincipalName("as_server"); diff --git a/Client/src/main/java/entities/Client.java b/Client/src/main/java/entities/Client.java index a83a74d..71980a8 100644 --- a/Client/src/main/java/entities/Client.java +++ b/Client/src/main/java/entities/Client.java @@ -41,10 +41,13 @@ public class Client { private String loginPassword; private ImmutableKrbKdcReq requestToAs; private ImmutableKrbKdcRep replyFromAs; + private ImmutableKrbError errorReplyFromAs; private ImmutableKrbKdcReq requestToTgs; private ImmutableKrbKdcRep replyFromTgs; + private ImmutableKrbError errorReplyFromTgs; private ImmutableKrbApReq requestToAp; private ImmutableKrbApRep replyFromAp; + private ImmutableKrbError errorReplyFromAp; private Ticket ticketGrantingTicket; private Ticket serviceGrantingTicket; private byte[] sessionKeyWithTgs; @@ -67,7 +70,7 @@ public Client(PrincipalName clientKerberosId, String loginPassword) { This is used for request/response exchange with a server. Server can either be KDC or Application Server */ - private void sendRequestToServerAndReceiveResponse(int serverPort, ServerType serverType) { + private int sendRequestToServerAndReceiveResponse(int serverPort, ServerType serverType) { try { /* * Instantiate client socket. @@ -79,22 +82,37 @@ private void sendRequestToServerAndReceiveResponse(int serverPort, ServerType se InetAddress IPAddress = InetAddress.getByName("localhost"); /* Serialization of object into json string */ + int applicationNumber = 0; String requestJsonString = null; ObjectMapper objectMapper = new ObjectMapper(); switch (serverType) { case AS: + applicationNumber = AS_REQUEST_MESSSAGE_TYPE; requestJsonString = objectMapper.writeValueAsString(requestToAs); break; case TGS: + applicationNumber = TGS_REQUEST_MESSSAGE_TYPE; requestJsonString = objectMapper.writeValueAsString(requestToTgs); break; case AP: + applicationNumber = AP_REQUEST_MESSAGE_TYPE; requestJsonString = objectMapper.writeValueAsString(requestToAp); break; } /* Convert string to byte array */ - byte[] data = requestJsonString.getBytes(); + byte[] requestData = requestJsonString.getBytes(StandardCharsets.UTF_8); + + /* Enclose this message bodu inside the KrbMessage */ + ImmutableKrbMessage krbMessageRequest = ImmutableKrbMessage.builder() + .applicationNumber(applicationNumber) + .krbMessageBody(requestData) + .build(); + + String krbMessageJsonString = objectMapper.writeValueAsString(krbMessageRequest); + + /* Convert string to byte array */ + byte[] data = krbMessageJsonString.getBytes(StandardCharsets.UTF_8); /* Creating a UDP packet */ DatagramPacket sendingPacket = new DatagramPacket(data, data.length, IPAddress, serverPort); @@ -108,26 +126,48 @@ private void sendRequestToServerAndReceiveResponse(int serverPort, ServerType se DatagramPacket receivingPacket = new DatagramPacket(receivingDataBuffer, receivingDataBuffer.length); clientSocket.receive(receivingPacket); - byte[] dataReceived = receivingPacket.getData(); - String dataString = new String(dataReceived); - - /* Deserialization of json string to object */ - switch (serverType) { - case AS: - replyFromAs = objectMapper.readValue(dataString, ImmutableKrbKdcRep.class); - break; - case TGS: - replyFromTgs = objectMapper.readValue(dataString, ImmutableKrbKdcRep.class); - break; - case AP: - replyFromAp = objectMapper.readValue(dataString, ImmutableKrbApRep.class); - break; + byte[] krbMessageReceivedData = receivingPacket.getData(); + String krbMessageReceivedString = new String(krbMessageReceivedData, StandardCharsets.UTF_8); + + /* Deserialization of json string to object (KrbMessage) */ + KrbMessage krbMessageReceived = objectMapper.readValue(krbMessageReceivedString, KrbMessage.class); + + if (krbMessageReceived.applicationNumber() == KRB_ERROR_MESSAGE_TYPE) { + // Error + switch (serverType) { + case AS: + errorReplyFromAs = objectMapper.readValue(krbMessageReceivedString, ImmutableKrbError.class); + break; + case TGS: + errorReplyFromTgs = objectMapper.readValue(krbMessageReceivedString, ImmutableKrbError.class); + break; + case AP: + errorReplyFromAp = objectMapper.readValue(krbMessageReceivedString, ImmutableKrbError.class); + break; + } + System.out.println(); + return KRB_ERROR_MESSAGE_TYPE; + + } else { + /* Deserialization of json string to object */ + switch (serverType) { + case AS: + replyFromAs = objectMapper.readValue(krbMessageReceivedString, ImmutableKrbKdcRep.class); + break; + case TGS: + replyFromTgs = objectMapper.readValue(krbMessageReceivedString, ImmutableKrbKdcRep.class); + break; + case AP: + replyFromAp = objectMapper.readValue(krbMessageReceivedString, ImmutableKrbApRep.class); + break; + } + + // Closing the socket connection with the server + clientSocket.close(); + return SUCCESS; } -// System.out.println(replyFromAs.toString()); - // Closing the socket connection with the server - clientSocket.close(); } catch (Exception e) { e.printStackTrace(); } @@ -359,6 +399,16 @@ private void handleApReply() throws InvalidAlgorithmParameterException, NoSuchPa } } + private void printKerberosErrorMessageFromAs() { + System.out.println("Kerberos Authentication Failed!"); + System.out.println("Error Code " + errorReplyFromAs.eText() + ": " + errorReplyFromAs.eText()); + } + + private void printKerberosErrorMessageFromTgs() { + System.out.println("Kerberos Authentication Failed!"); + System.out.println("Error Code " + errorReplyFromTgs.eText() + ": " + errorReplyFromTgs.eText()); + } + public static void main(String[] args) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, InvalidKeySpecException, BadPaddingException, InvalidKeyException, JsonProcessingException, TimestampMismatchException { System.out.println("WELCOME TO KERBEROS AUTHENTICATION SYSTEM!"); System.out.println("Please enter your kerberos id and password to get started"); @@ -373,7 +423,11 @@ public static void main(String[] args) throws InvalidAlgorithmParameterException /* AS Exchange */ client.constructAuthenticationServerRequest(); - client.sendRequestToServerAndReceiveResponse(KDC_SERVICE_PORT, ServerType.AS); + int ret = client.sendRequestToServerAndReceiveResponse(KDC_SERVICE_PORT, ServerType.AS); + if (ret == KRB_ERROR_MESSAGE_TYPE) { + client.printKerberosErrorMessageFromAs(); + exit(1); + } /* TODO: check if user is successfully authenticated */ client.handleAsReply(); @@ -385,7 +439,11 @@ public static void main(String[] args) throws InvalidAlgorithmParameterException /* TGS Exchange */ client.constructTicketGrantingServerRequest(client.applicationServerKerberosId); - client.sendRequestToServerAndReceiveResponse(KDC_SERVICE_PORT, ServerType.TGS); + ret = client.sendRequestToServerAndReceiveResponse(KDC_SERVICE_PORT, ServerType.TGS); + if (ret == KRB_ERROR_MESSAGE_TYPE) { + client.printKerberosErrorMessageFromTgs(); + exit(1); + } client.handleTgsReply(); /* AP Exchange */ diff --git a/Client/src/main/java/messageformats/KrbError.java b/Client/src/main/java/messageformats/KrbError.java new file mode 100644 index 0000000..b300d5c --- /dev/null +++ b/Client/src/main/java/messageformats/KrbError.java @@ -0,0 +1,23 @@ +package messageformats; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.immutables.value.Value; + +import java.sql.Timestamp; +import java.util.Optional; + +@Value.Immutable +@Value.Style(privateNoargConstructor = true) +@JsonSerialize(as = ImmutableKrbError.class) +@JsonDeserialize(as = ImmutableKrbError.class) +public interface KrbError { + int pvno(); + int msgType(); + Optional ctime(); + Timestamp stime(); + int errorCode(); + Optional cname(); + PrincipalName sname(); + String eText(); +} diff --git a/Client/src/main/java/messageformats/KrbMessage.java b/Client/src/main/java/messageformats/KrbMessage.java new file mode 100644 index 0000000..35b9492 --- /dev/null +++ b/Client/src/main/java/messageformats/KrbMessage.java @@ -0,0 +1,16 @@ +package messageformats; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.immutables.value.Value; + +@Value.Immutable +@Value.Style(privateNoargConstructor = true) +@JsonSerialize(as = ImmutableKrbMessage.class) +@JsonDeserialize(as = ImmutableKrbMessage.class) +public interface KrbMessage { + // Message Header + int applicationNumber(); + // Message Body + byte[] krbMessageBody(); +} diff --git a/Client/src/main/java/utils/Constants.java b/Client/src/main/java/utils/Constants.java index c61b35c..aad5d1d 100644 --- a/Client/src/main/java/utils/Constants.java +++ b/Client/src/main/java/utils/Constants.java @@ -14,6 +14,7 @@ public class Constants { public static final int TGS_REQUEST_MESSSAGE_TYPE = 12; public static final int TGS_REPLY_MESSSAGE_TYPE = 13; public static final int AP_REQUEST_MESSAGE_TYPE = 14; + public static final int KRB_ERROR_MESSAGE_TYPE = 30; // Hardcoded Server PrincipalNames public static final PrincipalName AS_SERVER = new PrincipalName("as_server"); @@ -39,21 +40,6 @@ public static enum ServerType { AP } - - // public static final ImmutablePrincipalName client = ImmutablePrincipalName.builder() -// .nameString("client") -// .build(); - -// public static final ImmutablePrincipalName as_server = ImmutablePrincipalName.builder() -// .nameString("as_server") -// .build(); - -// public static final ImmutablePrincipalName tgs_server = ImmutablePrincipalName.builder() -// .nameString("tgs_server") -// .build(); -// -// public static final ImmutablePrincipalName application_server = ImmutablePrincipalName.builder() -// .nameString("application_server") -// .build(); + public static final int SUCCESS = 0; } diff --git a/KDC/src/main/java/entities/KeyDistributionCentre.java b/KDC/src/main/java/entities/KeyDistributionCentre.java index 96444d6..842264f 100644 --- a/KDC/src/main/java/entities/KeyDistributionCentre.java +++ b/KDC/src/main/java/entities/KeyDistributionCentre.java @@ -52,6 +52,7 @@ public class KeyDistributionCentre { private static ArrayList userAuthDatabase; private KrbKdcReq clientAsRequest; private KrbKdcRep asReplyForClient; + private KrbError asErrorReplyForClient; private KrbKdcReq clientTgsRequest; private KrbKdcRep tgsReplyForClient; private final static byte[] tgsSecretKey = "abcdefghijklmnopqrstuvwxyz123456".getBytes(StandardCharsets.UTF_8); @@ -89,48 +90,87 @@ public void receiveClientRequestAndReply() { /* get the data bytes from inputPacket and convert byte array to json string */ byte[] dataReceived = inputPacket.getData(); - String dataString = new String(dataReceived); + String dataString = new String(dataReceived, StandardCharsets.UTF_8); - /* Deserialization of json string to object */ ObjectMapper objectMapper = new ObjectMapper(); - KrbKdcReq clientRequest = objectMapper.readValue(dataString, KrbKdcReq.class); - System.out.println(clientRequest.toString()); - - /* Obtain client's IP address and the port */ - InetAddress senderAddress = inputPacket.getAddress(); - int senderPort = inputPacket.getPort(); - - String replyForClientJsonString = null; - switch (clientRequest.msgType()) { - - case AS_REQUEST_MESSSAGE_TYPE: - clientAsRequest = clientRequest; - // TODO: Add logic for verification of client's identity and other AS functions - loadUserAuthData(); - String clientPassword = getClientCredentials(clientRequest.reqBody().getCname().getNameString()); - System.out.println("The client password is {" + clientPassword + "}"); - constructAsReplyForClient(clientPassword); - /* Serialization of reply object into json string */ - replyForClientJsonString = objectMapper.writeValueAsString(asReplyForClient); - break; - - case TGS_REQUEST_MESSSAGE_TYPE: - clientTgsRequest = clientRequest; - doClientAuthenticationFromTgsRequest(); - constructTgsReplyForClient(); - /* Serialization of reply object into json string */ - replyForClientJsonString = objectMapper.writeValueAsString(tgsReplyForClient); - break; - } - - /* Convert string to byte array */ - byte[] data = replyForClientJsonString.getBytes(); - - /* Creating a UDP packet */ - DatagramPacket replyPacket = new DatagramPacket(data, data.length, senderAddress, senderPort); - /* Send the created packet to client */ - serverSocket.send(replyPacket); + /* Deserialization of json string to object (KrbMessage) */ + KrbMessage krbMessageRequest = objectMapper.readValue(dataString, KrbMessage.class); + + if (krbMessageRequest.applicationNumber() == KRB_ERROR_MESSAGE_TYPE) { + // DO WHATEVER NECESSARY + } else { + /* Deserialization of json string to object (KrbKdcReq) */ + KrbKdcReq clientRequest = objectMapper.readValue(new String(krbMessageRequest.krbMessageBody(), + StandardCharsets.UTF_8), KrbKdcReq.class); + System.out.println(clientRequest.toString()); + + /* Obtain client's IP address and the port */ + InetAddress senderAddress = inputPacket.getAddress(); + int senderPort = inputPacket.getPort(); + + int applicationNumber = 0; + String replyForClientJsonString = null; + switch (clientRequest.msgType()) { + + case AS_REQUEST_MESSSAGE_TYPE: + clientAsRequest = clientRequest; + // TODO: Add logic for verification of client's identity and other AS functions + loadUserAuthData(); + String clientPassword = getClientCredentials(clientRequest.reqBody().getCname().getNameString()); + System.out.println("The client password is {" + clientPassword + "}"); + + if (clientPassword.equals("USER_NOT_FOUND")) { + // User does not exist + applicationNumber = KRB_ERROR_MESSAGE_TYPE; + constructKerberosErrorMessageReplyForClient(); + replyForClientJsonString = objectMapper.writeValueAsString(asErrorReplyForClient); + } else { + applicationNumber = AS_REPLY_MESSSAGE_TYPE; + constructAsReplyForClient(clientPassword); + /* Serialization of reply object into json string */ + replyForClientJsonString = objectMapper.writeValueAsString(asReplyForClient); + } + + break; + + case TGS_REQUEST_MESSSAGE_TYPE: + clientTgsRequest = clientRequest; + int ret = doClientAuthenticationFromTgsRequest(); + + if (ret != 0) { + // User does not exist + applicationNumber = KRB_ERROR_MESSAGE_TYPE; + constructKerberosErrorMessageReplyForClient(); + replyForClientJsonString = objectMapper.writeValueAsString(asErrorReplyForClient); + } else { + applicationNumber = TGS_REQUEST_MESSSAGE_TYPE; + constructTgsReplyForClient(); + /* Serialization of reply object into json string */ + replyForClientJsonString = objectMapper.writeValueAsString(tgsReplyForClient); + } + + break; + } + + /* Convert string to byte array */ + byte[] requestData = replyForClientJsonString.getBytes(StandardCharsets.UTF_8); + + ImmutableKrbMessage krbMessageReply = ImmutableKrbMessage.builder() + .applicationNumber(applicationNumber) + .krbMessageBody(requestData) + .build(); + + String krbMessageReplyJsonString = objectMapper.writeValueAsString(krbMessageReply); + + byte[] data = krbMessageReplyJsonString.getBytes(StandardCharsets.UTF_8); + + /* Creating a UDP packet */ + DatagramPacket replyPacket = new DatagramPacket(data, data.length, senderAddress, senderPort); + + /* Send the created packet to client */ + serverSocket.send(replyPacket); + } } catch (Exception e) { e.printStackTrace(); @@ -210,6 +250,19 @@ public void constructAsReplyForClient(String clientPassword) throws NoSuchAlgori System.out.println("ciphertext" + encryptedEncKdcRepPart.getCipherText()); } + private void constructKerberosErrorMessageReplyForClient() { + asErrorReplyForClient = ImmutableKrbError.builder() + .pvno(KERBEROS_VERSION_NUMBER) + .msgType(KRB_ERROR_MESSAGE_TYPE) + .stime(new Timestamp(System.currentTimeMillis())) + .errorCode(KDC_ERR_C_PRINCIPAL_UNKNOWN) + .cname(clientAsRequest.reqBody().getCname()) + .sname(clientAsRequest.reqBody().getSname()) + .eText("Client not found in Kerberos database") + .build(); + + } + public void loadUserAuthData() throws IOException, CsvValidationException { // File file = new File("src/main/java/resources/ClientAuthenticationDatabase.csv"); // // Create a fileReader object @@ -239,7 +292,6 @@ public void loadUserAuthData() throws IOException, CsvValidationException { UserAuthData gokul = new UserAuthData("sreekg", "gokul@123"); allUserAuthData.add(jessiya); allUserAuthData.add(gokul); - userAuthDatabase = allUserAuthData; } @@ -255,24 +307,18 @@ public String getClientCredentials(String clientUserid) { return "USER_NOT_FOUND"; } - private void doClientAuthenticationFromTgsRequest() { + private int doClientAuthenticationFromTgsRequest() { try { - KrbApReq apReqInTgsRequest = null; - // TODO: Add logic for verification of client's identity and other TGS functions -// for (PaData paData: clientRequest.paData()){ -// if (paData.getPadataType() == PA_TGS_REQ) { - String aPReqJson = new String(clientTgsRequest.paData()[0].getPadataValue(), StandardCharsets.UTF_8); + String apReqJson = new String(clientTgsRequest.paData()[0].getPadataValue(), StandardCharsets.UTF_8); ObjectMapper objectMapper = new ObjectMapper(); - apReqInTgsRequest = objectMapper.readValue(aPReqJson, KrbApReq.class); -// } -// } + KrbApReq apReqInTgsRequest = objectMapper.readValue(apReqJson, KrbApReq.class); System.out.println("appp"+apReqInTgsRequest.toString()); /* - Decrypt TGT from AP_REQ to retrieve session key + Decrypt TGT from AP_REQ using secret key of TGS to retrieve session key */ Ticket tgt = apReqInTgsRequest.ticket(); EncryptedData encryptedDataForTicket = tgt.getEncPart(); @@ -288,6 +334,9 @@ private void doClientAuthenticationFromTgsRequest() { plainTextForTicket, EncTicketPart.class); sessionKeyForTgs = unencryptedTicketFromTgsReq.getKey().getKeyValue(); + /* + Decrypt Authenticator from AP_REQ using the obtained session key + */ EncryptedData encryptedDataForAuthenticator = apReqInTgsRequest.authenticator(); String cipherTextForAuthenticator = new String( encryptedDataForAuthenticator.getCipher(), StandardCharsets.UTF_8); @@ -302,13 +351,13 @@ private void doClientAuthenticationFromTgsRequest() { /* CHECKS ON AUTHENTICATOR: - 1. Is Timestamp recent? (if issued maximum 10 minutes before) + 1. Is Timestamp recent? (if issued maximum 5 minutes before) 2. Is client name in authenticator and ticket same? */ Timestamp timeStampAsSessionKeyProof = unencryptedAuthenticatorFromTgsReq.getcTime(); Timestamp currentTimeStamp = new Timestamp(System.currentTimeMillis()); - if (addMinutes(timeStampAsSessionKeyProof, 10).before(currentTimeStamp)) { - throw new IncorrectAuthenticatorException("Timestamp in client authenticator is not recent"); + if (addMinutes(timeStampAsSessionKeyProof, 5).before(currentTimeStamp)) { + return KRB_AP_ERR_SKEW; } String cNameInAuthenticator = unencryptedAuthenticatorFromTgsReq.getCname().getNameString(); if (! unencryptedTicketFromTgsReq.getCname().getNameString().equals(cNameInAuthenticator)) { @@ -318,6 +367,10 @@ private void doClientAuthenticationFromTgsRequest() { } catch (Exception e) { e.printStackTrace(); } + + + + return 0; } public void constructTgsReplyForClient() throws NoSuchAlgorithmException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, InvalidKeySpecException, BadPaddingException, InvalidKeyException { diff --git a/KDC/src/main/java/messageformats/KrbApReq.java b/KDC/src/main/java/messageformats/KrbApReq.java index 3b05ca8..b088eab 100644 --- a/KDC/src/main/java/messageformats/KrbApReq.java +++ b/KDC/src/main/java/messageformats/KrbApReq.java @@ -10,7 +10,6 @@ @JsonDeserialize(as = ImmutableKrbApReq.class) public interface KrbApReq { int pvno(); - /* KRB_AP_REQ has type as 14 */ int msgType(); Ticket ticket(); EncryptedData authenticator(); diff --git a/KDC/src/main/java/messageformats/KrbError.java b/KDC/src/main/java/messageformats/KrbError.java new file mode 100644 index 0000000..b300d5c --- /dev/null +++ b/KDC/src/main/java/messageformats/KrbError.java @@ -0,0 +1,23 @@ +package messageformats; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.immutables.value.Value; + +import java.sql.Timestamp; +import java.util.Optional; + +@Value.Immutable +@Value.Style(privateNoargConstructor = true) +@JsonSerialize(as = ImmutableKrbError.class) +@JsonDeserialize(as = ImmutableKrbError.class) +public interface KrbError { + int pvno(); + int msgType(); + Optional ctime(); + Timestamp stime(); + int errorCode(); + Optional cname(); + PrincipalName sname(); + String eText(); +} diff --git a/KDC/src/main/java/messageformats/KrbKdcReq.java b/KDC/src/main/java/messageformats/KrbKdcReq.java index 87bb3e8..18a1bac 100644 --- a/KDC/src/main/java/messageformats/KrbKdcReq.java +++ b/KDC/src/main/java/messageformats/KrbKdcReq.java @@ -15,8 +15,6 @@ @JsonSerialize(as = ImmutableKrbKdcReq.class) @JsonDeserialize(as = ImmutableKrbKdcReq.class) public interface KrbKdcReq { -// long serialVersionUID = 1L; - int pvno(); int msgType(); PaData[] paData(); diff --git a/KDC/src/main/java/messageformats/KrbMessage.java b/KDC/src/main/java/messageformats/KrbMessage.java new file mode 100644 index 0000000..35b9492 --- /dev/null +++ b/KDC/src/main/java/messageformats/KrbMessage.java @@ -0,0 +1,16 @@ +package messageformats; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.immutables.value.Value; + +@Value.Immutable +@Value.Style(privateNoargConstructor = true) +@JsonSerialize(as = ImmutableKrbMessage.class) +@JsonDeserialize(as = ImmutableKrbMessage.class) +public interface KrbMessage { + // Message Header + int applicationNumber(); + // Message Body + byte[] krbMessageBody(); +} diff --git a/KDC/src/main/java/utils/Constants.java b/KDC/src/main/java/utils/Constants.java index c61b35c..5ba7f38 100644 --- a/KDC/src/main/java/utils/Constants.java +++ b/KDC/src/main/java/utils/Constants.java @@ -14,6 +14,8 @@ public class Constants { public static final int TGS_REQUEST_MESSSAGE_TYPE = 12; public static final int TGS_REPLY_MESSSAGE_TYPE = 13; public static final int AP_REQUEST_MESSAGE_TYPE = 14; + public static final int KRB_ERROR_MESSAGE_TYPE = 30; + // Hardcoded Server PrincipalNames public static final PrincipalName AS_SERVER = new PrincipalName("as_server"); @@ -39,21 +41,9 @@ public static enum ServerType { AP } + // Kerberos Error Codes + public static final int KDC_ERR_C_PRINCIPAL_UNKNOWN = 6; + public static final int KRB_AP_ERR_SKEW = 10; - // public static final ImmutablePrincipalName client = ImmutablePrincipalName.builder() -// .nameString("client") -// .build(); - -// public static final ImmutablePrincipalName as_server = ImmutablePrincipalName.builder() -// .nameString("as_server") -// .build(); - -// public static final ImmutablePrincipalName tgs_server = ImmutablePrincipalName.builder() -// .nameString("tgs_server") -// .build(); -// -// public static final ImmutablePrincipalName application_server = ImmutablePrincipalName.builder() -// .nameString("application_server") -// .build(); } diff --git a/KDC/target/generated-sources/annotations/messageformats/ImmutableKrbApRep.java b/KDC/target/generated-sources/annotations/messageformats/ImmutableKrbApRep.java deleted file mode 100644 index 85156cd..0000000 --- a/KDC/target/generated-sources/annotations/messageformats/ImmutableKrbApRep.java +++ /dev/null @@ -1,144 +0,0 @@ -package messageformats; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.util.Objects; -import org.immutables.value.Generated; - -/** - * Immutable implementation of {@link KrbApRep}. - *

- * Use the builder to create immutable instances: - * {@code ImmutableKrbApRep.builder()}. - */ -@Generated(from = "KrbApRep", generator = "Immutables") -@SuppressWarnings({"all"}) -@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") -public final class ImmutableKrbApRep implements KrbApRep { - - private ImmutableKrbApRep() {} - - private ImmutableKrbApRep(ImmutableKrbApRep.Builder builder) { - } - - /** - * This instance is equal to all instances of {@code ImmutableKrbApRep} that have equal attribute values. - * @return {@code true} if {@code this} is equal to {@code another} instance - */ - @Override - public boolean equals(Object another) { - if (this == another) return true; - return another instanceof ImmutableKrbApRep - && equalTo(0, (ImmutableKrbApRep) another); - } - - @SuppressWarnings("MethodCanBeStatic") - private boolean equalTo(int synthetic, ImmutableKrbApRep another) { - return true; - } - - /** - * Returns a constant hash code value. - * @return hashCode value - */ - @Override - public int hashCode() { - return -1675945109; - } - - /** - * Prints the immutable value {@code KrbApRep}. - * @return A string representation of the value - */ - @Override - public String toString() { - return "KrbApRep{}"; - } - - /** - * Utility type used to correctly read immutable object from JSON representation. - * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure - */ - @Generated(from = "KrbApRep", generator = "Immutables") - @Deprecated - @JsonDeserialize - @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) - static final class Json implements KrbApRep { - } - - /** - * @param json A JSON-bindable data structure - * @return An immutable value type - * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure - */ - @Deprecated - @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - static ImmutableKrbApRep fromJson(Json json) { - ImmutableKrbApRep.Builder builder = ImmutableKrbApRep.builder(); - return builder.build(); - } - - /** - * Creates an immutable copy of a {@link KrbApRep} value. - * Uses accessors to get values to initialize the new immutable instance. - * If an instance is already immutable, it is returned as is. - * @param instance The instance to copy - * @return A copied immutable KrbApRep instance - */ - public static ImmutableKrbApRep copyOf(KrbApRep instance) { - if (instance instanceof ImmutableKrbApRep) { - return (ImmutableKrbApRep) instance; - } - return ImmutableKrbApRep.builder() - .from(instance) - .build(); - } - - /** - * Creates a builder for {@link ImmutableKrbApRep ImmutableKrbApRep}. - *

-   * ImmutableKrbApRep.builder()
-   *    .build();
-   * 
- * @return A new ImmutableKrbApRep builder - */ - public static ImmutableKrbApRep.Builder builder() { - return new ImmutableKrbApRep.Builder(); - } - - /** - * Builds instances of type {@link ImmutableKrbApRep ImmutableKrbApRep}. - * Initialize attributes and then invoke the {@link #build()} method to create an - * immutable instance. - *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, - * but instead used immediately to create instances. - */ - @Generated(from = "KrbApRep", generator = "Immutables") - public static final class Builder { - - private Builder() { - } - - /** - * Fill a builder with attribute values from the provided {@code KrbApRep} instance. - * Regular attribute values will be replaced with those from the given instance. - * Absent optional values will not replace present values. - * @param instance The instance from which to copy values - * @return {@code this} builder for use in a chained invocation - */ - public final Builder from(KrbApRep instance) { - Objects.requireNonNull(instance, "instance"); - return this; - } - - /** - * Builds a new {@link ImmutableKrbApRep ImmutableKrbApRep}. - * @return An immutable instance of KrbApRep - * @throws java.lang.IllegalStateException if any required attributes are missing - */ - public ImmutableKrbApRep build() { - return new ImmutableKrbApRep(this); - } - } -} diff --git a/KDC/target/generated-sources/annotations/messageformats/ImmutableKrbApReq.java b/KDC/target/generated-sources/annotations/messageformats/ImmutableKrbApReq.java deleted file mode 100644 index cad6788..0000000 --- a/KDC/target/generated-sources/annotations/messageformats/ImmutableKrbApReq.java +++ /dev/null @@ -1,376 +0,0 @@ -package messageformats; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import org.immutables.value.Generated; - -/** - * Immutable implementation of {@link KrbApReq}. - *

- * Use the builder to create immutable instances: - * {@code ImmutableKrbApReq.builder()}. - */ -@Generated(from = "KrbApReq", generator = "Immutables") -@SuppressWarnings({"all"}) -@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") -public final class ImmutableKrbApReq implements KrbApReq { - private final int pvno; - private final int msgType; - private final Ticket ticket; - private final EncryptedData authenticator; - - private ImmutableKrbApReq() { - this.pvno = 0; - this.msgType = 0; - this.ticket = null; - this.authenticator = null; - } - - private ImmutableKrbApReq(int pvno, int msgType, Ticket ticket, EncryptedData authenticator) { - this.pvno = pvno; - this.msgType = msgType; - this.ticket = ticket; - this.authenticator = authenticator; - } - - /** - * @return The value of the {@code pvno} attribute - */ - @JsonProperty("pvno") - @Override - public int pvno() { - return pvno; - } - - /** - * @return The value of the {@code msgType} attribute - */ - @JsonProperty("msgType") - @Override - public int msgType() { - return msgType; - } - - /** - * @return The value of the {@code ticket} attribute - */ - @JsonProperty("ticket") - @Override - public Ticket ticket() { - return ticket; - } - - /** - * @return The value of the {@code authenticator} attribute - */ - @JsonProperty("authenticator") - @Override - public EncryptedData authenticator() { - return authenticator; - } - - /** - * Copy the current immutable object by setting a value for the {@link KrbApReq#pvno() pvno} attribute. - * A value equality check is used to prevent copying of the same value by returning {@code this}. - * @param value A new value for pvno - * @return A modified copy of the {@code this} object - */ - public final ImmutableKrbApReq withPvno(int value) { - if (this.pvno == value) return this; - return new ImmutableKrbApReq(value, this.msgType, this.ticket, this.authenticator); - } - - /** - * Copy the current immutable object by setting a value for the {@link KrbApReq#msgType() msgType} attribute. - * A value equality check is used to prevent copying of the same value by returning {@code this}. - * @param value A new value for msgType - * @return A modified copy of the {@code this} object - */ - public final ImmutableKrbApReq withMsgType(int value) { - if (this.msgType == value) return this; - return new ImmutableKrbApReq(this.pvno, value, this.ticket, this.authenticator); - } - - /** - * Copy the current immutable object by setting a value for the {@link KrbApReq#ticket() ticket} attribute. - * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. - * @param value A new value for ticket - * @return A modified copy of the {@code this} object - */ - public final ImmutableKrbApReq withTicket(Ticket value) { - if (this.ticket == value) return this; - Ticket newValue = Objects.requireNonNull(value, "ticket"); - return new ImmutableKrbApReq(this.pvno, this.msgType, newValue, this.authenticator); - } - - /** - * Copy the current immutable object by setting a value for the {@link KrbApReq#authenticator() authenticator} attribute. - * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. - * @param value A new value for authenticator - * @return A modified copy of the {@code this} object - */ - public final ImmutableKrbApReq withAuthenticator(EncryptedData value) { - if (this.authenticator == value) return this; - EncryptedData newValue = Objects.requireNonNull(value, "authenticator"); - return new ImmutableKrbApReq(this.pvno, this.msgType, this.ticket, newValue); - } - - /** - * This instance is equal to all instances of {@code ImmutableKrbApReq} that have equal attribute values. - * @return {@code true} if {@code this} is equal to {@code another} instance - */ - @Override - public boolean equals(Object another) { - if (this == another) return true; - return another instanceof ImmutableKrbApReq - && equalTo(0, (ImmutableKrbApReq) another); - } - - private boolean equalTo(int synthetic, ImmutableKrbApReq another) { - return pvno == another.pvno - && msgType == another.msgType - && ticket.equals(another.ticket) - && authenticator.equals(another.authenticator); - } - - /** - * Computes a hash code from attributes: {@code pvno}, {@code msgType}, {@code ticket}, {@code authenticator}. - * @return hashCode value - */ - @Override - public int hashCode() { - int h = 5381; - h += (h << 5) + pvno; - h += (h << 5) + msgType; - h += (h << 5) + ticket.hashCode(); - h += (h << 5) + authenticator.hashCode(); - return h; - } - - /** - * Prints the immutable value {@code KrbApReq} with attribute values. - * @return A string representation of the value - */ - @Override - public String toString() { - return "KrbApReq{" - + "pvno=" + pvno - + ", msgType=" + msgType - + ", ticket=" + ticket - + ", authenticator=" + authenticator - + "}"; - } - - /** - * Utility type used to correctly read immutable object from JSON representation. - * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure - */ - @Generated(from = "KrbApReq", generator = "Immutables") - @Deprecated - @JsonDeserialize - @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) - static final class Json implements KrbApReq { - int pvno; - boolean pvnoIsSet; - int msgType; - boolean msgTypeIsSet; - Ticket ticket; - EncryptedData authenticator; - @JsonProperty("pvno") - public void setPvno(int pvno) { - this.pvno = pvno; - this.pvnoIsSet = true; - } - @JsonProperty("msgType") - public void setMsgType(int msgType) { - this.msgType = msgType; - this.msgTypeIsSet = true; - } - @JsonProperty("ticket") - public void setTicket(Ticket ticket) { - this.ticket = ticket; - } - @JsonProperty("authenticator") - public void setAuthenticator(EncryptedData authenticator) { - this.authenticator = authenticator; - } - @Override - public int pvno() { throw new UnsupportedOperationException(); } - @Override - public int msgType() { throw new UnsupportedOperationException(); } - @Override - public Ticket ticket() { throw new UnsupportedOperationException(); } - @Override - public EncryptedData authenticator() { throw new UnsupportedOperationException(); } - } - - /** - * @param json A JSON-bindable data structure - * @return An immutable value type - * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure - */ - @Deprecated - @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - static ImmutableKrbApReq fromJson(Json json) { - ImmutableKrbApReq.Builder builder = ImmutableKrbApReq.builder(); - if (json.pvnoIsSet) { - builder.pvno(json.pvno); - } - if (json.msgTypeIsSet) { - builder.msgType(json.msgType); - } - if (json.ticket != null) { - builder.ticket(json.ticket); - } - if (json.authenticator != null) { - builder.authenticator(json.authenticator); - } - return builder.build(); - } - - /** - * Creates an immutable copy of a {@link KrbApReq} value. - * Uses accessors to get values to initialize the new immutable instance. - * If an instance is already immutable, it is returned as is. - * @param instance The instance to copy - * @return A copied immutable KrbApReq instance - */ - public static ImmutableKrbApReq copyOf(KrbApReq instance) { - if (instance instanceof ImmutableKrbApReq) { - return (ImmutableKrbApReq) instance; - } - return ImmutableKrbApReq.builder() - .from(instance) - .build(); - } - - /** - * Creates a builder for {@link ImmutableKrbApReq ImmutableKrbApReq}. - *

-   * ImmutableKrbApReq.builder()
-   *    .pvno(int) // required {@link KrbApReq#pvno() pvno}
-   *    .msgType(int) // required {@link KrbApReq#msgType() msgType}
-   *    .ticket(messageformats.Ticket) // required {@link KrbApReq#ticket() ticket}
-   *    .authenticator(messageformats.EncryptedData) // required {@link KrbApReq#authenticator() authenticator}
-   *    .build();
-   * 
- * @return A new ImmutableKrbApReq builder - */ - public static ImmutableKrbApReq.Builder builder() { - return new ImmutableKrbApReq.Builder(); - } - - /** - * Builds instances of type {@link ImmutableKrbApReq ImmutableKrbApReq}. - * Initialize attributes and then invoke the {@link #build()} method to create an - * immutable instance. - *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, - * but instead used immediately to create instances. - */ - @Generated(from = "KrbApReq", generator = "Immutables") - public static final class Builder { - private static final long INIT_BIT_PVNO = 0x1L; - private static final long INIT_BIT_MSG_TYPE = 0x2L; - private static final long INIT_BIT_TICKET = 0x4L; - private static final long INIT_BIT_AUTHENTICATOR = 0x8L; - private long initBits = 0xfL; - - private int pvno; - private int msgType; - private Ticket ticket; - private EncryptedData authenticator; - - private Builder() { - } - - /** - * Fill a builder with attribute values from the provided {@code KrbApReq} instance. - * Regular attribute values will be replaced with those from the given instance. - * Absent optional values will not replace present values. - * @param instance The instance from which to copy values - * @return {@code this} builder for use in a chained invocation - */ - public final Builder from(KrbApReq instance) { - Objects.requireNonNull(instance, "instance"); - pvno(instance.pvno()); - msgType(instance.msgType()); - ticket(instance.ticket()); - authenticator(instance.authenticator()); - return this; - } - - /** - * Initializes the value for the {@link KrbApReq#pvno() pvno} attribute. - * @param pvno The value for pvno - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("pvno") - public final Builder pvno(int pvno) { - this.pvno = pvno; - initBits &= ~INIT_BIT_PVNO; - return this; - } - - /** - * Initializes the value for the {@link KrbApReq#msgType() msgType} attribute. - * @param msgType The value for msgType - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("msgType") - public final Builder msgType(int msgType) { - this.msgType = msgType; - initBits &= ~INIT_BIT_MSG_TYPE; - return this; - } - - /** - * Initializes the value for the {@link KrbApReq#ticket() ticket} attribute. - * @param ticket The value for ticket - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("ticket") - public final Builder ticket(Ticket ticket) { - this.ticket = Objects.requireNonNull(ticket, "ticket"); - initBits &= ~INIT_BIT_TICKET; - return this; - } - - /** - * Initializes the value for the {@link KrbApReq#authenticator() authenticator} attribute. - * @param authenticator The value for authenticator - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("authenticator") - public final Builder authenticator(EncryptedData authenticator) { - this.authenticator = Objects.requireNonNull(authenticator, "authenticator"); - initBits &= ~INIT_BIT_AUTHENTICATOR; - return this; - } - - /** - * Builds a new {@link ImmutableKrbApReq ImmutableKrbApReq}. - * @return An immutable instance of KrbApReq - * @throws java.lang.IllegalStateException if any required attributes are missing - */ - public ImmutableKrbApReq build() { - if (initBits != 0) { - throw new IllegalStateException(formatRequiredAttributesMessage()); - } - return new ImmutableKrbApReq(pvno, msgType, ticket, authenticator); - } - - private String formatRequiredAttributesMessage() { - List attributes = new ArrayList<>(); - if ((initBits & INIT_BIT_PVNO) != 0) attributes.add("pvno"); - if ((initBits & INIT_BIT_MSG_TYPE) != 0) attributes.add("msgType"); - if ((initBits & INIT_BIT_TICKET) != 0) attributes.add("ticket"); - if ((initBits & INIT_BIT_AUTHENTICATOR) != 0) attributes.add("authenticator"); - return "Cannot build KrbApReq, some of required attributes are not set " + attributes; - } - } -} diff --git a/KDC/target/generated-sources/annotations/messageformats/ImmutableKrbKdcRep.java b/KDC/target/generated-sources/annotations/messageformats/ImmutableKrbKdcRep.java deleted file mode 100644 index 5264165..0000000 --- a/KDC/target/generated-sources/annotations/messageformats/ImmutableKrbKdcRep.java +++ /dev/null @@ -1,490 +0,0 @@ -package messageformats; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import org.immutables.value.Generated; - -/** - * Immutable implementation of {@link KrbKdcRep}. - *

- * Use the builder to create immutable instances: - * {@code ImmutableKrbKdcRep.builder()}. - */ -@Generated(from = "KrbKdcRep", generator = "Immutables") -@SuppressWarnings({"all"}) -@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") -public final class ImmutableKrbKdcRep implements KrbKdcRep { - private final int pvno; - private final int msgType; - private final PaData[] paData; - private final PrincipalName cname; - private final Ticket ticket; - private final EncryptedData encPart; - - private ImmutableKrbKdcRep() { - this.pvno = 0; - this.msgType = 0; - this.paData = null; - this.cname = null; - this.ticket = null; - this.encPart = null; - } - - private ImmutableKrbKdcRep( - int pvno, - int msgType, - PaData[] paData, - PrincipalName cname, - Ticket ticket, - EncryptedData encPart) { - this.pvno = pvno; - this.msgType = msgType; - this.paData = paData; - this.cname = cname; - this.ticket = ticket; - this.encPart = encPart; - } - - /** - * @return The value of the {@code pvno} attribute - */ - @JsonProperty("pvno") - @Override - public int pvno() { - return pvno; - } - - /** - * @return The value of the {@code msgType} attribute - */ - @JsonProperty("msgType") - @Override - public int msgType() { - return msgType; - } - - /** - * @return A cloned {@code paData} array - */ - @JsonProperty("paData") - @Override - public PaData[] paData() { - return paData.clone(); - } - - /** - * @return The value of the {@code cname} attribute - */ - @JsonProperty("cname") - @Override - public PrincipalName cname() { - return cname; - } - - /** - * @return The value of the {@code ticket} attribute - */ - @JsonProperty("ticket") - @Override - public Ticket ticket() { - return ticket; - } - - /** - * @return The value of the {@code encPart} attribute - */ - @JsonProperty("encPart") - @Override - public EncryptedData encPart() { - return encPart; - } - - /** - * Copy the current immutable object by setting a value for the {@link KrbKdcRep#pvno() pvno} attribute. - * A value equality check is used to prevent copying of the same value by returning {@code this}. - * @param value A new value for pvno - * @return A modified copy of the {@code this} object - */ - public final ImmutableKrbKdcRep withPvno(int value) { - if (this.pvno == value) return this; - return new ImmutableKrbKdcRep(value, this.msgType, this.paData, this.cname, this.ticket, this.encPart); - } - - /** - * Copy the current immutable object by setting a value for the {@link KrbKdcRep#msgType() msgType} attribute. - * A value equality check is used to prevent copying of the same value by returning {@code this}. - * @param value A new value for msgType - * @return A modified copy of the {@code this} object - */ - public final ImmutableKrbKdcRep withMsgType(int value) { - if (this.msgType == value) return this; - return new ImmutableKrbKdcRep(this.pvno, value, this.paData, this.cname, this.ticket, this.encPart); - } - - /** - * Copy the current immutable object with elements that replace the content of {@link KrbKdcRep#paData() paData}. - * The array is cloned before being saved as attribute values. - * @param elements The non-null elements for paData - * @return A modified copy of {@code this} object - */ - public final ImmutableKrbKdcRep withPaData(PaData... elements) { - PaData[] newValue = elements.clone(); - return new ImmutableKrbKdcRep(this.pvno, this.msgType, newValue, this.cname, this.ticket, this.encPart); - } - - /** - * Copy the current immutable object by setting a value for the {@link KrbKdcRep#cname() cname} attribute. - * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. - * @param value A new value for cname - * @return A modified copy of the {@code this} object - */ - public final ImmutableKrbKdcRep withCname(PrincipalName value) { - if (this.cname == value) return this; - PrincipalName newValue = Objects.requireNonNull(value, "cname"); - return new ImmutableKrbKdcRep(this.pvno, this.msgType, this.paData, newValue, this.ticket, this.encPart); - } - - /** - * Copy the current immutable object by setting a value for the {@link KrbKdcRep#ticket() ticket} attribute. - * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. - * @param value A new value for ticket - * @return A modified copy of the {@code this} object - */ - public final ImmutableKrbKdcRep withTicket(Ticket value) { - if (this.ticket == value) return this; - Ticket newValue = Objects.requireNonNull(value, "ticket"); - return new ImmutableKrbKdcRep(this.pvno, this.msgType, this.paData, this.cname, newValue, this.encPart); - } - - /** - * Copy the current immutable object by setting a value for the {@link KrbKdcRep#encPart() encPart} attribute. - * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. - * @param value A new value for encPart - * @return A modified copy of the {@code this} object - */ - public final ImmutableKrbKdcRep withEncPart(EncryptedData value) { - if (this.encPart == value) return this; - EncryptedData newValue = Objects.requireNonNull(value, "encPart"); - return new ImmutableKrbKdcRep(this.pvno, this.msgType, this.paData, this.cname, this.ticket, newValue); - } - - /** - * This instance is equal to all instances of {@code ImmutableKrbKdcRep} that have equal attribute values. - * @return {@code true} if {@code this} is equal to {@code another} instance - */ - @Override - public boolean equals(Object another) { - if (this == another) return true; - return another instanceof ImmutableKrbKdcRep - && equalTo(0, (ImmutableKrbKdcRep) another); - } - - private boolean equalTo(int synthetic, ImmutableKrbKdcRep another) { - return pvno == another.pvno - && msgType == another.msgType - && Arrays.equals(paData, another.paData) - && cname.equals(another.cname) - && ticket.equals(another.ticket) - && encPart.equals(another.encPart); - } - - /** - * Computes a hash code from attributes: {@code pvno}, {@code msgType}, {@code paData}, {@code cname}, {@code ticket}, {@code encPart}. - * @return hashCode value - */ - @Override - public int hashCode() { - int h = 5381; - h += (h << 5) + pvno; - h += (h << 5) + msgType; - h += (h << 5) + Arrays.hashCode(paData); - h += (h << 5) + cname.hashCode(); - h += (h << 5) + ticket.hashCode(); - h += (h << 5) + encPart.hashCode(); - return h; - } - - /** - * Prints the immutable value {@code KrbKdcRep} with attribute values. - * @return A string representation of the value - */ - @Override - public String toString() { - return "KrbKdcRep{" - + "pvno=" + pvno - + ", msgType=" + msgType - + ", paData=" + Arrays.toString(paData) - + ", cname=" + cname - + ", ticket=" + ticket - + ", encPart=" + encPart - + "}"; - } - - /** - * Utility type used to correctly read immutable object from JSON representation. - * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure - */ - @Generated(from = "KrbKdcRep", generator = "Immutables") - @Deprecated - @JsonDeserialize - @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) - static final class Json implements KrbKdcRep { - int pvno; - boolean pvnoIsSet; - int msgType; - boolean msgTypeIsSet; - PaData[] paData; - PrincipalName cname; - Ticket ticket; - EncryptedData encPart; - @JsonProperty("pvno") - public void setPvno(int pvno) { - this.pvno = pvno; - this.pvnoIsSet = true; - } - @JsonProperty("msgType") - public void setMsgType(int msgType) { - this.msgType = msgType; - this.msgTypeIsSet = true; - } - @JsonProperty("paData") - public void setPaData(PaData[] paData) { - this.paData = paData; - } - @JsonProperty("cname") - public void setCname(PrincipalName cname) { - this.cname = cname; - } - @JsonProperty("ticket") - public void setTicket(Ticket ticket) { - this.ticket = ticket; - } - @JsonProperty("encPart") - public void setEncPart(EncryptedData encPart) { - this.encPart = encPart; - } - @Override - public int pvno() { throw new UnsupportedOperationException(); } - @Override - public int msgType() { throw new UnsupportedOperationException(); } - @Override - public PaData[] paData() { throw new UnsupportedOperationException(); } - @Override - public PrincipalName cname() { throw new UnsupportedOperationException(); } - @Override - public Ticket ticket() { throw new UnsupportedOperationException(); } - @Override - public EncryptedData encPart() { throw new UnsupportedOperationException(); } - } - - /** - * @param json A JSON-bindable data structure - * @return An immutable value type - * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure - */ - @Deprecated - @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - static ImmutableKrbKdcRep fromJson(Json json) { - ImmutableKrbKdcRep.Builder builder = ImmutableKrbKdcRep.builder(); - if (json.pvnoIsSet) { - builder.pvno(json.pvno); - } - if (json.msgTypeIsSet) { - builder.msgType(json.msgType); - } - if (json.paData != null) { - builder.paData(json.paData); - } - if (json.cname != null) { - builder.cname(json.cname); - } - if (json.ticket != null) { - builder.ticket(json.ticket); - } - if (json.encPart != null) { - builder.encPart(json.encPart); - } - return builder.build(); - } - - /** - * Creates an immutable copy of a {@link KrbKdcRep} value. - * Uses accessors to get values to initialize the new immutable instance. - * If an instance is already immutable, it is returned as is. - * @param instance The instance to copy - * @return A copied immutable KrbKdcRep instance - */ - public static ImmutableKrbKdcRep copyOf(KrbKdcRep instance) { - if (instance instanceof ImmutableKrbKdcRep) { - return (ImmutableKrbKdcRep) instance; - } - return ImmutableKrbKdcRep.builder() - .from(instance) - .build(); - } - - /** - * Creates a builder for {@link ImmutableKrbKdcRep ImmutableKrbKdcRep}. - *

-   * ImmutableKrbKdcRep.builder()
-   *    .pvno(int) // required {@link KrbKdcRep#pvno() pvno}
-   *    .msgType(int) // required {@link KrbKdcRep#msgType() msgType}
-   *    .paData(messageformats.PaData) // required {@link KrbKdcRep#paData() paData}
-   *    .cname(messageformats.PrincipalName) // required {@link KrbKdcRep#cname() cname}
-   *    .ticket(messageformats.Ticket) // required {@link KrbKdcRep#ticket() ticket}
-   *    .encPart(messageformats.EncryptedData) // required {@link KrbKdcRep#encPart() encPart}
-   *    .build();
-   * 
- * @return A new ImmutableKrbKdcRep builder - */ - public static ImmutableKrbKdcRep.Builder builder() { - return new ImmutableKrbKdcRep.Builder(); - } - - /** - * Builds instances of type {@link ImmutableKrbKdcRep ImmutableKrbKdcRep}. - * Initialize attributes and then invoke the {@link #build()} method to create an - * immutable instance. - *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, - * but instead used immediately to create instances. - */ - @Generated(from = "KrbKdcRep", generator = "Immutables") - public static final class Builder { - private static final long INIT_BIT_PVNO = 0x1L; - private static final long INIT_BIT_MSG_TYPE = 0x2L; - private static final long INIT_BIT_PA_DATA = 0x4L; - private static final long INIT_BIT_CNAME = 0x8L; - private static final long INIT_BIT_TICKET = 0x10L; - private static final long INIT_BIT_ENC_PART = 0x20L; - private long initBits = 0x3fL; - - private int pvno; - private int msgType; - private PaData[] paData; - private PrincipalName cname; - private Ticket ticket; - private EncryptedData encPart; - - private Builder() { - } - - /** - * Fill a builder with attribute values from the provided {@code KrbKdcRep} instance. - * Regular attribute values will be replaced with those from the given instance. - * Absent optional values will not replace present values. - * @param instance The instance from which to copy values - * @return {@code this} builder for use in a chained invocation - */ - public final Builder from(KrbKdcRep instance) { - Objects.requireNonNull(instance, "instance"); - pvno(instance.pvno()); - msgType(instance.msgType()); - paData(instance.paData()); - cname(instance.cname()); - ticket(instance.ticket()); - encPart(instance.encPart()); - return this; - } - - /** - * Initializes the value for the {@link KrbKdcRep#pvno() pvno} attribute. - * @param pvno The value for pvno - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("pvno") - public final Builder pvno(int pvno) { - this.pvno = pvno; - initBits &= ~INIT_BIT_PVNO; - return this; - } - - /** - * Initializes the value for the {@link KrbKdcRep#msgType() msgType} attribute. - * @param msgType The value for msgType - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("msgType") - public final Builder msgType(int msgType) { - this.msgType = msgType; - initBits &= ~INIT_BIT_MSG_TYPE; - return this; - } - - /** - * Initializes the value for the {@link KrbKdcRep#paData() paData} attribute. - * @param paData The elements for paData - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("paData") - public final Builder paData(PaData... paData) { - this.paData = paData.clone(); - initBits &= ~INIT_BIT_PA_DATA; - return this; - } - - /** - * Initializes the value for the {@link KrbKdcRep#cname() cname} attribute. - * @param cname The value for cname - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("cname") - public final Builder cname(PrincipalName cname) { - this.cname = Objects.requireNonNull(cname, "cname"); - initBits &= ~INIT_BIT_CNAME; - return this; - } - - /** - * Initializes the value for the {@link KrbKdcRep#ticket() ticket} attribute. - * @param ticket The value for ticket - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("ticket") - public final Builder ticket(Ticket ticket) { - this.ticket = Objects.requireNonNull(ticket, "ticket"); - initBits &= ~INIT_BIT_TICKET; - return this; - } - - /** - * Initializes the value for the {@link KrbKdcRep#encPart() encPart} attribute. - * @param encPart The value for encPart - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("encPart") - public final Builder encPart(EncryptedData encPart) { - this.encPart = Objects.requireNonNull(encPart, "encPart"); - initBits &= ~INIT_BIT_ENC_PART; - return this; - } - - /** - * Builds a new {@link ImmutableKrbKdcRep ImmutableKrbKdcRep}. - * @return An immutable instance of KrbKdcRep - * @throws java.lang.IllegalStateException if any required attributes are missing - */ - public ImmutableKrbKdcRep build() { - if (initBits != 0) { - throw new IllegalStateException(formatRequiredAttributesMessage()); - } - return new ImmutableKrbKdcRep(pvno, msgType, paData, cname, ticket, encPart); - } - - private String formatRequiredAttributesMessage() { - List attributes = new ArrayList<>(); - if ((initBits & INIT_BIT_PVNO) != 0) attributes.add("pvno"); - if ((initBits & INIT_BIT_MSG_TYPE) != 0) attributes.add("msgType"); - if ((initBits & INIT_BIT_PA_DATA) != 0) attributes.add("paData"); - if ((initBits & INIT_BIT_CNAME) != 0) attributes.add("cname"); - if ((initBits & INIT_BIT_TICKET) != 0) attributes.add("ticket"); - if ((initBits & INIT_BIT_ENC_PART) != 0) attributes.add("encPart"); - return "Cannot build KrbKdcRep, some of required attributes are not set " + attributes; - } - } -} diff --git a/KDC/target/generated-sources/annotations/messageformats/ImmutableKrbKdcReq.java b/KDC/target/generated-sources/annotations/messageformats/ImmutableKrbKdcReq.java deleted file mode 100644 index b1f120c..0000000 --- a/KDC/target/generated-sources/annotations/messageformats/ImmutableKrbKdcReq.java +++ /dev/null @@ -1,376 +0,0 @@ -package messageformats; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import org.immutables.value.Generated; - -/** - * Immutable implementation of {@link KrbKdcReq}. - *

- * Use the builder to create immutable instances: - * {@code ImmutableKrbKdcReq.builder()}. - */ -@Generated(from = "KrbKdcReq", generator = "Immutables") -@SuppressWarnings({"all"}) -@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") -public final class ImmutableKrbKdcReq implements KrbKdcReq { - private final int pvno; - private final int msgType; - private final PaData[] paData; - private final KrbKdcReqBody reqBody; - - private ImmutableKrbKdcReq() { - this.pvno = 0; - this.msgType = 0; - this.paData = null; - this.reqBody = null; - } - - private ImmutableKrbKdcReq(int pvno, int msgType, PaData[] paData, KrbKdcReqBody reqBody) { - this.pvno = pvno; - this.msgType = msgType; - this.paData = paData; - this.reqBody = reqBody; - } - - /** - * @return The value of the {@code pvno} attribute - */ - @JsonProperty("pvno") - @Override - public int pvno() { - return pvno; - } - - /** - * @return The value of the {@code msgType} attribute - */ - @JsonProperty("msgType") - @Override - public int msgType() { - return msgType; - } - - /** - * @return A cloned {@code paData} array - */ - @JsonProperty("paData") - @Override - public PaData[] paData() { - return paData.clone(); - } - - /** - * @return The value of the {@code reqBody} attribute - */ - @JsonProperty("reqBody") - @Override - public KrbKdcReqBody reqBody() { - return reqBody; - } - - /** - * Copy the current immutable object by setting a value for the {@link KrbKdcReq#pvno() pvno} attribute. - * A value equality check is used to prevent copying of the same value by returning {@code this}. - * @param value A new value for pvno - * @return A modified copy of the {@code this} object - */ - public final ImmutableKrbKdcReq withPvno(int value) { - if (this.pvno == value) return this; - return new ImmutableKrbKdcReq(value, this.msgType, this.paData, this.reqBody); - } - - /** - * Copy the current immutable object by setting a value for the {@link KrbKdcReq#msgType() msgType} attribute. - * A value equality check is used to prevent copying of the same value by returning {@code this}. - * @param value A new value for msgType - * @return A modified copy of the {@code this} object - */ - public final ImmutableKrbKdcReq withMsgType(int value) { - if (this.msgType == value) return this; - return new ImmutableKrbKdcReq(this.pvno, value, this.paData, this.reqBody); - } - - /** - * Copy the current immutable object with elements that replace the content of {@link KrbKdcReq#paData() paData}. - * The array is cloned before being saved as attribute values. - * @param elements The non-null elements for paData - * @return A modified copy of {@code this} object - */ - public final ImmutableKrbKdcReq withPaData(PaData... elements) { - PaData[] newValue = elements.clone(); - return new ImmutableKrbKdcReq(this.pvno, this.msgType, newValue, this.reqBody); - } - - /** - * Copy the current immutable object by setting a value for the {@link KrbKdcReq#reqBody() reqBody} attribute. - * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. - * @param value A new value for reqBody - * @return A modified copy of the {@code this} object - */ - public final ImmutableKrbKdcReq withReqBody(KrbKdcReqBody value) { - if (this.reqBody == value) return this; - KrbKdcReqBody newValue = Objects.requireNonNull(value, "reqBody"); - return new ImmutableKrbKdcReq(this.pvno, this.msgType, this.paData, newValue); - } - - /** - * This instance is equal to all instances of {@code ImmutableKrbKdcReq} that have equal attribute values. - * @return {@code true} if {@code this} is equal to {@code another} instance - */ - @Override - public boolean equals(Object another) { - if (this == another) return true; - return another instanceof ImmutableKrbKdcReq - && equalTo(0, (ImmutableKrbKdcReq) another); - } - - private boolean equalTo(int synthetic, ImmutableKrbKdcReq another) { - return pvno == another.pvno - && msgType == another.msgType - && Arrays.equals(paData, another.paData) - && reqBody.equals(another.reqBody); - } - - /** - * Computes a hash code from attributes: {@code pvno}, {@code msgType}, {@code paData}, {@code reqBody}. - * @return hashCode value - */ - @Override - public int hashCode() { - int h = 5381; - h += (h << 5) + pvno; - h += (h << 5) + msgType; - h += (h << 5) + Arrays.hashCode(paData); - h += (h << 5) + reqBody.hashCode(); - return h; - } - - /** - * Prints the immutable value {@code KrbKdcReq} with attribute values. - * @return A string representation of the value - */ - @Override - public String toString() { - return "KrbKdcReq{" - + "pvno=" + pvno - + ", msgType=" + msgType - + ", paData=" + Arrays.toString(paData) - + ", reqBody=" + reqBody - + "}"; - } - - /** - * Utility type used to correctly read immutable object from JSON representation. - * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure - */ - @Generated(from = "KrbKdcReq", generator = "Immutables") - @Deprecated - @JsonDeserialize - @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) - static final class Json implements KrbKdcReq { - int pvno; - boolean pvnoIsSet; - int msgType; - boolean msgTypeIsSet; - PaData[] paData; - KrbKdcReqBody reqBody; - @JsonProperty("pvno") - public void setPvno(int pvno) { - this.pvno = pvno; - this.pvnoIsSet = true; - } - @JsonProperty("msgType") - public void setMsgType(int msgType) { - this.msgType = msgType; - this.msgTypeIsSet = true; - } - @JsonProperty("paData") - public void setPaData(PaData[] paData) { - this.paData = paData; - } - @JsonProperty("reqBody") - public void setReqBody(KrbKdcReqBody reqBody) { - this.reqBody = reqBody; - } - @Override - public int pvno() { throw new UnsupportedOperationException(); } - @Override - public int msgType() { throw new UnsupportedOperationException(); } - @Override - public PaData[] paData() { throw new UnsupportedOperationException(); } - @Override - public KrbKdcReqBody reqBody() { throw new UnsupportedOperationException(); } - } - - /** - * @param json A JSON-bindable data structure - * @return An immutable value type - * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure - */ - @Deprecated - @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - static ImmutableKrbKdcReq fromJson(Json json) { - ImmutableKrbKdcReq.Builder builder = ImmutableKrbKdcReq.builder(); - if (json.pvnoIsSet) { - builder.pvno(json.pvno); - } - if (json.msgTypeIsSet) { - builder.msgType(json.msgType); - } - if (json.paData != null) { - builder.paData(json.paData); - } - if (json.reqBody != null) { - builder.reqBody(json.reqBody); - } - return builder.build(); - } - - /** - * Creates an immutable copy of a {@link KrbKdcReq} value. - * Uses accessors to get values to initialize the new immutable instance. - * If an instance is already immutable, it is returned as is. - * @param instance The instance to copy - * @return A copied immutable KrbKdcReq instance - */ - public static ImmutableKrbKdcReq copyOf(KrbKdcReq instance) { - if (instance instanceof ImmutableKrbKdcReq) { - return (ImmutableKrbKdcReq) instance; - } - return ImmutableKrbKdcReq.builder() - .from(instance) - .build(); - } - - /** - * Creates a builder for {@link ImmutableKrbKdcReq ImmutableKrbKdcReq}. - *

-   * ImmutableKrbKdcReq.builder()
-   *    .pvno(int) // required {@link KrbKdcReq#pvno() pvno}
-   *    .msgType(int) // required {@link KrbKdcReq#msgType() msgType}
-   *    .paData(messageformats.PaData) // required {@link KrbKdcReq#paData() paData}
-   *    .reqBody(messageformats.KrbKdcReqBody) // required {@link KrbKdcReq#reqBody() reqBody}
-   *    .build();
-   * 
- * @return A new ImmutableKrbKdcReq builder - */ - public static ImmutableKrbKdcReq.Builder builder() { - return new ImmutableKrbKdcReq.Builder(); - } - - /** - * Builds instances of type {@link ImmutableKrbKdcReq ImmutableKrbKdcReq}. - * Initialize attributes and then invoke the {@link #build()} method to create an - * immutable instance. - *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, - * but instead used immediately to create instances. - */ - @Generated(from = "KrbKdcReq", generator = "Immutables") - public static final class Builder { - private static final long INIT_BIT_PVNO = 0x1L; - private static final long INIT_BIT_MSG_TYPE = 0x2L; - private static final long INIT_BIT_PA_DATA = 0x4L; - private static final long INIT_BIT_REQ_BODY = 0x8L; - private long initBits = 0xfL; - - private int pvno; - private int msgType; - private PaData[] paData; - private KrbKdcReqBody reqBody; - - private Builder() { - } - - /** - * Fill a builder with attribute values from the provided {@code KrbKdcReq} instance. - * Regular attribute values will be replaced with those from the given instance. - * Absent optional values will not replace present values. - * @param instance The instance from which to copy values - * @return {@code this} builder for use in a chained invocation - */ - public final Builder from(KrbKdcReq instance) { - Objects.requireNonNull(instance, "instance"); - pvno(instance.pvno()); - msgType(instance.msgType()); - paData(instance.paData()); - reqBody(instance.reqBody()); - return this; - } - - /** - * Initializes the value for the {@link KrbKdcReq#pvno() pvno} attribute. - * @param pvno The value for pvno - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("pvno") - public final Builder pvno(int pvno) { - this.pvno = pvno; - initBits &= ~INIT_BIT_PVNO; - return this; - } - - /** - * Initializes the value for the {@link KrbKdcReq#msgType() msgType} attribute. - * @param msgType The value for msgType - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("msgType") - public final Builder msgType(int msgType) { - this.msgType = msgType; - initBits &= ~INIT_BIT_MSG_TYPE; - return this; - } - - /** - * Initializes the value for the {@link KrbKdcReq#paData() paData} attribute. - * @param paData The elements for paData - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("paData") - public final Builder paData(PaData... paData) { - this.paData = paData.clone(); - initBits &= ~INIT_BIT_PA_DATA; - return this; - } - - /** - * Initializes the value for the {@link KrbKdcReq#reqBody() reqBody} attribute. - * @param reqBody The value for reqBody - * @return {@code this} builder for use in a chained invocation - */ - @JsonProperty("reqBody") - public final Builder reqBody(KrbKdcReqBody reqBody) { - this.reqBody = Objects.requireNonNull(reqBody, "reqBody"); - initBits &= ~INIT_BIT_REQ_BODY; - return this; - } - - /** - * Builds a new {@link ImmutableKrbKdcReq ImmutableKrbKdcReq}. - * @return An immutable instance of KrbKdcReq - * @throws java.lang.IllegalStateException if any required attributes are missing - */ - public ImmutableKrbKdcReq build() { - if (initBits != 0) { - throw new IllegalStateException(formatRequiredAttributesMessage()); - } - return new ImmutableKrbKdcReq(pvno, msgType, paData, reqBody); - } - - private String formatRequiredAttributesMessage() { - List attributes = new ArrayList<>(); - if ((initBits & INIT_BIT_PVNO) != 0) attributes.add("pvno"); - if ((initBits & INIT_BIT_MSG_TYPE) != 0) attributes.add("msgType"); - if ((initBits & INIT_BIT_PA_DATA) != 0) attributes.add("paData"); - if ((initBits & INIT_BIT_REQ_BODY) != 0) attributes.add("reqBody"); - return "Cannot build KrbKdcReq, some of required attributes are not set " + attributes; - } - } -}