Author: erodriguez
Date: Mon Oct 11 18:56:32 2004
New Revision: 54639

Added:
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/Checksum.java
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/EncryptedData.java
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/EncryptedTimeStamp.java
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/EncryptionKey.java
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/KerberosTime.java
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/TransitedEncoding.java
Log:
Some immutable values.

Added: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/Checksum.java
==============================================================================
--- (empty file)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/Checksum.java
     Mon Oct 11 18:56:32 2004
@@ -0,0 +1,51 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.kerberos.messages.value;
+
+import org.apache.kerberos.crypto.checksum.*;
+
+import java.util.*;
+
+public class Checksum {
+
+       private ChecksumType _checksumType;
+       private byte[] _checksum;
+       
+       public Checksum(ChecksumType cksumType, byte[] checksum) {
+               _checksumType = cksumType;
+               _checksum     = checksum;
+       }
+       
+       public boolean equals(Object o) {
+               if (this == o)
+                       return true;
+               if (!(o instanceof Checksum))
+                       return false;
+
+               Checksum that = (Checksum) o;
+               return (this._checksumType == that._checksumType)
+                               && (Arrays.equals(this._checksum, 
that._checksum));
+       }
+       
+       public byte[] getChecksumValue() {
+               return _checksum;
+       }
+       public ChecksumType getChecksumType() {
+               return _checksumType;
+       }
+}
+

Added: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/EncryptedData.java
==============================================================================
--- (empty file)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/EncryptedData.java
        Mon Oct 11 18:56:32 2004
@@ -0,0 +1,64 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.kerberos.messages.value;
+
+import org.apache.kerberos.crypto.encryption.*;
+
+public class EncryptedData {
+
+       private EncryptionType _encryptionType;
+       private int            _keyVersion;     //optional
+       private byte[]         _cipherText;
+       
+       public EncryptedData() {
+               // TODO - temp
+       }
+       
+       public EncryptedData(EncryptionType eType, byte[] cipher) {
+               _encryptionType = eType;
+               _cipherText     = cipher;
+       }
+       
+       public EncryptedData(EncryptionType eType, int kvno, byte[] cipher) {
+               _encryptionType = eType;
+               _keyVersion     = kvno;
+               _cipherText     = cipher;
+       }
+       
+       // getters
+       public EncryptionType getEncryptionType() {
+               return _encryptionType;
+       }
+       public int getKeyVersion() {
+               return _keyVersion;
+       }
+       public byte[] getCipherText() {
+               return _cipherText;
+       }
+       
+       // setters
+       public void setCipherText(byte[] text) {
+               _cipherText = text;
+       }
+       public void setEncryptionType(EncryptionType type) {
+               _encryptionType = type;
+       }
+       public void setKeyVersion(int version) {
+               _keyVersion = version;
+       }
+}
+

Added: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/EncryptedTimeStamp.java
==============================================================================
--- (empty file)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/EncryptedTimeStamp.java
   Mon Oct 11 18:56:32 2004
@@ -0,0 +1,39 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.kerberos.messages.value;
+
+/**
+ * Pre-authentication encrypted timestamp
+ */
+public class EncryptedTimeStamp {
+       private KerberosTime _timeStamp;
+       private int          _microSeconds; //optional
+
+       public EncryptedTimeStamp(KerberosTime timeStamp, int microSeconds) {
+               _timeStamp = timeStamp;
+               _microSeconds = microSeconds;
+       }
+
+       public KerberosTime getTimeStamp() {
+               return _timeStamp;
+       }
+       
+       public int getMicroSeconds() {
+               return _microSeconds;
+       }
+}
+

Added: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/EncryptionKey.java
==============================================================================
--- (empty file)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/EncryptionKey.java
        Mon Oct 11 18:56:32 2004
@@ -0,0 +1,69 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.kerberos.messages.value;
+
+import org.apache.kerberos.crypto.encryption.*;
+
+public class EncryptionKey {
+       public static final int KEYTYPE_NULL = 0;
+       public static final int KEYTYPE_DES  = 1;
+       
+       private EncryptionType _keyType;
+       private byte[]         _keyValue;
+       private int            _keyVersion;
+       
+       public EncryptionKey(EncryptionType keyType, byte[] keyValue) {
+               _keyType    = keyType;
+               _keyValue   = keyValue;
+       }
+       
+       public EncryptionKey(EncryptionType keyType, byte[] keyValue, int 
keyVersion) {
+               _keyType    = keyType;
+               _keyValue   = keyValue;
+               /**
+                * keyVersion is sent over the wire as part of EncryptedData 
but makes more sense
+                * in the domain model to have here as part of the key itself.  
Therefore, the
+                * keyVersion should only be constructor-injected when 
EncryptionKey's are
+                * retrieved from persisted storage.
+                * 
+                * TODO - keyVersion may move into persisted user configuration
+                */
+               _keyVersion = keyVersion;
+       }
+
+       public synchronized void destroy() {
+               if (_keyValue != null)
+                       for (int i = 0; i < _keyValue.length; i++)
+                               _keyValue[i] = 0;
+       }
+       
+       public String toString() {
+               return _keyType.toString() + " (" + _keyType.getOrdinal() + ")";
+       }
+
+       public EncryptionType getKeyType() {
+               return _keyType;
+       }
+       public byte[] getKeyValue() {
+               return _keyValue;
+       }
+       
+       public int getKeyVersion() {
+               return _keyVersion;
+       }
+}
+

Added: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/KerberosTime.java
==============================================================================
--- (empty file)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/KerberosTime.java
 Mon Oct 11 18:56:32 2004
@@ -0,0 +1,101 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.kerberos.messages.value;
+
+import org.apache.kerberos.kdc.*;
+
+import java.util.*;
+
+/**
+ * Implementation of the time object for Kerberos
+ */
+public class KerberosTime implements Comparable {
+       
+       public static final KerberosTime INFINITY = new 
KerberosTime(Long.MAX_VALUE);
+       
+       private long _localTime;
+
+       public KerberosTime() {
+               Date temp = new Date();
+               _localTime = temp.getTime();
+       }
+
+       public KerberosTime(long time) {
+               _localTime = time;
+       }
+
+       public KerberosTime(Date time) {
+               _localTime = time.getTime();
+       }
+
+       public int compareTo(Object o) {
+               final int BEFORE = -1;
+               final int EQUAL  = 0;
+               final int AFTER  = 1;
+
+               // this optimization is usually worthwhile, and can always be 
added
+               if (this == o)
+                       return EQUAL;
+
+               // Performing explicit checks for nullity and type are made 
redundant by
+               // the following cast, which will throw NullPointerException and
+               // ClassCastException in these respective cases.
+               final KerberosTime that = (KerberosTime) o;
+
+               // primitive numbers follow this form
+               if (this._localTime < that._localTime)
+                       return BEFORE;
+               if (this._localTime > that._localTime)
+                       return AFTER;
+               
+               return EQUAL;
+       }
+
+       public long getTime() {
+               return _localTime;
+       }
+
+       public Date toDate() {
+               return new Date(_localTime);
+       }
+
+       public boolean isInClockSkew(long clockSkew) {
+               KerberosTime now = new KerberosTime();
+               return Math.abs(_localTime - now._localTime) < clockSkew;
+       }
+
+       public boolean isInClockSkew() {
+               return isInClockSkew(LocalConfig.KDC_ALLOWABLE_CLOCKSKEW);
+       }
+
+       public boolean greaterThan(KerberosTime time) {
+               return _localTime > time._localTime;
+       }
+       
+       public boolean lessThan(KerberosTime time) {
+               return _localTime < time._localTime;
+       }
+
+       public boolean equals(KerberosTime time) {
+               return _localTime == time._localTime;
+       }
+
+       public boolean isZero() {
+               return _localTime == 0;
+       }
+}
+

Added: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/TransitedEncoding.java
==============================================================================
--- (empty file)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/TransitedEncoding.java
    Mon Oct 11 18:56:32 2004
@@ -0,0 +1,41 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.kerberos.messages.value;
+
+public class TransitedEncoding {
+       
+       private int    _type;
+       private byte[] _contents;
+       
+       public TransitedEncoding() {
+               _type = 0;
+               _contents = new byte[0];
+       }
+       
+       public TransitedEncoding(int type, byte[] contents) {
+               _type = type;
+               _contents = contents;
+       }
+       
+       public byte[] getContents() {
+               return _contents;
+       }
+       public int getType() {
+               return _type;
+       }
+}
+

Reply via email to