目录

FIDO Kit手工转换指导书

开发准备

您若需要应用支持FIDO Kit,必须完成接入准备,请参见开发准备。

GlobalEnvSetting类中的接口

GlobalEnvSetting初始化:

GlobalEnvSetting.init();

GlobalEnvSetting判断:

if(GlobalEnvSetting.isHms());

Fido类中的接口

Google API

To HMS API

Fido.getFido2ApiClient(Activity activity)

Fido2.getFido2Client(Activity activity)

Google API调用示例:

Fido2ApiClient fido2Client= Fido.getFido2ApiClient(activity);

To HMS API调用示例:

Fido2Client fido2Client = Fido2.getFido2Client(activity);

Fido类中的字符串

FIDO2_KEY_RESPONSE_EXTRA

FIDO2_KEY_ERROR_EXTRA

The key used by the calling Activity to retrieve AuthenticatorAttestationResponse or AuthenticatorAssertionResponse from the Intent received by onActivityResult(int, int, Intent) after launching Fido2PendingIntent.

The key used by the calling Activity to retrieve AuthenticatorErrorResponse from the Intent received by onActivityResult(int, int, Intent) after launching Fido2PendingIntent.

GMS服务迁移到HMS Core服务时,org.xms.g.fido.Fido类中缺少以上两个关键的注册和认证的回复判断值,有如下两种解决方式:

  1. 引入com.google.android.gms.fido.Fido.FIDO2_KEY_RESPONSE_EXTRA和com.google.android.gms.fido.Fido.FIDO2_KEY_ERROR_EXTRA。
  2. org.xms.g.fido.Fido类中添加:
    // TODO start USER_CUSTOM_CODE_IN_CLASS_BODY_org.xms.g.fido.Fido
    public static final String FIDO2_KEY_RESPONSE_EXTRA = "FIDO2_RESPONSE_EXTRA";
    public static final String FIDO2_KEY_ERROR_EXTRA = "FIDO2_ERROR_EXTRA";
    // TODO end USER_CUSTOM_CODE_IN_CLASS_BODY_org.xms.g.fido.Fido

Fido2ApiClient类中的接口

Google API

Add HMS API

To HMS API

Fido2ApiClient.getRegisterIntent

(PublicKeyCredentialCreationOptions requestOptions)

Fido2Client.getRegistrationIntent

(Fido2RegistrationRequest request, NativeFido2RegistrationOptions options, Fido2IntentCallback callback)

Fido2Client.getRegistrationIntent

(Fido2RegistrationRequest request, NativeFido2RegistrationOptions options, Fido2IntentCallback callback)

Fido2ApiClient.getSignIntent

(PublicKeyCredentialRequestOptions requestOptions)

Fido2Client.getAuthenticationIntent

(Fido2AuthenticationRequest request, NativeFido2AuthenticationOptions options, Fido2IntentCallback callback)

Fido2Client.getAuthenticationIntent

(Fido2AuthenticationRequest request, NativeFido2AuthenticationOptions options, Fido2IntentCallback callback)

Fido2PrivilegedApiClient类中的接口

Google API

To HMS API

Add HMS API

Fido2PrivilegedApiClient.getRegisterIntent(PublicKeyCredentialCreationOptions requestOptions)

Fido2Client.getRegistrationIntent(Fido2RegistrationRequest request, NativeFido2RegistrationOptions options, Fido2IntentCallback callback)

Fido2Client.getRegistrationIntent(Fido2RegistrationRequest request, NativeFido2RegistrationOptions options, Fido2IntentCallback callback)

Fido2PrivilegedApiClient.getSignIntent(PublicKeyCredentialRequestOptions requestOptions)

Fido2Client.getAuthenticationIntent(Fido2AuthenticationRequest request, NativeFido2AuthenticationOptions options, Fido2IntentCallback callback)

Fido2Client.getAuthenticationIntent(Fido2AuthenticationRequest request, NativeFido2AuthenticationOptions options, Fido2IntentCallback callback)

参照Fido2ApiClient类getSignIntent()接口。

PublicKeyCredentialCreationOptions类中的接口

Google API

To HMS API

PublicKeyCredentialCreationOptions.getTimeoutSeconds()

PublicKeyCredentialCreationOptions.getTimeoutSeconds()

PublicKeyCredentialCreationOptions.Builder.setTimeoutSeconds(Double timeoutSeconds)

PublicKeyCredentialCreationOptions.Builder.setTimeoutSeconds(Long timeoutSeconds)

Google API调用示例:

PublicKeyCredentialCreationOptions.Builder builder = new PublicKeyCredentialCreationOptions.Builder();
builder.setTimeoutSeconds(60d);
//设置一些属性后,build()出一个PublicKeyCredentialCreationOptions对象。
PublicKeyCredentialCreationOptions options =  builder.build();
Double timeoutSeconds = options.getTimeoutSeconds();

To HMS API调用示例:

PublicKeyCredentialCreationOptions.Builder builder = new PublicKeyCredentialCreationOptions.Builder();
builder.setTimeoutSeconds(60L);
//设置一些属性后,build()出一个PublicKeyCredentialCreationOptions对象。
PublicKeyCredentialCreationOptions options =  builder.build();
Long timeoutSeconds = options.getTimeoutSeconds();

PublicKeyCredentialDescriptor类中的接口

Google API

To HMS API

PublicKeyCredentialDescriptor(String type, byte[] id, List<Transport> transports)

PublicKeyCredentialDescriptor(PublicKeyCredentialType type, byte[] id, ArrayList<AuthenticatorTransport> transports)

Google API调用示例:

String type= PublicKeyCredentialType.PUBLIC_KEY.toString();
List<Transport> atlist = new ArrayList<Transport>();
atlist.add(Transport.USB);
atlist.add(Transport.NFC);
atlist.add(Transport.BLUETOOTH_LOW_ENERGY);
byte[] id = SecureRandom.getSeed(16);
PublicKeyCredentialDescriptor pd = new PublicKeyCredentialDescriptor(type, id, atlist);

To HMS API调用示例:

PublicKeyCredentialType type= PublicKeyCredentialType.PUBLIC_KEY;
List<AuthenticatorTransport> atlist = new ArrayList<AuthenticatorTransport>();
atlist.add(AuthenticatorTransport.USB);
atlist.add(AuthenticatorTransport.NFC);
atlist.add(AuthenticatorTransport.BLE);
byte[] id = SecureRandom.getSeed(16);
PublicKeyCredentialDescriptor pd = new PublicKeyCredentialDescriptor(type, id, atlist);

PublicKeyCredentialParameters类中的接口

Google API

To HMS API

PublicKeyCredentialParameters(String type, int algorithm)

PublicKeyCredentialParameters(PublicKeyCredentialType type, Algorithm algorithm)

Google API调用示例:

PublicKeyCredentialParameters pp = new PublicKeyCredentialParameters(PublicKeyCredentialType.PUBLIC_KEY.toString(), EC2Algorithm.ES256.getAlgoValue());

To HMS API调用示例:

PublicKeyCredentialParameters pp = new PublicKeyCredentialParameters(PublicKeyCredentialType.PUBLIC_KEY, Algorithm.ES256);

PublicKeyCredentialRequestOptions类中的接口

Google API

To HMS API

PublicKeyCredentialRequestOptions.getTimeoutSeconds()

PublicKeyCredentialRequestOptions.getTimeoutSeconds()

PublicKeyCredentialRequestOptions.Builder setTimeoutSeconds(Double timeoutSeconds)

PublicKeyCredentialRequestOptions.Builder setTimeoutSeconds(Long timeoutSeconds)

参见PublicKeyCredentialCreationOptions类中的getTimeoutSeconds()和setTimeoutSeconds()接口。

PublicKeyCredentialUserEntity类中的接口

Google API

To HMS API

PublicKeyCredentialUserEntity(byte[] id, String name, String icon, String displayName)

PublicKeyCredentialUserEntity(String displayName, byte[] id, String name, String icon)

仅参数顺序不一致。

Google API调用示例:

byte[] id = SecureRandom.getSeed(16);
String name = "Fido2Demo";
String icon = "fido2.png";
String displayName = "fido2 demo";
PublicKeyCredentialUserEntity user = new PublicKeyCredentialUserEntity(id, name, icon, displayName);

To HMS API调用示例:

byte[] id = SecureRandom.getSeed(16);
String name = "Fido2Demo";
String icon = "fido2.png";
String displayName = "fido2 demo";
PublicKeyCredentialUserEntity user = new PublicKeyCredentialUserEntity(displayName, id, name, icon);

RSAAlgorithm类中的接口

Google API

To HMS API

RSAAlgorithm.PS256

Algorithm.PS256

RSAAlgorithm.PS384

Algorithm.PS384

RSAAlgorithm.PS512

Algorithm.PS512

RSAAlgorithm.RS256

Algorithm.RS256

RSAAlgorithm.RS384

Algorithm.RS384

RSAAlgorithm.RS512

Algorithm.RS512

Google API调用示例:

RSAAlgorithm rsaAlgorithm  = RSAAlgorithm.PS256;

To HMS API调用示例:

Algorithm algorithm  = Algorithm.PS256;

TokenBinding类中的接口

Google API

To HMS API

TokenBinding.getTokenBindingStatusAsString()

TokenBinding.getStatus()

Google API调用示例:

TokenBinding tb = new TokenBinding("tb");
String statusString = tb.getTokenBindingStatusAsString();

To HMS API调用示例:

TokenBinding tb = new TokenBinding(TokenBindingStatus.fromValue("tb"),"id");
TokenBindingStatus status = tb.getStatus();
String statusString = status.getValue();