Package com.android.identity
Class MobileSecurityObjectGenerator
- java.lang.Object
-
- com.android.identity.MobileSecurityObjectGenerator
-
public class MobileSecurityObjectGenerator extends java.lang.Object
Helper class for buildingMobileSecurityObject
CBOR as specified ISO/IEC 18013-5 section 9.1.2 Issuer data authentication.
-
-
Constructor Summary
Constructors Constructor Description MobileSecurityObjectGenerator(java.lang.String digestAlgorithm, java.lang.String docType, java.security.PublicKey deviceKey)
Constructs a newMobileSecurityObjectGenerator
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MobileSecurityObjectGenerator
addDigestIdsForNamespace(java.lang.String nameSpace, java.util.Map<java.lang.Long,byte[]> digestIDs)
Populates theValueDigests
mapping.byte[]
generate()
Builds theMobileSecurityObject
CBOR.MobileSecurityObjectGenerator
setDeviceKeyAuthorizedDataElements(java.util.Map<java.lang.String,java.util.List<java.lang.String>> authorizedDataElements)
Populates theAuthorizedDataElements
portion of thekeyAuthorizations
withinDeviceKeyInfo
.MobileSecurityObjectGenerator
setDeviceKeyAuthorizedNameSpaces(java.util.List<java.lang.String> authorizedNameSpaces)
Populates theAuthorizedNameSpaces
portion of thekeyAuthorizations
withinDeviceKeyInfo
.MobileSecurityObjectGenerator
setDeviceKeyInfo(java.util.Map<java.lang.Long,byte[]> keyInfo)
Provides extra info for the mdoc authentication public key as part of theKeyInfo
portion of theDeviceKeyInfo
.MobileSecurityObjectGenerator
setValidityInfo(Timestamp signed, Timestamp validFrom, Timestamp validUntil, Timestamp expectedUpdate)
Sets theValidityInfo
structure which contains information related to the validity of the MSO and its signature.
-
-
-
Constructor Detail
-
MobileSecurityObjectGenerator
public MobileSecurityObjectGenerator(@NonNull java.lang.String digestAlgorithm, @NonNull java.lang.String docType, @NonNull java.security.PublicKey deviceKey)
Constructs a newMobileSecurityObjectGenerator
.- Parameters:
digestAlgorithm
- The digest algorithm identifier. Must be one of {"SHA-256", "SHA-384", "SHA-512"}.docType
- The document type.deviceKey
- The public part of the key pair used for mdoc authentication.- Throws:
java.lang.IllegalArgumentException
- if thedigestAlgorithm
is not one of {"SHA-256", "SHA-384", "SHA-512"}.
-
-
Method Detail
-
addDigestIdsForNamespace
@NonNull public MobileSecurityObjectGenerator addDigestIdsForNamespace(@NonNull java.lang.String nameSpace, @NonNull java.util.Map<java.lang.Long,byte[]> digestIDs)
Populates theValueDigests
mapping. This must be called at least once before generating sinceValueDigests
must be non-empty.- Parameters:
nameSpace
- The namespace.digestIDs
- A non-empty mapping between aDigestID
and aDigest
.- Returns:
- The
MobileSecurityObjectGenerator
. - Throws:
java.lang.IllegalArgumentException
- if thedigestIDs
is empty.
-
setDeviceKeyAuthorizedNameSpaces
@NonNull public MobileSecurityObjectGenerator setDeviceKeyAuthorizedNameSpaces(@NonNull java.util.List<java.lang.String> authorizedNameSpaces)
Populates theAuthorizedNameSpaces
portion of thekeyAuthorizations
withinDeviceKeyInfo
. This gives authorizations to full namespaces included in theauthorizedNameSpaces
array. If authorization is given for a full namespace, that namespace shall not be included insetDeviceKeyAuthorizedDataElements(Map)
.- Parameters:
authorizedNameSpaces
- A list of namespaces which should be given authorization.- Returns:
- The
MobileSecurityObjectGenerator
. - Throws:
java.lang.IllegalArgumentException
- if the authorizedNameSpaces does not meet the constraints.
-
setDeviceKeyAuthorizedDataElements
@NonNull public MobileSecurityObjectGenerator setDeviceKeyAuthorizedDataElements(@NonNull java.util.Map<java.lang.String,java.util.List<java.lang.String>> authorizedDataElements)
Populates theAuthorizedDataElements
portion of thekeyAuthorizations
withinDeviceKeyInfo
. This gives authorizations to data elements included in theauthorizedDataElements
mapping. If a namespace is included here, then it should not be included insetDeviceKeyAuthorizedNameSpaces(List)
- Parameters:
authorizedDataElements
- A mapping from namespaces to a list ofDataElementIdentifier
- Returns:
- The
MobileSecurityObjectGenerator
. - Throws:
java.lang.IllegalArgumentException
- if authorizedDataElements does not meet the constraints.
-
setDeviceKeyInfo
@NonNull public MobileSecurityObjectGenerator setDeviceKeyInfo(@NonNull java.util.Map<java.lang.Long,byte[]> keyInfo)
Provides extra info for the mdoc authentication public key as part of theKeyInfo
portion of theDeviceKeyInfo
.- Parameters:
keyInfo
- A mapping to represent additional key information.- Returns:
- The
MobileSecurityObjectGenerator
.
-
setValidityInfo
@NonNull public MobileSecurityObjectGenerator setValidityInfo(@NonNull Timestamp signed, @NonNull Timestamp validFrom, @NonNull Timestamp validUntil, @Nullable Timestamp expectedUpdate)
Sets theValidityInfo
structure which contains information related to the validity of the MSO and its signature. This must be called before generating since this a required component of theMobileSecurityObject
.- Parameters:
signed
- The timestamp at which the MSO signature was created.validFrom
- The timestamp before which the MSO is not yet valid. This shall be equal or later than the signed element.validUntil
- The timestamp after which the MSO is no longer valid. This shall be later than the validFrom element.expectedUpdate
- Optional: if provided, represents the timestamp at which the issuing authority infrastructure expects to re-sign the MSO, else, null- Returns:
- The
MobileSecurityObjectGenerator
. - Throws:
java.lang.IllegalArgumentException
- if the times are do not meet the constraints.
-
generate
@NonNull public byte[] generate()
Builds theMobileSecurityObject
CBOR.It's mandatory to call
addDigestIdsForNamespace(String, Map)
andsetValidityInfo(Timestamp, Timestamp, Timestamp, Timestamp)
before this call.- Returns:
- the bytes of
MobileSecurityObject
CBOR. - Throws:
java.lang.IllegalStateException
- if required data hasn't been set using the setter methods on this class.
-
-