From 856e036b0d0c212d3a4c8bca749115d6005cf568 Mon Sep 17 00:00:00 2001 From: gokulsreekumar Date: Fri, 18 Mar 2022 02:38:46 +0530 Subject: [PATCH 1/4] Reply from AP to client done --- .DS_Store | Bin 8196 -> 6148 bytes ApplicationServer/src/main/java/Main.java | 4 - .../main/java/entities/ApplicationServer.java | 106 ++++++++++++------ .../java/messageformats/EncApRepPart.java | 36 ++++++ .../main/java/messageformats/KrbApRep.java | 4 +- .../main/java/messageformats/KrbApReq.java | 2 +- .../main/java/messageformats/KrbKdcRep.java | 2 - .../main/java/messageformats/KrbKdcReq.java | 6 - .../java/messageformats/KrbKdcReqBody.java | 4 - .../src/main/java/messageformats/Ticket.java | 2 - .../src/main/java/utils/Constants.java | 19 +--- Client/Client.iml | 25 +++++ .../TimestampMismatchException.java | 8 ++ Client/src/main/java/entities/Client.java | 53 +++++++-- .../java/messageformats/EncApRepPart.java | 36 ++++++ .../main/java/messageformats/KrbApRep.java | 4 +- KDC/.idea/compiler.xml | 3 + 17 files changed, 234 insertions(+), 80 deletions(-) create mode 100644 ApplicationServer/src/main/java/messageformats/EncApRepPart.java create mode 100644 Client/Client.iml create mode 100644 Client/src/main/java/Exceptions/TimestampMismatchException.java create mode 100644 Client/src/main/java/messageformats/EncApRepPart.java diff --git a/.DS_Store b/.DS_Store index 63d1286782fe8de15a29919ae1fb8b1e851f37f8..5952efa056623c5045b8693b7b47fee1e760de2a 100644 GIT binary patch delta 211 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{MGqg`E6q~50D9Q|EGlIo38IlgsN1Q{F|3V<*NC7@Xlk8w(ZK7qfG42!bpD0s(Fy;R?j<8w0pY1z$tWN7JVG5|b2B@ugezK_%{HgI&7aE!m`b2!T8* z`g;U_i2fI!^vp*}vaul*D}m01xo39f-pS0lJF|N?M8p~cuSB#(L?#Nyd=Bal!uxqy zkd$h<3uN#oH;7!+^C(YLp9aloXI;t!TeXKvj# zOvB8X@9g7fX!o7|AZ|FlH~i`dlXa(c$9?5@hwc1EGYb2TA9j1f!S}i_dHdQAy=d5o z2B8-VUt4yVSu@+t-ye;t#bUwQDHg{CYgDT2R|{6PTp5qE=DmlH9v`+(g3~bKi-RzA zNYNd6eWAagw(^3fZ1cfZb~?9vVGxBM;KTh)M8H9O9CA_Og=jp0&1^Il?5C4}9R_j_B~B0^HClnYjAuO>pWSF07Q+D`Q^Lb9;1rK?U*yqRPLyJ-N* zkHHe(8a{PI2z+dZaE7t3$(#7v8QUC seqNumber; + + public EncApRepPart(Timestamp ctime) { + this.ctime = ctime; + } + + public EncApRepPart(Timestamp ctime, Optional seqNumber) { + this.ctime = ctime; + this.seqNumber = seqNumber; + } + + public Timestamp getCtime() { + return ctime; + } + + public void setCtime(Timestamp ctime) { + this.ctime = ctime; + } + + public Optional getSeqNumber() { + return seqNumber; + } + + public void setSeqNumber(Optional seqNumber) { + this.seqNumber = seqNumber; + } +} diff --git a/ApplicationServer/src/main/java/messageformats/KrbApRep.java b/ApplicationServer/src/main/java/messageformats/KrbApRep.java index 4b48713..2045eae 100644 --- a/ApplicationServer/src/main/java/messageformats/KrbApRep.java +++ b/ApplicationServer/src/main/java/messageformats/KrbApRep.java @@ -9,5 +9,7 @@ @JsonSerialize(as = ImmutableKrbApRep.class) @JsonDeserialize(as = ImmutableKrbApRep.class) public interface KrbApRep { - + int pvno(); + int msgType(); + EncryptedData encPart(); } diff --git a/ApplicationServer/src/main/java/messageformats/KrbApReq.java b/ApplicationServer/src/main/java/messageformats/KrbApReq.java index 3b05ca8..c79ebaf 100644 --- a/ApplicationServer/src/main/java/messageformats/KrbApReq.java +++ b/ApplicationServer/src/main/java/messageformats/KrbApReq.java @@ -10,8 +10,8 @@ @JsonDeserialize(as = ImmutableKrbApReq.class) public interface KrbApReq { int pvno(); - /* KRB_AP_REQ has type as 14 */ int msgType(); Ticket ticket(); EncryptedData authenticator(); + // TODO: Keep ApOptions and check if to send APRep or not. } diff --git a/ApplicationServer/src/main/java/messageformats/KrbKdcRep.java b/ApplicationServer/src/main/java/messageformats/KrbKdcRep.java index 2270159..ee31c06 100644 --- a/ApplicationServer/src/main/java/messageformats/KrbKdcRep.java +++ b/ApplicationServer/src/main/java/messageformats/KrbKdcRep.java @@ -4,8 +4,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.immutables.value.Value; -import java.util.Optional; - @Value.Immutable @Value.Style(privateNoargConstructor = true) @JsonSerialize(as = ImmutableKrbKdcRep.class) diff --git a/ApplicationServer/src/main/java/messageformats/KrbKdcReq.java b/ApplicationServer/src/main/java/messageformats/KrbKdcReq.java index 87bb3e8..8986644 100644 --- a/ApplicationServer/src/main/java/messageformats/KrbKdcReq.java +++ b/ApplicationServer/src/main/java/messageformats/KrbKdcReq.java @@ -1,15 +1,9 @@ package messageformats; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.immutables.value.Value; -import java.io.Serializable; -import java.util.Optional; - @Value.Immutable @Value.Style(privateNoargConstructor = true) @JsonSerialize(as = ImmutableKrbKdcReq.class) diff --git a/ApplicationServer/src/main/java/messageformats/KrbKdcReqBody.java b/ApplicationServer/src/main/java/messageformats/KrbKdcReqBody.java index da78ba2..ee367da 100644 --- a/ApplicationServer/src/main/java/messageformats/KrbKdcReqBody.java +++ b/ApplicationServer/src/main/java/messageformats/KrbKdcReqBody.java @@ -1,9 +1,5 @@ package messageformats; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import org.immutables.value.Value; - import java.io.Serializable; import java.sql.Timestamp; import java.util.Optional; diff --git a/ApplicationServer/src/main/java/messageformats/Ticket.java b/ApplicationServer/src/main/java/messageformats/Ticket.java index 8512cc0..4dbb132 100644 --- a/ApplicationServer/src/main/java/messageformats/Ticket.java +++ b/ApplicationServer/src/main/java/messageformats/Ticket.java @@ -2,8 +2,6 @@ import java.io.Serializable; -import static utils.Constants.*; - public class Ticket implements Serializable { int tktVno; PrincipalName sname; diff --git a/ApplicationServer/src/main/java/utils/Constants.java b/ApplicationServer/src/main/java/utils/Constants.java index c61b35c..2523045 100644 --- a/ApplicationServer/src/main/java/utils/Constants.java +++ b/ApplicationServer/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 AP_REPLY_MESSAGE_TYPE = 15; // Hardcoded Server PrincipalNames public static final PrincipalName AS_SERVER = new PrincipalName("as_server"); @@ -38,22 +39,4 @@ public static enum ServerType { TGS, 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(); - } diff --git a/Client/Client.iml b/Client/Client.iml new file mode 100644 index 0000000..caca054 --- /dev/null +++ b/Client/Client.iml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Client/src/main/java/Exceptions/TimestampMismatchException.java b/Client/src/main/java/Exceptions/TimestampMismatchException.java new file mode 100644 index 0000000..fdd109d --- /dev/null +++ b/Client/src/main/java/Exceptions/TimestampMismatchException.java @@ -0,0 +1,8 @@ +package Exceptions; + +public class TimestampMismatchException extends Exception { + public TimestampMismatchException(String message) { + super(message); + } + +} diff --git a/Client/src/main/java/entities/Client.java b/Client/src/main/java/entities/Client.java index 9a1beee..5dc86c0 100644 --- a/Client/src/main/java/entities/Client.java +++ b/Client/src/main/java/entities/Client.java @@ -1,6 +1,8 @@ package entities; import Exceptions.NonceDisMatchException; +import Exceptions.TimestampMismatchException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import messageformats.*; import messageformats.ImmutableKrbApRep; @@ -10,8 +12,15 @@ import utils.EncryptionData; import utils.PrivateKeyEncryptor; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; import java.net.*; import java.nio.charset.StandardCharsets; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.spec.InvalidKeySpecException; import java.sql.Timestamp; import java.util.Random; import java.util.Scanner; @@ -42,6 +51,11 @@ public class Client { private byte[] sessionKeyWithServiceServer; private int nonceROne; private int nonceRTwo; + + private Timestamp authenticationServerRequestTime; + private Timestamp ticketGrantingServerRequestTime; + private Timestamp applicationServerRequestTime; + // private PaData derEncodingOfApReqForTgsRequest; public Client(PrincipalName clientKerberosId, String loginPassword) { @@ -121,9 +135,10 @@ private void sendRequestToServerAndReceiveResponse(int serverPort, ServerType se private void constructAuthenticationServerRequest() { nonceROne = generateNonce(32); + authenticationServerRequestTime = new Timestamp(System.currentTimeMillis()); KrbKdcReqBody krbKdcReqBody = new KrbKdcReqBody(clientKerberosId, TGS_SERVER, - addDays(new Timestamp(System.currentTimeMillis()), 1), + addDays(authenticationServerRequestTime, 1), nonceROne, 1); @@ -189,13 +204,13 @@ private void constructTicketGrantingServerRequest(String applicationServerKerber ticketGrantingTicket = replyFromAs.ticket(); PrincipalName applicationServerPrincipalName = new PrincipalName(applicationServerKerberosId); - Timestamp currentTime = new Timestamp(System.currentTimeMillis()); + ticketGrantingServerRequestTime = new Timestamp(System.currentTimeMillis()); /* Create Authenticator object */ UnencryptedAuthenticator authenticatorForTgsReq = new UnencryptedAuthenticator( AUTHENTICATOR_VERSION_NUMBER, clientKerberosId, - currentTime + ticketGrantingServerRequestTime ); /* Serialize Authenticator object into JSON string */ @@ -233,7 +248,7 @@ private void constructTicketGrantingServerRequest(String applicationServerKerber KrbKdcReqBody krbKdcReqBody = new KrbKdcReqBody( clientKerberosId, applicationServerPrincipalName, - addDays(currentTime, 1), + addDays(ticketGrantingServerRequestTime, 1), nonceRTwo, 1); @@ -291,12 +306,12 @@ private void constructApplicationServerRequest() { PrincipalName applicationServerPrincipalName = new PrincipalName(applicationServerKerberosId); - Timestamp currentTime = new Timestamp(System.currentTimeMillis()); + applicationServerRequestTime = new Timestamp(System.currentTimeMillis()); UnencryptedAuthenticator authenticatorForApReq = new UnencryptedAuthenticator( AUTHENTICATOR_VERSION_NUMBER, clientKerberosId, - currentTime + applicationServerRequestTime ); ObjectMapper objectMapper = new ObjectMapper(); @@ -322,7 +337,29 @@ private void constructApplicationServerRequest() { } } - public static void main(String[] args) { + private void handleApReply() throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, InvalidKeySpecException, BadPaddingException, InvalidKeyException, JsonProcessingException, TimestampMismatchException { + /* Decrypt encrypted part of the AP reply using the session key with service server*/ + EncryptionData encryptionData = new EncryptionData( + new String(replyFromAp.encPart().getCipher(), StandardCharsets.UTF_8), + null, + replyFromAp.encPart().getIv()); + System.out.println("ciphertext_replyFromAp"+new String(replyFromAp.encPart().getCipher(), StandardCharsets.UTF_8)); + String plainText = PrivateKeyEncryptor.getDecryptionUsingSecretKey(encryptionData, sessionKeyWithServiceServer); + System.out.println(plainText); + + /* See if the Timestamp sent in AP Request is same as the Timestamp present in AP Response */ + ObjectMapper objectMapper = new ObjectMapper(); + EncApRepPart encApRepPart = objectMapper.readValue(plainText, EncApRepPart.class); + + if (encApRepPart.getCtime() == applicationServerRequestTime) { + // Kerberos Authentication Successful + System.out.println("Kerberos Authentication is Successful."); + } else { + throw new TimestampMismatchException("Timestamp received from AP Reply is mismatched from AP Request timestamp"); + } + } + + 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"); Scanner myObj = new Scanner(System.in); @@ -354,7 +391,7 @@ public static void main(String[] args) { /* AP Exchange */ client.constructApplicationServerRequest(); client.sendRequestToServerAndReceiveResponse(AP_SERVICE_PORT, ServerType.AP); -// client.handleApReply(); + client.handleApReply(); } } diff --git a/Client/src/main/java/messageformats/EncApRepPart.java b/Client/src/main/java/messageformats/EncApRepPart.java new file mode 100644 index 0000000..2fb9225 --- /dev/null +++ b/Client/src/main/java/messageformats/EncApRepPart.java @@ -0,0 +1,36 @@ +package messageformats; + +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.Optional; + +public class EncApRepPart implements Serializable { + Timestamp ctime; + // Integer cusec; + private Optional seqNumber; + + public EncApRepPart(Timestamp ctime) { + this.ctime = ctime; + } + + public EncApRepPart(Timestamp ctime, Optional seqNumber) { + this.ctime = ctime; + this.seqNumber = seqNumber; + } + + public Timestamp getCtime() { + return ctime; + } + + public void setCtime(Timestamp ctime) { + this.ctime = ctime; + } + + public Optional getSeqNumber() { + return seqNumber; + } + + public void setSeqNumber(Optional seqNumber) { + this.seqNumber = seqNumber; + } +} diff --git a/Client/src/main/java/messageformats/KrbApRep.java b/Client/src/main/java/messageformats/KrbApRep.java index 4b48713..2045eae 100644 --- a/Client/src/main/java/messageformats/KrbApRep.java +++ b/Client/src/main/java/messageformats/KrbApRep.java @@ -9,5 +9,7 @@ @JsonSerialize(as = ImmutableKrbApRep.class) @JsonDeserialize(as = ImmutableKrbApRep.class) public interface KrbApRep { - + int pvno(); + int msgType(); + EncryptedData encPart(); } diff --git a/KDC/.idea/compiler.xml b/KDC/.idea/compiler.xml index c14372a..ead71c4 100644 --- a/KDC/.idea/compiler.xml +++ b/KDC/.idea/compiler.xml @@ -10,5 +10,8 @@ + + + \ No newline at end of file From c31270a8fa15cf946839bb135d266320224b0a0a Mon Sep 17 00:00:00 2001 From: gokulsreekumar Date: Sun, 20 Mar 2022 12:23:07 +0530 Subject: [PATCH 2/4] Working Properly till AS reply (including Password checking) --- .../main/java/utils/PrivateKeyEncryptor.java | 6 +- .../java/entities/KeyDistributionCentre.java | 60 +++++++++++-------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/Client/src/main/java/utils/PrivateKeyEncryptor.java b/Client/src/main/java/utils/PrivateKeyEncryptor.java index adfd0a0..617da27 100644 --- a/Client/src/main/java/utils/PrivateKeyEncryptor.java +++ b/Client/src/main/java/utils/PrivateKeyEncryptor.java @@ -134,9 +134,9 @@ public static String getDecryptionUsingPassword(EncryptionData cipher, String pa SecretKey key = generateSecretKeyFromPassword(password, Arrays.toString(cipher.salt)); -// System.out.println(password); -// System.out.println(Arrays.toString(cipher.iv)); -// System.out.println(Arrays.toString(cipher.salt)); + System.out.println(password); + System.out.println(Arrays.toString(cipher.iv)); + System.out.println(Arrays.toString(cipher.salt)); return decrypt(SYMMETRIC_KEY_ALGORITHM, cipher.cipherText, key, new IvParameterSpec(cipher.iv)); } diff --git a/KDC/src/main/java/entities/KeyDistributionCentre.java b/KDC/src/main/java/entities/KeyDistributionCentre.java index c4b9013..e098bce 100644 --- a/KDC/src/main/java/entities/KeyDistributionCentre.java +++ b/KDC/src/main/java/entities/KeyDistributionCentre.java @@ -106,9 +106,10 @@ public void receiveClientRequestAndReply() { 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()); - constructAsReplyForClient("jessiya@123"); + 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; @@ -210,35 +211,44 @@ public void constructAsReplyForClient(String clientPassword) throws NoSuchAlgori } public void loadUserAuthData() throws IOException, CsvValidationException { - File file = new File("src/main/java/resources/ClientAuthenticationDatabase.csv"); - // Create a fileReader object - FileReader fileReader = new FileReader(file.getPath()); +// File file = new File("src/main/java/resources/ClientAuthenticationDatabase.csv"); +// // Create a fileReader object +// FileReader fileReader = new FileReader(file.getPath()); +// +// // Create a csvReader object by passing fileReader as parameter +// CSVReader csvReader = new CSVReader(fileReader); +// +// ArrayList allUserAuthData = new ArrayList<>(); +// // Reading client record line by line +// String[] nextRecord; +// while ((nextRecord = csvReader.readNext()) != null) { +// UserAuthData oneUserAuthData = new UserAuthData(); +// for (int _i = 0; _i < 2; _i++) { +// System.out.print(nextRecord[_i] + "\t"); +// if (_i == 0) { +// oneUserAuthData.setUserid(nextRecord[_i]); +// } else if (_i == 1) { +// oneUserAuthData.setPassword(nextRecord[_i]); +// } +// } +// allUserAuthData.add(oneUserAuthData); +// System.out.println(); +// } + ArrayList allUserAuthData = new ArrayList<>(); + UserAuthData jessiya = new UserAuthData("joyjes", "jessiya@123"); + UserAuthData gokul = new UserAuthData("sreekg", "gokul@123"); - // Create a csvReader object by passing fileReader as parameter - CSVReader csvReader = new CSVReader(fileReader); + allUserAuthData.add(jessiya); allUserAuthData.add(gokul); - ArrayList allUserAuthData = new ArrayList<>(); - // Reading client record line by line - String[] nextRecord; - while ((nextRecord = csvReader.readNext()) != null) { - UserAuthData oneUserAuthData = new UserAuthData(); - for (int _i = 0; _i < 2; _i++) { - System.out.print(nextRecord[_i] + "\t"); - if (_i == 0) { - oneUserAuthData.setUserid(nextRecord[_i]); - } else if (_i == 1) { - oneUserAuthData.setPassword(nextRecord[_i]); - } - } - allUserAuthData.add(oneUserAuthData); - System.out.println(); - } userAuthDatabase = allUserAuthData; } public String getClientCredentials(String clientUserid) { + System.out.println("Client User Id = " + clientUserid); for (UserAuthData user : userAuthDatabase) { - if (user.getUserid() == clientUserid) { + System.out.println("USER = " + user.getUserid()); + if (clientUserid.equals(user.getUserid())) { + System.out.println("Im here"); return user.getPassword(); } } From 126654bd6d4f5366dbbc0b84d2fe326f8230f378 Mon Sep 17 00:00:00 2001 From: gokulsreekumar Date: Thu, 24 Mar 2022 12:18:42 +0530 Subject: [PATCH 3/4] Working Authentication Flow --- .../src/main/java/entities/ApplicationServer.java | 2 +- .../src/main/java/messageformats/EncTicketPart.java | 4 ++++ Client/src/main/java/entities/Client.java | 10 +++++----- Client/src/main/java/messageformats/EncApRepPart.java | 4 ++++ KDC/src/main/java/entities/KeyDistributionCentre.java | 3 ++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ApplicationServer/src/main/java/entities/ApplicationServer.java b/ApplicationServer/src/main/java/entities/ApplicationServer.java index 3d45657..e25dc3f 100644 --- a/ApplicationServer/src/main/java/entities/ApplicationServer.java +++ b/ApplicationServer/src/main/java/entities/ApplicationServer.java @@ -106,7 +106,7 @@ private void doClientAuthentication() { throw new IncorrectAuthenticatorException("Timestamp in client authenticator is not recent"); } String cNameInAuthenticator = unencryptedAuthenticator.getCname().getNameString(); - if (! unencryptedTicket.getCname().equals(cNameInAuthenticator)) { + if (! unencryptedTicket.getCname().getNameString().equals(cNameInAuthenticator)) { throw new IncorrectAuthenticatorException("Client name is incorrect"); } } catch (Exception e) { diff --git a/ApplicationServer/src/main/java/messageformats/EncTicketPart.java b/ApplicationServer/src/main/java/messageformats/EncTicketPart.java index 502f62c..859ced4 100644 --- a/ApplicationServer/src/main/java/messageformats/EncTicketPart.java +++ b/ApplicationServer/src/main/java/messageformats/EncTicketPart.java @@ -11,6 +11,10 @@ public class EncTicketPart { Timestamp endTime; Optional renewTill; + // For serialization + public EncTicketPart() { + } + public EncTicketPart(EncryptionKey key, PrincipalName cname, Timestamp authTime, Optional startTime, Timestamp endTime, Optional renewTill) { this.key = key; this.cname = cname; diff --git a/Client/src/main/java/entities/Client.java b/Client/src/main/java/entities/Client.java index 5dc86c0..a83a74d 100644 --- a/Client/src/main/java/entities/Client.java +++ b/Client/src/main/java/entities/Client.java @@ -269,10 +269,10 @@ private void handleTgsReply() { try { /* Decrypt encrypted part of the TGS reply */ EncryptionData encryptionData = new EncryptionData( - new String(replyFromAs.encPart().getCipher(), StandardCharsets.UTF_8), + new String(replyFromTgs.encPart().getCipher(), StandardCharsets.UTF_8), null, - replyFromAs.encPart().getIv()); - System.out.println("ciphertext"+new String(replyFromAs.encPart().getCipher(), StandardCharsets.UTF_8)); + replyFromTgs.encPart().getIv()); + System.out.println("ciphertext"+new String(replyFromTgs.encPart().getCipher(), StandardCharsets.UTF_8)); String plainText = PrivateKeyEncryptor.getDecryptionUsingSecretKey(encryptionData, sessionKeyWithTgs); System.out.println(plainText); @@ -302,7 +302,7 @@ private void handleTgsReply() { private void constructApplicationServerRequest() { try { - serviceGrantingTicket = replyFromAs.ticket(); + serviceGrantingTicket = replyFromTgs.ticket(); PrincipalName applicationServerPrincipalName = new PrincipalName(applicationServerKerberosId); @@ -351,7 +351,7 @@ private void handleApReply() throws InvalidAlgorithmParameterException, NoSuchPa ObjectMapper objectMapper = new ObjectMapper(); EncApRepPart encApRepPart = objectMapper.readValue(plainText, EncApRepPart.class); - if (encApRepPart.getCtime() == applicationServerRequestTime) { + if (encApRepPart.getCtime().equals(applicationServerRequestTime)) { // Kerberos Authentication Successful System.out.println("Kerberos Authentication is Successful."); } else { diff --git a/Client/src/main/java/messageformats/EncApRepPart.java b/Client/src/main/java/messageformats/EncApRepPart.java index 2fb9225..ef8adb6 100644 --- a/Client/src/main/java/messageformats/EncApRepPart.java +++ b/Client/src/main/java/messageformats/EncApRepPart.java @@ -9,6 +9,10 @@ public class EncApRepPart implements Serializable { // Integer cusec; private Optional seqNumber; + public EncApRepPart() { + + } + public EncApRepPart(Timestamp ctime) { this.ctime = ctime; } diff --git a/KDC/src/main/java/entities/KeyDistributionCentre.java b/KDC/src/main/java/entities/KeyDistributionCentre.java index e098bce..96444d6 100644 --- a/KDC/src/main/java/entities/KeyDistributionCentre.java +++ b/KDC/src/main/java/entities/KeyDistributionCentre.java @@ -311,7 +311,7 @@ private void doClientAuthenticationFromTgsRequest() { throw new IncorrectAuthenticatorException("Timestamp in client authenticator is not recent"); } String cNameInAuthenticator = unencryptedAuthenticatorFromTgsReq.getCname().getNameString(); - if (! unencryptedTicketFromTgsReq.getCname().equals(cNameInAuthenticator)) { + if (! unencryptedTicketFromTgsReq.getCname().getNameString().equals(cNameInAuthenticator)) { throw new IncorrectAuthenticatorException("Client name is incorrect"); } @@ -373,6 +373,7 @@ public void constructTgsReplyForClient() throws NoSuchAlgorithmException, JsonPr new EncryptedData( 1, KERBEROS_VERSION_NUMBER, + encryptionDataForTicket.getIv(), encryptionDataForTicket.getCipherText().getBytes(StandardCharsets.UTF_8))); PaData[] paData = new PaData[0]; From 5e72137e65e354dfc876682b97540e7ed910b0ff Mon Sep 17 00:00:00 2001 From: gokulsreekumar Date: Thu, 24 Mar 2022 18:27:16 +0530 Subject: [PATCH 4/4] AddeError Check --- .../src/main/java/utils/Constants.java | 1 + Client/src/main/java/entities/Client.java | 100 +++- .../main/java/messageformats/KrbError.java | 23 + .../main/java/messageformats/KrbMessage.java | 16 + Client/src/main/java/utils/Constants.java | 18 +- .../java/entities/KeyDistributionCentre.java | 157 ++++-- .../main/java/messageformats/KrbApReq.java | 1 - .../main/java/messageformats/KrbError.java | 23 + .../main/java/messageformats/KrbKdcReq.java | 2 - .../main/java/messageformats/KrbMessage.java | 16 + KDC/src/main/java/utils/Constants.java | 20 +- .../messageformats/ImmutableKrbApRep.java | 144 ----- .../messageformats/ImmutableKrbApReq.java | 376 -------------- .../messageformats/ImmutableKrbKdcRep.java | 490 ------------------ .../messageformats/ImmutableKrbKdcReq.java | 376 -------------- 15 files changed, 270 insertions(+), 1493 deletions(-) create mode 100644 Client/src/main/java/messageformats/KrbError.java create mode 100644 Client/src/main/java/messageformats/KrbMessage.java create mode 100644 KDC/src/main/java/messageformats/KrbError.java create mode 100644 KDC/src/main/java/messageformats/KrbMessage.java delete mode 100644 KDC/target/generated-sources/annotations/messageformats/ImmutableKrbApRep.java delete mode 100644 KDC/target/generated-sources/annotations/messageformats/ImmutableKrbApReq.java delete mode 100644 KDC/target/generated-sources/annotations/messageformats/ImmutableKrbKdcRep.java delete mode 100644 KDC/target/generated-sources/annotations/messageformats/ImmutableKrbKdcReq.java 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..e9c6801 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,49 +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; + /* 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); } - /* 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); - } catch (Exception e) { e.printStackTrace(); /* Close the socket connection */ @@ -210,6 +249,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 @@ -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; - } - } -}