Home | History | Annotate | Download | only in pbapclient
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.bluetooth.pbapclient;
     18 
     19 import android.os.Handler;
     20 import android.util.Log;
     21 
     22 import javax.obex.Authenticator;
     23 import javax.obex.PasswordAuthentication;
     24 
     25 /* ObexAuthentication is a required component for PBAP in order to support backwards compatibility
     26  * with PSE devices prior to PBAP 1.2. With profiles prior to 1.2 the actual initiation of
     27  * authentication is implementation defined.
     28  */
     29 
     30 
     31 class BluetoothPbapObexAuthenticator implements Authenticator {
     32 
     33     private final static String TAG = "BluetoothPbapObexAuthenticator";
     34 
     35     //Default session key for legacy devices is 0000
     36     private String mSessionKey = "0000";
     37 
     38     private final Handler mCallback;
     39 
     40     public BluetoothPbapObexAuthenticator(Handler callback) {
     41         mCallback = callback;
     42     }
     43 
     44     @Override
     45     public PasswordAuthentication onAuthenticationChallenge(String description,
     46             boolean isUserIdRequired, boolean isFullAccess) {
     47         PasswordAuthentication pa = null;
     48         Log.v(TAG, "onAuthenticationChallenge: starting");
     49 
     50         if (mSessionKey != null && mSessionKey.length() != 0) {
     51             Log.v(TAG, "onAuthenticationChallenge: mSessionKey=" + mSessionKey);
     52             pa = new PasswordAuthentication(null, mSessionKey.getBytes());
     53         } else {
     54             Log.v(TAG, "onAuthenticationChallenge: mSessionKey is empty, timeout/cancel occured");
     55         }
     56 
     57         return pa;
     58     }
     59 
     60     @Override
     61     public byte[] onAuthenticationResponse(byte[] userName) {
     62         Log.v(TAG, "onAuthenticationResponse: " + userName);
     63         /* required only in case PCE challenges PSE which we don't do now */
     64         return null;
     65     }
     66 
     67 }
     68