Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11907. OzoneSecretKey does not need to implement Writable #7574

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
package org.apache.hadoop.hdds.security;

import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString;
import java.io.ByteArrayInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.IOException;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
Expand All @@ -32,16 +26,14 @@
import org.apache.hadoop.hdds.annotation.InterfaceStability;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.security.x509.keys.SecurityUtil;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.SecretKeyProto;

/**
* Wrapper class for Ozone/Hdds secret keys. Used in delegation tokens and block
* tokens.
*/
@InterfaceAudience.Private
@InterfaceStability.Unstable
public class OzoneSecretKey implements Writable {
public class OzoneSecretKey {

private int keyId;
private long expiryDate;
Expand Down Expand Up @@ -107,28 +99,6 @@ public void setExpiryDate(long expiryDate) {
this.expiryDate = expiryDate;
}

@Override
public void write(DataOutput out) throws IOException {
SecretKeyProto token = SecretKeyProto.newBuilder()
.setKeyId(getKeyId())
.setExpiryDate(getExpiryDate())
.setPrivateKeyBytes(ByteString.copyFrom(getEncodedPrivateKey()))
.setPublicKeyBytes(ByteString.copyFrom(getEncodedPubliceKey()))
.build();
out.write(token.toByteArray());
}

@Override
public void readFields(DataInput in) throws IOException {
SecretKeyProto secretKey = SecretKeyProto.parseFrom((DataInputStream) in);
expiryDate = secretKey.getExpiryDate();
keyId = secretKey.getKeyId();
privateKey = SecurityUtil.getPrivateKey(secretKey.getPrivateKeyBytes()
.toByteArray(), securityConfig);
publicKey = SecurityUtil.getPublicKey(secretKey.getPublicKeyBytes()
.toByteArray(), securityConfig);
}

@Override
public int hashCode() {
HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(537, 963);
Expand Down Expand Up @@ -158,25 +128,4 @@ public boolean equals(Object obj) {
return false;
}

/**
* Reads protobuf encoded input stream to construct {@link OzoneSecretKey}.
*/
static OzoneSecretKey readProtoBuf(DataInput in) throws IOException {
Preconditions.checkNotNull(in);
SecretKeyProto key = SecretKeyProto.parseFrom((DataInputStream) in);
return new OzoneSecretKey(key.getKeyId(), key.getExpiryDate(),
key.getPrivateKeyBytes().toByteArray(),
key.getPublicKeyBytes().toByteArray());
}

/**
* Reads protobuf encoded input stream to construct {@link OzoneSecretKey}.
*/
static OzoneSecretKey readProtoBuf(byte[] identifier) throws IOException {
Preconditions.checkNotNull(identifier);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(
identifier));
return readProtoBuf(in);
}

}
Loading