Skip to content

Commit

Permalink
[CBRD-23637] Changing the method of sending magicString for SSL (#2339)
Browse files Browse the repository at this point in the history
* [CBRD-23637] Changing the method of sending magicString for SSL
Add driverInfossl for SSL

* [CBRD-23637] Fix indentation
  • Loading branch information
airnet73 authored May 28, 2020
1 parent 984ef17 commit de852d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/jdbc/cubrid/jdbc/driver/CUBRIDDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ public Connection connect(String url, Properties info) throws SQLException {
u_con.setCharset(connProperties.getCharSet());
u_con.setZeroDateTimeBehavior(connProperties.getZeroDateTimeBehavior());
u_con.setResultWithCUBRIDTypes(connProperties.getResultWithCUBRIDTypes());
u_con.setDriverMagicStr(connProperties.getUseSSL());
u_con.setConnectionProperties(connProperties);
u_con.tryConnect();
return new CUBRIDConnection(u_con, url, user);
Expand Down
19 changes: 11 additions & 8 deletions src/jdbc/cubrid/jdbc/jci/UConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public class UConnection {
private boolean isAutoCommitBySelf = false;

public static byte[] driverInfo;
public static byte[] driverInfossl;

private ConnectionProperties connectionProperties = new ConnectionProperties();
private long lastFailureTime = 0;
Expand All @@ -240,6 +241,16 @@ public class UConnection {
driverInfo[9] = 0; // reserved
}

static {
driverInfossl = new byte[10];
UJCIUtil.copy_bytes(driverInfossl, 0, 5, magicStringSSL);
driverInfossl[5] = CAS_CLIENT_JDBC;
driverInfossl[6] = CAS_PROTO_INDICATOR | CAS_PROTOCOL_VERSION;
driverInfossl[7] = CAS_RENEWED_ERROR_CODE | CAS_SUPPORT_HOLDABLE_RESULT;
driverInfossl[8] = 0; // reserved
driverInfossl[9] = 0; // reserved
}

private int lastShardId = UShardInfo.SHARD_ID_INVALID;

private int numShard = 0;
Expand Down Expand Up @@ -2494,12 +2505,4 @@ synchronized public UShardInfo getShardInfo(int shard_id) {

return shardInfo[shard_id];
}

public void setDriverMagicStr(boolean useSSL) {
if (useSSL == true) {
UJCIUtil.copy_bytes(driverInfo, 0, 5, magicStringSSL);
} else {
UJCIUtil.copy_bytes(driverInfo, 0, 5, magicString);
}
}
}
8 changes: 7 additions & 1 deletion src/jdbc/cubrid/jdbc/net/BrokerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ public static Socket connectBroker(String ip, int port, boolean useSSL, int time
toBroker.setKeepAlive(true);
in = new UTimedDataInputStream(toBroker.getInputStream(), ip, port, timeout);
out = new DataOutputStream(toBroker.getOutputStream());
out.write(UConnection.driverInfo);

if (useSSL == true) {
out.write(UConnection.driverInfossl);
} else {
out.write(UConnection.driverInfo);
}

out.flush();
int code = in.readInt();
if (code < 0) {
Expand Down

0 comments on commit de852d6

Please sign in to comment.