안드로이드의 Platform key로 App을 Signing하면 플랫폼에서만 허용가능한 퍼미션을 얻을 수 있습니다.
예를 들어, 아래와 같이 안드로이드 시스템에서 선언한 퍼미션들을 얻으려면 동일한 key로 앱이 서명되어야 합니다.
<!-- Allows applications to call into AccountAuthenticators.
<p>Not for use by third-party applications. -->
<permission android:name="android.permission.ACCOUNT_MANAGER"
android:protectionLevel="signature" />
또는, 다음과 같이 자신의 앱을 안드로이드 시스템과 동일한 sharedUserId로 설정할 수 있습니다.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.app"
android:sharedUserId="android.uid.system"
다만 여기서 소개하는 platform key로 서명하는 방식은 에뮬레이터에서만 사용이 가능한 방법입니다. 시장에서 판매되는 안드로이드 디바이스에는 적용이 안됩니다.
서명을 하려면 AOSP의 /build/target/product/security
경로에서 다음 두개의 파일이 필요합니다.
- platform.x509.pem
- platform.pk8
이 두개의 파일로 서명하는 방법은 다음과 같이 두가지가 있습니다.
- apk를 직접 서명하는 방법
- jks 파일을 만들어 안드로이드 스튜디오에서 서명하는 방법
Apk를 직접 서명
platform.pk8
와 app-debug.apk
파일을 구했다면, 그 다음 필요한 것은 Apk Sign라는 툴을 다운받는 것입니다.
이 링크에서 중간쯤 보시면 signapk.jar
를 다운받는 링크가 있습니다.
그럼, 다음 명령어로 "app-unsigned.apk"
파일을 플랫폼 키로 signing을 할 수 있습니다. 서명된 apk는 "app-signed.apk"
로 생성됩니다.
$ java -jar signapk.jar platform.x509.pem platform.pk8 app-unsigned.apk app-signed.apk
jks 파일을 만들어 안드로이드 스튜디오에서 서명
platform.pk8
와 app-debug.apk
파일이 준비된 상태에서 다음 명령어를 입력하면 platform.jks
라는 파일이 생성됩니다.
$ openssl pkcs8 -inform DER -nocrypt -in platform.pk8 -out platform.pem
$ openssl pkcs12 -export -in platform.x509.pem -inkey platform.pem -out platform.p12 -password pass:android -name platform
$ keytool -importkeystore -deststorepass android -destkeystore platform.jks -srcstoretype PKCS12 -srcstorepass android -srckeystore
Android Studio에서 이 파일을 키로 등록하여 앱을 서명할 수 있습니다.
위의 명령어에서 alias와 password 등을 다음과 같이 정하였습니다. 이 부분은 변경이 가능한 부분입니다.
key store password: android
key alias: platform
key password: android
주의할 점은 이 키는 AOSP를 빌드하여 만든 이미지에만 적용이 됩니다. 안드로이드 스튜디오에서 에뮬레이터에게 제공하는 이미지는 키가 달라서 적용이 안됩니다.
참고
Related Posts
- Android 14 - 사진/동영상 파일, 일부 접근 권한 소개
- Android - adb push, pull로 파일 복사, 다운로드
- Android 14 - 암시적 인텐트 변경사항 및 문제 해결
- Jetpack Compose - Row와 Column
- Android 13, AOSP 오픈소스 다운로드 및 빌드
- Android 13 - 세분화된 미디어 파일 권한
- Android 13에서 Notification 권한 요청, 알림 띄우기
- Android 13에서 'Access blocked: ComponentInfo' 에러 해결
- 에러 해결: android gradle plugin requires java 11 to run. you are currently using java 1.8.
- 안드로이드 - 코루틴과 Retrofit으로 비동기 통신 예제
- 안드로이드 - 코루틴으로 URL 이미지 불러오기
- Android - 진동, Vibrator, VibrationEffect 예제
- Some problems were found with the configuration of task 에러 수정
- Query method parameters should either be a type that can be converted into a database column or a List
- 우분투에서 Android 12 오픈소스 다운로드 및 빌드
- Android - ViewModel을 생성하는 방법
- Android - Transformations.map(), switchMap() 차이점
- Android - Transformations.distinctUntilChanged() 소개
- Android - TabLayout 구현 방법 (+ ViewPager2)
- Android - 휴대폰 전화번호 가져오는 방법
- Android 12 - Splash Screens 알아보기
- Android 12 - Incremental Install (Play as you Download) 소개
- Android - adb 명령어로 bugreport 로그 파일 추출
- Android - adb 명령어로 App 데이터 삭제
- Android - adb 명령어로 앱 비활성화, 활성화
- Android - adb 명령어로 특정 패키지의 PID 찾기
- Android - adb 명령어로 퍼미션 Grant 또는 Revoke
- Android - adb 명령어로 apk 설치, 삭제
- Android - adb 명령어로 특정 패키지의 프로세스 종료
- Android - adb 명령어로 screen capture 저장
- Android - adb 명령어로 System 앱 삭제, 설치
- Android - adb 명령어로 settings value 확인, 변경
- Android 12 - IntentFilter의 exported 명시적 선언
- Android - adb 명령어로 공장초기화(Factory reset)
- Android - adb logcat 명령어로 로그 출력