Skip to content

Commit d0d0b69

Browse files
committed
added missing zeroed out logic
1 parent 538b901 commit d0d0b69

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

java-spanner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/omni/LoginClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public AccessToken login(String username, SecretBytes password) throws SpannerEx
129129
initialResponse.getOpaqueResponse().getInitialResponse();
130130

131131
ByteString envelope = initialOpaqueResponse.getMaskedResponse();
132-
if (envelope.size() < 65) {
132+
if (envelope.size() != 65) {
133133
throw new GeneralSecurityException("Invalid envelope size: " + envelope.size());
134134
}
135135

@@ -233,7 +233,7 @@ private byte[] generateClientMac(
233233
OpaqueUtil.xorBytes(
234234
initialOpaqueResponse.getMaskedResponse().toByteArray(), credentialResponsePad);
235235
ByteString envelope = ByteString.copyFrom(serializedEnvelope);
236-
if (envelope.size() < 65) {
236+
if (envelope.size() != 65) {
237237
throw new GeneralSecurityException("Invalid envelope size: " + envelope.size());
238238
}
239239
ByteString serverPublicKey = envelope.substring(0, 33);

java-spanner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/omni/SpannerOmniCredentials.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,22 @@ public class SpannerOmniCredentials extends GoogleCredentials {
5050

5151
public static SecretBytes convertToSecretBytes(char[] passwordChars) {
5252
byte[] passwordBytes = null;
53+
ByteBuffer byteBuffer = null;
5354
try {
5455
CharsetEncoder encoder = StandardCharsets.UTF_8.newEncoder();
5556
CharBuffer charBuffer = CharBuffer.wrap(passwordChars);
56-
ByteBuffer byteBuffer =
57-
ByteBuffer.allocate((int) (encoder.maxBytesPerChar() * charBuffer.remaining()));
57+
byteBuffer = ByteBuffer.allocate((int) (encoder.maxBytesPerChar() * charBuffer.remaining()));
5858
encoder.encode(charBuffer, byteBuffer, true);
5959
encoder.flush(byteBuffer);
6060
byteBuffer.flip();
6161
passwordBytes = new byte[byteBuffer.remaining()];
6262
byteBuffer.get(passwordBytes);
63-
Arrays.fill(byteBuffer.array(), (byte) 0);
6463
return SecretBytes.copyFrom(
6564
passwordBytes, com.google.crypto.tink.InsecureSecretKeyAccess.get());
6665
} finally {
66+
if (byteBuffer != null) {
67+
Arrays.fill(byteBuffer.array(), (byte) 0);
68+
}
6769
if (passwordBytes != null) {
6870
Arrays.fill(passwordBytes, (byte) 0);
6971
}

java-spanner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/testing/SpannerOmniHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void setSpannerOmniOptions(SpannerOptions.Builder builder) {
7373
builder.setType(SpannerOptions.InstanceType.OMNI);
7474
String username = System.getProperty(USERNAME, "");
7575
String password = System.getProperty(PASSWORD, "");
76-
if (!Strings.isNullOrEmpty(username)) {
76+
if (!Strings.isNullOrEmpty(username) && !Strings.isNullOrEmpty(password)) {
7777
builder.login(username, password.toCharArray());
7878
}
7979
if (usePlainText) {

0 commit comments

Comments
 (0)