| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.security.keystore2; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.security.KeyStoreSecurityLevel; |
| 21 |
import android.security.keystore.ArrayUtils; |
| 22 |
import android.system.keystore2.KeyDescriptor; |
| 23 |
import android.system.keystore2.KeyMetadata; |
| 24 |
|
| 25 |
import java.security.PublicKey; |
| 26 |
import java.util.Arrays; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public abstract class AndroidKeyStorePublicKey extends AndroidKeyStoreKey implements PublicKey { |
| 34 |
private final byte[] mCertificate; |
| 35 |
private final byte[] mCertificateChain; |
| 36 |
private final byte[] mEncoded; |
| 37 |
|
| 38 |
public AndroidKeyStorePublicKey(@NonNull KeyDescriptor descriptor, |
| 39 |
@NonNull KeyMetadata metadata, @NonNull byte[] x509EncodedForm, |
| 40 |
@NonNull String algorithm, @NonNull KeyStoreSecurityLevel securityLevel) { |
| 41 |
super(descriptor, metadata.key.nspace, metadata.authorizations, algorithm, securityLevel); |
| 42 |
mCertificate = metadata.certificate; |
| 43 |
mCertificateChain = metadata.certificateChain; |
| 44 |
mEncoded = x509EncodedForm; |
| 45 |
} |
| 46 |
|
| 47 |
abstract AndroidKeyStorePrivateKey getPrivateKey(); |
| 48 |
|
| 49 |
@Override |
| 50 |
public String getFormat() { |
| 51 |
return "X.509"; |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public byte[] getEncoded() { |
| 56 |
return ArrayUtils.cloneIfNotEmpty(mEncoded); |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
public int hashCode() { |
| 61 |
final int prime = 31; |
| 62 |
int result = 1; |
| 63 |
|
| 64 |
result = prime * result + super.hashCode(); |
| 65 |
result = prime * result + Arrays.hashCode(mCertificate); |
| 66 |
result = prime * result + Arrays.hashCode(mCertificateChain); |
| 67 |
|
| 68 |
return result; |
| 69 |
} |
| 70 |
|
| 71 |
@Override |
| 72 |
public boolean equals(Object obj) { |
| 73 |
if (this == obj) { |
| 74 |
return true; |
| 75 |
} |
| 76 |
if (!super.equals(obj)) { |
| 77 |
return false; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
final AndroidKeyStorePublicKey other = (AndroidKeyStorePublicKey) obj; |
| 85 |
|
| 86 |
return Arrays.equals(mCertificate, other.mCertificate) && Arrays.equals(mCertificateChain, |
| 87 |
other.mCertificateChain); |
| 88 |
} |
| 89 |
} |