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.util.Log; 20 21 import com.android.internal.annotations.VisibleForTesting; 22 import com.android.obex.Authenticator; 23 import com.android.obex.PasswordAuthentication; 24 25 import java.util.Arrays; 26 27 /* ObexAuthentication is a required component for PBAP in order to support backwards compatibility 28 * with PSE devices prior to PBAP 1.2. With profiles prior to 1.2 the actual initiation of 29 * authentication is implementation defined. 30 */ 31 class PbapClientObexAuthenticator implements Authenticator { 32 private static final String TAG = PbapClientObexAuthenticator.class.getSimpleName(); 33 34 // Default session key for legacy devices is 0000 35 @VisibleForTesting String mSessionKey = "0000"; 36 37 @Override onAuthenticationChallenge( String description, boolean isUserIdRequired, boolean isFullAccess)38 public PasswordAuthentication onAuthenticationChallenge( 39 String description, boolean isUserIdRequired, boolean isFullAccess) { 40 PasswordAuthentication pa = null; 41 Log.d(TAG, "onAuthenticationChallenge: starting"); 42 43 if (mSessionKey != null && mSessionKey.length() != 0) { 44 Log.d(TAG, "onAuthenticationChallenge: mSessionKey=" + mSessionKey); 45 pa = new PasswordAuthentication(null, mSessionKey.getBytes()); 46 } else { 47 Log.d(TAG, "onAuthenticationChallenge: mSessionKey is empty, timeout/cancel occurred"); 48 } 49 50 return pa; 51 } 52 53 @Override onAuthenticationResponse(byte[] userName)54 public byte[] onAuthenticationResponse(byte[] userName) { 55 Log.v(TAG, "onAuthenticationResponse: " + Arrays.toString(userName)); 56 /* required only in case PCE challenges PSE which we don't do now */ 57 return null; 58 } 59 } 60