cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Third-Party Certificate Provider in android native application with SMP3.0

Former Member
0 Kudos

I am trying to implement certificate based authentication with android native application with SMP3.0 sp11

I configured the appid in SMP3.0 for x509 certificate based authentication and tested with rest client by using the user certificate demouser.p12

Now I installed the certificate demouser.p12 in android device and used maf login components and libs in android project. I am referring the doc below-

http://help.sap.com/saphelp_smp3011sdk/helpdata/en/3c/227ce642834b60a210baacc39cc7d7/content.htm

I am not able to call the getCertificate method. Please suggest what wrong i am doing.

-------------------------------------------------------------------------------------------------------------------

package com.sample.x509test; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.InputType; import android.util.Log; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import com.google.android.gms.appindexing.Action; import com.google.android.gms.appindexing.AppIndex; import com.google.android.gms.common.api.GoogleApiClient; import com.sap.maf.tools.logon.core.LogonCore; import com.sap.maf.tools.logon.core.LogonCoreException; import com.sap.maf.tools.logon.core.reg.RegistrationManager; import com.sap.maf.tools.logon.logonui.api.CertificateProvider; import com.sap.maf.tools.logon.logonui.api.CertificateProviderException; import com.sap.maf.tools.logon.logonui.api.CertificateProviderListener; import com.sap.maf.tools.logon.logonui.api.LogonListener; import com.sap.maf.tools.logon.logonui.api.LogonUIFacade; import com.sap.maf.tools.logon.manager.LogonContext; import com.sap.maf.tools.logon.manager.LogonManager; import java.util.Map; import javax.net.ssl.X509KeyManager; public class MAFLogonActivity extends AppCompatActivity implements LogonListener, CertificateProvider{ private String _alias = "defaultAlias"; private String _filePath = "defaultFilePath"; private String _certPwd = "defaultPassword"; private String _appId; private Activity _activity; Context mContext; CertificateProviderListener certificateProviderListener; /** * ATTENTION: This was auto-generated to implement the App Indexing API. * See https://g.co/AppIndexing/AndroidStudio for more information. */ private GoogleApiClient client; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_maflogon); // set context reference mContext = this; // get an instance of the LogonUIFacade LogonUIFacade mLogonUIFacade = LogonUIFacade.getInstance(); //Initialize the Logon UI Facade mLogonUIFacade.init(this, mContext, AppSettings.APP_ID); //customize the maf logon screen mLogonUIFacade.setDefaultValue(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_SUPSERVERURL, XXXXXX); mLogonUIFacade.setDefaultValue(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_SUPSERVERPORT, "8082"); mLogonUIFacade.setDefaultValue(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_HTTPSSTATUS, "True"); mLogonUIFacade.setDefaultValue(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_SECCONFIG, "CertAuth"); mLogonUIFacade.setDefaultValue(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_APPID, "com.x509.test"); mLogonUIFacade.setDefaultValue(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_USERCREATIONPOLICY, "certificate"); /* mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_USERNAME, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_PASSWORD, true);*/ mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_SUPSERVERFARMID, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_URLSUFFIX, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_MOBILEUSER, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_ACTIVATIONCODE, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_HTTPSSTATUS, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_GATEWAYCLIENT, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_SUPSERVERDOMAIN, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_PINGPATH, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_GWONLY, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_MOBILEPLACE, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_PASSCODESTATUS, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_VAULTPOLICY, true); setContentView(mLogonUIFacade.logon()); // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. } @Override public void getCertificate(CertificateProviderListener callback) { certificateProviderListener = callback; mContext = (Activity) LogonUIFacade.getInstance().getActivityContext(); mContext.startActivity(new Intent(mContext, ProviderActivity.class)); } @Override public X509KeyManager getStoredCertificate() { // This function is how the certificate is retrieved synchronously. CustomKeyManager keyManager = null; try { keyManager = new CustomKeyManager(_filePath, _certPwd, _alias); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return keyManager; } @Override public void deleteStoredCertificate() throws CertificateProviderException { } @Override public void onLogonFinished(String s, boolean b, LogonContext logonContext) { String TAG = MAFLogonActivity.class.getSimpleName(); Log.d(TAG, "onLogonFinished: " + s); //Check if it finished successfully if (b) { try { //For debugging purposes will log the app connection id and // the end point url. // In a productive app, remember to remove these logs String appConnID = LogonCore.getInstance().getLogonContext().getConnId(); Log.d(TAG, "onLogonFinished: appcid:" + appConnID); Log.d(TAG, "onLogonFinished: endpointurl:" + logonContext.getEndPointUrl()); } catch (LogonManager.LogonManagerException e) { Log.e(TAG, e.getLocalizedMessage(), e); } catch (LogonCoreException e) { Log.e(TAG, e.getLocalizedMessage(), e); } // Navigate to the Main menu screen Intent goToNextActivity = new Intent(this, MainActivity.class); startActivity(goToNextActivity); finish(); } } @Override public void onSecureStorePasswordChanged(boolean b, String s) { } @Override public void onBackendPasswordChanged(boolean b) { } @Override public void onUserDeleted() { } @Override public void onApplicationSettingsUpdated() { } @Override public void registrationInfo() { } @Override public void objectFromSecureStoreForKey() { } @Override public void onRefreshCertificate(boolean b, String s) { } }

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Suresh,

May i suggest you to try with latest SDK , please check this guide: https://uacp2.hana.ondemand.com/viewer/42dc90f1e1ed45d9aafad60c80646d10/3.0.15/en-US/3c227ce642834b6...

If you still see same error, reach out to SAP support team by raising an OSS ticket.

Regards,

JK (Moderator)

PS: If your query has already been resolved, please close it by providing your solution, it will help others.

Accepted Solutions (0)

Answers (0)