Package com.android.identity
Class MobileSecurityObjectGenerator
- java.lang.Object
-
- com.android.identity.MobileSecurityObjectGenerator
-
public class MobileSecurityObjectGenerator extends java.lang.ObjectHelper class for buildingMobileSecurityObjectCBOR 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 MobileSecurityObjectGeneratoraddDigestIdsForNamespace(java.lang.String nameSpace, java.util.Map<java.lang.Long,byte[]> digestIDs)Populates theValueDigestsmapping.byte[]generate()Builds theMobileSecurityObjectCBOR.MobileSecurityObjectGeneratorsetDeviceKeyAuthorizedDataElements(java.util.Map<java.lang.String,java.util.List<java.lang.String>> authorizedDataElements)Populates theAuthorizedDataElementsportion of thekeyAuthorizationswithinDeviceKeyInfo.MobileSecurityObjectGeneratorsetDeviceKeyAuthorizedNameSpaces(java.util.List<java.lang.String> authorizedNameSpaces)Populates theAuthorizedNameSpacesportion of thekeyAuthorizationswithinDeviceKeyInfo.MobileSecurityObjectGeneratorsetDeviceKeyInfo(java.util.Map<java.lang.Long,byte[]> keyInfo)Provides extra info for the mdoc authentication public key as part of theKeyInfoportion of theDeviceKeyInfo.MobileSecurityObjectGeneratorsetValidityInfo(Timestamp signed, Timestamp validFrom, Timestamp validUntil, Timestamp expectedUpdate)Sets theValidityInfostructure 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 thedigestAlgorithmis 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 theValueDigestsmapping. This must be called at least once before generating sinceValueDigestsmust be non-empty.- Parameters:
nameSpace- The namespace.digestIDs- A non-empty mapping between aDigestIDand aDigest.- Returns:
- The
MobileSecurityObjectGenerator. - Throws:
java.lang.IllegalArgumentException- if thedigestIDsis empty.
-
setDeviceKeyAuthorizedNameSpaces
@NonNull public MobileSecurityObjectGenerator setDeviceKeyAuthorizedNameSpaces(@NonNull java.util.List<java.lang.String> authorizedNameSpaces)
Populates theAuthorizedNameSpacesportion of thekeyAuthorizationswithinDeviceKeyInfo. This gives authorizations to full namespaces included in theauthorizedNameSpacesarray. 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 theAuthorizedDataElementsportion of thekeyAuthorizationswithinDeviceKeyInfo. This gives authorizations to data elements included in theauthorizedDataElementsmapping. 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 theKeyInfoportion 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 theValidityInfostructure 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 theMobileSecurityObjectCBOR.It's mandatory to call
addDigestIdsForNamespace(String, Map)andsetValidityInfo(Timestamp, Timestamp, Timestamp, Timestamp)before this call.- Returns:
- the bytes of
MobileSecurityObjectCBOR. - Throws:
java.lang.IllegalStateException- if required data hasn't been set using the setter methods on this class.
-
-