| 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.system.keystore2.Authorization; |
| 22 |
import android.system.keystore2.Domain; |
| 23 |
import android.system.keystore2.KeyDescriptor; |
| 24 |
|
| 25 |
import com.android.internal.annotations.VisibleForTesting; |
| 26 |
|
| 27 |
import java.security.Key; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public class AndroidKeyStoreKey implements Key { |
| 35 |
|
| 36 |
|
| 37 |
private final KeyDescriptor mDescriptor; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
private final long mKeyId; |
| 43 |
private final Authorization[] mAuthorizations; |
| 44 |
|
| 45 |
private final String mAlgorithm; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
private final KeyStoreSecurityLevel mSecurityLevel; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
@VisibleForTesting |
| 55 |
public AndroidKeyStoreKey(@NonNull KeyDescriptor descriptor, |
| 56 |
long keyId, |
| 57 |
@NonNull Authorization[] authorizations, |
| 58 |
@NonNull String algorithm, |
| 59 |
@NonNull KeyStoreSecurityLevel securityLevel) { |
| 60 |
mDescriptor = descriptor; |
| 61 |
mKeyId = keyId; |
| 62 |
mAuthorizations = authorizations; |
| 63 |
mAlgorithm = algorithm; |
| 64 |
mSecurityLevel = securityLevel; |
| 65 |
} |
| 66 |
|
| 67 |
KeyDescriptor getUserKeyDescriptor() { |
| 68 |
return mDescriptor; |
| 69 |
} |
| 70 |
|
| 71 |
KeyDescriptor getKeyIdDescriptor() { |
| 72 |
KeyDescriptor descriptor = new KeyDescriptor(); |
| 73 |
descriptor.nspace = mKeyId; |
| 74 |
descriptor.domain = Domain.KEY_ID; |
| 75 |
descriptor.alias = null; |
| 76 |
descriptor.blob = null; |
| 77 |
return descriptor; |
| 78 |
} |
| 79 |
|
| 80 |
Authorization[] getAuthorizations() { |
| 81 |
return mAuthorizations; |
| 82 |
} |
| 83 |
|
| 84 |
KeyStoreSecurityLevel getSecurityLevel() { |
| 85 |
return mSecurityLevel; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
@Override |
| 90 |
public String getAlgorithm() { |
| 91 |
return mAlgorithm; |
| 92 |
} |
| 93 |
|
| 94 |
@Override |
| 95 |
public String getFormat() { |
| 96 |
|
| 97 |
return null; |
| 98 |
} |
| 99 |
|
| 100 |
@Override |
| 101 |
public byte[] getEncoded() { |
| 102 |
|
| 103 |
return null; |
| 104 |
} |
| 105 |
|
| 106 |
@Override |
| 107 |
public int hashCode() { |
| 108 |
final int prime = 31; |
| 109 |
int result = 1; |
| 110 |
|
| 111 |
result = prime * result + getClass().hashCode(); |
| 112 |
result = prime * result + (int) (mKeyId >>> 32); |
| 113 |
result = prime * result + (int) (mKeyId & 0xffffffff); |
| 114 |
return result; |
| 115 |
} |
| 116 |
|
| 117 |
@Override |
| 118 |
public boolean equals(Object obj) { |
| 119 |
if (this == obj) { |
| 120 |
return true; |
| 121 |
} |
| 122 |
if (obj == null) { |
| 123 |
return false; |
| 124 |
} |
| 125 |
if (getClass() != obj.getClass()) { |
| 126 |
return false; |
| 127 |
} |
| 128 |
AndroidKeyStoreKey other = (AndroidKeyStoreKey) obj; |
| 129 |
return mKeyId == other.mKeyId; |
| 130 |
} |
| 131 |
} |