directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject directory-kerby git commit: DIRKRB-642 Remove the bytes util functions in GssTokenBase. Contributed by Lin Zeng.
Date Fri, 04 Aug 2017 06:11:40 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/trunk 8053f03aa -> 358c37296


DIRKRB-642 Remove the bytes util functions in GssTokenBase. Contributed by Lin Zeng.


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/358c3729
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/358c3729
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/358c3729

Branch: refs/heads/trunk
Commit: 358c372960903e5b979402e1ce76d45e547bb017
Parents: 8053f03
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Fri Aug 4 14:11:33 2017 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Fri Aug 4 14:11:33 2017 +0800

----------------------------------------------------------------------
 .../kerberos/kerb/gss/impl/GssTokenBase.java    | 31 --------------------
 .../kerberos/kerb/gss/impl/GssTokenV1.java      |  9 ++----
 .../kerberos/kerb/gss/impl/GssTokenV2.java      | 10 +++----
 3 files changed, 8 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/358c3729/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenBase.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenBase.java
b/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenBase.java
index ec66aa5..c629209 100644
--- a/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenBase.java
+++ b/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenBase.java
@@ -25,35 +25,4 @@ public abstract class GssTokenBase {
     public static final int TOKEN_MIC_V1 = 0x101;
     public static final int TOKEN_WRAP_V2 = 0x504;
     public static final int TOKEN_MIC_V2 = 0x404;
-
-    public void writeBigEndian(byte[] buf, int offset, int value) {
-        buf[offset] = (byte) (value >>> 24);
-        buf[offset + 1] = (byte) (value >>> 16);
-        buf[offset + 2] = (byte) (value >>> 8);
-        buf[offset + 3] = (byte) (value);
-    }
-
-    public int readBigEndian(byte[] buf, int offset) {
-        int value = 0;
-        value += (buf[offset] & 0xFF) << 24;
-        value += (buf[offset + 1] & 0xFF) << 16;
-        value += (buf[offset + 2] & 0xFF) << 8;
-        value += buf[offset + 3] & 0xFF;
-        return value;
-    }
-
-    /**
-     *
-     * @param buf
-     * @param offset
-     * @param len should not be larger than sizeof(int)
-     * @return
-     */
-    public int readBigEndian(byte[] buf, int offset, int len) {
-        int value = 0;
-        for (int i = 0; i < len; i++) {
-            value += (buf[offset + i] & 0xFF) << 8;
-        }
-        return value;
-    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/358c3729/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenV1.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenV1.java
b/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenV1.java
index 1f063c3..715301f 100644
--- a/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenV1.java
+++ b/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenV1.java
@@ -19,9 +19,9 @@
  */
 package org.apache.kerby.kerberos.kerb.gss.impl;
 
-
 import org.ietf.jgss.GSSException;
 import org.ietf.jgss.MessageProp;
+import org.apache.kerby.kerberos.kerb.crypto.util.BytesUtil;
 import sun.security.jgss.GSSHeader;
 import sun.security.util.ObjectIdentifier;
 
@@ -219,12 +219,9 @@ abstract class GssTokenV1 extends GssTokenBase {
     private void encryptSequenceNumber() throws GSSException {
         plainSequenceBytes = new byte[8];
         if (encryptor.isArcFourHmac()) {
-            writeBigEndian(plainSequenceBytes, 0, sequenceNumber);
+            BytesUtil.int2bytes(sequenceNumber, plainSequenceBytes, 0, true);
         } else {
-            plainSequenceBytes[0] = (byte) sequenceNumber;
-            plainSequenceBytes[1] = (byte) (sequenceNumber >>> 8);
-            plainSequenceBytes[2] = (byte) (sequenceNumber >>> 16);
-            plainSequenceBytes[3] = (byte) (sequenceNumber >>> 24);
+            BytesUtil.int2bytes(sequenceNumber, plainSequenceBytes, 0, false);
         }
 
         // Hex 0 - sender is the context initiator, Hex FF - sender is the context acceptor

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/358c3729/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenV2.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenV2.java
b/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenV2.java
index 5220900..9c381ec 100644
--- a/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenV2.java
+++ b/kerby-kerb/kerb-gssapi/src/main/java/org/apache/kerby/kerberos/kerb/gss/impl/GssTokenV2.java
@@ -21,6 +21,7 @@ package org.apache.kerby.kerberos.kerb.gss.impl;
 
 import org.ietf.jgss.GSSException;
 import org.ietf.jgss.MessageProp;
+import org.apache.kerby.kerberos.kerb.crypto.util.BytesUtil;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -221,7 +222,7 @@ abstract class GssTokenV2 extends GssTokenBase {
             header[6] = (byte) 0xFF;
             header[7] = (byte) 0xFF;
         }
-        writeBigEndian(header, 12, sequenceNumber);
+        BytesUtil.int2bytes(sequenceNumber, header, 12, true);
     }
 
     // Reconstruct a token header
@@ -253,9 +254,8 @@ abstract class GssTokenV2 extends GssTokenBase {
                 if (header[3] != (byte) 0xFF) {
                     throw new GSSException(GSSException.DEFECTIVE_TOKEN, -1, "Invalid token
filler");
                 }
-
-                ec = readBigEndian(header, OFFSET_EC, 2);
-                rrc = readBigEndian(header, OFFSET_RRC, 2);
+                ec = BytesUtil.bytes2short(header, OFFSET_EC, true);
+                rrc = BytesUtil.bytes2short(header, OFFSET_RRC, true);
             } else if (tokenType == TOKEN_MIC_V2) {
                 for (int i = 3; i < 8; i++) {
                     if ((header[i] & 0xFF) != 0xFF) {
@@ -265,7 +265,7 @@ abstract class GssTokenV2 extends GssTokenBase {
             }
 
             prop.setQOP(0);
-            sequenceNumber = readBigEndian(header, 0, 8);
+            sequenceNumber = (int) BytesUtil.bytes2long(header, 0, true);
         } catch (IOException e) {
             throw new GSSException(GSSException.FAILURE, -1, "Phrase token header failed");
         }


Mime
View raw message